1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // Module PI : Peida Interactive PIBaseWdg
|
---|
3 | // Reza 95-96
|
---|
4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
5 |
|
---|
6 | #include <stdio.h>
|
---|
7 |
|
---|
8 | #include <X11/Intrinsic.h>
|
---|
9 | #include <X11/StringDefs.h>
|
---|
10 | #include <X11/cursorfont.h>
|
---|
11 |
|
---|
12 | #include <X11/IntrinsicP.h>
|
---|
13 | #include <X11/CoreP.h>
|
---|
14 |
|
---|
15 | #include "pixtbaseP.h"
|
---|
16 | #include "pixtbase.h"
|
---|
17 |
|
---|
18 | #include "pibwdgx.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | // #define DEBUG_PIBWDGX Flag pour impression de debug etc ...
|
---|
22 | static unsigned long colpixwhite, colpixblack;
|
---|
23 | #define NMAXCURS 5
|
---|
24 | static Cursor curs[NMAXCURS];
|
---|
25 |
|
---|
26 |
|
---|
27 | /* --Methode-- */
|
---|
28 | PIBaseWdgX::PIBaseWdgX(PIContainerGen *par, char *nom,
|
---|
29 | int sx, int sy, int px, int py)
|
---|
30 | : PIBaseWdgGen(par, nom, sx, sy, px, py)
|
---|
31 |
|
---|
32 | {
|
---|
33 | Arg wargs[3];
|
---|
34 |
|
---|
35 | Init();
|
---|
36 | mWGrC = NULL; // PIGraphic (Contexte graphique) associe a la fenetre
|
---|
37 | finishDone = false; // FinishCreate() pas encore appele
|
---|
38 |
|
---|
39 | CreateXtWdg(nom, piXtBaseWidgetClass, NULL, sx, sy, px, py);
|
---|
40 |
|
---|
41 | XtSetArg(wargs[0],PIXNobject,this);
|
---|
42 | XtSetArg(wargs[1],XtNbackground, colpixwhite);
|
---|
43 | XtSetArg(wargs[2],XtNborderWidth, (Dimension)0);
|
---|
44 | XtSetValues(XtWdg(), wargs, 3);
|
---|
45 |
|
---|
46 | ((PIXtBaseWidget)XtWdg())->pixtbase.myeventmask = 0;
|
---|
47 | XtUninstallTranslations(XtWdg());
|
---|
48 |
|
---|
49 | mPtrS = PI_CrossPointer;
|
---|
50 | SelPointerShape();
|
---|
51 | // PIGraphic (Contexte graphique) associe a la fenetre
|
---|
52 | // Si pas cree par FinishCreate()
|
---|
53 | if (!mWGrC) mWGrC = new PIGraphicX(this);
|
---|
54 | Manage();
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | /* --Methode-- */
|
---|
59 | PIBaseWdgX::~PIBaseWdgX()
|
---|
60 | {
|
---|
61 | #ifdef DEBUG_PIBWDGX
|
---|
62 | printf("PIBaseWdgX::~PIBaseWdgX()_Debug: Object= %lx (%lx) Wdg= %lx \n",
|
---|
63 | (long)this, (long)(((PIXtBaseWidget)XtWdg())->pixtbase.objet), (long)XtWdg() );
|
---|
64 | #endif
|
---|
65 | Arg wargs[2];
|
---|
66 | XtSetArg(wargs[0],PIXNobject,NULL);
|
---|
67 | XtSetValues(XtWdg(), wargs, 1);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* --Methode-- */
|
---|
71 | void PIBaseWdgX::FinishCreate()
|
---|
72 | {
|
---|
73 | if (finishDone) {
|
---|
74 | fprintf(stderr, "BUG/PIBaseWdgX::FinishCreate() multiple call \n");
|
---|
75 | return;
|
---|
76 | }
|
---|
77 | // appele par la fenetre mere, apres XtRealize()
|
---|
78 | // J'active le backing store pour la fenetre X
|
---|
79 | XSetWindowAttributes xswa;
|
---|
80 | if (!XtIsRealized(XtWdg())) XtRealizeWidget( XtWdg() ) ;
|
---|
81 |
|
---|
82 | Window mwi = XtWindow(XtWdg());
|
---|
83 |
|
---|
84 | /*
|
---|
85 | XWindowAttributes xwa;
|
---|
86 | XGetWindowAttributes(PIXDisplay(), mwi, &xwa);
|
---|
87 | printf("PIBaseWdgX::FinishCreate() BS= %d (No=%d Map=%d Always=%d) planes=%lx \n",
|
---|
88 | xwa.backing_store, NotUseful, WhenMapped, Always, (long)xwa.backing_planes);
|
---|
89 | */
|
---|
90 | xswa.backing_store = WhenMapped;
|
---|
91 | // xswa.backing_planes = ~0;
|
---|
92 | // XChangeWindowAttributes(PIXDisplay(), XtWindow(XtWdg()), CWBackingPlanes|CWBackingStore, &xswa);
|
---|
93 | XChangeWindowAttributes(PIXDisplay(), mwi, CWBackingStore, &xswa);
|
---|
94 |
|
---|
95 | // PIGraphic (Contexte graphique) associe a la fenetre
|
---|
96 | if (!mWGrC) mWGrC = new PIGraphicX(this);
|
---|
97 | mWGrC->TerminateInit();
|
---|
98 | finishDone = true; // FinishCreate() fait
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* --Methode-- */
|
---|
102 | bool PIBaseWdgX::IsVisible()
|
---|
103 | {
|
---|
104 | return (finishDone && PIWdg::IsVisible() );
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* --Methode-- */
|
---|
108 | void PIBaseWdgX::Refresh()
|
---|
109 | {
|
---|
110 | if ( IsVisible() ) {
|
---|
111 | // EraseWindow(); --> Ne pas faire Reza 12/98
|
---|
112 | Draw(mWGrC, 0, 0, XSize(), YSize());
|
---|
113 | CallDrawers(mWGrC);
|
---|
114 | CallDrawHandlers(0, 0, XSize(), YSize());
|
---|
115 | }
|
---|
116 | return;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | /* --Methode-- */
|
---|
121 | void PIBaseWdgX::ActivatePtrCross()
|
---|
122 | {
|
---|
123 | XtAddEventHandler( XtWdg(), EnterWindowMask | LeaveWindowMask,
|
---|
124 | FALSE, event_handler_pixtbase, NULL);
|
---|
125 | return;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | /* --Methode-- */
|
---|
130 | void PIBaseWdgX::ActivateButton(int bid)
|
---|
131 | {
|
---|
132 | #ifdef DEBUG_PIBWDGX
|
---|
133 | printf("PIBaseWdgX::ActivateButton %d \n \n", bid);
|
---|
134 | #endif
|
---|
135 | if ( (bid < 1) && (bid > 3) ) return;
|
---|
136 | XtAddEventHandler( XtWdg(), ButtonPressMask | ButtonReleaseMask,
|
---|
137 | FALSE, event_handler_pixtbase, NULL);
|
---|
138 | if (bid == 1) ((PIXtBaseWidget)XtWdg())->pixtbase.myeventmask |= Button1Mask ;
|
---|
139 | else if (bid == 2) ((PIXtBaseWidget)XtWdg())->pixtbase.myeventmask |= Button2Mask ;
|
---|
140 | else if (bid == 3) ((PIXtBaseWidget)XtWdg())->pixtbase.myeventmask |= Button3Mask ;
|
---|
141 | return;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* --Methode-- */
|
---|
145 | void PIBaseWdgX::ActivateMove(int bid)
|
---|
146 | {
|
---|
147 | #ifdef DEBUG_PIBWDGX
|
---|
148 | printf("PIBaseWdgX::ActivateMove %d \n \n", bid);
|
---|
149 | #endif
|
---|
150 | unsigned long evtmask ;
|
---|
151 |
|
---|
152 | // bid == 0 -> PointerMove sans bouton
|
---|
153 | if ( (bid < 0) && (bid > 3) ) return;
|
---|
154 |
|
---|
155 | if (bid == 0) evtmask = PointerMotionHintMask ;
|
---|
156 | else if (bid == 1) evtmask = Button1MotionMask | PointerMotionHintMask ;
|
---|
157 | else if (bid == 2) evtmask = Button2MotionMask | PointerMotionHintMask ;
|
---|
158 | else if (bid == 3) evtmask = Button3MotionMask | PointerMotionHintMask ;
|
---|
159 | XtAddEventHandler( XtWdg(), evtmask, FALSE, event_handler_pixtbase, NULL);
|
---|
160 | return;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /* --Methode-- */
|
---|
165 | void PIBaseWdgX::ActivateKeyboard()
|
---|
166 | {
|
---|
167 | XtAddEventHandler( XtWdg(), KeyPressMask, FALSE, event_handler_pixtbase, NULL);
|
---|
168 | ((PIXtBaseWidget)XtWdg())->pixtbase.myeventmask |= ShiftMask ;
|
---|
169 | return;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /* --Methode-- */
|
---|
173 | void PIBaseWdgX::SetBackgroundColor(PIColors col)
|
---|
174 | {
|
---|
175 | Arg wargs[2];
|
---|
176 | XtSetArg(wargs[0],XtNbackground, mWGrC->GetPixelValueforColor(col) );
|
---|
177 | XtSetValues(XtWdg(), wargs, 1);
|
---|
178 | mBCol = col;
|
---|
179 | return;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /* --Methode-- */
|
---|
183 | void PIBaseWdgX::EraseWindow(int x0, int y0, int dx, int dy)
|
---|
184 | {
|
---|
185 | XClearArea (XtDisplay(XtWdg()),XtWindow(XtWdg()), x0, y0, dx, dy, False );
|
---|
186 | return;
|
---|
187 | }
|
---|
188 |
|
---|
189 | /* --Methode-- */
|
---|
190 | void PIBaseWdgX::SelPointerShape(PIPointer ptr)
|
---|
191 | {
|
---|
192 | if (ptr == mPtrS) return;
|
---|
193 | if ( (ptr < 0) || (ptr >= NMAXCURS)) return;
|
---|
194 | if ( XtIsRealized(XtWdg()) )
|
---|
195 | XDefineCursor(XtDisplay (XtWdg()), XtWindow(XtWdg()), curs[ptr]);
|
---|
196 | mPtrS = ptr;
|
---|
197 | return;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* --Methode-- */
|
---|
201 | void PIBaseWdgX::AssignKeyboard()
|
---|
202 | {
|
---|
203 | XSetInputFocus(XtDisplay (XtWdg()), XtWindow(XtWdg()), RevertToParent, PIXGetLastEventTime());
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* --Methode-- */
|
---|
207 | PIColors PIBaseWdgX::GetBackgroundColor()
|
---|
208 | {
|
---|
209 | return(mBCol);
|
---|
210 | }
|
---|
211 |
|
---|
212 | /* --Methode-- */
|
---|
213 | PIPointer PIBaseWdgX::GetPointerShape()
|
---|
214 | {
|
---|
215 | return (mPtrS);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /* --Methode-- */
|
---|
219 | void PIBaseWdgX::GetLastEventInfo(PIKeyModifier& kmod, unsigned long& tm)
|
---|
220 | {
|
---|
221 | unsigned int st;
|
---|
222 | Time t;
|
---|
223 | PIXGetLastEventInfo(st, t);
|
---|
224 | tm = t;
|
---|
225 | kmod = PIKM_Blank;
|
---|
226 | if (st & ShiftMask) kmod = (PIKeyModifier) (kmod | PIKM_Shift);
|
---|
227 | if (st & ControlMask) kmod = (PIKeyModifier) (kmod | PIKM_Cntl);
|
---|
228 | if (st & Mod1Mask) kmod = (PIKeyModifier) (kmod | PIKM_Alt);
|
---|
229 | return;
|
---|
230 | }
|
---|
231 |
|
---|
232 | static bool fgbwdg = false ;
|
---|
233 |
|
---|
234 | /* --Methode-- */
|
---|
235 | void PIBaseWdgX::Init()
|
---|
236 | {
|
---|
237 | int i;
|
---|
238 |
|
---|
239 | if (fgbwdg) return;
|
---|
240 | fgbwdg = true;
|
---|
241 |
|
---|
242 | Display *mdsp = PIXDisplay();
|
---|
243 | int scr = XDefaultScreen(mdsp);
|
---|
244 |
|
---|
245 | colpixwhite = XWhitePixel(mdsp, scr);
|
---|
246 | colpixblack = XBlackPixel(mdsp, scr);
|
---|
247 |
|
---|
248 | curs[0] = XCreateFontCursor(mdsp, XC_X_cursor);
|
---|
249 | for(i=1; i<NMAXCURS; i++) curs[i] = curs[0];
|
---|
250 |
|
---|
251 | curs[PI_ArrowPointer] = XCreateFontCursor(mdsp, XC_arrow);
|
---|
252 | curs[PI_CrossPointer] = XCreateFontCursor(mdsp, XC_crosshair);
|
---|
253 | curs[PI_HandPointer] = XCreateFontCursor(mdsp, XC_hand2);
|
---|
254 | curs[PI_TDLRArrowPointer] = XCreateFontCursor(mdsp, XC_fleur);
|
---|
255 |
|
---|
256 | return;
|
---|
257 | }
|
---|
258 |
|
---|
259 | /* --Methode-- */
|
---|
260 | void PIBaseWdgX::eXposeProcess(int x0, int y0, int dx, int dy)
|
---|
261 | {
|
---|
262 | // Appel depuis le PIXtBaseWidget uniquement (ExposeEvt de Xt )
|
---|
263 | Draw(mWGrC, x0, y0, dx, dy);
|
---|
264 | CallDrawers(mWGrC, x0, y0, dx, dy);
|
---|
265 | return;
|
---|
266 | }
|
---|