| 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 | // ============================================================================ |
| 13 | // declarations |
| 14 | // ============================================================================ |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // headers |
| 18 | // ---------------------------------------------------------------------------- |
| 19 | |
| 20 | #ifdef __GNUG__ |
| 21 | #pragma implementation "window.h" |
| 22 | #endif |
| 23 | |
| 24 | #ifdef __VMS |
| 25 | #define XtDisplay XTDISPLAY |
| 26 | #define XtWindow XTWINDOW |
| 27 | #define XtScreen XTSCREEN |
| 28 | #endif |
| 29 | |
| 30 | #include "wx/setup.h" |
| 31 | #include "wx/menu.h" |
| 32 | #include "wx/dc.h" |
| 33 | #include "wx/dcclient.h" |
| 34 | #include "wx/utils.h" |
| 35 | #include "wx/app.h" |
| 36 | #include "wx/panel.h" |
| 37 | #include "wx/layout.h" |
| 38 | #include "wx/dialog.h" |
| 39 | #include "wx/listbox.h" |
| 40 | #include "wx/button.h" |
| 41 | #include "wx/settings.h" |
| 42 | #include "wx/msgdlg.h" |
| 43 | #include "wx/frame.h" |
| 44 | #include "wx/scrolwin.h" |
| 45 | #include "wx/module.h" |
| 46 | #include "wx/menuitem.h" |
| 47 | #include "wx/log.h" |
| 48 | |
| 49 | #if wxUSE_DRAG_AND_DROP |
| 50 | #include "wx/dnd.h" |
| 51 | #endif |
| 52 | |
| 53 | #ifdef __VMS__ |
| 54 | #pragma message disable nosimpint |
| 55 | #endif |
| 56 | #include <Xm/Xm.h> |
| 57 | |
| 58 | #include <Xm/DrawingA.h> |
| 59 | #include <Xm/ScrolledW.h> |
| 60 | #include <Xm/ScrollBar.h> |
| 61 | #include <Xm/Frame.h> |
| 62 | #include <Xm/Label.h> |
| 63 | #include <Xm/RowColumn.h> // for XmMenuPosition |
| 64 | #ifdef __VMS__ |
| 65 | #pragma message enable nosimpint |
| 66 | #endif |
| 67 | |
| 68 | #include "wx/motif/private.h" |
| 69 | |
| 70 | #include <string.h> |
| 71 | |
| 72 | // ---------------------------------------------------------------------------- |
| 73 | // constants |
| 74 | // ---------------------------------------------------------------------------- |
| 75 | |
| 76 | static const int SCROLL_MARGIN = 4; |
| 77 | |
| 78 | // ---------------------------------------------------------------------------- |
| 79 | // global variables for this module |
| 80 | // ---------------------------------------------------------------------------- |
| 81 | |
| 82 | extern wxHashTable *wxWidgetHashTable; |
| 83 | static wxWindow* g_captureWindow = NULL; |
| 84 | |
| 85 | |
| 86 | // ---------------------------------------------------------------------------- |
| 87 | // private functions |
| 88 | // ---------------------------------------------------------------------------- |
| 89 | |
| 90 | static void wxCanvasRepaintProc(Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs); |
| 91 | static void wxCanvasInputEvent(Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs); |
| 92 | static void wxCanvasMotionEvent(Widget, XButtonEvent * event); |
| 93 | static void wxCanvasEnterLeave(Widget drawingArea, XtPointer clientData, XCrossingEvent * event); |
| 94 | static void wxScrollBarCallback(Widget widget, XtPointer clientData, |
| 95 | XmScrollBarCallbackStruct *cbs); |
| 96 | static void wxPanelItemEventHandler(Widget wid, |
| 97 | XtPointer client_data, |
| 98 | XEvent* event, |
| 99 | Boolean *continueToDispatch); |
| 100 | |
| 101 | // unused for now |
| 102 | #if 0 |
| 103 | |
| 104 | // Helper function for 16-bit fonts |
| 105 | static int str16len(const char *s) |
| 106 | { |
| 107 | int count = 0; |
| 108 | |
| 109 | while (s[0] && s[1]) { |
| 110 | count++; |
| 111 | s += 2; |
| 112 | } |
| 113 | |
| 114 | return count; |
| 115 | } |
| 116 | |
| 117 | #endif // 0 |
| 118 | |
| 119 | // ---------------------------------------------------------------------------- |
| 120 | // macros |
| 121 | // ---------------------------------------------------------------------------- |
| 122 | |
| 123 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) |
| 124 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) |
| 125 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) |
| 126 | |
| 127 | // ---------------------------------------------------------------------------- |
| 128 | // event tables |
| 129 | // ---------------------------------------------------------------------------- |
| 130 | |
| 131 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) |
| 132 | |
| 133 | BEGIN_EVENT_TABLE(wxWindow, wxWindowBase) |
| 134 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) |
| 135 | EVT_IDLE(wxWindow::OnIdle) |
| 136 | END_EVENT_TABLE() |
| 137 | |
| 138 | // ============================================================================ |
| 139 | // implementation |
| 140 | // ============================================================================ |
| 141 | |
| 142 | // ---------------------------------------------------------------------------- |
| 143 | // helper functions |
| 144 | // ---------------------------------------------------------------------------- |
| 145 | |
| 146 | void wxWindow::UnmanageAndDestroy(WXWidget widget) |
| 147 | { |
| 148 | Widget w = (Widget)widget; |
| 149 | if ( w ) |
| 150 | { |
| 151 | XtUnmanageChild(w); |
| 152 | XtDestroyWidget(w); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | bool wxWindow::MapOrUnmap(WXWidget widget, bool map) |
| 157 | { |
| 158 | Widget w = (Widget)widget; |
| 159 | if ( !w ) |
| 160 | return FALSE; |
| 161 | |
| 162 | if ( map ) |
| 163 | XtMapWidget(w); |
| 164 | else |
| 165 | XtUnmapWidget(w); |
| 166 | |
| 167 | return TRUE; |
| 168 | } |
| 169 | |
| 170 | // ---------------------------------------------------------------------------- |
| 171 | // constructors |
| 172 | // ---------------------------------------------------------------------------- |
| 173 | |
| 174 | void wxWindow::Init() |
| 175 | { |
| 176 | // generic initializations first |
| 177 | InitBase(); |
| 178 | |
| 179 | // Motif-specific |
| 180 | m_needsRefresh = TRUE; |
| 181 | m_mainWidget = (WXWidget) 0; |
| 182 | |
| 183 | m_button1Pressed = |
| 184 | m_button2Pressed = |
| 185 | m_button3Pressed = FALSE; |
| 186 | |
| 187 | m_winCaptured = FALSE; |
| 188 | |
| 189 | m_isShown = TRUE; |
| 190 | m_isBeingDeleted = FALSE; |
| 191 | |
| 192 | m_hScrollBar = |
| 193 | m_vScrollBar = |
| 194 | m_borderWidget = |
| 195 | m_scrolledWindow = |
| 196 | m_drawingArea = (WXWidget) 0; |
| 197 | |
| 198 | m_hScroll = |
| 199 | m_vScroll = FALSE; |
| 200 | |
| 201 | m_scrollPosX = |
| 202 | m_scrollPosY = 0; |
| 203 | |
| 204 | m_backingPixmap = (WXPixmap) 0; |
| 205 | m_pixmapWidth = |
| 206 | m_pixmapHeight = 0; |
| 207 | |
| 208 | m_pixmapOffsetX = |
| 209 | m_pixmapOffsetY = 0; |
| 210 | |
| 211 | m_lastTS = 0; |
| 212 | m_lastButton = 0; |
| 213 | m_canAddEventHandler = FALSE; |
| 214 | } |
| 215 | |
| 216 | // real construction (Init() must have been called before!) |
| 217 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, |
| 218 | const wxPoint& pos, |
| 219 | const wxSize& size, |
| 220 | long style, |
| 221 | const wxString& name) |
| 222 | { |
| 223 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); |
| 224 | |
| 225 | CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); |
| 226 | |
| 227 | parent->AddChild(this); |
| 228 | |
| 229 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
| 230 | m_foregroundColour = *wxBLACK; |
| 231 | |
| 232 | //// TODO: we should probably optimize by only creating a |
| 233 | //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL). |
| 234 | //// But for now, let's simplify things by always creating the |
| 235 | //// drawing area, since otherwise the translations are different. |
| 236 | |
| 237 | // New translations for getting mouse motion feedback |
| 238 | static const String translations = |
| 239 | "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ |
| 240 | <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ |
| 241 | <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ |
| 242 | <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ |
| 243 | <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\ |
| 244 | <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\ |
| 245 | <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\ |
| 246 | <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ |
| 247 | <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ |
| 248 | <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ |
| 249 | <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\ |
| 250 | <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ |
| 251 | <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ |
| 252 | <Key>: DrawingAreaInput()"; |
| 253 | |
| 254 | XtActionsRec actions[1]; |
| 255 | actions[0].string = "wxCanvasMotionEvent"; |
| 256 | actions[0].proc = (XtActionProc) wxCanvasMotionEvent; |
| 257 | XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1); |
| 258 | |
| 259 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
| 260 | |
| 261 | if (style & wxSIMPLE_BORDER) |
| 262 | { |
| 263 | m_borderWidget = (WXWidget)XtVaCreateManagedWidget |
| 264 | ( |
| 265 | "canvasBorder", |
| 266 | xmFrameWidgetClass, parentWidget, |
| 267 | XmNshadowType, XmSHADOW_IN, |
| 268 | XmNshadowThickness, 1, |
| 269 | NULL |
| 270 | ); |
| 271 | } else if (style & wxSUNKEN_BORDER) |
| 272 | { |
| 273 | m_borderWidget = (WXWidget)XtVaCreateManagedWidget |
| 274 | ( |
| 275 | "canvasBorder", |
| 276 | xmFrameWidgetClass, parentWidget, |
| 277 | XmNshadowType, XmSHADOW_IN, |
| 278 | NULL |
| 279 | ); |
| 280 | } else if (style & wxRAISED_BORDER) |
| 281 | { |
| 282 | m_borderWidget = (WXWidget)XtVaCreateManagedWidget |
| 283 | ( |
| 284 | "canvasBorder", |
| 285 | xmFrameWidgetClass, parentWidget, |
| 286 | XmNshadowType, XmSHADOW_OUT, |
| 287 | NULL |
| 288 | ); |
| 289 | } |
| 290 | |
| 291 | m_scrolledWindow = (WXWidget)XtVaCreateManagedWidget |
| 292 | ( |
| 293 | "scrolledWindow", |
| 294 | xmScrolledWindowWidgetClass, |
| 295 | m_borderWidget ? (Widget) m_borderWidget |
| 296 | : parentWidget, |
| 297 | XmNresizePolicy, XmRESIZE_NONE, |
| 298 | XmNspacing, 0, |
| 299 | XmNscrollingPolicy, XmAPPLICATION_DEFINED, |
| 300 | //XmNscrollBarDisplayPolicy, XmAS_NEEDED, |
| 301 | NULL |
| 302 | ); |
| 303 | |
| 304 | XtTranslations ptr = XtParseTranslationTable(translations); |
| 305 | m_drawingArea = (WXWidget)XtVaCreateWidget |
| 306 | ( |
| 307 | name, |
| 308 | xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow, |
| 309 | XmNunitType, XmPIXELS, |
| 310 | // XmNresizePolicy, XmRESIZE_ANY, |
| 311 | XmNresizePolicy, XmRESIZE_NONE, |
| 312 | XmNmarginHeight, 0, |
| 313 | XmNmarginWidth, 0, |
| 314 | XmNtranslations, ptr, |
| 315 | NULL |
| 316 | ); |
| 317 | XtFree((char *) ptr); |
| 318 | |
| 319 | #if 0 |
| 320 | if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS) |
| 321 | { |
| 322 | ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()"); |
| 323 | XtOverrideTranslations ((Widget) m_drawingArea, ptr); |
| 324 | XtFree ((char *) ptr); |
| 325 | } |
| 326 | #endif // 0 |
| 327 | |
| 328 | wxAddWindowToTable((Widget) m_drawingArea, this); |
| 329 | wxAddWindowToTable((Widget) m_scrolledWindow, this); |
| 330 | |
| 331 | // This order is very important in Motif 1.2.1 |
| 332 | XtRealizeWidget ((Widget) m_scrolledWindow); |
| 333 | XtRealizeWidget ((Widget) m_drawingArea); |
| 334 | XtManageChild ((Widget) m_drawingArea); |
| 335 | |
| 336 | ptr = XtParseTranslationTable("<Configure>: resize()"); |
| 337 | XtOverrideTranslations((Widget) m_drawingArea, ptr); |
| 338 | XtFree ((char *) ptr); |
| 339 | |
| 340 | XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this); |
| 341 | XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this); |
| 342 | |
| 343 | // TODO? |
| 344 | #if 0 |
| 345 | display = XtDisplay (scrolledWindow); |
| 346 | xwindow = XtWindow (drawingArea); |
| 347 | #endif // 0 |
| 348 | |
| 349 | XtAddEventHandler( |
| 350 | (Widget)m_drawingArea, |
| 351 | PointerMotionHintMask | EnterWindowMask | |
| 352 | LeaveWindowMask | FocusChangeMask, |
| 353 | False, |
| 354 | (XtEventHandler) wxCanvasEnterLeave, |
| 355 | (XtPointer) this |
| 356 | ); |
| 357 | |
| 358 | // Scrolled widget needs to have its colour changed or we get a little blue |
| 359 | // square where the scrollbars abutt |
| 360 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
| 361 | DoChangeBackgroundColour(m_scrolledWindow, backgroundColour, TRUE); |
| 362 | DoChangeBackgroundColour(m_drawingArea, backgroundColour, TRUE); |
| 363 | |
| 364 | XmScrolledWindowSetAreas( |
| 365 | (Widget)m_scrolledWindow, |
| 366 | (Widget) 0, (Widget) 0, |
| 367 | (Widget) m_drawingArea); |
| 368 | |
| 369 | #if 0 |
| 370 | if (m_hScrollBar) |
| 371 | XtRealizeWidget ((Widget) m_hScrollBar); |
| 372 | if (m_vScrollBar) |
| 373 | XtRealizeWidget ((Widget) m_vScrollBar); |
| 374 | #endif // 0 |
| 375 | |
| 376 | // Without this, the cursor may not be restored properly (e.g. in splitter |
| 377 | // sample). |
| 378 | SetCursor(*wxSTANDARD_CURSOR); |
| 379 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); |
| 380 | SetSize(pos.x, pos.y, size.x, size.y); |
| 381 | |
| 382 | return TRUE; |
| 383 | } |
| 384 | |
| 385 | // Destructor |
| 386 | wxWindow::~wxWindow() |
| 387 | { |
| 388 | if (g_captureWindow == this) |
| 389 | g_captureWindow = NULL; |
| 390 | |
| 391 | m_isBeingDeleted = TRUE; |
| 392 | |
| 393 | // Motif-specific actions first |
| 394 | WXWidget wMain = GetMainWidget(); |
| 395 | if ( wMain ) |
| 396 | { |
| 397 | // Removes event handlers |
| 398 | DetachWidget(wMain); |
| 399 | } |
| 400 | |
| 401 | ClearUpdateRects(); |
| 402 | |
| 403 | if ( m_parent ) |
| 404 | m_parent->RemoveChild( this ); |
| 405 | |
| 406 | // If m_drawingArea, we're a fully-fledged window with drawing area, |
| 407 | // scrollbars etc. (what wxCanvas used to be) |
| 408 | if ( m_drawingArea ) |
| 409 | { |
| 410 | // Destroy children before destroying self |
| 411 | DestroyChildren(); |
| 412 | |
| 413 | if (m_backingPixmap) |
| 414 | XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap); |
| 415 | |
| 416 | Widget w = (Widget) m_drawingArea; |
| 417 | wxDeleteWindowFromTable(w); |
| 418 | |
| 419 | if (w) |
| 420 | { |
| 421 | XtDestroyWidget(w); |
| 422 | m_drawingArea = (WXWidget) 0; |
| 423 | } |
| 424 | |
| 425 | // Only if we're _really_ a canvas (not a dialog box/panel) |
| 426 | if (m_scrolledWindow) |
| 427 | { |
| 428 | wxDeleteWindowFromTable((Widget) m_scrolledWindow); |
| 429 | } |
| 430 | |
| 431 | if (m_hScrollBar) |
| 432 | { |
| 433 | wxDeleteWindowFromTable((Widget) m_hScrollBar); |
| 434 | XtUnmanageChild((Widget) m_hScrollBar); |
| 435 | } |
| 436 | if (m_vScrollBar) |
| 437 | { |
| 438 | wxDeleteWindowFromTable((Widget) m_vScrollBar); |
| 439 | XtUnmanageChild((Widget) m_vScrollBar); |
| 440 | } |
| 441 | |
| 442 | if (m_hScrollBar) |
| 443 | XtDestroyWidget((Widget) m_hScrollBar); |
| 444 | if (m_vScrollBar) |
| 445 | XtDestroyWidget((Widget) m_vScrollBar); |
| 446 | |
| 447 | UnmanageAndDestroy(m_scrolledWindow); |
| 448 | |
| 449 | if (m_borderWidget) |
| 450 | { |
| 451 | XtDestroyWidget ((Widget) m_borderWidget); |
| 452 | m_borderWidget = (WXWidget) 0; |
| 453 | } |
| 454 | } |
| 455 | else // Why wasn't this here before? JACS 8/3/2000 |
| 456 | DestroyChildren(); |
| 457 | |
| 458 | |
| 459 | // Destroy the window |
| 460 | if (GetMainWidget()) |
| 461 | { |
| 462 | // If this line (XtDestroyWidget) causes a crash, you may comment it out. |
| 463 | // Child widgets will get destroyed automatically when a frame |
| 464 | // or dialog is destroyed, but before that you may get some memory |
| 465 | // leaks and potential layout problems if you delete and then add |
| 466 | // child windows. |
| 467 | |
| 468 | // GRG, Feb/2000: commented this out when adding support for |
| 469 | // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported |
| 470 | // that this call crashed wxMotif under OS/2, so it seems |
| 471 | // that leaving it out is the right thing to do. |
| 472 | // SN, Feb/2000: newgrid/griddemo shows why it is needed :-( |
| 473 | XtDestroyWidget((Widget) GetMainWidget()); |
| 474 | SetMainWidget((WXWidget) NULL); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | // ---------------------------------------------------------------------------- |
| 479 | // scrollbar management |
| 480 | // ---------------------------------------------------------------------------- |
| 481 | |
| 482 | // Helper function |
| 483 | void wxWindow::CreateScrollbar(wxOrientation orientation) |
| 484 | { |
| 485 | wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" ); |
| 486 | |
| 487 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); |
| 488 | |
| 489 | // Add scrollbars if required |
| 490 | if (orientation == wxHORIZONTAL) |
| 491 | { |
| 492 | Widget hScrollBar = XtVaCreateManagedWidget ("hsb", |
| 493 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, |
| 494 | XmNorientation, XmHORIZONTAL, |
| 495 | NULL); |
| 496 | XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 497 | XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 498 | XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 499 | XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 500 | XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 501 | XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 502 | XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 503 | XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); |
| 504 | |
| 505 | XtVaSetValues (hScrollBar, |
| 506 | XmNincrement, 1, |
| 507 | XmNvalue, 0, |
| 508 | NULL); |
| 509 | |
| 510 | m_hScrollBar = (WXWidget) hScrollBar; |
| 511 | |
| 512 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
| 513 | DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE); |
| 514 | |
| 515 | XtRealizeWidget(hScrollBar); |
| 516 | |
| 517 | XtVaSetValues((Widget) m_scrolledWindow, |
| 518 | XmNhorizontalScrollBar, (Widget) m_hScrollBar, |
| 519 | NULL); |
| 520 | |
| 521 | m_hScroll = TRUE; |
| 522 | |
| 523 | wxAddWindowToTable( hScrollBar, this ); |
| 524 | } |
| 525 | |
| 526 | if (orientation == wxVERTICAL) |
| 527 | { |
| 528 | Widget vScrollBar = XtVaCreateManagedWidget ("vsb", |
| 529 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, |
| 530 | XmNorientation, XmVERTICAL, |
| 531 | NULL); |
| 532 | XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 533 | XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 534 | XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 535 | XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 536 | XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 537 | XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 538 | XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 539 | XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); |
| 540 | |
| 541 | XtVaSetValues (vScrollBar, |
| 542 | XmNincrement, 1, |
| 543 | XmNvalue, 0, |
| 544 | NULL); |
| 545 | |
| 546 | m_vScrollBar = (WXWidget) vScrollBar; |
| 547 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
| 548 | DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE); |
| 549 | |
| 550 | XtRealizeWidget(vScrollBar); |
| 551 | |
| 552 | XtVaSetValues((Widget) m_scrolledWindow, |
| 553 | XmNverticalScrollBar, (Widget) m_vScrollBar, |
| 554 | NULL); |
| 555 | |
| 556 | m_vScroll = TRUE; |
| 557 | |
| 558 | wxAddWindowToTable( vScrollBar, this ); |
| 559 | } |
| 560 | |
| 561 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); |
| 562 | } |
| 563 | |
| 564 | void wxWindow::DestroyScrollbar(wxOrientation orientation) |
| 565 | { |
| 566 | wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" ); |
| 567 | |
| 568 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); |
| 569 | // Add scrollbars if required |
| 570 | if (orientation == wxHORIZONTAL) |
| 571 | { |
| 572 | if (m_hScrollBar) |
| 573 | { |
| 574 | wxDeleteWindowFromTable((Widget)m_hScrollBar); |
| 575 | XtDestroyWidget((Widget) m_hScrollBar); |
| 576 | } |
| 577 | m_hScrollBar = (WXWidget) 0; |
| 578 | m_hScroll = FALSE; |
| 579 | |
| 580 | XtVaSetValues((Widget) m_scrolledWindow, |
| 581 | XmNhorizontalScrollBar, (Widget) 0, |
| 582 | NULL); |
| 583 | |
| 584 | } |
| 585 | |
| 586 | if (orientation == wxVERTICAL) |
| 587 | { |
| 588 | if (m_vScrollBar) |
| 589 | { |
| 590 | wxDeleteWindowFromTable((Widget)m_vScrollBar); |
| 591 | XtDestroyWidget((Widget) m_vScrollBar); |
| 592 | } |
| 593 | m_vScrollBar = (WXWidget) 0; |
| 594 | m_vScroll = FALSE; |
| 595 | |
| 596 | XtVaSetValues((Widget) m_scrolledWindow, |
| 597 | XmNverticalScrollBar, (Widget) 0, |
| 598 | NULL); |
| 599 | |
| 600 | } |
| 601 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); |
| 602 | } |
| 603 | |
| 604 | // --------------------------------------------------------------------------- |
| 605 | // basic operations |
| 606 | // --------------------------------------------------------------------------- |
| 607 | |
| 608 | void wxWindow::SetFocus() |
| 609 | { |
| 610 | Widget wMain = (Widget) GetMainWidget(); |
| 611 | XmProcessTraversal(wMain, XmTRAVERSE_CURRENT); |
| 612 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); |
| 613 | } |
| 614 | |
| 615 | // Get the window with the focus |
| 616 | wxWindow *wxWindowBase::FindFocus() |
| 617 | { |
| 618 | // TODO Problems: |
| 619 | // (1) Can there be multiple focussed widgets in an application? |
| 620 | // In which case we need to find the top-level window that's |
| 621 | // currently active. |
| 622 | // (2) The widget with the focus may not be in the widget table |
| 623 | // depending on which widgets I put in the table |
| 624 | wxWindow *winFocus = (wxWindow *)NULL; |
| 625 | for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); |
| 626 | node; |
| 627 | node = node->GetNext() ) |
| 628 | { |
| 629 | wxWindow *win = node->GetData(); |
| 630 | |
| 631 | Widget w = XmGetFocusWidget ((Widget) win->GetTopWidget()); |
| 632 | |
| 633 | if (w != (Widget) NULL) |
| 634 | { |
| 635 | winFocus = wxGetWindowFromTable(w); |
| 636 | if ( winFocus ) |
| 637 | break; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return winFocus; |
| 642 | } |
| 643 | |
| 644 | bool wxWindow::Enable(bool enable) |
| 645 | { |
| 646 | if ( !wxWindowBase::Enable(enable) ) |
| 647 | return FALSE; |
| 648 | |
| 649 | Widget wMain = (Widget)GetMainWidget(); |
| 650 | if ( wMain ) |
| 651 | { |
| 652 | XtSetSensitive(wMain, enable); |
| 653 | XmUpdateDisplay(wMain); |
| 654 | } |
| 655 | |
| 656 | return TRUE; |
| 657 | } |
| 658 | |
| 659 | bool wxWindow::Show(bool show) |
| 660 | { |
| 661 | if ( !wxWindowBase::Show(show) ) |
| 662 | return FALSE; |
| 663 | |
| 664 | if (m_borderWidget || m_scrolledWindow) |
| 665 | { |
| 666 | MapOrUnmap(m_drawingArea, show); |
| 667 | MapOrUnmap(m_borderWidget ? m_borderWidget : m_scrolledWindow, show); |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | if ( !MapOrUnmap(GetTopWidget(), show) ) |
| 672 | MapOrUnmap(GetMainWidget(), show); |
| 673 | } |
| 674 | |
| 675 | #if 0 |
| 676 | Window xwin = (Window) GetXWindow(); |
| 677 | Display *xdisp = (Display*) GetXDisplay(); |
| 678 | if (show) |
| 679 | XMapWindow(xdisp, xwin); |
| 680 | else |
| 681 | XUnmapWindow(xdisp, xwin); |
| 682 | #endif |
| 683 | |
| 684 | return TRUE; |
| 685 | } |
| 686 | |
| 687 | // Raise the window to the top of the Z order |
| 688 | void wxWindow::Raise() |
| 689 | { |
| 690 | Widget wTop = (Widget) GetTopWidget(); |
| 691 | Window window = XtWindow(wTop); |
| 692 | XRaiseWindow(XtDisplay(wTop), window); |
| 693 | } |
| 694 | |
| 695 | // Lower the window to the bottom of the Z order |
| 696 | void wxWindow::Lower() |
| 697 | { |
| 698 | Widget wTop = (Widget) GetTopWidget(); |
| 699 | Window window = XtWindow(wTop); |
| 700 | XLowerWindow(XtDisplay(wTop), window); |
| 701 | } |
| 702 | |
| 703 | void wxWindow::SetTitle(const wxString& title) |
| 704 | { |
| 705 | XtVaSetValues((Widget)GetMainWidget(), XmNtitle, title.c_str(), NULL); |
| 706 | } |
| 707 | |
| 708 | wxString wxWindow::GetTitle() const |
| 709 | { |
| 710 | char *title; |
| 711 | XtVaGetValues((Widget)GetMainWidget(), XmNtitle, &title, NULL); |
| 712 | |
| 713 | return wxString(title); |
| 714 | } |
| 715 | |
| 716 | void wxWindow::CaptureMouse() |
| 717 | { |
| 718 | g_captureWindow = this; |
| 719 | if ( m_winCaptured ) |
| 720 | return; |
| 721 | |
| 722 | Widget wMain = (Widget)GetMainWidget(); |
| 723 | if ( wMain ) |
| 724 | XtAddGrab(wMain, TRUE, FALSE); |
| 725 | |
| 726 | m_winCaptured = TRUE; |
| 727 | } |
| 728 | |
| 729 | void wxWindow::ReleaseMouse() |
| 730 | { |
| 731 | g_captureWindow = NULL; |
| 732 | if ( !m_winCaptured ) |
| 733 | return; |
| 734 | |
| 735 | Widget wMain = (Widget)GetMainWidget(); |
| 736 | if ( wMain ) |
| 737 | XtRemoveGrab(wMain); |
| 738 | |
| 739 | m_winCaptured = FALSE; |
| 740 | } |
| 741 | |
| 742 | bool wxWindow::SetFont(const wxFont& font) |
| 743 | { |
| 744 | if ( !wxWindowBase::SetFont(font) ) |
| 745 | { |
| 746 | // nothing to do |
| 747 | return FALSE; |
| 748 | } |
| 749 | |
| 750 | ChangeFont(); |
| 751 | |
| 752 | return TRUE; |
| 753 | } |
| 754 | |
| 755 | bool wxWindow::SetCursor(const wxCursor& cursor) |
| 756 | { |
| 757 | if ( !wxWindowBase::SetCursor(cursor) ) |
| 758 | { |
| 759 | // no change |
| 760 | return FALSE; |
| 761 | } |
| 762 | |
| 763 | // wxASSERT_MSG( m_cursor.Ok(), |
| 764 | // wxT("cursor must be valid after call to the base version")); |
| 765 | wxCursor* cursor2 = NULL; |
| 766 | if (m_cursor.Ok()) |
| 767 | cursor2 = & m_cursor; |
| 768 | else |
| 769 | cursor2 = wxSTANDARD_CURSOR; |
| 770 | |
| 771 | WXDisplay *dpy = GetXDisplay(); |
| 772 | WXCursor x_cursor = cursor2->GetXCursor(dpy); |
| 773 | |
| 774 | Widget w = (Widget) GetMainWidget(); |
| 775 | Window win = XtWindow(w); |
| 776 | XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); |
| 777 | |
| 778 | return TRUE; |
| 779 | } |
| 780 | |
| 781 | // Coordinates relative to the window |
| 782 | void wxWindow::WarpPointer (int x, int y) |
| 783 | { |
| 784 | Widget wClient = (Widget)GetClientWidget(); |
| 785 | |
| 786 | XWarpPointer(XtDisplay(wClient), None, XtWindow(wClient), 0, 0, 0, 0, x, y); |
| 787 | } |
| 788 | |
| 789 | // --------------------------------------------------------------------------- |
| 790 | // scrolling stuff |
| 791 | // --------------------------------------------------------------------------- |
| 792 | |
| 793 | int wxWindow::GetScrollPos(int orient) const |
| 794 | { |
| 795 | if (orient == wxHORIZONTAL) |
| 796 | return m_scrollPosX; |
| 797 | else |
| 798 | return m_scrollPosY; |
| 799 | |
| 800 | #if 0 |
| 801 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
| 802 | if (scrollBar) |
| 803 | { |
| 804 | int pos; |
| 805 | XtVaGetValues(scrollBar, XmNvalue, &pos, NULL); |
| 806 | return pos; |
| 807 | } |
| 808 | else |
| 809 | return 0; |
| 810 | #endif // 0 |
| 811 | } |
| 812 | |
| 813 | // This now returns the whole range, not just the number of positions that we |
| 814 | // can scroll. |
| 815 | int wxWindow::GetScrollRange(int orient) const |
| 816 | { |
| 817 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
| 818 | wxCHECK_MSG( scrollBar, 0, "no such scrollbar" ); |
| 819 | |
| 820 | int range; |
| 821 | XtVaGetValues(scrollBar, XmNmaximum, &range, NULL); |
| 822 | return range; |
| 823 | } |
| 824 | |
| 825 | int wxWindow::GetScrollThumb(int orient) const |
| 826 | { |
| 827 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
| 828 | wxCHECK_MSG( scrollBar, 0, "no such scrollbar" ); |
| 829 | |
| 830 | int thumb; |
| 831 | XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL); |
| 832 | return thumb; |
| 833 | } |
| 834 | |
| 835 | void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
| 836 | { |
| 837 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
| 838 | |
| 839 | if ( scrollBar ) |
| 840 | { |
| 841 | XtVaSetValues (scrollBar, XmNvalue, pos, NULL); |
| 842 | } |
| 843 | |
| 844 | SetInternalScrollPos((wxOrientation)orient, pos); |
| 845 | } |
| 846 | |
| 847 | // New function that will replace some of the above. |
| 848 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, |
| 849 | int range, bool WXUNUSED(refresh)) |
| 850 | { |
| 851 | int oldW, oldH; |
| 852 | GetSize(& oldW, & oldH); |
| 853 | |
| 854 | if (range == 0) |
| 855 | range = 1; |
| 856 | if (thumbVisible == 0) |
| 857 | thumbVisible = 1; |
| 858 | |
| 859 | if (thumbVisible > range) |
| 860 | thumbVisible = range; |
| 861 | |
| 862 | // Save the old state to see if it changed |
| 863 | WXWidget oldScrollBar = GetScrollbar((wxOrientation)orient); |
| 864 | |
| 865 | if (orient == wxHORIZONTAL) |
| 866 | { |
| 867 | if (thumbVisible == range) |
| 868 | { |
| 869 | if (m_hScrollBar) |
| 870 | DestroyScrollbar(wxHORIZONTAL); |
| 871 | } |
| 872 | else |
| 873 | { |
| 874 | if (!m_hScrollBar) |
| 875 | CreateScrollbar(wxHORIZONTAL); |
| 876 | } |
| 877 | } |
| 878 | if (orient == wxVERTICAL) |
| 879 | { |
| 880 | if (thumbVisible == range) |
| 881 | { |
| 882 | if (m_vScrollBar) |
| 883 | DestroyScrollbar(wxVERTICAL); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | if (!m_vScrollBar) |
| 888 | CreateScrollbar(wxVERTICAL); |
| 889 | } |
| 890 | } |
| 891 | WXWidget newScrollBar = GetScrollbar((wxOrientation)orient); |
| 892 | |
| 893 | if (oldScrollBar != newScrollBar) |
| 894 | { |
| 895 | // This is important! Without it, scrollbars misbehave badly. |
| 896 | XtUnrealizeWidget((Widget) m_scrolledWindow); |
| 897 | XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea); |
| 898 | XtRealizeWidget((Widget) m_scrolledWindow); |
| 899 | XtManageChild((Widget) m_scrolledWindow); |
| 900 | } |
| 901 | |
| 902 | if (newScrollBar) |
| 903 | { |
| 904 | XtVaSetValues((Widget) newScrollBar, |
| 905 | XmNvalue, pos, |
| 906 | XmNminimum, 0, |
| 907 | XmNmaximum, range, |
| 908 | XmNsliderSize, thumbVisible, |
| 909 | NULL); |
| 910 | } |
| 911 | |
| 912 | SetInternalScrollPos((wxOrientation)orient, pos); |
| 913 | |
| 914 | int newW, newH; |
| 915 | GetSize(& newW, & newH); |
| 916 | |
| 917 | // Adjusting scrollbars can resize the canvas accidentally |
| 918 | if (newW != oldW || newH != oldH) |
| 919 | SetSize(-1, -1, oldW, oldH); |
| 920 | } |
| 921 | |
| 922 | // Does a physical scroll |
| 923 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
| 924 | { |
| 925 | int x, y, w, h; |
| 926 | if (rect) |
| 927 | { |
| 928 | // Use specified rectangle |
| 929 | x = rect->x; y = rect->y; w = rect->width; h = rect->height; |
| 930 | } |
| 931 | else |
| 932 | { |
| 933 | // Use whole client area |
| 934 | x = 0; y = 0; |
| 935 | GetClientSize(& w, & h); |
| 936 | } |
| 937 | |
| 938 | wxNode *cnode = m_children.First(); |
| 939 | while (cnode) |
| 940 | { |
| 941 | wxWindow *child = (wxWindow*) cnode->Data(); |
| 942 | int sx = 0; |
| 943 | int sy = 0; |
| 944 | child->GetSize( &sx, &sy ); |
| 945 | wxPoint pos( child->GetPosition() ); |
| 946 | child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); |
| 947 | cnode = cnode->Next(); |
| 948 | } |
| 949 | |
| 950 | int x1 = (dx >= 0) ? x : x - dx; |
| 951 | int y1 = (dy >= 0) ? y : y - dy; |
| 952 | int w1 = w - abs(dx); |
| 953 | int h1 = h - abs(dy); |
| 954 | int x2 = (dx >= 0) ? x + dx : x; |
| 955 | int y2 = (dy >= 0) ? y + dy : y; |
| 956 | |
| 957 | wxClientDC dc(this); |
| 958 | |
| 959 | dc.SetLogicalFunction (wxCOPY); |
| 960 | |
| 961 | Widget widget = (Widget) GetMainWidget(); |
| 962 | Window window = XtWindow(widget); |
| 963 | Display* display = XtDisplay(widget); |
| 964 | |
| 965 | XCopyArea(display, window, window, (GC) dc.GetGC(), |
| 966 | x1, y1, w1, h1, x2, y2); |
| 967 | |
| 968 | dc.SetAutoSetting(TRUE); |
| 969 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
| 970 | dc.SetBrush(brush); // FIXME: needed? |
| 971 | |
| 972 | // We'll add rectangles to the list of update rectangles according to which |
| 973 | // bits we've exposed. |
| 974 | wxList updateRects; |
| 975 | |
| 976 | if (dx > 0) |
| 977 | { |
| 978 | wxRect *rect = new wxRect; |
| 979 | rect->x = x; |
| 980 | rect->y = y; |
| 981 | rect->width = dx; |
| 982 | rect->height = h; |
| 983 | |
| 984 | XFillRectangle(display, window, |
| 985 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); |
| 986 | |
| 987 | rect->x = rect->x; |
| 988 | rect->y = rect->y; |
| 989 | rect->width = rect->width; |
| 990 | rect->height = rect->height; |
| 991 | |
| 992 | updateRects.Append((wxObject*) rect); |
| 993 | } |
| 994 | else if (dx < 0) |
| 995 | { |
| 996 | wxRect *rect = new wxRect; |
| 997 | |
| 998 | rect->x = x + w + dx; |
| 999 | rect->y = y; |
| 1000 | rect->width = -dx; |
| 1001 | rect->height = h; |
| 1002 | |
| 1003 | XFillRectangle(display, window, |
| 1004 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, |
| 1005 | rect->height); |
| 1006 | |
| 1007 | rect->x = rect->x; |
| 1008 | rect->y = rect->y; |
| 1009 | rect->width = rect->width; |
| 1010 | rect->height = rect->height; |
| 1011 | |
| 1012 | updateRects.Append((wxObject*) rect); |
| 1013 | } |
| 1014 | if (dy > 0) |
| 1015 | { |
| 1016 | wxRect *rect = new wxRect; |
| 1017 | |
| 1018 | rect->x = x; |
| 1019 | rect->y = y; |
| 1020 | rect->width = w; |
| 1021 | rect->height = dy; |
| 1022 | |
| 1023 | XFillRectangle(display, window, |
| 1024 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); |
| 1025 | |
| 1026 | rect->x = rect->x; |
| 1027 | rect->y = rect->y; |
| 1028 | rect->width = rect->width; |
| 1029 | rect->height = rect->height; |
| 1030 | |
| 1031 | updateRects.Append((wxObject*) rect); |
| 1032 | } |
| 1033 | else if (dy < 0) |
| 1034 | { |
| 1035 | wxRect *rect = new wxRect; |
| 1036 | |
| 1037 | rect->x = x; |
| 1038 | rect->y = y + h + dy; |
| 1039 | rect->width = w; |
| 1040 | rect->height = -dy; |
| 1041 | |
| 1042 | XFillRectangle(display, window, |
| 1043 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); |
| 1044 | |
| 1045 | rect->x = rect->x; |
| 1046 | rect->y = rect->y; |
| 1047 | rect->width = rect->width; |
| 1048 | rect->height = rect->height; |
| 1049 | |
| 1050 | updateRects.Append((wxObject*) rect); |
| 1051 | } |
| 1052 | dc.SetBrush(wxNullBrush); |
| 1053 | |
| 1054 | // Now send expose events |
| 1055 | |
| 1056 | wxNode* node = updateRects.First(); |
| 1057 | while (node) |
| 1058 | { |
| 1059 | wxRect* rect = (wxRect*) node->Data(); |
| 1060 | XExposeEvent event; |
| 1061 | |
| 1062 | event.type = Expose; |
| 1063 | event.display = display; |
| 1064 | event.send_event = True; |
| 1065 | event.window = window; |
| 1066 | |
| 1067 | event.x = rect->x; |
| 1068 | event.y = rect->y; |
| 1069 | event.width = rect->width; |
| 1070 | event.height = rect->height; |
| 1071 | |
| 1072 | event.count = 0; |
| 1073 | |
| 1074 | XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); |
| 1075 | |
| 1076 | node = node->Next(); |
| 1077 | |
| 1078 | } |
| 1079 | |
| 1080 | // Delete the update rects |
| 1081 | node = updateRects.First(); |
| 1082 | while (node) |
| 1083 | { |
| 1084 | wxRect* rect = (wxRect*) node->Data(); |
| 1085 | delete rect; |
| 1086 | node = node->Next(); |
| 1087 | } |
| 1088 | |
| 1089 | XmUpdateDisplay((Widget) GetMainWidget()); |
| 1090 | } |
| 1091 | |
| 1092 | // --------------------------------------------------------------------------- |
| 1093 | // drag and drop |
| 1094 | // --------------------------------------------------------------------------- |
| 1095 | |
| 1096 | #if wxUSE_DRAG_AND_DROP |
| 1097 | |
| 1098 | void wxWindow::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) |
| 1099 | { |
| 1100 | // TODO |
| 1101 | } |
| 1102 | |
| 1103 | #endif |
| 1104 | |
| 1105 | // Old style file-manager drag&drop |
| 1106 | void wxWindow::DragAcceptFiles(bool WXUNUSED(accept)) |
| 1107 | { |
| 1108 | // TODO |
| 1109 | } |
| 1110 | |
| 1111 | // ---------------------------------------------------------------------------- |
| 1112 | // tooltips |
| 1113 | // ---------------------------------------------------------------------------- |
| 1114 | |
| 1115 | #if wxUSE_TOOLTIPS |
| 1116 | |
| 1117 | void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) |
| 1118 | { |
| 1119 | // TODO |
| 1120 | } |
| 1121 | |
| 1122 | #endif // wxUSE_TOOLTIPS |
| 1123 | |
| 1124 | // ---------------------------------------------------------------------------- |
| 1125 | // popup menus |
| 1126 | // ---------------------------------------------------------------------------- |
| 1127 | |
| 1128 | bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) |
| 1129 | { |
| 1130 | Widget widget = (Widget) GetMainWidget(); |
| 1131 | |
| 1132 | /* The menuId field seems to be usused, so we'll use it to |
| 1133 | indicate whether a menu is popped up or not: |
| 1134 | 0: Not currently created as a popup |
| 1135 | -1: Created as a popup, but not active |
| 1136 | 1: Active popup. |
| 1137 | */ |
| 1138 | |
| 1139 | if (menu->GetParent() && (menu->GetId() != -1)) |
| 1140 | return FALSE; |
| 1141 | |
| 1142 | if (menu->GetMainWidget()) { |
| 1143 | menu->DestroyMenu(TRUE); |
| 1144 | } |
| 1145 | |
| 1146 | menu->SetId(1); /* Mark as popped-up */ |
| 1147 | menu->CreateMenu(NULL, widget, menu); |
| 1148 | menu->SetInvokingWindow(this); |
| 1149 | |
| 1150 | menu->UpdateUI(); |
| 1151 | |
| 1152 | // menu->SetParent(parent); |
| 1153 | // parent->children->Append(menu); // Store menu for later deletion |
| 1154 | |
| 1155 | Widget menuWidget = (Widget) menu->GetMainWidget(); |
| 1156 | |
| 1157 | int rootX = 0; |
| 1158 | int rootY = 0; |
| 1159 | |
| 1160 | int deviceX = x; |
| 1161 | int deviceY = y; |
| 1162 | /* |
| 1163 | if (this->IsKindOf(CLASSINFO(wxCanvas))) |
| 1164 | { |
| 1165 | wxCanvas *canvas = (wxCanvas *) this; |
| 1166 | deviceX = canvas->GetDC ()->LogicalToDeviceX (x); |
| 1167 | deviceY = canvas->GetDC ()->LogicalToDeviceY (y); |
| 1168 | } |
| 1169 | */ |
| 1170 | |
| 1171 | Display *display = XtDisplay (widget); |
| 1172 | Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget)); |
| 1173 | Window thisWindow = XtWindow (widget); |
| 1174 | Window childWindow; |
| 1175 | XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY, |
| 1176 | &rootX, &rootY, &childWindow); |
| 1177 | |
| 1178 | XButtonPressedEvent event; |
| 1179 | event.type = ButtonPress; |
| 1180 | event.button = 1; |
| 1181 | |
| 1182 | event.x = deviceX; |
| 1183 | event.y = deviceY; |
| 1184 | |
| 1185 | event.x_root = rootX; |
| 1186 | event.y_root = rootY; |
| 1187 | |
| 1188 | XmMenuPosition (menuWidget, &event); |
| 1189 | XtManageChild (menuWidget); |
| 1190 | |
| 1191 | return TRUE; |
| 1192 | } |
| 1193 | |
| 1194 | // --------------------------------------------------------------------------- |
| 1195 | // moving and resizing |
| 1196 | // --------------------------------------------------------------------------- |
| 1197 | |
| 1198 | bool wxWindow::PreResize() |
| 1199 | { |
| 1200 | return TRUE; |
| 1201 | } |
| 1202 | |
| 1203 | // Get total size |
| 1204 | void wxWindow::DoGetSize(int *x, int *y) const |
| 1205 | { |
| 1206 | if (m_drawingArea) |
| 1207 | { |
| 1208 | CanvasGetSize(x, y); |
| 1209 | return; |
| 1210 | } |
| 1211 | |
| 1212 | Widget widget = (Widget) GetTopWidget(); |
| 1213 | Dimension xx, yy; |
| 1214 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 1215 | if(x) *x = xx; if(y) *y = yy; |
| 1216 | } |
| 1217 | |
| 1218 | void wxWindow::DoGetPosition(int *x, int *y) const |
| 1219 | { |
| 1220 | if (m_drawingArea) |
| 1221 | { |
| 1222 | CanvasGetPosition(x, y); |
| 1223 | return; |
| 1224 | } |
| 1225 | Widget widget = (Widget) GetTopWidget(); |
| 1226 | Position xx, yy; |
| 1227 | XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL); |
| 1228 | |
| 1229 | // We may be faking the client origin. So a window that's really at (0, 30) |
| 1230 | // may appear (to wxWin apps) to be at (0, 0). |
| 1231 | if (GetParent()) |
| 1232 | { |
| 1233 | wxPoint pt(GetParent()->GetClientAreaOrigin()); |
| 1234 | xx -= pt.x; |
| 1235 | yy -= pt.y; |
| 1236 | } |
| 1237 | |
| 1238 | if(x) *x = xx; if(y) *y = yy; |
| 1239 | } |
| 1240 | |
| 1241 | void wxWindow::DoScreenToClient(int *x, int *y) const |
| 1242 | { |
| 1243 | Widget widget = (Widget) GetClientWidget(); |
| 1244 | Display *display = XtDisplay((Widget) GetMainWidget()); |
| 1245 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); |
| 1246 | Window thisWindow = XtWindow(widget); |
| 1247 | |
| 1248 | Window childWindow; |
| 1249 | int xx = *x; |
| 1250 | int yy = *y; |
| 1251 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); |
| 1252 | } |
| 1253 | |
| 1254 | void wxWindow::DoClientToScreen(int *x, int *y) const |
| 1255 | { |
| 1256 | Widget widget = (Widget) GetClientWidget(); |
| 1257 | Display *display = XtDisplay(widget); |
| 1258 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); |
| 1259 | Window thisWindow = XtWindow(widget); |
| 1260 | |
| 1261 | Window childWindow; |
| 1262 | int xx = *x; |
| 1263 | int yy = *y; |
| 1264 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | // Get size *available for subwindows* i.e. excluding menu bar etc. |
| 1269 | void wxWindow::DoGetClientSize(int *x, int *y) const |
| 1270 | { |
| 1271 | Widget widget = (Widget) GetClientWidget(); |
| 1272 | Dimension xx, yy; |
| 1273 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 1274 | if(x) *x = xx; if(y) *y = yy; |
| 1275 | } |
| 1276 | |
| 1277 | void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
| 1278 | { |
| 1279 | // A bit of optimization to help sort out the flickers. |
| 1280 | int oldX, oldY, oldW, oldH; |
| 1281 | GetSize(& oldW, & oldH); |
| 1282 | GetPosition(& oldX, & oldY); |
| 1283 | |
| 1284 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) |
| 1285 | { |
| 1286 | if ( x == -1 ) |
| 1287 | x = oldX; |
| 1288 | if ( y == -1 ) |
| 1289 | y = oldY; |
| 1290 | } |
| 1291 | |
| 1292 | if ( width == -1 ) |
| 1293 | width = oldW; |
| 1294 | if ( height == -1 ) |
| 1295 | height = oldH; |
| 1296 | |
| 1297 | bool nothingChanged = (x == oldX) && (y == oldY) && |
| 1298 | (width == oldW) && (height == oldH); |
| 1299 | |
| 1300 | if (!wxNoOptimize::CanOptimize()) |
| 1301 | { |
| 1302 | nothingChanged = FALSE; |
| 1303 | } |
| 1304 | |
| 1305 | if ( !nothingChanged ) |
| 1306 | { |
| 1307 | if (m_drawingArea) |
| 1308 | { |
| 1309 | CanvasSetSize(x, y, width, height, sizeFlags); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | Widget widget = (Widget) GetTopWidget(); |
| 1314 | if (!widget) |
| 1315 | return; |
| 1316 | |
| 1317 | bool managed = XtIsManaged( widget ); |
| 1318 | if (managed) |
| 1319 | XtUnmanageChild(widget); |
| 1320 | |
| 1321 | int xx = x; |
| 1322 | int yy = y; |
| 1323 | AdjustForParentClientOrigin(xx, yy, sizeFlags); |
| 1324 | |
| 1325 | DoMoveWindow(xx, yy, width, height); |
| 1326 | |
| 1327 | if (managed) |
| 1328 | XtManageChild(widget); |
| 1329 | |
| 1330 | // How about this bit. Maybe we don't need to generate size events |
| 1331 | // all the time -- they'll be generated when the window is sized anyway. |
| 1332 | #if 0 |
| 1333 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); |
| 1334 | sizeEvent.SetEventObject(this); |
| 1335 | |
| 1336 | GetEventHandler()->ProcessEvent(sizeEvent); |
| 1337 | #endif // 0 |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | void wxWindow::DoSetClientSize(int width, int height) |
| 1342 | { |
| 1343 | if (m_drawingArea) |
| 1344 | { |
| 1345 | CanvasSetClientSize(width, height); |
| 1346 | return; |
| 1347 | } |
| 1348 | |
| 1349 | Widget widget = (Widget) GetTopWidget(); |
| 1350 | |
| 1351 | if (width > -1) |
| 1352 | XtVaSetValues(widget, XmNwidth, width, NULL); |
| 1353 | if (height > -1) |
| 1354 | XtVaSetValues(widget, XmNheight, height, NULL); |
| 1355 | |
| 1356 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); |
| 1357 | sizeEvent.SetEventObject(this); |
| 1358 | |
| 1359 | GetEventHandler()->ProcessEvent(sizeEvent); |
| 1360 | } |
| 1361 | |
| 1362 | // For implementation purposes - sometimes decorations make the client area |
| 1363 | // smaller |
| 1364 | wxPoint wxWindow::GetClientAreaOrigin() const |
| 1365 | { |
| 1366 | return wxPoint(0, 0); |
| 1367 | } |
| 1368 | |
| 1369 | // Makes an adjustment to the window position (for example, a frame that has |
| 1370 | // a toolbar that it manages itself). |
| 1371 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) |
| 1372 | { |
| 1373 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
| 1374 | { |
| 1375 | wxPoint pt(GetParent()->GetClientAreaOrigin()); |
| 1376 | x += pt.x; y += pt.y; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) |
| 1381 | { |
| 1382 | m_minWidth = minW; |
| 1383 | m_minHeight = minH; |
| 1384 | m_maxWidth = maxW; |
| 1385 | m_maxHeight = maxH; |
| 1386 | |
| 1387 | wxFrame *frame = wxDynamicCast(this, wxFrame); |
| 1388 | if ( !frame ) |
| 1389 | { |
| 1390 | // TODO what about dialogs? |
| 1391 | return; |
| 1392 | } |
| 1393 | |
| 1394 | Widget widget = (Widget) frame->GetShellWidget(); |
| 1395 | |
| 1396 | if (minW > -1) |
| 1397 | XtVaSetValues(widget, XmNminWidth, minW, NULL); |
| 1398 | if (minH > -1) |
| 1399 | XtVaSetValues(widget, XmNminHeight, minH, NULL); |
| 1400 | if (maxW > -1) |
| 1401 | XtVaSetValues(widget, XmNmaxWidth, maxW, NULL); |
| 1402 | if (maxH > -1) |
| 1403 | XtVaSetValues(widget, XmNmaxHeight, maxH, NULL); |
| 1404 | if (incW > -1) |
| 1405 | XtVaSetValues(widget, XmNwidthInc, incW, NULL); |
| 1406 | if (incH > -1) |
| 1407 | XtVaSetValues(widget, XmNheightInc, incH, NULL); |
| 1408 | } |
| 1409 | |
| 1410 | void wxWindow::DoMoveWindow(int x, int y, int width, int height) |
| 1411 | { |
| 1412 | XtVaSetValues((Widget)GetTopWidget(), |
| 1413 | XmNx, x, |
| 1414 | XmNy, y, |
| 1415 | XmNwidth, width, |
| 1416 | XmNheight, height, |
| 1417 | NULL); |
| 1418 | } |
| 1419 | |
| 1420 | // --------------------------------------------------------------------------- |
| 1421 | // text metrics |
| 1422 | // --------------------------------------------------------------------------- |
| 1423 | |
| 1424 | int wxWindow::GetCharHeight() const |
| 1425 | { |
| 1426 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); |
| 1427 | |
| 1428 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); |
| 1429 | |
| 1430 | int direction, ascent, descent; |
| 1431 | XCharStruct overall; |
| 1432 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, |
| 1433 | &descent, &overall); |
| 1434 | |
| 1435 | // return (overall.ascent + overall.descent); |
| 1436 | return (ascent + descent); |
| 1437 | } |
| 1438 | |
| 1439 | int wxWindow::GetCharWidth() const |
| 1440 | { |
| 1441 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); |
| 1442 | |
| 1443 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); |
| 1444 | |
| 1445 | int direction, ascent, descent; |
| 1446 | XCharStruct overall; |
| 1447 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, |
| 1448 | &descent, &overall); |
| 1449 | |
| 1450 | return overall.width; |
| 1451 | } |
| 1452 | |
| 1453 | void wxWindow::GetTextExtent(const wxString& string, |
| 1454 | int *x, int *y, |
| 1455 | int *descent, int *externalLeading, |
| 1456 | const wxFont *theFont) const |
| 1457 | { |
| 1458 | wxFont *fontToUse = (wxFont *)theFont; |
| 1459 | if (!fontToUse) |
| 1460 | fontToUse = (wxFont *) & m_font; |
| 1461 | |
| 1462 | wxCHECK_RET( fontToUse->Ok(), "valid window font needed" ); |
| 1463 | |
| 1464 | WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay()); |
| 1465 | |
| 1466 | int direction, ascent, descent2; |
| 1467 | XCharStruct overall; |
| 1468 | int slen = string.Len(); |
| 1469 | |
| 1470 | #if 0 |
| 1471 | if (use16) |
| 1472 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, |
| 1473 | &ascent, &descent2, &overall); |
| 1474 | #endif |
| 1475 | |
| 1476 | XTextExtents((XFontStruct*) pFontStruct, string, slen, |
| 1477 | &direction, &ascent, &descent2, &overall); |
| 1478 | |
| 1479 | if ( x ) |
| 1480 | *x = (overall.width); |
| 1481 | if ( y ) |
| 1482 | *y = (ascent + descent2); |
| 1483 | if (descent) |
| 1484 | *descent = descent2; |
| 1485 | if (externalLeading) |
| 1486 | *externalLeading = 0; |
| 1487 | |
| 1488 | } |
| 1489 | |
| 1490 | // ---------------------------------------------------------------------------- |
| 1491 | // painting |
| 1492 | // ---------------------------------------------------------------------------- |
| 1493 | |
| 1494 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
| 1495 | { |
| 1496 | m_needsRefresh = TRUE; |
| 1497 | Display *display = XtDisplay((Widget) GetMainWidget()); |
| 1498 | Window thisWindow = XtWindow((Widget) GetMainWidget()); |
| 1499 | |
| 1500 | XExposeEvent dummyEvent; |
| 1501 | int width, height; |
| 1502 | GetSize(&width, &height); |
| 1503 | |
| 1504 | dummyEvent.type = Expose; |
| 1505 | dummyEvent.display = display; |
| 1506 | dummyEvent.send_event = True; |
| 1507 | dummyEvent.window = thisWindow; |
| 1508 | if (rect) |
| 1509 | { |
| 1510 | dummyEvent.x = rect->x; |
| 1511 | dummyEvent.y = rect->y; |
| 1512 | dummyEvent.width = rect->width; |
| 1513 | dummyEvent.height = rect->height; |
| 1514 | } |
| 1515 | else |
| 1516 | { |
| 1517 | dummyEvent.x = 0; |
| 1518 | dummyEvent.y = 0; |
| 1519 | dummyEvent.width = width; |
| 1520 | dummyEvent.height = height; |
| 1521 | } |
| 1522 | dummyEvent.count = 0; |
| 1523 | |
| 1524 | if (eraseBack) |
| 1525 | { |
| 1526 | wxClientDC dc(this); |
| 1527 | wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID); |
| 1528 | dc.SetBackground(backgroundBrush); |
| 1529 | if (rect) |
| 1530 | dc.Clear(*rect); |
| 1531 | else |
| 1532 | dc.Clear(); |
| 1533 | } |
| 1534 | |
| 1535 | XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent); |
| 1536 | } |
| 1537 | |
| 1538 | void wxWindow::Clear() |
| 1539 | { |
| 1540 | wxClientDC dc(this); |
| 1541 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
| 1542 | dc.SetBackground(brush); |
| 1543 | dc.Clear(); |
| 1544 | } |
| 1545 | |
| 1546 | void wxWindow::ClearUpdateRects() |
| 1547 | { |
| 1548 | wxRectList::Node* node = m_updateRects.GetFirst(); |
| 1549 | while (node) |
| 1550 | { |
| 1551 | wxRect* rect = node->GetData(); |
| 1552 | delete rect; |
| 1553 | node = node->GetNext(); |
| 1554 | } |
| 1555 | |
| 1556 | m_updateRects.Clear(); |
| 1557 | } |
| 1558 | |
| 1559 | void wxWindow::DoPaint() |
| 1560 | { |
| 1561 | //TODO : make a temporary gc so we can do the XCopyArea below |
| 1562 | if (m_backingPixmap && !m_needsRefresh) |
| 1563 | { |
| 1564 | wxPaintDC dc(this); |
| 1565 | |
| 1566 | GC tempGC = (GC) dc.GetBackingGC(); |
| 1567 | |
| 1568 | Widget widget = (Widget) GetMainWidget(); |
| 1569 | |
| 1570 | int scrollPosX = 0; |
| 1571 | int scrollPosY = 0; |
| 1572 | |
| 1573 | // We have to test whether it's a wxScrolledWindow (hack!) because |
| 1574 | // otherwise we don't know how many pixels have been scrolled. We might |
| 1575 | // solve this in the future by defining virtual wxWindow functions to get |
| 1576 | // the scroll position in pixels. Or, each kind of scrolled window has to |
| 1577 | // implement backing stores itself, using generic wxWindows code. |
| 1578 | wxScrolledWindow* scrolledWindow = wxDynamicCast(this, wxScrolledWindow); |
| 1579 | if ( scrolledWindow ) |
| 1580 | { |
| 1581 | int x, y; |
| 1582 | scrolledWindow->CalcScrolledPosition(0, 0, &x, &y); |
| 1583 | |
| 1584 | scrollPosX = - x; |
| 1585 | scrollPosY = - y; |
| 1586 | } |
| 1587 | |
| 1588 | // TODO: This could be optimized further by only copying the areas in the |
| 1589 | // current update region. |
| 1590 | |
| 1591 | // Only blit the part visible in the client area. The backing pixmap |
| 1592 | // always starts at 0, 0 but we may be looking at only a portion of it. |
| 1593 | wxSize clientArea = GetClientSize(); |
| 1594 | int toBlitX = m_pixmapWidth - scrollPosX; |
| 1595 | int toBlitY = m_pixmapHeight - scrollPosY; |
| 1596 | |
| 1597 | // Copy whichever is samller, the amount of pixmap we have to copy, |
| 1598 | // or the size of the client area. |
| 1599 | toBlitX = wxMin(toBlitX, clientArea.x); |
| 1600 | toBlitY = wxMin(toBlitY, clientArea.y); |
| 1601 | |
| 1602 | // Make sure we're not negative |
| 1603 | toBlitX = wxMax(0, toBlitX); |
| 1604 | toBlitY = wxMax(0, toBlitY); |
| 1605 | |
| 1606 | XCopyArea |
| 1607 | ( |
| 1608 | XtDisplay(widget), |
| 1609 | (Pixmap) m_backingPixmap, |
| 1610 | XtWindow (widget), |
| 1611 | tempGC, |
| 1612 | scrollPosX, scrollPosY, // Start at the scroll position |
| 1613 | toBlitX, toBlitY, // How much of the pixmap to copy |
| 1614 | 0, 0 // Destination |
| 1615 | ); |
| 1616 | } |
| 1617 | else |
| 1618 | { |
| 1619 | // Set an erase event first |
| 1620 | wxEraseEvent eraseEvent(GetId()); |
| 1621 | eraseEvent.SetEventObject(this); |
| 1622 | GetEventHandler()->ProcessEvent(eraseEvent); |
| 1623 | |
| 1624 | wxPaintEvent event(GetId()); |
| 1625 | event.SetEventObject(this); |
| 1626 | GetEventHandler()->ProcessEvent(event); |
| 1627 | |
| 1628 | m_needsRefresh = FALSE; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | // ---------------------------------------------------------------------------- |
| 1633 | // event handlers |
| 1634 | // ---------------------------------------------------------------------------- |
| 1635 | |
| 1636 | // Responds to colour changes: passes event on to children. |
| 1637 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) |
| 1638 | { |
| 1639 | wxWindowList::Node *node = GetChildren().GetFirst(); |
| 1640 | while ( node ) |
| 1641 | { |
| 1642 | // Only propagate to non-top-level windows |
| 1643 | wxWindow *win = node->GetData(); |
| 1644 | if ( win->GetParent() ) |
| 1645 | { |
| 1646 | wxSysColourChangedEvent event2; |
| 1647 | event.m_eventObject = win; |
| 1648 | win->GetEventHandler()->ProcessEvent(event2); |
| 1649 | } |
| 1650 | |
| 1651 | node = node->GetNext(); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event)) |
| 1656 | { |
| 1657 | // This calls the UI-update mechanism (querying windows for |
| 1658 | // menu/toolbar/control state information) |
| 1659 | UpdateWindowUI(); |
| 1660 | } |
| 1661 | |
| 1662 | // ---------------------------------------------------------------------------- |
| 1663 | // accelerators |
| 1664 | // ---------------------------------------------------------------------------- |
| 1665 | |
| 1666 | bool wxWindow::ProcessAccelerator(wxKeyEvent& event) |
| 1667 | { |
| 1668 | if (!m_acceleratorTable.Ok()) |
| 1669 | return FALSE; |
| 1670 | |
| 1671 | int count = m_acceleratorTable.GetCount(); |
| 1672 | wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries(); |
| 1673 | int i; |
| 1674 | for (i = 0; i < count; i++) |
| 1675 | { |
| 1676 | wxAcceleratorEntry* entry = & (entries[i]); |
| 1677 | if (entry->MatchesEvent(event)) |
| 1678 | { |
| 1679 | // Bingo, we have a match. Now find a control that matches the |
| 1680 | // entry command id. |
| 1681 | |
| 1682 | // Need to go up to the top of the window hierarchy, since it might |
| 1683 | // be e.g. a menu item |
| 1684 | wxWindow* parent = this; |
| 1685 | while ( parent && !parent->IsTopLevel() ) |
| 1686 | parent = parent->GetParent(); |
| 1687 | |
| 1688 | if (!parent) |
| 1689 | return FALSE; |
| 1690 | |
| 1691 | wxFrame* frame = wxDynamicCast(parent, wxFrame); |
| 1692 | if ( frame ) |
| 1693 | { |
| 1694 | // Try for a menu command |
| 1695 | if (frame->GetMenuBar()) |
| 1696 | { |
| 1697 | wxMenuItem* item = frame->GetMenuBar()->FindItem(entry->GetCommand()); |
| 1698 | if (item) |
| 1699 | { |
| 1700 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand()); |
| 1701 | commandEvent.SetEventObject(frame); |
| 1702 | |
| 1703 | // If ProcessEvent returns TRUE (it was handled), then |
| 1704 | // the calling code will skip the event handling. |
| 1705 | return frame->GetEventHandler()->ProcessEvent(commandEvent); |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | // Find a child matching the command id |
| 1711 | wxWindow* child = parent->FindWindow(entry->GetCommand()); |
| 1712 | |
| 1713 | // No such child |
| 1714 | if (!child) |
| 1715 | return FALSE; |
| 1716 | |
| 1717 | // Now we process those kinds of windows that we can. |
| 1718 | // For now, only buttons. |
| 1719 | if ( wxDynamicCast(child, wxButton) ) |
| 1720 | { |
| 1721 | wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId()); |
| 1722 | commandEvent.SetEventObject(child); |
| 1723 | return child->GetEventHandler()->ProcessEvent(commandEvent); |
| 1724 | } |
| 1725 | |
| 1726 | return FALSE; |
| 1727 | } // matches event |
| 1728 | }// for |
| 1729 | |
| 1730 | // We didn't match the key event against an accelerator. |
| 1731 | return FALSE; |
| 1732 | } |
| 1733 | |
| 1734 | // ============================================================================ |
| 1735 | // Motif-specific stuff from here on |
| 1736 | // ============================================================================ |
| 1737 | |
| 1738 | // ---------------------------------------------------------------------------- |
| 1739 | // function which maintain the global hash table mapping Widgets to wxWindows |
| 1740 | // ---------------------------------------------------------------------------- |
| 1741 | |
| 1742 | bool wxAddWindowToTable(Widget w, wxWindow *win) |
| 1743 | { |
| 1744 | wxWindow *oldItem = NULL; |
| 1745 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) |
| 1746 | { |
| 1747 | wxLogDebug("Widget table clash: new widget is %ld, %s", |
| 1748 | (long)w, win->GetClassInfo()->GetClassName()); |
| 1749 | return FALSE; |
| 1750 | } |
| 1751 | |
| 1752 | wxWidgetHashTable->Put((long) w, win); |
| 1753 | |
| 1754 | wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)", |
| 1755 | w, win, win->GetClassInfo()->GetClassName()); |
| 1756 | |
| 1757 | return TRUE; |
| 1758 | } |
| 1759 | |
| 1760 | wxWindow *wxGetWindowFromTable(Widget w) |
| 1761 | { |
| 1762 | return (wxWindow *)wxWidgetHashTable->Get((long) w); |
| 1763 | } |
| 1764 | |
| 1765 | void wxDeleteWindowFromTable(Widget w) |
| 1766 | { |
| 1767 | wxWidgetHashTable->Delete((long)w); |
| 1768 | } |
| 1769 | |
| 1770 | // ---------------------------------------------------------------------------- |
| 1771 | // add/remove window from the table |
| 1772 | // ---------------------------------------------------------------------------- |
| 1773 | |
| 1774 | // Add to hash table, add event handler |
| 1775 | bool wxWindow::AttachWidget (wxWindow* WXUNUSED(parent), WXWidget mainWidget, |
| 1776 | WXWidget formWidget, int x, int y, int width, int height) |
| 1777 | { |
| 1778 | wxAddWindowToTable((Widget) mainWidget, this); |
| 1779 | if (CanAddEventHandler()) |
| 1780 | { |
| 1781 | XtAddEventHandler((Widget) mainWidget, |
| 1782 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, |
| 1783 | False, |
| 1784 | wxPanelItemEventHandler, |
| 1785 | (XtPointer) this); |
| 1786 | } |
| 1787 | |
| 1788 | if (!formWidget) |
| 1789 | { |
| 1790 | XtTranslations ptr; |
| 1791 | XtOverrideTranslations ((Widget) mainWidget, |
| 1792 | ptr = XtParseTranslationTable ("<Configure>: resize()")); |
| 1793 | XtFree ((char *) ptr); |
| 1794 | } |
| 1795 | |
| 1796 | // Some widgets have a parent form widget, e.g. wxRadioBox |
| 1797 | if (formWidget) |
| 1798 | { |
| 1799 | if (!wxAddWindowToTable((Widget) formWidget, this)) |
| 1800 | return FALSE; |
| 1801 | |
| 1802 | XtTranslations ptr; |
| 1803 | XtOverrideTranslations ((Widget) formWidget, |
| 1804 | ptr = XtParseTranslationTable ("<Configure>: resize()")); |
| 1805 | XtFree ((char *) ptr); |
| 1806 | } |
| 1807 | |
| 1808 | if (x == -1) |
| 1809 | x = 0; |
| 1810 | if (y == -1) |
| 1811 | y = 0; |
| 1812 | SetSize (x, y, width, height); |
| 1813 | |
| 1814 | return TRUE; |
| 1815 | } |
| 1816 | |
| 1817 | // Remove event handler, remove from hash table |
| 1818 | bool wxWindow::DetachWidget(WXWidget widget) |
| 1819 | { |
| 1820 | if (CanAddEventHandler()) |
| 1821 | { |
| 1822 | XtRemoveEventHandler((Widget) widget, |
| 1823 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, |
| 1824 | False, |
| 1825 | wxPanelItemEventHandler, |
| 1826 | (XtPointer)this); |
| 1827 | } |
| 1828 | |
| 1829 | wxDeleteWindowFromTable((Widget) widget); |
| 1830 | return TRUE; |
| 1831 | } |
| 1832 | |
| 1833 | // ---------------------------------------------------------------------------- |
| 1834 | // Motif-specific accessors |
| 1835 | // ---------------------------------------------------------------------------- |
| 1836 | |
| 1837 | // Get the underlying X window |
| 1838 | WXWindow wxWindow::GetXWindow() const |
| 1839 | { |
| 1840 | Widget wMain = (Widget)GetMainWidget(); |
| 1841 | if ( wMain ) |
| 1842 | return (WXWindow) XtWindow(wMain); |
| 1843 | else |
| 1844 | return (WXWindow) 0; |
| 1845 | } |
| 1846 | |
| 1847 | // Get the underlying X display |
| 1848 | WXDisplay *wxWindow::GetXDisplay() const |
| 1849 | { |
| 1850 | Widget wMain = (Widget)GetMainWidget(); |
| 1851 | if ( wMain ) |
| 1852 | return (WXDisplay*) XtDisplay(wMain); |
| 1853 | else |
| 1854 | return (WXDisplay*) NULL; |
| 1855 | } |
| 1856 | |
| 1857 | WXWidget wxWindow::GetMainWidget() const |
| 1858 | { |
| 1859 | if (m_drawingArea) |
| 1860 | return m_drawingArea; |
| 1861 | else |
| 1862 | return m_mainWidget; |
| 1863 | } |
| 1864 | |
| 1865 | WXWidget wxWindow::GetClientWidget() const |
| 1866 | { |
| 1867 | if (m_drawingArea != (WXWidget) 0) |
| 1868 | return m_drawingArea; |
| 1869 | else |
| 1870 | return GetMainWidget(); |
| 1871 | } |
| 1872 | |
| 1873 | WXWidget wxWindow::GetTopWidget() const |
| 1874 | { |
| 1875 | return GetMainWidget(); |
| 1876 | } |
| 1877 | |
| 1878 | WXWidget wxWindow::GetLabelWidget() const |
| 1879 | { |
| 1880 | return GetMainWidget(); |
| 1881 | } |
| 1882 | |
| 1883 | // ---------------------------------------------------------------------------- |
| 1884 | // Motif callbacks |
| 1885 | // ---------------------------------------------------------------------------- |
| 1886 | |
| 1887 | // All widgets should have this as their resize proc. |
| 1888 | // OnSize sent to wxWindow via client data. |
| 1889 | void wxWidgetResizeProc(Widget w, XConfigureEvent *WXUNUSED(event), String WXUNUSED(args)[], int *WXUNUSED(num_args)) |
| 1890 | { |
| 1891 | wxWindow *win = wxGetWindowFromTable(w); |
| 1892 | if (!win) |
| 1893 | return; |
| 1894 | |
| 1895 | if (win->PreResize()) |
| 1896 | { |
| 1897 | int width, height; |
| 1898 | win->GetSize(&width, &height); |
| 1899 | wxSizeEvent sizeEvent(wxSize(width, height), win->GetId()); |
| 1900 | sizeEvent.SetEventObject(win); |
| 1901 | win->GetEventHandler()->ProcessEvent(sizeEvent); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | static void wxCanvasRepaintProc(Widget drawingArea, |
| 1906 | XtPointer clientData, |
| 1907 | XmDrawingAreaCallbackStruct * cbs) |
| 1908 | { |
| 1909 | if (!wxGetWindowFromTable(drawingArea)) |
| 1910 | return; |
| 1911 | |
| 1912 | XEvent * event = cbs->event; |
| 1913 | wxWindow * win = (wxWindow *) clientData; |
| 1914 | |
| 1915 | switch (event->type) |
| 1916 | { |
| 1917 | case Expose: |
| 1918 | { |
| 1919 | win->AddUpdateRect(event->xexpose.x, event->xexpose.y, |
| 1920 | event->xexpose.width, event->xexpose.height); |
| 1921 | |
| 1922 | if (event -> xexpose.count == 0) |
| 1923 | { |
| 1924 | win->DoPaint(); |
| 1925 | win->ClearUpdateRects(); |
| 1926 | } |
| 1927 | break; |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4) |
| 1933 | static void wxCanvasEnterLeave(Widget drawingArea, |
| 1934 | XtPointer WXUNUSED(clientData), |
| 1935 | XCrossingEvent * event) |
| 1936 | { |
| 1937 | XmDrawingAreaCallbackStruct cbs; |
| 1938 | XEvent ev; |
| 1939 | |
| 1940 | ((XCrossingEvent &) ev) = *event; |
| 1941 | |
| 1942 | cbs.reason = XmCR_INPUT; |
| 1943 | cbs.event = &ev; |
| 1944 | |
| 1945 | wxCanvasInputEvent(drawingArea, (XtPointer) NULL, &cbs); |
| 1946 | } |
| 1947 | |
| 1948 | // Fix to make it work under Motif 1.0 (!) |
| 1949 | static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), XButtonEvent * WXUNUSED(event)) |
| 1950 | { |
| 1951 | #if XmVersion <= 1000 |
| 1952 | XmDrawingAreaCallbackStruct cbs; |
| 1953 | XEvent ev; |
| 1954 | |
| 1955 | ev = *((XEvent *) event); |
| 1956 | cbs.reason = XmCR_INPUT; |
| 1957 | cbs.event = &ev; |
| 1958 | |
| 1959 | wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs); |
| 1960 | #endif // XmVersion <= 1000 |
| 1961 | } |
| 1962 | |
| 1963 | static void wxCanvasInputEvent(Widget drawingArea, |
| 1964 | XtPointer WXUNUSED(data), |
| 1965 | XmDrawingAreaCallbackStruct * cbs) |
| 1966 | { |
| 1967 | wxWindow *canvas = wxGetWindowFromTable(drawingArea); |
| 1968 | XEvent local_event; |
| 1969 | |
| 1970 | if (canvas==NULL) |
| 1971 | return; |
| 1972 | |
| 1973 | if (cbs->reason != XmCR_INPUT) |
| 1974 | return; |
| 1975 | |
| 1976 | local_event = *(cbs->event); // We must keep a copy! |
| 1977 | |
| 1978 | switch (local_event.xany.type) |
| 1979 | { |
| 1980 | case EnterNotify: |
| 1981 | case LeaveNotify: |
| 1982 | case ButtonPress: |
| 1983 | case ButtonRelease: |
| 1984 | case MotionNotify: |
| 1985 | { |
| 1986 | // FIXME: most of this mouse event code is more or less |
| 1987 | // duplicated in wxTranslateMouseEvent |
| 1988 | // |
| 1989 | wxEventType eventType = wxEVT_NULL; |
| 1990 | |
| 1991 | if (local_event.xany.type == EnterNotify) |
| 1992 | { |
| 1993 | //if (local_event.xcrossing.mode!=NotifyNormal) |
| 1994 | // return ; // Ignore grab events |
| 1995 | eventType = wxEVT_ENTER_WINDOW; |
| 1996 | // canvas->GetEventHandler()->OnSetFocus(); |
| 1997 | } |
| 1998 | else if (local_event.xany.type == LeaveNotify) |
| 1999 | { |
| 2000 | //if (local_event.xcrossingr.mode!=NotifyNormal) |
| 2001 | // return ; // Ignore grab events |
| 2002 | eventType = wxEVT_LEAVE_WINDOW; |
| 2003 | // canvas->GetEventHandler()->OnKillFocus(); |
| 2004 | } |
| 2005 | else if (local_event.xany.type == MotionNotify) |
| 2006 | { |
| 2007 | eventType = wxEVT_MOTION; |
| 2008 | } |
| 2009 | |
| 2010 | else if (local_event.xany.type == ButtonPress) |
| 2011 | { |
| 2012 | if (local_event.xbutton.button == Button1) |
| 2013 | { |
| 2014 | eventType = wxEVT_LEFT_DOWN; |
| 2015 | canvas->SetButton1(TRUE); |
| 2016 | } |
| 2017 | else if (local_event.xbutton.button == Button2) |
| 2018 | { |
| 2019 | eventType = wxEVT_MIDDLE_DOWN; |
| 2020 | canvas->SetButton2(TRUE); |
| 2021 | } |
| 2022 | else if (local_event.xbutton.button == Button3) |
| 2023 | { |
| 2024 | eventType = wxEVT_RIGHT_DOWN; |
| 2025 | canvas->SetButton3(TRUE); |
| 2026 | } |
| 2027 | } |
| 2028 | else if (local_event.xany.type == ButtonRelease) |
| 2029 | { |
| 2030 | if (local_event.xbutton.button == Button1) |
| 2031 | { |
| 2032 | eventType = wxEVT_LEFT_UP; |
| 2033 | canvas->SetButton1(FALSE); |
| 2034 | } |
| 2035 | else if (local_event.xbutton.button == Button2) |
| 2036 | { |
| 2037 | eventType = wxEVT_MIDDLE_UP; |
| 2038 | canvas->SetButton2(FALSE); |
| 2039 | } |
| 2040 | else if (local_event.xbutton.button == Button3) |
| 2041 | { |
| 2042 | eventType = wxEVT_RIGHT_UP; |
| 2043 | canvas->SetButton3(FALSE); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | wxMouseEvent wxevent (eventType); |
| 2048 | |
| 2049 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) |
| 2050 | || (event_left_is_down (&local_event) |
| 2051 | && (eventType != wxEVT_LEFT_UP))); |
| 2052 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) |
| 2053 | || (event_middle_is_down (&local_event) |
| 2054 | && (eventType != wxEVT_MIDDLE_UP))); |
| 2055 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) |
| 2056 | || (event_right_is_down (&local_event) |
| 2057 | && (eventType != wxEVT_RIGHT_UP))); |
| 2058 | |
| 2059 | wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask; |
| 2060 | wxevent.m_controlDown = local_event.xbutton.state & ControlMask; |
| 2061 | wxevent.m_altDown = local_event.xbutton.state & Mod3Mask; |
| 2062 | wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask; |
| 2063 | wxevent.SetTimestamp(local_event.xbutton.time); |
| 2064 | |
| 2065 | if ( eventType == wxEVT_MOTION ) |
| 2066 | { |
| 2067 | if (local_event.xmotion.is_hint == NotifyHint) |
| 2068 | { |
| 2069 | Window root, child; |
| 2070 | Display *dpy = XtDisplay (drawingArea); |
| 2071 | |
| 2072 | XQueryPointer (dpy, XtWindow (drawingArea), |
| 2073 | &root, &child, |
| 2074 | &local_event.xmotion.x_root, |
| 2075 | &local_event.xmotion.y_root, |
| 2076 | &local_event.xmotion.x, |
| 2077 | &local_event.xmotion.y, |
| 2078 | &local_event.xmotion.state); |
| 2079 | } |
| 2080 | else |
| 2081 | { |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | // Now check if we need to translate this event into a double click |
| 2086 | if (TRUE) // canvas->doubleClickAllowed) |
| 2087 | { |
| 2088 | if (wxevent.ButtonDown()) |
| 2089 | { |
| 2090 | long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()); |
| 2091 | |
| 2092 | // get button and time-stamp |
| 2093 | int button = 0; |
| 2094 | if (wxevent.LeftDown()) |
| 2095 | button = 1; |
| 2096 | else if (wxevent.MiddleDown()) |
| 2097 | button = 2; |
| 2098 | else if (wxevent.RightDown()) |
| 2099 | button = 3; |
| 2100 | long ts = wxevent.GetTimestamp(); |
| 2101 | |
| 2102 | // check, if single or double click |
| 2103 | int buttonLast = canvas->GetLastClickedButton(); |
| 2104 | long lastTS = canvas->GetLastClickTime(); |
| 2105 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) |
| 2106 | { |
| 2107 | // I have a dclick |
| 2108 | canvas->SetLastClick(0, ts); |
| 2109 | |
| 2110 | wxEventType typeDouble; |
| 2111 | if ( eventType == wxEVT_LEFT_DOWN ) |
| 2112 | typeDouble = wxEVT_LEFT_DCLICK; |
| 2113 | else if ( eventType == wxEVT_MIDDLE_DOWN ) |
| 2114 | typeDouble = wxEVT_MIDDLE_DCLICK; |
| 2115 | else if ( eventType == wxEVT_RIGHT_DOWN ) |
| 2116 | typeDouble = wxEVT_RIGHT_DCLICK; |
| 2117 | else |
| 2118 | typeDouble = wxEVT_NULL; |
| 2119 | |
| 2120 | if ( typeDouble != wxEVT_NULL ) |
| 2121 | { |
| 2122 | wxevent.SetEventType(typeDouble); |
| 2123 | } |
| 2124 | } |
| 2125 | else |
| 2126 | { |
| 2127 | // not fast enough or different button |
| 2128 | canvas->SetLastClick(button, ts); |
| 2129 | } |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | wxevent.SetId(canvas->GetId()); |
| 2134 | wxevent.SetEventObject(canvas); |
| 2135 | wxevent.m_x = local_event.xbutton.x; |
| 2136 | wxevent.m_y = local_event.xbutton.y; |
| 2137 | canvas->GetEventHandler()->ProcessEvent (wxevent); |
| 2138 | #if 0 |
| 2139 | if (eventType == wxEVT_ENTER_WINDOW || |
| 2140 | eventType == wxEVT_LEAVE_WINDOW || |
| 2141 | eventType == wxEVT_MOTION |
| 2142 | ) |
| 2143 | return; |
| 2144 | #endif // 0 |
| 2145 | break; |
| 2146 | } |
| 2147 | case KeyPress: |
| 2148 | { |
| 2149 | KeySym keySym; |
| 2150 | #if 0 |
| 2151 | XComposeStatus compose; |
| 2152 | (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose); |
| 2153 | #endif // 0 |
| 2154 | |
| 2155 | (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); |
| 2156 | int id = wxCharCodeXToWX (keySym); |
| 2157 | |
| 2158 | wxEventType eventType = wxEVT_CHAR; |
| 2159 | |
| 2160 | wxKeyEvent event (eventType); |
| 2161 | |
| 2162 | if (local_event.xkey.state & ShiftMask) |
| 2163 | event.m_shiftDown = TRUE; |
| 2164 | if (local_event.xkey.state & ControlMask) |
| 2165 | event.m_controlDown = TRUE; |
| 2166 | if (local_event.xkey.state & Mod3Mask) |
| 2167 | event.m_altDown = TRUE; |
| 2168 | if (local_event.xkey.state & Mod1Mask) |
| 2169 | event.m_metaDown = TRUE; |
| 2170 | event.SetEventObject(canvas); |
| 2171 | event.m_keyCode = id; |
| 2172 | event.SetTimestamp(local_event.xkey.time); |
| 2173 | |
| 2174 | if (id > -1) |
| 2175 | { |
| 2176 | // Implement wxFrame::OnCharHook by checking ancestor. |
| 2177 | wxWindow *parent = canvas->GetParent(); |
| 2178 | while (parent && !parent->IsKindOf(CLASSINFO(wxFrame))) |
| 2179 | parent = parent->GetParent(); |
| 2180 | |
| 2181 | if (parent) |
| 2182 | { |
| 2183 | event.SetEventType(wxEVT_CHAR_HOOK); |
| 2184 | if (parent->GetEventHandler()->ProcessEvent(event)) |
| 2185 | return; |
| 2186 | } |
| 2187 | |
| 2188 | // For simplicity, OnKeyDown is the same as OnChar |
| 2189 | // TODO: filter modifier key presses from OnChar |
| 2190 | event.SetEventType(wxEVT_KEY_DOWN); |
| 2191 | |
| 2192 | // Only process OnChar if OnKeyDown didn't swallow it |
| 2193 | if (!canvas->GetEventHandler()->ProcessEvent (event)) |
| 2194 | { |
| 2195 | event.SetEventType(wxEVT_CHAR); |
| 2196 | canvas->GetEventHandler()->ProcessEvent (event); |
| 2197 | } |
| 2198 | } |
| 2199 | break; |
| 2200 | } |
| 2201 | case KeyRelease: |
| 2202 | { |
| 2203 | KeySym keySym; |
| 2204 | (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); |
| 2205 | int id = wxCharCodeXToWX (keySym); |
| 2206 | |
| 2207 | wxKeyEvent event (wxEVT_KEY_UP); |
| 2208 | |
| 2209 | if (local_event.xkey.state & ShiftMask) |
| 2210 | event.m_shiftDown = TRUE; |
| 2211 | if (local_event.xkey.state & ControlMask) |
| 2212 | event.m_controlDown = TRUE; |
| 2213 | if (local_event.xkey.state & Mod3Mask) |
| 2214 | event.m_altDown = TRUE; |
| 2215 | if (local_event.xkey.state & Mod1Mask) |
| 2216 | event.m_metaDown = TRUE; |
| 2217 | event.SetEventObject(canvas); |
| 2218 | event.m_keyCode = id; |
| 2219 | event.SetTimestamp(local_event.xkey.time); |
| 2220 | |
| 2221 | if (id > -1) |
| 2222 | { |
| 2223 | canvas->GetEventHandler()->ProcessEvent (event); |
| 2224 | } |
| 2225 | break; |
| 2226 | } |
| 2227 | case FocusIn: |
| 2228 | { |
| 2229 | if (local_event.xfocus.detail != NotifyPointer) |
| 2230 | { |
| 2231 | wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId()); |
| 2232 | event.SetEventObject(canvas); |
| 2233 | canvas->GetEventHandler()->ProcessEvent(event); |
| 2234 | } |
| 2235 | break; |
| 2236 | } |
| 2237 | case FocusOut: |
| 2238 | { |
| 2239 | if (local_event.xfocus.detail != NotifyPointer) |
| 2240 | { |
| 2241 | wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId()); |
| 2242 | event.SetEventObject(canvas); |
| 2243 | canvas->GetEventHandler()->ProcessEvent(event); |
| 2244 | } |
| 2245 | break; |
| 2246 | } |
| 2247 | default: |
| 2248 | break; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | static void wxPanelItemEventHandler(Widget wid, |
| 2253 | XtPointer WXUNUSED(client_data), |
| 2254 | XEvent* event, |
| 2255 | Boolean *continueToDispatch) |
| 2256 | { |
| 2257 | // Widget can be a label or the actual widget. |
| 2258 | |
| 2259 | wxWindow *window = wxGetWindowFromTable(wid); |
| 2260 | if (window) |
| 2261 | { |
| 2262 | wxMouseEvent wxevent(0); |
| 2263 | if (wxTranslateMouseEvent(wxevent, window, wid, event)) |
| 2264 | { |
| 2265 | window->GetEventHandler()->ProcessEvent(wxevent); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | // TODO: probably the key to allowing default behaviour to happen. Say we |
| 2270 | // set a m_doDefault flag to FALSE at the start of this function. Then in |
| 2271 | // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to |
| 2272 | // TRUE, indicating that default processing can happen. Thus, behaviour can |
| 2273 | // appear to be overridden just by adding an event handler and not calling |
| 2274 | // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current |
| 2275 | // way of handling drawing area events, to simplify things. |
| 2276 | *continueToDispatch = True; |
| 2277 | } |
| 2278 | |
| 2279 | static void wxScrollBarCallback(Widget scrollbar, |
| 2280 | XtPointer clientData, |
| 2281 | XmScrollBarCallbackStruct *cbs) |
| 2282 | { |
| 2283 | wxWindow *win = wxGetWindowFromTable(scrollbar); |
| 2284 | int orientation = (int) clientData; |
| 2285 | |
| 2286 | wxEventType eventType = wxEVT_NULL; |
| 2287 | switch (cbs->reason) |
| 2288 | { |
| 2289 | case XmCR_INCREMENT: |
| 2290 | { |
| 2291 | eventType = wxEVT_SCROLLWIN_LINEDOWN; |
| 2292 | break; |
| 2293 | } |
| 2294 | case XmCR_DECREMENT: |
| 2295 | { |
| 2296 | eventType = wxEVT_SCROLLWIN_LINEUP; |
| 2297 | break; |
| 2298 | } |
| 2299 | case XmCR_DRAG: |
| 2300 | { |
| 2301 | eventType = wxEVT_SCROLLWIN_THUMBTRACK; |
| 2302 | break; |
| 2303 | } |
| 2304 | case XmCR_VALUE_CHANGED: |
| 2305 | { |
| 2306 | eventType = wxEVT_SCROLLWIN_THUMBRELEASE; |
| 2307 | break; |
| 2308 | } |
| 2309 | case XmCR_PAGE_INCREMENT: |
| 2310 | { |
| 2311 | eventType = wxEVT_SCROLLWIN_PAGEDOWN; |
| 2312 | break; |
| 2313 | } |
| 2314 | case XmCR_PAGE_DECREMENT: |
| 2315 | { |
| 2316 | eventType = wxEVT_SCROLLWIN_PAGEUP; |
| 2317 | break; |
| 2318 | } |
| 2319 | case XmCR_TO_TOP: |
| 2320 | { |
| 2321 | eventType = wxEVT_SCROLLWIN_TOP; |
| 2322 | break; |
| 2323 | } |
| 2324 | case XmCR_TO_BOTTOM: |
| 2325 | { |
| 2326 | eventType = wxEVT_SCROLLWIN_BOTTOM; |
| 2327 | break; |
| 2328 | } |
| 2329 | default: |
| 2330 | { |
| 2331 | // Should never get here |
| 2332 | wxFAIL_MSG("Unknown scroll event."); |
| 2333 | break; |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | wxScrollWinEvent event(eventType, |
| 2338 | cbs->value, |
| 2339 | ((orientation == XmHORIZONTAL) ? |
| 2340 | wxHORIZONTAL : wxVERTICAL)); |
| 2341 | event.SetEventObject( win ); |
| 2342 | win->GetEventHandler()->ProcessEvent(event); |
| 2343 | } |
| 2344 | |
| 2345 | // For repainting arbitrary windows |
| 2346 | void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *) |
| 2347 | { |
| 2348 | Window window; |
| 2349 | Display *display; |
| 2350 | |
| 2351 | wxWindow* win = wxGetWindowFromTable(w); |
| 2352 | if (!win) |
| 2353 | return; |
| 2354 | |
| 2355 | switch(event -> type) |
| 2356 | { |
| 2357 | case Expose: |
| 2358 | { |
| 2359 | window = (Window) win -> GetXWindow(); |
| 2360 | display = (Display *) win -> GetXDisplay(); |
| 2361 | |
| 2362 | if (event -> xexpose.count == 0) |
| 2363 | { |
| 2364 | win->DoPaint(); |
| 2365 | |
| 2366 | win->ClearUpdateRects(); |
| 2367 | } |
| 2368 | else |
| 2369 | { |
| 2370 | win->AddUpdateRect(event->xexpose.x, event->xexpose.y, |
| 2371 | event->xexpose.width, event->xexpose.height); |
| 2372 | } |
| 2373 | |
| 2374 | break; |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | // ---------------------------------------------------------------------------- |
| 2380 | // CanvaseXXXSize() functions |
| 2381 | // ---------------------------------------------------------------------------- |
| 2382 | |
| 2383 | // SetSize, but as per old wxCanvas (with drawing widget etc.) |
| 2384 | void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags) |
| 2385 | { |
| 2386 | // A bit of optimization to help sort out the flickers. |
| 2387 | int oldX, oldY, oldW, oldH; |
| 2388 | GetSize(& oldW, & oldH); |
| 2389 | GetPosition(& oldX, & oldY); |
| 2390 | |
| 2391 | bool useOldPos = FALSE; |
| 2392 | bool useOldSize = FALSE; |
| 2393 | |
| 2394 | if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)) |
| 2395 | useOldPos = TRUE; |
| 2396 | else if (x == oldX && y == oldY) |
| 2397 | useOldPos = TRUE; |
| 2398 | |
| 2399 | if ((w == -1) && (h == -1)) |
| 2400 | useOldSize = TRUE; |
| 2401 | else if (w == oldW && h == oldH) |
| 2402 | useOldSize = TRUE; |
| 2403 | |
| 2404 | if (!wxNoOptimize::CanOptimize()) |
| 2405 | { |
| 2406 | useOldSize = FALSE; useOldPos = FALSE; |
| 2407 | } |
| 2408 | |
| 2409 | if (useOldPos && useOldSize) |
| 2410 | return; |
| 2411 | |
| 2412 | Widget drawingArea = (Widget) m_drawingArea; |
| 2413 | bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); |
| 2414 | |
| 2415 | if (managed) |
| 2416 | XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); |
| 2417 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); |
| 2418 | |
| 2419 | int xx = x; int yy = y; |
| 2420 | AdjustForParentClientOrigin(xx, yy, sizeFlags); |
| 2421 | |
| 2422 | if (!useOldPos) |
| 2423 | { |
| 2424 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
| 2425 | { |
| 2426 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, |
| 2427 | XmNx, xx, NULL); |
| 2428 | } |
| 2429 | |
| 2430 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
| 2431 | { |
| 2432 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, |
| 2433 | XmNy, yy, NULL); |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | if (!useOldSize) |
| 2438 | { |
| 2439 | |
| 2440 | if (w > -1) |
| 2441 | { |
| 2442 | if (m_borderWidget) |
| 2443 | { |
| 2444 | XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL); |
| 2445 | short thick, margin; |
| 2446 | XtVaGetValues ((Widget) m_borderWidget, |
| 2447 | XmNshadowThickness, &thick, |
| 2448 | XmNmarginWidth, &margin, |
| 2449 | NULL); |
| 2450 | w -= 2 * (thick + margin); |
| 2451 | } |
| 2452 | |
| 2453 | XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL); |
| 2454 | |
| 2455 | Dimension spacing; |
| 2456 | Widget sbar; |
| 2457 | XtVaGetValues ((Widget) m_scrolledWindow, |
| 2458 | XmNspacing, &spacing, |
| 2459 | XmNverticalScrollBar, &sbar, |
| 2460 | NULL); |
| 2461 | Dimension wsbar; |
| 2462 | if (sbar) |
| 2463 | XtVaGetValues (sbar, XmNwidth, &wsbar, NULL); |
| 2464 | else |
| 2465 | wsbar = 0; |
| 2466 | |
| 2467 | w -= (spacing + wsbar); |
| 2468 | |
| 2469 | #if 0 |
| 2470 | XtVaSetValues(drawingArea, XmNwidth, w, NULL); |
| 2471 | #endif // 0 |
| 2472 | } |
| 2473 | if (h > -1) |
| 2474 | { |
| 2475 | if (m_borderWidget) |
| 2476 | { |
| 2477 | XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL); |
| 2478 | short thick, margin; |
| 2479 | XtVaGetValues ((Widget) m_borderWidget, |
| 2480 | XmNshadowThickness, &thick, |
| 2481 | XmNmarginHeight, &margin, |
| 2482 | NULL); |
| 2483 | h -= 2 * (thick + margin); |
| 2484 | } |
| 2485 | |
| 2486 | XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL); |
| 2487 | |
| 2488 | Dimension spacing; |
| 2489 | Widget sbar; |
| 2490 | XtVaGetValues ((Widget) m_scrolledWindow, |
| 2491 | XmNspacing, &spacing, |
| 2492 | XmNhorizontalScrollBar, &sbar, |
| 2493 | NULL); |
| 2494 | Dimension wsbar; |
| 2495 | if (sbar) |
| 2496 | XtVaGetValues (sbar, XmNheight, &wsbar, NULL); |
| 2497 | else |
| 2498 | wsbar = 0; |
| 2499 | |
| 2500 | h -= (spacing + wsbar); |
| 2501 | |
| 2502 | #if 0 |
| 2503 | XtVaSetValues(drawingArea, XmNheight, h, NULL); |
| 2504 | #endif // 0 |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | if (managed) |
| 2509 | XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); |
| 2510 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); |
| 2511 | |
| 2512 | #if 0 |
| 2513 | int ww, hh; |
| 2514 | GetClientSize (&ww, &hh); |
| 2515 | wxSizeEvent sizeEvent(wxSize(ww, hh), GetId()); |
| 2516 | sizeEvent.SetEventObject(this); |
| 2517 | |
| 2518 | GetEventHandler()->ProcessEvent(sizeEvent); |
| 2519 | #endif // 0 |
| 2520 | } |
| 2521 | |
| 2522 | void wxWindow::CanvasSetClientSize (int w, int h) |
| 2523 | { |
| 2524 | Widget drawingArea = (Widget) m_drawingArea; |
| 2525 | |
| 2526 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); |
| 2527 | |
| 2528 | if (w > -1) |
| 2529 | XtVaSetValues(drawingArea, XmNwidth, w, NULL); |
| 2530 | if (h > -1) |
| 2531 | XtVaSetValues(drawingArea, XmNheight, h, NULL); |
| 2532 | |
| 2533 | #if 0 |
| 2534 | // TODO: is this necessary? |
| 2535 | allowRepainting = FALSE; |
| 2536 | |
| 2537 | XSync (XtDisplay (drawingArea), FALSE); |
| 2538 | XEvent event; |
| 2539 | while (XtAppPending (wxTheApp->appContext)) |
| 2540 | { |
| 2541 | XFlush (XtDisplay (drawingArea)); |
| 2542 | XtAppNextEvent (wxTheApp->appContext, &event); |
| 2543 | XtDispatchEvent (&event); |
| 2544 | } |
| 2545 | #endif // 0 |
| 2546 | |
| 2547 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); |
| 2548 | |
| 2549 | #if 0 |
| 2550 | allowRepainting = TRUE; |
| 2551 | DoRefresh (); |
| 2552 | |
| 2553 | wxSizeEvent sizeEvent(wxSize(w, h), GetId()); |
| 2554 | sizeEvent.SetEventObject(this); |
| 2555 | |
| 2556 | GetEventHandler()->ProcessEvent(sizeEvent); |
| 2557 | #endif // 0 |
| 2558 | } |
| 2559 | |
| 2560 | void wxWindow::CanvasGetClientSize (int *w, int *h) const |
| 2561 | { |
| 2562 | // Must return the same thing that was set via SetClientSize |
| 2563 | Dimension xx, yy; |
| 2564 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 2565 | *w = xx; |
| 2566 | *h = yy; |
| 2567 | } |
| 2568 | |
| 2569 | void wxWindow::CanvasGetSize (int *w, int *h) const |
| 2570 | { |
| 2571 | Dimension xx, yy; |
| 2572 | if ((Widget) m_borderWidget) |
| 2573 | XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 2574 | else if ((Widget) m_scrolledWindow) |
| 2575 | XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 2576 | else |
| 2577 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); |
| 2578 | |
| 2579 | *w = xx; |
| 2580 | *h = yy; |
| 2581 | } |
| 2582 | |
| 2583 | void wxWindow::CanvasGetPosition (int *x, int *y) const |
| 2584 | { |
| 2585 | Position xx, yy; |
| 2586 | XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL); |
| 2587 | |
| 2588 | // We may be faking the client origin. |
| 2589 | // So a window that's really at (0, 30) may appear |
| 2590 | // (to wxWin apps) to be at (0, 0). |
| 2591 | if (GetParent()) |
| 2592 | { |
| 2593 | wxPoint pt(GetParent()->GetClientAreaOrigin()); |
| 2594 | xx -= pt.x; |
| 2595 | yy -= pt.y; |
| 2596 | } |
| 2597 | |
| 2598 | *x = xx; |
| 2599 | *y = yy; |
| 2600 | } |
| 2601 | |
| 2602 | // ---------------------------------------------------------------------------- |
| 2603 | // TranslateXXXEvent() functions |
| 2604 | // ---------------------------------------------------------------------------- |
| 2605 | |
| 2606 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent) |
| 2607 | { |
| 2608 | switch (xevent->xany.type) |
| 2609 | { |
| 2610 | case EnterNotify: // never received here - yes ? MB |
| 2611 | case LeaveNotify: // never received here - yes ? MB |
| 2612 | case ButtonPress: |
| 2613 | case ButtonRelease: |
| 2614 | case MotionNotify: |
| 2615 | { |
| 2616 | wxEventType eventType = wxEVT_NULL; |
| 2617 | |
| 2618 | // FIXME: this is never true I think - MB |
| 2619 | // |
| 2620 | if (xevent->xany.type == LeaveNotify) |
| 2621 | { |
| 2622 | win->SetButton1(FALSE); |
| 2623 | win->SetButton2(FALSE); |
| 2624 | win->SetButton3(FALSE); |
| 2625 | return FALSE; |
| 2626 | } |
| 2627 | else if (xevent->xany.type == MotionNotify) |
| 2628 | { |
| 2629 | eventType = wxEVT_MOTION; |
| 2630 | } |
| 2631 | else if (xevent->xany.type == ButtonPress) |
| 2632 | { |
| 2633 | wxevent.SetTimestamp(xevent->xbutton.time); |
| 2634 | int button = 0; |
| 2635 | if (xevent->xbutton.button == Button1) |
| 2636 | { |
| 2637 | eventType = wxEVT_LEFT_DOWN; |
| 2638 | win->SetButton1(TRUE); |
| 2639 | button = 1; |
| 2640 | } |
| 2641 | else if (xevent->xbutton.button == Button2) |
| 2642 | { |
| 2643 | eventType = wxEVT_MIDDLE_DOWN; |
| 2644 | win->SetButton2(TRUE); |
| 2645 | button = 2; |
| 2646 | } |
| 2647 | else if (xevent->xbutton.button == Button3) |
| 2648 | { |
| 2649 | eventType = wxEVT_RIGHT_DOWN; |
| 2650 | win->SetButton3(TRUE); |
| 2651 | button = 3; |
| 2652 | } |
| 2653 | |
| 2654 | // check for a double click |
| 2655 | // |
| 2656 | long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()); |
| 2657 | long ts = wxevent.GetTimestamp(); |
| 2658 | |
| 2659 | int buttonLast = win->GetLastClickedButton(); |
| 2660 | long lastTS = win->GetLastClickTime(); |
| 2661 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) |
| 2662 | { |
| 2663 | // I have a dclick |
| 2664 | win->SetLastClick(0, ts); |
| 2665 | if ( eventType == wxEVT_LEFT_DOWN ) |
| 2666 | eventType = wxEVT_LEFT_DCLICK; |
| 2667 | else if ( eventType == wxEVT_MIDDLE_DOWN ) |
| 2668 | eventType = wxEVT_MIDDLE_DCLICK; |
| 2669 | else if ( eventType == wxEVT_RIGHT_DOWN ) |
| 2670 | eventType = wxEVT_RIGHT_DCLICK; |
| 2671 | } |
| 2672 | else |
| 2673 | { |
| 2674 | // not fast enough or different button |
| 2675 | win->SetLastClick(button, ts); |
| 2676 | } |
| 2677 | } |
| 2678 | else if (xevent->xany.type == ButtonRelease) |
| 2679 | { |
| 2680 | if (xevent->xbutton.button == Button1) |
| 2681 | { |
| 2682 | eventType = wxEVT_LEFT_UP; |
| 2683 | win->SetButton1(FALSE); |
| 2684 | } |
| 2685 | else if (xevent->xbutton.button == Button2) |
| 2686 | { |
| 2687 | eventType = wxEVT_MIDDLE_UP; |
| 2688 | win->SetButton2(FALSE); |
| 2689 | } |
| 2690 | else if (xevent->xbutton.button == Button3) |
| 2691 | { |
| 2692 | eventType = wxEVT_RIGHT_UP; |
| 2693 | win->SetButton3(FALSE); |
| 2694 | } |
| 2695 | else return FALSE; |
| 2696 | } |
| 2697 | else |
| 2698 | { |
| 2699 | return FALSE; |
| 2700 | } |
| 2701 | |
| 2702 | wxevent.SetEventType(eventType); |
| 2703 | |
| 2704 | Position x1, y1; |
| 2705 | XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL); |
| 2706 | |
| 2707 | int x2, y2; |
| 2708 | win->GetPosition(&x2, &y2); |
| 2709 | |
| 2710 | // The button x/y must be translated to wxWindows |
| 2711 | // window space - the widget might be a label or button, |
| 2712 | // within a form. |
| 2713 | int dx = 0; |
| 2714 | int dy = 0; |
| 2715 | if (widget != (Widget)win->GetMainWidget()) |
| 2716 | { |
| 2717 | dx = x1; |
| 2718 | dy = y1; |
| 2719 | } |
| 2720 | |
| 2721 | wxevent.m_x = xevent->xbutton.x + dx; |
| 2722 | wxevent.m_y = xevent->xbutton.y + dy; |
| 2723 | |
| 2724 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) |
| 2725 | || (event_left_is_down (xevent) |
| 2726 | && (eventType != wxEVT_LEFT_UP))); |
| 2727 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) |
| 2728 | || (event_middle_is_down (xevent) |
| 2729 | && (eventType != wxEVT_MIDDLE_UP))); |
| 2730 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) |
| 2731 | || (event_right_is_down (xevent) |
| 2732 | && (eventType != wxEVT_RIGHT_UP))); |
| 2733 | |
| 2734 | wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask; |
| 2735 | wxevent.m_controlDown = xevent->xbutton.state & ControlMask; |
| 2736 | wxevent.m_altDown = xevent->xbutton.state & Mod3Mask; |
| 2737 | wxevent.m_metaDown = xevent->xbutton.state & Mod1Mask; |
| 2738 | |
| 2739 | wxevent.SetId(win->GetId()); |
| 2740 | wxevent.SetEventObject(win); |
| 2741 | |
| 2742 | return TRUE; |
| 2743 | } |
| 2744 | } |
| 2745 | return FALSE; |
| 2746 | } |
| 2747 | |
| 2748 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget WXUNUSED(widget), XEvent *xevent) |
| 2749 | { |
| 2750 | switch (xevent->xany.type) |
| 2751 | { |
| 2752 | case KeyPress: |
| 2753 | case KeyRelease: |
| 2754 | { |
| 2755 | char buf[20]; |
| 2756 | |
| 2757 | KeySym keySym; |
| 2758 | #if 0 |
| 2759 | XComposeStatus compose; |
| 2760 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose); |
| 2761 | #endif // 0 |
| 2762 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); |
| 2763 | int id = wxCharCodeXToWX (keySym); |
| 2764 | |
| 2765 | if (xevent->xkey.state & ShiftMask) |
| 2766 | wxevent.m_shiftDown = TRUE; |
| 2767 | if (xevent->xkey.state & ControlMask) |
| 2768 | wxevent.m_controlDown = TRUE; |
| 2769 | if (xevent->xkey.state & Mod3Mask) |
| 2770 | wxevent.m_altDown = TRUE; |
| 2771 | if (xevent->xkey.state & Mod1Mask) |
| 2772 | wxevent.m_metaDown = TRUE; |
| 2773 | wxevent.SetEventObject(win); |
| 2774 | wxevent.m_keyCode = id; |
| 2775 | wxevent.SetTimestamp(xevent->xkey.time); |
| 2776 | |
| 2777 | wxevent.m_x = xevent->xbutton.x; |
| 2778 | wxevent.m_y = xevent->xbutton.y; |
| 2779 | |
| 2780 | if (id > -1) |
| 2781 | return TRUE; |
| 2782 | else |
| 2783 | return FALSE; |
| 2784 | break; |
| 2785 | } |
| 2786 | default: |
| 2787 | break; |
| 2788 | } |
| 2789 | return FALSE; |
| 2790 | } |
| 2791 | |
| 2792 | // ---------------------------------------------------------------------------- |
| 2793 | // Colour stuff |
| 2794 | // ---------------------------------------------------------------------------- |
| 2795 | |
| 2796 | #define YAllocColor XAllocColor |
| 2797 | XColor g_itemColors[5]; |
| 2798 | int wxComputeColours (Display *display, wxColour * back, wxColour * fore) |
| 2799 | { |
| 2800 | int result; |
| 2801 | static XmColorProc colorProc; |
| 2802 | |
| 2803 | result = wxNO_COLORS; |
| 2804 | |
| 2805 | if (back) |
| 2806 | { |
| 2807 | g_itemColors[0].red = (((long) back->Red ()) << 8); |
| 2808 | g_itemColors[0].green = (((long) back->Green ()) << 8); |
| 2809 | g_itemColors[0].blue = (((long) back->Blue ()) << 8); |
| 2810 | g_itemColors[0].flags = DoRed | DoGreen | DoBlue; |
| 2811 | if (colorProc == (XmColorProc) NULL) |
| 2812 | { |
| 2813 | // Get a ptr to the actual function |
| 2814 | colorProc = XmSetColorCalculation ((XmColorProc) NULL); |
| 2815 | // And set it back to motif. |
| 2816 | XmSetColorCalculation (colorProc); |
| 2817 | } |
| 2818 | (*colorProc) (&g_itemColors[wxBACK_INDEX], |
| 2819 | &g_itemColors[wxFORE_INDEX], |
| 2820 | &g_itemColors[wxSELE_INDEX], |
| 2821 | &g_itemColors[wxTOPS_INDEX], |
| 2822 | &g_itemColors[wxBOTS_INDEX]); |
| 2823 | result = wxBACK_COLORS; |
| 2824 | } |
| 2825 | if (fore) |
| 2826 | { |
| 2827 | g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8); |
| 2828 | g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8); |
| 2829 | g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8); |
| 2830 | g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue; |
| 2831 | if (result == wxNO_COLORS) |
| 2832 | result = wxFORE_COLORS; |
| 2833 | } |
| 2834 | |
| 2835 | Display *dpy = display; |
| 2836 | Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy); |
| 2837 | |
| 2838 | if (back) |
| 2839 | { |
| 2840 | /* 5 Colours to allocate */ |
| 2841 | for (int i = 0; i < 5; i++) |
| 2842 | if (!YAllocColor (dpy, cmap, &g_itemColors[i])) |
| 2843 | result = wxNO_COLORS; |
| 2844 | } |
| 2845 | else if (fore) |
| 2846 | { |
| 2847 | /* Only 1 colour to allocate */ |
| 2848 | if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX])) |
| 2849 | result = wxNO_COLORS; |
| 2850 | } |
| 2851 | |
| 2852 | return (result); |
| 2853 | |
| 2854 | } |
| 2855 | |
| 2856 | // Changes the foreground and background colours to be derived from the current |
| 2857 | // background colour. To change the foreground colour, you must call |
| 2858 | // SetForegroundColour explicitly. |
| 2859 | void wxWindow::ChangeBackgroundColour() |
| 2860 | { |
| 2861 | WXWidget mainWidget = GetMainWidget(); |
| 2862 | if ( mainWidget ) |
| 2863 | DoChangeBackgroundColour(mainWidget, m_backgroundColour); |
| 2864 | |
| 2865 | // This not necessary |
| 2866 | #if 0 |
| 2867 | |
| 2868 | if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow)) |
| 2869 | { |
| 2870 | DoChangeBackgroundColour(m_scrolledWindow, m_backgroundColour); |
| 2871 | // Have to set the scrollbar colours back since |
| 2872 | // the scrolled window seemed to change them |
| 2873 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); |
| 2874 | |
| 2875 | if (m_hScrollBar) |
| 2876 | DoChangeBackgroundColour(m_hScrollBar, backgroundColour); |
| 2877 | if (m_vScrollBar) |
| 2878 | DoChangeBackgroundColour(m_vScrollBar, backgroundColour); |
| 2879 | } |
| 2880 | #endif |
| 2881 | } |
| 2882 | |
| 2883 | void wxWindow::ChangeForegroundColour() |
| 2884 | { |
| 2885 | WXWidget mainWidget = GetMainWidget(); |
| 2886 | if ( mainWidget ) |
| 2887 | DoChangeForegroundColour(mainWidget, m_foregroundColour); |
| 2888 | if ( m_scrolledWindow && mainWidget != m_scrolledWindow ) |
| 2889 | DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour); |
| 2890 | } |
| 2891 | |
| 2892 | // Change a widget's foreground and background colours. |
| 2893 | void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) |
| 2894 | { |
| 2895 | // When should we specify the foreground, if it's calculated |
| 2896 | // by wxComputeColours? |
| 2897 | // Solution: say we start with the default (computed) foreground colour. |
| 2898 | // If we call SetForegroundColour explicitly for a control or window, |
| 2899 | // then the foreground is changed. |
| 2900 | // Therefore SetBackgroundColour computes the foreground colour, and |
| 2901 | // SetForegroundColour changes the foreground colour. The ordering is |
| 2902 | // important. |
| 2903 | |
| 2904 | Widget w = (Widget)widget; |
| 2905 | XtVaSetValues( |
| 2906 | w, |
| 2907 | XmNforeground, foregroundColour.AllocColour(XtDisplay(w)), |
| 2908 | NULL |
| 2909 | ); |
| 2910 | } |
| 2911 | |
| 2912 | void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour) |
| 2913 | { |
| 2914 | wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, |
| 2915 | (wxColour*) NULL); |
| 2916 | |
| 2917 | XtVaSetValues ((Widget) widget, |
| 2918 | XmNbackground, g_itemColors[wxBACK_INDEX].pixel, |
| 2919 | XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel, |
| 2920 | XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel, |
| 2921 | XmNforeground, g_itemColors[wxFORE_INDEX].pixel, |
| 2922 | NULL); |
| 2923 | |
| 2924 | if (changeArmColour) |
| 2925 | XtVaSetValues ((Widget) widget, |
| 2926 | XmNarmColor, g_itemColors[wxSELE_INDEX].pixel, |
| 2927 | NULL); |
| 2928 | } |
| 2929 | |
| 2930 | bool wxWindow::SetBackgroundColour(const wxColour& col) |
| 2931 | { |
| 2932 | if ( !wxWindowBase::SetBackgroundColour(col) ) |
| 2933 | return FALSE; |
| 2934 | |
| 2935 | ChangeBackgroundColour(); |
| 2936 | |
| 2937 | return TRUE; |
| 2938 | } |
| 2939 | |
| 2940 | bool wxWindow::SetForegroundColour(const wxColour& col) |
| 2941 | { |
| 2942 | if ( !wxWindowBase::SetForegroundColour(col) ) |
| 2943 | return FALSE; |
| 2944 | |
| 2945 | ChangeForegroundColour(); |
| 2946 | |
| 2947 | return TRUE; |
| 2948 | } |
| 2949 | |
| 2950 | void wxWindow::ChangeFont(bool keepOriginalSize) |
| 2951 | { |
| 2952 | // Note that this causes the widget to be resized back |
| 2953 | // to its original size! We therefore have to set the size |
| 2954 | // back again. TODO: a better way in Motif? |
| 2955 | Widget w = (Widget) GetLabelWidget(); // Usually the main widget |
| 2956 | if (w && m_font.Ok()) |
| 2957 | { |
| 2958 | int width, height, width1, height1; |
| 2959 | GetSize(& width, & height); |
| 2960 | |
| 2961 | // lesstif 0.87 hangs here |
| 2962 | #ifndef LESSTIF_VERSION |
| 2963 | XtVaSetValues (w, |
| 2964 | XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)), |
| 2965 | NULL); |
| 2966 | #endif |
| 2967 | |
| 2968 | GetSize(& width1, & height1); |
| 2969 | if (keepOriginalSize && (width != width1 || height != height1)) |
| 2970 | { |
| 2971 | SetSize(-1, -1, width, height); |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | // ---------------------------------------------------------------------------- |
| 2977 | // global functions |
| 2978 | // ---------------------------------------------------------------------------- |
| 2979 | |
| 2980 | wxWindow *wxGetActiveWindow() |
| 2981 | { |
| 2982 | // TODO |
| 2983 | wxFAIL_MSG("Not implemented"); |
| 2984 | return NULL; |
| 2985 | } |
| 2986 | |
| 2987 | /* static */ |
| 2988 | wxWindow *wxWindowBase::GetCapture() |
| 2989 | { |
| 2990 | return (wxWindow *)g_captureWindow; |
| 2991 | } |
| 2992 | |
| 2993 | |
| 2994 | // Find the wxWindow at the current mouse position, returning the mouse |
| 2995 | // position. |
| 2996 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) |
| 2997 | { |
| 2998 | return wxFindWindowAtPoint(wxGetMousePosition()); |
| 2999 | } |
| 3000 | |
| 3001 | // Get the current mouse position. |
| 3002 | wxPoint wxGetMousePosition() |
| 3003 | { |
| 3004 | Display *display = (Display*) wxGetDisplay(); |
| 3005 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
| 3006 | Window rootReturn, childReturn; |
| 3007 | int rootX, rootY, winX, winY; |
| 3008 | unsigned int maskReturn; |
| 3009 | |
| 3010 | XQueryPointer (display, |
| 3011 | rootWindow, |
| 3012 | &rootReturn, |
| 3013 | &childReturn, |
| 3014 | &rootX, &rootY, &winX, &winY, &maskReturn); |
| 3015 | return wxPoint(rootX, rootY); |
| 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | // ---------------------------------------------------------------------------- |
| 3020 | // wxNoOptimize: switch off size optimization |
| 3021 | // ---------------------------------------------------------------------------- |
| 3022 | |
| 3023 | int wxNoOptimize::ms_count = 0; |
| 3024 | |