From: Julian Smart Date: Sat, 17 Oct 1998 09:38:15 +0000 (+0000) Subject: Motif updates X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/89c7e9622933c3ee7906c39bc3927a7d5616b94b Motif updates git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@864 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/distrib/msw/motif.rsp b/distrib/msw/motif.rsp index abcf194fee..5b311108a5 100644 --- a/distrib/msw/motif.rsp +++ b/distrib/msw/motif.rsp @@ -4,6 +4,11 @@ src/motif/*.h src/motif/makefile* src/motif/*.inc src/motif/*.xbm +src/motif/combobox/*.c +src/motif/combobox/*.h +src/motif/combobox/*.doc +src/motif/combobox/*.man +src/motif/combobox/*.txt src/make.env src/makeprog.env diff --git a/docs/motif/todo.txt b/docs/motif/todo.txt index 67b0a0e3cb..66028e122d 100644 --- a/docs/motif/todo.txt +++ b/docs/motif/todo.txt @@ -16,6 +16,9 @@ High Priority - Work out why XFreeFont in font.cpp produces a segv. This is currently commented out, which presumably causes a memory leak. +- Also work out why wxWindow::SetFont causes the widget to be shrunk + to fit its text. + - Bitmap versions of widgets (wxBitmapButton etc.) - wxRadioBox @@ -84,7 +87,8 @@ Low Priority http://www.motifzone.com/tmd/articles/DnD/dnd.html - Optimize colour management so we don't get clashes when e.g. - Netscape is running. + Netscape is running. See: + http://www.motifzone.com/tmd/articles/John_Cwikla/index.html - wxCheckBoxList diff --git a/docs/msw/todo.txt b/docs/msw/todo.txt index 29f8a89190..7b1ebecf5b 100644 --- a/docs/msw/todo.txt +++ b/docs/msw/todo.txt @@ -88,6 +88,11 @@ printer characteristics) and more reliable printing framework. Add GetIcon, GetBitmap to wxImageList. Perhaps store bitmaps in image list so we can get them later. +Add centring, right justify styles to wxStaticText. + +Synchronize drawing functions on all platforms, using Chris's +code to test them. + LOW PRIORITY ------------ diff --git a/include/wx/motif/dcscreen.h b/include/wx/motif/dcscreen.h index 1a228b165a..e4d4c16979 100644 --- a/include/wx/motif/dcscreen.h +++ b/include/wx/motif/dcscreen.h @@ -32,6 +32,15 @@ class WXDLLEXPORT wxScreenDC: public wxWindowDC static bool StartDrawingOnTop(wxWindow* window); static bool StartDrawingOnTop(wxRect* rect = NULL); static bool EndDrawingOnTop(); + +private: + static WXWindow sm_overlayWindow; + + // If we have started transparent drawing at a non-(0,0) point + // then we will have to adjust the device origin in the + // constructor. + static int sm_overlayWindowX; + static int sm_overlayWindowY; }; #endif diff --git a/include/wx/motif/listbox.h b/include/wx/motif/listbox.h index 5ca22a7d03..8672e99ada 100644 --- a/include/wx/motif/listbox.h +++ b/include/wx/motif/listbox.h @@ -89,6 +89,8 @@ class WXDLLEXPORT wxListBox: public wxControl void Command(wxCommandEvent& event); + WXWidget GetTopWidget() const; + protected: int m_noItems; int m_selected; diff --git a/include/wx/motif/setup.h b/include/wx/motif/setup.h index 74e0dbb668..a53bfbea35 100644 --- a/include/wx/motif/setup.h +++ b/include/wx/motif/setup.h @@ -52,7 +52,9 @@ // 0 for no splines #define wxUSE_TOOLBAR 1 - // Use toolbars + // Use toolbars +#define wxUSE_COMBOBOX 1 + // Use wxComboBox #define wxUSE_DRAG_AND_DROP 1 // 0 for no drag and drop diff --git a/samples/docview/makefile.unx b/samples/docview/makefile.unx index bbdccc3fc4..e49d7b7335 100644 --- a/samples/docview/makefile.unx +++ b/samples/docview/makefile.unx @@ -1,64 +1,18 @@ # # File: makefile.unx # Author: Julian Smart -# Created: 1993 +# Created: 1998 # Updated: -# Copyright: (c) 1993, AIAI, University of Edinburgh +# Copyright: (c) 1998 Julian Smart # # "%W% %G%" # # Makefile for docview example (UNIX). -WXDIR = ../.. +PROGRAM=docview -# All common UNIX compiler flags and options are now in -# this central makefile. -include $(WXDIR)/src/make.env +OBJECTS=$(PROGRAM).o doc.o view.o -OBJECTS = $(OBJDIR)/docview.$(OBJSUFF) $(OBJDIR)/view.$(OBJSUFF) $(OBJDIR)/doc.$(OBJSUFF) +include ../../src/makeprog.env -.SUFFIXES: -all: $(OBJDIR) wx$(GUISUFFIX) docview$(GUISUFFIX) - -wx_motif: - cd $(WXDIR)/src/x; $(MAKE) -f makefile.unx motif - -wx_ol: - cd $(WXDIR)/src/x; $(MAKE) -f makefile.unx xview -motif: - $(MAKE) -f makefile.unx GUISUFFIX=_motif GUI=-Dwx_motif GUISUFFIX=_motif OPT='$(OPT)' LDLIBS='$(MOTIFLDLIBS)' OPTIONS='$(OPTIONS)' DEBUG='$(DEBUG)' WARN='$(WARN)' XLIB='$(XLIB)' XINCLUDE='$(XINCLUDE)' XVIEW_LINK= - -xview: - $(MAKE) -f makefile.unx GUI=-Dwx_xview GUISUFFIX=_ol CC=$(CC) OPTIONS='$(OPTIONS)' DEBUG='$(DEBUG)' WARN='$(WARN)' XLIB='$(XLIB)' XINCLUDE='$(XINCLUDE)' - -hp: - $(MAKE) -f makefile,unx GUI=-Dwx_motif GUISUFFIX=_hp CC=CC DEBUG='$(DEBUG)' WARN='-w' \ - XINCLUDE='$(HPXINCLUDE)' XLIB='$(HPXLIB)' XVIEW_LINK='' LDLIBS='$(HPLDLIBS)' - -$(OBJDIR): - mkdir $(OBJDIR) - -docview$(GUISUFFIX): $(OBJECTS) $(WXLIB) - $(CC) $(LDFLAGS) -o docview$(GUISUFFIX) $(OBJECTS) $(XVIEW_LINK) $(LDLIBS) - -$(OBJDIR)/docview.$(OBJSUFF): docview.$(SRCSUFF) docview.h doc.h view.h - $(CC) -c $(CPPFLAGS) -o $@ docview.$(SRCSUFF) - -$(OBJDIR)/doc.$(OBJSUFF): doc.$(SRCSUFF) doc.h - $(CC) -c $(CPPFLAGS) -o $@ doc.$(SRCSUFF) - -$(OBJDIR)/view.$(OBJSUFF): view.$(SRCSUFF) view.h - $(CC) -c $(CPPFLAGS) -o $@ view.$(SRCSUFF) - -clean_motif: - $(MAKE) -f makefile.unx GUISUFFIX=_motif cleanany - -clean_ol: - $(MAKE) -f makefile.unx GUISUFFIX=_ol cleanany - -clean_hp: - $(MAKE) -f makefile.unx GUISUFFIX=_hp cleanany - -cleanany: - rm -f $(OBJECTS) docview$(GUISUFFIX) core diff --git a/samples/docview/view.cpp b/samples/docview/view.cpp index 14f768dd6a..e0e01bb499 100644 --- a/samples/docview/view.cpp +++ b/samples/docview/view.cpp @@ -57,7 +57,7 @@ bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) // X seems to require a forced resize int x, y; frame->GetSize(&x, &y); - frame->SetSize(x, y); + frame->SetSize(-1, -1, x, y); #endif frame->Show(TRUE); } @@ -168,7 +168,7 @@ bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) // X seems to require a forced resize int x, y; frame->GetSize(&x, &y); - frame->SetSize(x, y); + frame->SetSize(-1, -1, x, y); #endif frame->Show(TRUE); diff --git a/src/motif/button.cpp b/src/motif/button.cpp index 455f2e17fb..8a8ae59c49 100644 --- a/src/motif/button.cpp +++ b/src/motif/button.cpp @@ -14,6 +14,7 @@ #endif #include "wx/button.h" +#include "wx/utils.h" #include #include @@ -45,9 +46,9 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, else m_windowId = id; - char* label1 = (label.IsNull() ? "" : (char*) (const char*) label); + wxString label1(wxStripMenuCodes(label)); - XmString text = XmStringCreateSimple (label1); + XmString text = XmStringCreateSimple ((char*) (const char*) label1); Widget parentWidget = (Widget) parent->GetClientWidget(); /* diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 43547b43c2..1ebd7a76ea 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -15,6 +15,14 @@ #include "wx/combobox.h" +#if wxUSE_COMBOBOX + +#include +#include "combobox/combobox.h" + +void wxComboBoxCallback (Widget w, XtPointer clientData, + XmComboBoxSelectionCallbackStruct * cbs); + #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) #endif @@ -40,36 +48,83 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, else m_windowId = id; - // TODO: create combobox control + Widget parentWidget = (Widget) parent->GetClientWidget(); + + Widget buttonWidget = XtVaCreateManagedWidget((char*) (const char*) name, + xmComboBoxWidgetClass, parentWidget, + XmNmarginHeight, 0, + XmNmarginWidth, 0, + XmNshowLabel, False, + XmNeditable, ((style & wxCB_READONLY) != wxCB_READONLY), + XmNsorted, ((style & wxCB_SORT) == wxCB_SORT), + XmNstaticList, ((style & wxCB_SIMPLE) == wxCB_SIMPLE), + NULL); + + XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, + (XtPointer) this); + XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, + (XtPointer) this); + + int i; + for (i = 0; i < n; i++) + { + XmString str = XmStringCreateLtoR((char*) (const char*) choices[i], XmSTRING_DEFAULT_CHARSET); + XmComboBoxAddItem(buttonWidget, str, 0); + XmStringFree(str); + m_stringList.Add(choices[i]); + } + m_noStrings = n; + + m_mainWidget = (Widget) buttonWidget; + + XtManageChild (buttonWidget); + + SetValue(value); + + SetCanAddEventHandler(TRUE); + AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); + + SetFont(* parent->GetFont()); + ChangeColour(m_mainWidget); return TRUE; } wxString wxComboBox::GetValue() const { - // TODO - return wxString(""); + char *s = XmComboBoxGetString ((Widget) m_mainWidget); + if (s) + { + wxString str(s); + XtFree (s); + return str; + } + else + return wxEmptyString; } void wxComboBox::SetValue(const wxString& value) { - // TODO + m_inSetValue = TRUE; + if (!value.IsNull()) + XmComboBoxSetString ((Widget) m_mainWidget, (char*) (const char*) value); + m_inSetValue = FALSE; } // Clipboard operations void wxComboBox::Copy() { - // TODO + XmComboBoxCopy((Widget) m_mainWidget, CurrentTime); } void wxComboBox::Cut() { - // TODO + XmComboBoxCut((Widget) m_mainWidget, CurrentTime); } void wxComboBox::Paste() { - // TODO + XmComboBoxPaste((Widget) m_mainWidget); } void wxComboBox::SetEditable(bool editable) @@ -79,38 +134,76 @@ void wxComboBox::SetEditable(bool editable) void wxComboBox::SetInsertionPoint(long pos) { - // TODO + XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos); } void wxComboBox::SetInsertionPointEnd() { - // TODO + XmTextPosition pos = XmComboBoxGetLastPosition ((Widget) m_mainWidget); + XmComboBoxSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) (pos + 1)); } long wxComboBox::GetInsertionPoint() const { - // TODO - return 0; + return (long) XmComboBoxGetInsertionPosition ((Widget) m_mainWidget); } long wxComboBox::GetLastPosition() const { - // TODO - return 0; + return (long) XmComboBoxGetLastPosition ((Widget) m_mainWidget); } void wxComboBox::Replace(long from, long to, const wxString& value) { - // TODO + XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, + (char*) (const char*) value); } void wxComboBox::Remove(long from, long to) { - // TODO + XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, + (Time) 0); + XmComboBoxRemove ((Widget) m_mainWidget); } void wxComboBox::SetSelection(long from, long to) { - // TODO + XmComboBoxSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, + (Time) 0); +} + +void wxComboBoxCallback (Widget w, XtPointer clientData, + XmComboBoxSelectionCallbackStruct * cbs) +{ + wxComboBox *item = (wxComboBox *) clientData; + + switch (cbs->reason) + { + case XmCR_SINGLE_SELECT: + case XmCR_BROWSE_SELECT: + { + wxCommandEvent event (wxEVT_COMMAND_COMBOBOX_SELECTED, item->GetId()); + event.m_commandInt = cbs->index - 1; + // event.m_commandString = item->GetString (event.m_commandInt); + event.m_extraLong = TRUE; + event.SetEventObject(item); + item->ProcessCommand (event); + break; + } + case XmCR_VALUE_CHANGED: + { + wxCommandEvent event (wxEVT_COMMAND_TEXT_UPDATED, item->GetId()); + event.m_commandInt = -1; + // event.m_commandString = item->GetValue(); + event.m_extraLong = TRUE; + event.SetEventObject(item); + item->ProcessCommand (event); + break; + } + default: + break; + } } +#endif + diff --git a/src/motif/dcscreen.cpp b/src/motif/dcscreen.cpp index 7a08281638..050acdcd5e 100644 --- a/src/motif/dcscreen.cpp +++ b/src/motif/dcscreen.cpp @@ -14,36 +14,112 @@ #endif #include "wx/dcscreen.h" +#include "wx/utils.h" + +#include + +#include #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC) #endif +WXWindow wxScreenDC::sm_overlayWindow = 0; +int wxScreenDC::sm_overlayWindowX = 0; +int wxScreenDC::sm_overlayWindowY = 0; + // Create a DC representing the whole screen wxScreenDC::wxScreenDC() { - // TODO + m_display = wxGetDisplay(); + Display* display = (Display*) m_display; + + if (sm_overlayWindow) + { + m_pixmap = sm_overlayWindow; + m_deviceOriginX = - sm_overlayWindowX; + m_deviceOriginY = - sm_overlayWindowY; + } + else + m_pixmap = (WXPixmap) RootWindow(display, DefaultScreen(display)); + + XGCValues gcvalues; + gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); + gcvalues.background = WhitePixel (display, DefaultScreen (display)); + gcvalues.graphics_exposures = False; + gcvalues.line_width = 1; + m_gc = XCreateGC (display, RootWindow (display, DefaultScreen (display)), + GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth, + &gcvalues); + + m_backgroundPixel = (int) gcvalues.background; + m_ok = TRUE; } wxScreenDC::~wxScreenDC() { - // TODO } bool wxScreenDC::StartDrawingOnTop(wxWindow* window) { - // TODO - return FALSE; + wxRect rect; + int x, y, width, height; + window->GetPosition(& x, & y); + window->ClientToScreen(& x, & y); + window->GetSize(& width, & height); + rect.x = x; rect.y = y; + rect.width = width; rect.height = height; + + return StartDrawingOnTop(& rect); } bool wxScreenDC::StartDrawingOnTop(wxRect* rect = NULL) { - // TODO + if (sm_overlayWindow) + return FALSE; + + Display *dpy = (Display*) wxGetDisplay(); + Pixmap screenPixmap = RootWindow(dpy, DefaultScreen(dpy)); + + int x = 0; + int y = 0; + int width, height; + wxDisplaySize(&width, &height); + + if (rect) + { + x = rect->x; y = rect->y; + width = rect->width; height = rect->height; + } + sm_overlayWindowX = x; + sm_overlayWindowY = y; + + XSetWindowAttributes attributes; + attributes.override_redirect = True; + unsigned long valueMask = CWOverrideRedirect; + + sm_overlayWindow = (WXWindow) XCreateWindow(dpy, screenPixmap, x, y, width, height, 0, + wxDisplayDepth(), InputOutput, + DefaultVisual(dpy, 0), valueMask, + & attributes); + + if (sm_overlayWindow) + { + XMapWindow(dpy, (Window) sm_overlayWindow); + return TRUE; + } + else return FALSE; } bool wxScreenDC::EndDrawingOnTop() { - // TODO + if (sm_overlayWindow) + { + XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow); + sm_overlayWindow = 0; return TRUE; + } + else + return FALSE; } diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index e83b831ebc..c3222764ab 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -342,14 +342,12 @@ void wxFrame::GetClientSize(int *x, int *y) const Dimension xx, yy; XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL); - /* TODO - if (status_line_exists) + if (m_frameStatusBar) { - Dimension ys; - XtVaGetValues(statusLineWidget, XmNheight, &ys, NULL); - yy -= ys; + int sbw, sbh; + m_frameStatusBar->GetSize(& sbw, & sbh); + yy -= sbh; } - */ if (GetMenuBar() != (wxMenuBar*) NULL) { @@ -589,7 +587,7 @@ void wxFrame::PositionStatusBar() // Since we wish the status bar to be directly under the client area, // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. - m_frameStatusBar->SetSize(0-sh, h, w, sh); + m_frameStatusBar->SetSize(0, h, w, sh); } WXWidget wxFrame::GetMenuBarWidget() const diff --git a/src/motif/gauge.cpp b/src/motif/gauge.cpp index d756fc4946..e80910d276 100644 --- a/src/motif/gauge.cpp +++ b/src/motif/gauge.cpp @@ -15,10 +15,64 @@ #include "wx/gauge.h" +#include +#include + #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) #endif +// XmGauge copyright notice: + +/* + * Copyright 1994 GROUPE BULL + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of GROUPE BULL not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. GROUPE BULL makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * GROUPE BULL disclaims all warranties with regard to this software, + * including all implied warranties of merchantability and fitness, + * in no event shall GROUPE BULL be liable for any special, + * indirect or consequential damages or any damages + * whatsoever resulting from loss of use, data or profits, + * whether in an action of contract, negligence or other tortious + * action, arising out of or in connection with the use + * or performance of this software. + * + */ + +//// PUBLIC XMGAUGE DECLARATIONS +typedef struct _XmGaugeClassRec* XmGaugeWidgetClass; +typedef struct _XmGaugeRec* XmGaugeWidget; + +#ifdef __cplusplus +extern "C" WidgetClass xmGaugeWidgetClass; +#else +extern WidgetClass xmGaugeWidgetClass; +#endif + +typedef struct _XmGaugeCallbackStruct{ + int reason; + XEvent *event; + int value; +} XmGaugeCallbackStruct; + + +void +XmGaugeSetValue(Widget w, int value); + +int +XmGaugeGetValue(Widget w); + + + bool wxGauge::Create(wxWindow *parent, wxWindowID id, int range, const wxPoint& pos, @@ -39,57 +93,667 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, else m_windowId = id; + Widget parentWidget = (Widget) parent->GetClientWidget(); + + Arg args[4]; + int count = 4; + if (style & wxHORIZONTAL) + { + XtSetArg (args[0], XmNorientation, XmHORIZONTAL); + XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_RIGHT); + } + else + { + XtSetArg (args[0], XmNorientation, XmVERTICAL); + XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_TOP); + } + XtSetArg(args[2], XmNminimum, 0); + XtSetArg(args[3], XmNmaximum, range); + Widget gaugeWidget = XtCreateManagedWidget("gauge", xmGaugeWidgetClass, parentWidget, args, count); + m_mainWidget = (WXWidget) gaugeWidget ; + + XtManageChild (gaugeWidget); - // TODO - return FALSE; + int x = pos.x; int y = pos.y; + int width = size.x; int height = size.y; + if (width == -1) + width = 150; + if (height == -1) + height = 80; + + SetCanAddEventHandler(TRUE); + AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height); + + SetFont(* parent->GetFont()); + ChangeColour(m_mainWidget); + + return TRUE; } void wxGauge::SetSize(int x, int y, int width, int height, int sizeFlags) { - // TODO + wxControl::SetSize(x, y, width, height, sizeFlags); } void wxGauge::SetShadowWidth(int w) { - // TODO optional + if (w == 0) + w = 1; + XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL); } void wxGauge::SetBezelFace(int w) { - // TODO optional } void wxGauge::SetRange(int r) { m_rangeMax = r; - // TODO + XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL); } void wxGauge::SetValue(int pos) { m_gaugePos = pos; - // TODO + XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL); } int wxGauge::GetShadowWidth() const { - // TODO optional - return 0; + Dimension w; + XtVaGetValues((Widget) m_mainWidget, XmNshadowThickness, &w, NULL); + return (int)w; } int wxGauge::GetBezelFace() const { - // TODO optional return 0; } int wxGauge::GetRange() const { - return m_rangeMax; + int r; + XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL); + return (int)r; +// return m_rangeMax; } int wxGauge::GetValue() const { - return m_gaugePos; + int pos; + XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL); + return pos; +// return m_gaugePos; +} + +//// PRIVATE DECLARATIONS FOR XMGAUGE + +#include +#include + +typedef struct { + int empty; +} XmGaugeClassPart; + +typedef struct _XmGaugeClassRec { + CoreClassPart core_class; + XmPrimitiveClassPart primitive_class; + XmGaugeClassPart gauge_class; +} XmGaugeClassRec; + + +typedef struct _XmGaugePart{ + int value; + int minimum; + int maximum; + unsigned char orientation; + unsigned char processingDirection; + + XtCallbackList dragCallback; + XtCallbackList valueChangedCallback; + + /* private fields */ + Boolean dragging; /* drag in progress ? */ + int oldx, oldy; + GC gc; +} XmGaugePart; + + +typedef struct _XmGaugeRec { + CorePart core; + XmPrimitivePart primitive; + XmGaugePart gauge; +} XmGaugeRec; + +extern XmGaugeClassRec xmGaugeClassRec; + +/* Copyright 1994 GROUPE BULL -- See license conditions in file COPYRIGHT */ + +//// XMGAUGE IMPLEMENTATION + +void +GaugePick(Widget w, XEvent *e, String *args, Cardinal *num_args); +void +GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args); +void +GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args); + + + +static char translations[] = +": GaugePick()\n\ + : GaugeDrag()\n\ + : GaugeDrop()\n\ +"; + + + +static XtActionsRec actions[] = { + {"GaugePick", GaugePick}, + {"GaugeDrag", GaugeDrag}, + {"GaugeDrop", GaugeDrop}, +}; + +static void +DrawSlider(XmGaugeWidget gw, Boolean clear) +{ +#define THIS gw->gauge + int size, sht; + float ratio; +/***chubraev + char string[20]; + int len; + unsigned long backgr,foregr; + XRectangle rects[1]; +***/ + + sht = gw->primitive.shadow_thickness; + + ratio = (float)THIS.value/ + (float)(THIS.maximum - THIS.minimum); +/***chubraev + sprintf(string,"%-d%%",(int)(ratio*100)); + len=strlen(string); + XtVaGetValues(gw,XmNbackground,&backgr,XmNforeground,&foregr,NULL); +***/ + + if(clear) { + XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht, + gw->core.width - 2 * sht, gw->core.height - 2 * sht, False); + } + switch(THIS.orientation) { + case XmHORIZONTAL: + size = (int) ((gw->core.width - 2 * sht)*ratio); + /***chubraev + XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2, +gw->core.height - 2 * sht, string, len); + ***/ + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, sht, size, gw->core.height - 2 * sht); + + /***chubraev + rects[0].x = sht; rects[0].y = sht; + rects[0].width = size; rects[0].height = gw->core.height - 2 * sht; + ***/ + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + gw->core.width - size - sht, sht, + size, gw->core.height - 2 * sht); + + /***chubraev + rects[0].x = gw->core.width - size - sht; rects[0].y = sht; + rects[0].width = size; rects[0].height = gw->core.height - 2 * sht; + ***/ + break; + } + /***chubraev + XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted); + XSetForeground(XtDisplay(gw), THIS.gc, backgr); + XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht+gw->core.width/2, +gw->core.height - 2 * sht, string, len); + ***/ + + break; + case XmVERTICAL: + size = (int) ((gw->core.height - 2 * sht)*ratio); + /***chubraev + XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht, +sht+gw->core.height/2, string,len); + ***/ + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, sht, gw->core.width - 2 * sht, size); + + /***chubraev + rects[0].x = sht; rects[0].y = sht; + rects[0].width = gw->core.width - 2 * sht; rects[0].height = size; + ***/ + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, gw->core.height - size - sht, + gw->core.width - 2 * sht, size); + + /***chubraev + rects[0].x = sht; rects[0].y = gw->core.height - size - sht; + rects[0].width = gw->core.width - 2 * sht; rects[0].height = size; + ***/ + } + /***chubraev + XSetClipRectangles(XtDisplay(gw), THIS.gc, 0, 0, rects, 1, Unsorted); + XSetForeground(XtDisplay(gw), THIS.gc, backgr); + XDrawString(XtDisplay(gw), XtWindow(gw), THIS.gc, sht, +sht+gw->core.height/2, string,len); + ***/ + break; + } + /***chubraev + XSetClipMask(XtDisplay(gw), THIS.gc, None); + XSetForeground(XtDisplay(gw), THIS.gc, foregr); + ***/ +#undef THIS +} + +/* Old code + */ +#if 0 +static void +DrawSlider(XmGaugeWidget gw, Boolean clear) +{ +#define THIS gw->gauge + int size, sht; +/* float ratio; */ + + sht = gw->primitive.shadow_thickness; +/* See fix comment below: can cause divide by zero error. + ratio = (float)((float)THIS.maximum - + (float)THIS.minimum) / (float)THIS.value; +*/ + if(clear) { + XClearArea(XtDisplay(gw), XtWindow(gw), sht, sht, + gw->core.width - 2 * sht, gw->core.height - 2 * sht, False); + } + switch(THIS.orientation) { + case XmHORIZONTAL: +/* size = (gw->core.width - 2 * sht) / ratio; */ +/* A fix suggested by Dmitri Chubraev */ + size = (gw->core.width - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value; + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, sht, size, gw->core.height - 2 * sht); + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + gw->core.width - size - sht, sht, + size, gw->core.height - 2 * sht); + break; + } + break; + case XmVERTICAL: + size = (gw->core.height - 2 * sht) /((float)THIS.maximum-(float)THIS.minimum)*(float)THIS.value; +/* size = (gw->core.height - 2 * sht)/ ratio; */ + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, sht, gw->core.width - 2 * sht, size); + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + XFillRectangle(XtDisplay(gw), XtWindow(gw), THIS.gc, + sht, gw->core.height - size - sht, + gw->core.width - 2 * sht, size); + } + break; + } +#undef THIS +} +#endif + +static void +Initialize(Widget req, Widget new_w, ArgList args, Cardinal *num_args ) +{ + XmGaugeWidget gw = (XmGaugeWidget)new_w; +#define THIS gw->gauge + XGCValues values; + + values.foreground = gw->primitive.foreground; + THIS.gc = XtGetGC(new_w, GCForeground, &values); + +#undef THIS + +} + + + +static void +Destroy(Widget w) +{ + XmGaugeWidget gw = (XmGaugeWidget)w; +#define THIS gw->gauge + XtReleaseGC(w, THIS.gc); +#undef THIS +} + + + + +static Boolean +SetValues( + Widget cw, + Widget rw, + Widget nw, + ArgList args, + Cardinal *num_args ) +{ + XmGaugeWidget cgw = (XmGaugeWidget)cw; + XmGaugeWidget ngw = (XmGaugeWidget)nw; + + Boolean redraw = False; + if(cgw->primitive.foreground != ngw->primitive.foreground) { + XGCValues values; + + redraw = True; + XtReleaseGC(nw, ngw->gauge.gc); + values.foreground = ngw->primitive.foreground; + ngw->gauge.gc = XtGetGC(nw, GCForeground, &values); + } + if(cgw->gauge.value != ngw->gauge.value) { + redraw = True; + } + return redraw; +} + + + + +static void +ExposeProc(Widget w, XEvent *event, Region r) +{ + XmGaugeWidget gw = (XmGaugeWidget)w; +#define THIS gw->gauge + int sht; + + sht = gw->primitive.shadow_thickness; + _XmDrawShadows(XtDisplay(w), XtWindow(w), + gw->primitive.top_shadow_GC, + gw->primitive.bottom_shadow_GC, + 0, 0, w->core.width, w->core.height, + sht, XmSHADOW_IN); + DrawSlider(gw, False); +#undef THIS +} + + + + + +static XtResource +resources[] = { +#define offset(field) XtOffset(XmGaugeWidget, gauge.field) + {XmNvalue, XmCValue, XtRInt, sizeof(int), + offset(value), XtRImmediate, (caddr_t)10}, + + {XmNminimum, XmCValue, XtRInt, sizeof(int), + offset(minimum), XtRImmediate, (caddr_t)0}, + + {XmNmaximum, XmCValue, XtRInt, sizeof(int), + offset(maximum), XtRImmediate, (caddr_t)100}, + + {XmNorientation, XmCOrientation, XmROrientation, sizeof(unsigned char), + offset(orientation), XtRImmediate, (caddr_t)XmVERTICAL}, + + {XmNprocessingDirection, XmCProcessingDirection, + XmRProcessingDirection, sizeof(unsigned char), + offset(processingDirection), XtRImmediate, (caddr_t)XmMAX_ON_RIGHT}, + + {XmNdragCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), + offset(dragCallback), XtRImmediate, (caddr_t)NULL}, + + {XmNvalueChangedCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList), + offset(valueChangedCallback), XtRImmediate, (caddr_t)NULL}, + + +#undef offset +}; + + +XmGaugeClassRec xmGaugeClassRec = { + { /* core fields */ + (WidgetClass) &xmPrimitiveClassRec, /* superclass */ + "XmGauge", /* class_name */ + sizeof(XmGaugeRec), /* widget_size */ + NULL, /* class_initialize */ + NULL, /* class_part_initialize */ + FALSE, /* class_inited */ + Initialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + TRUE, /* compress_motion */ + TRUE, /* compress_exposure */ + TRUE, /* compress_enterleave */ + FALSE, /* visible_interest */ + Destroy, /* destroy */ + NULL, /* resize */ + ExposeProc, /* expose */ + SetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + translations, /* tm_table */ + NULL, /* query_geometry */ + NULL, /* display_accelerator */ + NULL /* extension */ + }, + /* primitive_class fields */ + { + NULL, /* border_highlight */ + NULL, /* border_unhighlight */ + NULL, /* translations */ + NULL, /* arm_and_activate */ + NULL, /* syn_resources */ + 0, /* num_syn_resources */ + NULL /* extension */ + }, + { /* gauge fields */ + 0 /* empty */ + } +}; + +WidgetClass xmGaugeWidgetClass = (WidgetClass)&xmGaugeClassRec; + + + + +void +GaugePick(Widget w, XEvent *e, String *args, Cardinal *num_args) +{ +/* Commented out for a read-only gauge in wxWindows */ +#if 0 + XmGaugeWidget gw = (XmGaugeWidget)w; +#define THIS gw->gauge + int size, sht; + float ratio; + Boolean dragging = False; + XButtonEvent *event = (XButtonEvent *)e; + int x, y; + + x = event->x; + y = event->y; + sht = gw->primitive.shadow_thickness; + _XmDrawShadows(XtDisplay(w), XtWindow(w), + gw->primitive.top_shadow_GC, + gw->primitive.bottom_shadow_GC, + 0, 0, w->core.width, w->core.height, + sht, XmSHADOW_IN); + + + ratio = (float)((float)THIS.maximum - + (float)THIS.minimum) / (float)THIS.value; + switch(THIS.orientation) { + case XmHORIZONTAL: + size = (w->core.width - 2 * sht) / ratio; + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + dragging = (x > sht) && (y > sht) && + (x < sht + size) && (y < w->core.height - sht); + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + dragging = (x > w->core.width - size - sht) && (y > sht) && + (x < w->core.width - sht) && (y < w->core.height + sht); + break; + } + break; + case XmVERTICAL: + size = (w->core.height - 2 * sht) / ratio; + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + dragging = (x > sht) && (y > sht) && + (x < w->core.width - sht) && + (y < w->core.width - 2 * sht + size); + break; + case XmMAX_ON_LEFT: + case XmMAX_ON_TOP: + dragging = (x > sht) && (y > w->core.height - size - sht) && + (x < w->core.width - sht) && (y < w->core.height - sht); + } + break; + } + THIS.dragging = dragging; + THIS.oldx = x; + THIS.oldy = y; +#undef THIS +#endif } +#define round(x) ( (x) > 0 ? ((x) + 0.5) : -(-(x) + 0.5) ) + +void +GaugeDrag(Widget w, XEvent *e, String *args, Cardinal *num_args) +{ +/* Commented out for a read-only gauge in wxWindows */ +#if 0 + XmGaugeWidget gw = (XmGaugeWidget)w; +#define THIS gw->gauge + int sht, x, y, max, value; + float ratio, nratio, size, nsize, fvalue, delta; + XMotionEvent *event = (XMotionEvent *)e; + + if( ! THIS.dragging) return; + + x = event->x; + y = event->y; + sht = gw->primitive.shadow_thickness; + + ratio = (float)THIS.value / (float)((float)THIS.maximum - + (float)THIS.minimum); + switch(THIS.orientation) { + case XmHORIZONTAL: + max = (w->core.width - 2 * sht); + size = (float)max * ratio; + delta = (float)x - (float)THIS.oldx; + break; + case XmVERTICAL: + max = (w->core.height - 2 * sht); + size = (float) max * ratio; + delta = (float)y - (float)THIS.oldy; + break; + } + switch(THIS.processingDirection) { + case XmMAX_ON_RIGHT: + case XmMAX_ON_BOTTOM: + nsize = size + delta; + break; + default: + nsize = size - delta; + } + if(nsize > (float)max) nsize = (float)max; + if(nsize < (float)0 ) nsize = (float)0; + nratio = nsize / (float)max; + + fvalue = (int)((float)THIS.maximum - + (float)THIS.minimum) * (float)nsize / (float)max; + value = round(fvalue); + + THIS.value = value; + THIS.oldx = x; + THIS.oldy = y; + + /* clear old slider only if it was larger */ + DrawSlider(gw, (nsize < size)); + + { + XmGaugeCallbackStruct call; + + if(NULL != THIS.dragCallback) { + call.reason = XmCR_DRAG; + call.event = e; + call.value = THIS.value; + XtCallCallbacks(w, XmNdragCallback, &call); + } + } +#undef THIS +#endif +} + + +void +GaugeDrop(Widget w, XEvent *e, String *args, Cardinal *num_args) +{ +/* Commented out for a read-only gauge in wxWindows */ +#if 0 + XmGaugeWidget gw = (XmGaugeWidget)w; +#define THIS gw->gauge + if( ! THIS.dragging) return; + + if(NULL != THIS.valueChangedCallback) { + XmGaugeCallbackStruct call; + call.reason = XmCR_VALUE_CHANGED; + call.event = e; + call.value = THIS.value; + XtCallCallbacks(w, XmNvalueChangedCallback, &call); + } + THIS.dragging = False; +#undef THIS +#endif +} + +void +XmGaugeSetValue(Widget w, int value) +{ + XmGaugeWidget gw = (XmGaugeWidget)w; + + gw->gauge.value = value; + DrawSlider(gw, True); + XFlush(XtDisplay(w)); +} + +int +XmGaugeGetValue(Widget w) +{ + XmGaugeWidget gw = (XmGaugeWidget)w; + + return gw->gauge.value; +} diff --git a/src/motif/listbox.cpp b/src/motif/listbox.cpp index 2dffe82cb1..7425164595 100644 --- a/src/motif/listbox.cpp +++ b/src/motif/listbox.cpp @@ -514,6 +514,13 @@ void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags) // Check resulting size is correct int tempW, tempH; GetSize (&tempW, &tempH); + + /* + if (tempW != width || tempH != height) + { + cout << "wxListBox::SetSize sizes not set correctly."); + } + */ } void wxListBox::InsertItems(int nItems, const wxString items[], int pos) @@ -726,4 +733,7 @@ void wxListBoxDefaultActionProc (Widget list_w, XtPointer client_data, XmListCal lbox->GetEventHandler()->ProcessEvent(event) ; } - +WXWidget wxListBox::GetTopWidget() const +{ + return (WXWidget) XtParent( (Widget) m_mainWidget ); +} diff --git a/src/motif/makefile.unx b/src/motif/makefile.unx index d447de4949..89c66ecb6b 100644 --- a/src/motif/makefile.unx +++ b/src/motif/makefile.unx @@ -164,11 +164,14 @@ LIB_C_SRC=\ ../common/y_tab.c \ ../common/extended.c +EXTRA_C_SRC=\ + combobox/combobox.c + all: $(WXLIB) # Define library objects OBJECTS=\ - $(LIB_CPP_SRC:.cpp=.o) $(LIB_C_SRC:.c=.o) + $(LIB_CPP_SRC:.cpp=.o) $(LIB_C_SRC:.c=.o) $(EXTRA_C_SRC:.c=.o) $(WXLIB) : $(OBJECTS) ar $(AROPTIONS) $@ $(OBJECTS) @@ -193,6 +196,8 @@ $(WXLIB) : $(OBJECTS) $(YACC) ../common/parser.y mv y.tab.c ../common/y_tab.c +combobox/combobox.o: combobox/combobox.c + $(CCC) -c $(CFLAGS) -o $@ combobox/combobox.c clean: rm -f $(OBJECTS) $(WXLIB) diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 2aaf9006d6..b17a7515ba 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -1267,6 +1267,9 @@ void wxWindow::SetFont(const wxFont& font) { m_windowFont = font; + // Note that this causes the widget to be resized back + // to its original size! How can we stop that? + /* Widget w = (Widget) GetLabelWidget(); // Usually the main widget if (w && m_windowFont.Ok()) { @@ -1274,6 +1277,7 @@ void wxWindow::SetFont(const wxFont& font) XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)), NULL); } + */ } void wxWindow::OnChar(wxKeyEvent& event) @@ -3049,6 +3053,7 @@ void wxWindow::ChangeColour(WXWidget widget) void wxWindow::ChangeFont(WXWidget widget) { + /* if (widget && GetFont() && GetFont()->Ok()) { XmFontList fontList = (XmFontList) GetFont()->GetFontList(1.0, GetXDisplay()); @@ -3057,4 +3062,5 @@ void wxWindow::ChangeFont(WXWidget widget) XmNfontList, fontList, NULL); } + */ }