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