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