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