[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 |
|
---|
| 116 |
|
---|
[2] | 117 | topwdg = new PIWdgX(narg, arg);
|
---|
| 118 |
|
---|
[365] | 119 | int msx,msy;
|
---|
[1592] | 120 | PrefCompSize(msx, msy);
|
---|
[365] | 121 | msy+=5;
|
---|
| 122 | topwdg->SetSize(sx, sy+msy);
|
---|
[3216] | 123 | //DBG printf("PIApplicationX-DBG:: Size=%d %d \n", topwdg->XSize(), topwdg->YSize());
|
---|
[365] | 124 |
|
---|
[2] | 125 | intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
|
---|
[365] | 126 | sx, sy+msy, 0, 0);
|
---|
[60] | 127 | // Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
|
---|
| 128 | SetTopWdgForMenuX(intcont->XtWdg());
|
---|
| 129 |
|
---|
[2] | 130 | menubar = new PIMenubar(this, "DefMenubar");
|
---|
[23] | 131 | Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
|
---|
[2] | 132 | sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
|
---|
[365] | 133 | syt = ( sy > 10 ) ? sy : 10;
|
---|
| 134 | // syt += Menubar()->YSize();
|
---|
| 135 | // syt += msy;
|
---|
| 136 | // topwdg->SetSize(sxt, syt);
|
---|
| 137 | // MBCont()->SetSize(sxt, syt);
|
---|
[132] | 138 | if (sx < sxt) sx = sxt;
|
---|
| 139 | if (sy < 10) sy = 10;
|
---|
[457] | 140 | topcont = new PITopContAppX(MBCont(), "TopLevelCont", topwdg,
|
---|
[132] | 141 | sx, sy, 0, msy);
|
---|
[163] | 142 | MBCont()->Show();
|
---|
[3216] | 143 | //DBG printf("PIApplicationX-DBG2:: MBContSize=%d %d \n", MBCont()->XSize(), MBCont()->YSize());
|
---|
[2] | 144 |
|
---|
[1074] | 145 |
|
---|
[365] | 146 | topcont->Show();
|
---|
[18] | 147 |
|
---|
[365] | 148 |
|
---|
[18] | 149 | if (!a_fgcur)
|
---|
| 150 | {
|
---|
| 151 | Display *mdsp;
|
---|
| 152 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 153 | a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
|
---|
| 154 | a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
|
---|
| 155 | a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[365] | 158 | topwdg->Manage();
|
---|
[1263] | 159 |
|
---|
| 160 | // ------------------------------------------------------
|
---|
| 161 | // Pour la gestion des close window des Window manager
|
---|
| 162 |
|
---|
| 163 | if (fgactl == 0) {
|
---|
| 164 | XtActionsRec desact = {(char *)"CloseWindow" ,CloseWindow};
|
---|
| 165 | int szx, szy, szf;
|
---|
| 166 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 167 | XtAppAddActions(*appctx, &desact, 1);
|
---|
| 168 | Display *mdsp;
|
---|
| 169 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 170 | Atom wmd;
|
---|
| 171 | wmd = XInternAtom(mdsp, "WM_DELETE_WINDOW",False);
|
---|
| 172 | XSetWMProtocols(mdsp, XtWindow(topwdg->XtWdg()), &wmd, 1);
|
---|
| 173 | fgactl = 1;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | XtTranslations trans;
|
---|
| 177 | trans = XtParseTranslationTable("<Message>WM_PROTOCOLS:CloseWindow()");
|
---|
| 178 | XtOverrideTranslations(topwdg->XtWdg() , trans);
|
---|
| 179 | Arg warg[2];
|
---|
| 180 | XtSetArg(warg[0], XmNdeleteResponse, XmDO_NOTHING);
|
---|
| 181 | XtSetValues(topwdg->XtWdg(), warg, 1);
|
---|
| 182 |
|
---|
| 183 | XtAddCallback(topwdg->XtWdg(), XtNpopdownCallback,
|
---|
| 184 | (XtCallbackProc)popdwn_cb_app, (XtPointer)this);
|
---|
| 185 |
|
---|
| 186 | // ------------------------------------------------------
|
---|
| 187 |
|
---|
[111] | 188 | cur_piapp = this;
|
---|
[18] | 189 | mState = -1;
|
---|
| 190 | SetReady();
|
---|
[2] | 191 | }
|
---|
| 192 |
|
---|
| 193 | /* --Methode-- */
|
---|
| 194 | PIApplicationX::~PIApplicationX()
|
---|
| 195 | {
|
---|
| 196 | #ifdef DEBUG_APPLX
|
---|
| 197 | puts("PIApplicationX::~PIApplicationX()_info : App delete");
|
---|
| 198 | #endif
|
---|
[18] | 199 | Display *mdsp;
|
---|
| 200 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[52] | 201 | topwdg->UnManage();
|
---|
[6] | 202 | delete menubar;
|
---|
| 203 | if (topcont != MBCont()) delete topcont;
|
---|
| 204 | delete intcont;
|
---|
[2] | 205 | delete topwdg;
|
---|
[18] | 206 | XtCloseDisplay(mdsp);
|
---|
[111] | 207 | cur_piapp = NULL;
|
---|
[18] | 208 | return;
|
---|
[2] | 209 | }
|
---|
| 210 |
|
---|
| 211 | /* --Methode-- */
|
---|
| 212 | void PIApplicationX::Run()
|
---|
| 213 | {
|
---|
| 214 | XEvent evt;
|
---|
| 215 | #ifdef DEBUG_APPLX
|
---|
| 216 | puts("PIApplicationX::Run()_info : App Run ");
|
---|
| 217 | #endif
|
---|
| 218 |
|
---|
| 219 |
|
---|
[114] | 220 | int szx, szy, szf;
|
---|
| 221 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[90] | 222 |
|
---|
[110] | 223 | // Pour appeler FinishCreate() des objets dans la fenetre principale
|
---|
[365] | 224 | if (mStop) { // C'est la premiere fois
|
---|
[1074] | 225 | topcont->SetSize(topcont->XSize(), topcont->YSize());
|
---|
| 226 | // topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
|
---|
[365] | 227 | MBCont()->FinishCreate();
|
---|
| 228 | }
|
---|
[141] | 229 | else mStop = true; // On rerentre apres un stop
|
---|
[2] | 230 | while (mStop)
|
---|
| 231 | {
|
---|
[90] | 232 | XtAppNextEvent(*appctx, &evt);
|
---|
[2] | 233 | XtDispatchEvent(&evt);
|
---|
| 234 | }
|
---|
| 235 | return;
|
---|
| 236 | }
|
---|
[18] | 237 |
|
---|
| 238 |
|
---|
| 239 | /* --Methode-- */
|
---|
| 240 | void PIApplicationX::SetReady()
|
---|
| 241 | {
|
---|
[138] | 242 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 243 | if (mState != kReadyState)
|
---|
| 244 | {
|
---|
| 245 | mState = kReadyState;
|
---|
[106] | 246 | Menubar()->SetSensitive();
|
---|
[18] | 247 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
|
---|
| 248 | }
|
---|
[138] | 249 | XFlush(mdsp);
|
---|
[18] | 250 | }
|
---|
| 251 |
|
---|
| 252 | /* --Methode-- */
|
---|
| 253 | void PIApplicationX::SetBusy()
|
---|
| 254 | {
|
---|
[138] | 255 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 256 | if (mState != kBusyState)
|
---|
| 257 | {
|
---|
| 258 | mState = kBusyState;
|
---|
[106] | 259 | Menubar()->SetSensitive();
|
---|
[18] | 260 | // if ( XtIsRealized(topwdg->XtWdg()) )
|
---|
| 261 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
|
---|
| 262 | }
|
---|
[138] | 263 | XFlush(mdsp);
|
---|
[18] | 264 | }
|
---|
| 265 |
|
---|
| 266 | /* --Methode-- */
|
---|
| 267 | void PIApplicationX::SetBlocked()
|
---|
| 268 | {
|
---|
[138] | 269 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 270 | if (mState != kBlockedState)
|
---|
| 271 | {
|
---|
| 272 | mState = kBlockedState;
|
---|
[106] | 273 | Menubar()->SetUnSensitive();
|
---|
[18] | 274 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
|
---|
| 275 | }
|
---|
[138] | 276 | XFlush(mdsp);
|
---|
| 277 | return;
|
---|
[18] | 278 | }
|
---|
[75] | 279 |
|
---|
| 280 |
|
---|
| 281 | /* --Methode-- */
|
---|
[1592] | 282 | void PIApplicationX::PrefCompSize(int& szx, int& szy)
|
---|
[75] | 283 | {
|
---|
[114] | 284 | int szf;
|
---|
| 285 | PIXtAppCtx(szx, szy, szf);
|
---|
[90] | 286 | return;
|
---|
[75] | 287 | }
|
---|
| 288 |
|
---|
[92] | 289 | /* --Methode-- */
|
---|
[1592] | 290 | void PIApplicationX::ScreenSize(int& szx, int& szy)
|
---|
[92] | 291 | {
|
---|
| 292 | Display * dsp = PIXDisplay();
|
---|
| 293 | szx = DisplayWidth(dsp, DefaultScreen(dsp));
|
---|
| 294 | szy = DisplayHeight(dsp, DefaultScreen(dsp));
|
---|
| 295 | }
|
---|
[75] | 296 |
|
---|
[1592] | 297 | /* --Methode-- */
|
---|
| 298 | void PIApplicationX::ScreenSizeMM(int& szx, int& szy)
|
---|
| 299 | {
|
---|
| 300 | Display * dsp = PIXDisplay();
|
---|
| 301 | szx = DisplayWidthMM(dsp, DefaultScreen(dsp));
|
---|
| 302 | szy = DisplayHeightMM(dsp, DefaultScreen(dsp));
|
---|
| 303 | }
|
---|
[92] | 304 |
|
---|
[1592] | 305 | /* --Methode-- */
|
---|
| 306 | void PIApplicationX::ScreenResolution(int& resolx, int& resoly)
|
---|
| 307 | {
|
---|
| 308 | Display * dsp = PIXDisplay();
|
---|
| 309 | resolx = (int)((double)DisplayWidth(dsp, DefaultScreen(dsp))*10./
|
---|
| 310 | (double)DisplayWidthMM(dsp, DefaultScreen(dsp)));
|
---|
| 311 | resoly = (int)((double)DisplayHeight(dsp, DefaultScreen(dsp))*10./
|
---|
| 312 | (double)DisplayHeightMM(dsp, DefaultScreen(dsp)));
|
---|
| 313 | }
|
---|
[92] | 314 |
|
---|
[1592] | 315 |
|
---|
| 316 |
|
---|
| 317 |
|
---|
| 318 |
|
---|
[78] | 319 | /* Call-Back - Fonction privee de ce fichier */
|
---|
[81] | 320 | static void redirectstream_callback(XtPointer, int *, XtInputId*);
|
---|
[78] | 321 |
|
---|
[81] | 322 | static PIConsole* consstream[2] = {NULL, NULL};
|
---|
| 323 | static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
|
---|
| 324 | static int streamno[2] = {0,1};
|
---|
[135] | 325 | static XtInputId inputid[2];
|
---|
| 326 | static int origfiledes[2]={-1, -1}; // descripteurs de fichiers de depart
|
---|
[78] | 327 |
|
---|
[81] | 328 | static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
|
---|
[78] | 329 | {
|
---|
[2607] | 330 | char buff[512];
|
---|
[78] | 331 | int nr;
|
---|
[81] | 332 |
|
---|
| 333 | int idx = *((int*)cld);
|
---|
| 334 | if (idx != 1) idx = 0;
|
---|
[135] | 335 | if (!consstream[idx]) return;
|
---|
[2607] | 336 | while ( (nr=read(*fd, buff, 512)) > 0 ) {
|
---|
[81] | 337 | buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
|
---|
[78] | 338 | }
|
---|
[81] | 339 | consstream[idx]->Refresh();
|
---|
[78] | 340 | }
|
---|
| 341 |
|
---|
| 342 | /* --Methode-- */
|
---|
[81] | 343 | void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
|
---|
[78] | 344 | {
|
---|
[135] | 345 | if ( origfiledes[0]<0 ) origfiledes[0] = fcntl(1, F_DUPFD);
|
---|
| 346 | if ( cons == consstream[0]) return;
|
---|
| 347 | if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
|
---|
| 348 | else if (!cons) {
|
---|
| 349 | consstream[0] = NULL;
|
---|
| 350 | XtRemoveInput(inputid[0]);
|
---|
| 351 | dup2(origfiledes[0], 1);
|
---|
| 352 | return;
|
---|
| 353 | }
|
---|
[78] | 354 |
|
---|
[81] | 355 | consstream[0] = cons; streamva[0] = va;
|
---|
| 356 |
|
---|
[78] | 357 | int p[2];
|
---|
| 358 | pipe(p);
|
---|
[90] | 359 | // Redirection de stdout (fid=1) :
|
---|
[78] | 360 | close(1);
|
---|
| 361 | dup(p[1]);
|
---|
| 362 | close(p[1]);
|
---|
| 363 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 364 |
|
---|
[365] | 365 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 366 | setlinebuf(stdout);
|
---|
[163] | 367 | #endif
|
---|
[135] | 368 | ios::sync_with_stdio();
|
---|
[78] | 369 |
|
---|
[114] | 370 | int szx, szy, szf;
|
---|
| 371 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 372 | inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 373 | redirectstream_callback, (XtPointer) streamno);
|
---|
[78] | 374 | }
|
---|
[81] | 375 |
|
---|
| 376 | /* --Methode-- */
|
---|
| 377 | void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
|
---|
| 378 | {
|
---|
[135] | 379 | if ( origfiledes[1]<0 ) origfiledes[1] = fcntl(2, F_DUPFD);
|
---|
| 380 | if ( cons == consstream[1]) return;
|
---|
| 381 | if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
|
---|
| 382 | else if (!cons) {
|
---|
| 383 | consstream[1] = NULL;
|
---|
| 384 | XtRemoveInput(inputid[1]);
|
---|
| 385 | dup2(origfiledes[1], 2);
|
---|
| 386 | return;
|
---|
| 387 | }
|
---|
[81] | 388 |
|
---|
| 389 | consstream[1] = cons; streamva[1] = va;
|
---|
| 390 |
|
---|
| 391 | int p[2];
|
---|
| 392 | pipe(p);
|
---|
[135] | 393 | // Redirection de stderr (fid=2) :
|
---|
[81] | 394 | close(2);
|
---|
| 395 | dup(p[1]);
|
---|
| 396 | close(p[1]);
|
---|
| 397 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 398 |
|
---|
[365] | 399 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 400 | setlinebuf(stderr);
|
---|
[163] | 401 | #endif
|
---|
[135] | 402 | ios::sync_with_stdio();
|
---|
[81] | 403 |
|
---|
[114] | 404 | int szx, szy, szf;
|
---|
| 405 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 406 | inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 407 | redirectstream_callback, (XtPointer) (streamno+1));
|
---|
[81] | 408 | }
|
---|
| 409 |
|
---|