1. DoSetSize() simplified, DoGetBestSize() introduced

2. code cleanup here and there
3. attempts to make static boxes behave better (i.e. stay below other controls)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-07-02 22:02:05 +00:00
parent 44719c473b
commit 4438caf41a
30 changed files with 599 additions and 894 deletions

View File

@@ -63,9 +63,7 @@ protected:
// send a notification event, return TRUE if processed // send a notification event, return TRUE if processed
bool SendClickEvent(); bool SendClickEvent();
virtual void DoSetSize(int x, int y, virtual wxSize DoGetBestSize();
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -53,9 +53,7 @@ public:
WXUINT message, WXWPARAM wParam, WXLPARAM lParam); WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
protected: protected:
virtual void DoSetSize(int x, int y, virtual wxSize DoGetBestSize();
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox
@@ -82,15 +80,7 @@ public:
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxCheckBoxNameStr); const wxString& name = wxCheckBoxNameStr);
virtual void SetValue(bool value);
virtual bool GetValue() const ;
virtual void SetLabel(const wxBitmap& bitmap); virtual void SetLabel(const wxBitmap& bitmap);
protected:
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif
// _WX_CHECKBOX_H_ // _WX_CHECKBOX_H_

View File

@@ -73,9 +73,10 @@ public:
protected: protected:
int m_noStrings; int m_noStrings;
virtual wxSize DoGetBestSize();
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -6,14 +6,14 @@
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_COMBOBOX_H_ #ifndef _WX_COMBOBOX_H_
#define _WX_COMBOBOX_H_ #define _WX_COMBOBOX_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "combobox.h" #pragma interface "combobox.h"
#endif #endif
#include "wx/choice.h" #include "wx/choice.h"
@@ -23,59 +23,64 @@
WXDLLEXPORT_DATA(extern const wxChar*) wxComboBoxNameStr; WXDLLEXPORT_DATA(extern const wxChar*) wxComboBoxNameStr;
WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
// Combobox item // ----------------------------------------------------------------------------
// Combobox control
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxComboBox: public wxChoice class WXDLLEXPORT wxComboBox: public wxChoice
{ {
DECLARE_DYNAMIC_CLASS(wxComboBox) DECLARE_DYNAMIC_CLASS(wxComboBox)
public: public:
inline wxComboBox(void) {} wxComboBox() { }
inline wxComboBox(wxWindow *parent, wxWindowID id, wxComboBox(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString, const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL, int n = 0, const wxString choices[] = NULL,
long style = 0, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr) const wxString& name = wxComboBoxNameStr)
{ {
Create(parent, id, value, pos, size, n, choices, style, validator, name); Create(parent, id, value, pos, size, n, choices, style, validator, name);
} }
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString, const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
int n = 0, const wxString choices[] = NULL, int n = 0, const wxString choices[] = NULL,
long style = 0, long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxComboBoxNameStr); const wxString& name = wxComboBoxNameStr);
// List functions: see wxChoice // List functions: see wxChoice
// Text field functions
virtual wxString GetValue(void) const ;
virtual void SetValue(const wxString& value);
// Clipboard operations // Text field functions
virtual void Copy(void); wxString GetValue() const { return GetLabel(); }
virtual void Cut(void); virtual void SetValue(const wxString& value);
virtual void Paste(void);
virtual void SetInsertionPoint(long pos);
virtual void SetInsertionPointEnd(void);
virtual long GetInsertionPoint(void) const ;
virtual long GetLastPosition(void) const ;
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
virtual void SetSelection(int n)
{
wxChoice::SetSelection(n);
}
virtual void SetSelection(long from, long to);
virtual void SetEditable(bool editable);
virtual bool MSWCommand(WXUINT param, WXWORD id); // Clipboard operations
virtual void Copy();
virtual void Cut();
virtual void Paste();
virtual void SetInsertionPoint(long pos);
virtual void SetInsertionPointEnd();
virtual long GetInsertionPoint() const;
virtual long GetLastPosition() const;
virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to);
virtual void SetSelection(int n) { wxChoice::SetSelection(n); }
virtual void SetSelection(long from, long to);
virtual void SetEditable(bool editable);
virtual bool MSWCommand(WXUINT param, WXWORD id);
protected:
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif // wxUSE_COMBOBOX #endif // wxUSE_COMBOBOX

View File

@@ -69,6 +69,8 @@ protected:
// For controls like radiobuttons which are really composite // For controls like radiobuttons which are really composite
wxList m_subControls; wxList m_subControls;
virtual wxSize DoGetBestSize();
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -70,10 +70,6 @@ public:
protected: protected:
int m_rangeMax; int m_rangeMax;
int m_gaugePos; int m_gaugePos;
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -70,10 +70,6 @@ public:
protected: protected:
int m_rangeMax; int m_rangeMax;
int m_gaugePos; int m_gaugePos;
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -133,10 +133,6 @@ protected:
// control items // control items
wxListBoxItemsArray m_aItems; wxListBoxItemsArray m_aItems;
#endif #endif
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -83,9 +83,7 @@ protected:
wxBitmap *bitmap; wxBitmap *bitmap;
} m_image; } m_image;
virtual void DoSetSize(int x, int y, virtual wxSize DoGetBestSize();
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -24,7 +24,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxStaticBoxNameStr;
class WXDLLEXPORT wxStaticBox : public wxControl class WXDLLEXPORT wxStaticBox : public wxControl
{ {
DECLARE_DYNAMIC_CLASS(wxStaticBox) DECLARE_DYNAMIC_CLASS(wxStaticBox)
public: public:
wxStaticBox() { } wxStaticBox() { }
@@ -37,30 +37,32 @@ public:
{ {
Create(parent, id, label, pos, size, style, name); Create(parent, id, label, pos, size, style, name);
} }
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
const wxString& label, const wxString& label,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxStaticBoxNameStr); const wxString& name = wxStaticBoxNameStr);
// implementation from now on
// --------------------------
void OnEraseBackground(wxEraseEvent& event); void OnEraseBackground(wxEraseEvent& event);
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
void SetLabel(const wxString& label);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam); WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
// overriden base class virtuals // overriden base class virtuals
virtual bool AcceptsFocus() const { return FALSE; } virtual bool AcceptsFocus() const { return FALSE; }
protected: protected:
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);
virtual wxSize DoGetBestSize();
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -6,7 +6,7 @@
// Created: 01/02/97 // Created: 01/02/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_STATTEXT_H_ #ifndef _WX_STATTEXT_H_
@@ -26,7 +26,7 @@ DECLARE_DYNAMIC_CLASS(wxStaticText)
public: public:
wxStaticText() { } wxStaticText() { }
wxStaticText(wxWindow *parent, wxWindowID id, wxStaticText(wxWindow *parent, wxWindowID id,
const wxString& label, const wxString& label,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
@@ -36,29 +36,27 @@ public:
{ {
Create(parent, id, label, pos, size, style, name); Create(parent, id, label, pos, size, style, name);
} }
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
const wxString& label, const wxString& label,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxStaticTextNameStr); const wxString& name = wxStaticTextNameStr);
// accessors // accessors
void SetLabel(const wxString& label); void SetLabel(const wxString& label);
// overriden base class virtuals // overriden base class virtuals
virtual bool AcceptsFocus() const { return FALSE; } virtual bool AcceptsFocus() const { return FALSE; }
// callbacks // callbacks
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam); WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
protected: protected:
virtual void DoSetSize(int x, int y, virtual wxSize DoGetBestSize();
int width, int height,
int sizeFlags = wxSIZE_AUTO);
}; };
#endif #endif

