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