EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp)
EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
+ EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown)
EVT_MOTION (wxLayoutWindow::OnMouseMove)
EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE, wxLayoutWindow::OnUpdateMenuUnderline)
wxDefaultPosition, wxDefaultSize,
wxHSCROLL | wxVSCROLL |
wxBORDER |
- wxWANTS_CHARS)
+ wxWANTS_CHARS),
+ m_llist(NULL)
{
SetStatusBar(NULL); // don't use statusbar
m_Editable = false;
m_bitmap = new wxBitmap(4,4);
m_bitmapSize = wxPoint(4,4);
m_llist = new wxLayoutList();
-
+ SetAutoDeleteSelection(false);
m_BGbitmap = NULL;
m_ScrollToCursor = false;
SetWrapMargin(0);
+
+ // initially the list is empty, so why would we need the scrollbars?
+#if 0
wxPoint max = m_llist->GetSize();
SetScrollbars(X_SCROLL_PAGE, Y_SCROLL_PAGE,
max.x / X_SCROLL_PAGE + 1, max.y / Y_SCROLL_PAGE + 1);
EnableScrolling(true, true);
m_maxx = max.x + X_SCROLL_PAGE;
m_maxy = max.y + Y_SCROLL_PAGE;
+#endif // 0
- // no scrollbars initially (BTW, why then we do all the stuff above?)
+ // no scrollbars initially
m_hasHScrollbar =
m_hasVScrollbar = false;
{
GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
+ wxScrolledWindow::Clear();
ResizeScrollbars(true);
SetDirty();
SetModified(false);
DoPaint((wxRect *)NULL);
}
+void wxLayoutWindow::Refresh(bool eraseBackground, const wxRect *rect)
+{
+ wxScrolledWindow::Refresh(eraseBackground, rect);
+
+ ResizeScrollbars();
+ ScrollToCursor();
+}
+
void
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
case WXLOWIN_MENU_LDOWN:
{
// always move cursor to mouse click:
- m_llist->MoveCursorTo(cursorPos);
+ if ( obj )
+ {
+ // we have found the real position
+ m_llist->MoveCursorTo(cursorPos);
+ }
+ else
+ {
+ // click beyond the end of the text
+ m_llist->MoveCursorToEnd();
+ }
// clicking a mouse removes the selection
if ( m_llist->HasSelection() )
}
break;
- case WXLOWIN_MENU_RCLICK:
- // remove the selection if mouse click is outside it (TODO)
+ case WXLOWIN_MENU_MDOWN:
+ Paste(TRUE);
break;
case WXLOWIN_MENU_DBLCLICK:
wxLayoutWindow::OnChar(wxKeyEvent& event)
{
int keyCode = event.KeyCode();
+ bool ctrlDown = event.ControlDown();
#ifdef WXLAYOUT_DEBUG
if(keyCode == WXK_F1)
}
#endif
- wxASSERT_MSG( !m_Selecting || event.ShiftDown(),
- "m_Selecting is normally reset in OnKeyUp() when Shift "
- "goes up!" );
-
- if ( !m_Selecting && m_llist->HasSelection() )
- {
- // pressing any non-arrow key replaces the selection
- if ( !IsDirectionKey(keyCode) )
- {
- m_llist->DeleteSelection();
- }
- else if ( !event.ShiftDown() )
- {
- m_llist->DiscardSelection();
- }
- }
-
+ // Force m_Selecting to be false if shift is no longer
+ // pressed. OnKeyUp() cannot catch all Shift-Up events.
+ if(!event.ShiftDown())
+ m_Selecting = false;
+
+ // pressing any non-arrow key optionally replaces the selection:
+ if(m_AutoDeleteSelection
+ && !m_Selecting
+ && m_llist->HasSelection()
+ && ! IsDirectionKey(keyCode)
+ && ! (event.AltDown() || ctrlDown)
+ )
+ m_llist->DeleteSelection();
+
// <Shift>+<arrow> starts selection
- if ( event.ShiftDown() && IsDirectionKey(keyCode) )
+ if ( IsDirectionKey(keyCode) )
{
if ( !m_Selecting )
{
m_Selecting = true;
m_llist->StartSelection();
}
- //else: just continue the old selection
+ else
+ {
+ // just continue the old selection
+ if(! event.ShiftDown() )
+ m_llist->DiscardSelection();
+ }
}
-
+
// If needed, make cursor visible:
if(m_CursorVisibility == -1)
m_CursorVisibility = 1;
cursor, etc. It's default will process all keycodes causing
modifications to the buffer, but only if editing is allowed.
*/
- bool ctrlDown = event.ControlDown();
switch(keyCode)
{
case WXK_RIGHT:
break;
case WXK_END:
if ( ctrlDown )
- m_llist->MoveCursorTo(m_llist->GetSize());
+ m_llist->MoveCursorToEnd();
else
m_llist->MoveCursorToEndOfLine();
break;
else if( IsEditable() )
{
/* First, handle control keys */
- if(event.ControlDown() && ! event.AltDown())
+ if(ctrlDown && ! event.AltDown())
{
switch(keyCode)
{
m_llist->WrapLine(m_WrapMargin);
m_llist->LineBreak();
break;
+
+ case WXK_TAB:
+ {
+ // TODO should be configurable
+ static const int tabSize = 8;
+
+ CoordType x = m_llist->GetCursorPos().x;
+ size_t numSpaces = tabSize - x % tabSize;
+ m_llist->Insert(wxString(' ', numSpaces));
+ }
+ break;
+
default:
if((!(event.ControlDown() || event.AltDown() || event.MetaDown()))
&& (keyCode < 256 && keyCode >= 32)
WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0, y0));
// Get the size of the visible window:
- GetClientSize(&x1,&y1);
+ GetClientSize(&x1, &y1);
- // notice that the client size may be (0, 0)...
- wxASSERT(x1 >= 0 && y1 >= 0);
-
- // VZ: I think this is false - if you do it here, ResizeScrollbars() won't
- // call SetScrollbars() later
-#if 0
- // As we have the values anyway, use them to avoid unnecessary scrollbar
- // updates.
- if(x1 > m_maxx) m_maxx = x1;
- if(y1 > m_maxy) m_maxy = y1;
-#endif // 0
+ // update the cursor screen position
+ m_llist->Layout(dc);
// Make sure that the scrollbars are at a position so that the cursor is
// visible if we are editing
void
wxLayoutWindow::OnSize(wxSizeEvent &event)
{
- ResizeScrollbars();
+ if ( m_llist )
+ {
+ ResizeScrollbars();
+ }
- event.Skip();
+ event.Skip();
}
// change the range and position of scrollbars
m_maxx = max.x + X_SCROLL_PAGE;
m_maxy = max.y + Y_SCROLL_PAGE;
}
+#if 0
else
{
// check if the window hasn't become too big, thus making the scrollbars
m_hasVScrollbar = false;
}
}
+#endif
}
// ----------------------------------------------------------------------------
// clipboard operations
+//
// ----------------------------------------------------------------------------
void
-wxLayoutWindow::Paste(void)
+wxLayoutWindow::Paste(bool primary)
{
// Read some text
if (wxTheClipboard->Open())
{
+#if __WXGTK__
+ if(primary)
+ wxTheClipboard->UsePrimarySelection();
+#endif
#if wxUSE_PRIVATE_CLIPBOARD_FORMAT
wxLayoutDataObject wxldo;
if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
}
wxTheClipboard->Close();
}
-
-#if 0
- /* My attempt to get the primary selection, but it does not
- work. :-( */
- if(text.Length() == 0)
- {
- wxTextCtrl tmp_tctrl(this,-1);
- tmp_tctrl.Paste();
- text += tmp_tctrl.GetValue();
- }
-#endif
}
bool
switch (event.GetId())
{
case WXLOWIN_MENU_LARGER:
- m_llist->SetFontLarger();
- break;
+ m_llist->SetFontLarger(); Refresh(FALSE); break;
case WXLOWIN_MENU_SMALLER:
- m_llist->SetFontSmaller();
- break;
-
+ m_llist->SetFontSmaller(); Refresh(FALSE); break;
case WXLOWIN_MENU_UNDERLINE:
- m_llist->ToggleFontUnderline();
- break;
+ m_llist->ToggleFontUnderline(); Refresh(FALSE); break;
case WXLOWIN_MENU_BOLD:
- m_llist->ToggleFontWeight();
- break;
+ m_llist->ToggleFontWeight(); Refresh(FALSE); break;
case WXLOWIN_MENU_ITALICS:
- m_llist->ToggleFontItalics();
- break;
-
+ m_llist->ToggleFontItalics(); Refresh(FALSE); break;
case WXLOWIN_MENU_ROMAN:
- m_llist->SetFontFamily(wxROMAN); break;
+ m_llist->SetFontFamily(wxROMAN); Refresh(FALSE); break;
case WXLOWIN_MENU_TYPEWRITER:
- m_llist->SetFontFamily(wxFIXED); break;
+ m_llist->SetFontFamily(wxFIXED); Refresh(FALSE); break;
case WXLOWIN_MENU_SANSSERIF:
- m_llist->SetFontFamily(wxSWISS); break;
+ m_llist->SetFontFamily(wxSWISS); Refresh(FALSE); break;
}
}