tesseract
5.0.0-alpha-619-ge9db
svmnode.cpp
Go to the documentation of this file.
1
// File: svmnode.cpp
3
// description_: ScrollView Menu Node
4
// Author: Joern Wanke
5
// Created: Thu Nov 29 2007
6
//
7
// (C) Copyright 2007, Google Inc.
8
// Licensed under the Apache License, Version 2.0 (the "License");
9
// you may not use this file except in compliance with the License.
10
// You may obtain a copy of the License at
11
// http://www.apache.org/licenses/LICENSE-2.0
12
// Unless required by applicable law or agreed to in writing, software
13
// distributed under the License is distributed on an "AS IS" BASIS,
14
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
// See the License for the specific language governing permissions and
16
// limitations under the License.
17
//
19
//
20
// A SVMenuNode is an entity which contains the mapping from a menu entry on
21
// the server side to the corresponding associated commands on the client.
22
// It is designed to be a tree structure with a root node, which can then be
23
// used to generate the appropriate messages to the server to display the
24
// menu structure there.
25
// A SVMenuNode can both be used in the context_ of popup menus as well as
26
// menu bars.
27
28
#include <cstring>
29
#include <iostream>
30
31
#include "
svmnode.h
"
32
33
// Include automatically generated configuration file if running autoconf.
34
#ifdef HAVE_CONFIG_H
35
#include "config_auto.h"
36
#endif
37
38
#ifndef GRAPHICS_DISABLED
39
40
#include "
scrollview.h
"
41
42
// Create the empty root menu node. with just a caption. All other nodes should
43
// be added to this or one of the submenus.
44
SVMenuNode::SVMenuNode
() {
45
cmd_event_ = -1;
46
child_ =
nullptr
;
47
next_ =
nullptr
;
48
parent_ =
nullptr
;
49
toggle_value_ =
false
;
50
is_check_box_entry_ =
false
;
51
}
52
53
SVMenuNode::~SVMenuNode
() {
54
}
55
56
// Create a new sub menu node with just a caption. This is used to create
57
// nodes which act as parent nodes to other nodes (e.g. submenus).
58
SVMenuNode
*
SVMenuNode::AddChild
(
const
char
* txt) {
59
auto
* s =
new
SVMenuNode
(-1, txt,
false
,
false
,
nullptr
,
nullptr
);
60
this->
AddChild
(s);
61
return
s;
62
}
63
64
// Create a "normal" menu node which is associated with a command event.
65
void
SVMenuNode::AddChild
(
const
char
* txt,
int
command_event) {
66
this->
AddChild
(
new
SVMenuNode
(command_event, txt,
false
,
false
,
nullptr
,
nullptr
));
67
}
68
69
// Create a menu node with an associated value (which might be changed
70
// through the gui).
71
void
SVMenuNode::AddChild
(
const
char
* txt,
int
command_event,
72
const
char
* val) {
73
this->
AddChild
(
new
SVMenuNode
(command_event, txt,
false
,
false
, val,
nullptr
));
74
}
75
76
// Create a menu node with an associated value and description_.
77
void
SVMenuNode::AddChild
(
const
char
* txt,
int
command_event,
const
char
* val,
78
const
char
* desc) {
79
this->
AddChild
(
new
SVMenuNode
(command_event, txt,
false
,
false
, val, desc));
80
}
81
82
// Create a flag menu node.
83
void
SVMenuNode::AddChild
(
const
char
* txt,
int
command_event,
int
tv) {
84
this->
AddChild
(
new
SVMenuNode
(command_event, txt, tv,
true
,
nullptr
,
nullptr
));
85
}
86
87
// Convenience function called from the different constructors to initialize
88
// the different values of the menu node.
89
SVMenuNode::SVMenuNode
(
int
command_event,
const
char
* txt,
90
int
tv,
bool
check_box_entry,
const
char
* val,
91
const
char
* desc)
92
: text_(txt), value_(val), description_(desc) {
93
cmd_event_ = command_event;
94
95
child_ =
nullptr
;
96
next_ =
nullptr
;
97
parent_ =
nullptr
;
98
toggle_value_ = tv != 0;
99
is_check_box_entry_ = check_box_entry;
100
}
101
102
// Add a child node to this menu node.
103
void
SVMenuNode::AddChild
(
SVMenuNode
* svmn) {
104
svmn->parent_ =
this
;
105
// No children yet.
106
if
(child_ ==
nullptr
) {
107
child_ = svmn;
108
}
else
{
109
SVMenuNode
* cur = child_;
110
while
(cur->next_ !=
nullptr
) { cur = cur->next_; }
111
cur->next_ = svmn;
112
}
113
}
114
115
// Build a menu structure for the server and send the necessary messages.
116
// Should be called on the root node. If menu_bar is true, a menu_bar menu
117
// is built (e.g. on top of the window), if it is false a popup menu is
118
// built which gets shown by right clicking on the window.
119
// Deletes itself afterwards.
120
void
SVMenuNode::BuildMenu
(
ScrollView
* sv,
bool
menu_bar) {
121
if
((parent_ !=
nullptr
) && (menu_bar)) {
122
if
(is_check_box_entry_) {
123
sv->
MenuItem
(parent_->text_.
c_str
(), text_.
c_str
(), cmd_event_,
124
toggle_value_);
125
}
else
{
126
sv->
MenuItem
(parent_->text_.
c_str
(), text_.
c_str
(), cmd_event_); }
127
}
else
if
((parent_ !=
nullptr
) && (!menu_bar)) {
128
if
(description_.
length
() > 0) {
129
sv->
PopupItem
(parent_->text_.
c_str
(), text_.
c_str
(), cmd_event_,
130
value_.
c_str
(), description_.
c_str
());
131
}
else
{
132
sv->
PopupItem
(parent_->text_.
c_str
(), text_.
c_str
());
133
}
134
}
135
if
(child_ !=
nullptr
) {
136
child_->
BuildMenu
(sv, menu_bar);
delete
child_;
137
}
138
if
(next_ !=
nullptr
) {
139
next_->
BuildMenu
(sv, menu_bar);
delete
next_;
140
}
141
}
142
143
#endif // GRAPHICS_DISABLED
ScrollView
Definition:
scrollview.h:97
SVMenuNode::SVMenuNode
SVMenuNode()
Definition:
svmnode.cpp:44
SVMenuNode::AddChild
SVMenuNode * AddChild(const char *txt)
Definition:
svmnode.cpp:58
ScrollView::MenuItem
void MenuItem(const char *parent, const char *name)
Definition:
scrollview.cpp:679
svmnode.h
STRING::c_str
const char * c_str() const
Definition:
strngs.cpp:192
SVMenuNode::BuildMenu
void BuildMenu(ScrollView *sv, bool menu_bar=true)
Definition:
svmnode.cpp:120
STRING::length
int32_t length() const
Definition:
strngs.cpp:187
SVMenuNode
Definition:
svmnode.h:35
SVMenuNode::~SVMenuNode
~SVMenuNode()
Definition:
svmnode.cpp:53
scrollview.h
ScrollView::PopupItem
void PopupItem(const char *parent, const char *name)
Definition:
scrollview.cpp:685
src
viewer
svmnode.cpp
Generated on Thu Jan 30 2020 14:22:21 for tesseract by
1.8.16