[2] | 1 | #include <stdio.h>
|
---|
[18] | 2 | #include <X11/cursorfont.h>
|
---|
[1074] | 3 | #include <X11/IntrinsicP.h>
|
---|
[1263] | 4 | #include <X11/Shell.h>
|
---|
| 5 | #include <X11/StringDefs.h>
|
---|
| 6 | #include <Xm/Xm.h>
|
---|
[2615] | 7 | #include "sopnamsp.h"
|
---|
[2] | 8 | #include "piapplx.h"
|
---|
| 9 | #include "picontainerx.h"
|
---|
| 10 |
|
---|
[365] | 11 | // $CHECK$ - Reza Aout 99
|
---|
| 12 | // Il y a un probleme sur la gestion de la taille de la fenetre principale
|
---|
| 13 | // SetBinding(elastic) ne marche correctement pas sur la fenetre principale
|
---|
| 14 | // et Des SetSize intempestive peuvent generer des comportements bizarres !
|
---|
[2] | 15 |
|
---|
[78] | 16 | // Pour rediriger stdout
|
---|
| 17 | #include <unistd.h>
|
---|
| 18 | #include <fcntl.h>
|
---|
[2] | 19 |
|
---|
[2322] | 20 | #include <iostream>
|
---|
[78] | 21 |
|
---|
[135] | 22 |
|
---|
[78] | 23 | // #define DEBUG_APPLX
|
---|
| 24 |
|
---|
[18] | 25 | static Cursor a_curs[3];
|
---|
| 26 | static bool a_fgcur=false;
|
---|
| 27 |
|
---|
[60] | 28 | // Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
|
---|
| 29 | void SetTopWdgForMenuX(SysDWdg mtw);
|
---|
| 30 |
|
---|
[111] | 31 | static PIApplication* cur_piapp = NULL;
|
---|
| 32 | PIApplication* PIApplicationGetApp() { return cur_piapp; }
|
---|
| 33 |
|
---|
[126] | 34 |
|
---|
[132] | 35 | // Classe de container special pour top-container de Application X
|
---|
[126] | 36 |
|
---|
[132] | 37 | class PITopContAppX : public PIContainer {
|
---|
| 38 | public :
|
---|
[457] | 39 | PITopContAppX(PIContainer *par, char *nom, PIWdg* topw,
|
---|
[132] | 40 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 41 | virtual ~PITopContAppX();
|
---|
| 42 |
|
---|
| 43 | virtual void SetSize(int sx, int sy);
|
---|
| 44 | virtual void SetPos(int px, int py);
|
---|
[457] | 45 |
|
---|
| 46 | PIWdg* mTopWdg;
|
---|
[132] | 47 | };
|
---|
| 48 |
|
---|
[1074] | 49 |
|
---|
[2] | 50 | /* --Methode-- */
|
---|
[457] | 51 | PITopContAppX::PITopContAppX(PIContainer *par, char *nom, PIWdg* topw, int sx, int sy, int px, int py)
|
---|
[365] | 52 | : PIContainer(par, nom, (sx>10)?sx:10, (sy>10)?sy:10, px, py)
|
---|
[132] | 53 | {
|
---|
[457] | 54 | mTopWdg = topw;
|
---|
[365] | 55 | SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
|
---|
[132] | 56 | }
|
---|
| 57 |
|
---|
| 58 | /* --Methode-- */
|
---|
| 59 | PITopContAppX::~PITopContAppX()
|
---|
| 60 | {
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /* --Methode-- */
|
---|
| 64 | void PITopContAppX::SetSize(int sx, int sy)
|
---|
| 65 | {
|
---|
[365] | 66 | if ((sx <10) || (sy < 10) ) return;
|
---|
[1074] | 67 |
|
---|
| 68 | int px = XPos();
|
---|
| 69 | int py = YPos();
|
---|
[1133] | 70 | // Probleme sur Sun - Reza 10/99 , REGLE 08/2000
|
---|
| 71 |
|
---|
[1074] | 72 | mTopWdg->SetSize(sx+px, sy+py);
|
---|
| 73 |
|
---|
| 74 | XtConfigureWidget(Parent()->XtWdg(), 0, 0, sx+px, sy+py, 0);
|
---|
| 75 | XtConfigureWidget(XtWdg(), px, py, sx, sy, 0);
|
---|
| 76 | // SetPos(px, py);
|
---|
| 77 | // PIContainer::SetSize(sx, sy);
|
---|
[132] | 78 | }
|
---|
| 79 |
|
---|
[365] | 80 |
|
---|
[132] | 81 | /* --Methode-- */
|
---|
| 82 | void PITopContAppX::SetPos(int px, int py)
|
---|
| 83 | {
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[1263] | 86 | // ---------------------------------------------
|
---|
| 87 | // Fonction pour gestion des close-window
|
---|
| 88 |
|
---|
| 89 | /* Nouvelle-Fonction */
|
---|
| 90 | static int fgactl = 0;
|
---|
| 91 |
|
---|
| 92 | static void CloseWindow (Widget w, XEvent*, String*,Cardinal*)
|
---|
| 93 | {
|
---|
| 94 | XtCallCallbacks(w, XtNpopdownCallback, NULL);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /* Nouvelle-Fonction */
|
---|
| 98 | static void popdwn_cb_app(Widget /*w*/, XtPointer *usd, XtPointer * )
|
---|
| 99 | {
|
---|
| 100 | PIApplicationX * app = (PIApplicationX *) usd;
|
---|
| 101 | app->SendSelf(0,PIMsg_Close, NULL) ;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 |
|
---|
[132] | 105 | /* --Methode-- */
|
---|
[2] | 106 | PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
|
---|
| 107 | : PIApplicationGen()
|
---|
| 108 | {
|
---|
| 109 | int sxt, syt;
|
---|
| 110 |
|
---|
| 111 | #ifdef DEBUG_APPLX
|
---|
| 112 | puts("PIApplicationX::PIApplicationX()_info : App creation");
|
---|
| 113 | #endif
|
---|
| 114 | mStop = true;
|
---|
[365] | 115 |
|
---|
[3215] | 116 | puts("PIApplicationX::PIApplicationX()_info : Appel topwdg = new PIWdgX(narg, arg);");
|
---|
[365] | 117 |
|
---|
[2] | 118 | topwdg = new PIWdgX(narg, arg);
|
---|
[3215] | 119 | puts("PIApplicationX::PIApplicationX()_info : topwdg OK ");
|
---|
[2] | 120 |
|
---|
[365] | 121 | int msx,msy;
|
---|
[1592] | 122 | PrefCompSize(msx, msy);
|
---|
[365] | 123 | msy+=5;
|
---|
| 124 | topwdg->SetSize(sx, sy+msy);
|
---|
[3215] | 125 | printf("PIApplicationX-DBG:: Size=%d %d \n", topwdg->XSize(), topwdg->YSize());
|
---|
[365] | 126 |
|
---|
[2] | 127 | intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
|
---|
[365] | 128 | sx, sy+msy, 0, 0);
|
---|
[60] | 129 | // Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
|
---|
| 130 | SetTopWdgForMenuX(intcont->XtWdg());
|
---|
| 131 |
|
---|
[2] | 132 | menubar = new PIMenubar(this, "DefMenubar");
|
---|
[23] | 133 | Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
|
---|
[2] | 134 | sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
|
---|
[365] | 135 | syt = ( sy > 10 ) ? sy : 10;
|
---|
| 136 | // syt += Menubar()->YSize();
|
---|
| 137 | // syt += msy;
|
---|
| 138 | // topwdg->SetSize(sxt, syt);
|
---|
| 139 | // MBCont()->SetSize(sxt, syt);
|
---|
[132] | 140 | if (sx < sxt) sx = sxt;
|
---|
| 141 | if (sy < 10) sy = 10;
|
---|
[457] | 142 | topcont = new PITopContAppX(MBCont(), "TopLevelCont", topwdg,
|
---|
[132] | 143 | sx, sy, 0, msy);
|
---|
[163] | 144 | MBCont()->Show();
|
---|
[3215] | 145 | printf("PIApplicationX-DBG2:: MBContSize=%d %d \n", MBCont()->XSize(), MBCont()->YSize());
|
---|
[2] | 146 |
|
---|
[1074] | 147 |
|
---|
[365] | 148 | topcont->Show();
|
---|
[18] | 149 |
|
---|
[365] | 150 |
|
---|
[18] | 151 | if (!a_fgcur)
|
---|
| 152 | {
|
---|
| 153 | Display *mdsp;
|
---|
| 154 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 155 | a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
|
---|
| 156 | a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
|
---|
| 157 | a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[365] | 160 | topwdg->Manage();
|
---|
[1263] | 161 |
|
---|
| 162 | // ------------------------------------------------------
|
---|
| 163 | // Pour la gestion des close window des Window manager
|
---|
| 164 |
|
---|
| 165 | if (fgactl == 0) {
|
---|
| 166 | XtActionsRec desact = {(char *)"CloseWindow" ,CloseWindow};
|
---|
| 167 | int szx, szy, szf;
|
---|
| 168 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 169 | XtAppAddActions(*appctx, &desact, 1);
|
---|
| 170 | Display *mdsp;
|
---|
| 171 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 172 | Atom wmd;
|
---|
| 173 | wmd = XInternAtom(mdsp, "WM_DELETE_WINDOW",False);
|
---|
| 174 | XSetWMProtocols(mdsp, XtWindow(topwdg->XtWdg()), &wmd, 1);
|
---|
| 175 | fgactl = 1;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | XtTranslations trans;
|
---|
| 179 | trans = XtParseTranslationTable("<Message>WM_PROTOCOLS:CloseWindow()");
|
---|
| 180 | XtOverrideTranslations(topwdg->XtWdg() , trans);
|
---|
| 181 | Arg warg[2];
|
---|
| 182 | XtSetArg(warg[0], XmNdeleteResponse, XmDO_NOTHING);
|
---|
| 183 | XtSetValues(topwdg->XtWdg(), warg, 1);
|
---|
| 184 |
|
---|
| 185 | XtAddCallback(topwdg->XtWdg(), XtNpopdownCallback,
|
---|
| 186 | (XtCallbackProc)popdwn_cb_app, (XtPointer)this);
|
---|
| 187 |
|
---|
| 188 | // ------------------------------------------------------
|
---|
| 189 |
|
---|
[111] | 190 | cur_piapp = this;
|
---|
[18] | 191 | mState = -1;
|
---|
| 192 | SetReady();
|
---|
[2] | 193 | }
|
---|
| 194 |
|
---|
| 195 | /* --Methode-- */
|
---|
| 196 | PIApplicationX::~PIApplicationX()
|
---|
| 197 | {
|
---|
| 198 | #ifdef DEBUG_APPLX
|
---|
| 199 | puts("PIApplicationX::~PIApplicationX()_info : App delete");
|
---|
| 200 | #endif
|
---|
[18] | 201 | Display *mdsp;
|
---|
| 202 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[52] | 203 | topwdg->UnManage();
|
---|
[6] | 204 | delete menubar;
|
---|
| 205 | if (topcont != MBCont()) delete topcont;
|
---|
| 206 | delete intcont;
|
---|
[2] | 207 | delete topwdg;
|
---|
[18] | 208 | XtCloseDisplay(mdsp);
|
---|
[111] | 209 | cur_piapp = NULL;
|
---|
[18] | 210 | return;
|
---|
[2] | 211 | }
|
---|
| 212 |
|
---|
| 213 | /* --Methode-- */
|
---|
| 214 | void PIApplicationX::Run()
|
---|
| 215 | {
|
---|
| 216 | XEvent evt;
|
---|
| 217 | #ifdef DEBUG_APPLX
|
---|
| 218 | puts("PIApplicationX::Run()_info : App Run ");
|
---|
| 219 | #endif
|
---|
| 220 |
|
---|
| 221 |
|
---|
[114] | 222 | int szx, szy, szf;
|
---|
| 223 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[90] | 224 |
|
---|
[110] | 225 | // Pour appeler FinishCreate() des objets dans la fenetre principale
|
---|
[365] | 226 | if (mStop) { // C'est la premiere fois
|
---|
[1074] | 227 | topcont->SetSize(topcont->XSize(), topcont->YSize());
|
---|
| 228 | // topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
|
---|
[365] | 229 | MBCont()->FinishCreate();
|
---|
| 230 | }
|
---|
[141] | 231 | else mStop = true; // On rerentre apres un stop
|
---|
[2] | 232 | while (mStop)
|
---|
| 233 | {
|
---|
[90] | 234 | XtAppNextEvent(*appctx, &evt);
|
---|
[2] | 235 | XtDispatchEvent(&evt);
|
---|
| 236 | }
|
---|
| 237 | return;
|
---|
| 238 | }
|
---|
[18] | 239 |
|
---|
| 240 |
|
---|
| 241 | /* --Methode-- */
|
---|
| 242 | void PIApplicationX::SetReady()
|
---|
| 243 | {
|
---|
[138] | 244 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 245 | if (mState != kReadyState)
|
---|
| 246 | {
|
---|
| 247 | mState = kReadyState;
|
---|
[106] | 248 | Menubar()->SetSensitive();
|
---|
[18] | 249 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
|
---|
| 250 | }
|
---|
[138] | 251 | XFlush(mdsp);
|
---|
[18] | 252 | }
|
---|
| 253 |
|
---|
| 254 | /* --Methode-- */
|
---|
| 255 | void PIApplicationX::SetBusy()
|
---|
| 256 | {
|
---|
[138] | 257 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 258 | if (mState != kBusyState)
|
---|
| 259 | {
|
---|
| 260 | mState = kBusyState;
|
---|
[106] | 261 | Menubar()->SetSensitive();
|
---|
[18] | 262 | // if ( XtIsRealized(topwdg->XtWdg()) )
|
---|
| 263 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
|
---|
| 264 | }
|
---|
[138] | 265 | XFlush(mdsp);
|
---|
[18] | 266 | }
|
---|
| 267 |
|
---|
| 268 | /* --Methode-- */
|
---|
| 269 | void PIApplicationX::SetBlocked()
|
---|
| 270 | {
|
---|
[138] | 271 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 272 | if (mState != kBlockedState)
|
---|
| 273 | {
|
---|
| 274 | mState = kBlockedState;
|
---|
[106] | 275 | Menubar()->SetUnSensitive();
|
---|
[18] | 276 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
|
---|
| 277 | }
|
---|
[138] | 278 | XFlush(mdsp);
|
---|
| 279 | return;
|
---|
[18] | 280 | }
|
---|
[75] | 281 |
|
---|
| 282 |
|
---|
| 283 | /* --Methode-- */
|
---|
[1592] | 284 | void PIApplicationX::PrefCompSize(int& szx, int& szy)
|
---|
[75] | 285 | {
|
---|
[114] | 286 | int szf;
|
---|
| 287 | PIXtAppCtx(szx, szy, szf);
|
---|
[90] | 288 | return;
|
---|
[75] | 289 | }
|
---|
| 290 |
|
---|
[92] | 291 | /* --Methode-- */
|
---|
[1592] | 292 | void PIApplicationX::ScreenSize(int& szx, int& szy)
|
---|
[92] | 293 | {
|
---|
| 294 | Display * dsp = PIXDisplay();
|
---|
| 295 | szx = DisplayWidth(dsp, DefaultScreen(dsp));
|
---|
| 296 | szy = DisplayHeight(dsp, DefaultScreen(dsp));
|
---|
| 297 | }
|
---|
[75] | 298 |
|
---|
[1592] | 299 | /* --Methode-- */
|
---|
| 300 | void PIApplicationX::ScreenSizeMM(int& szx, int& szy)
|
---|
| 301 | {
|
---|
| 302 | Display * dsp = PIXDisplay();
|
---|
| 303 | szx = DisplayWidthMM(dsp, DefaultScreen(dsp));
|
---|
| 304 | szy = DisplayHeightMM(dsp, DefaultScreen(dsp));
|
---|
| 305 | }
|
---|
[92] | 306 |
|
---|
[1592] | 307 | /* --Methode-- */
|
---|
| 308 | void PIApplicationX::ScreenResolution(int& resolx, int& resoly)
|
---|
| 309 | {
|
---|
| 310 | Display * dsp = PIXDisplay();
|
---|
| 311 | resolx = (int)((double)DisplayWidth(dsp, DefaultScreen(dsp))*10./
|
---|
| 312 | (double)DisplayWidthMM(dsp, DefaultScreen(dsp)));
|
---|
| 313 | resoly = (int)((double)DisplayHeight(dsp, DefaultScreen(dsp))*10./
|
---|
| 314 | (double)DisplayHeightMM(dsp, DefaultScreen(dsp)));
|
---|
| 315 | }
|
---|
[92] | 316 |
|
---|
[1592] | 317 |
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 |
|
---|
[78] | 321 | /* Call-Back - Fonction privee de ce fichier */
|
---|
[81] | 322 | static void redirectstream_callback(XtPointer, int *, XtInputId*);
|
---|
[78] | 323 |
|
---|
[81] | 324 | static PIConsole* consstream[2] = {NULL, NULL};
|
---|
| 325 | static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
|
---|
| 326 | static int streamno[2] = {0,1};
|
---|
[135] | 327 | static XtInputId inputid[2];
|
---|
| 328 | static int origfiledes[2]={-1, -1}; // descripteurs de fichiers de depart
|
---|
[78] | 329 |
|
---|
[81] | 330 | static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
|
---|
[78] | 331 | {
|
---|
[2607] | 332 | char buff[512];
|
---|
[78] | 333 | int nr;
|
---|
[81] | 334 |
|
---|
| 335 | int idx = *((int*)cld);
|
---|
| 336 | if (idx != 1) idx = 0;
|
---|
[135] | 337 | if (!consstream[idx]) return;
|
---|
[2607] | 338 | while ( (nr=read(*fd, buff, 512)) > 0 ) {
|
---|
[81] | 339 | buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
|
---|
[78] | 340 | }
|
---|
[81] | 341 | consstream[idx]->Refresh();
|
---|
[78] | 342 | }
|
---|
| 343 |
|
---|
| 344 | /* --Methode-- */
|
---|
[81] | 345 | void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
|
---|
[78] | 346 | {
|
---|
[135] | 347 | if ( origfiledes[0]<0 ) origfiledes[0] = fcntl(1, F_DUPFD);
|
---|
| 348 | if ( cons == consstream[0]) return;
|
---|
| 349 | if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
|
---|
| 350 | else if (!cons) {
|
---|
| 351 | consstream[0] = NULL;
|
---|
| 352 | XtRemoveInput(inputid[0]);
|
---|
| 353 | dup2(origfiledes[0], 1);
|
---|
| 354 | return;
|
---|
| 355 | }
|
---|
[78] | 356 |
|
---|
[81] | 357 | consstream[0] = cons; streamva[0] = va;
|
---|
| 358 |
|
---|
[78] | 359 | int p[2];
|
---|
| 360 | pipe(p);
|
---|
[90] | 361 | // Redirection de stdout (fid=1) :
|
---|
[78] | 362 | close(1);
|
---|
| 363 | dup(p[1]);
|
---|
| 364 | close(p[1]);
|
---|
| 365 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 366 |
|
---|
[365] | 367 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 368 | setlinebuf(stdout);
|
---|
[163] | 369 | #endif
|
---|
[135] | 370 | ios::sync_with_stdio();
|
---|
[78] | 371 |
|
---|
[114] | 372 | int szx, szy, szf;
|
---|
| 373 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 374 | inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 375 | redirectstream_callback, (XtPointer) streamno);
|
---|
[78] | 376 | }
|
---|
[81] | 377 |
|
---|
| 378 | /* --Methode-- */
|
---|
| 379 | void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
|
---|
| 380 | {
|
---|
[135] | 381 | if ( origfiledes[1]<0 ) origfiledes[1] = fcntl(2, F_DUPFD);
|
---|
| 382 | if ( cons == consstream[1]) return;
|
---|
| 383 | if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
|
---|
| 384 | else if (!cons) {
|
---|
| 385 | consstream[1] = NULL;
|
---|
| 386 | XtRemoveInput(inputid[1]);
|
---|
| 387 | dup2(origfiledes[1], 2);
|
---|
| 388 | return;
|
---|
| 389 | }
|
---|
[81] | 390 |
|
---|
| 391 | consstream[1] = cons; streamva[1] = va;
|
---|
| 392 |
|
---|
| 393 | int p[2];
|
---|
| 394 | pipe(p);
|
---|
[135] | 395 | // Redirection de stderr (fid=2) :
|
---|
[81] | 396 | close(2);
|
---|
| 397 | dup(p[1]);
|
---|
| 398 | close(p[1]);
|
---|
| 399 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 400 |
|
---|
[365] | 401 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 402 | setlinebuf(stderr);
|
---|
[163] | 403 | #endif
|
---|
[135] | 404 | ios::sync_with_stdio();
|
---|
[81] | 405 |
|
---|
[114] | 406 | int szx, szy, szf;
|
---|
| 407 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 408 | inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 409 | redirectstream_callback, (XtPointer) (streamno+1));
|
---|
[81] | 410 | }
|
---|
| 411 |
|
---|