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
This commit is contained in:
Vadim Zeitlin
2000-10-20 20:19:03 +00:00
parent f104f965eb
commit 1f720ce54b
9 changed files with 87 additions and 36 deletions

View File

@@ -72,12 +72,15 @@ public:
virtual int CalcScrollInc(wxScrollWinEvent& event); virtual int CalcScrollInc(wxScrollWinEvent& event);
// Normally the wxScrolledWindow will scroll itself, but in some rare // 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 // occasions you might want it to scroll [part of] another window (e.g. a
// in order to scroll only a portion the area between the scrollbars // child of it in order to scroll only a portion the area between the
// (spreadsheet: only cell area will move). // scrollbars (spreadsheet: only cell area will move).
virtual void SetTargetWindow(wxWindow *target); virtual void SetTargetWindow(wxWindow *target);
virtual wxWindow *GetTargetWindow() const; 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) // Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) { } virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
@@ -91,9 +94,17 @@ public:
void HandleOnChar(wxKeyEvent& event); void HandleOnChar(wxKeyEvent& event);
protected: 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, wxWindow *m_win,
*m_targetWindow; *m_targetWindow;
wxRect m_rectToScroll;
int m_xScrollPixelsPerLine; int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine; int m_yScrollPixelsPerLine;
int m_xScrollPosition; int m_xScrollPosition;

View File

@@ -266,9 +266,8 @@ protected:
// refresh the text in the given range (in text coords) in this line // refresh the text in the given range (in text coords) in this line
void RefreshColRange(long line, long start, long count); void RefreshColRange(long line, long start, long count);
// refresh the text from in the given line range (inclusive), if lineLast // refresh the text from in the given line range (inclusive)
// is -1, refresh all [visible] text after the lineFirst void RefreshLineRange(long lineFirst, long lineLast);
void RefreshLineRange(long lineFirst, long lineLast = -1);
// refresh the text in the given range which can span multiple lines // refresh the text in the given range which can span multiple lines
// (this method accepts arguments in any order) // (this method accepts arguments in any order)

View File

@@ -239,12 +239,8 @@ private:
m_lbox->AppendAndEnsureVisible(msg); m_lbox->AppendAndEnsureVisible(msg);
#else // other ports don't have this method yet #else // other ports don't have this method yet
m_lbox->Append(msg); m_lbox->Append(msg);
// SetFirstItem() isn't implemented in wxGTK
#ifndef __WXGTK__
m_lbox->SetFirstItem(m_lbox->GetCount() - 1); m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
#endif #endif
#endif
} }
// the control we use // the control we use
@@ -316,7 +312,7 @@ bool LboxTestApp::OnInit()
frame->Show(); frame->Show();
//wxLog::AddTraceMask(_T("listbox")); //wxLog::AddTraceMask(_T("listbox"));
wxLog::AddTraceMask(_T("scrollbar")); //wxLog::AddTraceMask(_T("scrollbar"));
return TRUE; return TRUE;
} }

View File

@@ -190,6 +190,7 @@ bool MyApp::OnInit()
"Text wxWindows sample", 50, 50, 660, 420); "Text wxWindows sample", 50, 50, 660, 420);
frame->SetSizeHints( 500, 400 ); frame->SetSizeHints( 500, 400 );
#if wxUSE_MENUS
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C", file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C",
"Clear the log window contents"); "Clear the log window contents");
@@ -234,6 +235,7 @@ bool MyApp::OnInit()
menu_bar->Append(menuText, "&Text"); menu_bar->Append(menuText, "&Text");
frame->SetMenuBar(menu_bar); frame->SetMenuBar(menu_bar);
#endif // wxUSE_MENUS
frame->Show(TRUE); 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) 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) ) : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h) )
{ {
#if wxUSE_STATUSBAR
CreateStatusBar(2); CreateStatusBar(2);
#endif // wxUSE_STATUSBAR
m_panel = new MyPanel( this, 10, 10, 300, 100 ); m_panel = new MyPanel( this, 10, 10, 300, 100 );
} }
@@ -928,7 +932,9 @@ void MyFrame::OnIdle( wxIdleEvent& event )
#endif #endif
); );
#if wxUSE_STATUSBAR
SetStatusText(msg); SetStatusText(msg);
#endif // wxUSE_STATUSBAR
} }
event.Skip(); event.Skip();
} }

