+ Position xx, yy;
+ XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
+
+ // We may be faking the client origin.
+ // So a window that's really at (0, 30) may appear
+ // (to wxWin apps) to be at (0, 0).
+ if (GetParent())
+ {
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ xx -= pt.x;
+ yy -= pt.y;
+ }
+
+ *x = xx;
+ *y = yy;
+}
+
+// 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;
+}
+
+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);
+}
+
+bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
+{
+ switch (xevent->xany.type)
+ {
+ case EnterNotify:
+ case LeaveNotify:
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ {
+ wxEventType eventType = wxEVT_NULL;
+
+ if (xevent->xany.type == LeaveNotify)
+ {
+ win->m_button1Pressed = FALSE;
+ win->m_button2Pressed = FALSE;
+ win->m_button3Pressed = FALSE;
+ return FALSE;
+ }
+ else if (xevent->xany.type == MotionNotify)
+ {
+ eventType = wxEVT_MOTION;
+ }
+ else if (xevent->xany.type == ButtonPress)
+ {
+ if (xevent->xbutton.button == Button1)
+ {
+ eventType = wxEVT_LEFT_DOWN;
+ win->m_button1Pressed = TRUE;
+ }
+ else if (xevent->xbutton.button == Button2)
+ {
+ eventType = wxEVT_MIDDLE_DOWN;
+ win->m_button2Pressed = TRUE;
+ }
+ else if (xevent->xbutton.button == Button3)
+ {
+ eventType = wxEVT_RIGHT_DOWN;
+ win->m_button3Pressed = TRUE;
+ }
+ }
+ else if (xevent->xany.type == ButtonRelease)
+ {
+ if (xevent->xbutton.button == Button1)
+ {
+ eventType = wxEVT_LEFT_UP;
+ win->m_button1Pressed = FALSE;
+ }
+ else if (xevent->xbutton.button == Button2)
+ {
+ eventType = wxEVT_MIDDLE_UP;
+ win->m_button2Pressed = FALSE;
+ }
+ else if (xevent->xbutton.button == Button3)
+ {
+ eventType = wxEVT_RIGHT_UP;
+ win->m_button3Pressed = FALSE;
+ }
+ else return FALSE;
+ }
+ else return FALSE;
+
+ wxevent.m_eventHandle = (char *)xevent;
+ wxevent.SetEventType(eventType);
+
+ Position x1, y1;
+ XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
+
+ int x2, y2;
+ win->GetPosition(&x2, &y2);
+
+ // The button x/y must be translated to wxWindows
+ // window space - the widget might be a label or button,
+ // within a form.
+ int dx = 0;
+ int dy = 0;
+ if (widget != (Widget)win->GetMainWidget())
+ {
+ dx = x1;
+ dy = y1;
+ }
+
+ wxevent.m_x = xevent->xbutton.x + dx;
+ wxevent.m_y = xevent->xbutton.y + dy;
+
+ wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
+ || (event_left_is_down (xevent)
+ && (eventType != wxEVT_LEFT_UP)));
+ wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
+ || (event_middle_is_down (xevent)
+ && (eventType != wxEVT_MIDDLE_UP)));
+ wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
+ || (event_right_is_down (xevent)
+ && (eventType != wxEVT_RIGHT_UP)));
+
+ wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
+ wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
+{
+ switch (xevent->xany.type)
+ {
+ case KeyPress:
+ {
+ char buf[20];
+
+ KeySym keySym;
+// XComposeStatus compose;
+// (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
+ (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
+ int id = wxCharCodeXToWX (keySym);
+
+ if (xevent->xkey.state & ShiftMask)
+ wxevent.m_shiftDown = TRUE;
+ if (xevent->xkey.state & ControlMask)
+ wxevent.m_controlDown = TRUE;
+ if (xevent->xkey.state & Mod3Mask)
+ wxevent.m_altDown = TRUE;
+ if (xevent->xkey.state & Mod1Mask)
+ wxevent.m_metaDown = TRUE;
+ wxevent.SetEventObject(win);
+ wxevent.m_keyCode = id;
+ wxevent.SetTimestamp(xevent->xkey.time);
+
+ wxevent.m_x = xevent->xbutton.x;
+ wxevent.m_y = xevent->xbutton.y;
+
+ if (id > -1)
+ return TRUE;
+ else
+ return FALSE;
+ break;
+ }
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+// TODO From wxWin 1.68. What does it do exactly?
+#define YAllocColor XAllocColor
+
+XColor itemColors[5];
+int wxComputeColors (Display *display, wxColour * back, wxColour * fore)
+{
+ int result;
+ static XmColorProc colorProc;
+
+ result = wxNO_COLORS;
+
+ if (back)
+ {
+ itemColors[0].red = (((long) back->Red ()) << 8);
+ itemColors[0].green = (((long) back->Green ()) << 8);
+ itemColors[0].blue = (((long) back->Blue ()) << 8);
+ itemColors[0].flags = DoRed | DoGreen | DoBlue;
+ if (colorProc == (XmColorProc) NULL)
+ {
+ // Get a ptr to the actual function
+ colorProc = XmSetColorCalculation ((XmColorProc) NULL);
+ // And set it back to motif.
+ XmSetColorCalculation (colorProc);
+ }
+ (*colorProc) (&itemColors[wxBACK_INDEX],
+ &itemColors[wxFORE_INDEX],
+ &itemColors[wxSELE_INDEX],
+ &itemColors[wxTOPS_INDEX],
+ &itemColors[wxBOTS_INDEX]);
+ result = wxBACK_COLORS;
+ }
+ if (fore)
+ {
+ itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
+ itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
+ itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
+ itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
+ if (result == wxNO_COLORS)
+ result = wxFORE_COLORS;
+ }
+
+ Display *dpy = display;
+ Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
+
+ if (back)
+ {
+ /* 5 Colours to allocate */
+ for (int i = 0; i < 5; i++)
+ if (!YAllocColor (dpy, cmap, &itemColors[i]))
+ result = wxNO_COLORS;
+ }
+ else if (fore)
+ {
+ /* Only 1 colour to allocate */
+ if (!YAllocColor (dpy, cmap, &itemColors[wxFORE_INDEX]))
+ result = wxNO_COLORS;
+ }
+
+ return (result);
+
+}
+
+void wxWindow::ChangeColour(WXWidget widget)
+{
+ // TODO
+#if 0
+ int change;
+
+ // TODO: how to determine whether we can change this item's colours?
+ // We used to have wxUSER_COLOURS. Now perhaps we assume we always
+ // can change it.
+ // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
+ // return;
+
+ change = wxComputeColors (XtDisplay((Widget)widget), panel->GetBackgroundColour(),
+ panel->GetLabelColour());
+ if (change == wxBACK_COLORS)
+ XtVaSetValues ((Widget) widget,
+ XmNbackground, itemColors[wxBACK_INDEX].pixel,
+ XmNtopShadowColor, itemColors[wxTOPS_INDEX].pixel,
+ XmNbottomShadowColor, itemColors[wxBOTS_INDEX].pixel,
+ XmNforeground, itemColors[wxFORE_INDEX].pixel,
+ NULL);
+ else if (change == wxFORE_COLORS)
+ XtVaSetValues (formWidget,
+ XmNforeground, itemColors[wxFORE_INDEX].pixel,
+ NULL);
+
+ change = wxComputeColors (XtDisplay((Widget)formWidget), GetBackgroundColour(), GetLabelColour());
+ if (change == wxBACK_COLORS)
+ XtVaSetValues (labelWidget,
+ XmNbackground, itemColors[wxBACK_INDEX].pixel,
+ XmNtopShadowColor, itemColors[wxTOPS_INDEX].pixel,
+ XmNbottomShadowColor, itemColors[wxBOTS_INDEX].pixel,
+ XmNarmColor, itemColors[wxSELE_INDEX].pixel,
+ XmNforeground, itemColors[wxFORE_INDEX].pixel,
+ NULL);
+ else if (change == wxFORE_COLORS)
+ XtVaSetValues (labelWidget,
+ XmNforeground, itemColors[wxFORE_INDEX].pixel,
+ NULL);
+#endif
+}
+
+void wxWindow::ChangeFont(WXWidget widget)
+{
+ /*
+ if (widget && GetFont() && GetFont()->Ok())
+ {
+ XmFontList fontList = (XmFontList) GetFont()->GetFontList(1.0, GetXDisplay());
+ if (fontList)
+ XtVaSetValues ((Widget) widget,
+ XmNfontList, fontList,
+ NULL);
+ }
+ */