source: Sophya/trunk/Poubelle/PI/Tests/pitst.cc@ 222

Last change on this file since 222 was 222, checked in by ansari, 26 years ago

Creation module DPC/PI Reza 09/04/99

File size: 13.7 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3
4/* Ceci est un programme test des differents composants de PI : PEIDA Interactif */
5/* Reza , 96-98 */
6
7/* C'est ecrit n'importe comment ! */
8
9#include "pisysdep.h"
10
11#include PIAPP_H
12#include PIWIN_H
13#include PIMENU_H
14#include PIOPTMENU_H
15#include PISTDWDG_H
16#include PIBWDG_H
17#include PIPIXMAP_H
18#include PIFILECHO_H
19#include PILIST_H
20
21#include "piscdrawwdg.h"
22
23/*
24int SysBeep(int n)
25{
26for(int i=0; i<n; i++) putchar('\007');
27return(0);
28}
29*/
30
31class PITestApp : public PIApplication {
32public:
33 PITestApp(int sx, int sy);
34 ~PITestApp();
35
36 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
37
38 PIMenu *m[5];
39 PIMenu *mc[2];
40 PICheckBox * ckb;
41 PIText * text;
42 PIButton * bouton;
43 PIButton * bouton2, * bouton3, * bouton4, * bouton5;
44 PIButton * bouton11, * bouton12, * bouton13,* bouton14 ,* bouton15 ;
45 PILabel * label;
46 PIScale * scl;
47 PIMenu * menu;
48 PIOptMenu * opt, * opt2;
49 bool stnewmen[2];
50
51};
52
53
54
55PITestApp::PITestApp(int sx, int sy)
56: PIApplication(550, 350)
57{
58char ans[128];
59 m[0] = new PIMenu(Menubar(),"File");
60 m[0]->AppendItem("Open", 10101);
61 m[0]->AppendItem("Close", 10102);
62 m[0]->AppendItem("New", 10103);
63// m[0]->AppendItem("ScBar", 10105);
64 m[0]->AppendItem("Quit", 10104);
65
66 m[1] = new PIMenu(Menubar(),"Edit");
67 m[1]->AppendItem("Copier", 10201);
68 m[1]->AppendItem("Coller", 10202);
69 m[1]->AppendItem("Couper", 10203);
70 m[1]->AppendCheckItem("Check It", 10205);
71 mc[0] = new PIMenu(m[1], "Cascade");
72 mc[0]->AppendItem("EdeCas-1", 10221);
73 mc[0]->AppendItem("EdeCas-2", 10222);
74 mc[0]->AppendItem("EdeCas-3", 10223);
75 m[1]->AppendPDMenu(mc[0]);
76
77 m[2] = new PIMenu(Menubar(),"Operation");
78 m[2]->AppendItem("AddItem", 10301);
79 m[2]->AppendItem("DelItemName", 10302);
80 m[2]->AppendItem("DelItemMsg", 10303);
81
82 m[3] = new PIMenu(Menubar(),"Special");
83 m[3]->AppendItem("Spec-Opt1", 10401);
84 m[3]->AppendItem("Spec-Opt2", 10402);
85 m[3]->AppendItem("Spec-Cascade", 10403);
86 mc[1] = new PIMenu(m[3], "Spec-Cascade");
87 mc[1]->AppendItem("Spec-Cas-1", 10441);
88 mc[1]->AppendItem("Spec-Cas-2", 10442);
89 mc[1]->AppendItem("Spec-Cas-3", 10443);
90 m[3]->AppendPDMenu(mc[1]);
91 m[3]->AppendCheckItem("Checkable", 10414);
92
93 m[4] = new PIMenu(Menubar(),"AddMenu2");
94 m[4]->AppendItem("option-A", 10501);
95 m[4]->AppendItem("option-B", 10502);
96 m[4]->AppendItem("option-C", 10503);
97
98 AppendMenu(m[0]);
99 AppendMenu(m[1]);
100 AppendMenu(m[2]);
101
102 ckb = new PICheckBox(this->MainWin(), "CheckBox", 166, 60, 20, 10, 10);
103 text = new PIText(this->MainWin(), "TEXTE", 180, 30, 20,40);
104 text->SetMsg(7440);
105 label = new PILabel(this->MainWin(), "Label", 180, 20, 20,80);
106 label->SetBorderWidth(1);
107 bouton = new PIButton(this->MainWin(), "->Menu", 33, 60, 25, 20, 120);
108 bouton2 = new PIButton(this->MainWin(), "Dialog", 333, 60, 25, 100, 120);
109 bouton3 = new PIButton(this->MainWin(), "ScDraw", 433, 60, 25, 180, 120);
110 bouton4 = new PIButton(this->MainWin(), "Pixmap", 133, 60, 25, 260, 120);
111 bouton5 = new PIButton(this->MainWin(), "List", 533, 60, 25, 340, 120);
112
113 scl = new PIScale(this->MainWin(), "Scale", 88, kSDirRtoL, 200, 20, 10, 150);
114 scl->SetMinMax(5, 45);
115
116 int psx, psy;
117 PrefCompSz(psx, psy);
118 cout << " Creation bouton 11 -14 avec Sx,Sy= " << psx << " , " << psy << endl;
119
120 bouton11 = new PIButton(this->MainWin(), "AddMen-1", 1133, psx*1.5, psy, 20, 250);
121 bouton12 = new PIButton(this->MainWin(), "AddMen-2", 1233, psx*1.5, psy, 40+psx*1.5, 250);
122 stnewmen[0] = stnewmen[1] = false;
123 bouton13 = new PIButton(this->MainWin(), "Ready/Bloc", 1333, psx*1.5, psy, 20, 300);
124 bouton14 = new PIButton(this->MainWin(), "TS-BWdg", 1433, psx*1.5, psy, 40+psx*1.5, 300);
125 bouton15 = new PIButton(this->MainWin(), "TS-MenuIt", 1533, psx*1.5, psy, 60+psx*3, 300);
126
127// XSync(PIXDisplay(), FALSE);
128// printf("Creation PIPUMenu DoIt-1... \n"); gets(ans);
129 menu = new PIMenu(this->MainWin(), "myMenu");
130// XSync(PIXDisplay(), FALSE);
131// printf("Apres Creation PIPUMenu -AppendItem() 1 ... \n"); gets(ans);
132
133 menu->AppendItem("DoIt-1", 4401);
134// XSync(PIXDisplay(), FALSE);
135// printf("Apres Creation PIPUMenu -AppendItem() 2 ... \n"); gets(ans);
136
137 menu->AppendItem("DoIt-2", 4402);
138 menu->AppendItem("DoIt-25", 4425);
139 menu->AppendItem("DoIt-26", 4426);
140 menu->AppendItem("Check-33", 4433);
141
142// XSync(PIXDisplay(), FALSE);
143// printf("Creation PIPUMenu Copier ... \n"); gets(ans);
144
145
146 opt = new PIOptMenu(this->MainWin(), "Option-Menu-1", 120, 25, 10, 200);
147 opt->AppendItem("Linear", 5601);
148 opt->AppendItem("Log.", 5602);
149 opt->AppendItem("Sqrt", 5603);
150 opt->AppendItem("Expon", 5604);
151 opt->AppendItem("Polyn", 5605);
152
153 string ops = "Sqrt";
154 opt->SetValueStr(ops);
155
156 opt2 = new PIOptMenu(this->MainWin(), "Option-Menu-1", 120, 25, 150, 200);
157 opt2->AppendItem("Copier", 80201);
158 opt2->AppendItem("Coller", 80202);
159 opt2->AppendItem("Couper", 80203);
160 opt2->AppendItem("Undo", 80204);
161 opt2->AppendItem("Select-All", 80205);
162
163}
164
165PITestApp::~PITestApp()
166{
167 delete ckb;
168 delete text;
169 delete label;
170 delete bouton;
171 delete bouton2;
172 delete bouton3;
173 delete bouton4;
174 delete bouton5;
175 delete bouton11;
176 delete bouton12;
177 delete bouton13;
178 delete bouton14;
179 delete bouton15;
180 delete menu;
181 delete m[0]; delete m[1]; delete m[2]; delete m[3]; delete m[4];
182 delete mc[0]; delete mc[1];
183 delete opt;
184 delete opt2;
185 delete scl;
186}
187
188/* ........................................................... */
189/* Classe ScSample */
190/* ........................................................... */
191
192class ScSample : public PIScDrawWdg {
193public:
194 ScSample(PIContainerGen *par, char *nom,
195 int sx=10, int sy=10, int px=0, int py=0);
196 virtual ~ScSample();
197};
198
199static double fpol(double x) {return (0.3*x*x*x-x*x+7.);}
200static double fx2(double x) {return (0.5*x*x);}
201
202ScSample::ScSample(PIContainerGen *par, char *nom,
203 int sx, int sy, int px, int py)
204:PIScDrawWdg(par, nom, sx, sy, px, py)
205
206{
207// Definition des limites
208SetLimits(-3,5,-10,15);
209
210// Creation et ajout d'un drawer de fonctions
211PIFuncDrawer* mfd = new PIFuncDrawer(fpol);
212mfd->SetColAtt(PI_Blue);
213mfd->SetLineAtt(PI_NormalLine);
214AddScDrawer(mfd,true);
215PIFuncDrawer* mfd2 = new PIFuncDrawer(fx2);
216mfd2->SetColAtt(PI_Red);
217mfd2->SetLineAtt(PI_NormalLine);
218AddScDrawer(mfd2,true);
219SetAxesFlags(kAxesDflt);
220}
221
222ScSample::~ScSample()
223{
224}
225
226static ScSample *scs1, *scs2, *scs3;
227static PIScrollBar *scb, *scb2;
228
229static PIWindow * wp3, *wp4, *wp5, *wp6;
230static PIPixmap * pxm;
231static unsigned char pixels[25000];
232static PIFileChooser *pfc;
233static bool fgpxm = false;
234static bool fgt = false;
235static bool fgt2 = false;
236static bool fgt3 = false;
237
238static PIListX * pil;
239
240void
241PITestApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
242{
243 static int x = 0;
244 static numsg=8800;
245
246 char truc[256];
247 sprintf(truc,"< %ld - %d (%d)>",msg,x++, (int)((PIWdgGen *)sender)->kind());
248 this->label->SetLabel(truc);
249 sprintf(truc,"[%d] Msg= %ld (%d-%d) Kind=(%d) Data= (%ld - %lx)",x, msg, (int)UserMsg(msg),
250 (int)ModMsg(msg), (int)((PIWdgGen *)sender)->kind(), (long)data, (long)data);
251 puts(truc);
252
253 if (ModMsg(msg) == PIMsg_Active)
254 printf("Process: Setting active Wdg (%lx) \n", (long)sender);
255
256 if (ModMsg(msg) == PIMsg_Close)
257 {
258 printf("Close Message received (Sender= %lx)\n", (long)sender);
259 return;
260 }
261
262 msg = UserMsg(msg);
263 if (msg == 33) { ckb->SetState(true); menu->Show(); }
264
265 if (msg == 133)
266 {
267 if (!fgpxm) { wp3->Show(); fgpxm = true; }
268 for (int i=0; i<25000; i++) pixels[i] = rand()%256;
269 if ((x % 3) == 0) pxm->SetColMapId(CMAP_GREY32);
270 if ((x % 3) == 1) pxm->SetColMapId(CMAP_COLRJ32);
271 if ((x % 3) == 2) pxm->SetColMapId(CMAP_COLBR32);
272 }
273
274 if (msg == 333) wp4->Show();
275 if ( (msg == 6001) || (msg == 6002) ) wp4->Hide();
276
277 if (msg == 433)
278 {
279 if (fgt2) { wp5->Hide(); fgt2 = false; }
280 else { wp5->Show(); fgt2 = true; }
281 }
282
283 if (msg == 533)
284 {
285 if (fgt3) { wp6->Hide(); fgt3 = false; }
286 else { wp6->Show(); fgt3 = true; }
287 }
288
289 if ( (msg == 1133) || (msg == 1233) ) { // On ajoute ou on enleve un menu du menu-bar
290 int idxmen = (msg-1133)/100;
291 cout << " Add/Remove Menu idxmen= " << idxmen << " Bool= "
292 << Menubar()->IsSensitive(m[idxmen+3]) << " ( " << stnewmen[idxmen] << ")" << endl;
293 if ( Menubar()->IsSensitive(m[idxmen+3]) )
294 { Menubar()->RemoveMenu(m[idxmen+3]); stnewmen[idxmen] = false; }
295 else { Menubar()->AppendMenu(m[idxmen+3]); stnewmen[idxmen] = true; }
296 }
297
298 if (msg == 1333) { // Changement de sensibilite de Menu-Bar (par SetBusy())
299 cout << " SetSens() Menubar, State= " << GetState() << endl;
300 if (GetState() != kReadyState) SetReady();
301 else SetBlocked();
302 }
303
304 if (msg == 1533) { // Changement de sensibilite de Cascade
305 cout << " ChangeSensitivity() Cascade Bool= " << m[1]->IsSensitive("Cascade") << endl;
306 if (m[1]->IsSensitive("Cascade") ) m[1]->SetSensitivity("Cascade", false);
307 else m[1]->SetSensitivity("Cascade", true);
308 }
309
310 if (msg == 1433) { // Changement de sensibilite de BaseWidget (ScSample)
311 if (scs1->IfSensitive()) scs1->SetUnSensitive();
312 else scs1->SetSensitive();
313 }
314// if (msg == 555) (this->menu)->Show();
315
316 if (msg == 10105) scb->SetSlSize(atoi(((char *)text->GetText().c_str())));
317 if (msg == 10104) Stop();
318 if (msg == 10101) { pfc->AcceptNewFile(false); pfc->Show(); }
319 if (msg == 10103) { pfc->AcceptNewFile(true); pfc->Show(); }
320
321 if ((msg == 10205) || (msg == 166)) { // CheckItem Menu or checkbox
322 cout << "PITestApp::Process CheckItem/Box Menu (" << msg
323 << ") State=" << *((bool *)data) << endl;
324 }
325
326 if (msg == 10301)
327 {
328 numsg++;
329 string nit;
330 nit = text->GetText();
331 m[1]->AppendItem((char *)nit.c_str(), numsg);
332 opt2->SetValue(numsg);
333 }
334
335 if (msg == 10302) { m[1]->DeleteItem((char *)text->GetText().c_str()); }
336 if (msg == 10303)
337 {
338 string nit;
339 nit = text->GetText();
340 long ml = atol(nit.c_str());
341 m[1]->DeleteItemMsg(ml);
342 opt2->SetValue(10201);
343 }
344
345
346 if (msg > 9000) printf("PITestApp::MenubarReturn: %d --> %lx \n", msg, (long)data);
347 if (msg == 5000)
348 {
349 if (data)
350 {
351 printf("PITestApp::Process(5000) OK from PIFileChooser: %s \n", (char *)data);
352 }
353 else printf("PITestApp::Process(5000) Cancel from PIFileChooser (data=NULL) \n"); }
354
355 if ((msg / 100) == 56)
356 printf("PITestApp::Process(%d) : %lx \n", (int)msg, (long)data);
357
358 if (msg == 8811) printf("PITestApp::Process(8811) ScrollBar( %d ) \n", *( (int*)data) );
359 else if (msg == 8821) printf("PITestApp::Process(8821) ScrollBar( %d ) \n", *( (int*)data) );
360
361}
362
363int main(int narg, char *arg[])
364{
365 int mii;
366
367 if (narg < 2) {
368 printf("Usage pitst str1 [str2 ....] \n"); exit(1);
369 }
370
371 PITestApp * app;
372 app = new PITestApp(350, 350);
373
374
375 wp4 = new PIWindow(app, "Window-4", PIWK_dialog, 200, 200, 350, 350);
376 PIButton bt1(wp4, "OK", 6001, 60, 30, 20, 160);
377 PIButton bt2(wp4, "Cancel", 6002, 60, 30, 100, 160);
378 bt1.SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
379 bt2.SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
380 PILabel lb1(wp4, "Editable", 40, 30, 10, 10);
381 lb1.SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
382 PIText tx1(wp4, "A00", 100, 30, 60, 10);
383 tx1.SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
384 tx1.SetText("Hello");
385 tx1.SetTextEditable(false);
386 // PILabel lb2(wp4, "", 30, 20, 10, 40);
387 PIText tx2(wp4, "A11", 180, 100, 15, 50);
388 tx2.SetMutiLineMode(true);
389 tx2.SetText(" Bonjour, \n Comment ca va ? \n A demain. ");
390 tx2.SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
391
392 wp3 = new PIWindow(app, "Window-3", PIWK_normal, 200, 200, 350, 350);
393 pxm = new PIPixmap(wp3, "myPixmap", 150, 150, 10, 10);
394 pxm->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed,PIBK_fixed );
395 pxm->SetPixmap(pixels, 150, 150);
396
397 wp5 = new PIWindow(app, "Window-5", PIWK_normal, 420, 450, 200, 200);
398 scs1 = new ScSample(wp5, "ScSample", 200, 200, 0, 0);
399 scs1->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
400 scs2 = new ScSample(wp5, "ScSample", 160, 160, 220, 20);
401 printf("DBG-WP5 (A) , SCS2, SzC %d %d , Sz %d %d Pos %d %d \n", wp5->XSize(),
402 wp5->YSize(), scs2->XSize(), scs2->YSize(),scs2->XPos(), scs2->YPos() );
403// scs2->SetBinding(PIBK_elastic,PIBK_fixed,PIBK_fixed,PIBK_elastic);
404 scs2->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
405 printf("DBG-WP5 (B) , SCS2, SzC %d %d , Sz %d %d Pos %d %d \n", wp5->XSize(),
406 wp5->YSize(), scs2->XSize(), scs2->YSize(),scs2->XPos(), scs2->YPos() );
407
408 scb = new PIScrollBar(wp5, "ScBar", 8811, kSDirUpDown, 15, 420, 405, 0);
409 scb->SetBinding(PIBK_free,PIBK_fixed,PIBK_fixed,PIBK_fixed);
410 scb->ActivateDrag(true);
411 scb2 = new PIScrollBar(wp5, "ScBar", 8821, kSDirRtoL, 420, 15, 0, 425);
412 scb2->SetBinding(PIBK_fixed,PIBK_free,PIBK_fixed,PIBK_fixed);
413
414 scs3 = new ScSample(wp5, "ScSample", 200, 200, 100, 220);
415 scs3->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
416
417 pfc = new PIFileChooser(app,"FileChooser", 5000);
418// pfc->SetPath("/exp/eros/ImagRed/");
419
420 wp6 = new PIWindow(app, "Window-List", PIWK_normal, 200, 250, 300, 400);
421 pil = new PIListX(wp6, "MyList", 200, 250, 0, 0);
422 pil->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed,PIBK_fixed);
423 for(mii=1; mii<narg; mii++)
424 {
425// printf("AppendItem[%d] - %s (%ld) \n", mii, arg[mii], 3330+mii);
426 pil->AppendItem(arg[mii], 3330+mii);
427// puts("Append-OK");
428 }
429 pil->SetMultipleSelect(true);
430 pil->SelectItem("user.cc");
431// Int32 ioNumber = 100;
432 app->Run();
433 delete app;
434 exit(0);
435}
Note: See TracBrowser for help on using the repository browser.