Do not derive wxCursor from wxBitmap, plus misc cleanup.

Derive wxGauge from wxGaugeBase, use XmScale for the
implementation if the Motif version supports the
XmTHERMOMETER style.
  Derive wxSlider from wxSliderBase; generate
wxEVT_SCROLL_THUMBRELEASE in addition to wxEVT_SCROLL_THUMBTRACK;
misc cleanup.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-03-22 15:46:22 +00:00
parent 13de23f6d8
commit 93e73c740e
6 changed files with 187 additions and 450 deletions

View File

@@ -16,38 +16,13 @@
#pragma interface "cursor.h" #pragma interface "cursor.h"
#endif #endif
#include "wx/bitmap.h" #include "wx/object.h"
#include "wx/list.h" #include "wx/gdicmn.h"
/* Cursor for one display, so we can choose the correct one for class WXDLLEXPORT wxImage;
* the current display.
*/
class wxXCursor : public wxObject
{
DECLARE_DYNAMIC_CLASS(wxXCursor)
public:
WXDisplay* m_display;
WXCursor m_cursor;
};
class WXDLLEXPORT wxCursorRefData: public wxBitmapRefData
{
friend class WXDLLEXPORT wxBitmap;
friend class WXDLLEXPORT wxCursor;
public:
wxCursorRefData();
~wxCursorRefData();
wxList m_cursors; // wxXCursor objects, one per display
wxStockCursor m_cursorId; // wxWindows standard cursor id
};
#define M_CURSORDATA ((wxCursorRefData *)m_refData)
#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData)
// Cursor // Cursor
class WXDLLEXPORT wxCursor: public wxBitmap class WXDLLEXPORT wxCursor: public wxObject
{ {
DECLARE_DYNAMIC_CLASS(wxCursor) DECLARE_DYNAMIC_CLASS(wxCursor)
@@ -70,15 +45,19 @@ public:
wxCursor(wxStockCursor id); wxCursor(wxStockCursor id);
~wxCursor(); ~wxCursor();
virtual bool Ok() const { return ((m_refData != NULL) && M_CURSORDATA->m_ok); } virtual bool Ok() const;
wxCursor& operator = (const wxCursor& cursor) { if (*this == cursor) return (*this); Ref(cursor); return *this; } wxCursor& operator = (const wxCursor& cursor)
bool operator == (const wxCursor& cursor) const { return m_refData == cursor.m_refData; } { if (*this == cursor) return (*this); Ref(cursor); return *this; }
bool operator != (const wxCursor& cursor) const { return m_refData != cursor.m_refData; } bool operator == (const wxCursor& cursor) const
{ return m_refData == cursor.m_refData; }
bool operator != (const wxCursor& cursor) const
{ return m_refData != cursor.m_refData; }
// Motif-specific. // Motif-specific.
// Create/get a cursor for the current display // Create/get a cursor for the current display
WXCursor GetXCursor(WXDisplay* display) ; WXCursor GetXCursor(WXDisplay* display) ;
private:
// Make a cursor from standard id // Make a cursor from standard id
WXCursor MakeCursor(WXDisplay* display, wxStockCursor id); WXCursor MakeCursor(WXDisplay* display, wxStockCursor id);
}; };

View File

@@ -16,12 +16,10 @@
#pragma interface "gauge.h" #pragma interface "gauge.h"
#endif #endif
#include "wx/control.h"
WXDLLEXPORT_DATA(extern const char*) wxGaugeNameStr; WXDLLEXPORT_DATA(extern const char*) wxGaugeNameStr;
// Group box // Group box
class WXDLLEXPORT wxGauge : public wxControl class WXDLLEXPORT wxGauge : public wxGaugeBase
{ {
DECLARE_DYNAMIC_CLASS(wxGauge) DECLARE_DYNAMIC_CLASS(wxGauge)
@@ -48,25 +46,18 @@ public:
const wxString& name = wxGaugeNameStr); const wxString& name = wxGaugeNameStr);
void SetShadowWidth(int w); void SetShadowWidth(int w);
void SetBezelFace(int w);
void SetRange(int r); void SetRange(int r);
void SetValue(int pos); void SetValue(int pos);
int GetShadowWidth() const ; int GetShadowWidth() const ;
int GetBezelFace() const ;
int GetRange() const ; int GetRange() const ;
int GetValue() const ; int GetValue() const ;
virtual void Command(wxCommandEvent& WXUNUSED(event)) {} ; virtual void Command(wxCommandEvent& WXUNUSED(event)) {} ;
// Implementation private:
virtual void ChangeFont(bool keepOriginalSize = TRUE); virtual wxSize DoGetBestSize() const;
virtual void ChangeBackgroundColour(); virtual void DoMoveWindow(int x, int y, int width, int height);
virtual void ChangeForegroundColour();
protected:
int m_rangeMax;
int m_gaugePos;
}; };
#endif #endif

