My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#include "CtrlCore.h"

#ifdef GUI_X11

NAMESPACE_UPP

/////////////////////////////////////////////////////////////////////////////////////////
// Constructor
DHCtrl::DHCtrl()
{
// Sets control NOT initialized
isInitialized = false;

// Sets control NOT mapped
isMapped = false;

// Resets error contition
isError = false;

// Sets the user visual to null
UserVisualInfo = 0;

// No background painting
backpaint = NOBACKPAINT;
// transparent = true;
hwnd = 0;
} // END Constructor class DHCtrl

/////////////////////////////////////////////////////////////////////////////////////////
// Destructor
DHCtrl::~DHCtrl()
{
// Destroys the associated window and clean up stuffs
Terminate();

} // END Destructor class DHCtrl

/////////////////////////////////////////////////////////////////////////////////////////
// Maps/unmaps the window
void DHCtrl::MapWindow(bool map)
{
GuiLock __;
// no action if not initialized
if(!isInitialized)
return;

if(map && !isMapped)
XMapWindow(Xdisplay, top->window);
else if(!map && isMapped)
XUnmapWindow(Xdisplay, top->window);

isMapped = map;

} // END DHCtrl::MapWndow()


/////////////////////////////////////////////////////////////////////////////////////////
// Initializes the view
bool DHCtrl::Init()
{
GuiLock __;
static bool isInitializing = false;

// Just for security sakes...
if(isInitialized)
return true;

// Prevents reentrant call....
if(isInitializing)
return false;
isInitializing = true;

// Call BeforeInit user func...
BeforeInit();

// if display is null, error
if(!Xdisplay)
{
// Call AfterInit user func...
AfterInit(true);

// Sets the appropriate error message
SetErrorMessage("DHCtrl : Bad display");

isError = true;
isInitializing = false;
return false;
}

// Calls the user visual function
UserVisualInfo = CreateVisual();

// If error, returns
if(isError)
{
isInitializing = false;
return false;
}

// Gets the default visual, if none is given
Visual *visual;
int Depth;
if(UserVisualInfo)
{
visual = UserVisualInfo->visual;
Depth = UserVisualInfo->depth;
}
else
{
visual = DefaultVisual(Xdisplay, DefaultScreen(Xdisplay));
Depth = DefaultDepth(Xdisplay, DefaultScreen(Xdisplay));
}

// Initializes attribute setting flags
unsigned long ValueMask =
CWBorderPixel
| CWColormap
| CWSaveUnder
// | CWBackPixel
// | CWBorderPixel
| CWColormap
// | CWEventMask
// | CWWinGravity
// | CWBitGravity
; // END ValueMask

// Initializes attribute structure
XSetWindowAttributes winAttributes;
// creates a ColorMap, in case we're not using default visual
winAttributes.colormap = XCreateColormap(Xdisplay, GetTopWindow()->GetWindow(), visual, AllocNone);
winAttributes.border_pixel = 0;
winAttributes.save_under = XFalse;
// winAttributes.win_gravity = StaticGravity;
// winAttributes.bit_gravity = ForgetGravity;

// Calls the attributes user setting routine
SetAttributes(ValueMask, winAttributes);

// Creates the X11 window
Rect r = GetRectInParentWindow();
if (!hwnd) {
hwnd = XCreateWindow
(
Xdisplay, // display
// GetTopWindow()->GetWindow(), // parent
GetParentWindow(),

r.left, r.top, r.Width(), r.Height(), // x, y, width, height
0, // border width
Depth, // depth
InputOutput, // class
visual, // visual
ValueMask, // value mask
&winAttributes // attributes
);
} else {
XReparentWindow(Xdisplay, hwnd, GetParentWindow(), r.left, r.top);
XResizeWindow(Xdisplay, hwnd, r.Width(), r.Height());
XChangeWindowAttributes(Xdisplay, hwnd, ValueMask, &winAttributes);
}

// Frees VisualInfo
if (UserVisualInfo)
{
XFree( (char *)UserVisualInfo);
UserVisualInfo = 0;
}

// If problem creating window, error
if(!hwnd)
{
// Call AfterInit user func...
AfterInit(true);

// Sets the appropriate error message
SetErrorMessage("DHCtrl : Can't create window");

isError = true;
isInitializing = false;
return false;
}

// Adds window to UPP managed windows
XWindow *cw = AddXWindow(hwnd);

cw->xic = xim ? XCreateIC
(
xim,
XNInputStyle,
XIMPreeditNothing | XIMStatusNothing,
XNClientWindow,
hwnd,
XNFocusWindow,
hwnd,
NULL
)
: NULL;

top = new Top;
top->window = hwnd;

long im_event_mask = 0;
if(cw->xic)
XGetICValues(cw->xic, XNFilterEvents, &im_event_mask, NULL);
XSelectInput
(
Xdisplay,
hwnd,
ExposureMask
// | StructureNotifyMask // *very* important, flag MUST NOT be set
| KeyPressMask
| FocusChangeMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
| PropertyChangeMask
| VisibilityChangeMask
| im_event_mask
);

int version = 5;
XChangeProperty
(
Xdisplay,
hwnd,
XAtom("XdndAware"),
XA_ATOM,
32,
0,
(byte *)&version,
1
);

// Maps the window if needed
if(IsShown())
MapWindow(true);

// Flushes the display
XFlush(Xdisplay);

// Stores the initial control size
CurrentSize = GetSize();

// Exits from initializing lock
isInitializing = false;

// mark control as initialized
isInitialized = true;

// Resets the message
isError = false;
SetErrorMessage("");

// Call AfterInit user func...
AfterInit(false);

return true;

} // END DHCtrl::Init()


