From 1f720ce54b509390814299b4cfc92611f5bb6169 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 20 Oct 2000 20:19:03 +0000 Subject: [PATCH] 1. wxScrollHelper can be used to scroll only parts of window 2. wxTextCtrl and wxButton size calc adjusted again git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8610 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/scrolwin.h | 19 ++++++++++++---- include/wx/univ/textctrl.h | 5 ++--- samples/listbox/lboxtest.cpp | 8 ++----- samples/text/text.cpp | 6 ++++++ samples/univ/univ.cpp | 6 +++--- src/generic/scrolwin.cpp | 33 ++++++++++++++++++++++------ src/univ/button.cpp | 1 + src/univ/files.lst | 3 ++- src/univ/textctrl.cpp | 42 +++++++++++++++++++++++++----------- 9 files changed, 87 insertions(+), 36 deletions(-) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 6c032db884..7c6fb6a5ec 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -72,12 +72,15 @@ public: virtual int CalcScrollInc(wxScrollWinEvent& event); // Normally the wxScrolledWindow will scroll itself, but in some rare - // occasions you might want it to scroll another window (e.g. a child of it - // in order to scroll only a portion the area between the scrollbars - // (spreadsheet: only cell area will move). - virtual void SetTargetWindow( wxWindow *target ); + // occasions you might want it to scroll [part of] another window (e.g. a + // child of it in order to scroll only a portion the area between the + // scrollbars (spreadsheet: only cell area will move). + virtual void SetTargetWindow(wxWindow *target); virtual wxWindow *GetTargetWindow() const; + void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; } + wxRect GetTargetRect() const { return m_rectToScroll; } + // Override this function to draw the graphic (or just process EVT_PAINT) virtual void OnDraw(wxDC& WXUNUSED(dc)) { } @@ -91,9 +94,17 @@ public: void HandleOnChar(wxKeyEvent& event); protected: + // get pointer to our scroll rect if we use it or NULL + const wxRect *GetRect() const + { + return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL; + } + wxWindow *m_win, *m_targetWindow; + wxRect m_rectToScroll; + int m_xScrollPixelsPerLine; int m_yScrollPixelsPerLine; int m_xScrollPosition; diff --git a/include/wx/univ/textctrl.h b/include/wx/univ/textctrl.h index 757cac771a..7582ba95a9 100644 --- a/include/wx/univ/textctrl.h +++ b/include/wx/univ/textctrl.h @@ -266,9 +266,8 @@ protected: // refresh the text in the given range (in text coords) in this line void RefreshColRange(long line, long start, long count); - // refresh the text from in the given line range (inclusive), if lineLast - // is -1, refresh all [visible] text after the lineFirst - void RefreshLineRange(long lineFirst, long lineLast = -1); + // refresh the text from in the given line range (inclusive) + void RefreshLineRange(long lineFirst, long lineLast); // refresh the text in the given range which can span multiple lines // (this method accepts arguments in any order) diff --git a/samples/listbox/lboxtest.cpp b/samples/listbox/lboxtest.cpp index 02902e15be..a7d69c6d0a 100644 --- a/samples/listbox/lboxtest.cpp +++ b/samples/listbox/lboxtest.cpp @@ -239,11 +239,7 @@ private: m_lbox->AppendAndEnsureVisible(msg); #else // other ports don't have this method yet m_lbox->Append(msg); - - // SetFirstItem() isn't implemented in wxGTK - #ifndef __WXGTK__ - m_lbox->SetFirstItem(m_lbox->GetCount() - 1); - #endif + m_lbox->SetFirstItem(m_lbox->GetCount() - 1); #endif } @@ -316,7 +312,7 @@ bool LboxTestApp::OnInit() frame->Show(); //wxLog::AddTraceMask(_T("listbox")); - wxLog::AddTraceMask(_T("scrollbar")); + //wxLog::AddTraceMask(_T("scrollbar")); return TRUE; } diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 03895e1d11..4a39e5c127 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -190,6 +190,7 @@ bool MyApp::OnInit() "Text wxWindows sample", 50, 50, 660, 420); frame->SetSizeHints( 500, 400 ); +#if wxUSE_MENUS wxMenu *file_menu = new wxMenu; file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C", "Clear the log window contents"); @@ -234,6 +235,7 @@ bool MyApp::OnInit() menu_bar->Append(menuText, "&Text"); frame->SetMenuBar(menu_bar); +#endif // wxUSE_MENUS frame->Show(TRUE); @@ -791,7 +793,9 @@ END_EVENT_TABLE() MyFrame::MyFrame(wxFrame *frame, const char *title, int x, int y, int w, int h) : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h) ) { +#if wxUSE_STATUSBAR CreateStatusBar(2); +#endif // wxUSE_STATUSBAR m_panel = new MyPanel( this, 10, 10, 300, 100 ); } @@ -928,7 +932,9 @@ void MyFrame::OnIdle( wxIdleEvent& event ) #endif ); +#if wxUSE_STATUSBAR SetStatusText(msg); +#endif // wxUSE_STATUSBAR } event.Skip(); } diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index 697da9beff..9456dd9d2f 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -384,7 +384,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title) new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxPoint(550, 150), wxDefaultSize); #else // TEST_TEXT_ONLY -#if 1 +#if 0 wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxPoint(10, 40)); text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, @@ -394,11 +394,11 @@ MyUnivFrame::MyUnivFrame(const wxString& title) text->SetSize(sizeText); #else wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello,\nMultiverse!"), - wxPoint(10, 10), wxDefaultSize, + wxPoint(10, 30), wxDefaultSize, wxTE_MULTILINE); #endif text->SetFocus(); - text->SetEditable(FALSE); + //text->SetEditable(FALSE); #endif // !TEST_TEXT_ONLY/TEST_TEXT_ONLY } diff --git a/src/generic/scrolwin.cpp b/src/generic/scrolwin.cpp index e6258d7af4..7cc1292503 100644 --- a/src/generic/scrolwin.cpp +++ b/src/generic/scrolwin.cpp @@ -276,20 +276,41 @@ void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event) m_yScrollPosition += nScrollInc; } + bool needsRefresh = FALSE; + int dx = 0, + dy = 0; if (orient == wxHORIZONTAL) { - if (m_xScrollingEnabled) - m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL); + if ( m_xScrollingEnabled ) + { + dx = -m_xScrollPixelsPerLine * nScrollInc; + } else - m_targetWindow->Refresh(); + { + needsRefresh = TRUE; + } } else { - if (m_yScrollingEnabled) - m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL); + if ( m_yScrollingEnabled ) + { + dy = -m_yScrollPixelsPerLine * nScrollInc; + } else - m_targetWindow->Refresh(); + { + needsRefresh = TRUE; + } } + + if ( needsRefresh ) + { + m_targetWindow->Refresh(GetRect()); + } + else + { + m_targetWindow->ScrollWindow(dx, dy, GetRect()); + } + #ifdef __WXMAC__ m_targetWindow->MacUpdateImmediately() ; #endif diff --git a/src/univ/button.cpp b/src/univ/button.cpp index bd2ddb2fb4..b926d7a9e5 100644 --- a/src/univ/button.cpp +++ b/src/univ/button.cpp @@ -31,6 +31,7 @@ #ifndef WX_PRECOMP #include "wx/dcclient.h" + #include "wx/dcscreen.h" #include "wx/button.h" #include "wx/validate.h" #endif diff --git a/src/univ/files.lst b/src/univ/files.lst index 20c255bfe9..387605dd02 100644 --- a/src/univ/files.lst +++ b/src/univ/files.lst @@ -15,12 +15,13 @@ UNIVOBJS = \ statbox.o \ statline.o \ stattext.o \ - textctrl.o \ theme.o \ gtk.o \ winuniv.o \ win32.o +#textctrl.o \ + UNIVDEPS = \ bmpbuttn.d \ button.d \ diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 52f5a9a26c..7f8e63c21b 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -438,7 +438,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text) // (4) refresh the lines: if we had replaced exactly the same number of // lines that we had before, we can just refresh these lines, // otherwise the lines below will change as well, so we have to - // refresh them too (by passing -1 as RefreshLineRange() argument) + // refresh them too if ( refreshAllBelow || (lineStart < lineEnd - 1) ) { RefreshLineRange(lineStart + 1, refreshAllBelow ? -1 : lineEnd - 1); @@ -629,9 +629,10 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text) } else { - // number of lines did change, we need to refresh everything below the - // start line - RefreshLineRange(lineStart + 1); + // number of lines did change, we need to refresh everything below + // the start line + RefreshLineRange(lineStart + 1, + wxMax(m_lines.GetCount(), countOld) - 1); // the vert scrollbar might [dis]appear m_updateScrollbarY = TRUE; @@ -1342,8 +1343,9 @@ wxSize wxTextCtrl::DoGetBestClientSize() const int wChar = GetCharWidth(), hChar = GetCharHeight(); - if ( w < wChar ) - w = 8*wChar; + int widthMin = wxMin(10*wChar, 100); + if ( w < widthMin ) + w = widthMin; if ( h < hChar ) h = hChar; @@ -1371,6 +1373,9 @@ void wxTextCtrl::UpdateTextRect() GetTextClientArea(this, wxRect(wxPoint(0, 0), GetClientSize())); + // only scroll this rect when the window is scrolled + SetTargetRect(m_rectText); + UpdateLastVisible(); } @@ -1776,12 +1781,18 @@ void wxTextCtrl::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const void wxTextCtrl::DoPrepareDC(wxDC& dc) { - // adjust the DC origin if the text is shifted + // for single line controls we only have to deal with m_ofsHorz and it's + // useless to call base class version as they don't use normal scrolling if ( m_ofsHorz ) { + // adjust the DC origin if the text is shifted wxPoint pt = dc.GetDeviceOrigin(); dc.SetDeviceOrigin(pt.x - m_ofsHorz, pt.y); } + else + { + wxScrollHelper::DoPrepareDC(dc); + } } void wxTextCtrl::UpdateMaxWidth(long line) @@ -1889,15 +1900,20 @@ void wxTextCtrl::OnIdle(wxIdleEvent& event) void wxTextCtrl::RefreshLineRange(long lineFirst, long lineLast) { - wxASSERT_MSG( (lineLast == -1) || (lineFirst <= lineLast), - _T("no lines to refresh") ); + wxASSERT_MSG( lineFirst <= lineLast, _T("no lines to refresh") ); wxRect rect; // rect.x is already 0 rect.width = m_rectText.width; wxCoord h = GetCharHeight(); rect.y = lineFirst*h; - rect.SetBottom(lineLast == -1 ? m_rectText.height : (lineLast + 1)*h); + + // don't refresh beyond the window boundary + wxCoord bottom = (lineLast + 1)*h; + if ( bottom > m_rectText.height ) + bottom = m_rectText.height; + + rect.SetBottom(bottom); RefreshTextRect(rect); } @@ -2079,11 +2095,11 @@ void wxTextCtrl::DoDrawTextInRect(wxDC& dc, const wxRect& rectUpdate) { // debugging trick to see the update rect visually #ifdef WXDEBUG_TEXT - if ( 0 ) + static int s_countUpdates = -1; + if ( s_countUpdates != -1 ) { wxWindowDC dc(this); - static int s_count = 0; - dc.SetBrush(*(++s_count % 2 ? wxRED_BRUSH : wxGREEN_BRUSH)); + dc.SetBrush(*(++s_countUpdates % 2 ? wxRED_BRUSH : wxGREEN_BRUSH)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(rectUpdate); }