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);
// 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;

View File

@@ -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)

View File

@@ -239,12 +239,8 @@ 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
#endif
}
// the control we use
@@ -316,7 +312,7 @@ bool LboxTestApp::OnInit()
frame->Show();
//wxLog::AddTraceMask(_T("listbox"));
wxLog::AddTraceMask(_T("scrollbar"));
//wxLog::AddTraceMask(_T("scrollbar"));
return TRUE;
}

View File

@@ -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();
}

View File

@@ -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
}

View File

@@ -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);
else
m_targetWindow->Refresh();
if ( m_xScrollingEnabled )
{
dx = -m_xScrollPixelsPerLine * nScrollInc;
}
else
{
if (m_yScrollingEnabled)
m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);
else
m_targetWindow->Refresh();
needsRefresh = TRUE;
}
}
else
{
if ( m_yScrollingEnabled )
{
dy = -m_yScrollPixelsPerLine * nScrollInc;
}
else
{
needsRefresh = TRUE;
}
}
if ( needsRefresh )
{
m_targetWindow->Refresh(GetRect());
}
else
{
m_targetWindow->ScrollWindow(dx, dy, GetRect());
}
#ifdef __WXMAC__
m_targetWindow->MacUpdateImmediately() ;
#endif

View File

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

View File

@@ -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 \

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
// 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);
}