diff --git a/samples/richedit/wxllist.cpp b/samples/richedit/wxllist.cpp index 600b7d60ff..e33fcc9bd8 100644 --- a/samples/richedit/wxllist.cpp +++ b/samples/richedit/wxllist.cpp @@ -472,7 +472,7 @@ wxLayoutStyleInfo::wxLayoutStyleInfo(int ifamily, m_fg_valid = fg != 0; m_bg_valid = bg != 0; m_fg = m_fg_valid ? *fg : *wxBLACK; - m_bg = m_fg_valid ? *bg : *wxWHITE; + m_bg = m_bg_valid ? *bg : *wxWHITE; } #define COPY_SI_(what) if(right.what != -1) what = right.what; diff --git a/samples/richedit/wxlwindow.cpp b/samples/richedit/wxlwindow.cpp index 7b00168c44..0745527116 100644 --- a/samples/richedit/wxlwindow.cpp +++ b/samples/richedit/wxlwindow.cpp @@ -84,6 +84,8 @@ static const int Y_SCROLL_PAGE = 20; // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow) + EVT_SIZE (wxLayoutWindow::OnSize) + EVT_PAINT (wxLayoutWindow::OnPaint) EVT_CHAR (wxLayoutWindow::OnChar) @@ -159,6 +161,11 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent) EnableScrolling(true, true); m_maxx = max.x + X_SCROLL_PAGE; m_maxy = max.y + Y_SCROLL_PAGE; + + // no scrollbars initially (BTW, why then we do all the stuff above?) + m_hasHScrollbar = + m_hasVScrollbar = false; + m_Selecting = false; #ifdef WXLAYOUT_USE_CARET @@ -333,6 +340,10 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) } break; + case WXLOWIN_MENU_RCLICK: + // remove the selection if mouse click is outside it (TODO) + break; + case WXLOWIN_MENU_DBLCLICK: // select a word under cursor m_llist->MoveCursorTo(cursorPos); @@ -828,17 +839,35 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) } } +void +wxLayoutWindow::OnSize(wxSizeEvent &event) +{ + ResizeScrollbars(); + + event.Skip(); +} + // change the range and position of scrollbars void wxLayoutWindow::ResizeScrollbars(bool exact) { wxPoint max = m_llist->GetSize(); + wxSize size = GetClientSize(); WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)", (long int)max.x, (long int) max.y)); + // in the absence of scrollbars we should compare with the client size + if ( !m_hasHScrollbar ) + m_maxx = size.x - WXLO_ROFFSET; + if ( !m_hasVScrollbar ) + m_maxy = size.y - WXLO_BOFFSET; + + // check if the text hasn't become too big + // TODO why do we set both at once? they're independent... if( max.x > m_maxx - WXLO_ROFFSET || max.y > m_maxy - WXLO_BOFFSET || exact ) { + // text became too large if ( !exact ) { // add an extra bit to the sizes to avoid future updates @@ -852,9 +881,30 @@ wxLayoutWindow::ResizeScrollbars(bool exact) m_ViewStartX, m_ViewStartY, true); + m_hasHScrollbar = + m_hasVScrollbar = true; + m_maxx = max.x + X_SCROLL_PAGE; m_maxy = max.y + Y_SCROLL_PAGE; } + else + { + // check if the window hasn't become too big, thus making the scrollbars + // unnecessary + if ( m_hasHScrollbar && (max.x < size.x) ) + { + // remove the horizontal scrollbar + SetScrollbars(0, -1, 0, -1, 0, -1, true); + m_hasHScrollbar = false; + } + + if ( m_hasVScrollbar && (max.y < size.y) ) + { + // remove the vertical scrollbar + SetScrollbars(-1, 0, -1, 0, -1, 0, true); + m_hasVScrollbar = false; + } + } } // ---------------------------------------------------------------------------- diff --git a/samples/richedit/wxlwindow.h b/samples/richedit/wxlwindow.h index 3bbaf90d43..e0ddabd627 100644 --- a/samples/richedit/wxlwindow.h +++ b/samples/richedit/wxlwindow.h @@ -127,6 +127,7 @@ public: /**@name Callbacks */ //@{ + void OnSize(wxSizeEvent &event); void OnPaint(wxPaintEvent &event); void OnChar(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event); @@ -202,6 +203,11 @@ protected: int m_maxx; int m_maxy; int m_lineHeight; + + /// do we have the corresponding scrollbar? + bool m_hasHScrollbar, + m_hasVScrollbar; + /** Visibility parameter for cursor. 0/1 as expected, -1: visible on demand. */