From a3a13581dd97d6923fb035a223560974b2bc270e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2000 23:12:36 +0000 Subject: [PATCH] 1. wxRadioBox event generation fixed 2. significantly expanded and enchanced listbox sample 3. wxTextCtrl::IsModified() implemented 4. wxRadioBox button layout fixed once again 5. wxTextCtrl::SetValue() refresh bug fixed 6. wxListCtrl doesn't keep invalid selection after Delete() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO | 2 + include/wx/univ/listbox.h | 1 + include/wx/univ/radiobox.h | 11 ++++ include/wx/univ/setup.h | 2 +- include/wx/univ/window.h | 3 + samples/listbox/lboxtest.cpp | 112 ++++++++++++++++++++++++++++++----- samples/univ/univ.cpp | 2 +- src/common/string.cpp | 2 + src/msw/frame.cpp | 9 +++ src/univ/listbox.cpp | 15 +++-- src/univ/radiobox.cpp | 75 ++++++++++++++++++++--- src/univ/textctrl.cpp | 19 ++++-- src/univ/themes/win32.cpp | 34 +++++++++-- src/univ/winuniv.cpp | 23 +++++-- 14 files changed, 267 insertions(+), 43 deletions(-) diff --git a/TODO b/TODO index 79a04ec86a..5ba5440349 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,8 @@ TODO wxTextCtrl * display corrupted when typing text in quickly +* text ctrl display pb when text is truncated +* listbox: horz scrollbar doesn't appear All diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index 4957a2b40a..18e46d066e 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -184,6 +184,7 @@ protected: // refresh the given item(s) or everything void RefreshItems(int from, int count); void RefreshItem(int n); + void RefreshFromItemToEnd(int n); void RefreshAll(); // send an event of the given type diff --git a/include/wx/univ/radiobox.h b/include/wx/univ/radiobox.h index 0cab16a50e..eb723e274c 100644 --- a/include/wx/univ/radiobox.h +++ b/include/wx/univ/radiobox.h @@ -62,6 +62,8 @@ public: const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr); + virtual ~wxRadioBox(); + // implement wxRadioBox interface virtual void SetSelection(int n); virtual int GetSelection() const; @@ -80,8 +82,13 @@ public: virtual void SetLabel(const wxString& label); // wxUniversal-only methods + + // another Append() version void Append(int n, const wxString *choices); + // implementation only: called by wxRadioHookHandler + void OnRadioButton(wxEvent& event); + protected: // override the base class methods dealing with window positioning/sizing // as we must move/size the buttons as well @@ -115,6 +122,10 @@ protected: // all radio buttons wxArrayRadioButtons m_buttons; + // the event handler which is used to translate radiobutton events into + // radiobox one + wxEvtHandler *m_evtRadioHook; + private: DECLARE_DYNAMIC_CLASS(wxRadioBox) }; diff --git a/include/wx/univ/setup.h b/include/wx/univ/setup.h index aed56d9911..a4bc7f6a57 100644 --- a/include/wx/univ/setup.h +++ b/include/wx/univ/setup.h @@ -125,7 +125,7 @@ #define wxUSE_HELP 0 #define wxUSE_MS_HTML_HELP 0 #define wxUSE_RESOURCES 0 -#define wxUSE_CONSTRAINTS 0 +#define wxUSE_CONSTRAINTS 1 #define wxUSE_CLIPBOARD 1 #define wxUSE_DATAOBJ 1 #define wxUSE_SPLINES 0 diff --git a/include/wx/univ/window.h b/include/wx/univ/window.h index 5fead5a626..9cc66d02a3 100644 --- a/include/wx/univ/window.h +++ b/include/wx/univ/window.h @@ -163,6 +163,9 @@ public: virtual void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL); + // we refresh the window when it is dis/enabled + virtual bool Enable(bool enable = TRUE); + // remember that the font/colour was changed virtual bool SetBackgroundColour(const wxColour& colour); virtual bool SetForegroundColour(const wxColour& colour); diff --git a/samples/listbox/lboxtest.cpp b/samples/listbox/lboxtest.cpp index af76209008..f204ec9ddf 100644 --- a/samples/listbox/lboxtest.cpp +++ b/samples/listbox/lboxtest.cpp @@ -7,6 +7,14 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +/* + Current bugs: + + 1. horz scrollbar doesn't appear in listbox + +2. truncating text ctrl doesn't update display + +3. deleting last listbox item doesn't update display + */ + // ============================================================================ // declarations // ============================================================================ @@ -61,9 +69,12 @@ enum LboxTest_Reset = 100, LboxTest_Create, LboxTest_Add, + LboxTest_AddText, LboxTest_AddSeveral, LboxTest_Clear, - LboxTest_Delete + LboxTest_Delete, + LboxTest_DeleteText, + LboxTest_DeleteSel }; // ---------------------------------------------------------------------------- @@ -95,15 +106,20 @@ protected: void OnButtonReset(wxCommandEvent& event); void OnButtonCreate(wxCommandEvent& event); void OnButtonDelete(wxCommandEvent& event); + void OnButtonDeleteSel(wxCommandEvent& event); void OnButtonClear(wxCommandEvent& event); void OnButtonAdd(wxCommandEvent& event); void OnButtonAddSeveral(wxCommandEvent& event); + void OnListbox(wxCommandEvent& event); + void OnCheckOrRadioBox(wxCommandEvent& event); + void OnUpdateUIAddSeveral(wxUpdateUIEvent& event); void OnUpdateUICreateButton(wxUpdateUIEvent& event); void OnUpdateUIClearButton(wxUpdateUIEvent& event); void OnUpdateUIDeleteButton(wxUpdateUIEvent& event); + void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event); // reset the listbox parameters void Reset(); @@ -147,9 +163,9 @@ protected: wxListBox *m_lbox; wxSizer *m_sizerLbox; - // the buttons to reset the settings and recreated the box - wxButton *m_btnReset, - *m_btnCreate; + // the text entries for "Add string" and "Delete" buttons + wxTextCtrl *m_textAdd, + *m_textDelete; private: // any class wishing to process wxWindows events must use this macro @@ -175,16 +191,23 @@ BEGIN_EVENT_TABLE(LboxTestFrame, wxFrame) EVT_BUTTON(LboxTest_Reset, LboxTestFrame::OnButtonReset) EVT_BUTTON(LboxTest_Create, LboxTestFrame::OnButtonCreate) EVT_BUTTON(LboxTest_Delete, LboxTestFrame::OnButtonDelete) + EVT_BUTTON(LboxTest_DeleteSel, LboxTestFrame::OnButtonDeleteSel) EVT_BUTTON(LboxTest_Clear, LboxTestFrame::OnButtonClear) EVT_BUTTON(LboxTest_Add, LboxTestFrame::OnButtonAdd) EVT_BUTTON(LboxTest_AddSeveral, LboxTestFrame::OnButtonAddSeveral) + EVT_TEXT_ENTER(LboxTest_AddText, LboxTestFrame::OnButtonAdd) + EVT_TEXT_ENTER(LboxTest_DeleteText, LboxTestFrame::OnButtonDelete) + EVT_UPDATE_UI_RANGE(LboxTest_Reset, LboxTest_Create, LboxTestFrame::OnUpdateUICreateButton) + EVT_UPDATE_UI(LboxTest_AddSeveral, LboxTestFrame::OnUpdateUIAddSeveral) EVT_UPDATE_UI(LboxTest_Clear, LboxTestFrame::OnUpdateUIClearButton) EVT_UPDATE_UI(LboxTest_Delete, LboxTestFrame::OnUpdateUIDeleteButton) + EVT_UPDATE_UI(LboxTest_DeleteSel, LboxTestFrame::OnUpdateUIDeleteSelButton) + EVT_LISTBOX(-1, LboxTestFrame::OnListbox) EVT_CHECKBOX(-1, LboxTestFrame::OnCheckOrRadioBox) EVT_RADIOBOX(-1, LboxTestFrame::OnCheckOrRadioBox) END_EVENT_TABLE() @@ -233,7 +256,7 @@ LboxTestFrame::LboxTestFrame(const wxString& title) */ wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL), *sizerUp = new wxBoxSizer(wxHORIZONTAL), - *sizerLeft = new wxBoxSizer(wxVERTICAL), + *sizerLeft, *sizerRight = new wxBoxSizer(wxVERTICAL); // upper left pane @@ -283,12 +306,26 @@ LboxTestFrame::LboxTestFrame(const wxString& title) wxStaticBox *box2 = new wxStaticBox(this, -1, _T("&Change listbox contents")); wxSizer *sizerDown = new wxStaticBoxSizer(box2, wxVERTICAL); - btn = new wxButton(this, LboxTest_Add, _T("&Add string...")); + wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); + btn = new wxButton(this, LboxTest_Add, _T("&Add this string")); + m_textAdd = new wxTextCtrl(this, LboxTest_AddText, _T("test string 0")); + sizerRow->Add(btn, 0, wxRIGHT, 5); + sizerRow->Add(m_textAdd, 1, wxLEFT, 5); + sizerDown->Add(sizerRow, 0, wxALL | wxGROW, 5); + + btn = new wxButton(this, LboxTest_AddSeveral, _T("&Insert a few strings")); sizerDown->Add(btn, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, LboxTest_AddSeveral, _T("Add a &few strings")); - sizerDown->Add(btn, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, LboxTest_Delete, _T("&Delete")); + + sizerRow = new wxBoxSizer(wxHORIZONTAL); + btn = new wxButton(this, LboxTest_Delete, _T("&Delete this item")); + m_textDelete = new wxTextCtrl(this, LboxTest_DeleteText, _T("")); + sizerRow->Add(btn, 0, wxRIGHT, 5); + sizerRow->Add(m_textDelete, 1, wxLEFT, 5); + sizerDown->Add(sizerRow, 0, wxALL | wxGROW, 5); + + btn = new wxButton(this, LboxTest_DeleteSel, _T("Delete &selection")); sizerDown->Add(btn, 0, wxALL | wxGROW, 5); + btn = new wxButton(this, LboxTest_Clear, _T("&Clear")); sizerDown->Add(btn, 0, wxALL | wxGROW, 5); @@ -297,6 +334,7 @@ LboxTestFrame::LboxTestFrame(const wxString& title) // final initialization Reset(); + m_dirty = FALSE; SetAutoLayout(TRUE); SetSizer(sizerTop); @@ -341,6 +379,13 @@ void LboxTestFrame::CreateLbox() case LboxSel_Multiple: flags |= wxLB_MULTIPLE; break; } + if ( m_chkVScroll->GetValue() ) + flags |= wxLB_ALWAYS_SB; + if ( m_chkHScroll->GetValue() ) + flags |= wxLB_HSCROLL; + if ( m_chkSort->GetValue() ) + flags |= wxLB_SORT; + wxArrayString items; if ( m_lbox ) { @@ -360,6 +405,7 @@ void LboxTestFrame::CreateLbox() flags); m_lbox->Set(items); m_sizerLbox->Add(m_lbox, 1, wxGROW | wxALL, 5); + m_sizerLbox->Layout(); m_dirty = FALSE; } @@ -368,17 +414,29 @@ void LboxTestFrame::CreateLbox() // event handlers // ---------------------------------------------------------------------------- -void LboxTestFrame::OnButtonReset(wxCommandEvent& event) +void LboxTestFrame::OnButtonReset(wxCommandEvent& WXUNUSED(event)) { Reset(); } -void LboxTestFrame::OnButtonCreate(wxCommandEvent& event) +void LboxTestFrame::OnButtonCreate(wxCommandEvent& WXUNUSED(event)) { CreateLbox(); } -void LboxTestFrame::OnButtonDelete(wxCommandEvent& event) +void LboxTestFrame::OnButtonDelete(wxCommandEvent& WXUNUSED(event)) +{ + unsigned long n; + if ( !m_textDelete->GetValue().ToULong(&n) || + (n >= (unsigned)m_lbox->GetCount()) ) + { + return; + } + + m_lbox->Delete(n); +} + +void LboxTestFrame::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event)) { wxArrayInt selections; int n = m_lbox->GetSelections(selections); @@ -396,7 +454,15 @@ void LboxTestFrame::OnButtonClear(wxCommandEvent& event) void LboxTestFrame::OnButtonAdd(wxCommandEvent& event) { static size_t s_item = 0; - m_lbox->Append(wxString::Format(_T("test item %u"), ++s_item)); + + wxString s = m_textAdd->GetValue(); + if ( !m_textAdd->IsModified() ) + { + // update the default string + m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item)); + } + + m_lbox->Append(s); } void LboxTestFrame::OnButtonAddSeveral(wxCommandEvent& event) @@ -404,7 +470,7 @@ void LboxTestFrame::OnButtonAddSeveral(wxCommandEvent& event) wxArrayString items; items.Add(_T("First")); items.Add(_T("another one")); - items.Add(_T("and the last (very very very very very long) one")); + items.Add(_T("and the last (very very very very very very very very very very long) one")); m_lbox->InsertItems(items, 0); } @@ -414,6 +480,13 @@ void LboxTestFrame::OnUpdateUICreateButton(wxUpdateUIEvent& event) } void LboxTestFrame::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) +{ + unsigned long n; + event.Enable(m_textDelete->GetValue().ToULong(&n) && + (n < (unsigned)m_lbox->GetCount())); +} + +void LboxTestFrame::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) { wxArrayInt selections; event.Enable(m_lbox->GetSelections(selections) != 0); @@ -424,7 +497,18 @@ void LboxTestFrame::OnUpdateUIClearButton(wxUpdateUIEvent& event) event.Enable(m_lbox->GetCount() != 0); } +void LboxTestFrame::OnUpdateUIAddSeveral(wxUpdateUIEvent& event) +{ + event.Enable(!(m_lbox->GetWindowStyle() & wxLB_SORT)); +} + +void LboxTestFrame::OnListbox(wxCommandEvent& event) +{ + m_textDelete->SetValue(wxString::Format(_T("%ld"), event.GetInt())); +} + void LboxTestFrame::OnCheckOrRadioBox(wxCommandEvent& event) { m_dirty = TRUE; } + diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index 40fc9635af..a0d7277c9c 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -53,7 +53,7 @@ #include "wx/univ/theme.h" -#define TEST_TEXT_ONLY +//#define TEST_TEXT_ONLY //#define DEBUG_SCROLL //#define DEBUG_LISTBOX diff --git a/src/common/string.cpp b/src/common/string.cpp index d97e47a0d1..1ac85f09b6 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1819,6 +1819,8 @@ wxArrayString& wxArrayString::operator=(const wxArrayString& src) Copy(src); + m_autoSort = src.m_autoSort; + return *this; } diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 64820c7467..599fa6f672 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -55,6 +55,11 @@ #include "wx/menuitem.h" #include "wx/log.h" +#ifdef __WXUNIVERSAL__ + #include "wx/univ/theme.h" + #include "wx/univ/colschem.h" +#endif // __WXUNIVERSAL__ + // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -142,7 +147,11 @@ bool wxFrame::Create(wxWindow *parent, m_frameStatusBar = NULL; #endif // wxUSE_STATUSBAR +#ifdef __WXUNIVERSAL__ + SetBackgroundColour(wxTHEME_COLOUR(CONTROL)); +#else // !__WXUNIVERSAL__ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); +#endif // __WXUNIVERSAL__/!__WXUNIVERSAL__ if ( id > -1 ) m_windowId = id; diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index ca729c2d3a..7d3a53fda7 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -142,7 +142,7 @@ int wxListBox::DoAppend(const wxString& item) } } - RefreshItem(m_strings.GetCount() - 1); + RefreshFromItemToEnd(index); return index; } @@ -171,7 +171,7 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos) // note that we have to refresh all the items after the ones we inserted, // not just these items - RefreshItems(pos, GetCount() - pos); + RefreshFromItemToEnd(pos); } void wxListBox::DoSetItems(const wxArrayString& items, void **clientData) @@ -263,6 +263,10 @@ void wxListBox::Delete(int n) { wxCHECK_RET( n < GetCount(), _T("invalid index in wxListBox::Delete") ); + // do it before removing the index as otherwise the last item will not be + // refreshed (as GetCount() will be decremented) + RefreshFromItemToEnd(n); + m_strings.RemoveAt(n); if ( HasClientObjectData() ) @@ -273,8 +277,6 @@ void wxListBox::Delete(int n) m_itemsClientData.RemoveAt(n); m_updateScrollbarY = TRUE; - - RefreshItems(n, GetCount() - n); } // ---------------------------------------------------------------------------- @@ -363,6 +365,11 @@ void wxListBox::Refresh(bool eraseBackground, const wxRect *rect) wxControl::Refresh(eraseBackground, rect); } +void wxListBox::RefreshFromItemToEnd(int from) +{ + RefreshItems(from, GetCount() - from); +} + void wxListBox::RefreshItems(int from, int count) { switch ( m_updateCount ) diff --git a/src/univ/radiobox.cpp b/src/univ/radiobox.cpp index 4c615ab5e8..35b5d33e01 100644 --- a/src/univ/radiobox.cpp +++ b/src/univ/radiobox.cpp @@ -51,6 +51,31 @@ static const int BUTTON_BORDER_Y = 0; static const int BOX_BORDER_X = 0; static const int BOX_BORDER_Y = 0; +// ---------------------------------------------------------------------------- +// wxRadioBox event handler +// ---------------------------------------------------------------------------- + +class wxRadioHookHandler : public wxEvtHandler +{ +public: + wxRadioHookHandler(wxRadioBox *radio) { m_radio = radio; } + + virtual bool ProcessEvent(wxEvent& event) + { + // we intercept the command events from radio buttons + if ( event.GetEventType() == wxEVT_COMMAND_RADIOBUTTON_SELECTED ) + { + m_radio->OnRadioButton(event); + } + + // just pass it on + return GetNextHandler()->ProcessEvent(event); + } + +private: + wxRadioBox *m_radio; +}; + // ============================================================================ // implementation // ============================================================================ @@ -98,6 +123,20 @@ bool wxRadioBox::Create(wxWindow *parent, return TRUE; } +wxRadioBox::~wxRadioBox() +{ + // remove the event handlers we pushed on them from all buttons + size_t count = m_buttons.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + m_buttons[n]->PopEventHandler(TRUE /* delete it */); + } +} + +// ---------------------------------------------------------------------------- +// wxRadioBox init +// ---------------------------------------------------------------------------- + void wxRadioBox::SetMajorDim(int majorDim) { m_majorDim = majorDim; @@ -125,10 +164,16 @@ void wxRadioBox::Append(int count, const wxString *choices) m_buttons.Alloc(count); for ( int n = 0; n < count; n++ ) { - // make the first button in the box the start of new group - m_buttons.Add(new wxRadioButton(parent, -1, choices[n], - wxDefaultPosition, wxDefaultSize, - n == 0 ? wxRB_GROUP : 0)); + // make the first button in the box the start of new group by giving it + // wxRB_GROUP style + wxRadioButton *btn = new wxRadioButton(parent, -1, choices[n], + wxDefaultPosition, + wxDefaultSize, + n == 0 ? wxRB_GROUP : 0); + + // we want to get the events from the buttons to translate it into + btn->PushEventHandler(new wxRadioHookHandler(this)); + m_buttons.Add(btn); } } @@ -151,6 +196,20 @@ int wxRadioBox::GetSelection() const return m_selection; } +void wxRadioBox::OnRadioButton(wxEvent& event) +{ + int n = m_buttons.Index((wxRadioButton *)event.GetEventObject()); + wxCHECK_RET( n != wxNOT_FOUND, _T("click from alien radio button") ); + + m_selection = n; + + wxCommandEvent event2(wxEVT_COMMAND_RADIOBOX_SELECTED, GetId()); + InitCommandEvent(event2); + event2.SetInt(n); + event2.SetString(GetString(n)); + Command(event2); +} + // ---------------------------------------------------------------------------- // methods forwarded to the buttons // ---------------------------------------------------------------------------- @@ -279,10 +338,10 @@ void wxRadioBox::DoMoveWindow(int x0, int y0, int width, int height) if ( GetWindowStyle() & wxRA_SPECIFY_COLS ) { - // from to to bottom - if ( (n == 0) || (n % m_numRows) ) + // from top to bottom + if ( (n + 1) % m_numRows ) { - // continue (or start if n == 0) in this column + // continue in this column y += sizeBtn.y; } else @@ -295,7 +354,7 @@ void wxRadioBox::DoMoveWindow(int x0, int y0, int width, int height) else // wxRA_SPECIFY_ROWS: mirror the code above { // from left to right - if ( (n == 0) || (n % m_numCols) ) + if ( (n + 1) % m_numCols ) { // continue in this row x += sizeBtn.x; diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index ca2c5b08fc..97b08aeefd 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -181,17 +181,21 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text) // remember it for later use wxCoord startNewText = GetTextWidth(valueNew); - // if we really replace something, refresh till the end of line as all - // remaining text in it is affected, but if we just added some text to the - // end of line, we only need to refresh the area occupied by this text - // refresh to the end of the line - wxCoord widthNewText; - valueNew += text; if ( (size_t)to < m_value.length() ) { valueNew += m_value.c_str() + (size_t)to; + } + // OPT: is the following really ok? not sure any more now at 2 am... + + // we usually refresh till the end of line except of the most common case + // when some text is appended to the end of the string in which case we + // refresh just it + wxCoord widthNewText; + + if ( (size_t)from < m_value.length() ) + { // refresh till the end of line widthNewText = 0; } @@ -1711,6 +1715,9 @@ bool wxTextCtrl::PerformAction(const wxControlAction& actionOrig, InitCommandEvent(event); event.SetString(GetValue()); GetEventHandler()->ProcessEvent(event); + + // as the text changed... + m_isModified = TRUE; } return TRUE; diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 2cdf5bbcb4..176bf3551d 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -45,7 +45,7 @@ // constants // ---------------------------------------------------------------------------- -static const int BORDER_THICKNESS = 20; +static const int BORDER_THICKNESS = 2; // ---------------------------------------------------------------------------- // wxWin32Renderer: draw the GUI elements in Win32 style @@ -175,11 +175,9 @@ public: { return 0; } virtual wxRect GetTextTotalArea(const wxTextCtrl *text, - const wxRect& rect) - { wxRect rectTotal = rect; rectTotal.Inflate(10); return rectTotal; } + const wxRect& rect); virtual wxRect GetTextClientArea(const wxTextCtrl *text, - const wxRect& rect) - { wxRect rectText = rect; rectText.Inflate(-10); return rectText; } + const wxRect& rect); protected: // common part of DrawLabel() and DrawItem() @@ -1720,6 +1718,32 @@ int wxWin32Renderer::PixelToScrollbar(const wxScrollBar *scrollbar, return StandardPixelToScrollbar(scrollbar, coord, m_sizeScrollbarArrow); } +// ---------------------------------------------------------------------------- +// text control geometry +// ---------------------------------------------------------------------------- + +wxRect wxWin32Renderer::GetTextTotalArea(const wxTextCtrl *text, + const wxRect& rect) +{ + // this is what Windows does + wxRect rectTotal = rect; + rectTotal.Inflate(1); + rectTotal.height++; + + return rectTotal; +} + +wxRect wxWin32Renderer::GetTextClientArea(const wxTextCtrl *text, + const wxRect& rect) +{ + // undo GetTextTotalArea() + wxRect rectText = rect; + rectText.height--; + rectText.Inflate(-1); + + return rectText; +} + // ---------------------------------------------------------------------------- // size adjustments // ---------------------------------------------------------------------------- diff --git a/src/univ/winuniv.cpp b/src/univ/winuniv.cpp index fd2a4df6ea..187818198e 100644 --- a/src/univ/winuniv.cpp +++ b/src/univ/winuniv.cpp @@ -302,6 +302,21 @@ void wxWindow::Refresh(bool eraseBackground, const wxRect *rectClient) // state flags // ---------------------------------------------------------------------------- +bool wxWindow::Enable(bool enable) +{ + if ( !wxWindowBase::Enable(enable) ) + return FALSE; + + if ( m_renderer ) + { + // a window with renderer is drawn by ourselves and it has to be + // refreshed to reflect its new status + Refresh(); + } + + return TRUE; +} + bool wxWindow::IsFocused() const { wxWindow *self = wxConstCast(this, wxWindow); @@ -423,7 +438,7 @@ void wxWindow::DoGetClientSize(int *width, int *height) const // if we don't have scrollbar or if it is outside the border (and not // blended into it), take account of the right border as well - if ( !m_scrollbarVert || !inside ) + if ( !m_scrollbarVert || inside ) w -= rectBorder.width; // and always account for the left border @@ -435,7 +450,7 @@ void wxWindow::DoGetClientSize(int *width, int *height) const if ( m_scrollbarHorz ) h -= m_scrollbarHorz->GetSize().y; - if ( !m_scrollbarHorz || !inside ) + if ( !m_scrollbarHorz || inside ) h -= rectBorder.height; *height = h - rectBorder.y; @@ -456,12 +471,12 @@ void wxWindow::DoSetClientSize(int width, int height) wxSize size = GetSize(); if ( m_scrollbarVert ) width += size.x - m_scrollbarVert->GetPosition().x; - if ( !m_scrollbarVert || !inside ) + if ( !m_scrollbarVert || inside ) width += rectBorder.width; if ( m_scrollbarHorz ) height += size.y - m_scrollbarHorz->GetPosition().y; - if ( !m_scrollbarHorz || !inside ) + if ( !m_scrollbarHorz || inside ) height += rectBorder.height; wxWindowNative::DoSetClientSize(width, height);