1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 9/2002 <mailto:tbretz@astro-uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MSearch
|
---|
28 | //
|
---|
29 | // Simple search dialog (usefull for TGTextViews)
|
---|
30 | //
|
---|
31 | // Sends: kC_USER, KS_START, mp1, txt
|
---|
32 | //
|
---|
33 | // with mp1: bit0 on=case sensitive
|
---|
34 | // bit1 on=backward
|
---|
35 | // mp2: char* pointing to the text to search for
|
---|
36 | //
|
---|
37 | // WARNING: Do not store mp2, immeditaly copy the text to a local
|
---|
38 | // location!
|
---|
39 | //
|
---|
40 | /////////////////////////////////////////////////////////////////////////////
|
---|
41 | #include "MSearch.h"
|
---|
42 |
|
---|
43 | #include <TSystem.h> // gSystem
|
---|
44 | #include <TGLabel.h> // TGLabel
|
---|
45 | #include <TGButton.h> // TGButton
|
---|
46 | #include <TGTextEntry.h> // TGTextEntry
|
---|
47 |
|
---|
48 | #include "MGList.h"
|
---|
49 |
|
---|
50 | ClassImp(MSearch);
|
---|
51 |
|
---|
52 | enum
|
---|
53 | {
|
---|
54 | kSearchText, kCase, kDirection, kSearch, kCancel
|
---|
55 | };
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor. w is the window which will receive the message.
|
---|
60 | // Id is currently useless.
|
---|
61 | //
|
---|
62 | MSearch::MSearch(const TGWindow *w, Int_t id) : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 1, 1), TGWidget(id)
|
---|
63 | {
|
---|
64 | Associate(w);
|
---|
65 |
|
---|
66 | fList = new MGList;
|
---|
67 | fList->SetOwner();
|
---|
68 |
|
---|
69 | // set the smallest and biggest size of the Main frame
|
---|
70 | SetWMSizeHints(320, 110, 250, 50, 0, 0);
|
---|
71 | Move(rand()%100+50, rand()%100+50);
|
---|
72 |
|
---|
73 | // -------------------------------------------------------------
|
---|
74 |
|
---|
75 | TGLayoutHints *lay4=new TGLayoutHints(kLHintsNormal|kLHintsExpandX);
|
---|
76 | TGLayoutHints *lay0=new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 4, 8, 4);
|
---|
77 | TGLayoutHints *lay1=new TGLayoutHints(kLHintsNormal, 6, 4, 8);
|
---|
78 | TGLayoutHints *lay2=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
|
---|
79 | TGLayoutHints *lay3=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
|
---|
80 | TGLayoutHints *lay5=new TGLayoutHints(kLHintsNormal, 5, 5, 5);
|
---|
81 | TGLayoutHints *lay7=new TGLayoutHints(kLHintsCenterX);
|
---|
82 |
|
---|
83 | // -------------------------------------------------------------
|
---|
84 | // Create Widgets
|
---|
85 | // -------------------------------------------------------------
|
---|
86 |
|
---|
87 | TGHorizontalFrame *f = new TGHorizontalFrame(this, 1, 1);
|
---|
88 | TGLabel *label = new TGLabel(this, "Find Text:");
|
---|
89 | TGTextEntry *entry = new TGTextEntry(f, "", kSearchText);
|
---|
90 | TGCheckButton *box1 = new TGCheckButton(this, "Match upper/lower case", kCase);
|
---|
91 | TGCheckButton *box2 = new TGCheckButton(this, "Search backward", kDirection);
|
---|
92 | TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 1, 1);
|
---|
93 | TGHorizontalFrame *f3 = new TGHorizontalFrame(f2, 1, 1);
|
---|
94 | TGTextButton *txt1 = new TGTextButton(f3, "Search", kSearch);
|
---|
95 | TGTextButton *txt2 = new TGTextButton(f3, "Cancel", kCancel);
|
---|
96 |
|
---|
97 | txt1->Associate(this);
|
---|
98 | txt2->Associate(this);
|
---|
99 |
|
---|
100 | // -------------------------------------------------------------
|
---|
101 | // Layout the widgets in the frame
|
---|
102 | // -------------------------------------------------------------
|
---|
103 |
|
---|
104 | AddFrame(f, lay4);
|
---|
105 | f->AddFrame(label, lay1);
|
---|
106 | f->AddFrame(entry, lay0);
|
---|
107 | AddFrame(box1, lay2);
|
---|
108 | AddFrame(box2, lay3);
|
---|
109 | AddFrame(f2, lay4);
|
---|
110 | f2->AddFrame(f3, lay7);
|
---|
111 | f3->AddFrame(txt1, lay5);
|
---|
112 | f3->AddFrame(txt2, lay5);
|
---|
113 |
|
---|
114 | // -------------------------------------------------------------
|
---|
115 |
|
---|
116 | entry->Associate(this);
|
---|
117 | txt1->Associate(this);
|
---|
118 | txt1->Associate(this);
|
---|
119 |
|
---|
120 | // -------------------------------------------------------------
|
---|
121 |
|
---|
122 | fList->Add(lay0);
|
---|
123 | fList->Add(lay1);
|
---|
124 | fList->Add(lay2);
|
---|
125 | fList->Add(lay3);
|
---|
126 | fList->Add(lay4);
|
---|
127 | fList->Add(lay5);
|
---|
128 | fList->Add(lay7);
|
---|
129 | fList->Add(f);
|
---|
130 | fList->Add(f2);
|
---|
131 | fList->Add(f3);
|
---|
132 | fList->Add(label);
|
---|
133 | fList->Add(entry);
|
---|
134 | fList->Add(box1);
|
---|
135 | fList->Add(box2);
|
---|
136 | fList->Add(txt1);
|
---|
137 | fList->Add(txt2);
|
---|
138 |
|
---|
139 | // -------------------------------------------------------------
|
---|
140 |
|
---|
141 | Layout();
|
---|
142 |
|
---|
143 | MapSubwindows();
|
---|
144 |
|
---|
145 | SetWindowName("Search in Text");
|
---|
146 | SetIconName("Search");
|
---|
147 |
|
---|
148 | MapWindow();
|
---|
149 | }
|
---|
150 |
|
---|
151 | // --------------------------------------------------------------------------
|
---|
152 | //
|
---|
153 | // Destruct the window with all its tiles and widgets.
|
---|
154 | //
|
---|
155 | MSearch::~MSearch()
|
---|
156 | {
|
---|
157 | delete fList;
|
---|
158 | }
|
---|
159 |
|
---|
160 | // --------------------------------------------------------------------------
|
---|
161 | //
|
---|
162 | // Send the search message to the associated TGWindow.
|
---|
163 | // See class description.
|
---|
164 | //
|
---|
165 | Bool_t MSearch::SendSearch()
|
---|
166 | {
|
---|
167 | if (!fMsgWindow)
|
---|
168 | return kTRUE;
|
---|
169 |
|
---|
170 | const TGCheckButton &b1 = *(TGCheckButton*)fList->FindWidget(kCase);
|
---|
171 | const TGCheckButton &b2 = *(TGCheckButton*)fList->FindWidget(kDirection);
|
---|
172 | const TGTextEntry &e = *(TGTextEntry*) fList->FindWidget(kSearchText);
|
---|
173 |
|
---|
174 | const Long_t msg = MK_MSG(kC_USER, (EWidgetMessageTypes)kS_START);
|
---|
175 | const Long_t mp1 = (b1.GetState()<<1) | b2.GetState();
|
---|
176 | const Long_t mp2 = (Long_t)e.GetText();
|
---|
177 |
|
---|
178 | SendMessage(fMsgWindow, msg, mp1, mp2);
|
---|
179 |
|
---|
180 | return kTRUE;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // --------------------------------------------------------------------------
|
---|
184 | //
|
---|
185 | // Process messages from the widgets.
|
---|
186 | //
|
---|
187 | Bool_t MSearch::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
|
---|
188 | {
|
---|
189 | // Can be found in WidgetMessageTypes.h
|
---|
190 | switch (GET_MSG(msg))
|
---|
191 | {
|
---|
192 | case kC_COMMAND:
|
---|
193 | switch (GET_SUBMSG(msg))
|
---|
194 | {
|
---|
195 | case kCM_BUTTON:
|
---|
196 | switch (mp1)
|
---|
197 | {
|
---|
198 | case kSearch:
|
---|
199 | return SendSearch();
|
---|
200 | case kCancel:
|
---|
201 | delete this;
|
---|
202 | return kTRUE;
|
---|
203 | }
|
---|
204 | return kTRUE;
|
---|
205 |
|
---|
206 | }
|
---|
207 | return kTRUE;
|
---|
208 | }
|
---|
209 | return kTRUE;
|
---|
210 | }
|
---|