implemented DoGetSize() for wxSlider (patch from Dimitri)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15212 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-04-20 09:57:28 +00:00
parent 93c4157c6c
commit 5f605ccf3f
2 changed files with 392 additions and 318 deletions

View File

@@ -46,8 +46,11 @@ public:
virtual int GetValue() const ;
virtual void SetValue(int);
void GetSize(int *x, int *y) const ;
void GetPosition(int *x, int *y) const ;
virtual void DoGetSize(int *width, int *height) const;
void GetSize(int *w, int *h) const;
void GetPosition(int *x, int *y) const;
bool Show(bool show);

View File

@@ -42,9 +42,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
// Slider
wxSlider95::wxSlider95()
{
m_staticValue = 0;
m_staticMin = 0;
m_staticMax = 0;
m_staticValue = (WXHWND) NULL;
m_staticMin = (WXHWND) NULL;
m_staticMax = (WXHWND) NULL;
m_pageSize = 1;
m_lineSize = 1;
m_rangeMax = 0;
@@ -65,12 +65,13 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
#endif // wxUSE_VALIDATORS
if (parent) parent->AddChild(this);
SetBackgroundColour(parent->GetBackgroundColour()) ;
SetForegroundColour(parent->GetForegroundColour()) ;
m_staticValue = 0;
m_staticMin = 0;
m_staticMax = 0;
m_staticValue = (WXHWND) NULL;;
m_staticMin = (WXHWND) NULL;;
m_staticMax = (WXHWND) NULL;;
m_pageSize = 1;
m_lineSize = 1;
m_windowStyle = style;
@@ -86,8 +87,8 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
int width = size.x;
int height = size.y;
long msStyle=0 ;
long wstyle=0 ;
long msStyle = 0;
long wstyle = 0;
if ( m_windowStyle & wxCLIP_SIBLINGS )
msStyle |= WS_CLIPSIBLINGS;
@@ -99,20 +100,26 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
bool want3D;
WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
m_staticValue = (WXHWND) CreateWindowEx(exStyle, wxT("STATIC"), NULL,
m_staticValue = (WXHWND) CreateWindowEx
(
exStyle, wxT("STATIC"), NULL,
msStyle,
0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
wxGetInstance(), NULL);
wxGetInstance(), NULL
);
// Now create min static control
wxSprintf(wxBuffer, wxT("%d"), minValue);
wstyle = STATIC_FLAGS;
if ( m_windowStyle & wxCLIP_SIBLINGS )
msStyle |= WS_CLIPSIBLINGS;
m_staticMin = (WXHWND) CreateWindowEx(0, wxT("STATIC"), wxBuffer,
m_staticMin = (WXHWND) CreateWindowEx
(
0, wxT("STATIC"), wxBuffer,
wstyle,
0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
wxGetInstance(), NULL);
wxGetInstance(), NULL
);
}
msStyle = 0;
@@ -142,12 +149,15 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
msStyle |= TBS_NOTICKS;
if ( m_windowStyle & wxSL_SELRANGE )
msStyle |= TBS_ENABLESELRANGE ;
msStyle |= TBS_ENABLESELRANGE;
HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer,
HWND scroll_bar = CreateWindowEx
(
MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer,
msStyle,
0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
wxGetInstance(), NULL);
wxGetInstance(), NULL
);
m_rangeMax = maxValue;
m_rangeMin = minValue;
@@ -162,7 +172,7 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
SubclassWin(GetHWND());
SetWindowText((HWND) m_hWnd, wxT(""));
::SetWindowText((HWND) m_hWnd, wxT(""));
SetFont(parent->GetFont());
@@ -171,12 +181,17 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
// Finally, create max value static item
wxSprintf(wxBuffer, wxT("%d"), maxValue);
wstyle = STATIC_FLAGS;
if ( m_windowStyle & wxCLIP_SIBLINGS )
msStyle |= WS_CLIPSIBLINGS;
m_staticMax = (WXHWND) CreateWindowEx(0, wxT("STATIC"), wxBuffer,
m_staticMax = (WXHWND) CreateWindowEx
(
0, wxT("STATIC"), wxBuffer,
wstyle,
0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)NewControlId(),
wxGetInstance(), NULL);
wxGetInstance(), NULL
);
if (GetFont().Ok())
@@ -184,14 +199,16 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id,
if (GetFont().GetResourceHandle())
{
if ( m_staticMin )
SendMessage((HWND)m_staticMin,WM_SETFONT,
(WPARAM)GetFont().GetResourceHandle(),0L);
::SendMessage((HWND) m_staticMin, WM_SETFONT,
(WPARAM) GetFont().GetResourceHandle(), 0L);
if ( m_staticMax )
SendMessage((HWND)m_staticMax,WM_SETFONT,
(WPARAM)GetFont().GetResourceHandle(),0L);
::SendMessage((HWND) m_staticMax, WM_SETFONT,
(WPARAM) GetFont().GetResourceHandle(), 0L);
if (m_staticValue)
SendMessage((HWND)m_staticValue,WM_SETFONT,
(WPARAM)GetFont().GetResourceHandle(),0L);
::SendMessage((HWND) m_staticValue, WM_SETFONT,
(WPARAM) GetFont().GetResourceHandle(), 0L);
}
}
}
@@ -242,7 +259,7 @@ bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
return FALSE;
}
int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
int newPos = (int) ::SendMessage((HWND) control, TBM_GETPOS, 0, 0);
if ( (newPos < GetMin()) || (newPos > GetMax()) )
{
// out of range - but we did process it
@@ -266,11 +283,22 @@ bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam,
wxSlider95::~wxSlider95()
{
if (m_staticMin)
DestroyWindow((HWND) m_staticMin);
{
::DestroyWindow((HWND) m_staticMin);
m_staticMin = (WXHWND) NULL;
}
if (m_staticMax)
DestroyWindow((HWND) m_staticMax);
{
::DestroyWindow((HWND) m_staticMax);
m_staticMax = (WXHWND) NULL;
}
if (m_staticValue)
DestroyWindow((HWND) m_staticValue);
{
::DestroyWindow((HWND) m_staticValue);
m_staticValue = (WXHWND) NULL;
}
}
int wxSlider95::GetValue() const
@@ -281,13 +309,19 @@ int wxSlider95::GetValue() const
void wxSlider95::SetValue(int value)
{
::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
if (m_staticValue)
{
wxSprintf(wxBuffer, wxT("%d"), value);
SetWindowText((HWND) m_staticValue, wxBuffer);
::SetWindowText((HWND) m_staticValue, wxBuffer);
}
}
void wxSlider95::DoGetSize(int *width, int *height) const
{
GetSize(width, height);
}
void wxSlider95::GetSize(int *width, int *height) const
{
RECT rect;
@@ -297,8 +331,10 @@ void wxSlider95::GetSize(int *width, int *height) const
if (m_staticMin)
wxFindMaxSize(m_staticMin, &rect);
if (m_staticMax)
wxFindMaxSize(m_staticMax, &rect);
if (m_staticValue)
wxFindMaxSize(m_staticValue, &rect);
@@ -338,6 +374,7 @@ void wxSlider95::GetPosition(int *x, int *y) const
point.x -= pt.x;
point.y -= pt.y;
}
*x = point.x;
*y = point.y;
}
@@ -377,12 +414,12 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int min_len = 0;
GetWindowText((HWND) m_staticMin, buf, 300);
::GetWindowText((HWND) m_staticMin, buf, 300);
GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
int max_len = 0;
GetWindowText((HWND) m_staticMax, buf, 300);
::GetWindowText((HWND) m_staticMax, buf, 300);
GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
if (m_staticValue)
{
@@ -393,14 +430,16 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
// a lot of space before the first character
new_width += 3*cx;
#endif
// The height needs to be a bit bigger under Win95 if using native
// 3D effects.
// The height needs to be a bit bigger under Win95 if
// using native 3D effects.
valueHeight = (int) (valueHeight * 1.5) ;
MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
new_width, valueHeight, TRUE);
x_offset += new_width + cx;
}
MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
MoveWindow((HWND) m_staticMin, x_offset, y_offset,
(int) min_len, cy, TRUE);
x_offset += (int)(min_len + cx);
int slider_length = (int)(w1 - x_offset - max_len - cx);
@@ -413,24 +452,33 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100)
slider_length = 100;
MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
::MoveWindow(GetHwnd(), x_offset, y_offset,
slider_length, slider_height, TRUE);
x_offset += slider_length + cx;
MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
MoveWindow((HWND) m_staticMax, x_offset, y_offset,
(int) max_len, cy, TRUE);
}
else
{
// No labels
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
if
(
width == -1
&& height == -1
&& ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
)
{
GetSize(&w1, &h1);
}
if ( w1 < 0 )
w1 = 200;
if ( h1 < 0 )
h1 = 20;
MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
}
}
else
@@ -438,11 +486,11 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if ( m_windowStyle & wxSL_LABELS )
{
int min_len;
GetWindowText((HWND) m_staticMin, buf, 300);
::GetWindowText((HWND) m_staticMin, buf, 300);
GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont());
int max_len;
GetWindowText((HWND) m_staticMax, buf, 300);
::GetWindowText((HWND) m_staticMax, buf, 300);
GetTextExtent(buf, &max_len, &cyf,NULL,NULL, & this->GetFont());
if (m_staticValue)
@@ -458,15 +506,17 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
... and replace with following line: */
new_width += cx;
// The height needs to be a bit bigger under Win95 if using native
// 3D effects.
// The height needs to be a bit bigger under Win95 if
// using native 3D effects.
valueHeight = (int) (valueHeight * 1.5) ;
MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE);
::MoveWindow((HWND) m_staticValue, x_offset, y_offset,
new_width, valueHeight, TRUE);
y_offset += valueHeight;
}
MoveWindow((HWND) m_staticMin, x_offset, y_offset, (int)min_len, cy, TRUE);
::MoveWindow((HWND) m_staticMin, x_offset, y_offset,
(int) min_len, cy, TRUE);
y_offset += cy;
int slider_length = (int)(h1 - y_offset - cy - cy);
@@ -479,24 +529,32 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100)
slider_length = 100;
MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
::MoveWindow(GetHwnd(), x_offset, y_offset,
slider_width, slider_length, TRUE);
y_offset += slider_length;
MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
::MoveWindow((HWND) m_staticMax, x_offset, y_offset,
(int)max_len, cy, TRUE);
}
else
{
// No labels
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
if
(
width == -1 && height == -1
&& ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)
)
{
GetSize(&w1, &h1);
}
if ( w1 < 0 )
w1 = 20;
if ( h1 < 0 )
h1 = 200;
MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
::MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
}
}
}
@@ -512,13 +570,13 @@ void wxSlider95::SetRange(int minValue, int maxValue)
if ( m_staticMin )
{
wxSprintf(buf, wxT("%d"), m_rangeMin);
SetWindowText((HWND) m_staticMin, buf);
::SetWindowText((HWND) m_staticMin, buf);
}
if ( m_staticMax )
{
wxSprintf(buf, wxT("%d"), m_rangeMax);
SetWindowText((HWND) m_staticMax, buf);
::SetWindowText((HWND) m_staticMax, buf);
}
}
@@ -568,22 +626,26 @@ void wxSlider95::SetLineSize(int lineSize)
int wxSlider95::GetLineSize() const
{
return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 );
return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE,
(WPARAM) 0, (LPARAM) 0 );
}
int wxSlider95::GetSelEnd() const
{
return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 );
return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND,
(WPARAM) 0, (LPARAM) 0 );
}
int wxSlider95::GetSelStart() const
{
return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 );
return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART,
(WPARAM) 0, (LPARAM) 0 );
}
void wxSlider95::SetSelection(int minPos, int maxPos)
{
::SendMessage( GetHwnd(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
::SendMessage(GetHwnd(), TBM_SETSEL,
(WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
}
void wxSlider95::SetThumbLength(int len)
@@ -593,7 +655,8 @@ void wxSlider95::SetThumbLength(int len)
int wxSlider95::GetThumbLength() const
{
return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 );
return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH,
(WPARAM) 0, (LPARAM) 0 );
}
void wxSlider95::SetTick(int tickPos)
@@ -603,7 +666,12 @@ void wxSlider95::SetTick(int tickPos)
bool wxSlider95::ContainsHWND(WXHWND hWnd) const
{
return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() );
return
(
hWnd == GetStaticMin()
|| hWnd == GetStaticMax()
|| hWnd == GetEditValue()
);
}
void wxSlider95::Command (wxCommandEvent & event)
@@ -624,10 +692,13 @@ bool wxSlider95::Show(bool show)
if(m_staticValue)
ShowWindow((HWND) m_staticValue, (BOOL)cshow);
if(m_staticMin)
ShowWindow((HWND) m_staticMin, (BOOL)cshow);
if(m_staticMax)
ShowWindow((HWND) m_staticMax, (BOOL)cshow);
return TRUE;
}