-bool wxSlider::Create(wxWindow *parent, const wxWindowID id,
- const int value, const int minValue, const int maxValue,
- const wxPoint& pos,
- const wxSize& size, const long style,
- const wxValidator& validator,
- const wxString& name)
-{
- SetName(name);
- SetValidator(validator);
-
- if (parent) parent->AddChild(this);
- SetBackgroundColour(parent->GetDefaultBackgroundColour()) ;
- SetForegroundColour(parent->GetDefaultForegroundColour()) ;
-
- m_staticValue = 0;
- m_staticMin = 0;
- m_staticMax = 0;
- m_pageSize = 1;
- m_lineSize = 1;
- m_windowStyle = style;
- m_tickFreq = 0;
-
- if ( id == -1 )
- m_windowId = (int)NewControlId();
- else
- m_windowId = id;
-
- int x = pos.x;
- int y = pos.y;
- int width = size.x;
- int height = size.y;
-
-#if defined(__WIN95__) && USE_TRACK_BAR
- long msStyle ;
-
- if ( m_windowStyle & wxSL_LABELS )
- {
- msStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER;
-
- bool want3D;
- WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
-
- m_staticValue = (WXHWND) CreateWindowEx(exStyle, "STATIC", NULL,
- msStyle,
- 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
- wxGetInstance(), NULL);
-
- // Now create min static control
- sprintf(wxBuffer, "%d", minValue);
- m_staticMin = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer,
- STATIC_FLAGS,
- 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
- wxGetInstance(), NULL);
- }
-
- msStyle = 0;
- if (m_windowStyle & wxSL_VERTICAL)
- msStyle = TBS_VERT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
- else
- msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ;
-
- if ( m_windowStyle & wxSL_AUTOTICKS )
- msStyle |= TBS_AUTOTICKS ;
-
- if ( m_windowStyle & wxSL_LEFT )
- msStyle |= TBS_LEFT;
- else if ( m_windowStyle & wxSL_RIGHT )
- msStyle |= TBS_RIGHT;
- else if ( m_windowStyle & wxSL_TOP )
- msStyle |= TBS_TOP;
- else if ( m_windowStyle & wxSL_BOTTOM )
- msStyle |= TBS_BOTTOM;
- else if ( m_windowStyle & wxSL_BOTH )
- msStyle |= TBS_BOTH;
- else if ( ! (m_windowStyle & wxSL_AUTOTICKS) )
- msStyle |= TBS_NOTICKS;
-
- if ( m_windowStyle & wxSL_SELRANGE )
- msStyle |= TBS_ENABLESELRANGE ;
-
- HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer,
- msStyle,
- 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
- wxGetInstance(), NULL);
-
- m_rangeMax = maxValue;
- m_rangeMin = minValue;
-
- m_pageSize = (int)((maxValue-minValue)/10);
-
- ::SendMessage(scroll_bar, TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
- ::SendMessage(scroll_bar, TBM_SETPOS, TRUE, (LPARAM)value);
- ::SendMessage(scroll_bar, TBM_SETPAGESIZE, 0, (LPARAM)m_pageSize);
-
- m_hWnd = (WXHWND)scroll_bar;
-
- SubclassWin(GetHWND());
-
- if ( m_windowStyle & wxSL_LABELS )
- {
- // Finally, create max value static item
- sprintf(wxBuffer, "%d", maxValue);
- m_staticMax = (WXHWND) CreateWindowEx(0, "STATIC", wxBuffer,
- STATIC_FLAGS,
- 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
- wxGetInstance(), NULL);
-
- SetFont(parent->GetFont());
-
- if (GetFont())
- {
-// GetFont()->RealizeResource();
- if (GetFont()->GetResourceHandle())
+bool wxSlider::Create(wxWindow *parent,
+ wxWindowID id,
+ int value,
+ int minValue,
+ int maxValue,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ wxCHECK_MSG( minValue < maxValue, false,
+ wxT("Slider minimum must be strictly less than the maximum.") );
+
+ // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and
+ // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility
+ // reasons we can't really change it, instead try to infer the orientation
+ // from the flags given to us here
+ switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) )
+ {
+ case wxSL_LEFT:
+ case wxSL_RIGHT:
+ style |= wxSL_VERTICAL;
+ break;
+
+ case wxSL_TOP:
+ case wxSL_BOTTOM:
+ style |= wxSL_HORIZONTAL;
+ break;
+
+ case 0:
+ // no specific direction, do we have at least the orientation?
+ if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) )
+ {
+ // no, choose default
+ style |= wxSL_BOTTOM | wxSL_HORIZONTAL;
+ }
+ };
+
+ wxASSERT_MSG( !(style & wxSL_VERTICAL) || !(style & wxSL_HORIZONTAL),
+ wxT("incompatible slider direction and orientation") );
+
+
+ // initialize everything
+ if ( !CreateControl(parent, id, pos, size, style, validator, name) )
+ return false;
+
+ // ensure that we have correct values for GetLabelsSize()
+ m_rangeMin = minValue;
+ m_rangeMax = maxValue;
+
+ // create the labels first, so that our DoGetBestSize() could take them
+ // into account
+ //
+ // note that we could simply create 3 wxStaticTexts here but it could
+ // result in some observable side effects at wx level (e.g. the parent of
+ // wxSlider would have 3 more children than expected) and so we prefer not
+ // to do it like this
+ if ( m_windowStyle & wxSL_LABELS )
+ {
+ m_labels = new wxSubwindows(SliderLabel_Last);
+
+ HWND hwndParent = GetHwndOf(parent);
+ for ( size_t n = 0; n < SliderLabel_Last; n++ )