View File

@@ -384,7 +384,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
new wxTextCtrl(this, -1, _T("Hello, Universe!"), new wxTextCtrl(this, -1, _T("Hello, Universe!"),
wxPoint(550, 150), wxDefaultSize); wxPoint(550, 150), wxDefaultSize);
#else // TEST_TEXT_ONLY #else // TEST_TEXT_ONLY
#if 1 #if 0
wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"), wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello, Universe!"),
wxPoint(10, 40)); wxPoint(10, 40));
text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT, text->SetFont(wxFont(24, wxFONTFAMILY_DEFAULT,
@@ -394,11 +394,11 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
text->SetSize(sizeText); text->SetSize(sizeText);
#else #else
wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello,\nMultiverse!"), wxTextCtrl *text = new wxTextCtrl(this, -1, _T("Hello,\nMultiverse!"),
wxPoint(10, 10), wxDefaultSize, wxPoint(10, 30), wxDefaultSize,
wxTE_MULTILINE); wxTE_MULTILINE);
#endif #endif
text->SetFocus(); text->SetFocus();
text->SetEditable(FALSE); //text->SetEditable(FALSE);
#endif // !TEST_TEXT_ONLY/TEST_TEXT_ONLY #endif // !TEST_TEXT_ONLY/TEST_TEXT_ONLY
} }

View File

@@ -276,20 +276,41 @@ void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event)
m_yScrollPosition += nScrollInc; m_yScrollPosition += nScrollInc;
} }
bool needsRefresh = FALSE;
int dx = 0,
dy = 0;
if (orient == wxHORIZONTAL) if (orient == wxHORIZONTAL)
{ {
if ( m_xScrollingEnabled ) if ( m_xScrollingEnabled )
m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL); {
dx = -m_xScrollPixelsPerLine * nScrollInc;
}
else else
m_targetWindow->Refresh(); {
needsRefresh = TRUE;
}
} }
else else
{ {
if ( m_yScrollingEnabled ) if ( m_yScrollingEnabled )
m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL); {
else dy = -m_yScrollPixelsPerLine * nScrollInc;
m_targetWindow->Refresh();
} }
else
{
needsRefresh = TRUE;
}
}
if ( needsRefresh )
{
m_targetWindow->Refresh(GetRect());
}
else
{
m_targetWindow->ScrollWindow(dx, dy, GetRect());
}
#ifdef __WXMAC__ #ifdef __WXMAC__
m_targetWindow->MacUpdateImmediately() ; m_targetWindow->MacUpdateImmediately() ;
#endif #endif

View File

@@ -31,6 +31,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/dcclient.h" #include "wx/dcclient.h"
#include "wx/dcscreen.h"
#include "wx/button.h" #include "wx/button.h"
#include "wx/validate.h" #include "wx/validate.h"
#endif #endif

View File

@@ -15,12 +15,13 @@ UNIVOBJS = \
statbox.o \ statbox.o \
statline.o \ statline.o \
stattext.o \ stattext.o \
textctrl.o \
theme.o \ theme.o \
gtk.o \ gtk.o \
winuniv.o \ winuniv.o \
win32.o win32.o
#textctrl.o \
UNIVDEPS = \ UNIVDEPS = \
bmpbuttn.d \ bmpbuttn.d \
button.d \ button.d \

View File