View File

@@ -59,7 +59,8 @@ public:
wxTextCtrl(wxWindow *parent, wxWindowID id, wxTextCtrl(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString, const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTextCtrlNameStr) const wxString& name = wxTextCtrlNameStr)
#ifndef NO_TEXT_WINDOW_STREAM #ifndef NO_TEXT_WINDOW_STREAM
@@ -72,13 +73,15 @@ public:
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString, const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTE_PROCESS_TAB, const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTextCtrlNameStr); const wxString& name = wxTextCtrlNameStr);
// accessors // accessors
// --------- // ---------
virtual wxString GetValue() const ;
virtual wxString GetValue() const;
virtual void SetValue(const wxString& value); virtual void SetValue(const wxString& value);
virtual int GetLineLength(long lineNo) const; virtual int GetLineLength(long lineNo) const;
@@ -148,25 +151,9 @@ public:
virtual void ShowPosition(long pos); virtual void ShowPosition(long pos);
virtual void Clear(); virtual void Clear();
// callbacks // Implementation from now on
// --------- // --------------------------
void OnDropFiles(wxDropFilesEvent& event);
void OnChar(wxKeyEvent& event); // Process 'enter' if required
void OnCut(wxCommandEvent& event);
void OnCopy(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
void OnUndo(wxCommandEvent& event);
void OnRedo(wxCommandEvent& event);
void OnUpdateCut(wxUpdateUIEvent& event);
void OnUpdateCopy(wxUpdateUIEvent& event);
void OnUpdatePaste(wxUpdateUIEvent& event);
void OnUpdateUndo(wxUpdateUIEvent& event);
void OnUpdateRedo(wxUpdateUIEvent& event);
// Implementation
// --------------
virtual void Command(wxCommandEvent& event); virtual void Command(wxCommandEvent& event);
virtual bool MSWCommand(WXUINT param, WXWORD id); virtual bool MSWCommand(WXUINT param, WXWORD id);
@@ -184,6 +171,23 @@ public:
virtual bool AcceptsFocus() const; virtual bool AcceptsFocus() const;
// callbacks
// ---------
void OnDropFiles(wxDropFilesEvent& event);
void OnChar(wxKeyEvent& event); // Process 'enter' if required
void OnCut(wxCommandEvent& event);
void OnCopy(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
void OnUndo(wxCommandEvent& event);
void OnRedo(wxCommandEvent& event);
void OnUpdateCut(wxUpdateUIEvent& event);
void OnUpdateCopy(wxUpdateUIEvent& event);
void OnUpdatePaste(wxUpdateUIEvent& event);
void OnUpdateUndo(wxUpdateUIEvent& event);
void OnUpdateRedo(wxUpdateUIEvent& event);
protected: protected:
#if wxUSE_RICHEDIT #if wxUSE_RICHEDIT
bool m_isRich; // Are we using rich text edit to implement this? bool m_isRich; // Are we using rich text edit to implement this?
@@ -195,9 +199,7 @@ protected:
// limit is big enough) // limit is big enough)
void AdjustSpaceLimit(); void AdjustSpaceLimit();
virtual void DoSetSize(int x, int y, virtual wxSize DoGetBestSize();
int width, int height,
int sizeFlags = wxSIZE_AUTO);
private: private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -399,6 +399,10 @@ protected:
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);
virtual void DoSetClientSize(int width, int height); virtual void DoSetClientSize(int width, int height);
// get the size which best suits the window: e.g., for a static text it
// will be the width and height of the text
virtual wxSize DoGetBestSize();
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip ); virtual void DoSetToolTip( wxToolTip *tip );
#endif // wxUSE_TOOLTIPS #endif // wxUSE_TOOLTIPS

View File

@@ -113,55 +113,28 @@ wxButton::~wxButton()
// size management including autosizing // size management including autosizing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxButton::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize wxButton::DoGetBestSize()
{ {
int currentX, currentY; wxString label = wxGetWindowText(GetHWND());
GetPosition(&currentX, &currentY); int wBtn;
int x1 = x; GetTextExtent(label, &wBtn, NULL);
int y1 = y;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags); int wChar, hChar;
wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont());
int actualWidth = width; // add a margin - the button is wider than just its label
int actualHeight = height; wBtn += 3*wChar;
int ww, hh;
GetSize(&ww, &hh);
int current_width; // the button height is proportional to the height of the font used
int cyf; int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
wxString buf = wxGetWindowText(GetHWND());
GetTextExtent(buf, &current_width, &cyf, NULL, NULL, &GetFont());
// If we're prepared to use the existing width, then... return wxSize(wBtn, hBtn);
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
{
actualWidth = ww;
}
else if (width == -1)
{
int cx;
int cy;
wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
actualWidth = (int)(current_width + 3*cx) ;
}
// If we're prepared to use the existing height, then...
if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
{
actualHeight = hh;
}
else if (height == -1)
{
actualHeight = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cyf);
}
MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE);
} }
// ----------------------------------------------------------------------------
// set this button as the default one in its panel
// ----------------------------------------------------------------------------
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();

View File

