1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/univ/slider.h
// Purpose: wxSlider control for wxUniversal
// Author: Vadim Zeitlin
// Modified by:
// Created: 09.02.01
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIV_SLIDER_H_
#define _WX_UNIV_SLIDER_H_
#include "wx/univ/scrthumb.h"
// ----------------------------------------------------------------------------
// the actions supported by this control
// ----------------------------------------------------------------------------
// our actions are the same as scrollbars
#define wxACTION_SLIDER_START wxT("start") // to the beginning
#define wxACTION_SLIDER_END wxT("end") // to the end
#define wxACTION_SLIDER_LINE_UP wxT("lineup") // one line up/left
#define wxACTION_SLIDER_PAGE_UP wxT("pageup") // one page up/left
#define wxACTION_SLIDER_LINE_DOWN wxT("linedown") // one line down/right
#define wxACTION_SLIDER_PAGE_DOWN wxT("pagedown") // one page down/right
#define wxACTION_SLIDER_PAGE_CHANGE wxT("pagechange")// change page by numArg
#define wxACTION_SLIDER_THUMB_DRAG wxT("thumbdrag")
#define wxACTION_SLIDER_THUMB_MOVE wxT("thumbmove")
#define wxACTION_SLIDER_THUMB_RELEASE wxT("thumbrelease")
// ----------------------------------------------------------------------------
// wxSlider
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxSlider : public wxSliderBase,
public wxControlWithThumb
{
public:
// ctors and such
wxSlider();
wxSlider(wxWindow *parent,
wxWindowID id,
int value, int minValue, int maxValue,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxSL_HORIZONTAL,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxSliderNameStr);
bool Create(wxWindow *parent,
wxWindowID id,
int value, int minValue, int maxValue,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxSL_HORIZONTAL,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxSliderNameStr);
// implement base class pure virtuals
virtual int GetValue() const;
virtual void SetValue(int value);
virtual void SetRange(int minValue, int maxValue);
virtual int GetMin() const;
virtual int GetMax() const;
virtual void SetLineSize(int lineSize);
virtual void SetPageSize(int pageSize);
virtual int GetLineSize() const;
virtual int GetPageSize() const;
virtual void SetThumbLength(int lenPixels);
virtual int GetThumbLength() const;
virtual int GetTickFreq() const { return m_tickFreq; }
// wxUniv-specific methods
// -----------------------
// is this a vertical slider?
bool IsVert() const { return (GetWindowStyle() & wxSL_VERTICAL) != 0; }
// get the slider orientation
wxOrientation GetOrientation() const
{ return IsVert() ? wxVERTICAL : wxHORIZONTAL; }
// do we have labels?
bool HasLabels() const
{ return ((GetWindowStyle() & wxSL_LABELS) != 0) &&
((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT)) != 0); }
// do we have ticks?
bool HasTicks() const
{ return ((GetWindowStyle() & wxSL_TICKS) != 0) &&
((GetWindowStyle() & (wxSL_TOP|wxSL_BOTTOM|wxSL_LEFT|wxSL_RIGHT|wxSL_BOTH)) != 0); }
// implement wxControlWithThumb interface
virtual wxWindow *GetWindow() { return this; }
virtual bool IsVertical() const { return IsVert(); }
virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const;
virtual wxCoord ThumbPosToPixel() const;
virtual int PixelToThumbPos(wxCoord x) const;
virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart,
int flag,
bool set = true);
virtual void OnThumbDragStart(int pos);
virtual void OnThumbDrag(int pos);
virtual void OnThumbDragEnd(int pos);
virtual void OnPageScrollStart();
virtual bool OnPageScroll(int pageInc);
// for wxStdSliderInputHandler
wxScrollThumb& GetThumb() { return m_thumb; }
virtual bool PerformAction(const wxControlAction& action,
long numArg = 0,
const wxString& strArg = wxEmptyString);
static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
{
return GetStdInputHandler(handlerDef);
}
protected:
enum
{
INVALID_THUMB_VALUE = -0xffff
};
// Platform-specific implementation of SetTickFreq
virtual void DoSetTickFreq(int freq);
// overridden base class virtuals
virtual wxSize DoGetBestClientSize() const;
virtual void DoDraw(wxControlRenderer *renderer);
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
// event handlers
void OnSize(wxSizeEvent& event);
// common part of all ctors
void Init();
// normalize the value to fit in the range
int NormalizeValue(int value) const;
// change the value by the given increment, return true if really changed
bool ChangeValueBy(int inc);
// change the value to the given one
bool ChangeValueTo(int value);
// is the value inside the range?
bool IsInRange(int value) { return (value >= m_min) && (value <= m_max); }
// format the value for printing as label
virtual wxString FormatValue(int value) const;
// calculate max label size
wxSize CalcLabelSize() const;
// calculate m_rectLabel/Slider
void CalcGeometry();
// get the thumb size
wxSize GetThumbSize() const;
// get the shaft rect (uses m_rectSlider which is supposed to be calculated)
wxRect GetShaftRect() const;
// calc the current thumb position using the shaft rect (if the pointer is
// NULL, we calculate it here too)
void CalcThumbRect(const wxRect *rectShaft,
wxRect *rectThumbOut,
wxRect *rectLabelOut,
int value = INVALID_THUMB_VALUE) const;
// return the slider rect calculating it if needed
const wxRect& GetSliderRect() const;
// refresh the current thumb position
void RefreshThumb();
private:
// get the default thumb size (without using m_thumbSize)
wxSize GetDefaultThumbSize() const;
// the object which manages our thumb
wxScrollThumb m_thumb;
// the slider range and value
int m_min,
m_max,
m_value;
// the tick frequence (default is 1)
int m_tickFreq;
// the line and page increments (logical units)
int m_lineSize,
m_pageSize;
// the size of the thumb (in pixels)
int m_thumbSize;
// the part of the client area reserved for the label, the ticks and the
// part for the slider itself
wxRect m_rectLabel,
m_rectTicks,
m_rectSlider;
// the state of the thumb (wxCONTROL_XXX constants sum)
int m_thumbFlags;
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxSlider)
};
#endif // _WX_UNIV_SLIDER_H_
|