source: trunk/Mars/mbase/MSearch.cc@ 14888

Last change on this file since 14888 was 9195, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.3 KB
Line 
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 <stdlib.h> // rand (Ubuntu 8.10)
44
45#include <TSystem.h> // gSystem
46#include <TGLabel.h> // TGLabel
47#include <TGButton.h> // TGButton
48#include <TGTextEntry.h> // TGTextEntry
49
50#include "MGList.h"
51
52ClassImp(MSearch);
53
54enum
55{
56 kSearchText, kCase, kDirection, kSearch, kCancel
57};
58
59// --------------------------------------------------------------------------
60//
61// Default constructor. w is the window which will receive the message.
62// Id is currently useless.
63//
64MSearch::MSearch(const TGWindow *w, Int_t id) : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 1, 1), TGWidget(id)
65{
66 Associate(w);
67
68 fList = new MGList;
69 fList->SetOwner();
70
71 // set the smallest and biggest size of the Main frame
72 SetWMSizeHints(320, 110, 250, 50, 0, 0);
73 Move(rand()%100+50, rand()%100+50);
74
75 // -------------------------------------------------------------
76
77 TGLayoutHints *lay4=new TGLayoutHints(kLHintsNormal|kLHintsExpandX);
78 TGLayoutHints *lay0=new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 4, 8, 4);
79 TGLayoutHints *lay1=new TGLayoutHints(kLHintsNormal, 6, 4, 8);
80 TGLayoutHints *lay2=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
81 TGLayoutHints *lay3=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
82 TGLayoutHints *lay5=new TGLayoutHints(kLHintsNormal, 5, 5, 5);
83 TGLayoutHints *lay7=new TGLayoutHints(kLHintsCenterX);
84
85 // -------------------------------------------------------------
86 // Create Widgets
87 // -------------------------------------------------------------
88
89 TGHorizontalFrame *f = new TGHorizontalFrame(this, 1, 1);
90 TGLabel *label = new TGLabel(this, "Find Text:");
91 TGTextEntry *entry = new TGTextEntry(f, "", kSearchText);
92 TGCheckButton *box1 = new TGCheckButton(this, "Match upper/lower case", kCase);
93 TGCheckButton *box2 = new TGCheckButton(this, "Search backward", kDirection);
94 TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 1, 1);
95 TGHorizontalFrame *f3 = new TGHorizontalFrame(f2, 1, 1);
96 TGTextButton *txt1 = new TGTextButton(f3, "Search", kSearch);
97 TGTextButton *txt2 = new TGTextButton(f3, "Cancel", kCancel);
98
99 txt1->Associate(this);
100 txt2->Associate(this);
101
102 // -------------------------------------------------------------
103 // Layout the widgets in the frame
104 // -------------------------------------------------------------
105
106 AddFrame(f, lay4);
107 f->AddFrame(label, lay1);
108 f->AddFrame(entry, lay0);
109 AddFrame(box1, lay2);
110 AddFrame(box2, lay3);
111 AddFrame(f2, lay4);
112 f2->AddFrame(f3, lay7);
113 f3->AddFrame(txt1, lay5);
114 f3->AddFrame(txt2, lay5);
115
116 // -------------------------------------------------------------
117
118 entry->Associate(this);
119 txt1->Associate(this);
120 txt1->Associate(this);
121
122 // -------------------------------------------------------------
123
124 fList->Add(lay0);
125 fList->Add(lay1);
126 fList->Add(lay2);
127 fList->Add(lay3);
128 fList->Add(lay4);
129 fList->Add(lay5);
130 fList->Add(lay7);
131 fList->Add(f);
132 fList->Add(f2);
133 fList->Add(f3);
134 fList->Add(label);
135 fList->Add(entry);
136 fList->Add(box1);
137 fList->Add(box2);
138 fList->Add(txt1);
139 fList->Add(txt2);
140
141 // -------------------------------------------------------------
142
143 Layout();
144
145 MapSubwindows();
146
147 SetWindowName("Search in Text");
148 SetIconName("Search");
149
150 MapWindow();
151}
152
153// --------------------------------------------------------------------------
154//
155// Destruct the window with all its tiles and widgets.
156//
157MSearch::~MSearch()
158{
159 delete fList;
160}
161
162// --------------------------------------------------------------------------
163//
164// Send the search message to the associated TGWindow.
165// See class description.
166//
167Bool_t MSearch::SendSearch()
168{
169 if (!fMsgWindow)
170 return kTRUE;
171
172 const TGCheckButton &b1 = *(TGCheckButton*)fList->FindWidget(kCase);
173 const TGCheckButton &b2 = *(TGCheckButton*)fList->FindWidget(kDirection);
174 const TGTextEntry &e = *(TGTextEntry*) fList->FindWidget(kSearchText);
175
176 const Long_t msg = MK_MSG(kC_USER, (EWidgetMessageTypes)kS_START);
177 const Long_t mp1 = (b1.GetState()<<1) | b2.GetState();
178 const Long_t mp2 = (Long_t)e.GetText();
179
180 SendMessage(fMsgWindow, msg, mp1, mp2);
181
182 return kTRUE;
183}
184
185// --------------------------------------------------------------------------
186//
187// Process messages from the widgets.
188//
189Bool_t MSearch::ProcessMessage(Long_t msg, Long_t mp1, Long_t /*mp2*/)
190{
191 // Can be found in WidgetMessageTypes.h
192 switch (GET_MSG(msg))
193 {
194 case kC_COMMAND:
195 switch (GET_SUBMSG(msg))
196 {
197 case kCM_BUTTON:
198 switch (mp1)
199 {
200 case kSearch:
201 return SendSearch();
202 case kCancel:
203 delete this;
204 return kTRUE;
205 }
206 return kTRUE;
207
208 }
209 return kTRUE;
210 }
211 return kTRUE;
212}
Note: See TracBrowser for help on using the repository browser.