@@ -6,39 +6,59 @@
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem // Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "checkbox.h" #pragma implementation "checkbox.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/checkbox.h" #include "wx/checkbox.h"
#include "wx/brush.h" #include "wx/brush.h"
#endif #endif
#include "wx/msw/private.h" #include "wx/msw/private.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
#endif #endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxCheckBox
// ----------------------------------------------------------------------------
bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
{ {
wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId); wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
event.SetInt(GetValue()); event.SetInt(GetValue());
event.SetEventObject(this); event.SetEventObject(this);
ProcessCommand(event); ProcessCommand(event);
return TRUE; return TRUE;
} }
// Single check box item // Single check box item
@@ -48,126 +68,102 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
SetName(name); SetName(name);
SetValidator(validator); SetValidator(validator);
if (parent) parent->AddChild(this); if (parent) parent->AddChild(this);
SetBackgroundColour(parent->GetBackgroundColour()) ; SetBackgroundColour(parent->GetBackgroundColour()) ;
SetForegroundColour(parent->GetForegroundColour()) ; SetForegroundColour(parent->GetForegroundColour()) ;
m_windowStyle = style; m_windowStyle = style;
wxString Label = label; wxString Label = label;
if (Label == _T("")) if (Label == _T(""))
Label = _T(" "); // Apparently needed or checkbox won't show Label = _T(" "); // Apparently needed or checkbox won't show
if ( id == -1 ) if ( id == -1 )
m_windowId = NewControlId(); m_windowId = NewControlId();
else else
m_windowId = id; m_windowId = id;
int x = pos.x; int x = pos.x;
int y = pos.y; int y = pos.y;
int width = size.x; int width = size.x;
int height = size.y; int height = size.y;
long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE; long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
if ( style & wxALIGN_RIGHT ) if ( style & wxALIGN_RIGHT )
msStyle |= BS_LEFTTEXT; msStyle |= BS_LEFTTEXT;
// We perhaps have different concepts of 3D here - a 3D border, // We perhaps have different concepts of 3D here - a 3D border,
// versus a 3D button. // versus a 3D button.
// So we only wish to give a border if this is specified // So we only wish to give a border if this is specified
// in the style. // in the style.
bool want3D; bool want3D;
WXDWORD exStyle = Determine3DEffects(0, &want3D) ; WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
// Even with extended styles, need to combine with WS_BORDER // Even with extended styles, need to combine with WS_BORDER
// for them to look right. // for them to look right.
/* /*
if ( want3D || wxStyleHasBorder(m_windowStyle) ) if ( want3D || wxStyleHasBorder(m_windowStyle) )
msStyle |= WS_BORDER; msStyle |= WS_BORDER;
*/ */
m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label, m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label,
msStyle, msStyle,
0, 0, 0, 0, 0, 0, 0, 0,
(HWND)parent->GetHWND(), (HMENU)m_windowId, (HWND)parent->GetHWND(), (HMENU)m_windowId,
wxGetInstance(), NULL); wxGetInstance(), NULL);
#if wxUSE_CTL3D #if wxUSE_CTL3D
if (want3D) if (want3D)
{ {
Ctl3dSubclassCtl((HWND)m_hWnd); Ctl3dSubclassCtl(GetHwnd());
m_useCtl3D = TRUE; m_useCtl3D = TRUE;
} }
#endif #endif
// Subclass again for purposes of dialog editing mode // Subclass again for purposes of dialog editing mode
SubclassWin(m_hWnd); SubclassWin(m_hWnd);
SetFont(parent->GetFont());
SetSize(x, y, width, height); SetFont(parent->GetFont());
return TRUE; SetSize(x, y, width, height);
return TRUE;
} }
void wxCheckBox::SetLabel(const wxString& label) void wxCheckBox::SetLabel(const wxString& label)
{ {
SetWindowText((HWND)GetHWND(), label); SetWindowText(GetHwnd(), label);
} }
void wxCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize wxCheckBox::DoGetBestSize()
{ {
int currentX, currentY; int wCheckbox, hCheckbox;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) wxString str = wxGetWindowText(GetHWND());
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags); if ( !str.IsEmpty() )
int current_width, cyf;
HWND button = (HWND) GetHWND();
int nLen = GetWindowTextLength(button);
wxString str;
GetWindowText(button, str.GetWriteBuf(nLen), nLen);
str.UngetWriteBuf();
if ( !str.IsEmpty() )
{
GetTextExtent(str, &current_width, &cyf, NULL, NULL, & this->GetFont());
if (w1 < 0)
w1 = (int)(current_width + RADIO_SIZE);
if (h1 < 0)
{ {
h1 = (int)(cyf); GetTextExtent(str, &wCheckbox, &hCheckbox);
if (h1 < RADIO_SIZE) wCheckbox += RADIO_SIZE;
h1 = RADIO_SIZE;
}
}
else
{
if (w1 < 0)
w1 = RADIO_SIZE;
if (h1 < 0)
h1 = RADIO_SIZE;
}
MoveWindow(button, x1, y1, w1, h1, TRUE); if ( hCheckbox < RADIO_SIZE )
hCheckbox = RADIO_SIZE;
}
else
{
wCheckbox = RADIO_SIZE;
hCheckbox = RADIO_SIZE;
}
return wxSize(wCheckbox, hCheckbox);
} }
void wxCheckBox::SetValue(bool val) void wxCheckBox::SetValue(bool val)
{ {
SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0); SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
} }
#ifndef BST_CHECKED #ifndef BST_CHECKED
@@ -177,20 +173,20 @@ void wxCheckBox::SetValue(bool val)
bool wxCheckBox::GetValue() const bool wxCheckBox::GetValue() const
{ {
#ifdef __WIN32__ #ifdef __WIN32__
return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0) == BST_CHECKED); return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
#else #else
return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003); return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x003);
#endif #endif
} }
WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam) WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{ {
#if wxUSE_CTL3D #if wxUSE_CTL3D
if ( m_useCtl3D ) if ( m_useCtl3D )
{ {
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam); HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush; return (WXHBRUSH) hbrush;
} }
#endif #endif
@@ -217,6 +213,10 @@ void wxCheckBox::Command (wxCommandEvent & event)
ProcessCommand (event); ProcessCommand (event);
} }
// ----------------------------------------------------------------------------
// wxBitmapCheckBox
// ----------------------------------------------------------------------------
bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label, bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, long style, const wxSize& size, long style,
@@ -231,10 +231,10 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
SetForegroundColour(parent->GetForegroundColour()) ; SetForegroundColour(parent->GetForegroundColour()) ;
m_windowStyle = style; m_windowStyle = style;
if ( id == -1 ) if ( id == -1 )
m_windowId = NewControlId(); m_windowId = NewControlId();
else else
m_windowId = id; m_windowId = id;
int x = pos.x; int x = pos.x;
int y = pos.y; int y = pos.y;
@@ -254,7 +254,7 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS)) if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
{ {
Ctl3dSubclassCtl(wx_button); Ctl3dSubclassCtl(wx_button);
m_useCtl3D = TRUE; m_useCtl3D = TRUE;
} }
#endif #endif
@@ -263,53 +263,14 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
// Subclass again for purposes of dialog editing mode // Subclass again for purposes of dialog editing mode
SubclassWin((WXHWND)wx_button); SubclassWin((WXHWND)wx_button);
// SetFont(parent->GetFont());
SetSize(x, y, width, height); SetSize(x, y, width, height);
ShowWindow(wx_button, SW_SHOW); ShowWindow(wx_button, SW_SHOW);
return TRUE; return TRUE;
} }
void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap) void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
{ {
wxFAIL_MSG("not implemented");
} }
void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int currentX, currentY;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
HWND button = (HWND) GetHWND();
/*
if (w1<0)
w1 = checkWidth + FB_MARGIN ;
if (h1<0)
h1 = checkHeight + FB_MARGIN ;
*/
MoveWindow(button, x1, y1, w1, h1, TRUE);
}
void wxBitmapCheckBox::SetValue(bool val)
{
SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0);
}
bool wxBitmapCheckBox::GetValue() const
{
return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003);
}

View File

