forked from xination/ROOTSCOPE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.h
170 lines (96 loc) · 4.01 KB
/
dev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/////////////////////////////////////////////////////////////////////////////////////
class Dlg_add_note: public TGTransientFrame {
TString* fnote;
TGHorizontalFrame* fHF;
TGTextEntry* fTextEntries;
TGTextButton* fBtn_close;
TGTextButton* fBtn_cancel;
public:
// class constructor
Dlg_add_note( const TGWindow* , /* base windows */
const TGWindow*, /* the windows transient from */
UInt_t , /* width */
UInt_t , /* height */
TString* );
void To_response_key( Event_t* );
void To_focus_on_entry( Event_t* );
void CloseWindow();
void Cancel();
void Update_note(char* );
};
void Dlg_add_note::Update_note(char* entry_output){
*fnote = entry_output;
}
void Dlg_add_note::Cancel(){
// cancel the change.
*fnote = "";
CloseWindow();
}
void Dlg_add_note::CloseWindow(){
fBtn_close->SetState(kButtonDisabled); // to avoid double click.
fBtn_cancel->SetState(kButtonDisabled);
DeleteWindow();
}
void Dlg_add_note::To_focus_on_entry( Event_t* e) {
fTextEntries->SetFocus();
fTextEntries->SelectAll();
}
void Dlg_add_note::To_response_key(Event_t* e) {
if ( e->fType == kGKeyPress )
{
// using LookuString to get the key mapping.
UInt_t key_symbol;
char tmp[2];
gVirtualX->LookupString( e, tmp,sizeof(tmp), key_symbol );
const unsigned key_enter = 36;
if( key_symbol == kKey_Enter ) { CloseWindow(); } // the enter key near num pad
else if ( e->fCode == key_enter ) { CloseWindow(); } // the enter key in regular position.
else if( key_symbol == kKey_Escape ) { CloseWindow(); }
}
}
// class constructor
Dlg_add_note::Dlg_add_note( const TGWindow* p,
const TGWindow* main,
UInt_t w,
UInt_t h,
TString* title)
: TGTransientFrame(p, main, w, h)
{
SetCleanup(kDeepCleanup); // important step for closing windows properly.
fnote = title;
TGLayoutHints* Layout1 = new TGLayoutHints( kLHintsCenterY, 2, 2, 2, 2);
fHF = new TGHorizontalFrame( this, 200, 30 );
//-------------------------------------------------------------------| text entry
fTextEntries =
new TGTextEntry( fHF, fnote->Data(), 1); /* base, init value, ID */
fTextEntries->Resize( 300, fTextEntries->GetDefaultHeight() );
fHF->AddFrame( fTextEntries, Layout1 );
//------------------------------------------------------------------| Connect
fTextEntries
-> Connect( "TextChanged(char*)",
"Dlg_add_note", this, "Update_note(char*)");
fTextEntries
-> Connect( "ProcessedEvent(Event_t*)",
"Dlg_add_note", this,
"To_response_key(Event_t*)");
//-------------------------------------------------------------------| btn: close the window
fBtn_close = new TGTextButton( fHF, " OK " );
fBtn_close -> Connect( "Clicked()", "Dlg_add_note", this, "CloseWindow()" );
fHF->AddFrame( fBtn_close, Layout1 );
fBtn_close->Resize( 150, fBtn_close->GetDefaultHeight() );
//-------------------------------------------------------------------| btn: cancel the change
fBtn_cancel = new TGTextButton( fHF, "Cancel" );
fBtn_cancel -> Connect( "Clicked()", "Dlg_add_note", this, "Cancel()" );
fHF->AddFrame( fBtn_cancel, Layout1 );
fBtn_cancel->Resize(150, fBtn_cancel->GetDefaultHeight() );
AddFrame( fHF, Layout1 );
//-----------------------------------------------------------to focus on entry
this->Connect( "ProcessedEvent(Event_t*)", "Dlg_add_note", this,
"To_focus_on_entry(Event_t*)" );
SetName("Dlg_add_note");
SetWindowName("Add note");
MapSubwindows();
Resize( GetDefaultSize() );
MapWindow();
gClient->WaitFor(this);
}