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