]> git.saurik.com Git - wxWidgets.git/blame - src/motif/window.cpp
wxListBox::FindString(): it's not an error if the string is not found, so
[wxWidgets.git] / src / motif / window.cpp
CommitLineData
4bb6408c
JS
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
31#include "wx/menuitem.h"
32#include "wx/log.h"
33
34#if USE_DRAG_AND_DROP
35#include "wx/dnd.h"
36#endif
37
38#include <Xm/Xm.h>
50414e24
JS
39
40#include <Xm/DrawingA.h>
41#include <Xm/ScrolledW.h>
42#include <Xm/ScrollBar.h>
43#include <Xm/Frame.h>
44#include <Xm/Label.h>
45
4bb6408c
JS
46#include "wx/motif/private.h"
47
48#include <string.h>
49
50414e24
JS
50#define SCROLL_MARGIN 4
51void wxCanvasRepaintProc (Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs);
52void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs);
53void wxCanvasMotionEvent (Widget, XButtonEvent * event);
54void wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
02e8b2f9
JS
55void wxPanelItemEventHandler (Widget wid,
56 XtPointer client_data,
57 XEvent* event,
58 Boolean *continueToDispatch);
50414e24
JS
59
60#define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
61#define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
62#define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
63
4bb6408c
JS
64extern wxList wxPendingDelete;
65
66#if !USE_SHARED_LIBRARY
67IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
68
69BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
70 EVT_CHAR(wxWindow::OnChar)
71 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
72 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
73 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
74 EVT_IDLE(wxWindow::OnIdle)
75END_EVENT_TABLE()
76
77#endif
78
79
80// Constructor
81wxWindow::wxWindow()
82{
83 // Generic
84 m_windowId = 0;
85 m_windowStyle = 0;
86 m_windowParent = NULL;
87 m_windowEventHandler = this;
88 m_windowName = "";
89 m_windowCursor = *wxSTANDARD_CURSOR;
90 m_children = new wxList;
91 m_constraints = NULL;
92 m_constraintsInvolvedIn = NULL;
93 m_windowSizer = NULL;
94 m_sizerParent = NULL;
95 m_autoLayout = FALSE;
96 m_windowValidator = NULL;
97 m_defaultItem = NULL;
98 m_returnCode = 0;
99 m_caretWidth = 0; m_caretHeight = 0;
100 m_caretEnabled = FALSE;
101 m_caretShown = FALSE;
102 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
103 m_foregroundColour = *wxBLACK;
104 m_defaultForegroundColour = *wxBLACK ;
105 m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
106
107#if USE_DRAG_AND_DROP
108 m_pDropTarget = NULL;
109#endif
110
50414e24 111 /// Motif-specific
4bb6408c
JS
112 m_mainWidget = (WXWidget) 0;
113 m_button1Pressed = FALSE;
114 m_button2Pressed = FALSE;
115 m_button3Pressed = FALSE;
116 m_winCaptured = FALSE;
117 m_isShown = TRUE;
50414e24
JS
118 m_hScrollBar = (WXWidget) 0;
119 m_vScrollBar = (WXWidget) 0;
120 m_borderWidget = (WXWidget) 0;
121 m_scrolledWindow = (WXWidget) 0;
122 m_drawingArea = (WXWidget) 0;
123 m_hScroll = FALSE;
124 m_vScroll = FALSE;
125 m_hScrollingEnabled = FALSE;
126 m_vScrollingEnabled = FALSE;
127 m_backingPixmap = (WXPixmap) 0;
128 m_pixmapWidth = 0;
129 m_pixmapHeight = 0;
130 m_pixmapOffsetX = 0;
131 m_pixmapOffsetY = 0;
132 m_lastTS = 0;
133 m_lastButton = 0;
02e8b2f9 134 m_canAddEventHandler = FALSE;
4bb6408c
JS
135}
136
137// Destructor
138wxWindow::~wxWindow()
139{
50414e24
JS
140 //// Motif-specific
141
02e8b2f9
JS
142 if (GetMainWidget())
143 DetachWidget(GetMainWidget()); // Removes event handlers
144
50414e24
JS
145 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
146 if (m_drawingArea)
147 {
148 // Destroy children before destroying self
149 DestroyChildren();
150
151 if (m_backingPixmap)
152 XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap);
153
154 Widget w = (Widget) m_drawingArea;
155 wxDeleteWindowFromTable(w);
156
157 if (w)
158 XtDestroyWidget(w);
159 m_mainWidget = (WXWidget) 0;
160
161 // Only if we're _really_ a canvas (not a dialog box/panel)
162 if (m_scrolledWindow)
163 {
164 wxDeleteWindowFromTable((Widget) m_scrolledWindow);
165 }
166
167 if (m_hScrollBar)
168 {
169 XtUnmanageChild ((Widget) m_hScrollBar);
170 XtDestroyWidget ((Widget) m_hScrollBar);
171 }
172 if (m_vScrollBar)
173 {
174 XtUnmanageChild ((Widget) m_vScrollBar);
175 XtDestroyWidget ((Widget) m_vScrollBar);
176 }
177 if (m_scrolledWindow)
178 {
179 XtUnmanageChild ((Widget) m_scrolledWindow);
180 XtDestroyWidget ((Widget) m_scrolledWindow);
181 }
182
183 if (m_borderWidget)
184 {
185 XtDestroyWidget ((Widget) m_borderWidget);
186 m_borderWidget = (WXWidget) 0;
187 }
188 }
189
50414e24
JS
190 //// Generic stuff
191
4bb6408c
JS
192 // Have to delete constraints/sizer FIRST otherwise
193 // sizers may try to look at deleted windows as they
194 // delete themselves.
195#if USE_CONSTRAINTS
196 DeleteRelatedConstraints();
197 if (m_constraints)
198 {
199 // This removes any dangling pointers to this window
200 // in other windows' constraintsInvolvedIn lists.
201 UnsetConstraints(m_constraints);
202 delete m_constraints;
203 m_constraints = NULL;
204 }
205 if (m_windowSizer)
206 {
207 delete m_windowSizer;
208 m_windowSizer = NULL;
209 }
210 // If this is a child of a sizer, remove self from parent
211 if (m_sizerParent)
212 m_sizerParent->RemoveChild((wxWindow *)this);
213#endif
214
215 if (m_windowParent)
216 m_windowParent->RemoveChild(this);
217
218 DestroyChildren();
219
220 // Destroy the window
221 if (GetMainWidget())
222 {
223 wxDeleteWindowFromTable((Widget) GetMainWidget());
224 XtDestroyWidget((Widget) GetMainWidget());
225 SetMainWidget((WXWidget) NULL);
226 }
227
228 delete m_children;
229 m_children = NULL;
230
231 // Just in case the window has been Closed, but
232 // we're then deleting immediately: don't leave
233 // dangling pointers.
234 wxPendingDelete.DeleteObject(this);
235
236 if ( m_windowValidator )
237 delete m_windowValidator;
238}
239
240// Destroy the window (delayed, if a managed window)
241bool wxWindow::Destroy()
242{
243 delete this;
244 return TRUE;
245}
246
247// Constructor
248bool wxWindow::Create(wxWindow *parent, wxWindowID id,
249 const wxPoint& pos,
250 const wxSize& size,
251 long style,
252 const wxString& name)
253{
254 // Generic
255 m_windowId = 0;
256 m_windowStyle = 0;
257 m_windowParent = NULL;
258 m_windowEventHandler = this;
259 m_windowName = "";
260 m_windowCursor = *wxSTANDARD_CURSOR;
261 m_constraints = NULL;
262 m_constraintsInvolvedIn = NULL;
263 m_windowSizer = NULL;
264 m_sizerParent = NULL;
265 m_autoLayout = FALSE;
266 m_windowValidator = NULL;
4bb6408c
JS
267#if USE_DRAG_AND_DROP
268 m_pDropTarget = NULL;
269#endif
4bb6408c
JS
270 m_caretWidth = 0; m_caretHeight = 0;
271 m_caretEnabled = FALSE;
272 m_caretShown = FALSE;
273 m_minSizeX = -1;
274 m_minSizeY = -1;
275 m_maxSizeX = -1;
276 m_maxSizeY = -1;
277 m_defaultItem = NULL;
278 m_windowParent = NULL;
50414e24
JS
279
280 // Motif-specific
02e8b2f9 281 m_canAddEventHandler = FALSE;
50414e24
JS
282 m_mainWidget = (WXWidget) 0;
283 m_button1Pressed = FALSE;
284 m_button2Pressed = FALSE;
285 m_button3Pressed = FALSE;
286 m_winCaptured = FALSE;
287 m_isShown = TRUE;
288 m_hScrollBar = (WXWidget) 0;
289 m_vScrollBar = (WXWidget) 0;
290 m_borderWidget = (WXWidget) 0;
291 m_scrolledWindow = (WXWidget) 0;
292 m_drawingArea = (WXWidget) 0;
293 m_hScroll = FALSE;
294 m_vScroll = FALSE;
295 m_hScrollingEnabled = FALSE;
296 m_vScrollingEnabled = FALSE;
297 m_backingPixmap = (WXPixmap) 0;
298 m_pixmapWidth = 0;
299 m_pixmapHeight = 0;
300 m_pixmapOffsetX = 0;
301 m_pixmapOffsetY = 0;
302
4bb6408c
JS
303 if (!parent)
304 return FALSE;
305
306 if (parent) parent->AddChild(this);
307
308 m_returnCode = 0;
309
310 SetName(name);
311
312 if ( id == -1 )
313 m_windowId = (int)NewControlId();
314 else
315 m_windowId = id;
316
317 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
318 m_foregroundColour = *wxBLACK;
319 m_defaultForegroundColour = *wxBLACK ;
320 m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
321
322 m_windowStyle = style;
323
324 if ( id == -1 )
325 m_windowId = (int)NewControlId();
326 else
327 m_windowId = id;
328
50414e24
JS
329 //// TODO: we should probably optimize by only creating a
330 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
331 //// But for now, let's simplify things by always creating the
332 //// drawing area, since otherwise the translations are different.
333
334 // New translations for getting mouse motion feedback
335 String translations =
336 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
337 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
338 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
339 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
340 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
341 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
342 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
343 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
344 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
345 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
346 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
347 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
348 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
349 <Key>: DrawingAreaInput()";
350
351 XtActionsRec actions[1];
352 actions[0].string = "wxCanvasMotionEvent";
353 actions[0].proc = (XtActionProc) wxCanvasMotionEvent;
354 XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1);
355
356 Widget parentWidget = (Widget) parent->GetClientWidget();
357 if (style & wxBORDER)
358 m_borderWidget = (WXWidget) XtVaCreateManagedWidget ("canvasBorder",
359 xmFrameWidgetClass, parentWidget,
360 XmNshadowType, XmSHADOW_IN,
361 NULL);
362
363 m_scrolledWindow = (WXWidget) XtVaCreateManagedWidget ("scrolledWindow",
364 xmScrolledWindowWidgetClass, m_borderWidget ? (Widget) m_borderWidget : parentWidget,
365 XmNspacing, 0,
366 XmNscrollingPolicy, XmAPPLICATION_DEFINED,
367 NULL);
368
369 XtTranslations ptr;
370 m_drawingArea = (WXWidget) XtVaCreateWidget ((char*) (const char*) name,
371 xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow,
372 XmNunitType, XmPIXELS,
373// XmNresizePolicy, XmRESIZE_ANY,
374 XmNresizePolicy, XmRESIZE_NONE,
375 XmNmarginHeight, 0,
376 XmNmarginWidth, 0,
377 XmNtranslations, ptr = XtParseTranslationTable (translations),
378 NULL);
379 /*
380 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
381 {
382 XtFree ((char *) ptr);
383 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
384 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
385 XtFree ((char *) ptr);
386 }
387 */
388
389 wxAddWindowToTable((Widget) m_drawingArea, this);
390 wxAddWindowToTable((Widget) m_scrolledWindow, this);
391
392 /*
393 * This order is very important in Motif 1.2.1
394 *
395 */
396
397 XtRealizeWidget ((Widget) m_scrolledWindow);
398 XtRealizeWidget ((Widget) m_drawingArea);
399 XtManageChild ((Widget) m_drawingArea);
400
401 XtOverrideTranslations ((Widget) m_drawingArea,
402 ptr = XtParseTranslationTable ("<Configure>: resize()"));
403 XtFree ((char *) ptr);
404
405 XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this);
406 XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this);
407
408 /* TODO?
409 display = XtDisplay (scrolledWindow);
410 xwindow = XtWindow (drawingArea);
411 */
412
413 XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask,
414 False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this);
4bb6408c
JS
415
416 return TRUE;
417}
418
419void wxWindow::SetFocus()
420{
421 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
422 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
423}
424
425void wxWindow::Enable(bool enable)
426{
427 if (GetMainWidget())
428 {
429 XtSetSensitive((Widget) GetMainWidget(), enable);
430 XmUpdateDisplay((Widget) GetMainWidget());
431 }
432}
433
434void wxWindow::CaptureMouse()
435{
436 if (m_winCaptured)
437 return;
438
439 if (GetMainWidget())
440 XtAddGrab((Widget) GetMainWidget(), TRUE, FALSE);
441
442 m_winCaptured = TRUE;
443}
444
445void wxWindow::ReleaseMouse()
446{
447 if (!m_winCaptured)
448 return;
449
450 if (GetMainWidget())
451 XtRemoveGrab((Widget) GetMainWidget());
452 m_winCaptured = FALSE;
453}
454
455// Push/pop event handler (i.e. allow a chain of event handlers
456// be searched)
457void wxWindow::PushEventHandler(wxEvtHandler *handler)
458{
459 handler->SetNextHandler(GetEventHandler());
460 SetEventHandler(handler);
461}
462
463wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
464{
465 if ( GetEventHandler() )
466 {
467 wxEvtHandler *handlerA = GetEventHandler();
468 wxEvtHandler *handlerB = handlerA->GetNextHandler();
469 handlerA->SetNextHandler(NULL);
470 SetEventHandler(handlerB);
471 if ( deleteHandler )
472 {
473 delete handlerA;
474 return NULL;
475 }
476 else
477 return handlerA;
478 }
479 else
480 return NULL;
481}
482
483#if USE_DRAG_AND_DROP
484
485void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
486{
487 if ( m_pDropTarget != 0 ) {
488 delete m_pDropTarget;
489 }
490
491 m_pDropTarget = pDropTarget;
492 if ( m_pDropTarget != 0 )
493 {
494 // TODO
495 }
496}
497
498#endif
499
500// Old style file-manager drag&drop
501void wxWindow::DragAcceptFiles(bool accept)
502{
503 // TODO
504}
505
506// Get total size
507void wxWindow::GetSize(int *x, int *y) const
508{
50414e24
JS
509 if (m_drawingArea)
510 {
511 CanvasGetSize(x, y);
512 return;
513 }
514
02e8b2f9 515 Widget widget = (Widget) GetTopWidget();
4bb6408c
JS
516 Dimension xx, yy;
517 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
518 *x = xx; *y = yy;
519}
520
521void wxWindow::GetPosition(int *x, int *y) const
522{
50414e24
JS
523 if (m_drawingArea)
524 {
525 CanvasGetPosition(x, y);
526 return;
527 }
02e8b2f9 528 Widget widget = (Widget) GetTopWidget();
4bb6408c
JS
529 Position xx, yy;
530 XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL);
531 *x = xx; *y = yy;
532}
533
534void wxWindow::ScreenToClient(int *x, int *y) const
535{
536 // TODO
537}
538
539void wxWindow::ClientToScreen(int *x, int *y) const
540{
02e8b2f9 541 Widget widget = (Widget) GetClientWidget();
4bb6408c
JS
542 Display *display = XtDisplay(widget);
543 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
544 Window thisWindow;
545 if (this->IsKindOf(CLASSINFO(wxFrame)))
546 {
547 wxFrame *fr = (wxFrame *)this;
548 // TODO
549 // thisWindow = XtWindow(fr->m_clientArea);
550 }
551 else
552 thisWindow = XtWindow((Widget)widget);
553
554 Window childWindow;
555 int xx = *x;
556 int yy = *y;
557 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
558}
559
560void wxWindow::SetCursor(const wxCursor& cursor)
561{
562 m_windowCursor = cursor;
563 if (m_windowCursor.Ok())
564 {
565 /* TODO when wxCursor implemented
566 WXDisplay *dpy = GetXDisplay();
567 Cursor x_cursor = cursor.GetXCursor(dpy);
568
569 Widget w = (Widget) GetMainWidget();
570 Window win = XtWindow(w);
571 XDefineCursor((Display*) dpy, win, x_cursor);
572 */
573 }
574}
575
576
577// Get size *available for subwindows* i.e. excluding menu bar etc.
578void wxWindow::GetClientSize(int *x, int *y) const
579{
02e8b2f9 580 Widget widget = (Widget) GetTopWidget();
4bb6408c
JS
581 Dimension xx, yy;
582 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
583 *x = xx; *y = yy;
584}
585
586void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
587{
50414e24
JS
588 if (m_drawingArea)
589 {
590 CanvasSetSize(x, y, width, height, sizeFlags);
591 return;
592 }
02e8b2f9
JS
593 Widget widget = (Widget) GetTopWidget();
594 if (!widget)
595 return;
596
597 bool managed = XtIsManaged( widget );
598 if (managed)
599 XtUnmanageChild(widget);
4bb6408c
JS
600
601 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
602 XtVaSetValues(widget, XmNx, x, NULL);
603 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
604 XtVaSetValues(widget, XmNy, y, NULL);
605 if (width > -1)
606 XtVaSetValues(widget, XmNwidth, width, NULL);
607 if (height > -1)
608 XtVaSetValues(widget, XmNheight, height, NULL);
609
02e8b2f9
JS
610 if (managed)
611 XtManageChild(widget);
612
4bb6408c
JS
613 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
614 sizeEvent.SetEventObject(this);
615
616 GetEventHandler()->ProcessEvent(sizeEvent);
617}
618
619void wxWindow::SetClientSize(int width, int height)
620{
50414e24
JS
621 if (m_drawingArea)
622 {
623 CanvasSetClientSize(width, height);
624 return;
625 }
626
02e8b2f9 627 Widget widget = (Widget) GetTopWidget();
4bb6408c
JS
628
629 if (width > -1)
630 XtVaSetValues(widget, XmNwidth, width, NULL);
631 if (height > -1)
632 XtVaSetValues(widget, XmNheight, height, NULL);
633
634 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
635 sizeEvent.SetEventObject(this);
636
637 GetEventHandler()->ProcessEvent(sizeEvent);
638}
639
640// For implementation purposes - sometimes decorations make the client area
641// smaller
642wxPoint wxWindow::GetClientAreaOrigin() const
643{
644 return wxPoint(0, 0);
645}
646
647// Makes an adjustment to the window position (for example, a frame that has
648// a toolbar that it manages itself).
649void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
650{
651 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
652 {
653 wxPoint pt(GetParent()->GetClientAreaOrigin());
654 x += pt.x; y += pt.y;
655 }
656}
657
658bool wxWindow::Show(bool show)
659{
50414e24
JS
660 if (show)
661 {
662 if (m_borderWidget || m_scrolledWindow)
663 {
664 XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
665 }
666 else
667 {
02e8b2f9 668 XtMapWidget((Widget) GetTopWidget());
50414e24
JS
669 }
670 }
671 else
672 {
673 if (m_borderWidget || m_scrolledWindow)
674 {
675 XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
676 }
677 else
678 {
02e8b2f9 679 XtUnmapWidget((Widget) GetTopWidget());
50414e24
JS
680 }
681 }
682
683 /*
4bb6408c
JS
684 Window xwin = (Window) GetXWindow();
685 Display *xdisp = (Display*) GetXDisplay();
686 if (show)
687 XMapWindow(xdisp, xwin);
688 else
689 XUnmapWindow(xdisp, xwin);
50414e24 690 */
4bb6408c
JS
691
692 m_isShown = show;
693
694 return TRUE;
695}
696
697bool wxWindow::IsShown() const
698{
699 return m_isShown;
700}
701
702int wxWindow::GetCharHeight() const
703{
704 // TODO
705 return 0;
706}
707
708int wxWindow::GetCharWidth() const
709{
710 // TODO
711 return 0;
712}
713
714void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
715 int *descent, int *externalLeading, const wxFont *theFont, bool) const
716{
717 wxFont *fontToUse = (wxFont *)theFont;
718 if (!fontToUse)
719 fontToUse = (wxFont *) & m_windowFont;
720
721 // TODO
722}
723
724void wxWindow::Refresh(bool eraseBack, const wxRectangle *rect)
725{
726 Display *display = XtDisplay((Widget) GetMainWidget());
727 Window thisWindow = XtWindow((Widget) GetMainWidget());
728
729 XExposeEvent dummyEvent;
730 int width, height;
731 GetSize(&width, &height);
732
733 dummyEvent.type = Expose;
734 dummyEvent.display = display;
735 dummyEvent.send_event = True;
736 dummyEvent.window = thisWindow;
737 if (rect)
738 {
739 dummyEvent.x = rect->x;
740 dummyEvent.y = rect->y;
741 dummyEvent.width = rect->width;
742 dummyEvent.height = rect->height;
743 }
744 else
745 {
746 dummyEvent.x = 0;
747 dummyEvent.y = 0;
748 dummyEvent.width = width;
749 dummyEvent.height = height;
750 }
751 dummyEvent.count = 0;
752
753 if (eraseBack)
754 {
755 wxClientDC dc(this);
756 dc.Clear();
757 }
758
759 XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
760}
761
762// Responds to colour changes: passes event on to children.
763void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
764{
765 wxNode *node = GetChildren()->First();
766 while ( node )
767 {
768 // Only propagate to non-top-level windows
769 wxWindow *win = (wxWindow *)node->Data();
770 if ( win->GetParent() )
771 {
772 wxSysColourChangedEvent event2;
773 event.m_eventObject = win;
774 win->GetEventHandler()->ProcessEvent(event2);
775 }
776
777 node = node->Next();
778 }
779}
780
781// This can be called by the app (or wxWindows) to do default processing for the current
782// event. Save message/event info in wxWindow so they can be used in this function.
783long wxWindow::Default()
784{
785 // TODO
786 return 0;
787}
788
789void wxWindow::InitDialog()
790{
791 wxInitDialogEvent event(GetId());
792 event.SetEventObject( this );
793 GetEventHandler()->ProcessEvent(event);
794}
795
796// Default init dialog behaviour is to transfer data to window
797void wxWindow::OnInitDialog(wxInitDialogEvent& event)
798{
799 TransferDataToWindow();
800}
801
802// Caret manipulation
803void wxWindow::CreateCaret(int w, int h)
804{
805 m_caretWidth = w;
806 m_caretHeight = h;
807 m_caretEnabled = TRUE;
808}
809
810void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
811{
812 // TODO
813}
814
815void wxWindow::ShowCaret(bool show)
816{
817 // TODO
818}
819
820void wxWindow::DestroyCaret()
821{
822 // TODO
823 m_caretEnabled = FALSE;
824}
825
826void wxWindow::SetCaretPos(int x, int y)
827{
828 // TODO
829}
830
831void wxWindow::GetCaretPos(int *x, int *y) const
832{
833 // TODO
834}
835
836wxWindow *wxGetActiveWindow()
837{
838 // TODO
839 return NULL;
840}
841
842void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
843{
844 m_minSizeX = minW;
845 m_minSizeY = minH;
846 m_maxSizeX = maxW;
847 m_maxSizeY = maxH;
848
849 if (!this->IsKindOf(CLASSINFO(wxFrame)))
850 return;
851
852 wxFrame *frame = (wxFrame *)this;
853
854 /* Uncomment when wxFrame implemented
855 if (minW > -1)
856 XtVaSetValues((Widget) frame->m_frameShell, XmNminWidth, minW, NULL);
857 if (minH > -1)
858 XtVaSetValues((Widget) frame->m_frameShell, XmNminHeight, minH, NULL);
859 if (maxW > -1)
860 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxWidth, maxW, NULL);
861 if (maxH > -1)
862 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxHeight, maxH, NULL);
863 if (incW > -1)
864 XtVaSetValues((Widget) frame->m_frameShell, XmNwidthInc, incW, NULL);
865 if (incH > -1)
866 XtVaSetValues((Widget) frame->m_frameShell, XmNheightInc, incH, NULL);
867 */
868}
869
870void wxWindow::Centre(int direction)
871{
872 int x, y, width, height, panel_width, panel_height, new_x, new_y;
873
874 wxWindow *father = (wxWindow *)GetParent();
875 if (!father)
876 return;
877
878 father->GetClientSize(&panel_width, &panel_height);
879 GetSize(&width, &height);
880 GetPosition(&x, &y);
881
882 new_x = -1;
883 new_y = -1;
884
885 if (direction & wxHORIZONTAL)
886 new_x = (int)((panel_width - width)/2);
887
888 if (direction & wxVERTICAL)
889 new_y = (int)((panel_height - height)/2);
890
891 SetSize(new_x, new_y, -1, -1);
892
893}
894
895// Coordinates relative to the window
50414e24 896void wxWindow::WarpPointer (int x, int y)
4bb6408c 897{
50414e24 898 XWarpPointer (XtDisplay((Widget) GetClientWidget()), None, XtWindow((Widget) GetClientWidget()), 0, 0, 0, 0, x, y);
4bb6408c
JS
899}
900
901void wxWindow::OnEraseBackground(wxEraseEvent& event)
902{
903 // TODO
904 Default();
905}
906
907int wxWindow::GetScrollPos(int orient) const
908{
909 // TODO
910 return 0;
911}
912
913// This now returns the whole range, not just the number
914// of positions that we can scroll.
915int wxWindow::GetScrollRange(int orient) const
916{
917 // TODO
918 return 0;
919}
920
921int wxWindow::GetScrollThumb(int orient) const
922{
923 // TODO
924 return 0;
925}
926
927void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
928{
929 // TODO
930 return;
931}
932
933// New function that will replace some of the above.
934void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
935 int range, bool refresh)
936{
937 // TODO
938}
939
940// Does a physical scroll
941void wxWindow::ScrollWindow(int dx, int dy, const wxRectangle *rect)
942{
943 // TODO
944 return;
945}
946
947void wxWindow::SetFont(const wxFont& font)
948{
949 m_windowFont = font;
950
951 if (!m_windowFont.Ok())
952 return;
953 // TODO
954}
955
956void wxWindow::OnChar(wxKeyEvent& event)
957{
958 if ( event.KeyCode() == WXK_TAB ) {
959 // propagate the TABs to the parent - it's up to it to decide what
960 // to do with it
961 if ( GetParent() ) {
962 if ( GetParent()->ProcessEvent(event) )
963 return;
964 }
965 }
966}
967
968void wxWindow::OnPaint(wxPaintEvent& event)
969{
970 Default();
971}
972
973bool wxWindow::IsEnabled() const
974{
975 // TODO
976 return FALSE;
977}
978
979// Dialog support: override these and call
980// base class members to add functionality
981// that can't be done using validators.
982// NOTE: these functions assume that controls
983// are direct children of this window, not grandchildren
984// or other levels of descendant.
985
986// Transfer values to controls. If returns FALSE,
987// it's an application error (pops up a dialog)
988bool wxWindow::TransferDataToWindow()
989{
990 wxNode *node = GetChildren()->First();
991 while ( node )
992 {
993 wxWindow *child = (wxWindow *)node->Data();
994 if ( child->GetValidator() &&
995 !child->GetValidator()->TransferToWindow() )
996 {
997 wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION);
998 return FALSE;
999 }
1000
1001 node = node->Next();
1002 }
1003 return TRUE;
1004}
1005
1006// Transfer values from controls. If returns FALSE,
1007// validation failed: don't quit
1008bool wxWindow::TransferDataFromWindow()
1009{
1010 wxNode *node = GetChildren()->First();
1011 while ( node )
1012 {
1013 wxWindow *child = (wxWindow *)node->Data();
1014 if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() )
1015 {
1016 return FALSE;
1017 }
1018
1019 node = node->Next();
1020 }
1021 return TRUE;
1022}
1023
1024bool wxWindow::Validate()
1025{
1026 wxNode *node = GetChildren()->First();
1027 while ( node )
1028 {
1029 wxWindow *child = (wxWindow *)node->Data();
1030 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
1031 {
1032 return FALSE;
1033 }
1034
1035 node = node->Next();
1036 }
1037 return TRUE;
1038}
1039
1040// Get the window with the focus
1041wxWindow *wxWindow::FindFocus()
1042{
1043 // TODO
1044 return NULL;
1045}
1046
1047void wxWindow::AddChild(wxWindow *child)
1048{
1049 GetChildren()->Append(child);
1050 child->m_windowParent = this;
1051}
1052
1053void wxWindow::RemoveChild(wxWindow *child)
1054{
1055 if (GetChildren())
1056 GetChildren()->DeleteObject(child);
1057 child->m_windowParent = NULL;
1058}
1059
1060void wxWindow::DestroyChildren()
1061{
1062 if (GetChildren()) {
1063 wxNode *node;
1064 while ((node = GetChildren()->First()) != (wxNode *)NULL) {
1065 wxWindow *child;
1066 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
1067 delete child;
1068 if ( GetChildren()->Member(child) )
1069 delete node;
1070 }
1071 } /* while */
1072 }
1073}
1074
1075void wxWindow::MakeModal(bool modal)
1076{
1077 // Disable all other windows
1078 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
1079 {
1080 wxNode *node = wxTopLevelWindows.First();
1081 while (node)
1082 {
1083 wxWindow *win = (wxWindow *)node->Data();
1084 if (win != this)
1085 win->Enable(!modal);
1086
1087 node = node->Next();
1088 }
1089 }
1090}
1091
02e8b2f9
JS
1092// If nothing defined for this, try the parent.
1093// E.g. we may be a button loaded from a resource, with no callback function
1094// defined.
1095void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1096{
1097 if (GetEventHandler()->ProcessEvent(event) )
1098 return;
1099 if (m_windowParent)
1100 m_windowParent->GetEventHandler()->OnCommand(win, event);
1101}
1102
4bb6408c
JS
1103void wxWindow::SetConstraints(wxLayoutConstraints *c)
1104{
1105 if (m_constraints)
1106 {
1107 UnsetConstraints(m_constraints);
1108 delete m_constraints;
1109 }
1110 m_constraints = c;
1111 if (m_constraints)
1112 {
1113 // Make sure other windows know they're part of a 'meaningful relationship'
1114 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
1115 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1116 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
1117 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1118 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
1119 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1120 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
1121 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1122 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
1123 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1124 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
1125 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1126 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
1127 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1128 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
1129 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1130 }
1131}
1132
1133// This removes any dangling pointers to this window
1134// in other windows' constraintsInvolvedIn lists.
1135void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
1136{
1137 if (c)
1138 {
1139 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1140 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1141 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1142 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1143 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
1144 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1145 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
1146 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1147 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
1148 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1149 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
1150 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1151 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
1152 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1153 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
1154 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1155 }
1156}
1157
1158// Back-pointer to other windows we're involved with, so if we delete
1159// this window, we must delete any constraints we're involved with.
1160void wxWindow::AddConstraintReference(wxWindow *otherWin)
1161{
1162 if (!m_constraintsInvolvedIn)
1163 m_constraintsInvolvedIn = new wxList;
1164 if (!m_constraintsInvolvedIn->Member(otherWin))
1165 m_constraintsInvolvedIn->Append(otherWin);
1166}
1167
1168// REMOVE back-pointer to other windows we're involved with.
1169void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
1170{
1171 if (m_constraintsInvolvedIn)
1172 m_constraintsInvolvedIn->DeleteObject(otherWin);
1173}
1174
1175// Reset any constraints that mention this window
1176void wxWindow::DeleteRelatedConstraints()
1177{
1178 if (m_constraintsInvolvedIn)
1179 {
1180 wxNode *node = m_constraintsInvolvedIn->First();
1181 while (node)
1182 {
1183 wxWindow *win = (wxWindow *)node->Data();
1184 wxNode *next = node->Next();
1185 wxLayoutConstraints *constr = win->GetConstraints();
1186
1187 // Reset any constraints involving this window
1188 if (constr)
1189 {
1190 constr->left.ResetIfWin((wxWindow *)this);
1191 constr->top.ResetIfWin((wxWindow *)this);
1192 constr->right.ResetIfWin((wxWindow *)this);
1193 constr->bottom.ResetIfWin((wxWindow *)this);
1194 constr->width.ResetIfWin((wxWindow *)this);
1195 constr->height.ResetIfWin((wxWindow *)this);
1196 constr->centreX.ResetIfWin((wxWindow *)this);
1197 constr->centreY.ResetIfWin((wxWindow *)this);
1198 }
1199 delete node;
1200 node = next;
1201 }
1202 delete m_constraintsInvolvedIn;
1203 m_constraintsInvolvedIn = NULL;
1204 }
1205}
1206
1207void wxWindow::SetSizer(wxSizer *sizer)
1208{
1209 m_windowSizer = sizer;
1210 if (sizer)
1211 sizer->SetSizerParent((wxWindow *)this);
1212}
1213
1214/*
1215 * New version
1216 */
1217
1218bool wxWindow::Layout()
1219{
1220 if (GetConstraints())
1221 {
1222 int w, h;
1223 GetClientSize(&w, &h);
1224 GetConstraints()->width.SetValue(w);
1225 GetConstraints()->height.SetValue(h);
1226 }
1227
1228 // If top level (one sizer), evaluate the sizer's constraints.
1229 if (GetSizer())
1230 {
1231 int noChanges;
1232 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1233 GetSizer()->LayoutPhase1(&noChanges);
1234 GetSizer()->LayoutPhase2(&noChanges);
1235 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1236 return TRUE;
1237 }
1238 else
1239 {
1240 // Otherwise, evaluate child constraints
1241 ResetConstraints(); // Mark all constraints as unevaluated
1242 DoPhase(1); // Just one phase need if no sizers involved
1243 DoPhase(2);
1244 SetConstraintSizes(); // Recursively set the real window sizes
1245 }
1246 return TRUE;
1247}
1248
1249
1250// Do a phase of evaluating constraints:
1251// the default behaviour. wxSizers may do a similar
1252// thing, but also impose their own 'constraints'
1253// and order the evaluation differently.
1254bool wxWindow::LayoutPhase1(int *noChanges)
1255{
1256 wxLayoutConstraints *constr = GetConstraints();
1257 if (constr)
1258 {
1259 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
1260 }
1261 else
1262 return TRUE;
1263}
1264
1265bool wxWindow::LayoutPhase2(int *noChanges)
1266{
1267 *noChanges = 0;
1268
1269 // Layout children
1270 DoPhase(1);
1271 DoPhase(2);
1272 return TRUE;
1273}
1274
1275// Do a phase of evaluating child constraints
1276bool wxWindow::DoPhase(int phase)
1277{
1278 int noIterations = 0;
1279 int maxIterations = 500;
1280 int noChanges = 1;
1281 int noFailures = 0;
1282 wxList succeeded;
1283 while ((noChanges > 0) && (noIterations < maxIterations))
1284 {
1285 noChanges = 0;
1286 noFailures = 0;
1287 wxNode *node = GetChildren()->First();
1288 while (node)
1289 {
1290 wxWindow *child = (wxWindow *)node->Data();
1291 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
1292 {
1293 wxLayoutConstraints *constr = child->GetConstraints();
1294 if (constr)
1295 {
1296 if (succeeded.Member(child))
1297 {
1298 }
1299 else
1300 {
1301 int tempNoChanges = 0;
1302 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1303 noChanges += tempNoChanges;
1304 if (success)
1305 {
1306 succeeded.Append(child);
1307 }
1308 }
1309 }
1310 }
1311 node = node->Next();
1312 }
1313 noIterations ++;
1314 }
1315 return TRUE;
1316}
1317
1318void wxWindow::ResetConstraints()
1319{
1320 wxLayoutConstraints *constr = GetConstraints();
1321 if (constr)
1322 {
1323 constr->left.SetDone(FALSE);
1324 constr->top.SetDone(FALSE);
1325 constr->right.SetDone(FALSE);
1326 constr->bottom.SetDone(FALSE);
1327 constr->width.SetDone(FALSE);
1328 constr->height.SetDone(FALSE);
1329 constr->centreX.SetDone(FALSE);
1330 constr->centreY.SetDone(FALSE);
1331 }
1332 wxNode *node = GetChildren()->First();
1333 while (node)
1334 {
1335 wxWindow *win = (wxWindow *)node->Data();
1336 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1337 win->ResetConstraints();
1338 node = node->Next();
1339 }
1340}
1341
1342// Need to distinguish between setting the 'fake' size for
1343// windows and sizers, and setting the real values.
1344void wxWindow::SetConstraintSizes(bool recurse)
1345{
1346 wxLayoutConstraints *constr = GetConstraints();
1347 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
1348 constr->width.GetDone() && constr->height.GetDone())
1349 {
1350 int x = constr->left.GetValue();
1351 int y = constr->top.GetValue();
1352 int w = constr->width.GetValue();
1353 int h = constr->height.GetValue();
1354
1355 // If we don't want to resize this window, just move it...
1356 if ((constr->width.GetRelationship() != wxAsIs) ||
1357 (constr->height.GetRelationship() != wxAsIs))
1358 {
1359 // Calls Layout() recursively. AAAGH. How can we stop that.
1360 // Simply take Layout() out of non-top level OnSizes.
1361 SizerSetSize(x, y, w, h);
1362 }
1363 else
1364 {
1365 SizerMove(x, y);
1366 }
1367 }
1368 else if (constr)
1369 {
1370 char *windowClass = this->GetClassInfo()->GetClassName();
1371
1372 wxString winName;
1373 if (GetName() == "")
1374 winName = "unnamed";
1375 else
1376 winName = GetName();
1377 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
1378 if (!constr->left.GetDone())
1379 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1380 if (!constr->right.GetDone())
1381 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1382 if (!constr->width.GetDone())
1383 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1384 if (!constr->height.GetDone())
1385 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1386 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1387 }
1388
1389 if (recurse)
1390 {
1391 wxNode *node = GetChildren()->First();
1392 while (node)
1393 {
1394 wxWindow *win = (wxWindow *)node->Data();
1395 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1396 win->SetConstraintSizes();
1397 node = node->Next();
1398 }
1399 }
1400}
1401
1402// This assumes that all sizers are 'on' the same
1403// window, i.e. the parent of this window.
1404void wxWindow::TransformSizerToActual(int *x, int *y) const
1405{
1406 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
1407 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
1408 return;
1409
1410 int xp, yp;
1411 m_sizerParent->GetPosition(&xp, &yp);
1412 m_sizerParent->TransformSizerToActual(&xp, &yp);
1413 *x += xp;
1414 *y += yp;
1415}
1416
1417void wxWindow::SizerSetSize(int x, int y, int w, int h)
1418{
1419 int xx = x;
1420 int yy = y;
1421 TransformSizerToActual(&xx, &yy);
1422 SetSize(xx, yy, w, h);
1423}
1424
1425void wxWindow::SizerMove(int x, int y)
1426{
1427 int xx = x;
1428 int yy = y;
1429 TransformSizerToActual(&xx, &yy);
1430 Move(xx, yy);
1431}
1432
1433// Only set the size/position of the constraint (if any)
1434void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
1435{
1436 wxLayoutConstraints *constr = GetConstraints();
1437 if (constr)
1438 {
1439 if (x != -1)
1440 {
1441 constr->left.SetValue(x);
1442 constr->left.SetDone(TRUE);
1443 }
1444 if (y != -1)
1445 {
1446 constr->top.SetValue(y);
1447 constr->top.SetDone(TRUE);
1448 }
1449 if (w != -1)
1450 {
1451 constr->width.SetValue(w);
1452 constr->width.SetDone(TRUE);
1453 }
1454 if (h != -1)
1455 {
1456 constr->height.SetValue(h);
1457 constr->height.SetDone(TRUE);
1458 }
1459 }
1460}
1461
1462void wxWindow::MoveConstraint(int x, int y)
1463{
1464 wxLayoutConstraints *constr = GetConstraints();
1465 if (constr)
1466 {
1467 if (x != -1)
1468 {
1469 constr->left.SetValue(x);
1470 constr->left.SetDone(TRUE);
1471 }
1472 if (y != -1)
1473 {
1474 constr->top.SetValue(y);
1475 constr->top.SetDone(TRUE);
1476 }
1477 }
1478}
1479
1480void wxWindow::GetSizeConstraint(int *w, int *h) const
1481{
1482 wxLayoutConstraints *constr = GetConstraints();
1483 if (constr)
1484 {
1485 *w = constr->width.GetValue();
1486 *h = constr->height.GetValue();
1487 }
1488 else
1489 GetSize(w, h);
1490}
1491
1492void wxWindow::GetClientSizeConstraint(int *w, int *h) const
1493{
1494 wxLayoutConstraints *constr = GetConstraints();
1495 if (constr)
1496 {
1497 *w = constr->width.GetValue();
1498 *h = constr->height.GetValue();
1499 }
1500 else
1501 GetClientSize(w, h);
1502}
1503
1504void wxWindow::GetPositionConstraint(int *x, int *y) const
1505{
1506 wxLayoutConstraints *constr = GetConstraints();
1507 if (constr)
1508 {
1509 *x = constr->left.GetValue();
1510 *y = constr->top.GetValue();
1511 }
1512 else
1513 GetPosition(x, y);
1514}
1515
1516bool wxWindow::Close(bool force)
1517{
1518 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
1519 event.SetEventObject(this);
1520 event.SetForce(force);
1521
1522 return GetEventHandler()->ProcessEvent(event);
1523}
1524
1525wxObject* wxWindow::GetChild(int number) const
1526{
1527 // Return a pointer to the Nth object in the window
1528 if (!GetChildren())
1529 return(NULL) ;
1530 wxNode *node = GetChildren()->First();
1531 int n = number;
1532 while (node && n--)
1533 node = node->Next() ;
1534 if (node)
1535 {
1536 wxObject *obj = (wxObject *)node->Data();
1537 return(obj) ;
1538 }
1539 else
1540 return NULL ;
1541}
1542
1543void wxWindow::OnDefaultAction(wxControl *initiatingItem)
1544{
1545 // Obsolete function
1546}
1547
1548void wxWindow::Clear()
1549{
1550 wxClientDC dc(this);
1551 wxBrush brush(GetBackgroundColour(), wxSOLID);
1552 dc.SetBackground(brush);
1553 dc.Clear();
1554}
1555
1556// Fits the panel around the items
1557void wxWindow::Fit()
1558{
1559 int maxX = 0;
1560 int maxY = 0;
1561 wxNode *node = GetChildren()->First();
1562 while ( node )
1563 {
1564 wxWindow *win = (wxWindow *)node->Data();
1565 int wx, wy, ww, wh;
1566 win->GetPosition(&wx, &wy);
1567 win->GetSize(&ww, &wh);
1568 if ( wx + ww > maxX )
1569 maxX = wx + ww;
1570 if ( wy + wh > maxY )
1571 maxY = wy + wh;
1572
1573 node = node->Next();
1574 }
1575 SetClientSize(maxX + 5, maxY + 5);
1576}
1577
1578void wxWindow::SetValidator(const wxValidator& validator)
1579{
1580 if ( m_windowValidator )
1581 delete m_windowValidator;
1582 m_windowValidator = validator.Clone();
1583
1584 if ( m_windowValidator )
1585 m_windowValidator->SetWindow(this) ;
1586}
1587
1588// Find a window by id or name
1589wxWindow *wxWindow::FindWindow(long id)
1590{
1591 if ( GetId() == id)
1592 return this;
1593
1594 wxNode *node = GetChildren()->First();
1595 while ( node )
1596 {
1597 wxWindow *child = (wxWindow *)node->Data();
1598 wxWindow *found = child->FindWindow(id);
1599 if ( found )
1600 return found;
1601 node = node->Next();
1602 }
1603 return NULL;
1604}
1605
1606wxWindow *wxWindow::FindWindow(const wxString& name)
1607{
1608 if ( GetName() == name)
1609 return this;
1610
1611 wxNode *node = GetChildren()->First();
1612 while ( node )
1613 {
1614 wxWindow *child = (wxWindow *)node->Data();
1615 wxWindow *found = child->FindWindow(name);
1616 if ( found )
1617 return found;
1618 node = node->Next();
1619 }
1620 return NULL;
1621}
1622
1623void wxWindow::OnIdle(wxIdleEvent& event)
1624{
1625/* TODO: you may need to do something like this
1626 * if your GUI doesn't generate enter/leave events
1627
1628 // Check if we need to send a LEAVE event
1629 if (m_mouseInWindow)
1630 {
1631 POINT pt;
1632 ::GetCursorPos(&pt);
1633 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1634 {
1635 // Generate a LEAVE event
1636 m_mouseInWindow = FALSE;
1637 MSWOnMouseLeave(pt.x, pt.y, 0);
1638 }
1639 }
1640*/
1641
1642 // This calls the UI-update mechanism (querying windows for
1643 // menu/toolbar/control state information)
1644 UpdateWindowUI();
1645}
1646
1647// Raise the window to the top of the Z order
1648void wxWindow::Raise()
1649{
02e8b2f9
JS
1650 Window window = XtWindow((Widget) GetTopWidget());
1651 XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window);
4bb6408c
JS
1652}
1653
1654// Lower the window to the bottom of the Z order
1655void wxWindow::Lower()
1656{
02e8b2f9
JS
1657 Window window = XtWindow((Widget) GetTopWidget());
1658 XLowerWindow(XtDisplay((Widget) GetTopWidget()), window);
4bb6408c
JS
1659}
1660
1661bool wxWindow::AcceptsFocus() const
1662{
1663 return IsShown() && IsEnabled();
1664}
1665
1666// Update region access
1667wxRegion wxWindow::GetUpdateRegion() const
1668{
1669 return m_updateRegion;
1670}
1671
1672bool wxWindow::IsExposed(int x, int y, int w, int h) const
1673{
1674 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
1675}
1676
1677bool wxWindow::IsExposed(const wxPoint& pt) const
1678{
1679 return (m_updateRegion.Contains(pt) != wxOutRegion);
1680}
1681
1682bool wxWindow::IsExposed(const wxRect& rect) const
1683{
1684 return (m_updateRegion.Contains(rect) != wxOutRegion);
1685}
1686
1687/*
1688 * Allocates control IDs
1689 */
1690
1691int wxWindow::NewControlId()
1692{
1693 static int s_controlId = 0;
1694 s_controlId ++;
1695 return s_controlId;
1696}
1697
1698void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel)
1699{
1700 m_acceleratorTable = accel;
1701}
1702
1703// All widgets should have this as their resize proc.
1704// OnSize sent to wxWindow via client data.
1705void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
1706{
1707 wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w);
1708 if (!win)
1709 return;
1710
1711 if (win->PreResize())
1712 {
1713 int width, height;
1714 win->GetSize(&width, &height);
1715 wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
1716 sizeEvent.SetEventObject(win);
1717 win->GetEventHandler()->ProcessEvent(sizeEvent);
1718 }
1719}
1720
1721bool wxAddWindowToTable(Widget w, wxWindow *win)
1722{
1723 wxWindow *oldItem = NULL;
1724#if DEBUG
1725// printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
1726#endif
1727 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
1728 {
1729 char buf[300];
1730 sprintf(buf, "Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName());
1731 wxError (buf);
1732 fflush(stderr);
1733 sprintf(buf, "Old widget was %s", oldItem->GetClassInfo()->GetClassName());
1734 wxError (buf);
1735 return FALSE;
1736 }
1737
1738 wxWidgetHashTable->Put ((long) w, win);
1739 return TRUE;
1740}
1741
1742wxWindow *wxGetWindowFromTable(Widget w)
1743{
1744 return (wxWindow *)wxWidgetHashTable->Get ((long) w);
1745}
1746
1747void wxDeleteWindowFromTable(Widget w)
1748{
4bb6408c
JS
1749 wxWidgetHashTable->Delete((long)w);
1750}
1751
1752// Get the underlying X window and display
1753WXWindow wxWindow::GetXWindow() const
1754{
50414e24 1755 return (WXWindow) XtWindow((Widget) GetMainWidget());
4bb6408c
JS
1756}
1757
1758WXDisplay *wxWindow::GetXDisplay() const
1759{
50414e24 1760 return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
4bb6408c
JS
1761}
1762
1763WXWidget wxWindow::GetMainWidget() const
1764{
50414e24
JS
1765 if (m_drawingArea)
1766 return m_drawingArea;
1767 else
1768 return m_mainWidget;
1769}
1770
1771WXWidget wxWindow::GetClientWidget() const
1772{
1773 if (m_drawingArea != (WXWidget) 0)
1774 return m_drawingArea;
1775 else
02e8b2f9
JS
1776 return GetMainWidget();
1777}
1778
1779WXWidget wxWindow::GetTopWidget() const
1780{
1781 return GetMainWidget();
4bb6408c
JS
1782}
1783
50414e24
JS
1784void wxCanvasRepaintProc (Widget drawingArea, XtPointer clientData,
1785 XmDrawingAreaCallbackStruct * cbs)
1786{
1787 if (!wxWidgetHashTable->Get ((long) (Widget) drawingArea))
1788 return;
1789
1790 XEvent * event = cbs->event;
1791 wxWindow * canvas = (wxWindow *) clientData;
1792 Display * display = (Display *) canvas->GetXDisplay();
1793 // GC gc = (GC) canvas->GetDC()->gc;
1794
1795 switch (event->type)
1796 {
1797 case Expose:
1798 {
1799 /* TODO
1800 wxCanvasDC* canvasDC = canvas->GetDC();
1801 if (canvasDC)
1802 {
1803 if (canvasDC->onpaint_reg)
1804 XDestroyRegion(canvasDC->onpaint_reg);
1805 canvasDC->onpaint_reg = XCreateRegion();
1806
1807 }
1808 */
1809
1810 int n = canvas->m_updateRects.Number();
1811 XRectangle* xrects = new XRectangle[n];
1812 int i;
1813 for (i = 0; i < canvas->m_updateRects.Number(); i++)
1814 {
1815 wxRect* rect = (wxRect*) canvas->m_updateRects.Nth(i)->Data();
1816 xrects[i].x = rect->x;
1817 xrects[i].y = rect->y;
1818 xrects[i].width = rect->width;
1819 xrects[i].height = rect->height;
1820 /* TODO (?) Actually ignore it I think.
1821 if (canvasDC)
1822 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
1823 canvasDC->onpaint_reg);
1824 */
1825 }
1826 /* TODO must clip the area being repainted. So we need a gc.
1827 * Alternatively, wxPaintDC must do the clipping
1828 * when it's created.
1829 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
1830 */
1831
1832 canvas->DoPaint() ; // xrects, n);
1833 delete[] xrects;
1834
1835 canvas->m_updateRects.Clear();
1836
1837 /*
1838 if (canvasDC)
1839 {
1840 XDestroyRegion(canvasDC->onpaint_reg);
1841 canvasDC->onpaint_reg = NULL;
1842 }
1843
1844 XGCValues gc_val;
1845 gc_val.clip_mask = None;
1846 XChangeGC(display, gc, GCClipMask, &gc_val);
1847 */
1848
1849 break;
1850 }
1851 default:
1852 {
1853 cout << "\n\nNew Event ! is = " << event -> type << "\n";
1854 break;
1855 }
1856 }
1857}
1858
1859// Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1860void
1861wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event)
1862{
1863 XmDrawingAreaCallbackStruct cbs;
1864 XEvent ev;
1865
1866 //if (event->mode!=NotifyNormal)
1867 // return ;
1868
1869// ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
1870 ((XCrossingEvent &) ev) = *event;
1871
1872 cbs.reason = XmCR_INPUT;
1873 cbs.event = &ev;
1874
1875 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
1876}
1877
1878// Fix to make it work under Motif 1.0 (!)
1879void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
1880{
1881#if XmVersion<=1000
4bb6408c 1882
50414e24
JS
1883 XmDrawingAreaCallbackStruct cbs;
1884 XEvent ev;
1885
1886 //ev.xbutton = *event;
1887 ev = *((XEvent *) event);
1888 cbs.reason = XmCR_INPUT;
1889 cbs.event = &ev;
1890
1891 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
1892#endif
1893}
1894
1895void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs)
1896{
1897 wxWindow *canvas = (wxWindow *) wxWidgetHashTable->Get ((long) (Widget) drawingArea);
1898 XEvent local_event;
1899
1900 if (canvas==NULL)
1901 return ;
1902
1903 if (cbs->reason != XmCR_INPUT)
1904 return;
1905
1906 local_event = *(cbs->event); // We must keep a copy!
1907
1908 switch (local_event.xany.type)
1909 {
1910 case EnterNotify:
1911 case LeaveNotify:
1912 case ButtonPress:
1913 case ButtonRelease:
1914 case MotionNotify:
1915 {
1916 wxEventType eventType = wxEVT_NULL;
1917
1918 if (local_event.xany.type == EnterNotify)
1919 {
1920 //if (local_event.xcrossing.mode!=NotifyNormal)
1921 // return ; // Ignore grab events
1922 eventType = wxEVT_ENTER_WINDOW;
1923// canvas->GetEventHandler()->OnSetFocus();
1924 }
1925 else if (local_event.xany.type == LeaveNotify)
1926 {
1927 //if (local_event.xcrossing.mode!=NotifyNormal)
1928 // return ; // Ignore grab events
1929 eventType = wxEVT_LEAVE_WINDOW;
1930// canvas->GetEventHandler()->OnKillFocus();
1931 }
1932 else if (local_event.xany.type == MotionNotify)
1933 {
1934 eventType = wxEVT_MOTION;
1935 if (local_event.xmotion.is_hint == NotifyHint)
1936 {
1937 Window root, child;
1938 Display *dpy = XtDisplay (drawingArea);
1939
1940 XQueryPointer (dpy, XtWindow (drawingArea),
1941 &root, &child,
1942 &local_event.xmotion.x_root,
1943 &local_event.xmotion.y_root,
1944 &local_event.xmotion.x,
1945 &local_event.xmotion.y,
1946 &local_event.xmotion.state);
1947 }
1948 else
1949 {
1950 }
1951 }
1952
1953 else if (local_event.xany.type == ButtonPress)
1954 {
1955 if (local_event.xbutton.button == Button1)
1956 {
1957 eventType = wxEVT_LEFT_DOWN;
1958 canvas->m_button1Pressed = TRUE;
1959 }
1960 else if (local_event.xbutton.button == Button2)
1961 {
1962 eventType = wxEVT_MIDDLE_DOWN;
1963 canvas->m_button2Pressed = TRUE;
1964 }
1965 else if (local_event.xbutton.button == Button3)
1966 {
1967 eventType = wxEVT_RIGHT_DOWN;
1968 canvas->m_button3Pressed = TRUE;
1969 }
1970 }
1971 else if (local_event.xany.type == ButtonRelease)
1972 {
1973 if (local_event.xbutton.button == Button1)
1974 {
1975 eventType = wxEVT_LEFT_UP;
1976 canvas->m_button1Pressed = FALSE;
1977 }
1978 else if (local_event.xbutton.button == Button2)
1979 {
1980 eventType = wxEVT_MIDDLE_UP;
1981 canvas->m_button2Pressed = FALSE;
1982 }
1983 else if (local_event.xbutton.button == Button3)
1984 {
1985 eventType = wxEVT_RIGHT_UP;
1986 canvas->m_button3Pressed = FALSE;
1987 }
1988 }
1989
1990 wxMouseEvent wxevent (eventType);
1991 wxevent.m_eventHandle = (char *) &local_event;
1992
1993 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
1994 || (event_left_is_down (&local_event)
1995 && (eventType != wxEVT_LEFT_UP)));
1996 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
1997 || (event_middle_is_down (&local_event)
1998 && (eventType != wxEVT_MIDDLE_UP)));
1999 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
2000 || (event_right_is_down (&local_event)
2001 && (eventType != wxEVT_RIGHT_UP)));
2002
2003 wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask;
2004 wxevent.m_controlDown = local_event.xbutton.state & ControlMask;
2005 wxevent.m_altDown = local_event.xbutton.state & Mod3Mask;
2006 wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask;
2007 wxevent.SetTimestamp(local_event.xbutton.time);
2008
2009 // Now check if we need to translate this event into a double click
2010 if (TRUE) // canvas->doubleClickAllowed)
2011 {
2012 if (wxevent.ButtonDown())
2013 {
2014 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()) ;
2015
2016 // get button and time-stamp
2017 int button = 0;
2018 if (wxevent.LeftDown()) button = 1;
2019 else if (wxevent.MiddleDown()) button = 2;
2020 else if (wxevent.RightDown()) button = 3;
2021 long ts = wxevent.GetTimestamp();
2022 // check, if single or double click
2023 if (canvas->m_lastButton && canvas->m_lastButton==button && (ts - canvas->m_lastTS) < dclickTime)
2024 {
2025 // I have a dclick
2026 canvas->m_lastButton = 0;
2027 switch ( eventType )
2028 {
2029 case wxEVT_LEFT_DOWN:
2030 wxevent.SetEventType(wxEVT_LEFT_DCLICK);
2031 break;
2032 case wxEVT_MIDDLE_DOWN:
2033 wxevent.SetEventType(wxEVT_MIDDLE_DCLICK);
2034 break;
2035 case wxEVT_RIGHT_DOWN:
2036 wxevent.SetEventType(wxEVT_RIGHT_DCLICK);
2037 break;
2038
2039 default :
2040 break;
2041 }
2042
2043 }
2044 else
2045 {
2046 // not fast enough or different button
2047 canvas->m_lastTS = ts;
2048 canvas->m_lastButton = button;
2049 }
2050 }
2051 }
2052
2053 wxevent.SetId(canvas->GetId());
2054 wxevent.SetEventObject(canvas);
2055 canvas->GetEventHandler()->ProcessEvent (wxevent);
2056 /*
2057 if (eventType == wxEVT_ENTER_WINDOW ||
2058 eventType == wxEVT_LEAVE_WINDOW ||
2059 eventType == wxEVT_MOTION
2060 )
2061 return;
2062 */
2063 break;
2064 }
2065 case KeyPress:
2066 {
2067 KeySym keySym;
2068// XComposeStatus compose;
2069// (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2070 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2071 int id = wxCharCodeXToWX (keySym);
2072
2073 wxKeyEvent event (wxEVT_CHAR);
2074
2075 if (local_event.xkey.state & ShiftMask)
2076 event.m_shiftDown = TRUE;
2077 if (local_event.xkey.state & ControlMask)
2078 event.m_controlDown = TRUE;
2079 if (local_event.xkey.state & Mod3Mask)
2080 event.m_altDown = TRUE;
2081 if (local_event.xkey.state & Mod1Mask)
2082 event.m_metaDown = TRUE;
2083 event.SetEventObject(canvas);
2084 event.m_keyCode = id;
2085 event.SetTimestamp(local_event.xkey.time);
2086
2087 if (id > -1)
2088 {
2089 // Implement wxFrame::OnCharHook by checking ancestor.
2090 wxWindow *parent = canvas->GetParent();
2091 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)))
2092 parent = parent->GetParent();
2093
2094 if (parent)
2095 {
2096 event.SetEventType(wxEVT_CHAR_HOOK);
2097 if (parent->GetEventHandler()->ProcessEvent(event))
2098 return;
2099 event.SetEventType(wxEVT_CHAR);
2100 }
2101
2102 canvas->GetEventHandler()->ProcessEvent (event);
2103 }
2104 break;
2105 }
2106 case FocusIn:
2107 {
2108 if (local_event.xfocus.detail != NotifyPointer)
2109 {
2110 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
2111 event.SetEventObject(canvas);
2112 canvas->GetEventHandler()->ProcessEvent(event);
2113 }
2114 break;
2115 }
2116 case FocusOut:
2117 {
2118 if (local_event.xfocus.detail != NotifyPointer)
2119 {
2120 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
2121 event.SetEventObject(canvas);
2122 canvas->GetEventHandler()->ProcessEvent(event);
2123 }
2124 break;
2125 }
2126 default:
2127 break;
2128 }
2129}
2130
2131void wxWindow::DoPaint()
2132{
2133 //TODO : make a temporary gc so we can do the XCopyArea below
2134 if (0) // m_backingPixmap)
2135 {
2136 /*
2137 Widget drawingArea = (Widget) m_drawingArea;
2138 // int orig = GetDC()->GetLogicalFunction();
2139 // GetDC()->SetLogicalFunction (wxCOPY);
2140
2141 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2142 // should be able to calculate them.
2143 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2144 m_pixmapOffsetX, m_pixmapOffsetY,
2145 m_pixmapWidth, m_pixmapHeight,
2146 0, 0);
2147
2148 // GetDC()->SetLogicalFunction (orig);
2149 */
2150 }
2151 else
2152 {
2153 wxPaintEvent event(GetId());
2154 event.SetEventObject(this);
2155 GetEventHandler()->ProcessEvent(event);
2156 }
2157}
2158
2159// SetSize, but as per old wxCanvas (with drawing widget etc.)
2160void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags)
2161{
2162 Widget drawingArea = (Widget) m_drawingArea;
2163 bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2164
2165 if (managed)
2166 XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2167 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2168
2169 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2170 {
2171 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2172 XmNx, x, NULL);
2173 }
2174
2175 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2176 {
2177 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2178 XmNy, y, NULL);
2179 }
2180
2181 if (w > -1)
2182 {
2183 if (m_borderWidget)
2184 {
2185 XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL);
2186 short thick, margin;
2187 XtVaGetValues ((Widget) m_borderWidget,
2188 XmNshadowThickness, &thick,
2189 XmNmarginWidth, &margin,
2190 NULL);
2191 w -= 2 * (thick + margin);
2192 }
2193
2194 XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL);
2195
2196 Dimension spacing;
2197 Widget sbar;
2198 XtVaGetValues ((Widget) m_scrolledWindow,
2199 XmNspacing, &spacing,
2200 XmNverticalScrollBar, &sbar,
2201 NULL);
2202 Dimension wsbar;
2203 if (sbar)
2204 XtVaGetValues (sbar, XmNwidth, &wsbar, NULL);
2205 else
2206 wsbar = 0;
2207
2208 w -= (spacing + wsbar);
2209
2210 XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2211 }
2212 if (h > -1)
2213 {
2214 if (m_borderWidget)
2215 {
2216 XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL);
2217 short thick, margin;
2218 XtVaGetValues ((Widget) m_borderWidget,
2219 XmNshadowThickness, &thick,
2220 XmNmarginHeight, &margin,
2221 NULL);
2222 h -= 2 * (thick + margin);
2223 }
2224
2225 XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL);
2226
2227 Dimension spacing;
2228 Widget sbar;
2229 XtVaGetValues ((Widget) m_scrolledWindow,
2230 XmNspacing, &spacing,
2231 XmNhorizontalScrollBar, &sbar,
2232 NULL);
2233 Dimension wsbar;
2234 if (sbar)
2235 XtVaGetValues (sbar, XmNheight, &wsbar, NULL);
2236 else
2237 wsbar = 0;
2238
2239 h -= (spacing + wsbar);
2240
2241 XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2242 }
2243 if (managed)
2244 XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2245 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2246
2247 int ww, hh;
2248 GetClientSize (&ww, &hh);
2249 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2250 sizeEvent.SetEventObject(this);
2251
2252 GetEventHandler()->ProcessEvent(sizeEvent);
2253}
2254
2255void wxWindow::CanvasSetClientSize (int w, int h)
2256{
2257 Widget drawingArea = (Widget) m_drawingArea;
2258
2259 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2260
2261 if (w > -1)
2262 XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2263 if (h > -1)
2264 XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2265 /* TODO: is this necessary?
2266 allowRepainting = FALSE;
2267
2268 XSync (XtDisplay (drawingArea), FALSE);
2269 XEvent event;
2270 while (XtAppPending (wxTheApp->appContext))
2271 {
2272 XFlush (XtDisplay (drawingArea));
2273 XtAppNextEvent (wxTheApp->appContext, &event);
2274 XtDispatchEvent (&event);
2275 }
2276 */
2277
2278 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2279
2280 /* TODO
2281 allowRepainting = TRUE;
2282 DoRefresh ();
2283 */
2284
2285 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2286 sizeEvent.SetEventObject(this);
2287
2288 GetEventHandler()->ProcessEvent(sizeEvent);
2289}
2290
2291void wxWindow::CanvasGetClientSize (int *w, int *h) const
2292{
2293 // Must return the same thing that was set via SetClientSize
2294 Dimension xx, yy;
2295 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2296 *w = xx;
2297 *h = yy;
2298}
2299
2300void wxWindow::CanvasGetSize (int *w, int *h) const
2301{
2302 Dimension xx, yy;
2303 if ((Widget) m_borderWidget)
2304 XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
2305 else if ((Widget) m_scrolledWindow)
2306 XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL);
2307 else
2308 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2309
2310 *w = xx;
2311 *h = yy;
2312}
2313
2314void wxWindow::CanvasGetPosition (int *x, int *y) const
2315{
2316 Position xx, yy;
2317 XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
2318 *x = xx;
2319 *y = yy;
2320}
02e8b2f9
JS
2321
2322// Add to hash table, add event handler
2323bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
2324 WXWidget formWidget, int x, int y, int width, int height)
2325{
2326 wxAddWindowToTable((Widget) mainWidget, this);
2327 if (CanAddEventHandler())
2328 {
2329 XtAddEventHandler((Widget) mainWidget,
2330 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
2331 False,
2332 wxPanelItemEventHandler,
2333 (XtPointer) this);
2334 }
2335
2336 if (!formWidget)
2337 {
2338 XtTranslations ptr;
2339 XtOverrideTranslations ((Widget) mainWidget,
2340 ptr = XtParseTranslationTable ("<Configure>: resize()"));
2341 XtFree ((char *) ptr);
2342 }
2343
2344 // Some widgets have a parent form widget, e.g. wxRadioBox
2345 if (formWidget)
2346 {
2347 if (!wxAddWindowToTable((Widget) formWidget, this))
2348 return FALSE;
2349
2350 XtTranslations ptr;
2351 XtOverrideTranslations ((Widget) formWidget,
2352 ptr = XtParseTranslationTable ("<Configure>: resize()"));
2353 XtFree ((char *) ptr);
2354 }
2355
2356 if (x == -1)
2357 x = 0;
2358 if (y == -1)
2359 y = 0;
2360 SetSize (x, y, width, height);
2361
2362 return TRUE;
2363}
2364
2365// Remove event handler, remove from hash table
2366bool wxWindow::DetachWidget(WXWidget widget)
2367{
2368 if (CanAddEventHandler())
2369 {
2370 XtRemoveEventHandler((Widget) widget,
2371 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
2372 False,
2373 wxPanelItemEventHandler,
2374 (XtPointer)this);
2375 }
2376
2377 wxDeleteWindowFromTable((Widget) widget);
2378 return TRUE;
2379}
2380
2381void wxPanelItemEventHandler (Widget wid,
2382 XtPointer client_data,
2383 XEvent* event,
2384 Boolean *continueToDispatch)
2385{
2386 // Widget can be a label or the actual widget.
2387
2388 wxWindow *window = (wxWindow *)wxWidgetHashTable->Get((long)wid);
2389 if (window)
2390 {
2391 wxMouseEvent wxevent(0);
2392 if (wxTranslateMouseEvent(wxevent, window, wid, event))
2393 {
2394 window->GetEventHandler()->ProcessEvent(wxevent);
2395 }
2396 }
2397 // TODO: probably the key to allowing default behaviour
2398 // to happen.
2399 // Say we set a m_doDefault flag to FALSE at the start of this
2400 // function. Then in e.g. wxWindow::OnMouseEvent we can
2401 // call Default() which sets this flag to TRUE, indicating
2402 // that default processing can happen. Thus, behaviour can appear
2403 // to be overridden just by adding an event handler and not calling
2404 // wxWindow::OnWhatever.
2405 // ALSO, maybe we can use this instead of the current way of handling
2406 // drawing area events, to simplify things.
2407 *continueToDispatch = True;
2408}
2409
2410bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
2411{
2412 switch (xevent->xany.type)
2413 {
2414 case EnterNotify:
2415 case LeaveNotify:
2416 case ButtonPress:
2417 case ButtonRelease:
2418 case MotionNotify:
2419 {
2420 wxEventType eventType = wxEVT_NULL;
2421
2422 if (xevent->xany.type == LeaveNotify)
2423 {
2424 win->m_button1Pressed = FALSE;
2425 win->m_button2Pressed = FALSE;
2426 win->m_button3Pressed = FALSE;
2427 return FALSE;
2428 }
2429 else if (xevent->xany.type == MotionNotify)
2430 {
2431 eventType = wxEVT_MOTION;
2432 }
2433 else if (xevent->xany.type == ButtonPress)
2434 {
2435 if (xevent->xbutton.button == Button1)
2436 {
2437 eventType = wxEVT_LEFT_DOWN;
2438 win->m_button1Pressed = TRUE;
2439 }
2440 else if (xevent->xbutton.button == Button2)
2441 {
2442 eventType = wxEVT_MIDDLE_DOWN;
2443 win->m_button2Pressed = TRUE;
2444 }
2445 else if (xevent->xbutton.button == Button3)
2446 {
2447 eventType = wxEVT_RIGHT_DOWN;
2448 win->m_button3Pressed = TRUE;
2449 }
2450 }
2451 else if (xevent->xany.type == ButtonRelease)
2452 {
2453 if (xevent->xbutton.button == Button1)
2454 {
2455 eventType = wxEVT_LEFT_UP;
2456 win->m_button1Pressed = FALSE;
2457 }
2458 else if (xevent->xbutton.button == Button2)
2459 {
2460 eventType = wxEVT_MIDDLE_UP;
2461 win->m_button2Pressed = FALSE;
2462 }
2463 else if (xevent->xbutton.button == Button3)
2464 {
2465 eventType = wxEVT_RIGHT_UP;
2466 win->m_button3Pressed = FALSE;
2467 }
2468 else return FALSE;
2469 }
2470 else return FALSE;
2471
2472 wxevent.m_eventHandle = (char *)xevent;
2473 wxevent.SetEventType(eventType);
2474
2475 Position x1, y1;
2476 XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
2477
2478 int x2, y2;
2479 win->GetPosition(&x2, &y2);
2480
2481 // The button x/y must be translated to wxWindows
2482 // window space - the widget might be a label or button,
2483 // within a form.
2484 int dx = 0;
2485 int dy = 0;
2486 if (widget != (Widget)win->GetMainWidget())
2487 {
2488 dx = x1;
2489 dy = y1;
2490 }
2491
2492 wxevent.m_x = xevent->xbutton.x + dx;
2493 wxevent.m_y = xevent->xbutton.y + dy;
2494
2495 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
2496 || (event_left_is_down (xevent)
2497 && (eventType != wxEVT_LEFT_UP)));
2498 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
2499 || (event_middle_is_down (xevent)
2500 && (eventType != wxEVT_MIDDLE_UP)));
2501 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
2502 || (event_right_is_down (xevent)
2503 && (eventType != wxEVT_RIGHT_UP)));
2504
2505 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
2506 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
2507 return TRUE;
2508 }
2509 }
2510 return FALSE;
2511}
2512
2513bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
2514{
2515 switch (xevent->xany.type)
2516 {
2517 case KeyPress:
2518 {
2519 char buf[20];
2520
2521 KeySym keySym;
2522// XComposeStatus compose;
2523// (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2524 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
2525 int id = wxCharCodeXToWX (keySym);
2526
2527 if (xevent->xkey.state & ShiftMask)
2528 wxevent.m_shiftDown = TRUE;
2529 if (xevent->xkey.state & ControlMask)
2530 wxevent.m_controlDown = TRUE;
2531 if (xevent->xkey.state & Mod3Mask)
2532 wxevent.m_altDown = TRUE;
2533 if (xevent->xkey.state & Mod1Mask)
2534 wxevent.m_metaDown = TRUE;
2535 wxevent.SetEventObject(win);
2536 wxevent.m_keyCode = id;
2537 wxevent.SetTimestamp(xevent->xkey.time);
2538
2539 wxevent.m_x = xevent->xbutton.x;
2540 wxevent.m_y = xevent->xbutton.y;
2541
2542 if (id > -1)
2543 return TRUE;
2544 else
2545 return FALSE;
2546 break;
2547 }
2548 default:
2549 break;
2550 }
2551 return FALSE;
2552}
2553
2554// TODO From wxWin 1.68. What does it do exactly?
2555#define YAllocColor XAllocColor
2556
2557XColor itemColors[5];
2558int wxComputeColors (Display *display, wxColour * back, wxColour * fore)
2559{
2560 int result;
2561 static XmColorProc colorProc;
2562
2563 result = wxNO_COLORS;
2564
2565 if (back)
2566 {
2567 itemColors[0].red = (((long) back->Red ()) << 8);
2568 itemColors[0].green = (((long) back->Green ()) << 8);
2569 itemColors[0].blue = (((long) back->Blue ()) << 8);
2570 itemColors[0].flags = DoRed | DoGreen | DoBlue;
2571 if (colorProc == (XmColorProc) NULL)
2572 {
2573 // Get a ptr to the actual function
2574 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
2575 // And set it back to motif.
2576 XmSetColorCalculation (colorProc);
2577 }
2578 (*colorProc) (&itemColors[wxBACK_INDEX],
2579 &itemColors[wxFORE_INDEX],
2580 &itemColors[wxSELE_INDEX],
2581 &itemColors[wxTOPS_INDEX],
2582 &itemColors[wxBOTS_INDEX]);
2583 result = wxBACK_COLORS;
2584 }
2585 if (fore)
2586 {
2587 itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
2588 itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
2589 itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
2590 itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
2591 if (result == wxNO_COLORS)
2592 result = wxFORE_COLORS;
2593 }
2594
2595 Display *dpy = display;
2596 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
2597
2598 if (back)
2599 {
2600 /* 5 Colours to allocate */
2601 for (int i = 0; i < 5; i++)
2602 if (!YAllocColor (dpy, cmap, &itemColors[i]))
2603 result = wxNO_COLORS;
2604 }
2605 else if (fore)
2606 {
2607 /* Only 1 colour to allocate */
2608 if (!YAllocColor (dpy, cmap, &itemColors[wxFORE_INDEX]))
2609 result = wxNO_COLORS;
2610 }
2611
2612 return (result);
2613
2614}
2615
2616void wxWindow::ChangeColour(WXWidget widget)
2617{
2618 // TODO
2619#if 0
2620 int change;
2621
2622 // TODO: how to determine whether we can change this item's colours?
2623 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
2624 // can change it.
2625 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
2626 // return;
2627
2628 change = wxComputeColors (XtDisplay((Widget)widget), panel->GetBackgroundColour(),
2629 panel->GetLabelColour());
2630 if (change == wxBACK_COLORS)
2631 XtVaSetValues ((Widget) widget,
2632 XmNbackground, itemColors[wxBACK_INDEX].pixel,
2633 XmNtopShadowColor, itemColors[wxTOPS_INDEX].pixel,
2634 XmNbottomShadowColor, itemColors[wxBOTS_INDEX].pixel,
2635 XmNforeground, itemColors[wxFORE_INDEX].pixel,
2636 NULL);
2637 else if (change == wxFORE_COLORS)
2638 XtVaSetValues (formWidget,
2639 XmNforeground, itemColors[wxFORE_INDEX].pixel,
2640 NULL);
2641
2642 change = wxComputeColors (XtDisplay((Widget)formWidget), GetBackgroundColour(), GetLabelColour());
2643 if (change == wxBACK_COLORS)
2644 XtVaSetValues (labelWidget,
2645 XmNbackground, itemColors[wxBACK_INDEX].pixel,
2646 XmNtopShadowColor, itemColors[wxTOPS_INDEX].pixel,
2647 XmNbottomShadowColor, itemColors[wxBOTS_INDEX].pixel,
2648 XmNarmColor, itemColors[wxSELE_INDEX].pixel,
2649 XmNforeground, itemColors[wxFORE_INDEX].pixel,
2650 NULL);
2651 else if (change == wxFORE_COLORS)
2652 XtVaSetValues (labelWidget,
2653 XmNforeground, itemColors[wxFORE_INDEX].pixel,
2654 NULL);
2655#endif
2656}
2657
2658void wxWindow::ChangeFont(WXWidget widget)
2659{
2660 /* TODO
2661 if (widget && GetFont() && GetFont()->IsOk())
2662 XtVaSetValues ((Widget) widget,
2663 XmNfontList, GetFont()->GetInternalFont (),
2664 NULL);
2665 */
2666}