[2] | 1 | #include <stdio.h>
|
---|
[18] | 2 | #include <X11/cursorfont.h>
|
---|
[2] | 3 | #include "piapplx.h"
|
---|
| 4 | #include "picontainerx.h"
|
---|
| 5 |
|
---|
| 6 |
|
---|
[78] | 7 | // Pour rediriger stdout
|
---|
| 8 | #include <unistd.h>
|
---|
| 9 | #include <fcntl.h>
|
---|
[2] | 10 |
|
---|
[78] | 11 |
|
---|
| 12 | // #define DEBUG_APPLX
|
---|
| 13 |
|
---|
[18] | 14 | static Cursor a_curs[3];
|
---|
| 15 | static bool a_fgcur=false;
|
---|
| 16 |
|
---|
[60] | 17 | // Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
|
---|
| 18 | void SetTopWdgForMenuX(SysDWdg mtw);
|
---|
| 19 |
|
---|
[2] | 20 | /* --Methode-- */
|
---|
| 21 | PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
|
---|
| 22 | : PIApplicationGen()
|
---|
| 23 | {
|
---|
| 24 | int sxt, syt;
|
---|
| 25 |
|
---|
| 26 | #ifdef DEBUG_APPLX
|
---|
| 27 | puts("PIApplicationX::PIApplicationX()_info : App creation");
|
---|
| 28 | #endif
|
---|
| 29 | mStop = true;
|
---|
| 30 | topwdg = new PIWdgX(narg, arg);
|
---|
| 31 |
|
---|
| 32 | intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
|
---|
| 33 | 10, 10, 0, 0);
|
---|
[60] | 34 | // Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
|
---|
| 35 | SetTopWdgForMenuX(intcont->XtWdg());
|
---|
| 36 |
|
---|
[2] | 37 | menubar = new PIMenubar(this, "DefMenubar");
|
---|
[23] | 38 | Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
|
---|
[2] | 39 | sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
|
---|
| 40 | syt = ( sy > 0 ) ? sy : 0;
|
---|
[7] | 41 | //syt += Menubar()->YSize();
|
---|
| 42 | syt += 40;
|
---|
[2] | 43 | MBCont()->SetSize(sxt, syt);
|
---|
| 44 | if ( (sx > 0) && (sy > 0) )
|
---|
| 45 | {
|
---|
| 46 | topcont = new PIContainerX(MBCont(), "TopLevelCont",
|
---|
[7] | 47 | sx, sy, 0, 40);
|
---|
[23] | 48 | topcont->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
|
---|
[2] | 49 | topcont->Show();
|
---|
| 50 | }
|
---|
| 51 | else topcont = MBCont();
|
---|
| 52 |
|
---|
| 53 | MBCont()->Show();
|
---|
| 54 | topwdg->Manage();
|
---|
[18] | 55 |
|
---|
| 56 | if (!a_fgcur)
|
---|
| 57 | {
|
---|
| 58 | Display *mdsp;
|
---|
| 59 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 60 | a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
|
---|
| 61 | a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
|
---|
| 62 | a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | mState = -1;
|
---|
| 66 | SetReady();
|
---|
[2] | 67 | }
|
---|
| 68 |
|
---|
| 69 | /* --Methode-- */
|
---|
| 70 | PIApplicationX::~PIApplicationX()
|
---|
| 71 | {
|
---|
| 72 | #ifdef DEBUG_APPLX
|
---|
| 73 | puts("PIApplicationX::~PIApplicationX()_info : App delete");
|
---|
| 74 | #endif
|
---|
[18] | 75 | Display *mdsp;
|
---|
| 76 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[52] | 77 | topwdg->UnManage();
|
---|
[6] | 78 | delete menubar;
|
---|
| 79 | if (topcont != MBCont()) delete topcont;
|
---|
| 80 | delete intcont;
|
---|
[2] | 81 | delete topwdg;
|
---|
[18] | 82 | XtCloseDisplay(mdsp);
|
---|
| 83 | return;
|
---|
[2] | 84 | }
|
---|
| 85 |
|
---|
| 86 | /* --Methode-- */
|
---|
| 87 | void PIApplicationX::Run()
|
---|
| 88 | {
|
---|
| 89 | XEvent evt;
|
---|
| 90 | #ifdef DEBUG_APPLX
|
---|
| 91 | puts("PIApplicationX::Run()_info : App Run ");
|
---|
| 92 | #endif
|
---|
| 93 |
|
---|
| 94 | topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
|
---|
| 95 |
|
---|
[90] | 96 | int szx, szy;
|
---|
| 97 | XtAppContext * appctx = PIXtAppCtx(szx, szy);
|
---|
| 98 |
|
---|
[2] | 99 | while (mStop)
|
---|
| 100 | {
|
---|
[90] | 101 | XtAppNextEvent(*appctx, &evt);
|
---|
[2] | 102 | XtDispatchEvent(&evt);
|
---|
| 103 | }
|
---|
| 104 | return;
|
---|
| 105 | }
|
---|
[18] | 106 |
|
---|
| 107 |
|
---|
| 108 | /* --Methode-- */
|
---|
| 109 | void PIApplicationX::SetReady()
|
---|
| 110 | {
|
---|
| 111 | if (mState != kReadyState)
|
---|
| 112 | {
|
---|
| 113 | Display * mdsp;
|
---|
| 114 | mState = kReadyState;
|
---|
| 115 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 116 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
|
---|
| 117 | XFlush(mdsp);
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /* --Methode-- */
|
---|
| 122 | void PIApplicationX::SetBusy()
|
---|
| 123 | {
|
---|
| 124 | if (mState != kBusyState)
|
---|
| 125 | {
|
---|
| 126 | Display * mdsp;
|
---|
| 127 | mState = kBusyState;
|
---|
| 128 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 129 | // if ( XtIsRealized(topwdg->XtWdg()) )
|
---|
| 130 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
|
---|
| 131 | XFlush(mdsp);
|
---|
| 132 | }
|
---|
| 133 | return;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /* --Methode-- */
|
---|
| 137 | void PIApplicationX::SetBlocked()
|
---|
| 138 | {
|
---|
| 139 | if (mState != kBlockedState)
|
---|
| 140 | {
|
---|
| 141 | Display * mdsp;
|
---|
| 142 | mState = kBlockedState;
|
---|
| 143 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 144 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
|
---|
| 145 | XFlush(mdsp);
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
[75] | 148 |
|
---|
| 149 |
|
---|
| 150 | /* --Methode-- */
|
---|
[90] | 151 | void PIApplicationX::PrefCompSz(int& szx, int& szy)
|
---|
[75] | 152 | {
|
---|
[90] | 153 | PIXtAppCtx(szx, szy);
|
---|
| 154 | return;
|
---|
[75] | 155 | }
|
---|
| 156 |
|
---|
| 157 |
|
---|
[78] | 158 | /* Call-Back - Fonction privee de ce fichier */
|
---|
[81] | 159 | static void redirectstream_callback(XtPointer, int *, XtInputId*);
|
---|
[78] | 160 |
|
---|
[81] | 161 | static PIConsole* consstream[2] = {NULL, NULL};
|
---|
| 162 | static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
|
---|
| 163 | static int streamno[2] = {0,1};
|
---|
[78] | 164 |
|
---|
[81] | 165 | static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
|
---|
[78] | 166 | {
|
---|
| 167 | char buff[128];
|
---|
| 168 | int nr;
|
---|
[81] | 169 |
|
---|
| 170 | int idx = *((int*)cld);
|
---|
| 171 | if (idx != 1) idx = 0;
|
---|
[78] | 172 | while ( (nr=read(*fd, buff, 127)) > 0 ) {
|
---|
[81] | 173 | buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
|
---|
[78] | 174 | }
|
---|
[81] | 175 | consstream[idx]->Refresh();
|
---|
[78] | 176 | }
|
---|
| 177 |
|
---|
| 178 | /* --Methode-- */
|
---|
[81] | 179 | void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
|
---|
[78] | 180 | {
|
---|
| 181 | if (!cons) return;
|
---|
| 182 |
|
---|
[81] | 183 | if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
|
---|
| 184 | consstream[0] = cons; streamva[0] = va;
|
---|
| 185 |
|
---|
[78] | 186 | int p[2];
|
---|
| 187 | pipe(p);
|
---|
[90] | 188 | // Redirection de stdout (fid=1) :
|
---|
[78] | 189 | close(1);
|
---|
| 190 | dup(p[1]);
|
---|
| 191 | close(p[1]);
|
---|
| 192 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[85] | 193 | setlinebuf(stdout);
|
---|
[78] | 194 |
|
---|
[90] | 195 | int szx, szy;
|
---|
| 196 | XtAppContext * appctx = PIXtAppCtx(szx, szy);
|
---|
| 197 | XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
|
---|
[78] | 198 | }
|
---|
[81] | 199 |
|
---|
| 200 | /* --Methode-- */
|
---|
| 201 | void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
|
---|
| 202 | {
|
---|
| 203 | if (!cons) return;
|
---|
| 204 |
|
---|
| 205 | if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
|
---|
| 206 | consstream[1] = cons; streamva[1] = va;
|
---|
| 207 |
|
---|
| 208 | int p[2];
|
---|
| 209 | pipe(p);
|
---|
[90] | 210 | // Redirection de stderr (fid=0) :
|
---|
[81] | 211 | close(2);
|
---|
| 212 | dup(p[1]);
|
---|
| 213 | close(p[1]);
|
---|
| 214 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[85] | 215 | setlinebuf(stderr);
|
---|
[81] | 216 |
|
---|
[90] | 217 | int szx, szy;
|
---|
| 218 | XtAppContext * appctx = PIXtAppCtx(szx, szy);
|
---|
| 219 | XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
|
---|
[81] | 220 | }
|
---|
| 221 |
|
---|