-// Add to hash table, add event handler
-bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
- WXWidget formWidget, int x, int y, int width, int height)
-{
- wxAddWindowToTable((Widget) mainWidget, this);
- if (CanAddEventHandler())
- {
- XtAddEventHandler((Widget) mainWidget,
- ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
- False,
- wxPanelItemEventHandler,
- (XtPointer) this);
- }
-
- if (!formWidget)
- {
- XtTranslations ptr;
- XtOverrideTranslations ((Widget) mainWidget,
- ptr = XtParseTranslationTable ("<Configure>: resize()"));
- XtFree ((char *) ptr);
- }
-
- // Some widgets have a parent form widget, e.g. wxRadioBox
- if (formWidget)
- {
- if (!wxAddWindowToTable((Widget) formWidget, this))
- return FALSE;
-
- XtTranslations ptr;
- XtOverrideTranslations ((Widget) formWidget,
- ptr = XtParseTranslationTable ("<Configure>: resize()"));
- XtFree ((char *) ptr);
- }
-
- if (x == -1)
- x = 0;
- if (y == -1)
- y = 0;
- SetSize (x, y, width, height);
-
- return TRUE;
-}
-
-// Remove event handler, remove from hash table
-bool wxWindow::DetachWidget(WXWidget widget)
-{
- if (CanAddEventHandler())
- {
- XtRemoveEventHandler((Widget) widget,
- ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
- False,
- wxPanelItemEventHandler,
- (XtPointer)this);
- }
-
- wxDeleteWindowFromTable((Widget) widget);
- return TRUE;
-}
-
-void wxPanelItemEventHandler (Widget wid,
- XtPointer client_data,
- XEvent* event,
- Boolean *continueToDispatch)
-{
- // Widget can be a label or the actual widget.
-
- wxWindow *window = (wxWindow *)wxWidgetHashTable->Get((long)wid);
- if (window)
- {
- wxMouseEvent wxevent(0);
- if (wxTranslateMouseEvent(wxevent, window, wid, event))
- {
- window->GetEventHandler()->ProcessEvent(wxevent);
- }
- }
- // TODO: probably the key to allowing default behaviour
- // to happen.
- // Say we set a m_doDefault flag to FALSE at the start of this
- // function. Then in e.g. wxWindow::OnMouseEvent we can
- // call Default() which sets this flag to TRUE, indicating
- // that default processing can happen. Thus, behaviour can appear
- // to be overridden just by adding an event handler and not calling
- // wxWindow::OnWhatever.
- // ALSO, maybe we can use this instead of the current way of handling
- // drawing area events, to simplify things.
- *continueToDispatch = True;
-}
-
-static void wxScrollBarCallback(Widget scrollbar, XtPointer clientData,
- XmScaleCallbackStruct *cbs)
-{
- Widget scrolledWindow = XtParent (scrollbar);
- wxWindow *win = (wxWindow *) wxWidgetHashTable->Get ((long) scrolledWindow);
- int orientation = (int) clientData;
-
- wxEventType eventType = wxEVT_NULL;
- switch (cbs->reason)
- {
- case XmCR_INCREMENT:
- {
- eventType = wxEVT_SCROLL_LINEDOWN;
- break;
- }
- case XmCR_DECREMENT:
- {
- eventType = wxEVT_SCROLL_LINEUP;
- break;
- }
- case XmCR_DRAG:
- {
- eventType = wxEVT_SCROLL_THUMBTRACK;
- break;
- }
- case XmCR_VALUE_CHANGED:
- {
- // TODO: Should this be intercepted too, or will it cause
- // duplicate events?
- eventType = wxEVT_SCROLL_THUMBTRACK;
- break;
- }
- case XmCR_PAGE_INCREMENT:
- {
- eventType = wxEVT_SCROLL_PAGEDOWN;
- break;
- }
- case XmCR_PAGE_DECREMENT:
- {
- eventType = wxEVT_SCROLL_PAGEUP;
- break;
- }
- case XmCR_TO_TOP:
- {
- eventType = wxEVT_SCROLL_TOP;
- break;
- }
- case XmCR_TO_BOTTOM:
- {
- eventType = wxEVT_SCROLL_BOTTOM;
- break;
- }
- default:
- {
- // Should never get here
- wxFAIL_MSG("Unknown scroll event.");
- break;
- }
- }
-
- wxScrollEvent event(eventType, win->GetId());
- event.SetEventObject(win);
- event.SetPosition(cbs->value);
- event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL );
-
- win->GetEventHandler()->ProcessEvent(event);
-}