source: Sophya/trunk/Poubelle/DPC:FitsIOServer/PI/pibwdgx.cc@ 658

Last change on this file since 658 was 658, checked in by ansari, 26 years ago

no message

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