]> git.saurik.com Git - wxWidgets.git/blob - src/motif/window.cpp
Fixed wxMotif's wxExecute again, added OnPaint capability to wxFrame,
[wxWidgets.git] / src / motif / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/dc.h"
19 #include "wx/dcclient.h"
20 #include "wx/utils.h"
21 #include "wx/app.h"
22 #include "wx/panel.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/frame.h"
30 #include "wx/scrolwin.h"
31
32 #include "wx/menuitem.h"
33 #include "wx/log.h"
34
35 #if wxUSE_DRAG_AND_DROP
36 #include "wx/dnd.h"
37 #endif
38
39 #include <Xm/Xm.h>
40
41 #include <Xm/DrawingA.h>
42 #include <Xm/ScrolledW.h>
43 #include <Xm/ScrollBar.h>
44 #include <Xm/Frame.h>
45 #include <Xm/Label.h>
46
47 #include "wx/motif/private.h"
48
49 #include <string.h>
50
51 #define SCROLL_MARGIN 4
52 void wxCanvasRepaintProc (Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs);
53 void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs);
54 void wxCanvasMotionEvent (Widget, XButtonEvent * event);
55 void wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
56 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
57 XmScaleCallbackStruct *cbs);
58 void wxPanelItemEventHandler (Widget wid,
59 XtPointer client_data,
60 XEvent* event,
61 Boolean *continueToDispatch);
62
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
66
67 extern wxList wxPendingDelete;
68
69 #if !USE_SHARED_LIBRARY
70 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
71
72 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
73 EVT_CHAR(wxWindow::OnChar)
74 EVT_KEY_DOWN(wxWindow::OnKeyDown)
75 EVT_KEY_UP(wxWindow::OnKeyUp)
76 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
77 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
78 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
79 EVT_IDLE(wxWindow::OnIdle)
80 END_EVENT_TABLE()
81
82 #endif
83
84
85 // Constructor
86 wxWindow::wxWindow()
87 {
88 // Generic
89 m_windowId = 0;
90 m_windowStyle = 0;
91 m_windowParent = NULL;
92 m_windowEventHandler = this;
93 m_windowName = "";
94 m_windowCursor = *wxSTANDARD_CURSOR;
95 m_children = new wxList;
96 m_constraints = NULL;
97 m_constraintsInvolvedIn = NULL;
98 m_windowSizer = NULL;
99 m_sizerParent = NULL;
100 m_autoLayout = FALSE;
101 m_windowValidator = NULL;
102 m_defaultItem = NULL;
103 m_returnCode = 0;
104 m_caretWidth = 0; m_caretHeight = 0;
105 m_caretEnabled = FALSE;
106 m_caretShown = FALSE;
107 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
108 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
109 m_foregroundColour = *wxBLACK;
110
111 #if wxUSE_DRAG_AND_DROP
112 m_pDropTarget = NULL;
113 #endif
114 m_clientObject = (wxClientData*) NULL;
115 m_clientData = NULL;
116
117 /// Motif-specific
118 m_needsRefresh = TRUE;
119 m_mainWidget = (WXWidget) 0;
120 m_button1Pressed = FALSE;
121 m_button2Pressed = FALSE;
122 m_button3Pressed = FALSE;
123 m_winCaptured = FALSE;
124 m_isShown = TRUE;
125 m_hScrollBar = (WXWidget) 0;
126 m_vScrollBar = (WXWidget) 0;
127 m_borderWidget = (WXWidget) 0;
128 m_scrolledWindow = (WXWidget) 0;
129 m_drawingArea = (WXWidget) 0;
130 m_hScroll = FALSE;
131 m_vScroll = FALSE;
132 m_backingPixmap = (WXPixmap) 0;
133 m_pixmapWidth = 0;
134 m_pixmapHeight = 0;
135 m_pixmapOffsetX = 0;
136 m_pixmapOffsetY = 0;
137 m_lastTS = 0;
138 m_lastButton = 0;
139 m_canAddEventHandler = FALSE;
140 m_scrollPosX = 0;
141 m_scrollPosY = 0;
142 }
143
144 // Destructor
145 wxWindow::~wxWindow()
146 {
147 //// Motif-specific
148
149 if (GetMainWidget())
150 DetachWidget(GetMainWidget()); // Removes event handlers
151
152 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
153 if (m_drawingArea)
154 {
155 // Destroy children before destroying self
156 DestroyChildren();
157
158 if (m_backingPixmap)
159 XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap);
160
161 Widget w = (Widget) m_drawingArea;
162 wxDeleteWindowFromTable(w);
163
164 if (w)
165 XtDestroyWidget(w);
166 m_mainWidget = (WXWidget) 0;
167
168 // Only if we're _really_ a canvas (not a dialog box/panel)
169 if (m_scrolledWindow)
170 {
171 wxDeleteWindowFromTable((Widget) m_scrolledWindow);
172 }
173
174 if (m_hScrollBar)
175 {
176 XtUnmanageChild ((Widget) m_hScrollBar);
177 XtDestroyWidget ((Widget) m_hScrollBar);
178 }
179 if (m_vScrollBar)
180 {
181 XtUnmanageChild ((Widget) m_vScrollBar);
182 XtDestroyWidget ((Widget) m_vScrollBar);
183 }
184 if (m_scrolledWindow)
185 {
186 XtUnmanageChild ((Widget) m_scrolledWindow);
187 XtDestroyWidget ((Widget) m_scrolledWindow);
188 }
189
190 if (m_borderWidget)
191 {
192 XtDestroyWidget ((Widget) m_borderWidget);
193 m_borderWidget = (WXWidget) 0;
194 }
195 }
196
197 //// Generic stuff
198
199 // Have to delete constraints/sizer FIRST otherwise
200 // sizers may try to look at deleted windows as they
201 // delete themselves.
202 #if wxUSE_CONSTRAINTS
203 DeleteRelatedConstraints();
204 if (m_constraints)
205 {
206 // This removes any dangling pointers to this window
207 // in other windows' constraintsInvolvedIn lists.
208 UnsetConstraints(m_constraints);
209 delete m_constraints;
210 m_constraints = NULL;
211 }
212 if (m_windowSizer)
213 {
214 delete m_windowSizer;
215 m_windowSizer = NULL;
216 }
217 // If this is a child of a sizer, remove self from parent
218 if (m_sizerParent)
219 m_sizerParent->RemoveChild((wxWindow *)this);
220 #endif
221
222 if (m_windowParent)
223 m_windowParent->RemoveChild(this);
224
225 DestroyChildren();
226
227 // Destroy the window
228 if (GetMainWidget())
229 {
230 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
231 // Child widgets will get destroyed automatically when a frame
232 // or dialog is destroyed, but before that you may get some memory
233 // leaks and potential layout problems if you delete and then add
234 // child windows.
235 XtDestroyWidget((Widget) GetMainWidget());
236 SetMainWidget((WXWidget) NULL);
237 }
238
239 delete m_children;
240 m_children = NULL;
241
242 // Just in case the window has been Closed, but
243 // we're then deleting immediately: don't leave
244 // dangling pointers.
245 wxPendingDelete.DeleteObject(this);
246
247 if ( m_windowValidator ) delete m_windowValidator;
248 if (m_clientObject) delete m_clientObject;
249
250 ClearUpdateRects();
251 }
252
253 // Destroy the window (delayed, if a managed window)
254 bool wxWindow::Destroy()
255 {
256 delete this;
257 return TRUE;
258 }
259
260 // Constructor
261 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
262 const wxPoint& pos,
263 const wxSize& size,
264 long style,
265 const wxString& name)
266 {
267 // Generic
268 m_windowId = 0;
269 m_windowStyle = 0;
270 m_windowParent = NULL;
271 m_windowEventHandler = this;
272 m_windowName = "";
273 m_windowCursor = *wxSTANDARD_CURSOR;
274 m_constraints = NULL;
275 m_constraintsInvolvedIn = NULL;
276 m_windowSizer = NULL;
277 m_sizerParent = NULL;
278 m_autoLayout = FALSE;
279 m_windowValidator = NULL;
280 #if wxUSE_DRAG_AND_DROP
281 m_pDropTarget = NULL;
282 #endif
283 m_caretWidth = 0; m_caretHeight = 0;
284 m_caretEnabled = FALSE;
285 m_caretShown = FALSE;
286 m_minSizeX = -1;
287 m_minSizeY = -1;
288 m_maxSizeX = -1;
289 m_maxSizeY = -1;
290 m_defaultItem = NULL;
291 m_windowParent = NULL;
292 m_clientObject = (wxClientData*) NULL;
293 m_clientData = NULL;
294
295 // Motif-specific
296 m_needsRefresh = TRUE;
297 m_canAddEventHandler = FALSE;
298 m_mainWidget = (WXWidget) 0;
299 m_button1Pressed = FALSE;
300 m_button2Pressed = FALSE;
301 m_button3Pressed = FALSE;
302 m_winCaptured = FALSE;
303 m_isShown = TRUE;
304 m_hScrollBar = (WXWidget) 0;
305 m_vScrollBar = (WXWidget) 0;
306 m_borderWidget = (WXWidget) 0;
307 m_scrolledWindow = (WXWidget) 0;
308 m_drawingArea = (WXWidget) 0;
309 m_hScroll = FALSE;
310 m_vScroll = FALSE;
311 m_backingPixmap = (WXPixmap) 0;
312 m_pixmapWidth = 0;
313 m_pixmapHeight = 0;
314 m_pixmapOffsetX = 0;
315 m_pixmapOffsetY = 0;
316 m_scrollPosX = 0;
317 m_scrollPosY = 0;
318
319 if (!parent)
320 return FALSE;
321
322 if (parent) parent->AddChild(this);
323
324 m_returnCode = 0;
325
326 SetName(name);
327
328 if ( id == -1 )
329 m_windowId = (int)NewControlId();
330 else
331 m_windowId = id;
332
333 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
334 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
335 m_foregroundColour = *wxBLACK;
336
337 m_windowStyle = style;
338
339 if ( id == -1 )
340 m_windowId = (int)NewControlId();
341 else
342 m_windowId = id;
343
344 //// TODO: we should probably optimize by only creating a
345 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
346 //// But for now, let's simplify things by always creating the
347 //// drawing area, since otherwise the translations are different.
348
349 // New translations for getting mouse motion feedback
350 String translations =
351 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
352 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
353 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
354 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
355 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
356 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
357 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
358 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
359 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
360 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
361 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
362 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
363 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
364 <Key>: DrawingAreaInput()";
365
366 XtActionsRec actions[1];
367 actions[0].string = "wxCanvasMotionEvent";
368 actions[0].proc = (XtActionProc) wxCanvasMotionEvent;
369 XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1);
370
371 Widget parentWidget = (Widget) parent->GetClientWidget();
372 if (style & wxBORDER)
373 m_borderWidget = (WXWidget) XtVaCreateManagedWidget ("canvasBorder",
374 xmFrameWidgetClass, parentWidget,
375 XmNshadowType, XmSHADOW_IN,
376 NULL);
377
378 m_scrolledWindow = (WXWidget) XtVaCreateManagedWidget ("scrolledWindow",
379 xmScrolledWindowWidgetClass, m_borderWidget ? (Widget) m_borderWidget : parentWidget,
380 XmNresizePolicy, XmRESIZE_NONE,
381 XmNspacing, 0,
382 XmNscrollingPolicy, XmAPPLICATION_DEFINED,
383 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
384 NULL);
385
386 XtTranslations ptr;
387 m_drawingArea = (WXWidget) XtVaCreateWidget ((char*) (const char*) name,
388 xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow,
389 XmNunitType, XmPIXELS,
390 // XmNresizePolicy, XmRESIZE_ANY,
391 XmNresizePolicy, XmRESIZE_NONE,
392 XmNmarginHeight, 0,
393 XmNmarginWidth, 0,
394 XmNtranslations, ptr = XtParseTranslationTable (translations),
395 NULL);
396 /*
397 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
398 {
399 XtFree ((char *) ptr);
400 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
401 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
402 XtFree ((char *) ptr);
403 }
404 */
405
406 wxAddWindowToTable((Widget) m_drawingArea, this);
407 wxAddWindowToTable((Widget) m_scrolledWindow, this);
408
409 /*
410 * This order is very important in Motif 1.2.1
411 *
412 */
413
414 XtRealizeWidget ((Widget) m_scrolledWindow);
415 XtRealizeWidget ((Widget) m_drawingArea);
416 XtManageChild ((Widget) m_drawingArea);
417
418 XtOverrideTranslations ((Widget) m_drawingArea,
419 ptr = XtParseTranslationTable ("<Configure>: resize()"));
420 XtFree ((char *) ptr);
421
422 XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this);
423 XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this);
424
425 /* TODO?
426 display = XtDisplay (scrolledWindow);
427 xwindow = XtWindow (drawingArea);
428 */
429
430 XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask,
431 False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this);
432
433 // Scrolled widget needs to have its colour changed or we get
434 // a little blue square where the scrollbars abutt
435 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
436 DoChangeBackgroundColour(m_scrolledWindow, backgroundColour, TRUE);
437 DoChangeBackgroundColour(m_drawingArea, backgroundColour, TRUE);
438
439 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) 0, (Widget) 0, (Widget) m_drawingArea);
440
441 /*
442 if (m_hScrollBar)
443 XtRealizeWidget ((Widget) m_hScrollBar);
444 if (m_vScrollBar)
445 XtRealizeWidget ((Widget) m_vScrollBar);
446 */
447
448 // Without this, the cursor may not be restored properly
449 // (e.g. in splitter sample).
450 SetCursor(*wxSTANDARD_CURSOR);
451 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
452 SetSize(pos.x, pos.y, size.x, size.y);
453
454 return TRUE;
455 }
456
457 // Helper function
458 void wxWindow::CreateScrollbar(int orientation)
459 {
460 if (!m_drawingArea)
461 return;
462
463 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
464
465 // Add scrollbars if required
466 if (orientation == wxHORIZONTAL)
467 {
468 Widget hScrollBar = XtVaCreateManagedWidget ("hsb",
469 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
470 XmNorientation, XmHORIZONTAL,
471 NULL);
472 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
473 XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
474 XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
475 XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
476 XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
477 XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
478 XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
479 XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
480
481 XtVaSetValues (hScrollBar,
482 XmNincrement, 1,
483 XmNvalue, 0,
484 NULL);
485
486 m_hScrollBar = (WXWidget) hScrollBar;
487
488 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
489 DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE);
490
491 XtRealizeWidget(hScrollBar);
492
493 XtVaSetValues((Widget) m_scrolledWindow,
494 XmNhorizontalScrollBar, (Widget) m_hScrollBar,
495 NULL);
496
497 m_hScroll = TRUE;
498 }
499
500 if (orientation == wxVERTICAL)
501 {
502 Widget vScrollBar = XtVaCreateManagedWidget ("vsb",
503 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
504 XmNorientation, XmVERTICAL,
505 NULL);
506 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
507 XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
508 XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
509 XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
510 XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
511 XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
512 XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
513 XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
514
515 XtVaSetValues (vScrollBar,
516 XmNincrement, 1,
517 XmNvalue, 0,
518 NULL);
519
520 m_vScrollBar = (WXWidget) vScrollBar;
521 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
522 DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE);
523
524 XtRealizeWidget(vScrollBar);
525
526 XtVaSetValues((Widget) m_scrolledWindow,
527 XmNverticalScrollBar, (Widget) m_vScrollBar,
528 NULL);
529
530 m_vScroll = TRUE;
531 }
532
533 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
534 }
535 void wxWindow::DestroyScrollbar(int orientation)
536 {
537 if (!m_drawingArea)
538 return;
539
540 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
541 // Add scrollbars if required
542 if (orientation == wxHORIZONTAL)
543 {
544 if (m_hScrollBar)
545 {
546 XtDestroyWidget((Widget) m_hScrollBar);
547 }
548 m_hScrollBar = (WXWidget) 0;
549 m_hScroll = FALSE;
550
551 XtVaSetValues((Widget) m_scrolledWindow,
552 XmNhorizontalScrollBar, (Widget) 0,
553 NULL);
554
555 }
556
557 if (orientation == wxVERTICAL)
558 {
559 if (m_vScrollBar)
560 {
561 XtDestroyWidget((Widget) m_vScrollBar);
562 }
563 m_vScrollBar = (WXWidget) 0;
564 m_vScroll = TRUE;
565
566 XtVaSetValues((Widget) m_scrolledWindow,
567 XmNverticalScrollBar, (Widget) 0,
568 NULL);
569
570 }
571 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
572 }
573
574 void wxWindow::SetFocus()
575 {
576 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
577 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
578 }
579
580 void wxWindow::Enable(bool enable)
581 {
582 if (GetMainWidget())
583 {
584 XtSetSensitive((Widget) GetMainWidget(), enable);
585 XmUpdateDisplay((Widget) GetMainWidget());
586 }
587 }
588
589 void wxWindow::CaptureMouse()
590 {
591 if (m_winCaptured)
592 return;
593
594 if (GetMainWidget())
595 XtAddGrab((Widget) GetMainWidget(), TRUE, FALSE);
596
597 m_winCaptured = TRUE;
598 }
599
600 void wxWindow::ReleaseMouse()
601 {
602 if (!m_winCaptured)
603 return;
604
605 if (GetMainWidget())
606 XtRemoveGrab((Widget) GetMainWidget());
607 m_winCaptured = FALSE;
608 }
609
610 // Push/pop event handler (i.e. allow a chain of event handlers
611 // be searched)
612 void wxWindow::PushEventHandler(wxEvtHandler *handler)
613 {
614 handler->SetNextHandler(GetEventHandler());
615 SetEventHandler(handler);
616 }
617
618 wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
619 {
620 if ( GetEventHandler() )
621 {
622 wxEvtHandler *handlerA = GetEventHandler();
623 wxEvtHandler *handlerB = handlerA->GetNextHandler();
624 handlerA->SetNextHandler(NULL);
625 SetEventHandler(handlerB);
626 if ( deleteHandler )
627 {
628 delete handlerA;
629 return NULL;
630 }
631 else
632 return handlerA;
633 }
634 else
635 return NULL;
636 }
637
638 #if wxUSE_DRAG_AND_DROP
639
640 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
641 {
642 if ( m_pDropTarget != 0 ) {
643 delete m_pDropTarget;
644 }
645
646 m_pDropTarget = pDropTarget;
647 if ( m_pDropTarget != 0 )
648 {
649 // TODO
650 }
651 }
652
653 #endif
654
655 // Old style file-manager drag&drop
656 void wxWindow::DragAcceptFiles(bool accept)
657 {
658 // TODO
659 }
660
661 // Get total size
662 void wxWindow::GetSize(int *x, int *y) const
663 {
664 if (m_drawingArea)
665 {
666 CanvasGetSize(x, y);
667 return;
668 }
669
670 Widget widget = (Widget) GetTopWidget();
671 Dimension xx, yy;
672 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
673 *x = xx; *y = yy;
674 }
675
676 void wxWindow::GetPosition(int *x, int *y) const
677 {
678 if (m_drawingArea)
679 {
680 CanvasGetPosition(x, y);
681 return;
682 }
683 Widget widget = (Widget) GetTopWidget();
684 Position xx, yy;
685 XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL);
686
687 // We may be faking the client origin.
688 // So a window that's really at (0, 30) may appear
689 // (to wxWin apps) to be at (0, 0).
690 if (GetParent())
691 {
692 wxPoint pt(GetParent()->GetClientAreaOrigin());
693 xx -= pt.x;
694 yy -= pt.y;
695 }
696
697 *x = xx; *y = yy;
698 }
699
700 void wxWindow::ScreenToClient(int *x, int *y) const
701 {
702 Widget widget = (Widget) GetClientWidget();
703 Display *display = XtDisplay((Widget) GetMainWidget());
704 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
705 Window thisWindow = XtWindow(widget);
706
707 Window childWindow;
708 int xx = *x;
709 int yy = *y;
710 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
711 }
712
713 void wxWindow::ClientToScreen(int *x, int *y) const
714 {
715 Widget widget = (Widget) GetClientWidget();
716 Display *display = XtDisplay(widget);
717 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
718 Window thisWindow = XtWindow(widget);
719
720 Window childWindow;
721 int xx = *x;
722 int yy = *y;
723 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
724 }
725
726 void wxWindow::SetCursor(const wxCursor& cursor)
727 {
728 m_windowCursor = cursor;
729 if (m_windowCursor.Ok())
730 {
731 WXDisplay *dpy = GetXDisplay();
732 WXCursor x_cursor = ((wxCursor&)cursor).GetXCursor(dpy);
733
734 Widget w = (Widget) GetMainWidget();
735 Window win = XtWindow(w);
736 XDefineCursor((Display*) dpy, win, (Cursor) x_cursor);
737 }
738 }
739
740
741 // Get size *available for subwindows* i.e. excluding menu bar etc.
742 void wxWindow::GetClientSize(int *x, int *y) const
743 {
744 Widget widget = (Widget) GetClientWidget();
745 Dimension xx, yy;
746 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
747 *x = xx; *y = yy;
748 }
749
750 void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
751 {
752 // A bit of optimization to help sort out the flickers.
753 int oldX, oldY, oldW, oldH;
754 GetSize(& oldW, & oldH);
755 GetPosition(& oldX, & oldY);
756
757 bool useOldPos = FALSE;
758 bool useOldSize = FALSE;
759
760 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
761 useOldPos = TRUE;
762 else if (x == oldX && y == oldY)
763 useOldPos = TRUE;
764
765 if ((width == -1) && (height == -1))
766 useOldSize = TRUE;
767 else if (width == oldW && height == oldH)
768 useOldSize = TRUE;
769
770 if (!wxNoOptimize::CanOptimize())
771 {
772 useOldSize = FALSE; useOldPos = FALSE;
773 }
774
775 if (useOldPos && useOldSize)
776 return;
777
778 if (m_drawingArea)
779 {
780 CanvasSetSize(x, y, width, height, sizeFlags);
781 return;
782 }
783 Widget widget = (Widget) GetTopWidget();
784 if (!widget)
785 return;
786
787 bool managed = XtIsManaged( widget );
788 if (managed)
789 XtUnmanageChild(widget);
790
791 int xx = x; int yy = y;
792 AdjustForParentClientOrigin(xx, yy, sizeFlags);
793
794 if (!useOldPos)
795 {
796 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
797 XtVaSetValues(widget, XmNx, xx, NULL);
798 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
799 XtVaSetValues(widget, XmNy, yy, NULL);
800 }
801 if (!useOldSize)
802 {
803 if (width > -1)
804 XtVaSetValues(widget, XmNwidth, width, NULL);
805 if (height > -1)
806 XtVaSetValues(widget, XmNheight, height, NULL);
807 }
808
809 if (managed)
810 XtManageChild(widget);
811
812 // How about this bit. Maybe we don't need to generate size events
813 // all the time -- they'll be generated when the window is sized anyway.
814 /*
815 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
816 sizeEvent.SetEventObject(this);
817
818 GetEventHandler()->ProcessEvent(sizeEvent);
819 */
820 }
821
822 void wxWindow::SetClientSize(int width, int height)
823 {
824 if (m_drawingArea)
825 {
826 CanvasSetClientSize(width, height);
827 return;
828 }
829
830 Widget widget = (Widget) GetTopWidget();
831
832 if (width > -1)
833 XtVaSetValues(widget, XmNwidth, width, NULL);
834 if (height > -1)
835 XtVaSetValues(widget, XmNheight, height, NULL);
836
837 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
838 sizeEvent.SetEventObject(this);
839
840 GetEventHandler()->ProcessEvent(sizeEvent);
841 }
842
843 // For implementation purposes - sometimes decorations make the client area
844 // smaller
845 wxPoint wxWindow::GetClientAreaOrigin() const
846 {
847 return wxPoint(0, 0);
848 }
849
850 // Makes an adjustment to the window position (for example, a frame that has
851 // a toolbar that it manages itself).
852 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
853 {
854 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
855 {
856 wxPoint pt(GetParent()->GetClientAreaOrigin());
857 x += pt.x; y += pt.y;
858 }
859 }
860
861 bool wxWindow::Show(bool show)
862 {
863 if (show)
864 {
865 if (m_borderWidget || m_scrolledWindow)
866 {
867 if (m_drawingArea)
868 XtMapWidget((Widget) m_drawingArea);
869 XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
870 }
871 else
872 {
873 WXWidget topWidget = GetTopWidget();
874 if (GetTopWidget())
875 XtMapWidget((Widget) GetTopWidget());
876 else if (GetMainWidget())
877 XtMapWidget((Widget) GetMainWidget());
878 }
879 }
880 else
881 {
882 if (m_borderWidget || m_scrolledWindow)
883 {
884 if (m_drawingArea)
885 XtUnmapWidget((Widget) m_drawingArea);
886 XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
887 }
888 else
889 {
890 if (GetTopWidget())
891 XtUnmapWidget((Widget) GetTopWidget());
892 else if (GetMainWidget())
893 XtUnmapWidget((Widget) GetMainWidget());
894 }
895 }
896
897 /*
898 Window xwin = (Window) GetXWindow();
899 Display *xdisp = (Display*) GetXDisplay();
900 if (show)
901 XMapWindow(xdisp, xwin);
902 else
903 XUnmapWindow(xdisp, xwin);
904 */
905
906 m_isShown = show;
907
908 return TRUE;
909 }
910
911 bool wxWindow::IsShown() const
912 {
913 return m_isShown;
914 }
915
916 int wxWindow::GetCharHeight() const
917 {
918 if (!m_windowFont.Ok())
919 return 0;
920
921 WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
922
923 int direction, ascent, descent;
924 XCharStruct overall;
925 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
926 &descent, &overall);
927 // return (overall.ascent + overall.descent);
928 return (ascent + descent);
929 }
930
931 int wxWindow::GetCharWidth() const
932 {
933 if (!m_windowFont.Ok())
934 return 0;
935
936 WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
937
938 int direction, ascent, descent;
939 XCharStruct overall;
940 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
941 &descent, &overall);
942 return overall.width;
943 }
944
945 /* Helper function for 16-bit fonts */
946 static int str16len(const char *s)
947 {
948 int count = 0;
949
950 while (s[0] && s[1]) {
951 count++;
952 s += 2;
953 }
954
955 return count;
956 }
957
958 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
959 int *descent, int *externalLeading, const wxFont *theFont, bool use16) const
960 {
961 wxFont *fontToUse = (wxFont *)theFont;
962 if (!fontToUse)
963 fontToUse = (wxFont *) & m_windowFont;
964
965 if (!fontToUse->Ok())
966 return;
967
968 WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
969
970 int direction, ascent, descent2;
971 XCharStruct overall;
972 int slen;
973
974 if (use16) slen = str16len(string); else slen = strlen(string);
975
976 if (use16)
977 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
978 &ascent, &descent2, &overall);
979 else
980 XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction,
981 &ascent, &descent2, &overall);
982
983 *x = (overall.width);
984 *y = (ascent + descent2);
985 if (descent)
986 *descent = descent2;
987 if (externalLeading)
988 *externalLeading = 0;
989 }
990
991 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
992 {
993 m_needsRefresh = TRUE;
994 Display *display = XtDisplay((Widget) GetMainWidget());
995 Window thisWindow = XtWindow((Widget) GetMainWidget());
996
997 XExposeEvent dummyEvent;
998 int width, height;
999 GetSize(&width, &height);
1000
1001 dummyEvent.type = Expose;
1002 dummyEvent.display = display;
1003 dummyEvent.send_event = True;
1004 dummyEvent.window = thisWindow;
1005 if (rect)
1006 {
1007 dummyEvent.x = rect->x;
1008 dummyEvent.y = rect->y;
1009 dummyEvent.width = rect->width;
1010 dummyEvent.height = rect->height;
1011 }
1012 else
1013 {
1014 dummyEvent.x = 0;
1015 dummyEvent.y = 0;
1016 dummyEvent.width = width;
1017 dummyEvent.height = height;
1018 }
1019 dummyEvent.count = 0;
1020
1021 if (eraseBack)
1022 {
1023 wxClientDC dc(this);
1024 wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID);
1025 dc.SetBackground(backgroundBrush);
1026 if (rect)
1027 dc.Clear(*rect);
1028 else
1029 dc.Clear();
1030 }
1031
1032 XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
1033 }
1034
1035 // Responds to colour changes: passes event on to children.
1036 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
1037 {
1038 wxNode *node = GetChildren().First();
1039 while ( node )
1040 {
1041 // Only propagate to non-top-level windows
1042 wxWindow *win = (wxWindow *)node->Data();
1043 if ( win->GetParent() )
1044 {
1045 wxSysColourChangedEvent event2;
1046 event.m_eventObject = win;
1047 win->GetEventHandler()->ProcessEvent(event2);
1048 }
1049
1050 node = node->Next();
1051 }
1052 }
1053
1054 // This can be called by the app (or wxWindows) to do default processing for the current
1055 // event. Save message/event info in wxWindow so they can be used in this function.
1056 long wxWindow::Default()
1057 {
1058 // TODO
1059 return 0;
1060 }
1061
1062 void wxWindow::InitDialog()
1063 {
1064 wxInitDialogEvent event(GetId());
1065 event.SetEventObject( this );
1066 GetEventHandler()->ProcessEvent(event);
1067 }
1068
1069 // Default init dialog behaviour is to transfer data to window
1070 void wxWindow::OnInitDialog(wxInitDialogEvent& event)
1071 {
1072 TransferDataToWindow();
1073 }
1074
1075 // Caret manipulation
1076 void wxWindow::CreateCaret(int w, int h)
1077 {
1078 m_caretWidth = w;
1079 m_caretHeight = h;
1080 m_caretEnabled = TRUE;
1081 }
1082
1083 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
1084 {
1085 // TODO
1086 }
1087
1088 void wxWindow::ShowCaret(bool show)
1089 {
1090 // TODO
1091 }
1092
1093 void wxWindow::DestroyCaret()
1094 {
1095 // TODO
1096 m_caretEnabled = FALSE;
1097 }
1098
1099 void wxWindow::SetCaretPos(int x, int y)
1100 {
1101 // TODO
1102 }
1103
1104 void wxWindow::GetCaretPos(int *x, int *y) const
1105 {
1106 // TODO
1107 }
1108
1109 wxWindow *wxGetActiveWindow()
1110 {
1111 // TODO
1112 return NULL;
1113 }
1114
1115 void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
1116 {
1117 m_minSizeX = minW;
1118 m_minSizeY = minH;
1119 m_maxSizeX = maxW;
1120 m_maxSizeY = maxH;
1121
1122 if (!this->IsKindOf(CLASSINFO(wxFrame)))
1123 return;
1124
1125 wxFrame *frame = (wxFrame *)this;
1126 Widget widget = (Widget) frame->GetShellWidget();
1127
1128 if (minW > -1)
1129 XtVaSetValues(widget, XmNminWidth, minW, NULL);
1130 if (minH > -1)
1131 XtVaSetValues(widget, XmNminHeight, minH, NULL);
1132 if (maxW > -1)
1133 XtVaSetValues(widget, XmNmaxWidth, maxW, NULL);
1134 if (maxH > -1)
1135 XtVaSetValues(widget, XmNmaxHeight, maxH, NULL);
1136 if (incW > -1)
1137 XtVaSetValues(widget, XmNwidthInc, incW, NULL);
1138 if (incH > -1)
1139 XtVaSetValues(widget, XmNheightInc, incH, NULL);
1140 }
1141
1142 void wxWindow::Centre(int direction)
1143 {
1144 int x, y, width, height, panel_width, panel_height, new_x, new_y;
1145
1146 wxWindow *father = (wxWindow *)GetParent();
1147 if (!father)
1148 return;
1149
1150 father->GetClientSize(&panel_width, &panel_height);
1151 GetSize(&width, &height);
1152 GetPosition(&x, &y);
1153
1154 new_x = -1;
1155 new_y = -1;
1156
1157 if (direction & wxHORIZONTAL)
1158 new_x = (int)((panel_width - width)/2);
1159
1160 if (direction & wxVERTICAL)
1161 new_y = (int)((panel_height - height)/2);
1162
1163 SetSize(new_x, new_y, -1, -1);
1164
1165 }
1166
1167 // Coordinates relative to the window
1168 void wxWindow::WarpPointer (int x, int y)
1169 {
1170 XWarpPointer (XtDisplay((Widget) GetClientWidget()), None, XtWindow((Widget) GetClientWidget()), 0, 0, 0, 0, x, y);
1171 }
1172
1173 void wxWindow::OnEraseBackground(wxEraseEvent& event)
1174 {
1175 // TODO
1176 Default();
1177 }
1178
1179 int wxWindow::GetScrollPos(int orient) const
1180 {
1181 if (orient == wxHORIZONTAL)
1182 return m_scrollPosX;
1183 else
1184 return m_scrollPosY;
1185 /*
1186 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1187 if (scrollBar)
1188 {
1189 int pos;
1190 XtVaGetValues(scrollBar,
1191 XmNvalue, &pos, NULL);
1192 return pos;
1193 }
1194 else
1195 return 0;
1196 */
1197 }
1198
1199 // This now returns the whole range, not just the number
1200 // of positions that we can scroll.
1201 int wxWindow::GetScrollRange(int orient) const
1202 {
1203 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1204 if (scrollBar)
1205 {
1206 int range;
1207 XtVaGetValues(scrollBar,
1208 XmNmaximum, &range, NULL);
1209 return range;
1210 }
1211 else
1212 return 0;
1213 }
1214
1215 int wxWindow::GetScrollThumb(int orient) const
1216 {
1217 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1218 if (scrollBar)
1219 {
1220 int thumb;
1221 XtVaGetValues(scrollBar,
1222 XmNsliderSize, &thumb, NULL);
1223 return thumb;
1224 }
1225 else
1226 return 0;
1227 }
1228
1229 void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1230 {
1231 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1232 if (scrollBar)
1233 {
1234 XtVaSetValues (scrollBar,
1235 XmNvalue, pos,
1236 NULL);
1237 }
1238 if (orient == wxHORIZONTAL)
1239 m_scrollPosX = pos;
1240 else
1241 m_scrollPosY = pos;
1242
1243 }
1244
1245 // New function that will replace some of the above.
1246 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
1247 int range, bool WXUNUSED(refresh))
1248 {
1249 int oldW, oldH;
1250 GetSize(& oldW, & oldH);
1251
1252 if (range == 0)
1253 range = 1;
1254 if (thumbVisible == 0)
1255 thumbVisible = 1;
1256
1257 if (thumbVisible > range)
1258 thumbVisible = range;
1259
1260 // Save the old state to see if it changed
1261 WXWidget oldScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar );
1262
1263 if (orient == wxHORIZONTAL)
1264 {
1265 if (thumbVisible == range)
1266 {
1267 if (m_hScrollBar)
1268 DestroyScrollbar(wxHORIZONTAL);
1269 }
1270 else
1271 {
1272 if (!m_hScrollBar)
1273 CreateScrollbar(wxHORIZONTAL);
1274 }
1275 }
1276 if (orient == wxVERTICAL)
1277 {
1278 if (thumbVisible == range)
1279 {
1280 if (m_vScrollBar)
1281 DestroyScrollbar(wxVERTICAL);
1282 }
1283 else
1284 {
1285 if (!m_vScrollBar)
1286 CreateScrollbar(wxVERTICAL);
1287 }
1288 }
1289 WXWidget newScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar );
1290
1291 if (oldScrollBar != newScrollBar)
1292 {
1293 // This is important! Without it, scrollbars misbehave
1294 // badly.
1295 XtUnrealizeWidget((Widget) m_scrolledWindow);
1296 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea);
1297 XtRealizeWidget((Widget) m_scrolledWindow);
1298 XtManageChild((Widget) m_scrolledWindow);
1299 }
1300
1301 if (newScrollBar)
1302 XtVaSetValues((Widget) newScrollBar,
1303 XmNvalue, pos,
1304 XmNminimum, 0,
1305 XmNmaximum, range,
1306 XmNsliderSize, thumbVisible,
1307 NULL);
1308
1309 if (orient == wxHORIZONTAL)
1310 m_scrollPosX = pos;
1311 else
1312 m_scrollPosY = pos;
1313
1314 int newW, newH;
1315 GetSize(& newW, & newH);
1316
1317 // Adjusting scrollbars can resize the canvas accidentally
1318 if (newW != oldW || newH != oldH)
1319 SetSize(-1, -1, oldW, oldH);
1320 }
1321
1322 // Does a physical scroll
1323 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1324 {
1325 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1326 int x, y, w, h;
1327 if (rect)
1328 {
1329 // Use specified rectangle
1330 x = rect->x; y = rect->y; w = rect->width; h = rect->height;
1331 }
1332 else
1333 {
1334 // Use whole client area
1335 x = 0; y = 0;
1336 GetClientSize(& w, & h);
1337 }
1338
1339 int x1 = (dx >= 0) ? x : x - dx ;
1340 int y1 = (dy >= 0) ? y : y - dy;
1341 int w1 = w - abs(dx);
1342 int h1 = h - abs(dy);
1343 int x2 = (dx >= 0) ? x + dx : x;
1344 int y2 = (dy >= 0) ? y + dy : y;
1345
1346 wxClientDC dc(this);
1347
1348 dc.SetLogicalFunction (wxCOPY);
1349
1350 Widget widget = (Widget) GetMainWidget();
1351 Window window = XtWindow(widget);
1352 Display* display = XtDisplay(widget);
1353
1354 XCopyArea(display, window,
1355 window, (GC) dc.GetGC(),
1356 x1, y1,
1357 w1, h1,
1358 x2, y2);
1359
1360 dc.SetAutoSetting(TRUE);
1361 wxBrush brush(GetBackgroundColour(), wxSOLID);
1362 dc.SetBrush(brush); // ??
1363
1364 // We'll add rectangles to the list of update rectangles
1365 // according to which bits we've exposed.
1366 wxList updateRects;
1367
1368 if (dx > 0)
1369 {
1370 wxRect *rect = new wxRect;
1371 rect->x = x;
1372 rect->y = y;
1373 rect->width = dx;
1374 rect->height = h;
1375
1376 XFillRectangle(display, window,
1377 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1378
1379 rect->x = rect->x;
1380 rect->y = rect->y;
1381 rect->width = rect->width;
1382 rect->height = rect->height;
1383
1384 updateRects.Append((wxObject*) rect);
1385 }
1386 else if (dx < 0)
1387 {
1388 wxRect *rect = new wxRect;
1389
1390 rect->x = x + w + dx;
1391 rect->y = y;
1392 rect->width = -dx;
1393 rect->height = h;
1394
1395 XFillRectangle(display, window,
1396 (GC) dc.GetGC(), rect->x, rect->y, rect->width,
1397 rect->height);
1398
1399 rect->x = rect->x;
1400 rect->y = rect->y;
1401 rect->width = rect->width;
1402 rect->height = rect->height;
1403
1404 updateRects.Append((wxObject*) rect);
1405 }
1406 if (dy > 0)
1407 {
1408 wxRect *rect = new wxRect;
1409
1410 rect->x = x;
1411 rect->y = y;
1412 rect->width = w;
1413 rect->height = dy;
1414
1415 XFillRectangle(display, window,
1416 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1417
1418 rect->x = rect->x;
1419 rect->y = rect->y;
1420 rect->width = rect->width;
1421 rect->height = rect->height;
1422
1423 updateRects.Append((wxObject*) rect);
1424 }
1425 else if (dy < 0)
1426 {
1427 wxRect *rect = new wxRect;
1428
1429 rect->x = x;
1430 rect->y = y + h + dy;
1431 rect->width = w;
1432 rect->height = -dy;
1433
1434 XFillRectangle(display, window,
1435 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1436
1437 rect->x = rect->x;
1438 rect->y = rect->y;
1439 rect->width = rect->width;
1440 rect->height = rect->height;
1441
1442 updateRects.Append((wxObject*) rect);
1443 }
1444 dc.SetBrush(wxNullBrush);
1445
1446 // Now send expose events
1447
1448 wxNode* node = updateRects.First();
1449 while (node)
1450 {
1451 wxRect* rect = (wxRect*) node->Data();
1452 XExposeEvent event;
1453
1454 event.type = Expose;
1455 event.display = display;
1456 event.send_event = True;
1457 event.window = window;
1458
1459 event.x = rect->x;
1460 event.y = rect->y;
1461 event.width = rect->width;
1462 event.height = rect->height;
1463
1464 event.count = 0;
1465
1466 XSendEvent(display, window, False, ExposureMask, (XEvent *)&event);
1467
1468 node = node->Next();
1469
1470 }
1471
1472 // Delete the update rects
1473 node = updateRects.First();
1474 while (node)
1475 {
1476 wxRect* rect = (wxRect*) node->Data();
1477 delete rect;
1478 node = node->Next();
1479 }
1480
1481 XmUpdateDisplay((Widget) GetMainWidget());
1482 }
1483
1484 void wxWindow::OnChar(wxKeyEvent& event)
1485 {
1486 event.Skip();
1487 /* ??
1488 if ( event.KeyCode() == WXK_TAB ) {
1489 // propagate the TABs to the parent - it's up to it to decide what
1490 // to do with it
1491 if ( GetParent() ) {
1492 if ( GetParent()->ProcessEvent(event) )
1493 return;
1494 }
1495 }
1496 */
1497 }
1498
1499 void wxWindow::OnKeyDown(wxKeyEvent& event)
1500 {
1501 event.Skip();
1502 }
1503
1504 void wxWindow::OnKeyUp(wxKeyEvent& event)
1505 {
1506 event.Skip();
1507 }
1508
1509 void wxWindow::OnPaint(wxPaintEvent& event)
1510 {
1511 Default();
1512 }
1513
1514 bool wxWindow::IsEnabled() const
1515 {
1516 // TODO. Is this right?
1517 // return XtGetSensitive((Widget) GetMainWidget());
1518 return FALSE;
1519 }
1520
1521 // Dialog support: override these and call
1522 // base class members to add functionality
1523 // that can't be done using validators.
1524 // NOTE: these functions assume that controls
1525 // are direct children of this window, not grandchildren
1526 // or other levels of descendant.
1527
1528 // Transfer values to controls. If returns FALSE,
1529 // it's an application error (pops up a dialog)
1530 bool wxWindow::TransferDataToWindow()
1531 {
1532 wxNode *node = GetChildren().First();
1533 while ( node )
1534 {
1535 wxWindow *child = (wxWindow *)node->Data();
1536 if ( child->GetValidator() &&
1537 !child->GetValidator()->TransferToWindow() )
1538 {
1539 wxLogError("Could not transfer data to window.");
1540 return FALSE;
1541 }
1542
1543 node = node->Next();
1544 }
1545 return TRUE;
1546 }
1547
1548 // Transfer values from controls. If returns FALSE,
1549 // validation failed: don't quit
1550 bool wxWindow::TransferDataFromWindow()
1551 {
1552 wxNode *node = GetChildren().First();
1553 while ( node )
1554 {
1555 wxWindow *child = (wxWindow *)node->Data();
1556 if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() )
1557 {
1558 return FALSE;
1559 }
1560
1561 node = node->Next();
1562 }
1563 return TRUE;
1564 }
1565
1566 bool wxWindow::Validate()
1567 {
1568 wxNode *node = GetChildren().First();
1569 while ( node )
1570 {
1571 wxWindow *child = (wxWindow *)node->Data();
1572 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
1573 {
1574 return FALSE;
1575 }
1576
1577 node = node->Next();
1578 }
1579 return TRUE;
1580 }
1581
1582 // Get the window with the focus
1583 wxWindow *wxWindow::FindFocus()
1584 {
1585 // TODO
1586 return NULL;
1587 }
1588
1589 void wxWindow::AddChild(wxWindow *child)
1590 {
1591 GetChildren().Append(child);
1592 child->m_windowParent = this;
1593 }
1594
1595 void wxWindow::RemoveChild(wxWindow *child)
1596 {
1597 GetChildren().DeleteObject(child);
1598 child->m_windowParent = NULL;
1599 }
1600
1601 // Reparents this window to have the new parent.
1602 bool wxWindow::Reparent(wxWindow* WXUNUSED(parent))
1603 {
1604 // For now, we indicate that this isn't implemented.
1605 return FALSE;
1606 }
1607
1608 void wxWindow::DestroyChildren()
1609 {
1610 wxNode *node = GetChildren().First();
1611 while (node)
1612 {
1613 wxNode* next = node->Next();
1614 wxWindow* child = (wxWindow*) node->Data();
1615 delete child;
1616 node = next;
1617 }
1618 GetChildren().Clear();
1619 #if 0
1620 wxNode *node;
1621 while ((node = GetChildren().First()) != (wxNode *)NULL) {
1622 wxWindow *child;
1623 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
1624 delete child;
1625 if ( GetChildren().Member(child) )
1626 delete node;
1627 }
1628 } /* while */
1629 #endif
1630 }
1631
1632 void wxWindow::MakeModal(bool modal)
1633 {
1634 // Disable all other windows
1635 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
1636 {
1637 wxNode *node = wxTopLevelWindows.First();
1638 while (node)
1639 {
1640 wxWindow *win = (wxWindow *)node->Data();
1641 if (win != this)
1642 win->Enable(!modal);
1643
1644 node = node->Next();
1645 }
1646 }
1647 }
1648
1649 // If nothing defined for this, try the parent.
1650 // E.g. we may be a button loaded from a resource, with no callback function
1651 // defined.
1652 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1653 {
1654 if (GetEventHandler()->ProcessEvent(event) )
1655 return;
1656 if (m_windowParent)
1657 m_windowParent->GetEventHandler()->OnCommand(win, event);
1658 }
1659
1660 void wxWindow::SetConstraints(wxLayoutConstraints *c)
1661 {
1662 if (m_constraints)
1663 {
1664 UnsetConstraints(m_constraints);
1665 delete m_constraints;
1666 }
1667 m_constraints = c;
1668 if (m_constraints)
1669 {
1670 // Make sure other windows know they're part of a 'meaningful relationship'
1671 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
1672 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1673 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
1674 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1675 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
1676 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1677 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
1678 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1679 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
1680 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1681 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
1682 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1683 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
1684 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1685 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
1686 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1687 }
1688 }
1689
1690 // This removes any dangling pointers to this window
1691 // in other windows' constraintsInvolvedIn lists.
1692 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
1693 {
1694 if (c)
1695 {
1696 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1697 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1698 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1699 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1700 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
1701 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1702 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
1703 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1704 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
1705 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1706 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
1707 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1708 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
1709 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1710 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
1711 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1712 }
1713 }
1714
1715 // Back-pointer to other windows we're involved with, so if we delete
1716 // this window, we must delete any constraints we're involved with.
1717 void wxWindow::AddConstraintReference(wxWindow *otherWin)
1718 {
1719 if (!m_constraintsInvolvedIn)
1720 m_constraintsInvolvedIn = new wxList;
1721 if (!m_constraintsInvolvedIn->Member(otherWin))
1722 m_constraintsInvolvedIn->Append(otherWin);
1723 }
1724
1725 // REMOVE back-pointer to other windows we're involved with.
1726 void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
1727 {
1728 if (m_constraintsInvolvedIn)
1729 m_constraintsInvolvedIn->DeleteObject(otherWin);
1730 }
1731
1732 // Reset any constraints that mention this window
1733 void wxWindow::DeleteRelatedConstraints()
1734 {
1735 if (m_constraintsInvolvedIn)
1736 {
1737 wxNode *node = m_constraintsInvolvedIn->First();
1738 while (node)
1739 {
1740 wxWindow *win = (wxWindow *)node->Data();
1741 wxNode *next = node->Next();
1742 wxLayoutConstraints *constr = win->GetConstraints();
1743
1744 // Reset any constraints involving this window
1745 if (constr)
1746 {
1747 constr->left.ResetIfWin((wxWindow *)this);
1748 constr->top.ResetIfWin((wxWindow *)this);
1749 constr->right.ResetIfWin((wxWindow *)this);
1750 constr->bottom.ResetIfWin((wxWindow *)this);
1751 constr->width.ResetIfWin((wxWindow *)this);
1752 constr->height.ResetIfWin((wxWindow *)this);
1753 constr->centreX.ResetIfWin((wxWindow *)this);
1754 constr->centreY.ResetIfWin((wxWindow *)this);
1755 }
1756 delete node;
1757 node = next;
1758 }
1759 delete m_constraintsInvolvedIn;
1760 m_constraintsInvolvedIn = NULL;
1761 }
1762 }
1763
1764 void wxWindow::SetSizer(wxSizer *sizer)
1765 {
1766 m_windowSizer = sizer;
1767 if (sizer)
1768 sizer->SetSizerParent((wxWindow *)this);
1769 }
1770
1771 /*
1772 * New version
1773 */
1774
1775 bool wxWindow::Layout()
1776 {
1777 if (GetConstraints())
1778 {
1779 int w, h;
1780 GetClientSize(&w, &h);
1781 GetConstraints()->width.SetValue(w);
1782 GetConstraints()->height.SetValue(h);
1783 }
1784
1785 // If top level (one sizer), evaluate the sizer's constraints.
1786 if (GetSizer())
1787 {
1788 int noChanges;
1789 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1790 GetSizer()->LayoutPhase1(&noChanges);
1791 GetSizer()->LayoutPhase2(&noChanges);
1792 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1793 return TRUE;
1794 }
1795 else
1796 {
1797 // Otherwise, evaluate child constraints
1798 ResetConstraints(); // Mark all constraints as unevaluated
1799 DoPhase(1); // Just one phase need if no sizers involved
1800 DoPhase(2);
1801 SetConstraintSizes(); // Recursively set the real window sizes
1802 }
1803 return TRUE;
1804 }
1805
1806
1807 // Do a phase of evaluating constraints:
1808 // the default behaviour. wxSizers may do a similar
1809 // thing, but also impose their own 'constraints'
1810 // and order the evaluation differently.
1811 bool wxWindow::LayoutPhase1(int *noChanges)
1812 {
1813 wxLayoutConstraints *constr = GetConstraints();
1814 if (constr)
1815 {
1816 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
1817 }
1818 else
1819 return TRUE;
1820 }
1821
1822 bool wxWindow::LayoutPhase2(int *noChanges)
1823 {
1824 *noChanges = 0;
1825
1826 // Layout children
1827 DoPhase(1);
1828 DoPhase(2);
1829 return TRUE;
1830 }
1831
1832 // Do a phase of evaluating child constraints
1833 bool wxWindow::DoPhase(int phase)
1834 {
1835 int noIterations = 0;
1836 int maxIterations = 500;
1837 int noChanges = 1;
1838 int noFailures = 0;
1839 wxList succeeded;
1840 while ((noChanges > 0) && (noIterations < maxIterations))
1841 {
1842 noChanges = 0;
1843 noFailures = 0;
1844 wxNode *node = GetChildren().First();
1845 while (node)
1846 {
1847 wxWindow *child = (wxWindow *)node->Data();
1848 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
1849 {
1850 wxLayoutConstraints *constr = child->GetConstraints();
1851 if (constr)
1852 {
1853 if (succeeded.Member(child))
1854 {
1855 }
1856 else
1857 {
1858 int tempNoChanges = 0;
1859 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1860 noChanges += tempNoChanges;
1861 if (success)
1862 {
1863 succeeded.Append(child);
1864 }
1865 }
1866 }
1867 }
1868 node = node->Next();
1869 }
1870 noIterations ++;
1871 }
1872 return TRUE;
1873 }
1874
1875 void wxWindow::ResetConstraints()
1876 {
1877 wxLayoutConstraints *constr = GetConstraints();
1878 if (constr)
1879 {
1880 constr->left.SetDone(FALSE);
1881 constr->top.SetDone(FALSE);
1882 constr->right.SetDone(FALSE);
1883 constr->bottom.SetDone(FALSE);
1884 constr->width.SetDone(FALSE);
1885 constr->height.SetDone(FALSE);
1886 constr->centreX.SetDone(FALSE);
1887 constr->centreY.SetDone(FALSE);
1888 }
1889 wxNode *node = GetChildren().First();
1890 while (node)
1891 {
1892 wxWindow *win = (wxWindow *)node->Data();
1893 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1894 win->ResetConstraints();
1895 node = node->Next();
1896 }
1897 }
1898
1899 // Need to distinguish between setting the 'fake' size for
1900 // windows and sizers, and setting the real values.
1901 void wxWindow::SetConstraintSizes(bool recurse)
1902 {
1903 wxLayoutConstraints *constr = GetConstraints();
1904 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
1905 constr->width.GetDone() && constr->height.GetDone())
1906 {
1907 int x = constr->left.GetValue();
1908 int y = constr->top.GetValue();
1909 int w = constr->width.GetValue();
1910 int h = constr->height.GetValue();
1911
1912 // If we don't want to resize this window, just move it...
1913 if ((constr->width.GetRelationship() != wxAsIs) ||
1914 (constr->height.GetRelationship() != wxAsIs))
1915 {
1916 // Calls Layout() recursively. AAAGH. How can we stop that.
1917 // Simply take Layout() out of non-top level OnSizes.
1918 SizerSetSize(x, y, w, h);
1919 }
1920 else
1921 {
1922 SizerMove(x, y);
1923 }
1924 }
1925 else if (constr)
1926 {
1927 char *windowClass = this->GetClassInfo()->GetClassName();
1928
1929 wxString winName;
1930 if (GetName() == "")
1931 winName = "unnamed";
1932 else
1933 winName = GetName();
1934 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
1935 if (!constr->left.GetDone())
1936 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1937 if (!constr->right.GetDone())
1938 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1939 if (!constr->width.GetDone())
1940 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1941 if (!constr->height.GetDone())
1942 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1943 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1944 }
1945
1946 if (recurse)
1947 {
1948 wxNode *node = GetChildren().First();
1949 while (node)
1950 {
1951 wxWindow *win = (wxWindow *)node->Data();
1952 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1953 win->SetConstraintSizes();
1954 node = node->Next();
1955 }
1956 }
1957 }
1958
1959 // This assumes that all sizers are 'on' the same
1960 // window, i.e. the parent of this window.
1961 void wxWindow::TransformSizerToActual(int *x, int *y) const
1962 {
1963 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
1964 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
1965 return;
1966
1967 int xp, yp;
1968 m_sizerParent->GetPosition(&xp, &yp);
1969 m_sizerParent->TransformSizerToActual(&xp, &yp);
1970 *x += xp;
1971 *y += yp;
1972 }
1973
1974 void wxWindow::SizerSetSize(int x, int y, int w, int h)
1975 {
1976 int xx = x;
1977 int yy = y;
1978 TransformSizerToActual(&xx, &yy);
1979 SetSize(xx, yy, w, h);
1980 }
1981
1982 void wxWindow::SizerMove(int x, int y)
1983 {
1984 int xx = x;
1985 int yy = y;
1986 TransformSizerToActual(&xx, &yy);
1987 Move(xx, yy);
1988 }
1989
1990 // Only set the size/position of the constraint (if any)
1991 void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
1992 {
1993 wxLayoutConstraints *constr = GetConstraints();
1994 if (constr)
1995 {
1996 if (x != -1)
1997 {
1998 constr->left.SetValue(x);
1999 constr->left.SetDone(TRUE);
2000 }
2001 if (y != -1)
2002 {
2003 constr->top.SetValue(y);
2004 constr->top.SetDone(TRUE);
2005 }
2006 if (w != -1)
2007 {
2008 constr->width.SetValue(w);
2009 constr->width.SetDone(TRUE);
2010 }
2011 if (h != -1)
2012 {
2013 constr->height.SetValue(h);
2014 constr->height.SetDone(TRUE);
2015 }
2016 }
2017 }
2018
2019 void wxWindow::MoveConstraint(int x, int y)
2020 {
2021 wxLayoutConstraints *constr = GetConstraints();
2022 if (constr)
2023 {
2024 if (x != -1)
2025 {
2026 constr->left.SetValue(x);
2027 constr->left.SetDone(TRUE);
2028 }
2029 if (y != -1)
2030 {
2031 constr->top.SetValue(y);
2032 constr->top.SetDone(TRUE);
2033 }
2034 }
2035 }
2036
2037 void wxWindow::GetSizeConstraint(int *w, int *h) const
2038 {
2039 wxLayoutConstraints *constr = GetConstraints();
2040 if (constr)
2041 {
2042 *w = constr->width.GetValue();
2043 *h = constr->height.GetValue();
2044 }
2045 else
2046 GetSize(w, h);
2047 }
2048
2049 void wxWindow::GetClientSizeConstraint(int *w, int *h) const
2050 {
2051 wxLayoutConstraints *constr = GetConstraints();
2052 if (constr)
2053 {
2054 *w = constr->width.GetValue();
2055 *h = constr->height.GetValue();
2056 }
2057 else
2058 GetClientSize(w, h);
2059 }
2060
2061 void wxWindow::GetPositionConstraint(int *x, int *y) const
2062 {
2063 wxLayoutConstraints *constr = GetConstraints();
2064 if (constr)
2065 {
2066 *x = constr->left.GetValue();
2067 *y = constr->top.GetValue();
2068 }
2069 else
2070 GetPosition(x, y);
2071 }
2072
2073 bool wxWindow::Close(bool force)
2074 {
2075 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
2076 event.SetEventObject(this);
2077 #if WXWIN_COMPATIBILITY
2078 event.SetForce(force);
2079 #endif
2080 event.SetCanVeto(!force);
2081
2082 return GetEventHandler()->ProcessEvent(event);
2083 }
2084
2085 wxObject* wxWindow::GetChild(int number) const
2086 {
2087 // Return a pointer to the Nth object in the window
2088 wxNode *node = GetChildren().First();
2089 int n = number;
2090 while (node && n--)
2091 node = node->Next() ;
2092 if (node)
2093 {
2094 wxObject *obj = (wxObject *)node->Data();
2095 return(obj) ;
2096 }
2097 else
2098 return NULL ;
2099 }
2100
2101 void wxWindow::OnDefaultAction(wxControl *initiatingItem)
2102 {
2103 // Obsolete function
2104 }
2105
2106 void wxWindow::Clear()
2107 {
2108 wxClientDC dc(this);
2109 wxBrush brush(GetBackgroundColour(), wxSOLID);
2110 dc.SetBackground(brush);
2111 dc.Clear();
2112 }
2113
2114 // Fits the panel around the items
2115 void wxWindow::Fit()
2116 {
2117 int maxX = 0;
2118 int maxY = 0;
2119 wxNode *node = GetChildren().First();
2120 while ( node )
2121 {
2122 wxWindow *win = (wxWindow *)node->Data();
2123 int wx, wy, ww, wh;
2124 win->GetPosition(&wx, &wy);
2125 win->GetSize(&ww, &wh);
2126 if ( wx + ww > maxX )
2127 maxX = wx + ww;
2128 if ( wy + wh > maxY )
2129 maxY = wy + wh;
2130
2131 node = node->Next();
2132 }
2133 SetClientSize(maxX + 5, maxY + 5);
2134 }
2135
2136 void wxWindow::SetValidator(const wxValidator& validator)
2137 {
2138 if ( m_windowValidator )
2139 delete m_windowValidator;
2140 m_windowValidator = validator.Clone();
2141
2142 if ( m_windowValidator )
2143 m_windowValidator->SetWindow(this) ;
2144 }
2145
2146 void wxWindow::SetClientObject( wxClientData *data )
2147 {
2148 if (m_clientObject) delete m_clientObject;
2149 m_clientObject = data;
2150 }
2151
2152 wxClientData *wxWindow::GetClientObject()
2153 {
2154 return m_clientObject;
2155 }
2156
2157 void wxWindow::SetClientData( void *data )
2158 {
2159 m_clientData = data;
2160 }
2161
2162 void *wxWindow::GetClientData()
2163 {
2164 return m_clientData;
2165 }
2166
2167 // Find a window by id or name
2168 wxWindow *wxWindow::FindWindow(long id)
2169 {
2170 if ( GetId() == id)
2171 return this;
2172
2173 wxNode *node = GetChildren().First();
2174 while ( node )
2175 {
2176 wxWindow *child = (wxWindow *)node->Data();
2177 wxWindow *found = child->FindWindow(id);
2178 if ( found )
2179 return found;
2180 node = node->Next();
2181 }
2182 return NULL;
2183 }
2184
2185 wxWindow *wxWindow::FindWindow(const wxString& name)
2186 {
2187 if ( GetName() == name)
2188 return this;
2189
2190 wxNode *node = GetChildren().First();
2191 while ( node )
2192 {
2193 wxWindow *child = (wxWindow *)node->Data();
2194 wxWindow *found = child->FindWindow(name);
2195 if ( found )
2196 return found;
2197 node = node->Next();
2198 }
2199 return NULL;
2200 }
2201
2202 void wxWindow::OnIdle(wxIdleEvent& event)
2203 {
2204 // This calls the UI-update mechanism (querying windows for
2205 // menu/toolbar/control state information)
2206 UpdateWindowUI();
2207 }
2208
2209 // Raise the window to the top of the Z order
2210 void wxWindow::Raise()
2211 {
2212 Window window = XtWindow((Widget) GetTopWidget());
2213 XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window);
2214 }
2215
2216 // Lower the window to the bottom of the Z order
2217 void wxWindow::Lower()
2218 {
2219 Window window = XtWindow((Widget) GetTopWidget());
2220 XLowerWindow(XtDisplay((Widget) GetTopWidget()), window);
2221 }
2222
2223 bool wxWindow::AcceptsFocus() const
2224 {
2225 return IsShown() && IsEnabled();
2226 }
2227
2228 // Update region access
2229 wxRegion& wxWindow::GetUpdateRegion() const
2230 {
2231 return (wxRegion&) m_updateRegion;
2232 }
2233
2234 bool wxWindow::IsExposed(int x, int y, int w, int h) const
2235 {
2236 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
2237 }
2238
2239 bool wxWindow::IsExposed(const wxPoint& pt) const
2240 {
2241 return (m_updateRegion.Contains(pt) != wxOutRegion);
2242 }
2243
2244 bool wxWindow::IsExposed(const wxRect& rect) const
2245 {
2246 return (m_updateRegion.Contains(rect) != wxOutRegion);
2247 }
2248
2249 /*
2250 * Allocates control IDs
2251 */
2252
2253 int wxWindow::NewControlId()
2254 {
2255 static int s_controlId = 0;
2256 s_controlId ++;
2257 return s_controlId;
2258 }
2259
2260 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel)
2261 {
2262 m_acceleratorTable = accel;
2263 }
2264
2265 // All widgets should have this as their resize proc.
2266 // OnSize sent to wxWindow via client data.
2267 void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
2268 {
2269 wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w);
2270 if (!win)
2271 return;
2272
2273 if (win->PreResize())
2274 {
2275 int width, height;
2276 win->GetSize(&width, &height);
2277 wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
2278 sizeEvent.SetEventObject(win);
2279 win->GetEventHandler()->ProcessEvent(sizeEvent);
2280 }
2281 }
2282
2283 bool wxAddWindowToTable(Widget w, wxWindow *win)
2284 {
2285 wxWindow *oldItem = NULL;
2286 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2287 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
2288 {
2289 wxLogError("Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName());
2290 return FALSE;
2291 }
2292
2293 wxWidgetHashTable->Put ((long) w, win);
2294 return TRUE;
2295 }
2296
2297 wxWindow *wxGetWindowFromTable(Widget w)
2298 {
2299 return (wxWindow *)wxWidgetHashTable->Get ((long) w);
2300 }
2301
2302 void wxDeleteWindowFromTable(Widget w)
2303 {
2304 wxWidgetHashTable->Delete((long)w);
2305 }
2306
2307 // Get the underlying X window and display
2308 WXWindow wxWindow::GetXWindow() const
2309 {
2310 return (WXWindow) XtWindow((Widget) GetMainWidget());
2311 }
2312
2313 WXDisplay *wxWindow::GetXDisplay() const
2314 {
2315 return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
2316 }
2317
2318 WXWidget wxWindow::GetMainWidget() const
2319 {
2320 if (m_drawingArea)
2321 return m_drawingArea;
2322 else
2323 return m_mainWidget;
2324 }
2325
2326 WXWidget wxWindow::GetClientWidget() const
2327 {
2328 if (m_drawingArea != (WXWidget) 0)
2329 return m_drawingArea;
2330 else
2331 return GetMainWidget();
2332 }
2333
2334 WXWidget wxWindow::GetTopWidget() const
2335 {
2336 return GetMainWidget();
2337 }
2338
2339 void wxCanvasRepaintProc (Widget drawingArea, XtPointer clientData,
2340 XmDrawingAreaCallbackStruct * cbs)
2341 {
2342 if (!wxWidgetHashTable->Get ((long) (Widget) drawingArea))
2343 return;
2344
2345 XEvent * event = cbs->event;
2346 wxWindow * win = (wxWindow *) clientData;
2347 Display * display = (Display *) win->GetXDisplay();
2348
2349 switch (event->type)
2350 {
2351 case Expose:
2352 {
2353 wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y,
2354 event->xexpose.width, event->xexpose.height);
2355 /*
2356 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2357 cout << rect->width << ", " << rect->height << "\n\n";
2358 */
2359
2360 win->m_updateRects.Append((wxObject*) rect);
2361
2362 if (event -> xexpose.count == 0)
2363 {
2364 /*
2365 wxPaintEvent event(win->GetId());
2366 event.SetEventObject(win);
2367 win->GetEventHandler()->ProcessEvent(event);
2368 */
2369
2370 win->DoPaint();
2371 win->ClearUpdateRects();
2372 }
2373 break;
2374 }
2375 default:
2376 {
2377 cout << "\n\nNew Event ! is = " << event -> type << "\n";
2378 break;
2379 }
2380 }
2381 }
2382
2383 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2384 void
2385 wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event)
2386 {
2387 XmDrawingAreaCallbackStruct cbs;
2388 XEvent ev;
2389
2390 //if (event->mode!=NotifyNormal)
2391 // return ;
2392
2393 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2394 ((XCrossingEvent &) ev) = *event;
2395
2396 cbs.reason = XmCR_INPUT;
2397 cbs.event = &ev;
2398
2399 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
2400 }
2401
2402 // Fix to make it work under Motif 1.0 (!)
2403 void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
2404 {
2405 #if XmVersion<=1000
2406
2407 XmDrawingAreaCallbackStruct cbs;
2408 XEvent ev;
2409
2410 //ev.xbutton = *event;
2411 ev = *((XEvent *) event);
2412 cbs.reason = XmCR_INPUT;
2413 cbs.event = &ev;
2414
2415 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
2416 #endif
2417 }
2418
2419 void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs)
2420 {
2421 wxWindow *canvas = (wxWindow *) wxWidgetHashTable->Get ((long) (Widget) drawingArea);
2422 XEvent local_event;
2423
2424 if (canvas==NULL)
2425 return ;
2426
2427 if (cbs->reason != XmCR_INPUT)
2428 return;
2429
2430 local_event = *(cbs->event); // We must keep a copy!
2431
2432 /*
2433 switch (local_event.xany.type)
2434 {
2435 case EnterNotify:
2436 cout << "EnterNotify\n";
2437 break;
2438 case LeaveNotify:
2439 cout << "LeaveNotify\n";
2440 break;
2441 case ButtonPress:
2442 cout << "ButtonPress\n";
2443 break;
2444 case ButtonRelease:
2445 cout << "ButtonRelease\n";
2446 break;
2447 case MotionNotify:
2448 cout << "MotionNotify\n";
2449 break;
2450 default:
2451 cout << "Something else\n";
2452 break;
2453 }
2454 */
2455
2456 switch (local_event.xany.type)
2457 {
2458 case EnterNotify:
2459 case LeaveNotify:
2460 case ButtonPress:
2461 case ButtonRelease:
2462 case MotionNotify:
2463 {
2464 wxEventType eventType = wxEVT_NULL;
2465
2466 if (local_event.xany.type == EnterNotify)
2467 {
2468 //if (local_event.xcrossing.mode!=NotifyNormal)
2469 // return ; // Ignore grab events
2470 eventType = wxEVT_ENTER_WINDOW;
2471 // canvas->GetEventHandler()->OnSetFocus();
2472 }
2473 else if (local_event.xany.type == LeaveNotify)
2474 {
2475 //if (local_event.xcrossing.mode!=NotifyNormal)
2476 // return ; // Ignore grab events
2477 eventType = wxEVT_LEAVE_WINDOW;
2478 // canvas->GetEventHandler()->OnKillFocus();
2479 }
2480 else if (local_event.xany.type == MotionNotify)
2481 {
2482 eventType = wxEVT_MOTION;
2483 if (local_event.xmotion.is_hint == NotifyHint)
2484 {
2485 Window root, child;
2486 Display *dpy = XtDisplay (drawingArea);
2487
2488 XQueryPointer (dpy, XtWindow (drawingArea),
2489 &root, &child,
2490 &local_event.xmotion.x_root,
2491 &local_event.xmotion.y_root,
2492 &local_event.xmotion.x,
2493 &local_event.xmotion.y,
2494 &local_event.xmotion.state);
2495 }
2496 else
2497 {
2498 }
2499 }
2500
2501 else if (local_event.xany.type == ButtonPress)
2502 {
2503 if (local_event.xbutton.button == Button1)
2504 {
2505 eventType = wxEVT_LEFT_DOWN;
2506 canvas->m_button1Pressed = TRUE;
2507 }
2508 else if (local_event.xbutton.button == Button2)
2509 {
2510 eventType = wxEVT_MIDDLE_DOWN;
2511 canvas->m_button2Pressed = TRUE;
2512 }
2513 else if (local_event.xbutton.button == Button3)
2514 {
2515 eventType = wxEVT_RIGHT_DOWN;
2516 canvas->m_button3Pressed = TRUE;
2517 }
2518 }
2519 else if (local_event.xany.type == ButtonRelease)
2520 {
2521 if (local_event.xbutton.button == Button1)
2522 {
2523 eventType = wxEVT_LEFT_UP;
2524 canvas->m_button1Pressed = FALSE;
2525 }
2526 else if (local_event.xbutton.button == Button2)
2527 {
2528 eventType = wxEVT_MIDDLE_UP;
2529 canvas->m_button2Pressed = FALSE;
2530 }
2531 else if (local_event.xbutton.button == Button3)
2532 {
2533 eventType = wxEVT_RIGHT_UP;
2534 canvas->m_button3Pressed = FALSE;
2535 }
2536 }
2537
2538 wxMouseEvent wxevent (eventType);
2539 wxevent.m_eventHandle = (char *) &local_event;
2540
2541 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
2542 || (event_left_is_down (&local_event)
2543 && (eventType != wxEVT_LEFT_UP)));
2544 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
2545 || (event_middle_is_down (&local_event)
2546 && (eventType != wxEVT_MIDDLE_UP)));
2547 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
2548 || (event_right_is_down (&local_event)
2549 && (eventType != wxEVT_RIGHT_UP)));
2550
2551 wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask;
2552 wxevent.m_controlDown = local_event.xbutton.state & ControlMask;
2553 wxevent.m_altDown = local_event.xbutton.state & Mod3Mask;
2554 wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask;
2555 wxevent.SetTimestamp(local_event.xbutton.time);
2556
2557 // Now check if we need to translate this event into a double click
2558 if (TRUE) // canvas->doubleClickAllowed)
2559 {
2560 if (wxevent.ButtonDown())
2561 {
2562 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()) ;
2563
2564 // get button and time-stamp
2565 int button = 0;
2566 if (wxevent.LeftDown()) button = 1;
2567 else if (wxevent.MiddleDown()) button = 2;
2568 else if (wxevent.RightDown()) button = 3;
2569 long ts = wxevent.GetTimestamp();
2570 // check, if single or double click
2571 if (canvas->m_lastButton && canvas->m_lastButton==button && (ts - canvas->m_lastTS) < dclickTime)
2572 {
2573 // I have a dclick
2574 canvas->m_lastButton = 0;
2575 switch ( eventType )
2576 {
2577 case wxEVT_LEFT_DOWN:
2578 wxevent.SetEventType(wxEVT_LEFT_DCLICK);
2579 break;
2580 case wxEVT_MIDDLE_DOWN:
2581 wxevent.SetEventType(wxEVT_MIDDLE_DCLICK);
2582 break;
2583 case wxEVT_RIGHT_DOWN:
2584 wxevent.SetEventType(wxEVT_RIGHT_DCLICK);
2585 break;
2586
2587 default :
2588 break;
2589 }
2590
2591 }
2592 else
2593 {
2594 // not fast enough or different button
2595 canvas->m_lastTS = ts;
2596 canvas->m_lastButton = button;
2597 }
2598 }
2599 }
2600
2601 wxevent.SetId(canvas->GetId());
2602 wxevent.SetEventObject(canvas);
2603 wxevent.m_x = local_event.xbutton.x;
2604 wxevent.m_y = local_event.xbutton.y;
2605 canvas->GetEventHandler()->ProcessEvent (wxevent);
2606 /*
2607 if (eventType == wxEVT_ENTER_WINDOW ||
2608 eventType == wxEVT_LEAVE_WINDOW ||
2609 eventType == wxEVT_MOTION
2610 )
2611 return;
2612 */
2613 break;
2614 }
2615 case KeyPress:
2616 {
2617 KeySym keySym;
2618 // XComposeStatus compose;
2619 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2620 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2621 int id = wxCharCodeXToWX (keySym);
2622
2623 wxEventType eventType = wxEVT_CHAR;
2624
2625 wxKeyEvent event (eventType);
2626
2627 if (local_event.xkey.state & ShiftMask)
2628 event.m_shiftDown = TRUE;
2629 if (local_event.xkey.state & ControlMask)
2630 event.m_controlDown = TRUE;
2631 if (local_event.xkey.state & Mod3Mask)
2632 event.m_altDown = TRUE;
2633 if (local_event.xkey.state & Mod1Mask)
2634 event.m_metaDown = TRUE;
2635 event.SetEventObject(canvas);
2636 event.m_keyCode = id;
2637 event.SetTimestamp(local_event.xkey.time);
2638
2639 if (id > -1)
2640 {
2641 // Implement wxFrame::OnCharHook by checking ancestor.
2642 wxWindow *parent = canvas->GetParent();
2643 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)))
2644 parent = parent->GetParent();
2645
2646 if (parent)
2647 {
2648 event.SetEventType(wxEVT_CHAR_HOOK);
2649 if (parent->GetEventHandler()->ProcessEvent(event))
2650 return;
2651 }
2652
2653 // For simplicity, OnKeyDown is the same as OnChar
2654 // TODO: filter modifier key presses from OnChar
2655 event.SetEventType(wxEVT_KEY_DOWN);
2656
2657 // Only process OnChar if OnKeyDown didn't swallow it
2658 if (!canvas->GetEventHandler()->ProcessEvent (event))
2659 {
2660 event.SetEventType(wxEVT_CHAR);
2661 canvas->GetEventHandler()->ProcessEvent (event);
2662 }
2663 }
2664 break;
2665 }
2666 case KeyRelease:
2667 {
2668 KeySym keySym;
2669 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2670 int id = wxCharCodeXToWX (keySym);
2671
2672 wxKeyEvent event (wxEVT_KEY_UP);
2673
2674 if (local_event.xkey.state & ShiftMask)
2675 event.m_shiftDown = TRUE;
2676 if (local_event.xkey.state & ControlMask)
2677 event.m_controlDown = TRUE;
2678 if (local_event.xkey.state & Mod3Mask)
2679 event.m_altDown = TRUE;
2680 if (local_event.xkey.state & Mod1Mask)
2681 event.m_metaDown = TRUE;
2682 event.SetEventObject(canvas);
2683 event.m_keyCode = id;
2684 event.SetTimestamp(local_event.xkey.time);
2685
2686 if (id > -1)
2687 {
2688 canvas->GetEventHandler()->ProcessEvent (event);
2689 }
2690 break;
2691 }
2692 case FocusIn:
2693 {
2694 if (local_event.xfocus.detail != NotifyPointer)
2695 {
2696 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
2697 event.SetEventObject(canvas);
2698 canvas->GetEventHandler()->ProcessEvent(event);
2699 }
2700 break;
2701 }
2702 case FocusOut:
2703 {
2704 if (local_event.xfocus.detail != NotifyPointer)
2705 {
2706 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
2707 event.SetEventObject(canvas);
2708 canvas->GetEventHandler()->ProcessEvent(event);
2709 }
2710 break;
2711 }
2712 default:
2713 break;
2714 }
2715 }
2716
2717 void wxWindow::DoPaint()
2718 {
2719 //TODO : make a temporary gc so we can do the XCopyArea below
2720 if (m_backingPixmap && !m_needsRefresh)
2721 {
2722 wxPaintDC dc(this);
2723
2724 GC tempGC = (GC) dc.GetBackingGC();
2725
2726 Widget widget = (Widget) GetMainWidget();
2727
2728 int scrollPosX = 0;
2729 int scrollPosY = 0;
2730
2731 // We have to test whether it's a wxScrolledWindow (hack!)
2732 // because otherwise we don't know how many pixels have been
2733 // scrolled. We might solve this in the future by defining
2734 // virtual wxWindow functions to get the scroll position in pixels.
2735 // Or, each kind of scrolled window has to implement backing
2736 // stores itself, using generic wxWindows code.
2737 if (this->IsKindOf(CLASSINFO(wxScrolledWindow)))
2738 {
2739 wxScrolledWindow* scrolledWindow = (wxScrolledWindow*) this;
2740 int x, y;
2741 scrolledWindow->CalcScrolledPosition(0, 0, & x, & y);
2742
2743 scrollPosX = - x;
2744 scrollPosY = - y;
2745 }
2746
2747 // TODO: This could be optimized further by only copying the
2748 // areas in the current update region.
2749
2750 // Only blit the part visible in the client area. The backing pixmap
2751 // always starts at 0, 0 but we may be looking at only a portion of it.
2752 wxSize clientArea = GetClientSize();
2753 int toBlitX = m_pixmapWidth - scrollPosX;
2754 int toBlitY = m_pixmapHeight - scrollPosY;
2755
2756 // Copy whichever is samller, the amount of pixmap we have to copy,
2757 // or the size of the client area.
2758 toBlitX = wxMin(toBlitX, clientArea.x);
2759 toBlitY = wxMin(toBlitY, clientArea.y);
2760
2761 // Make sure we're not negative
2762 toBlitX = wxMax(0, toBlitX);
2763 toBlitY = wxMax(0, toBlitY);
2764
2765 XCopyArea (XtDisplay (widget), (Pixmap) m_backingPixmap, XtWindow (widget), tempGC,
2766 scrollPosX, scrollPosY, // Start at the scroll position
2767 toBlitX, toBlitY, // How much of the pixmap to copy
2768 0, 0); // Destination
2769 }
2770 else
2771 {
2772 // Set an erase event first
2773 wxEraseEvent eraseEvent(GetId());
2774 eraseEvent.SetEventObject(this);
2775 GetEventHandler()->ProcessEvent(eraseEvent);
2776
2777 wxPaintEvent event(GetId());
2778 event.SetEventObject(this);
2779 GetEventHandler()->ProcessEvent(event);
2780
2781 m_needsRefresh = FALSE;
2782 }
2783 }
2784
2785 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2786 void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags)
2787 {
2788 // A bit of optimization to help sort out the flickers.
2789 int oldX, oldY, oldW, oldH;
2790 GetSize(& oldW, & oldH);
2791 GetPosition(& oldX, & oldY);
2792
2793 bool useOldPos = FALSE;
2794 bool useOldSize = FALSE;
2795
2796 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
2797 useOldPos = TRUE;
2798 else if (x == oldX && y == oldY)
2799 useOldPos = TRUE;
2800
2801 if ((w == -1) && (h == -1))
2802 useOldSize = TRUE;
2803 else if (w == oldW && h == oldH)
2804 useOldSize = TRUE;
2805
2806 if (!wxNoOptimize::CanOptimize())
2807 {
2808 useOldSize = FALSE; useOldPos = FALSE;
2809 }
2810
2811 if (useOldPos && useOldSize)
2812 return;
2813
2814 Widget drawingArea = (Widget) m_drawingArea;
2815 bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2816
2817 if (managed)
2818 XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2819 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2820
2821 int xx = x; int yy = y;
2822 AdjustForParentClientOrigin(xx, yy, sizeFlags);
2823
2824 if (!useOldPos)
2825 {
2826 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2827 {
2828 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2829 XmNx, xx, NULL);
2830 }
2831
2832 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2833 {
2834 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2835 XmNy, yy, NULL);
2836 }
2837 }
2838
2839 if (!useOldSize)
2840 {
2841
2842 if (w > -1)
2843 {
2844 if (m_borderWidget)
2845 {
2846 XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL);
2847 short thick, margin;
2848 XtVaGetValues ((Widget) m_borderWidget,
2849 XmNshadowThickness, &thick,
2850 XmNmarginWidth, &margin,
2851 NULL);
2852 w -= 2 * (thick + margin);
2853 }
2854
2855 XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL);
2856
2857 Dimension spacing;
2858 Widget sbar;
2859 XtVaGetValues ((Widget) m_scrolledWindow,
2860 XmNspacing, &spacing,
2861 XmNverticalScrollBar, &sbar,
2862 NULL);
2863 Dimension wsbar;
2864 if (sbar)
2865 XtVaGetValues (sbar, XmNwidth, &wsbar, NULL);
2866 else
2867 wsbar = 0;
2868
2869 w -= (spacing + wsbar);
2870
2871 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2872 }
2873 if (h > -1)
2874 {
2875 if (m_borderWidget)
2876 {
2877 XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL);
2878 short thick, margin;
2879 XtVaGetValues ((Widget) m_borderWidget,
2880 XmNshadowThickness, &thick,
2881 XmNmarginHeight, &margin,
2882 NULL);
2883 h -= 2 * (thick + margin);
2884 }
2885
2886 XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL);
2887
2888 Dimension spacing;
2889 Widget sbar;
2890 XtVaGetValues ((Widget) m_scrolledWindow,
2891 XmNspacing, &spacing,
2892 XmNhorizontalScrollBar, &sbar,
2893 NULL);
2894 Dimension wsbar;
2895 if (sbar)
2896 XtVaGetValues (sbar, XmNheight, &wsbar, NULL);
2897 else
2898 wsbar = 0;
2899
2900 h -= (spacing + wsbar);
2901
2902 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2903
2904 }
2905 }
2906
2907 if (managed)
2908 XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2909 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2910
2911 /*
2912 int ww, hh;
2913 GetClientSize (&ww, &hh);
2914 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2915 sizeEvent.SetEventObject(this);
2916
2917 GetEventHandler()->ProcessEvent(sizeEvent);
2918 */
2919
2920 }
2921
2922 void wxWindow::CanvasSetClientSize (int w, int h)
2923 {
2924 Widget drawingArea = (Widget) m_drawingArea;
2925
2926 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2927
2928 if (w > -1)
2929 XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2930 if (h > -1)
2931 XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2932 /* TODO: is this necessary?
2933 allowRepainting = FALSE;
2934
2935 XSync (XtDisplay (drawingArea), FALSE);
2936 XEvent event;
2937 while (XtAppPending (wxTheApp->appContext))
2938 {
2939 XFlush (XtDisplay (drawingArea));
2940 XtAppNextEvent (wxTheApp->appContext, &event);
2941 XtDispatchEvent (&event);
2942 }
2943 */
2944
2945 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2946
2947 /* TODO
2948 allowRepainting = TRUE;
2949 DoRefresh ();
2950 */
2951
2952 /*
2953 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2954 sizeEvent.SetEventObject(this);
2955
2956 GetEventHandler()->ProcessEvent(sizeEvent);
2957 */
2958 }
2959
2960 void wxWindow::CanvasGetClientSize (int *w, int *h) const
2961 {
2962 // Must return the same thing that was set via SetClientSize
2963 Dimension xx, yy;
2964 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2965 *w = xx;
2966 *h = yy;
2967 }
2968
2969 void wxWindow::CanvasGetSize (int *w, int *h) const
2970 {
2971 Dimension xx, yy;
2972 if ((Widget) m_borderWidget)
2973 XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
2974 else if ((Widget) m_scrolledWindow)
2975 XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL);
2976 else
2977 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2978
2979 *w = xx;
2980 *h = yy;
2981 }
2982
2983 void wxWindow::CanvasGetPosition (int *x, int *y) const
2984 {
2985 Position xx, yy;
2986 XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
2987
2988 // We may be faking the client origin.
2989 // So a window that's really at (0, 30) may appear
2990 // (to wxWin apps) to be at (0, 0).
2991 if (GetParent())
2992 {
2993 wxPoint pt(GetParent()->GetClientAreaOrigin());
2994 xx -= pt.x;
2995 yy -= pt.y;
2996 }
2997
2998 *x = xx;
2999 *y = yy;
3000 }
3001
3002 // Add to hash table, add event handler
3003 bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
3004 WXWidget formWidget, int x, int y, int width, int height)
3005 {
3006 wxAddWindowToTable((Widget) mainWidget, this);
3007 if (CanAddEventHandler())
3008 {
3009 XtAddEventHandler((Widget) mainWidget,
3010 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
3011 False,
3012 wxPanelItemEventHandler,
3013 (XtPointer) this);
3014 }
3015
3016 if (!formWidget)
3017 {
3018 XtTranslations ptr;
3019 XtOverrideTranslations ((Widget) mainWidget,
3020 ptr = XtParseTranslationTable ("<Configure>: resize()"));
3021 XtFree ((char *) ptr);
3022 }
3023
3024 // Some widgets have a parent form widget, e.g. wxRadioBox
3025 if (formWidget)
3026 {
3027 if (!wxAddWindowToTable((Widget) formWidget, this))
3028 return FALSE;
3029
3030 XtTranslations ptr;
3031 XtOverrideTranslations ((Widget) formWidget,
3032 ptr = XtParseTranslationTable ("<Configure>: resize()"));
3033 XtFree ((char *) ptr);
3034 }
3035
3036 if (x == -1)
3037 x = 0;
3038 if (y == -1)
3039 y = 0;
3040 SetSize (x, y, width, height);
3041
3042 return TRUE;
3043 }
3044
3045 // Remove event handler, remove from hash table
3046 bool wxWindow::DetachWidget(WXWidget widget)
3047 {
3048 if (CanAddEventHandler())
3049 {
3050 XtRemoveEventHandler((Widget) widget,
3051 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
3052 False,
3053 wxPanelItemEventHandler,
3054 (XtPointer)this);
3055 }
3056
3057 wxDeleteWindowFromTable((Widget) widget);
3058 return TRUE;
3059 }
3060
3061 void wxPanelItemEventHandler (Widget wid,
3062 XtPointer client_data,
3063 XEvent* event,
3064 Boolean *continueToDispatch)
3065 {
3066 // Widget can be a label or the actual widget.
3067
3068 wxWindow *window = (wxWindow *)wxWidgetHashTable->Get((long)wid);
3069 if (window)
3070 {
3071 wxMouseEvent wxevent(0);
3072 if (wxTranslateMouseEvent(wxevent, window, wid, event))
3073 {
3074 window->GetEventHandler()->ProcessEvent(wxevent);
3075 }
3076 }
3077 // TODO: probably the key to allowing default behaviour
3078 // to happen.
3079 // Say we set a m_doDefault flag to FALSE at the start of this
3080 // function. Then in e.g. wxWindow::OnMouseEvent we can
3081 // call Default() which sets this flag to TRUE, indicating
3082 // that default processing can happen. Thus, behaviour can appear
3083 // to be overridden just by adding an event handler and not calling
3084 // wxWindow::OnWhatever.
3085 // ALSO, maybe we can use this instead of the current way of handling
3086 // drawing area events, to simplify things.
3087 *continueToDispatch = True;
3088 }
3089
3090 static void wxScrollBarCallback(Widget scrollbar, XtPointer clientData,
3091 XmScaleCallbackStruct *cbs)
3092 {
3093 Widget scrolledWindow = XtParent (scrollbar);
3094 wxWindow *win = (wxWindow *) wxWidgetHashTable->Get ((long) scrolledWindow);
3095 int orientation = (int) clientData;
3096
3097 wxEventType eventType = wxEVT_NULL;
3098 switch (cbs->reason)
3099 {
3100 case XmCR_INCREMENT:
3101 {
3102 eventType = wxEVT_SCROLL_LINEDOWN;
3103 break;
3104 }
3105 case XmCR_DECREMENT:
3106 {
3107 eventType = wxEVT_SCROLL_LINEUP;
3108 break;
3109 }
3110 case XmCR_DRAG:
3111 {
3112 eventType = wxEVT_SCROLL_THUMBTRACK;
3113 break;
3114 }
3115 case XmCR_VALUE_CHANGED:
3116 {
3117 // TODO: Should this be intercepted too, or will it cause
3118 // duplicate events?
3119 eventType = wxEVT_SCROLL_THUMBTRACK;
3120 break;
3121 }
3122 case XmCR_PAGE_INCREMENT:
3123 {
3124 eventType = wxEVT_SCROLL_PAGEDOWN;
3125 break;
3126 }
3127 case XmCR_PAGE_DECREMENT:
3128 {
3129 eventType = wxEVT_SCROLL_PAGEUP;
3130 break;
3131 }
3132 case XmCR_TO_TOP:
3133 {
3134 eventType = wxEVT_SCROLL_TOP;
3135 break;
3136 }
3137 case XmCR_TO_BOTTOM:
3138 {
3139 eventType = wxEVT_SCROLL_BOTTOM;
3140 break;
3141 }
3142 default:
3143 {
3144 // Should never get here
3145 wxFAIL_MSG("Unknown scroll event.");
3146 break;
3147 }
3148 }
3149
3150 wxScrollEvent event(eventType, win->GetId());
3151 event.SetEventObject(win);
3152 event.SetPosition(cbs->value);
3153 event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL );
3154
3155 win->GetEventHandler()->ProcessEvent(event);
3156 }
3157
3158 bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
3159 {
3160 switch (xevent->xany.type)
3161 {
3162 case EnterNotify:
3163 case LeaveNotify:
3164 case ButtonPress:
3165 case ButtonRelease:
3166 case MotionNotify:
3167 {
3168 wxEventType eventType = wxEVT_NULL;
3169
3170 if (xevent->xany.type == LeaveNotify)
3171 {
3172 win->m_button1Pressed = FALSE;
3173 win->m_button2Pressed = FALSE;
3174 win->m_button3Pressed = FALSE;
3175 return FALSE;
3176 }
3177 else if (xevent->xany.type == MotionNotify)
3178 {
3179 eventType = wxEVT_MOTION;
3180 }
3181 else if (xevent->xany.type == ButtonPress)
3182 {
3183 if (xevent->xbutton.button == Button1)
3184 {
3185 eventType = wxEVT_LEFT_DOWN;
3186 win->m_button1Pressed = TRUE;
3187 }
3188 else if (xevent->xbutton.button == Button2)
3189 {
3190 eventType = wxEVT_MIDDLE_DOWN;
3191 win->m_button2Pressed = TRUE;
3192 }
3193 else if (xevent->xbutton.button == Button3)
3194 {
3195 eventType = wxEVT_RIGHT_DOWN;
3196 win->m_button3Pressed = TRUE;
3197 }
3198 }
3199 else if (xevent->xany.type == ButtonRelease)
3200 {
3201 if (xevent->xbutton.button == Button1)
3202 {
3203 eventType = wxEVT_LEFT_UP;
3204 win->m_button1Pressed = FALSE;
3205 }
3206 else if (xevent->xbutton.button == Button2)
3207 {
3208 eventType = wxEVT_MIDDLE_UP;
3209 win->m_button2Pressed = FALSE;
3210 }
3211 else if (xevent->xbutton.button == Button3)
3212 {
3213 eventType = wxEVT_RIGHT_UP;
3214 win->m_button3Pressed = FALSE;
3215 }
3216 else return FALSE;
3217 }
3218 else return FALSE;
3219
3220 wxevent.m_eventHandle = (char *)xevent;
3221 wxevent.SetEventType(eventType);
3222
3223 Position x1, y1;
3224 XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
3225
3226 int x2, y2;
3227 win->GetPosition(&x2, &y2);
3228
3229 // The button x/y must be translated to wxWindows
3230 // window space - the widget might be a label or button,
3231 // within a form.
3232 int dx = 0;
3233 int dy = 0;
3234 if (widget != (Widget)win->GetMainWidget())
3235 {
3236 dx = x1;
3237 dy = y1;
3238 }
3239
3240 wxevent.m_x = xevent->xbutton.x + dx;
3241 wxevent.m_y = xevent->xbutton.y + dy;
3242
3243 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
3244 || (event_left_is_down (xevent)
3245 && (eventType != wxEVT_LEFT_UP)));
3246 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
3247 || (event_middle_is_down (xevent)
3248 && (eventType != wxEVT_MIDDLE_UP)));
3249 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
3250 || (event_right_is_down (xevent)
3251 && (eventType != wxEVT_RIGHT_UP)));
3252
3253 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
3254 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
3255 return TRUE;
3256 }
3257 }
3258 return FALSE;
3259 }
3260
3261 bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
3262 {
3263 switch (xevent->xany.type)
3264 {
3265 case KeyPress:
3266 {
3267 char buf[20];
3268
3269 KeySym keySym;
3270 // XComposeStatus compose;
3271 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3272 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
3273 int id = wxCharCodeXToWX (keySym);
3274
3275 if (xevent->xkey.state & ShiftMask)
3276 wxevent.m_shiftDown = TRUE;
3277 if (xevent->xkey.state & ControlMask)
3278 wxevent.m_controlDown = TRUE;
3279 if (xevent->xkey.state & Mod3Mask)
3280 wxevent.m_altDown = TRUE;
3281 if (xevent->xkey.state & Mod1Mask)
3282 wxevent.m_metaDown = TRUE;
3283 wxevent.SetEventObject(win);
3284 wxevent.m_keyCode = id;
3285 wxevent.SetTimestamp(xevent->xkey.time);
3286
3287 wxevent.m_x = xevent->xbutton.x;
3288 wxevent.m_y = xevent->xbutton.y;
3289
3290 if (id > -1)
3291 return TRUE;
3292 else
3293 return FALSE;
3294 break;
3295 }
3296 default:
3297 break;
3298 }
3299 return FALSE;
3300 }
3301
3302 #define YAllocColor XAllocColor
3303 XColor g_itemColors[5];
3304 int wxComputeColours (Display *display, wxColour * back, wxColour * fore)
3305 {
3306 int result;
3307 static XmColorProc colorProc;
3308
3309 result = wxNO_COLORS;
3310
3311 if (back)
3312 {
3313 g_itemColors[0].red = (((long) back->Red ()) << 8);
3314 g_itemColors[0].green = (((long) back->Green ()) << 8);
3315 g_itemColors[0].blue = (((long) back->Blue ()) << 8);
3316 g_itemColors[0].flags = DoRed | DoGreen | DoBlue;
3317 if (colorProc == (XmColorProc) NULL)
3318 {
3319 // Get a ptr to the actual function
3320 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
3321 // And set it back to motif.
3322 XmSetColorCalculation (colorProc);
3323 }
3324 (*colorProc) (&g_itemColors[wxBACK_INDEX],
3325 &g_itemColors[wxFORE_INDEX],
3326 &g_itemColors[wxSELE_INDEX],
3327 &g_itemColors[wxTOPS_INDEX],
3328 &g_itemColors[wxBOTS_INDEX]);
3329 result = wxBACK_COLORS;
3330 }
3331 if (fore)
3332 {
3333 g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
3334 g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
3335 g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
3336 g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
3337 if (result == wxNO_COLORS)
3338 result = wxFORE_COLORS;
3339 }
3340
3341 Display *dpy = display;
3342 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
3343
3344 if (back)
3345 {
3346 /* 5 Colours to allocate */
3347 for (int i = 0; i < 5; i++)
3348 if (!YAllocColor (dpy, cmap, &g_itemColors[i]))
3349 result = wxNO_COLORS;
3350 }
3351 else if (fore)
3352 {
3353 /* Only 1 colour to allocate */
3354 if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX]))
3355 result = wxNO_COLORS;
3356 }
3357
3358 return (result);
3359
3360 }
3361
3362 // Changes the foreground and background colours to be derived
3363 // from the current background colour.
3364 // To change the foreground colour, you must call SetForegroundColour
3365 // explicitly.
3366 void wxWindow::ChangeBackgroundColour()
3367 {
3368 if (GetMainWidget())
3369 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
3370
3371 // This not necessary
3372 #if 0
3373
3374 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
3375 {
3376 DoChangeBackgroundColour(m_scrolledWindow, m_backgroundColour);
3377 // Have to set the scrollbar colours back since
3378 // the scrolled window seemed to change them
3379 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
3380
3381 if (m_hScrollBar)
3382 DoChangeBackgroundColour(m_hScrollBar, backgroundColour);
3383 if (m_vScrollBar)
3384 DoChangeBackgroundColour(m_vScrollBar, backgroundColour);
3385 }
3386 #endif
3387 }
3388
3389 void wxWindow::ChangeForegroundColour()
3390 {
3391 if (GetMainWidget())
3392 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
3393 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
3394 DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour);
3395 }
3396
3397 // Change a widget's foreground and background colours.
3398
3399 void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
3400 {
3401 // When should we specify the foreground, if it's calculated
3402 // by wxComputeColours?
3403 // Solution: say we start with the default (computed) foreground colour.
3404 // If we call SetForegroundColour explicitly for a control or window,
3405 // then the foreground is changed.
3406 // Therefore SetBackgroundColour computes the foreground colour, and
3407 // SetForegroundColour changes the foreground colour. The ordering is
3408 // important.
3409
3410 XtVaSetValues ((Widget) widget,
3411 XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)),
3412 NULL);
3413 }
3414
3415 void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
3416 {
3417 wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
3418 (wxColour*) NULL);
3419
3420 XtVaSetValues ((Widget) widget,
3421 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
3422 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
3423 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
3424 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
3425 NULL);
3426
3427 if (changeArmColour)
3428 XtVaSetValues ((Widget) widget,
3429 XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
3430 NULL);
3431 }
3432
3433 void wxWindow::SetBackgroundColour(const wxColour& col)
3434 {
3435 m_backgroundColour = col;
3436 ChangeBackgroundColour();
3437 }
3438
3439 void wxWindow::SetForegroundColour(const wxColour& col)
3440 {
3441 m_foregroundColour = col;
3442 ChangeForegroundColour();
3443 }
3444
3445 void wxWindow::ChangeFont(bool keepOriginalSize)
3446 {
3447 // Note that this causes the widget to be resized back
3448 // to its original size! We therefore have to set the size
3449 // back again. TODO: a better way in Motif?
3450 Widget w = (Widget) GetLabelWidget(); // Usually the main widget
3451 if (w && m_windowFont.Ok())
3452 {
3453 int width, height, width1, height1;
3454 GetSize(& width, & height);
3455
3456 // lesstif 0.87 hangs here
3457 #ifndef LESSTIF_VERSION
3458 XtVaSetValues (w,
3459 XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)),
3460 NULL);
3461 #endif
3462
3463 GetSize(& width1, & height1);
3464 if (keepOriginalSize && (width != width1 || height != height1))
3465 {
3466 SetSize(-1, -1, width, height);
3467 }
3468 }
3469 }
3470
3471 void wxWindow::SetFont(const wxFont& font)
3472 {
3473 m_windowFont = font;
3474 ChangeFont();
3475 }
3476
3477 void wxWindow::SetToolTip(const wxString& tooltip)
3478 {
3479 // TODO
3480 }
3481
3482 void wxWindow::ClearUpdateRects()
3483 {
3484 wxNode* node = m_updateRects.First();
3485 while (node)
3486 {
3487 wxRect* rect = (wxRect*) node->Data();
3488 delete rect;
3489 node = node->Next();
3490 }
3491 m_updateRects.Clear();
3492 }
3493
3494 bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
3495 {
3496 if (!m_acceleratorTable.Ok())
3497 return FALSE;
3498
3499 int count = m_acceleratorTable.GetCount();
3500 wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries();
3501 int i;
3502 for (i = 0; i < count; i++)
3503 {
3504 wxAcceleratorEntry* entry = & (entries[i]);
3505 if (entry->MatchesEvent(event))
3506 {
3507 // Bingo, we have a match. Now find a control
3508 // that matches the entry command id.
3509
3510 // Need to go up to the top of the window hierarchy,
3511 // since it might be e.g. a menu item
3512 wxWindow* parent = this;
3513 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)) && !parent->IsKindOf(CLASSINFO(wxDialog)))
3514 parent = parent->GetParent();
3515
3516 if (!parent)
3517 return FALSE;
3518
3519 if (parent->IsKindOf(CLASSINFO(wxFrame)))
3520 {
3521 // Try for a menu command
3522 wxFrame* frame = (wxFrame*) parent;
3523 if (frame->GetMenuBar())
3524 {
3525 wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand());
3526 if (item)
3527 {
3528 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand());
3529 commandEvent.SetEventObject(frame);
3530
3531 // If ProcessEvent returns TRUE (it was handled), then
3532 // the calling code will skip the event handling.
3533 return frame->GetEventHandler()->ProcessEvent(commandEvent);
3534 }
3535 }
3536 }
3537
3538 // Find a child matching the command id
3539 wxWindow* child = parent->FindWindow(entry->GetCommand());
3540
3541 // No such child
3542 if (!child)
3543 return FALSE;
3544
3545 // Now we process those kinds of windows that we can.
3546 // For now, only buttons.
3547 if (child->IsKindOf(CLASSINFO(wxButton)))
3548 {
3549 wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId());
3550 commandEvent.SetEventObject(child);
3551 return child->GetEventHandler()->ProcessEvent(commandEvent);
3552 }
3553
3554 return FALSE;
3555 } // matches event
3556 }// for
3557
3558 // We didn't match the key event against an accelerator.
3559 return FALSE;
3560 }
3561
3562 /*
3563 * wxNoOptimize: switch off size optimization
3564 */
3565
3566 int wxNoOptimize::m_count = 0;
3567
3568 wxNoOptimize::wxNoOptimize()
3569 {
3570 m_count ++;
3571 }
3572
3573 wxNoOptimize::~wxNoOptimize()
3574 {
3575 m_count --;
3576 }
3577
3578 bool wxNoOptimize::CanOptimize()
3579 {
3580 return (m_count == 0);
3581 }
3582
3583 // For repainting arbitrary windows
3584 void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *)
3585 {
3586 Window window;
3587 Display *display;
3588
3589 wxWindow* win = (wxWindow *)wxWidgetHashTable->Get((long)w);
3590 if (!win)
3591 return;
3592
3593 switch(event -> type)
3594 {
3595 case Expose :
3596 {
3597 window = (Window) win -> GetXWindow();
3598 display = (Display *) win -> GetXDisplay();
3599
3600 wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y,
3601 event->xexpose.width, event->xexpose.height);
3602 win->m_updateRects.Append((wxObject*) rect);
3603
3604 if (event -> xexpose.count == 0)
3605 {
3606 win->DoPaint();
3607
3608 win->ClearUpdateRects();
3609 }
3610 break;
3611 }
3612 default :
3613 {
3614 cout << "\n\nNew Event ! is = " << event -> type << "\n";
3615 break;
3616 }
3617 }
3618 }
3619