@@ -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 // (4) refresh the lines: if we had replaced exactly the same number of
// lines that we had before, we can just refresh these lines, // lines that we had before, we can just refresh these lines,
// otherwise the lines below will change as well, so we have to // 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) ) if ( refreshAllBelow || (lineStart < lineEnd - 1) )
{ {
RefreshLineRange(lineStart + 1, refreshAllBelow ? -1 : lineEnd - 1); RefreshLineRange(lineStart + 1, refreshAllBelow ? -1 : lineEnd - 1);
@@ -629,9 +629,10 @@ void wxTextCtrl::Replace(long from, long to, const wxString& text)
} }
else else
{ {
// number of lines did change, we need to refresh everything below the // number of lines did change, we need to refresh everything below
// start line // the start line
RefreshLineRange(lineStart + 1); RefreshLineRange(lineStart + 1,
wxMax(m_lines.GetCount(), countOld) - 1);
// the vert scrollbar might [dis]appear // the vert scrollbar might [dis]appear
m_updateScrollbarY = TRUE; m_updateScrollbarY = TRUE;
@@ -1342,8 +1343,9 @@ wxSize wxTextCtrl::DoGetBestClientSize() const
int wChar = GetCharWidth(), int wChar = GetCharWidth(),
hChar = GetCharHeight(); hChar = GetCharHeight();
if ( w < wChar ) int widthMin = wxMin(10*wChar, 100);
w = 8*wChar; if ( w < widthMin )
w = widthMin;
if ( h < hChar ) if ( h < hChar )
h = hChar; h = hChar;
@@ -1371,6 +1373,9 @@ void wxTextCtrl::UpdateTextRect()
GetTextClientArea(this, GetTextClientArea(this,
wxRect(wxPoint(0, 0), GetClientSize())); wxRect(wxPoint(0, 0), GetClientSize()));
// only scroll this rect when the window is scrolled
SetTargetRect(m_rectText);
UpdateLastVisible(); UpdateLastVisible();
} }
@@ -1776,12 +1781,18 @@ void wxTextCtrl::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
void wxTextCtrl::DoPrepareDC(wxDC& dc) 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 ) if ( m_ofsHorz )
{ {
// adjust the DC origin if the text is shifted
wxPoint pt = dc.GetDeviceOrigin(); wxPoint pt = dc.GetDeviceOrigin();
dc.SetDeviceOrigin(pt.x - m_ofsHorz, pt.y); dc.SetDeviceOrigin(pt.x - m_ofsHorz, pt.y);
} }
else
{
wxScrollHelper::DoPrepareDC(dc);
}
} }
void wxTextCtrl::UpdateMaxWidth(long line) void wxTextCtrl::UpdateMaxWidth(long line)
@@ -1889,15 +1900,20 @@ void wxTextCtrl::OnIdle(wxIdleEvent& event)
void wxTextCtrl::RefreshLineRange(long lineFirst, long lineLast) void wxTextCtrl::RefreshLineRange(long lineFirst, long lineLast)
{ {
wxASSERT_MSG( (lineLast == -1) || (lineFirst <= lineLast), wxASSERT_MSG( lineFirst <= lineLast, _T("no lines to refresh") );
_T("no lines to refresh") );
wxRect rect; wxRect rect;
// rect.x is already 0 // rect.x is already 0
rect.width = m_rectText.width; rect.width = m_rectText.width;
wxCoord h = GetCharHeight(); wxCoord h = GetCharHeight();
rect.y = lineFirst*h; 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); RefreshTextRect(rect);
} }
@@ -2079,11 +2095,11 @@ void wxTextCtrl::DoDrawTextInRect(wxDC& dc, const wxRect& rectUpdate)
{ {
// debugging trick to see the update rect visually // debugging trick to see the update rect visually
#ifdef WXDEBUG_TEXT #ifdef WXDEBUG_TEXT
if ( 0 ) static int s_countUpdates = -1;
if ( s_countUpdates != -1 )
{ {
wxWindowDC dc(this); wxWindowDC dc(this);
static int s_count = 0; dc.SetBrush(*(++s_countUpdates % 2 ? wxRED_BRUSH : wxGREEN_BRUSH));
dc.SetBrush(*(++s_count % 2 ? wxRED_BRUSH : wxGREEN_BRUSH));
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rectUpdate); dc.DrawRectangle(rectUpdate);
} }