@@ -123,19 +123,19 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
void wxChoice::Append(const wxString& item) void wxChoice::Append(const wxString& item)
{ {
SendMessage((HWND) GetHWND(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item); SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item);
m_noStrings ++; m_noStrings ++;
} }
void wxChoice::Delete(int n) void wxChoice::Delete(int n)
{ {
m_noStrings = (int)SendMessage((HWND) GetHWND(), CB_DELETESTRING, n, 0); m_noStrings = (int)SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
} }
void wxChoice::Clear(void) void wxChoice::Clear(void)
{ {
SendMessage((HWND) GetHWND(), CB_RESETCONTENT, 0, 0); SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
m_noStrings = 0; m_noStrings = 0;
} }
@@ -143,12 +143,12 @@ void wxChoice::Clear(void)
int wxChoice::GetSelection(void) const int wxChoice::GetSelection(void) const
{ {
return (int)SendMessage((HWND) GetHWND(), CB_GETCURSEL, 0, 0); return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
} }
void wxChoice::SetSelection(int n) void wxChoice::SetSelection(int n)
{ {
SendMessage((HWND) GetHWND(), CB_SETCURSEL, n, 0); SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
} }
int wxChoice::FindString(const wxString& s) const int wxChoice::FindString(const wxString& s) const
@@ -159,14 +159,14 @@ int wxChoice::FindString(const wxString& s) const
char buf[512]; char buf[512];
for (int i = 0; i < Number(); i++) for (int i = 0; i < Number(); i++)
{ {
int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf); int len = (int)SendMessage(GetHwnd(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf);
buf[len] = 0; buf[len] = 0;
if (strcmp(buf, (const char *)s) == 0) if (strcmp(buf, (const char *)s) == 0)
return i; return i;
} }
return -1; return -1;
#else #else
int pos = (int)SendMessage((HWND) GetHWND(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s); int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s);
if (pos == LB_ERR) if (pos == LB_ERR)
return -1; return -1;
else else
@@ -176,99 +176,60 @@ int wxChoice::FindString(const wxString& s) const
wxString wxChoice::GetString(int n) const wxString wxChoice::GetString(int n) const
{ {
int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, n, (long)wxBuffer); size_t len = (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0);
wxBuffer[len] = 0; wxString str;
return wxString(wxBuffer); if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n,
(LPARAM)str.GetWriteBuf(len)) == CB_ERR )
{
wxLogLastError("SendMessage(CB_GETLBTEXT)");
}
str.UngetWriteBuf();
return str;
} }
void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxChoice::DoSetSize(int x, int y,
int width, int height,
int sizeFlags)
{ {
int currentX, currentY; // Ignore height parameter because height doesn't mean 'initially
GetPosition(&currentX, &currentY); // displayed' height, it refers to the drop-down menu as well. The
// wxWindows interpretation is different; also, getting the size returns
// the _displayed_ size (NOT the drop down menu size) so
// setting-getting-setting size would not work.
wxControl::DoSetSize(x, y, width, -1, sizeFlags);
}
int x1 = x; wxSize wxChoice::DoGetBestSize()
int y1 = y; {
int w1 = width; // find the widest string
int h1 = height; int wLine;
int wChoice = 0;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) for ( int i = 0; i < m_noStrings; i++ )
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
int cx; // button font dimensions
int cy;
wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
int control_width, control_height;
// Ignore height parameter because height doesn't
// mean 'initially displayed' height, it refers to the
// drop-down menu as well. The wxWindows interpretation
// is different; also, getting the size returns the
// _displayed_ size (NOT the drop down menu size)
// so setting-getting-setting size would not work.
h1 = -1;
// Deal with default size (using -1 values)
if (width <= 0)
{
// Find the longest string
if (m_noStrings == 0)
{ {
control_width = 100;
}
else
{
int len, ht;
int longest = 0;
int i;
for (i = 0; i < m_noStrings; i++)
{
wxString str(GetString(i)); wxString str(GetString(i));
GetTextExtent(str, &len, &ht, NULL, NULL, & this->GetFont()); GetTextExtent(str, &wLine, NULL);
if ( len > longest) if ( wLine > wChoice )
longest = len; wChoice = wLine;
}
control_width = longest + cx*5;
} }
}
else
{
// If non-default width...
control_width = w1;
}
// give it some reasonable default value if there are no strings in the
// list
if ( wChoice == 0 )
wChoice = 100;
// Choice drop-down list depends on number of items (limited to 10) // the combobox should be larger than the widest string
if (h1 <= 0) int cx, cy;
{ wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
if (m_noStrings == 0)
h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10;
else
h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1);
}
control_height = h1; wChoice += 5*cx;
// Calculations may have made text size too small // Choice drop-down list depends on number of items (limited to 10)
if (control_height <= 0) size_t nStrings = m_noStrings == 0 ? 10 : wxMin(10, m_noStrings) + 1;
control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings;
if (control_width <= 0) return wxSize(wChoice, hChoice);
control_width = 100;
MoveWindow((HWND)GetHWND(), x1, y1,
control_width, control_height, TRUE);
} }
WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,

View File

