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