View File

@@ -21,7 +21,7 @@
WXDLLEXPORT_DATA(extern const char*) wxSliderNameStr; WXDLLEXPORT_DATA(extern const char*) wxSliderNameStr;
// Slider // Slider
class WXDLLEXPORT wxSlider: public wxControl class WXDLLEXPORT wxSlider: public wxSliderBase
{ {
DECLARE_DYNAMIC_CLASS(wxSlider) DECLARE_DYNAMIC_CLASS(wxSlider)
@@ -52,42 +52,26 @@ public:
virtual int GetValue() const ; virtual int GetValue() const ;
virtual void SetValue(int); virtual void SetValue(int);
void GetSize(int *x, int *y) const ;
void SetRange(int minValue, int maxValue); void SetRange(int minValue, int maxValue);
inline int GetMin() const { return m_rangeMin; } inline int GetMin() const { return m_rangeMin; }
inline int GetMax() const { return m_rangeMax; } inline int GetMax() const { return m_rangeMax; }
// For trackbars only // For trackbars only
void SetTickFreq(int n, int pos);
inline int GetTickFreq() const { return m_tickFreq; }
void SetPageSize(int pageSize); void SetPageSize(int pageSize);
int GetPageSize() const ; int GetPageSize() const ;
void ClearSel() ;
void ClearTicks() ;
void SetLineSize(int lineSize); void SetLineSize(int lineSize);
int GetLineSize() const ; int GetLineSize() const ;
int GetSelEnd() const ;
int GetSelStart() const ;
void SetSelection(int minPos, int maxPos);
void SetThumbLength(int len) ; void SetThumbLength(int len) ;
int GetThumbLength() const ; int GetThumbLength() const ;
void SetTick(int tickPos) ;
void Command(wxCommandEvent& event); void Command(wxCommandEvent& event);
// Implementation
virtual void ChangeFont(bool keepOriginalSize = TRUE);
virtual void ChangeBackgroundColour();
virtual void ChangeForegroundColour();
protected: protected:
int m_rangeMin; int m_rangeMin;
int m_rangeMax; int m_rangeMax;
int m_pageSize; int m_pageSize;
int m_lineSize; int m_lineSize;
int m_tickFreq;
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,

View File

@@ -14,10 +14,9 @@
#endif #endif
#include "wx/cursor.h" #include "wx/cursor.h"
#include "wx/gdicmn.h"
#include "wx/icon.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/list.h"
#if wxUSE_IMAGE #if wxUSE_IMAGE
#include "wx/image.h" #include "wx/image.h"
#endif #endif
@@ -33,23 +32,47 @@
#include "wx/motif/private.h" #include "wx/motif/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) // Cursor for one display, so we can choose the correct one for
IMPLEMENT_DYNAMIC_CLASS(wxXCursor, wxObject) // the current display.
class wxXCursor
{
public:
WXDisplay* m_display;
WXCursor m_cursor;
};
WX_DECLARE_LIST(wxXCursor, wxXCursorList);
#include "wx/listimpl.cpp"
WX_DEFINE_LIST(wxXCursorList);
class WXDLLEXPORT wxCursorRefData: public wxObjectRefData
{
friend class WXDLLEXPORT wxCursor;
public:
wxCursorRefData();
~wxCursorRefData();
wxXCursorList m_cursors; // wxXCursor objects, one per display
wxStockCursor m_cursorId; // wxWindows standard cursor id
};
#define M_CURSORDATA ((wxCursorRefData *)m_refData)
#define M_CURSORHANDLERDATA ((wxCursorRefData *)bitmap->m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxObject)
wxCursorRefData::wxCursorRefData() wxCursorRefData::wxCursorRefData()
{ {
m_width = 32; m_height = 32;
m_cursorId = wxCURSOR_NONE; m_cursorId = wxCURSOR_NONE;
} }
wxCursorRefData::~wxCursorRefData() wxCursorRefData::~wxCursorRefData()
{ {
wxList::Node* node = m_cursors.GetFirst(); wxXCursorList::Node* node = m_cursors.GetFirst();
while (node) while (node)
{ {
wxXCursor* c = (wxXCursor*) node->GetData(); wxXCursor* c = node->GetData();
// TODO: how to delete cursor? XFreeCursor((Display*) c->m_display, (Cursor) c->m_cursor);
// XDestroyCursor((Display*) c->m_display, (Cursor) c->m_cursor); // ??
delete c; delete c;
node = node->GetNext(); node = node->GetNext();
} }
@@ -89,7 +112,6 @@ wxCursor::wxCursor(const wxImage & image)
} }
} }
unsigned long keyMaskColor;
if (bHasMask) if (bHasMask)
{ {
unsigned char unsigned char
@@ -110,60 +132,13 @@ wxCursor::wxCursor(const wxImage & image)
cMask = cMask * 2; cMask = cMask * 2;
} }
} }
keyMaskColor = (r << 16) | (g << 8) | b;
} }
else // no mask else // no mask
{ {
for (i=0; i<imagebitcount; i++) for (i=0; i<imagebitcount; i++)
maskBits[i] = 0xFF; maskBits[i] = 0xFF;
// init it to avoid compiler warnings
keyMaskColor = 0;
}
/*
// find the most frequent color(s)
wxImageHistogram histogram;
image.ComputeHistogram(histogram);
// colors as rrggbb
unsigned long key;
unsigned long value;
long colMostFreq = 0;
unsigned long nMost = 0;
long colNextMostFreq = 0;
unsigned long nNext = 0;
for ( wxImageHistogram::iterator entry = histogram.begin();
entry != histogram.end();
++entry )
{
value = entry->second.value;
key = entry->first;
if ( !bHasMask || (key != keyMaskColor) )
{
if (value > nMost)
{
nMost = value;
colMostFreq = key;
}
else if (value > nNext)
{
nNext = value;
colNextMostFreq = key;
}
}
} }
wxColour fg = wxColour ( (unsigned char)(colMostFreq >> 16),
(unsigned char)(colMostFreq >> 8),
(unsigned char)(colMostFreq) );
wxColour bg = wxColour ( (unsigned char)(colNextMostFreq >> 16),
(unsigned char)(colNextMostFreq >> 8),
(unsigned char)(colNextMostFreq) );
end of color code
*/
int hotSpotX; int hotSpotX;
int hotSpotY; int hotSpotY;
@@ -230,13 +205,7 @@ end of color code
c->m_cursor = (WXCursor) cursor; c->m_cursor = (WXCursor) cursor;
c->m_display = (WXDisplay*) dpy; c->m_display = (WXDisplay*) dpy;
M_CURSORDATA->m_cursors.Append(c); M_CURSORDATA->m_cursors.Append(c);
M_CURSORDATA->m_ok = TRUE;
} }
else
{
M_CURSORDATA->m_ok = TRUE;
}
} }
#endif #endif
@@ -291,11 +260,6 @@ wxCursor::wxCursor(const char bits[], int width, int height,
c->m_cursor = (WXCursor) cursor; c->m_cursor = (WXCursor) cursor;
c->m_display = (WXDisplay*) dpy; c->m_display = (WXDisplay*) dpy;
M_CURSORDATA->m_cursors.Append(c); M_CURSORDATA->m_cursors.Append(c);
M_CURSORDATA->m_ok = TRUE;
}
else
{
M_CURSORDATA->m_ok = TRUE;
} }
} }
@@ -318,10 +282,6 @@ wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY)
wxConstCast(name.c_str(), char), wxConstCast(name.c_str(), char),
&w, &h, &pixmap, &hotX, &hotY); &w, &h, &pixmap, &hotX, &hotY);
M_BITMAPDATA->m_width = w;
M_BITMAPDATA->m_height = h;
M_BITMAPDATA->m_depth = 1;
if ((value == BitmapFileInvalid) || if ((value == BitmapFileInvalid) ||
(value == BitmapOpenFailed) || (value == BitmapOpenFailed) ||
(value == BitmapNoMemory)) (value == BitmapNoMemory))
@@ -366,7 +326,6 @@ wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY)
c->m_cursor = (WXCursor) cursor; c->m_cursor = (WXCursor) cursor;
c->m_display = (WXDisplay*) dpy; c->m_display = (WXDisplay*) dpy;
M_CURSORDATA->m_cursors.Append(c); M_CURSORDATA->m_cursors.Append(c);
M_CURSORDATA->m_ok = TRUE;
} }
} }
@@ -377,36 +336,32 @@ wxCursor::wxCursor(wxStockCursor id)
{ {
m_refData = new wxCursorRefData; m_refData = new wxCursorRefData;
M_CURSORDATA->m_cursorId = id; M_CURSORDATA->m_cursorId = id;
M_CURSORDATA->m_ok = TRUE;
WXDisplay* display = wxGetDisplay(); WXDisplay* display = wxGetDisplay();
if (!display) if (!display)
return; return;
WXCursor cursor = GetXCursor(display); WXCursor cursor = GetXCursor(display);
if (cursor)
{
wxXCursor* c = new wxXCursor;
c->m_cursor = cursor;
c->m_display = wxGetDisplay();
M_CURSORDATA->m_cursors.Append(c);
M_CURSORDATA->m_ok = TRUE;
}
} }
wxCursor::~wxCursor() wxCursor::~wxCursor()
{ {
} }
bool wxCursor::Ok() const
{
return m_refData != NULL;
}
// Motif-specific: create/get a cursor for the current display // Motif-specific: create/get a cursor for the current display
WXCursor wxCursor::GetXCursor(WXDisplay* display) WXCursor wxCursor::GetXCursor(WXDisplay* display)
{ {
if (!M_CURSORDATA) if (!M_CURSORDATA)
return (WXCursor) 0; return (WXCursor) 0;
wxList::Node* node = M_CURSORDATA->m_cursors.GetFirst(); wxXCursorList::Node* node = M_CURSORDATA->m_cursors.GetFirst();
while (node) while (node)
{ {
wxXCursor* c = (wxXCursor*) node->GetData(); wxXCursor* c = node->GetData();
if (c->m_display == display) if (c->m_display == display)
return c->m_cursor; return c->m_cursor;
node = node->GetNext(); node = node->GetNext();
@@ -438,149 +393,39 @@ WXCursor wxCursor::MakeCursor(WXDisplay* display, wxStockCursor id)
{ {
Display* dpy = (Display*) display; Display* dpy = (Display*) display;
Cursor cursor = (Cursor) 0; Cursor cursor = (Cursor) 0;
int x_cur = -1;
switch (id) switch (id)
{ {
case wxCURSOR_WAIT: case wxCURSOR_WAIT: x_cur = XC_watch; break;
{ case wxCURSOR_CROSS: x_cur = XC_crosshair; break;
cursor = XCreateFontCursor (dpy, XC_watch); case wxCURSOR_CHAR: return (WXCursor)cursor; break;
break; case wxCURSOR_HAND: x_cur = XC_hand1; break;
} case wxCURSOR_BULLSEYE: x_cur = XC_target; break;
case wxCURSOR_CROSS: case wxCURSOR_PENCIL: x_cur = XC_pencil; break;
{ case wxCURSOR_MAGNIFIER: x_cur = XC_sizing; break;
cursor = XCreateFontCursor (dpy, XC_crosshair); case wxCURSOR_IBEAM: x_cur = XC_xterm; break;
break; case wxCURSOR_NO_ENTRY: x_cur = XC_pirate; break;
} case wxCURSOR_LEFT_BUTTON: x_cur = XC_leftbutton; break;
case wxCURSOR_CHAR: case wxCURSOR_RIGHT_BUTTON: x_cur = XC_rightbutton; break;
{ case wxCURSOR_MIDDLE_BUTTON: x_cur = XC_middlebutton; break;
// Nothing case wxCURSOR_QUESTION_ARROW: x_cur = XC_question_arrow; break;
break; case wxCURSOR_SIZING: x_cur = XC_sizing; break;
} case wxCURSOR_WATCH: x_cur = XC_watch; break;
case wxCURSOR_HAND: case wxCURSOR_SPRAYCAN: x_cur = XC_spraycan; break;
{ case wxCURSOR_PAINT_BRUSH: x_cur = XC_spraycan; break;
cursor = XCreateFontCursor (dpy, XC_hand1);
break;
}
case wxCURSOR_BULLSEYE:
{
cursor = XCreateFontCursor (dpy, XC_target);
break;
}
case wxCURSOR_PENCIL:
{
cursor = XCreateFontCursor (dpy, XC_pencil);
break;
}
case wxCURSOR_MAGNIFIER:
{
cursor = XCreateFontCursor (dpy, XC_sizing);
break;
}
case wxCURSOR_IBEAM:
{
cursor = XCreateFontCursor (dpy, XC_xterm);
break;
}
case wxCURSOR_NO_ENTRY:
{
cursor = XCreateFontCursor (dpy, XC_pirate);
break;
}
case wxCURSOR_LEFT_BUTTON:
{
cursor = XCreateFontCursor (dpy, XC_leftbutton);
break;
}
case wxCURSOR_RIGHT_BUTTON:
{
cursor = XCreateFontCursor (dpy, XC_rightbutton);
break;
}
case wxCURSOR_MIDDLE_BUTTON:
{
cursor = XCreateFontCursor (dpy, XC_middlebutton);
break;
}
case wxCURSOR_QUESTION_ARROW:
{
cursor = XCreateFontCursor (dpy, XC_question_arrow);
break;
}
case wxCURSOR_SIZING:
{
cursor = XCreateFontCursor (dpy, XC_sizing);
break;
}
case wxCURSOR_WATCH:
{
cursor = XCreateFontCursor (dpy, XC_watch);
break;
}
case wxCURSOR_SPRAYCAN:
{
cursor = XCreateFontCursor (dpy, XC_spraycan);
break;
}
case wxCURSOR_PAINT_BRUSH:
{
cursor = XCreateFontCursor (dpy, XC_spraycan);
break;
}
case wxCURSOR_SIZENWSE: case wxCURSOR_SIZENWSE:
case wxCURSOR_SIZENESW: case wxCURSOR_SIZENESW: x_cur = XC_crosshair; break;
{ case wxCURSOR_SIZEWE: x_cur = XC_sb_h_double_arrow; break;
// Not available in X case wxCURSOR_SIZENS: x_cur = XC_sb_v_double_arrow; break;
cursor = XCreateFontCursor (dpy, XC_crosshair); case wxCURSOR_POINT_LEFT: x_cur = XC_sb_left_arrow; break;
break; case wxCURSOR_POINT_RIGHT: x_cur = XC_sb_right_arrow; break;
}
case wxCURSOR_SIZEWE:
{
cursor = XCreateFontCursor (dpy, XC_sb_h_double_arrow);
break;
}
case wxCURSOR_SIZENS:
{
cursor = XCreateFontCursor (dpy, XC_sb_v_double_arrow);
break;
}
case wxCURSOR_POINT_LEFT:
{
cursor = XCreateFontCursor (dpy, XC_sb_left_arrow);
break;
}
case wxCURSOR_POINT_RIGHT:
{
cursor = XCreateFontCursor (dpy, XC_sb_right_arrow);
break;
}
// (JD Huggins) added more stock cursors for X // (JD Huggins) added more stock cursors for X
// X-only cursors BEGIN // X-only cursors BEGIN
case wxCURSOR_CROSS_REVERSE: case wxCURSOR_CROSS_REVERSE: x_cur = XC_cross_reverse; break;
{ case wxCURSOR_DOUBLE_ARROW: x_cur = XC_double_arrow; break;
cursor = XCreateFontCursor(dpy, XC_cross_reverse); case wxCURSOR_BASED_ARROW_UP: x_cur = XC_based_arrow_up; break;
break; case wxCURSOR_BASED_ARROW_DOWN: x_cur = XC_based_arrow_down; break;
}
case wxCURSOR_DOUBLE_ARROW:
{
cursor = XCreateFontCursor(dpy, XC_double_arrow);
break;
}
case wxCURSOR_BASED_ARROW_UP:
{
cursor = XCreateFontCursor(dpy, XC_based_arrow_up);
break;
}
case wxCURSOR_BASED_ARROW_DOWN:
{
cursor = XCreateFontCursor(dpy, XC_based_arrow_down);
break;
}
default:
case wxCURSOR_ARROW:
{
cursor = XCreateFontCursor (dpy, XC_top_left_arrow);
break;
}
case wxCURSOR_BLANK: case wxCURSOR_BLANK:
{ {
GC gc; GC gc;
@@ -588,7 +433,8 @@ WXCursor wxCursor::MakeCursor(WXDisplay* display, wxStockCursor id)
Pixmap empty_pixmap; Pixmap empty_pixmap;
XColor blank_color; XColor blank_color;
empty_pixmap = XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)), empty_pixmap =
XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
16, 16, 1); 16, 16, 1);
gcv.function = GXxor; gcv.function = GXxor;
gc = XCreateGC (dpy, gc = XCreateGC (dpy,
@@ -612,7 +458,14 @@ WXCursor wxCursor::MakeCursor(WXDisplay* display, wxStockCursor id)
break; break;
} }
case wxCURSOR_ARROW:
default: x_cur = XC_top_left_arrow; break;
} }
if( x_cur == -1 )
return (WXCursor)cursor;
cursor = XCreateFontCursor (dpy, x_cur);
return (WXCursor) cursor; return (WXCursor) cursor;
} }

View File

@@ -23,6 +23,9 @@
#pragma message disable nosimpint #pragma message disable nosimpint
#endif #endif
#include <Xm/Xm.h> #include <Xm/Xm.h>
#ifdef __WXMOTIF20__
#include <Xm/Scale.h>
#endif // __WXMOTIF20__
#ifdef __VMS__ #ifdef __VMS__
#pragma message enable nosimpint #pragma message enable nosimpint
#endif #endif
@@ -30,6 +33,8 @@
IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
#if !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
// XmGauge copyright notice: // XmGauge copyright notice:
/* /*
@@ -79,7 +84,7 @@ XmGaugeSetValue(Widget w, int value);
int int
XmGaugeGetValue(Widget w); XmGaugeGetValue(Widget w);
#endif // !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
bool wxGauge::Create(wxWindow *parent, wxWindowID id, bool wxGauge::Create(wxWindow *parent, wxWindowID id,
int range, int range,
@@ -89,25 +94,14 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
SetName(name); if( !CreateControl( parent, id, pos, size, style, validator, name ) )
SetValidator(validator); return false;
m_rangeMax = range;
m_windowStyle = style;
m_backgroundColour = parent->GetBackgroundColour();
m_foregroundColour = parent->GetForegroundColour();
if (parent) parent->AddChild(this);
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Arg args[4]; Arg args[7];
int count = 4; int count = 4;
if (style & wxHORIZONTAL) if (style & wxGA_HORIZONTAL)
{ {
XtSetArg (args[0], XmNorientation, XmHORIZONTAL); XtSetArg (args[0], XmNorientation, XmHORIZONTAL);
XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_RIGHT); XtSetArg (args[1], XmNprocessingDirection, XmMAX_ON_RIGHT);
@@ -119,29 +113,46 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
} }
XtSetArg(args[2], XmNminimum, 0); XtSetArg(args[2], XmNminimum, 0);
XtSetArg(args[3], XmNmaximum, range); XtSetArg(args[3], XmNmaximum, range);
Widget gaugeWidget = XtCreateManagedWidget("gauge", xmGaugeWidgetClass, parentWidget, args, count); #if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
XtSetArg(args[4], XmNeditable, False); ++count;
XtSetArg(args[5], XmNslidingMode, XmTHERMOMETER); ++count;
// XtSetArg(args[6], XmNsliderVisual, XmFOREGROUND_COLOR ); ++count;
Widget gaugeWidget =
XtCreateManagedWidget("gauge", xmScaleWidgetClass,
parentWidget, args, count);
#else
Widget gaugeWidget =
XtCreateManagedWidget("gauge", xmGaugeWidgetClass,
parentWidget, args, count);
#endif
m_mainWidget = (WXWidget) gaugeWidget ; m_mainWidget = (WXWidget) gaugeWidget ;
XtManageChild (gaugeWidget); XtManageChild (gaugeWidget);
int x = pos.x; int y = pos.y; int x = pos.x; int y = pos.y;
int width = size.x; int height = size.y; wxSize best = GetBestSize();
if (width == -1) if( size.x != -1 ) best.x = size.x;
width = 150; if( size.y != -1 ) best.y = size.y;
if (height == -1)
height = 80;
m_font = parent->GetFont();
ChangeFont(FALSE); ChangeFont(FALSE);
SetCanAddEventHandler(TRUE); SetCanAddEventHandler(TRUE);
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y,
best.x, best.y);
ChangeBackgroundColour(); ChangeBackgroundColour();
return TRUE; return TRUE;
} }
wxSize wxGauge::DoGetBestSize() const
{
if( HasFlag(wxGA_HORIZONTAL) )
return wxSize( 100, 18 );
else
return wxSize( 18, 100 );
}
void wxGauge::SetShadowWidth(int w) void wxGauge::SetShadowWidth(int w)
{ {
if (w == 0) if (w == 0)
@@ -149,19 +160,13 @@ void wxGauge::SetShadowWidth(int w)
XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL); XtVaSetValues((Widget) m_mainWidget, XmNshadowThickness, w, NULL);
} }
void wxGauge::SetBezelFace(int WXUNUSED(w))
{
}
void wxGauge::SetRange(int r) void wxGauge::SetRange(int r)
{ {
m_rangeMax = r;
XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL); XtVaSetValues((Widget) m_mainWidget, XmNmaximum, r, NULL);
} }
void wxGauge::SetValue(int pos) void wxGauge::SetValue(int pos)
{ {
m_gaugePos = pos;
XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL); XtVaSetValues((Widget) m_mainWidget, XmNvalue, pos, NULL);
} }
@@ -172,17 +177,11 @@ int wxGauge::GetShadowWidth() const
return (int)w; return (int)w;
} }
int wxGauge::GetBezelFace() const
{
return 0;
}
int wxGauge::GetRange() const int wxGauge::GetRange() const
{ {
int r; int r;
XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL); XtVaGetValues((Widget) m_mainWidget, XmNmaximum, &r, NULL);
return (int)r; return (int)r;
// return m_rangeMax;
} }
int wxGauge::GetValue() const int wxGauge::GetValue() const
@@ -190,23 +189,19 @@ int wxGauge::GetValue() const
int pos; int pos;
XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL); XtVaGetValues((Widget) m_mainWidget, XmNvalue, &pos, NULL);
return pos; return pos;
// return m_gaugePos;
} }
void wxGauge::ChangeFont(bool keepOriginalSize) void wxGauge::DoMoveWindow(int x, int y, int width, int height)
{ {
wxWindow::ChangeFont(keepOriginalSize); wxGaugeBase::DoMoveWindow( x, y, width, height );
#ifdef __WXMOTIF20__
XtVaSetValues( (Widget)m_mainWidget,
XmNscaleHeight, height,
NULL );
#endif
} }
void wxGauge::ChangeBackgroundColour() #if !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()
{
wxWindow::ChangeBackgroundColour();
}
void wxGauge::ChangeForegroundColour()
{
wxWindow::ChangeForegroundColour();
}
//// PRIVATE DECLARATIONS FOR XMGAUGE //// PRIVATE DECLARATIONS FOR XMGAUGE
@@ -779,3 +774,5 @@ XmGaugeGetValue(Widget w)
return gw->gauge.value; return gw->gauge.value;
} }
#endif // !wxCHECK_MOTIF_VERSION( 2, 0 ) || wxCHECK_LESSTIF()

View File

@@ -46,7 +46,6 @@ wxSlider::wxSlider()
m_lineSize = 1; m_lineSize = 1;
m_rangeMax = 0; m_rangeMax = 0;
m_rangeMin = 0; m_rangeMin = 0;
m_tickFreq = 0;
} }
bool wxSlider::Create(wxWindow *parent, wxWindowID id, bool wxSlider::Create(wxWindow *parent, wxWindowID id,
@@ -59,21 +58,11 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) ) if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
style |= wxSL_HORIZONTAL; style |= wxSL_HORIZONTAL;
SetName(name); if( !CreateControl( parent, id, pos, size, style, validator, name ) )
SetValidator(validator); return false;
m_backgroundColour = parent->GetBackgroundColour();
m_foregroundColour = parent->GetForegroundColour();
if (parent) parent->AddChild(this);
m_lineSize = 1; m_lineSize = 1;
m_windowStyle = style; m_windowStyle = style;
m_tickFreq = 0;
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
m_rangeMax = maxValue; m_rangeMax = maxValue;
m_rangeMin = minValue; m_rangeMin = minValue;
@@ -114,8 +103,6 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
m_font = parent->GetFont();
ChangeFont(FALSE); ChangeFont(FALSE);
SetCanAddEventHandler(TRUE); SetCanAddEventHandler(TRUE);
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
@@ -141,11 +128,6 @@ void wxSlider::SetValue(int value)
XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL); XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
} }
void wxSlider::GetSize(int *width, int *height) const
{
wxControl::GetSize(width, height);
}
void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
Widget widget = (Widget) m_mainWidget; Widget widget = (Widget) m_mainWidget;
@@ -186,12 +168,6 @@ void wxSlider::SetRange(int minValue, int maxValue)
} }
// For trackbars only // For trackbars only
void wxSlider::SetTickFreq(int n, int WXUNUSED(pos))
{
// Not implemented in Motif
m_tickFreq = n;
}
void wxSlider::SetPageSize(int pageSize) void wxSlider::SetPageSize(int pageSize)
{ {
// Not implemented in Motif // Not implemented in Motif
@@ -203,16 +179,6 @@ int wxSlider::GetPageSize() const
return m_pageSize; return m_pageSize;
} }
void wxSlider::ClearSel()
{
// Not implemented in Motif
}
void wxSlider::ClearTicks()
{
// Not implemented in Motif
}
void wxSlider::SetLineSize(int lineSize) void wxSlider::SetLineSize(int lineSize)
{ {
// Not implemented in Motif // Not implemented in Motif
@@ -225,23 +191,6 @@ int wxSlider::GetLineSize() const
return m_lineSize; return m_lineSize;
} }
int wxSlider::GetSelEnd() const
{
// Not implemented in Motif
return 0;
}
int wxSlider::GetSelStart() const
{
// Not implemented in Motif
return 0;
}
void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
{
// Not implemented in Motif
}
void wxSlider::SetThumbLength(int WXUNUSED(len)) void wxSlider::SetThumbLength(int WXUNUSED(len))
{ {
// Not implemented in Motif (?) // Not implemented in Motif (?)
@@ -253,57 +202,41 @@ int wxSlider::GetThumbLength() const
return 0; return 0;
} }
void wxSlider::SetTick(int WXUNUSED(tickPos))
{
// Not implemented in Motif
}
void wxSlider::Command (wxCommandEvent & event) void wxSlider::Command (wxCommandEvent & event)
{ {
SetValue (event.GetInt()); SetValue (event.GetInt());
ProcessCommand (event); ProcessCommand (event);
} }
void wxSlider::ChangeFont(bool keepOriginalSize) void wxSliderCallback (Widget widget, XtPointer clientData,
{ XmScaleCallbackStruct * cbs)
wxWindow::ChangeFont(keepOriginalSize);
}
void wxSlider::ChangeBackgroundColour()
{
wxWindow::ChangeBackgroundColour();
}
void wxSlider::ChangeForegroundColour()
{
wxWindow::ChangeForegroundColour();
}
void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
{ {
wxSlider *slider = (wxSlider *) clientData; wxSlider *slider = (wxSlider *) clientData;
wxEventType scrollEvent;
switch (cbs->reason) switch (cbs->reason)
{ {
case XmCR_VALUE_CHANGED: case XmCR_VALUE_CHANGED:
case XmCR_DRAG: scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
default: break;
{
// TODO: the XmCR_VALUE_CHANGED case should be handled
// differently (it's not sent continually as the slider moves).
// In which case we need a similar behaviour for other platforms.
wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId()); case XmCR_DRAG:
scrollEvent = wxEVT_SCROLL_THUMBTRACK;
break;
default:
return;
}
wxScrollEvent event(scrollEvent, slider->GetId());
XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL); XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
event.SetEventObject(slider); event.SetEventObject(slider);
slider->ProcessCommand(event); slider->GetEventHandler()->ProcessEvent(event);
// Also send a wxCommandEvent for compatibility. // Also send a wxCommandEvent for compatibility.
wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId()); wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
event2.SetEventObject(slider); event2.SetEventObject(slider);
event2.SetInt( event.GetInt() ); event2.SetInt( event.GetInt() );
slider->ProcessCommand(event2); slider->GetEventHandler()->ProcessEvent(event2);
break;
}
}
} }