Fixed issue 1099

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1067 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
theraysmith@gmail.com 2014-04-24 00:06:36 +00:00
parent a9f483cffc
commit 4decc0f405
4 changed files with 40 additions and 40 deletions

View File

@ -132,22 +132,22 @@ const char* ParamContent::GetDescription() const {
}
// Getter for the value.
const char* ParamContent::GetValue() const {
char* msg = new char[1024];
STRING ParamContent::GetValue() const {
STRING result;
if (param_type_ == VT_INTEGER) {
sprintf(msg, "%d", ((inT32) *(iIt)));
result.add_str_int("", *iIt);
} else if (param_type_ == VT_BOOLEAN) {
sprintf(msg, "%d", ((BOOL8) * (bIt)));
result.add_str_int("", *bIt);
} else if (param_type_ == VT_DOUBLE) {
sprintf(msg, "%g", ((double) * (dIt)));
result.add_str_double("", *dIt);
} else if (param_type_ == VT_STRING) {
if (((STRING) * (sIt)).string() != NULL) {
sprintf(msg, "%s", ((STRING) * (sIt)).string());
result = sIt->string();
} else {
sprintf(msg, "Null");
result = "Null";
}
}
return msg;
return result;
}
// Setter for the value.
@ -246,19 +246,19 @@ SVMenuNode* ParamsEditor::BuildListOfAllLeaves(tesseract::Tesseract *tess) {
STRING tag3;
GetPrefixes(vc->GetName(), &tag, &tag2, &tag3);
if (amount[tag.string()] == 1) { other->AddChild(vc->GetName(), vc->GetId(),
vc->GetValue(),
if (amount[tag.string()] == 1) {
other->AddChild(vc->GetName(), vc->GetId(), vc->GetValue().string(),
vc->GetDescription());
} else { // More than one would use this submenu -> create submenu.
SVMenuNode* sv = mr->AddChild(tag.string());
if ((amount[tag.string()] <= MAX_ITEMS_IN_SUBMENU) ||
(amount[tag2.string()] <= 1)) {
sv->AddChild(vc->GetName(), vc->GetId(),
vc->GetValue(), vc->GetDescription());
vc->GetValue().string(), vc->GetDescription());
} else { // Make subsubmenus.
SVMenuNode* sv2 = sv->AddChild(tag2.string());
sv2->AddChild(vc->GetName(), vc->GetId(),
vc->GetValue(), vc->GetDescription());
vc->GetValue().string(), vc->GetDescription());
}
}
}
@ -278,7 +278,7 @@ void ParamsEditor::Notify(const SVEvent* sve) {
sve->command_id);
vc->SetValue(param);
sv_window_->AddMessage("Setting %s to %s",
vc->GetName(), vc->GetValue());
vc->GetName(), vc->GetValue().string());
}
}
}
@ -344,8 +344,8 @@ void ParamsEditor::WriteParams(char *filename,
++iter) {
ParamContent* cur = iter->second;
if (!changes_only || cur->HasChanged()) {
fprintf (fp, "%-25s %-12s # %s\n",
cur->GetName(), cur->GetValue(), cur->GetDescription());
fprintf(fp, "%-25s %-12s # %s\n",
cur->GetName(), cur->GetValue().string(), cur->GetDescription());
}
}
fclose(fp);

View File

@ -62,7 +62,7 @@ class ParamContent : public ELIST_LINK {
// Getters and Setters.
void SetValue(const char* val);
const char* GetValue() const;
STRING GetValue() const;
const char* GetName() const;
const char* GetDescription() const;

View File

@ -44,19 +44,14 @@
// be added to this or one of the submenus.
SVMenuNode::SVMenuNode() {
cmd_event_ = -1;
text_ = NULL;
child_ = NULL;
next_ = NULL;
parent_ = NULL;
toggle_value_ = false;
is_check_box_entry_ = false;
value_ = NULL;
description_ = NULL;
}
SVMenuNode::~SVMenuNode() {
delete[] text_;
// delete[] description_;
}
// Create a new sub menu node with just a caption. This is used to create
@ -94,16 +89,10 @@ void SVMenuNode::AddChild(const char* txt, int command_event, int tv) {
// the different values of the menu node.
SVMenuNode::SVMenuNode(int command_event, const char* txt,
int tv, bool check_box_entry, const char* val,
const char* desc) {
const char* desc)
: text_(txt), value_(val), description_(desc) {
cmd_event_ = command_event;
text_ = new char[strlen(txt) + 1];
strncpy(text_, txt, strlen(txt));
text_[strlen(txt)] = '\0';
value_ = val;
description_ = desc;
child_ = NULL;
next_ = NULL;
parent_ = NULL;
@ -132,15 +121,24 @@ void SVMenuNode::AddChild(SVMenuNode* svmn) {
void SVMenuNode::BuildMenu(ScrollView* sv, bool menu_bar) {
if ((parent_ != NULL) && (menu_bar)) {
if (is_check_box_entry_) {
sv->MenuItem(parent_->text_, text_, cmd_event_, toggle_value_);
} else { sv->MenuItem(parent_->text_, text_, cmd_event_); }
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_,
toggle_value_);
} else {
sv->MenuItem(parent_->text_.string(), text_.string(), cmd_event_); }
} else if ((parent_ != NULL) && (!menu_bar)) {
if (description_ != NULL) { sv->PopupItem(parent_->text_, text_,
cmd_event_, value_, description_);
} else { sv->PopupItem(parent_->text_, text_); }
if (description_.length() > 0) {
sv->PopupItem(parent_->text_.string(), text_.string(), cmd_event_,
value_.string(), description_.string());
} else {
sv->PopupItem(parent_->text_.string(), text_.string());
}
}
if (child_ != NULL) {
child_->BuildMenu(sv, menu_bar); delete child_;
}
if (next_ != NULL) {
next_->BuildMenu(sv, menu_bar); delete next_;
}
if (child_ != NULL) { child_->BuildMenu(sv, menu_bar); delete child_; }
if (next_ != NULL) { next_->BuildMenu(sv, menu_bar); delete next_; }
}
#endif // GRAPHICS_DISABLED

View File

@ -28,6 +28,8 @@
#ifndef TESSERACT_VIEWER_SVMNODE_H__
#define TESSERACT_VIEWER_SVMNODE_H__
#include "strngs.h"
class ScrollView;
class SVMenuNode {
@ -82,13 +84,13 @@ class SVMenuNode {
// The command event associated with a specific menu node. Should be unique.
int cmd_event_;
// The caption associated with a specific menu node.
char* text_;
STRING text_;
// The value of the flag (if this menu node is a flag).
bool toggle_value_;
// The value of the menu node. (optional)
const char* value_;
STRING value_;
// A description_ of the value. (optional)
const char* description_;
STRING description_;
};
#endif // TESSERACT_VIEWER_SVMNODE_H__