@@ -146,11 +146,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
return TRUE; return TRUE;
} }
wxString wxComboBox::GetValue() const
{
return wxGetWindowText(GetHWND());
}
void wxComboBox::SetValue(const wxString& value) void wxComboBox::SetValue(const wxString& value)
{ {
// If newlines are denoted by just 10, must stick 13 in front. // If newlines are denoted by just 10, must stick 13 in front.
@@ -177,43 +172,43 @@ void wxComboBox::SetValue(const wxString& value)
j ++; j ++;
} }
tmp[j] = 0; tmp[j] = 0;
SetWindowText((HWND) GetHWND(), tmp); SetWindowText(GetHwnd(), tmp);
delete[] tmp; delete[] tmp;
} }
else else
SetWindowText((HWND) GetHWND(), (const wxChar *)value); SetWindowText(GetHwnd(), value);
} }
// Clipboard operations // Clipboard operations
void wxComboBox::Copy() void wxComboBox::Copy()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
SendMessage(hWnd, WM_COPY, 0, 0L); SendMessage(hWnd, WM_COPY, 0, 0L);
} }
void wxComboBox::Cut() void wxComboBox::Cut()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
SendMessage(hWnd, WM_CUT, 0, 0L); SendMessage(hWnd, WM_CUT, 0, 0L);
} }
void wxComboBox::Paste() void wxComboBox::Paste()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
SendMessage(hWnd, WM_PASTE, 0, 0L); SendMessage(hWnd, WM_PASTE, 0, 0L);
} }
void wxComboBox::SetEditable(bool editable) void wxComboBox::SetEditable(bool editable)
{ {
// Can't implement in MSW? // Can't implement in MSW?
// HWND hWnd = (HWND) GetHWND(); // HWND hWnd = GetHwnd();
// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
} }
void wxComboBox::SetInsertionPoint(long pos) void wxComboBox::SetInsertionPoint(long pos)
{ {
/* /*
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
#ifdef __WIN32__ #ifdef __WIN32__
SendMessage(hWnd, EM_SETSEL, pos, pos); SendMessage(hWnd, EM_SETSEL, pos, pos);
SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
@@ -236,7 +231,7 @@ void wxComboBox::SetInsertionPointEnd()
long wxComboBox::GetInsertionPoint() const long wxComboBox::GetInsertionPoint() const
{ {
/* /*
DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L); DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
return Pos&0xFFFF; return Pos&0xFFFF;
*/ */
return 0; return 0;
@@ -245,14 +240,14 @@ long wxComboBox::GetInsertionPoint() const
long wxComboBox::GetLastPosition() const long wxComboBox::GetLastPosition() const
{ {
/* /*
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
// Will always return a number > 0 (according to docs) // Will always return a number > 0 (according to docs)
int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L); int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
// This gets the char index for the _beginning_ of the last line // This gets the char index for the _beginning_ of the last line
int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L); int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
// Get number of characters in the last line. We'll add this to the character // Get number of characters in the last line. We'll add this to the character
// index for the last line, 1st position. // index for the last line, 1st position.
int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L); int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
@@ -265,10 +260,10 @@ long wxComboBox::GetLastPosition() const
void wxComboBox::Replace(long from, long to, const wxString& value) void wxComboBox::Replace(long from, long to, const wxString& value)
{ {
#if wxUSE_CLIPBOARD #if wxUSE_CLIPBOARD
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
long fromChar = from; long fromChar = from;
long toChar = to; long toChar = to;
// Set selection and remove it // Set selection and remove it
#ifdef __WIN32__ #ifdef __WIN32__
SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
@@ -287,10 +282,10 @@ void wxComboBox::Replace(long from, long to, const wxString& value)
void wxComboBox::Remove(long from, long to) void wxComboBox::Remove(long from, long to)
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
long fromChar = from; long fromChar = from;
long toChar = to; long toChar = to;
// Cut all selected text // Cut all selected text
#ifdef __WIN32__ #ifdef __WIN32__
SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
@@ -302,7 +297,7 @@ void wxComboBox::Remove(long from, long to)
void wxComboBox::SetSelection(long from, long to) void wxComboBox::SetSelection(long from, long to)
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = GetHwnd();
long fromChar = from; long fromChar = from;
long toChar = to; long toChar = to;
// if from and to are both -1, it means // if from and to are both -1, it means
@@ -313,7 +308,7 @@ void wxComboBox::SetSelection(long from, long to)
fromChar = 0; fromChar = 0;
toChar = -1; toChar = -1;
} }
#ifdef __WIN32__ #ifdef __WIN32__
SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar); SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
// SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
@@ -323,6 +318,22 @@ void wxComboBox::SetSelection(long from, long to)
#endif #endif
} }
void wxComboBox::DoSetSize(int x, int y,
int width, int height,
int sizeFlags)
{
wxControl::DoSetSize(x, y, width, height, sizeFlags);
// VZ: for unknown (to me) reasons, if we don't do this, the combobox
// somehow is hidden by the static boxes, although static boxes do
// put themselves at the very end of Z-order.
if ( !::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE) )
{
wxLogLastError(_T("SetWindowPos"));
}
}
#endif #endif
// wxUSE_COMBOBOX // wxUSE_COMBOBOX

View File

@@ -58,6 +58,11 @@ wxControl::~wxControl()
m_isBeingDeleted = TRUE; m_isBeingDeleted = TRUE;
} }
wxSize wxControl::DoGetBestSize()
{
return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
}
bool wxControl::ProcessCommand(wxCommandEvent& event) bool wxControl::ProcessCommand(wxCommandEvent& event)
{ {
#if WXWIN_COMPATIBILITY #if WXWIN_COMPATIBILITY

View File

@@ -241,28 +241,11 @@ void wxFrame::DoGetPosition(int *x, int *y) const
void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
int currentX, currentY; wxWindow::DoSetSize(x, y, width, height, sizeFlags);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
GetPosition(&currentX, &currentY); wxSizeEvent event(wxSize(width, height), m_windowId);
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) event.SetEventObject( this );
x1 = currentX; GetEventHandler()->ProcessEvent(event);
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
int ww,hh ;
GetSize(&ww,&hh) ;
if (width == -1) w1 = ww ;
if (height==-1) h1 = hh ;
MoveWindow(GetHwnd(), x1, y1, w1, h1, (BOOL)TRUE);
wxSizeEvent event(wxSize(width, height), m_windowId);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
} }
bool wxFrame::Show(bool show) bool wxFrame::Show(bool show)

View File

@@ -58,9 +58,9 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
m_windowStyle = style; m_windowStyle = style;
if ( id == -1 ) if ( id == -1 )
m_windowId = (int)NewControlId(); m_windowId = (int)NewControlId();
else else
m_windowId = id; m_windowId = id;
int x = pos.x; int x = pos.x;
int y = pos.y; int y = pos.y;
@@ -108,38 +108,6 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
return TRUE; return TRUE;
} }
void wxGauge95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int currentX, currentY;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
// Deal with default size (using -1 values)
if (w1<=0)
w1 = DEFAULT_ITEM_WIDTH;
if (h1<=0)
h1 = DEFAULT_ITEM_HEIGHT;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
}
void wxGauge95::SetShadowWidth(int w) void wxGauge95::SetShadowWidth(int w)
{ {
} }

View File

@@ -126,8 +126,8 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id,
SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0); SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0);
SendMessage(wx_button, ZYZG_SETRANGE, range, 0); SendMessage(wx_button, ZYZG_SETRANGE, range, 0);
SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
SetFont(parent->GetFont()); SetFont(parent->GetFont());
@@ -137,85 +137,53 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id,
height = 50; height = 50;
SetSize(x, y, width, height); SetSize(x, y, width, height);
ShowWindow((HWND) GetHWND(), SW_SHOW); ShowWindow(GetHwnd(), SW_SHOW);
return TRUE; return TRUE;
} }
void wxGaugeMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
int currentX, currentY;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
// Deal with default size (using -1 values)
if (w1<=0)
w1 = DEFAULT_ITEM_WIDTH;
if (h1<=0)
h1 = DEFAULT_ITEM_HEIGHT;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
}
void wxGaugeMSW::SetShadowWidth(int w) void wxGaugeMSW::SetShadowWidth(int w)
{ {
SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0); SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0);
} }
void wxGaugeMSW::SetBezelFace(int w) void wxGaugeMSW::SetBezelFace(int w)
{ {
SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0); SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0);
} }
void wxGaugeMSW::SetRange(int r) void wxGaugeMSW::SetRange(int r)
{ {
m_rangeMax = r; m_rangeMax = r;
SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0); SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0);
} }
void wxGaugeMSW::SetValue(int pos) void wxGaugeMSW::SetValue(int pos)
{ {
m_gaugePos = pos; m_gaugePos = pos;
SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0); SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0);
} }
int wxGaugeMSW::GetShadowWidth(void) const int wxGaugeMSW::GetShadowWidth(void) const
{ {
return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0); return (int) SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0);
} }
int wxGaugeMSW::GetBezelFace(void) const int wxGaugeMSW::GetBezelFace(void) const
{ {
return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0); return (int) SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0);
} }
int wxGaugeMSW::GetRange(void) const int wxGaugeMSW::GetRange(void) const
{ {
return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0); return (int) SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0);
} }
int wxGaugeMSW::GetValue(void) const int wxGaugeMSW::GetValue(void) const
{ {
return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0); return (int) SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0);
} }
bool wxGaugeMSW::SetForegroundColour(const wxColour& col) bool wxGaugeMSW::SetForegroundColour(const wxColour& col)
@@ -223,7 +191,7 @@ bool wxGaugeMSW::SetForegroundColour(const wxColour& col)
if ( !wxControl::SetForegroundColour(col) ) if ( !wxControl::SetForegroundColour(col) )
return FALSE; return FALSE;
SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
return TRUE; return TRUE;
} }
@@ -233,7 +201,7 @@ bool wxGaugeMSW::SetBackgroundColour(const wxColour& col)
if ( !wxControl::SetBackgroundColour(col) ) if ( !wxControl::SetBackgroundColour(col) )
return FALSE; return FALSE;
SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
return TRUE; return TRUE;
} }

View File

@@ -518,65 +518,8 @@ wxString wxListBox::GetString(int N) const
return result; return result;
} }
void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) // Windows-specific code to set the horizontal extent of the listbox, if
{ // necessary. If s is non-NULL, it's used to calculate the horizontal extent.
int currentX, currentY;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
int cx; // button font dimensions
int cy;
wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
float control_width, control_height, control_x, control_y;
// Deal with default size (using -1 values)
if (w1<=0)
w1 = DEFAULT_ITEM_WIDTH;
if (h1<=0)
h1 = DEFAULT_ITEM_HEIGHT;
control_x = (float)x1;
control_y = (float)y1;
control_width = (float)w1;
control_height = (float)h1;
// Calculations may have made size too small
if (control_height <= 0)
control_height = (float)DEFAULT_ITEM_HEIGHT;
if (control_width <= 0)
control_width = (float)DEFAULT_ITEM_WIDTH;
MoveWindow(GetHwnd(),
(int)control_x, (int)control_y,
(int)control_width, (int)control_height,
TRUE);
}
// Windows-specific code to set the horizontal extent of
// the listbox, if necessary. If s is non-NULL, it's
// used to calculate the horizontal extent.
// Otherwise, all strings are used. // Otherwise, all strings are used.
void wxListBox::SetHorizontalExtent(const wxString& s) void wxListBox::SetHorizontalExtent(const wxString& s)
{ {

View File

@@ -351,135 +351,146 @@ wxString wxRadioBox::GetString(int N) const
// Restored old code. // Restored old code.
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
int currentX, currentY; int currentX, currentY;
GetPosition(&currentX, &currentY); GetPosition(&currentX, &currentY);
int xx = x; int xx = x;
int yy = y; int yy = y;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
xx = currentX; xx = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
yy = currentY; yy = currentY;
wxChar buf[400]; wxString buf;
int y_offset = yy; int y_offset = yy;
int x_offset = xx; int x_offset = xx;
int current_width, cyf; int current_width, cyf;
int cx1,cy1; int cx1,cy1;
wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont()); wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
// Attempt to have a look coherent with other platforms:
// We compute the biggest toggle dim, then we align all
// items according this value.
int maxWidth = -1;
int maxHeight = -1;
int i; // Attempt to have a look coherent with other platforms: We compute the
for (i = 0 ; i < m_noItems; i++) // biggest toggle dim, then we align all items according this value.
{ int maxWidth = -1;
int eachWidth; int maxHeight = -1;
int eachHeight;
if (m_radioWidth[i]<0) int i;
for (i = 0 ; i < m_noItems; i++)
{ {
// It's a labelled toggle int eachWidth;
GetWindowText((HWND) m_radioButtons[i], buf, 300); int eachHeight;
GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont()); if (m_radioWidth[i]<0)
eachWidth = (int)(current_width + RADIO_SIZE); {
eachHeight = (int)((3*cyf)/2); // It's a labelled toggle
buf = wxGetWindowText(m_radioButtons[i]);
GetTextExtent(buf, &current_width, &cyf);
eachWidth = (int)(current_width + RADIO_SIZE);
eachHeight = (int)((3*cyf)/2);
}
else
{
eachWidth = m_radioWidth[i];
eachHeight = m_radioHeight[i];
}
if (maxWidth<eachWidth)
maxWidth = eachWidth;
if (maxHeight<eachHeight)
maxHeight = eachHeight;
} }
else
if (m_hWnd)
{ {
eachWidth = m_radioWidth[i]; int totWidth;
eachHeight = m_radioHeight[i]; int totHeight;
}
if (maxWidth<eachWidth) maxWidth = eachWidth;
if (maxHeight<eachHeight) maxHeight = eachHeight;
}
if (m_hWnd) int nbHor = GetNumHor(),
{
int totWidth;
int totHeight;
int nbHor = GetNumHor(),
nbVer = GetNumVer(); nbVer = GetNumVer();
// this formula works, but I don't know why. // this formula works, but I don't know why.
// Please, be sure what you do if you modify it!! // Please, be sure what you do if you modify it!!
if (m_radioWidth[0]<0) if (m_radioWidth[0]<0)
totHeight = (nbVer * maxHeight) + cy1/2; totHeight = (nbVer * maxHeight) + cy1/2;
else else
totHeight = nbVer * (maxHeight+cy1/2); totHeight = nbVer * (maxHeight+cy1/2);
totWidth = nbHor * (maxWidth+cx1); totWidth = nbHor * (maxWidth+cx1);
int extraHeight = cy1;
#if !CTL3D
// Requires a bigger group box in plain Windows
extraHeight *= 3;
extraHeight /= 2;
#endif
MoveWindow(GetHwnd(), x_offset, y_offset,
totWidth+cx1, totHeight+extraHeight,
TRUE);
x_offset += cx1;
y_offset += cy1;
}
#if (!CTL3D) #if (!CTL3D)
// Requires a bigger group box in plain Windows y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE); // JACS 2/12/93. CTL3D draws group label quite high.
#else
MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE);
#endif #endif
x_offset += cx1; int startX = x_offset;
y_offset += cy1; int startY = y_offset;
}
#if (!CTL3D) for ( i = 0 ; i < m_noItems; i++)
y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label {
// JACS 2/12/93. CTL3D draws group label quite high. // Bidimensional radio adjustment
#endif if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
int startX = x_offset; {
int startY = y_offset; if (m_windowStyle & wxRA_VERTICAL)
{
y_offset = startY;
x_offset += maxWidth + cx1;
}
else
{
x_offset = startX;
y_offset += maxHeight;
if (m_radioWidth[0]>0)
y_offset += cy1/2;
}
}
int eachWidth;
int eachHeight;
if (m_radioWidth[i]<0)
{
// It's a labeled item
buf = wxGetWindowText(m_radioButtons[i]);
GetTextExtent(buf, &current_width, &cyf);
for ( i = 0 ; i < m_noItems; i++) // How do we find out radio button bitmap size!!
{ // By adjusting them carefully, manually :-)
// Bidimensional radio adjustment eachWidth = (int)(current_width + RADIO_SIZE);
if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0? eachHeight = (int)((3*cyf)/2);
{ }
if (m_windowStyle & wxRA_VERTICAL) else
{ {
y_offset = startY; eachWidth = m_radioWidth[i];
x_offset += maxWidth + cx1; eachHeight = m_radioHeight[i];
} }
else
{
x_offset = startX;
y_offset += maxHeight;
if (m_radioWidth[0]>0)
y_offset += cy1/2;
}
}
int eachWidth;
int eachHeight;
if (m_radioWidth[i]<0)
{
// It's a labeled item
GetWindowText((HWND) m_radioButtons[i], buf, 300);
GetTextExtent(buf, &current_width, &cyf,NULL,NULL, & GetFont());
// How do we find out radio button bitmap size!! MoveWindow((HWND)m_radioButtons[i], x_offset, y_offset,
// By adjusting them carefully, manually :-) eachWidth, eachHeight,
eachWidth = (int)(current_width + RADIO_SIZE); TRUE);
eachHeight = (int)((3*cyf)/2);
}
else
{
eachWidth = m_radioWidth[i];
eachHeight = m_radioHeight[i];
}
MoveWindow((HWND) m_radioButtons[i],x_offset,y_offset,eachWidth,eachHeight,TRUE); if (m_windowStyle & wxRA_SPECIFY_ROWS)
if (m_windowStyle & wxRA_SPECIFY_ROWS) {
{ y_offset += maxHeight;
y_offset += maxHeight; if (m_radioWidth[0]>0)
if (m_radioWidth[0]>0) y_offset += cy1/2;
y_offset += cy1/2; }
else
x_offset += maxWidth + cx1;
} }
else
x_offset += maxWidth + cx1;
}
} }
void wxRadioBox::GetSize(int *width, int *height) const void wxRadioBox::GetSize(int *width, int *height) const
{ {
RECT rect; RECT rect;

View File

@@ -277,12 +277,12 @@ wxSlider95::~wxSlider95()
int wxSlider95::GetValue() const int wxSlider95::GetValue() const
{ {
return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0); return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0);
} }
void wxSlider95::SetValue(int value) void wxSlider95::SetValue(int value)
{ {
::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value); ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
if (m_staticValue) if (m_staticValue)
{ {
wxSprintf(wxBuffer, _T("%d"), value); wxSprintf(wxBuffer, _T("%d"), value);
@@ -344,6 +344,8 @@ void wxSlider95::GetPosition(int *x, int *y) const
*y = point.y; *y = point.y;
} }
// TODO one day, make sense of all this horros and replace it with a readable
// DoGetBestSize()
void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
int x1 = x; int x1 = x;
@@ -413,7 +415,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100) if (slider_length < 100)
slider_length = 100; slider_length = 100;
MoveWindow((HWND) 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; 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);
@@ -430,7 +432,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
w1 = 200; w1 = 200;
if ( h1 < 0 ) if ( h1 < 0 )
h1 = 20; h1 = 20;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
} }
} }
else else
@@ -479,7 +481,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100) if (slider_length < 100)
slider_length = 100; slider_length = 100;
MoveWindow((HWND) 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; 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);
@@ -496,7 +498,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
w1 = 20; w1 = 20;
if ( h1 < 0 ) if ( h1 < 0 )
h1 = 200; h1 = 200;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
} }
} }
} }
@@ -506,7 +508,7 @@ void wxSlider95::SetRange(int minValue, int maxValue)
m_rangeMin = minValue; m_rangeMin = minValue;
m_rangeMax = maxValue; m_rangeMax = maxValue;
::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue)); ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
wxChar buf[40]; wxChar buf[40];
if ( m_staticMin ) if ( m_staticMin )
@@ -545,12 +547,12 @@ WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
void wxSlider95::SetTickFreq(int n, int pos) void wxSlider95::SetTickFreq(int n, int pos)
{ {
m_tickFreq = n; m_tickFreq = n;
::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos ); ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
} }
void wxSlider95::SetPageSize(int pageSize) void wxSlider95::SetPageSize(int pageSize)
{ {
::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize ); ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
m_pageSize = pageSize; m_pageSize = pageSize;
} }
@@ -561,53 +563,53 @@ int wxSlider95::GetPageSize() const
void wxSlider95::ClearSel() void wxSlider95::ClearSel()
{ {
::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 ); ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
} }
void wxSlider95::ClearTicks() void wxSlider95::ClearTicks()
{ {
::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 ); ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
} }
void wxSlider95::SetLineSize(int lineSize) void wxSlider95::SetLineSize(int lineSize)
{ {
m_lineSize = lineSize; m_lineSize = lineSize;
::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize ); ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
} }
int wxSlider95::GetLineSize() const int wxSlider95::GetLineSize() const
{ {
return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 ); return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 );
} }
int wxSlider95::GetSelEnd() const int wxSlider95::GetSelEnd() const
{ {
return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 ); return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 );
} }
int wxSlider95::GetSelStart() const int wxSlider95::GetSelStart() const
{ {
return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 ); return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 );
} }
void wxSlider95::SetSelection(int minPos, int maxPos) void wxSlider95::SetSelection(int minPos, int maxPos)
{ {
::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) ); ::SendMessage( GetHwnd(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
} }
void wxSlider95::SetThumbLength(int len) void wxSlider95::SetThumbLength(int len)
{ {
::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 ); ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
} }
int wxSlider95::GetThumbLength() const int wxSlider95::GetThumbLength() const
{ {
return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 ); return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 );
} }
void wxSlider95::SetTick(int tickPos) void wxSlider95::SetTick(int tickPos)
{ {
::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos ); ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
} }
bool wxSlider95::ContainsHWND(WXHWND hWnd) const bool wxSlider95::ContainsHWND(WXHWND hWnd) const

View File

@@ -248,12 +248,12 @@ wxSliderMSW::~wxSliderMSW()
int wxSliderMSW::GetValue() const int wxSliderMSW::GetValue() const
{ {
return ::GetScrollPos((HWND) GetHWND(), SB_CTL); return ::GetScrollPos(GetHwnd(), SB_CTL);
} }
void wxSliderMSW::SetValue(int value) void wxSliderMSW::SetValue(int value)
{ {
::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE); ::SetScrollPos(GetHwnd(), SB_CTL, value, TRUE);
if (m_staticValue) if (m_staticValue)
{ {
wxSprintf(wxBuffer, _T("%d"), value); wxSprintf(wxBuffer, _T("%d"), value);
@@ -315,6 +315,8 @@ void wxSliderMSW::GetPosition(int *x, int *y) const
*y = point.y; *y = point.y;
} }
// TODO one day, make sense of all this horros and replace it with a readable
// DoGetBestSize()
void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
int x1 = x; int x1 = x;
@@ -379,7 +381,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100) if (slider_length < 100)
slider_length = 100; slider_length = 100;
MoveWindow((HWND) 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; 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);
@@ -391,7 +393,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
w1 = 200; w1 = 200;
if ( h1 < 0 ) if ( h1 < 0 )
h1 = 20; h1 = 20;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
} }
} }
else else
@@ -435,7 +437,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (slider_length < 100) if (slider_length < 100)
slider_length = 100; slider_length = 100;
MoveWindow((HWND) 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; 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);
@@ -447,7 +449,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
w1 = 20; w1 = 20;
if ( h1 < 0 ) if ( h1 < 0 )
h1 = 200; h1 = 200;
MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
} }
} }
} }
@@ -457,7 +459,7 @@ void wxSliderMSW::SetRange(int minValue, int maxValue)
m_rangeMin = minValue; m_rangeMin = minValue;
m_rangeMax = maxValue; m_rangeMax = maxValue;
::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE); ::SetScrollRange(GetHwnd(), SB_CTL, m_rangeMin, m_rangeMax, TRUE);
wxChar buf[40]; wxChar buf[40];
if ( m_staticMin ) if ( m_staticMin )
{ {

View File

@@ -140,39 +140,11 @@ void wxStaticBitmap::Free()
m_image.icon = NULL; m_image.icon = NULL;
} }
void wxStaticBitmap::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize wxStaticBitmap::DoGetBestSize()
{ {
int currentX, currentY; // reuse the current size (as wxWindow does) instead of using some
GetPosition(&currentX, &currentY); // arbitrary default size (as wxControl, our immediate base class, does)
int x1 = x; return wxWindow::DoGetBestSize();
int y1 = y;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
int actualWidth = width;
int actualHeight = height;
int ww, hh;
GetSize(&ww, &hh);
// If we're prepared to use the existing width, then...
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
actualWidth = ww;
else
actualWidth = width;
// If we're prepared to use the existing height, then...
if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
actualHeight = hh;
else
actualHeight = height;
MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);
} }
void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)

View File

@@ -99,50 +99,31 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
return TRUE; return TRUE;
} }
void wxStaticBox::SetLabel(const wxString& label) wxSize wxStaticBox::DoGetBestSize()
{ {
SetWindowText((HWND)m_hWnd, (const wxChar *)label); int cx, cy;
wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
int wBox;
GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
wBox += 3*cx;
int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
return wxSize(wBox, hBox);
} }
void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
int currentX, currentY; wxControl::DoSetSize(x, y, width, height, sizeFlags);
GetPosition(&currentX, &currentY);
int x1 = x; // the static box should always be on the bottom of the Z-order, otherwise
int y1 = y; // it may hide controls which are positioned inside it
int w1 = width; if ( !::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0,
int h1 = height; SWP_NOMOVE | SWP_NOSIZE) )
{
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) wxLogLastError(_T("SetWindowPos"));
x1 = currentX; }
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
int current_width;
int cx;
int cy;
int cyf;
wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
GetTextExtent(wxGetWindowText(m_hWnd), &current_width, &cyf,
NULL,NULL, & this->GetFont());
if ( w1 < 0 )
w1 = current_width + 3*cx;
if ( h1 < 0 )
h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf);
MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE);
} }
WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
@@ -202,7 +183,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
RECT rect; RECT rect;
::GetClientRect((HWND) GetHWND(), &rect); ::GetClientRect(GetHwnd(), &rect);
::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush); ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
::DeleteObject(hBrush); ::DeleteObject(hBrush);
::SetMapMode((HDC) event.GetDC()->GetHDC(), mode); ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
@@ -215,7 +196,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{ {
if (nMsg == WM_NCHITTEST) if ( 0 )//nMsg == WM_NCHITTEST)
{ {
int xPos = LOWORD(lParam); // horizontal position of cursor int xPos = LOWORD(lParam); // horizontal position of cursor
int yPos = HIWORD(lParam); // vertical position of cursor int yPos = HIWORD(lParam); // vertical position of cursor

View File

@@ -94,24 +94,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
return TRUE; return TRUE;
} }
void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize wxStaticText::DoGetBestSize()
{ {
int currentX, currentY;
GetPosition(&currentX, &currentY);
int x1 = x;
int y1 = y;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
x1 = currentX;
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags);
int actualWidth = width;
int actualHeight = height;
wxString text(wxGetWindowText(GetHWND())); wxString text(wxGetWindowText(GetHWND()));
int widthTextMax = 0, widthLine, int widthTextMax = 0, widthLine,
@@ -138,36 +122,16 @@ void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
} }
} }
int ww, hh; return wxSize(widthTextMax, heightTextTotal);
GetSize(&ww, &hh);
// If we're prepared to use the existing width, then...
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
{
actualWidth = ww;
}
else if (width == -1)
{
actualWidth = widthTextMax;
}
// If we're prepared to use the existing height, then...
if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
{
actualHeight = hh;
}
else if (height == -1)
{
actualHeight = heightTextTotal;
}
MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE);
} }
void wxStaticText::SetLabel(const wxString& label) void wxStaticText::SetLabel(const wxString& label)
{ {
SetWindowText(GetHwnd(), label); SetWindowText(GetHwnd(), label);
// adjust the size of the window to fit to the label (this behaviour is
// backward compatible and generally makes sense but we might want to still
// provide the user a way to disable it) (VZ)
DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
} }

View File

@@ -336,53 +336,15 @@ void wxTextCtrl::SetValue(const wxString& value)
AdjustSpaceLimit(); AdjustSpaceLimit();
} }
void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxSize wxTextCtrl::DoGetBestSize()
{ {
int currentX, currentY; int cx, cy;
GetPosition(&currentX, &currentY); wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
int x1 = x;
int y1 = y;
int w1 = width;
int h1 = height;
if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) int wText = DEFAULT_ITEM_WIDTH;
x1 = currentX; int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
y1 = currentY;
AdjustForParentClientOrigin(x1, y1, sizeFlags); return wxSize(wText, hText);
int cx; // button font dimensions
int cy;
wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
int control_width, control_height, control_x, control_y;
// If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
{
GetSize(&w1, &h1);
}
// Deal with default size (using -1 values)
if (w1<=0)
w1 = DEFAULT_ITEM_WIDTH;
control_x = x1;
control_y = y1;
control_width = w1;
control_height = h1;
// Calculations may have made text size too small
if (control_height <= 0)
control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if (control_width <= 0)
control_width = DEFAULT_ITEM_WIDTH;
MoveWindow(GetHwnd(), (int)control_x, (int)control_y,
(int)control_width, (int)control_height, TRUE);
} }
// Clipboard operations // Clipboard operations
@@ -759,18 +721,23 @@ void wxTextCtrl::ShowPosition(long pos)
int wxTextCtrl::GetLineLength(long lineNo) const int wxTextCtrl::GetLineLength(long lineNo) const
{ {
long charIndex = XYToPosition(0, lineNo); long charIndex = XYToPosition(0, lineNo);
HWND hWnd = GetHwnd(); int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
int len = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0);
return len; return len;
} }
wxString wxTextCtrl::GetLineText(long lineNo) const wxString wxTextCtrl::GetLineText(long lineNo) const
{ {
HWND hWnd = GetHwnd(); size_t len = (size_t)GetLineLength(lineNo);
*(WORD *)wxBuffer = 512; char *buf = (char *)malloc(len);
int noChars = (int)SendMessage(hWnd, EM_GETLINE, (WPARAM)lineNo, (LPARAM)wxBuffer); *(WORD *)buf = len;
wxBuffer[noChars] = 0; int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
return wxString(wxBuffer); buf[noChars] = 0;
wxString str(buf);
free(buf);
return str;
} }
bool wxTextCtrl::CanCopy() const bool wxTextCtrl::CanCopy() const

View File

@@ -1172,35 +1172,80 @@ void wxWindow::DoGetClientSize(int *x, int *y) const
*y = rect.bottom; *y = rect.bottom;
} }
// set the size of the window: if the dimensions are positive, just use them,
// but if any of them is equal to -1, it means that we must find the value for
// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
// which case -1 is a valid value for x and y)
//
// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
// the width/height to best suit our contents, otherwise we reuse the current
// width/height
void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{ {
// get the current size and position...
int currentX, currentY; int currentX, currentY;
GetPosition(&currentX, &currentY); GetPosition(&currentX, &currentY);
int currentW,currentH; int currentW,currentH;
GetSize(&currentW, &currentH); GetSize(&currentW, &currentH);
if ( x == currentX && y == currentY && width == currentW && height == currentH ) // ... and don't do anything (avoiding flicker) if it's already ok
if ( x == currentX && y == currentY &&
width == currentW && height == currentH )
{
return; return;
}
int actualWidth = width;
int actualHeight = height;
int actualX = x;
int actualY = y;
if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
actualX = currentX; x = currentX;
if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
actualY = currentY; y = currentY;
AdjustForParentClientOrigin(actualX, actualY, sizeFlags); AdjustForParentClientOrigin(x, y, sizeFlags);
wxSize size(-1, -1);
if ( width == -1 ) if ( width == -1 )
actualWidth = currentW; {
if ( height == -1 ) if ( sizeFlags && wxSIZE_AUTO_WIDTH )
actualHeight = currentH; {
size = DoGetBestSize();
width = size.x;
}
else
{
// just take the current one
width = currentW;
}
}
HWND hWnd = GetHwnd(); if ( height == -1 )
if ( hWnd ) {
MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE); if ( sizeFlags && wxSIZE_AUTO_HEIGHT )
{
if ( size.x == -1 )
{
size= DoGetBestSize();
}
//else: already called DoGetBestSize() above
height = size.y;
}
else
{
// just take the current one
height = currentH;
}
}
if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
{
wxLogLastError("MoveWindow");
}
}
// for a generic window there is no natural best size - just use the current one
wxSize wxWindow::DoGetBestSize()
{
return GetSize();
} }
void wxWindow::DoSetClientSize(int width, int height) void wxWindow::DoSetClientSize(int width, int height)
@@ -1316,7 +1361,7 @@ void wxWindow::GetTextExtent(const wxString& string,
SIZE sizeRect; SIZE sizeRect;
TEXTMETRIC tm; TEXTMETRIC tm;
GetTextExtentPoint(dc, (const wxChar *)string, (int)string.Length(), &sizeRect); GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
GetTextMetrics(dc, &tm); GetTextMetrics(dc, &tm);
if ( fontToUse && fnt && hfontOld ) if ( fontToUse && fnt && hfontOld )