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