/////////////////////////////////////////////////////////////////////////////////////////
// Terminates the view
void DHCtrl::Terminate(void)
{
GuiLock __;
BeforeTerminate();

if(!isInitialized)
return;

// Unmaps the window
MapWindow(false);

// gathers data from XWindow (needs Input Context...)
XWindow *cw = XWindowFromWindow(top->window);

// Frees input context as needed
if(cw->xic)
{
XDestroyIC(cw->xic);
cw->xic = NULL;
}

// Removes XWindow from Upp list
RemoveXWindow(top->window);

// Destroys the window
// Not to do, it's done destroying the parent window by X11 system
// XDestroyWindow(Xdisplay, top->window);

// Destroys created Top struct
delete top;
top = NULL;

// Resets initialization and error flags
isInitialized = false;
isError = false;

} // END DHCtrl::Terminate()

/////////////////////////////////////////////////////////////////////////////////////////
// State handler
void DHCtrl::State(int reason)
{
GuiLock __;
// Window dummy;
// int x, y;
// unsigned int width, height, border, depth;
Rect r;

// No handling if in error state
if( isError)
return;

// Initializes the control if needed (and possible...)
if(!isInitialized && GetTopWindow() && GetTopWindow()->GetWindow())
Init();

if(isInitialized)
{
switch( reason )
{
case FOCUS : // = 10,
break;

case ACTIVATE : // = 11,
break;

case DEACTIVATE : // = 12,
break;

case SHOW : // = 13,
MapWindow(IsVisible());
break;

case ENABLE : // = 14,
break;

case EDITABLE : // = 15,
break;

case OPEN : // = 16,
MapWindow(IsShown());
break;

case CLOSE : // = 17,
Terminate();
break;

case POSITION : // = 100,
case LAYOUTPOS : // = 101,
SyncNativeWindows();
break;

default:
break;

} // switch(reason)
}
}

/////////////////////////////////////////////////////////////////////////////////////////
// Property Visual
Visual *DHCtrl::GetVisual(void)
{
GuiLock __;
if(UserVisualInfo)
return UserVisualInfo->visual;
else
return DefaultVisual(Xdisplay, DefaultScreen(Xdisplay));

} // END DHCtrl::getVisual()


/////////////////////////////////////////////////////////////////////////////////////////
// Property VisualInfo
XVisualInfo DHCtrl::GetVisualInfo(void)
{
GuiLock __;
// if present an user visual info, just return it
if(UserVisualInfo)
return *UserVisualInfo;

XVisualInfo visualInfo;
memset(&visualInfo, 0, sizeof(visualInfo));

// get the active visual
Visual *visual = GetVisual();

// gets a list of all available XVisualinfo
XVisualInfo *v = 0;
XVisualInfo vtemplate;
int nVis;
XVisualInfo *vlist = XGetVisualInfo(Xdisplay, VisualNoMask, &vtemplate, &nVis);

// search for current visual inside the list
if(vlist)
{
for (v = vlist; v < vlist + nVis; v++)
{
if (v->visual == visual)
{
visualInfo = *v;
break;
}
}
XFree(vlist);
}
else
{
isError = true;
ErrorMessage = "DHCtrl: no XVisualInfo for current Visual";
}

// returns the found XVisualInfo struct
return visualInfo;
}

END_UPP_NAMESPACE

#endif

Change log

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
Go to: 
Project members, sign in to write a code review

Older revisions

r3581 by cxl on Jul 1, 2011   Diff
.developing rainbow
r3509 by cxl on Jun 10, 2011   Diff
.developing rainbow
r2873 by cxl on Nov 28, 2010   Diff
*CtrlCore: ImageX11 fix, DHCtrl fix
All revisions of this file

File info

Size: 8535 bytes, 424 lines
Powered by Google Project Hosting