[181] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <string.h>
|
---|
| 4 |
|
---|
| 5 | #include <iostream.h>
|
---|
| 6 |
|
---|
| 7 | #include "pisysdep.h"
|
---|
| 8 | #include PIAPP_H
|
---|
| 9 | #include PIWIN_H
|
---|
| 10 | #include PIMENU_H
|
---|
| 11 | #include PISTDWDG_H
|
---|
| 12 | #include PIBWDG_H
|
---|
| 13 | #include "piscdrawwdg.h"
|
---|
| 14 | #include "pievthandler.h"
|
---|
| 15 | #include "parradapter.h"
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | /* Exemple d'utilisation PIBaseWdg - Creation d'une nouvelle composante graphique */
|
---|
| 19 |
|
---|
| 20 | // ---- Declaration de la classe ExBWdg --------
|
---|
| 21 | class ExBWdg : public PIBaseWdg
|
---|
| 22 | {
|
---|
| 23 | public:
|
---|
| 24 | // Les methodes ...
|
---|
| 25 |
|
---|
| 26 | ExBWdg(PIContainerGen *par, char *nom,
|
---|
| 27 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 28 | virtual ~ExBWdg();
|
---|
| 29 |
|
---|
| 30 | // Traitement des evenements
|
---|
| 31 | // virtual void Resize();
|
---|
| 32 | virtual void Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
|
---|
| 33 |
|
---|
| 34 | virtual void But1Press(int x, int y);
|
---|
| 35 | virtual void But1Release(int x, int y);
|
---|
| 36 | virtual void But2Press(int x, int y);
|
---|
| 37 | virtual void But2Release(int x, int y);
|
---|
| 38 | virtual void But3Press(int x, int y);
|
---|
| 39 | virtual void But3Release(int x, int y);
|
---|
| 40 | virtual void Keyboard(int key, PIKeyModifier kmod);
|
---|
| 41 |
|
---|
| 42 | protected:
|
---|
| 43 | int mfnt, mmrk;
|
---|
| 44 | int nc;
|
---|
| 45 | char str[32];
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | /* ........................................................... */
|
---|
| 50 | /* Classe ExBWdg (Implementation des methodes) */
|
---|
| 51 | /* ........................................................... */
|
---|
| 52 |
|
---|
| 53 | /* --Methode-- */
|
---|
| 54 | ExBWdg::ExBWdg(PIContainerGen *par, char *nom,
|
---|
| 55 | int sx, int sy, int px, int py)
|
---|
| 56 | : PIBaseWdg(par, nom, sx, sy, px, py)
|
---|
| 57 |
|
---|
| 58 | {
|
---|
| 59 | mmrk = mfnt = nc = 0;
|
---|
| 60 | strcpy(str, "Hello !");
|
---|
| 61 | for(int i=strlen(str); i<20; i++) str[i] = ' ';
|
---|
| 62 | str[20] = '\0';
|
---|
| 63 |
|
---|
| 64 | ActivateKeyboard();
|
---|
| 65 | ActivateButton(1);
|
---|
| 66 | ActivateButton(2);
|
---|
| 67 | ActivateButton(3);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | /* --Methode-- */
|
---|
| 71 | ExBWdg::~ExBWdg()
|
---|
| 72 | {
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /* --Methode--
|
---|
| 76 | void ExBWdg::Resize()
|
---|
| 77 | {
|
---|
| 78 | }
|
---|
| 79 | */
|
---|
| 80 |
|
---|
| 81 | /* --Methode-- */
|
---|
| 82 | void ExBWdg::Draw(PIGraphicGen* g, int /*x0*/, int /*y0*/, int /*dx*/, int /*dy*/)
|
---|
| 83 | {
|
---|
| 84 | PIFontAtt att[3] = { PI_RomanFont, PI_BoldFont, PI_ItalicFont};
|
---|
[403] | 85 | PIMarker pmk[11] = { PI_DotMarker , PI_PlusMarker, PI_CrossMarker,
|
---|
[181] | 86 | PI_CircleMarker, PI_FCircleMarker,
|
---|
| 87 | PI_BoxMarker, PI_FBoxMarker,
|
---|
[403] | 88 | PI_TriangleMarker, PI_FTriangleMarker,
|
---|
| 89 | PI_StarMarker, PI_FStarMarker };
|
---|
[181] | 90 | EraseWindow();
|
---|
| 91 | g->SelFont(PI_NormalSizeFont, att[mfnt]);
|
---|
| 92 | g->SelMarker(8, pmk[mmrk]);
|
---|
| 93 |
|
---|
| 94 | g->SelLine(PI_NormalLine);
|
---|
| 95 | g->DrawBox(10,10, XSize()-20, YSize()-20);
|
---|
| 96 |
|
---|
| 97 | g->SelLine(PI_ThinLine);
|
---|
| 98 | g->DrawFBox(20, 20, 20, 20);
|
---|
| 99 | g->DrawCircle(30, 30, 15);
|
---|
| 100 |
|
---|
| 101 | g->SelForeground(PI_Red);
|
---|
| 102 | g->DrawFCircle(70, 30, 15);
|
---|
| 103 |
|
---|
| 104 | g->SelForeground(PI_Yellow);
|
---|
| 105 | g->DrawFBox(10, 60, 120, 20);
|
---|
| 106 |
|
---|
[382] | 107 | PIFont f0;
|
---|
| 108 | g->SelFont(f0);
|
---|
[181] | 109 | g->SelForeground(PI_Black);
|
---|
| 110 | g->DrawString(20, 110, str);
|
---|
[382] | 111 | PIFont f(PI_TimesFont);
|
---|
| 112 | g->SelFont(f);
|
---|
| 113 | g->DrawString(20, 130, "Times-Font");
|
---|
| 114 | PIFont f2(14,PI_CourierFont,PI_BoldFont);
|
---|
| 115 | g->SelFont(f2);
|
---|
[403] | 116 | g->DrawString(20, 150, "Courier-Font-Bold");
|
---|
[382] | 117 | PIFont f3(14,PI_TimesFont,PI_BoldFont);
|
---|
| 118 | g->SelFont(f3);
|
---|
[402] | 119 | g->DrawString(20, 170, "Times-Font-Bold");
|
---|
[382] | 120 | PIFont f4(14,PI_HelveticaFont,PI_BoldFont);
|
---|
| 121 | g->SelFont(f4);
|
---|
[403] | 122 | g->DrawString(20, 190, "Helvetica-Font-Bold");
|
---|
| 123 | PIFont f5(14,PI_SymbolFont);
|
---|
[382] | 124 | g->SelFont(f5);
|
---|
| 125 | g->DrawString(20, 210, "Symbol-Font");
|
---|
[402] | 126 | g->SelFont(f0);
|
---|
[181] | 127 |
|
---|
[382] | 128 |
|
---|
[181] | 129 | g->SelLine(PI_ThinLine);
|
---|
| 130 | g->DrawLine(20, 140, 50, 130);
|
---|
| 131 | g->SelLine(PI_NormalLine);
|
---|
| 132 | g->DrawLine(50, 140, 80, 130);
|
---|
| 133 | g->SelLine(PI_ThickLine);
|
---|
| 134 | g->DrawLine(80, 140, 110, 130);
|
---|
| 135 |
|
---|
| 136 | g->SelForeground(PI_Magenta);
|
---|
| 137 | g->DrawFCircle(120, 30, 15);
|
---|
| 138 | g->SelForeground(PI_Grey);
|
---|
| 139 | g->DrawFCircle(120, 60, 15);
|
---|
| 140 |
|
---|
[382] | 141 |
|
---|
| 142 |
|
---|
| 143 |
|
---|
[403] | 144 | PIGrCoord x[5] = { 150, 165, 180, 195, 210 };
|
---|
| 145 | PIGrCoord y[5] = { 50, 50, 50, 50, 50 };
|
---|
[181] | 146 |
|
---|
| 147 | g->SelForeground(PI_Black);
|
---|
| 148 | g->DrawMarkers(x, y, 5);
|
---|
| 149 | return;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | static char strbuff[128];
|
---|
| 154 | /* --Methode-- */
|
---|
| 155 | void ExBWdg::But1Press(int x, int y)
|
---|
| 156 | {
|
---|
| 157 | SelPointerShape(PI_CrossPointer);
|
---|
| 158 | sprintf(strbuff,"Pos X= %d Y= %d", x, y);
|
---|
| 159 | mWGrC->SelFont(PI_NormalSizeFont, PI_BoldFont);
|
---|
| 160 | mWGrC->DrawString(x+10, y, strbuff);
|
---|
| 161 | Send(Msg(), PIMsg_Active);
|
---|
| 162 | return;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | /* --Methode-- */
|
---|
| 166 | void ExBWdg::But1Release(int x, int y)
|
---|
| 167 | {
|
---|
| 168 | SelPointerShape(PI_ArrowPointer);
|
---|
| 169 | Refresh();
|
---|
| 170 | return;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /* --Methode-- */
|
---|
| 174 | void ExBWdg::But2Press(int x, int y)
|
---|
| 175 | {
|
---|
| 176 | if (++mfnt > 2) mfnt = 0;
|
---|
[403] | 177 | if (++mmrk > 10) mmrk = 0;
|
---|
[181] | 178 | return;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | /* --Methode-- */
|
---|
| 182 | void ExBWdg::But2Release(int x, int y)
|
---|
| 183 | {
|
---|
| 184 | Refresh();
|
---|
| 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | /* --Methode-- */
|
---|
| 189 | void ExBWdg::But3Press(int x, int y)
|
---|
| 190 | {
|
---|
| 191 | SelPointerShape(PI_HandPointer);
|
---|
| 192 | mWGrC->SelForeground(PI_Blue);
|
---|
| 193 | mWGrC->DrawFBox(XSize()/3, YSize()/3, XSize()/8, YSize()/8);
|
---|
| 194 | return;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | /* --Methode-- */
|
---|
| 198 | void ExBWdg::But3Release(int x, int y)
|
---|
| 199 | {
|
---|
| 200 | mWGrC->SelForeground(PI_White);
|
---|
| 201 | mWGrC->DrawFBox(XSize()/3, YSize()/3, XSize()/8, YSize()/8);
|
---|
| 202 | mWGrC->SelForeground(PI_Black);
|
---|
| 203 | SelPointerShape(PI_ArrowPointer);
|
---|
| 204 | return;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /* --Methode-- */
|
---|
| 208 | void ExBWdg::Keyboard(int key, PIKeyModifier kmod)
|
---|
| 209 | {
|
---|
| 210 | str[nc] = key; str[nc+1] = '\0';
|
---|
| 211 | if (++nc > 30) nc = 0;
|
---|
| 212 | char buf[16];
|
---|
| 213 |
|
---|
| 214 | if (key == PIK_Return) { Refresh(); nc = 0; return; }
|
---|
| 215 | mWGrC->SelFont(PI_NormalSizeFont, PI_BoldFont);
|
---|
| 216 | sprintf(buf," %c (%3d) ", (char) key, key, (int)kmod);
|
---|
| 217 | mWGrC->DrawOpaqueString(20, 75, buf);
|
---|
| 218 |
|
---|
| 219 | if ( (kmod == PIKM_Alt) && (key == 'c') ) {
|
---|
| 220 | printf("ExBWdg::Keyboard: Test-Copy ... \n");
|
---|
| 221 | ClaimSelection();
|
---|
| 222 | }
|
---|
| 223 | if ( (kmod == PIKM_Alt) && (key == 'v') ) {
|
---|
| 224 | printf("ExBWdg::Keyboard: Test-Paste ... \n");
|
---|
| 225 | RequestSelection();
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | return;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | // ----- Exemple d'une classe heritant de PIScDrawWdg ----
|
---|
| 232 | /* ........................................................... */
|
---|
| 233 | /* Classe ScSample */
|
---|
| 234 | /* ........................................................... */
|
---|
| 235 |
|
---|
| 236 | class ScSample : public PIScDrawWdg {
|
---|
| 237 | public:
|
---|
| 238 | ScSample(PIContainerGen *par, char *nom,
|
---|
| 239 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 240 | virtual ~ScSample();
|
---|
| 241 | };
|
---|
| 242 |
|
---|
| 243 | static double fpol(double x) {return (0.3*x*x*x-x*x+7.);}
|
---|
| 244 | static float xpts[10] = {-2.4, -2 , -1., 1., 1.7, 2.2, 3., 3.75, 4.3, 4.8};
|
---|
| 245 | static float ypts[10] = {-5 , -1.5, 2.5, 5., 8.0, 12., 9., 6.00, 2.2, -3.0};
|
---|
| 246 |
|
---|
| 247 | ScSample::ScSample(PIContainerGen *par, char *nom,
|
---|
| 248 | int sx, int sy, int px, int py)
|
---|
| 249 | :PIScDrawWdg(par, nom, sx, sy, px, py)
|
---|
| 250 |
|
---|
| 251 | {
|
---|
| 252 | // Definition des limites
|
---|
| 253 | SetLimits(-3,5,-10,15);
|
---|
| 254 |
|
---|
| 255 | // Creation et ajout d'un drawer de fonctions
|
---|
| 256 | PIFuncDrawer* mfd = new PIFuncDrawer(fpol);
|
---|
| 257 | mfd->SetColAtt(PI_Blue);
|
---|
| 258 | mfd->SetLineAtt(PI_NormalLine);
|
---|
| 259 | AddScDrawer(mfd,true);
|
---|
| 260 |
|
---|
| 261 | // Creation et ajout d'un drawer de points
|
---|
| 262 | PIYfXDrawer* mxyd = new PIYfXDrawer(new P1DAdapter<float>(xpts, 10, false),
|
---|
| 263 | new P1DAdapter<float>(ypts, 10, false), true);
|
---|
| 264 | mxyd->SetColAtt(PI_Magenta);
|
---|
| 265 | mxyd->SetMarkerAtt(7, PI_FBoxMarker);
|
---|
| 266 | AddScDrawer(mxyd, true);
|
---|
| 267 |
|
---|
| 268 | // Ajout de texte
|
---|
| 269 | BaseDrawer()->SetFontAtt(PI_NormalSizeFont, PI_BoldFont);
|
---|
| 270 | BaseDrawer()->ElAddText(-2.8, 12., "---- ScSample ----", PI_Red);
|
---|
| 271 | BaseDrawer()->ElAddText(-2.8, 10., "f(x)=0.3*x^3-x^2+7.", PI_Red);
|
---|
| 272 |
|
---|
| 273 | SetAxesFlags(kAxesDflt);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | ScSample::~ScSample()
|
---|
| 277 | {
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | // ----------- Une classe EventHandler ----------
|
---|
| 281 | class MyEvHandler : public PIEventHandler {
|
---|
| 282 | public :
|
---|
| 283 | MyEvHandler();
|
---|
| 284 | ~MyEvHandler();
|
---|
| 285 | virtual void Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
|
---|
| 286 | virtual void ProcessEvent();
|
---|
| 287 | inline bool GrabOK() { return(grabok); }
|
---|
| 288 |
|
---|
| 289 | protected :
|
---|
| 290 | PIScreenBuffer* mscb;
|
---|
| 291 | int mposx, mposy;
|
---|
| 292 | int mposx2, mposy2;
|
---|
| 293 | int msx, msy;
|
---|
| 294 | bool grabok;
|
---|
| 295 | };
|
---|
| 296 |
|
---|
| 297 | /* --Methode-- */
|
---|
| 298 | MyEvHandler::MyEvHandler()
|
---|
| 299 | : PIEventHandler()
|
---|
| 300 | {
|
---|
| 301 | mscb = new PIScreenBuffer(100, 100);
|
---|
| 302 | msx = 100; msy = 100;
|
---|
| 303 | mposx = mposy = 0;
|
---|
| 304 | mposx2 = mposy2 = 0;
|
---|
| 305 | grabok = false;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | /* --Methode-- */
|
---|
| 309 | MyEvHandler::~MyEvHandler()
|
---|
| 310 | {
|
---|
| 311 | delete mscb;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | /* --Methode-- */
|
---|
| 315 | void MyEvHandler::Draw(PIGraphic* g, int, int, int, int)
|
---|
| 316 | {
|
---|
| 317 | if (GrabOK()) {
|
---|
| 318 | printf("MyEvHandler::Draw() : Copying from ScreenBuffer to wdg (%lx) \n", (unsigned long)CurrentWdg());
|
---|
| 319 | mscb->CopyToWdg(CurrentWdg(), 0, 0, msx, msy, CurrentWdg()->XSize()/2, CurrentWdg()->YSize()/2);
|
---|
| 320 | }
|
---|
| 321 | else printf("MyEvHandler::Draw() : Grab first from source \n");
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | /* --Methode-- */
|
---|
| 325 | void MyEvHandler::ProcessEvent()
|
---|
| 326 | {
|
---|
| 327 | printf("MyEvHandler::ProcessEvent() \n");
|
---|
| 328 | switch (EventType()) {
|
---|
| 329 |
|
---|
| 330 | case PIEvent_But3Press :
|
---|
| 331 | mposx = GetPosX();
|
---|
| 332 | mposy = GetPosY();
|
---|
| 333 | break;
|
---|
| 334 |
|
---|
| 335 | case PIEvent_But3Release :
|
---|
| 336 | mposx2 = GetPosX();
|
---|
| 337 | mposy2 = GetPosY();
|
---|
| 338 | printf("MyEvHandler::ProcessEvent(): Rectangle(%d,%d - %d,%d) \n", mposx, mposy, mposx2, mposy2);
|
---|
| 339 | // ((PIBaseWdg*)CurrentWdg())->WindowGraphic()->DrawBox(mposx, mposy, (mposx2-mposx), (mposy2-mposy));
|
---|
| 340 | break;
|
---|
| 341 |
|
---|
| 342 | case PIEvent_Keyboard :
|
---|
| 343 | if ((GetKeyMod() == PIKM_Alt) && ((GetKey() == 'G') || (GetKey() == 'g')) ) {
|
---|
| 344 | printf("MyEvHandler::ProcessEvent(): Grabbing(%dx%d) from Wdg(%lx)@(%d,%d) \n",
|
---|
| 345 | msx, msy, (unsigned long)CurrentWdg(), mposx, mposy);
|
---|
| 346 | mscb->CopyFromWdg(CurrentWdg(), mposx, mposy, msx, msy, 0, 0);
|
---|
| 347 | grabok = true;
|
---|
| 348 | }
|
---|
| 349 | break;
|
---|
| 350 |
|
---|
| 351 | default :
|
---|
| 352 | printf("MyEvHandler::ProcessEvent(): Unexpected Event (Type = %d) received \n", (int)EventType());
|
---|
| 353 | break;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | return;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | /* ........................................................... */
|
---|
| 360 | /* Classe PITApp */
|
---|
| 361 | /* ........................................................... */
|
---|
| 362 | class PITApp : public PIApplication {
|
---|
| 363 | public:
|
---|
| 364 | PITApp(int narg=0, char* arg[]=NULL);
|
---|
| 365 | ~PITApp();
|
---|
| 366 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
| 367 | private :
|
---|
| 368 | PIMenu* m[2];
|
---|
| 369 | PIText* txt;
|
---|
| 370 | MyEvHandler* evh;
|
---|
| 371 | PIWindow* mcurwin;
|
---|
| 372 | PIWdg* mdrhw;
|
---|
| 373 | PIWdg* mevhw;
|
---|
| 374 | PIWdg* mcurw;
|
---|
| 375 | };
|
---|
| 376 |
|
---|
| 377 |
|
---|
| 378 | /* --Methode-- */
|
---|
| 379 | PITApp::PITApp(int narg, char* arg[])
|
---|
| 380 | : PIApplication(300, 100, narg, arg)
|
---|
| 381 | {
|
---|
| 382 |
|
---|
| 383 | // Menus, les numeros ds AppendItem sont les numeros de messages
|
---|
| 384 | // qui seront passes a Process() et permettent d'identifier l'action
|
---|
| 385 |
|
---|
| 386 | // Creation du premier menu
|
---|
| 387 |
|
---|
| 388 | m[0] = new PIMenu(Menubar(),"Actions");
|
---|
| 389 | m[0]->AppendItem("Info", 10101);
|
---|
| 390 | m[0]->AppendItem("New ExBwdg", 10102);
|
---|
| 391 | m[0]->AppendItem("New ScSample", 10103);
|
---|
[382] | 392 | m[0]->AppendItem("->eps", 10111);
|
---|
[181] | 393 | m[0]->AppendItem("Exit", 10105);
|
---|
| 394 | // On accroche le menu au Menubar
|
---|
| 395 | AppendMenu(m[0]);
|
---|
| 396 |
|
---|
| 397 | m[1] = new PIMenu(Menubar(),"Edit");
|
---|
| 398 | m[1]->AppendItem("Copy", 10201);
|
---|
| 399 | m[1]->AppendItem("Paste", 10202);
|
---|
| 400 | // On accroche le menu au Menubar
|
---|
| 401 | AppendMenu(m[1]);
|
---|
| 402 |
|
---|
| 403 | // Creation d' zone texte multiligne
|
---|
[323] | 404 | txt = new PIText(MainWin(), "mltext", true, true, 290, 90, 5, 5);
|
---|
[181] | 405 | txt->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
[323] | 406 | // txt->SetMutiLineMode(true);
|
---|
[181] | 407 | txt->SetTextEditable(false);
|
---|
| 408 | txt->SetText("");
|
---|
| 409 |
|
---|
| 410 | evh = new MyEvHandler;
|
---|
| 411 | mcurwin = NULL;
|
---|
| 412 | mcurw = NULL;
|
---|
| 413 | mdrhw = NULL;
|
---|
| 414 | mdrhw = NULL;
|
---|
| 415 | SetReady();
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | /* --Methode-- */
|
---|
| 419 | PITApp::~PITApp()
|
---|
| 420 | {
|
---|
| 421 | delete m[0]; delete m[1]; delete txt;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
[382] | 424 | static int numpsf = 0;
|
---|
[181] | 425 | static int nbwin = 0;
|
---|
| 426 | /* --Methode-- */
|
---|
| 427 | void PITApp::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
|
---|
| 428 | {
|
---|
| 429 |
|
---|
| 430 | char strg[256];
|
---|
| 431 |
|
---|
| 432 | // Gestion des actions en fonctions des messages
|
---|
| 433 |
|
---|
| 434 | if ( ( ModMsg(msg) == PIMsg_Active) || (ModMsg(msg) == PIMsg_Close) ) {
|
---|
| 435 | PIWdg *sndw;
|
---|
| 436 | sndw = (PIWdg *)sender;
|
---|
| 437 | if (sndw->kind() == PIWindow::ClassId) {
|
---|
| 438 | if (ModMsg(msg) == PIMsg_Close) {
|
---|
| 439 | // printf("PITApp::Process()/Debug : Closing Window %lx \n", (long)sender);
|
---|
| 440 | if (mcurwin->UserData() == mcurw) mcurw = NULL;
|
---|
| 441 | if (mcurwin->UserData() == mdrhw) mdrhw = NULL;
|
---|
| 442 | if (mcurwin->UserData() == mevhw) mevhw = NULL;
|
---|
| 443 | delete (PIWindow *)sender;
|
---|
| 444 | mcurwin = NULL;
|
---|
| 445 | }
|
---|
| 446 | else mcurwin = (PIWindow *)sender;
|
---|
| 447 | }
|
---|
| 448 | else if ( ModMsg(msg) == PIMsg_Active) mcurw = sndw;
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | else switch(UserMsg(msg)) {
|
---|
| 452 |
|
---|
| 453 | case 10101: // Info
|
---|
| 454 | txt->SetText("pit1: PITApp \n PIBaseWdg - PIScDrawWdg test \n ExBWdg (:PIBaseWdg) Creation \n ScSample (:PIScDrawWdg) creation");
|
---|
| 455 | break;
|
---|
| 456 |
|
---|
| 457 | case 10102: // Creation d'un ExBWdg
|
---|
| 458 | {
|
---|
| 459 | nbwin++;
|
---|
| 460 | sprintf(strg, "Creation ExBwdg \n Fenetre No %d \n Test keyborard, button 1/2/3", nbwin);
|
---|
| 461 | txt->SetText(strg);
|
---|
| 462 | sprintf(strg,"Window %d - ExBwdg", nbwin);
|
---|
| 463 | PIWindow* wp = new PIWindow(this, strg, PIWK_normal, 250, 250, 150, 150);
|
---|
| 464 | wp->SetAutoDelChilds(true);
|
---|
| 465 | ExBWdg* exb = new ExBWdg(wp, "bwdg", 250, 250, 0, 0);
|
---|
| 466 | exb->SetBinding(PIBK_fixed,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
| 467 | wp->SetUserData(exb);
|
---|
| 468 | wp->Show();
|
---|
| 469 | }
|
---|
| 470 | break;
|
---|
| 471 |
|
---|
| 472 | case 10103: // Creation d'un ScSample
|
---|
| 473 | {
|
---|
| 474 | nbwin++;
|
---|
| 475 | sprintf(strg, "Creation Scsample \n Fenetre No %d \n Button 1 -> mouse position \n Button 2 -> Zoom \n keyboard <Alt>O <Alt>V", nbwin);
|
---|
| 476 | txt->SetText(strg);
|
---|
| 477 | sprintf(strg,"Window %d - ScSample", nbwin);
|
---|
| 478 | PIWindow* wp = new PIWindow(this, strg, PIWK_normal, 400, 400, 200, 200);
|
---|
| 479 | wp->SetAutoDelChilds(true);
|
---|
| 480 | ScSample* sc = new ScSample(wp, "scsample", 400, 400, 0, 0);
|
---|
| 481 | sc->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
| 482 | wp->SetUserData(sc);
|
---|
| 483 | wp->Show();
|
---|
| 484 | }
|
---|
| 485 | break;
|
---|
| 486 |
|
---|
[382] | 487 | case 10111: // -> eps
|
---|
| 488 | if (mcurwin) {
|
---|
| 489 | char buff[64];
|
---|
| 490 | sprintf(buff, "pit_%d.eps", numpsf); numpsf++;
|
---|
| 491 | printf("Creating EPS File %s (Encapsulated PostScript) \n", buff);
|
---|
| 492 | PSFile *mps;
|
---|
| 493 | mps = new PSFile(buff);
|
---|
| 494 | mcurwin->PSPrint(mps,0,0);
|
---|
| 495 | delete mps;
|
---|
| 496 | }
|
---|
| 497 | break;
|
---|
[181] | 498 | case 10105: // Sortie d'application
|
---|
| 499 | Stop();
|
---|
| 500 | break;
|
---|
| 501 |
|
---|
| 502 |
|
---|
| 503 | case 10201: // 2 eme menu Copy
|
---|
| 504 | if (mcurw == NULL) { printf("PITApp::Process()/Warning : Select a window for copy \n");
|
---|
| 505 | sprintf(strg, "Warning : Select a window for copy");
|
---|
| 506 | txt->SetText(strg);
|
---|
| 507 | }
|
---|
| 508 | else {
|
---|
| 509 | printf("Adding EventHandler to Wdg %lx", (long)mcurw);
|
---|
| 510 | sprintf(strg, "Adding EventHandler to Wdg %lx \n, Use button 3 to select copy zone \n, <Alt>G to Get copy",
|
---|
| 511 | (long)mcurw);
|
---|
| 512 | txt->SetText(strg);
|
---|
| 513 | if (mevhw != NULL) mevhw->RemoveEventHandler(evh); mevhw = NULL;
|
---|
| 514 | mcurw->AddEventHandler(evh, PIEvent_But3Press | PIEvent_But3Release | PIEvent_Keyboard, false);
|
---|
| 515 | }
|
---|
| 516 | break;
|
---|
| 517 |
|
---|
| 518 | case 10202: // 2eme Menu - Paste
|
---|
| 519 | if (mcurw == NULL) { printf("PITApp::Process()/Warning : Select a window for paste \n");
|
---|
| 520 | sprintf(strg, "Warning : Select a window for paste");
|
---|
| 521 | txt->SetText(strg);
|
---|
| 522 | }
|
---|
| 523 | else {
|
---|
| 524 | printf("Adding DrawHandler to Wdg %lx \n - Refreshing Wdg", (long)mcurw);
|
---|
| 525 | sprintf(strg, "Adding DrawHandler to Wdg %lx \n - Refreshing Wdg", (long)mcurw);
|
---|
| 526 | txt->SetText(strg);
|
---|
| 527 | mcurw->AddDrawHandler(evh, false);
|
---|
| 528 | mdrhw = mcurw;
|
---|
| 529 | ((PIBaseWdg*)mcurw)->Refresh();
|
---|
| 530 | }
|
---|
| 531 | break;
|
---|
| 532 |
|
---|
| 533 | default :
|
---|
| 534 | // printf("PITApp::Process() Msg= %d (%d - %d)??? \n",
|
---|
| 535 | // (int)msg, (int)UserMsg(msg),(int)ModMsg(msg));
|
---|
| 536 | break;
|
---|
| 537 |
|
---|
| 538 | }
|
---|
| 539 | return;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 |
|
---|
| 543 | // ................................................................
|
---|
| 544 | // programme principal
|
---|
| 545 | // ................................................................
|
---|
| 546 |
|
---|
| 547 | int main(int narg, char *arg[])
|
---|
| 548 | {
|
---|
| 549 | if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
|
---|
| 550 | printf("pit1 : ExBWdg (:PIBaseWdg) / ScSample (:PIScDrawWdg) test \n");
|
---|
| 551 | printf(" Usage : pit1 [Xt options] \n");
|
---|
| 552 | }
|
---|
| 553 | // Creation de l'objet application et appel de Run()
|
---|
| 554 | PITApp* app = new PITApp(narg, arg);
|
---|
| 555 | // puts("appel de Application.Run() ... ");
|
---|
| 556 | app->Run();
|
---|
| 557 |
|
---|
| 558 | delete app;
|
---|
| 559 | exit(0);
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 |
|
---|