1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 # pragma implementation "wxlwindow.h"
21 #include <wx/wxprec.h>
32 # include "gui/wxMenuDefs.h"
33 # include "gui/wxMApp.h"
35 # include "gui/wxlwindow.h"
36 # include "gui/wxlparser.h"
39 # include <wx/msw/private.h>
42 # include "wxlwindow.h"
43 # include "wxlparser.h"
46 #include <wx/clipbrd.h>
47 #include <wx/textctrl.h>
48 #include <wx/dataobj.h>
50 #ifdef WXLAYOUT_USE_CARET
51 # include <wx/caret.h>
52 #endif // WXLAYOUT_USE_CARET
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
61 # define WXLO_DEBUG(x) wxLogDebug x
63 # define WXLO_DEBUG(x)
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 /// offsets to put a nice frame around text
71 #define WXLO_XOFFSET 4
72 #define WXLO_YOFFSET 4
74 /// offset to the right and bottom for when to redraw scrollbars
75 #define WXLO_ROFFSET 20
76 #define WXLO_BOFFSET 20
78 /// the size of one scrollbar page in pixels
79 static const int X_SCROLL_PAGE
= 10;
80 static const int Y_SCROLL_PAGE
= 20;
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
87 EVT_SIZE (wxLayoutWindow::OnSize
)
89 EVT_PAINT (wxLayoutWindow::OnPaint
)
91 EVT_CHAR (wxLayoutWindow::OnChar
)
92 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
94 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
95 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
96 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
97 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
98 EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown
)
99 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
101 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
102 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
103 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
104 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
106 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
107 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
110 // ----------------------------------------------------------------------------
111 // function prototypes
112 // ----------------------------------------------------------------------------
114 /// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
115 static bool IsDirectionKey(long keyCode
);
117 // ============================================================================
119 // ============================================================================
121 #ifndef wxWANTS_CHARS
122 #define wxWANTS_CHARS 0
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
130 : wxScrolledWindow(parent
, -1,
131 wxDefaultPosition
, wxDefaultSize
,
132 wxHSCROLL
| wxVSCROLL
|
137 SetStatusBar(NULL
); // don't use statusbar
139 m_doSendEvents
= false;
140 m_ViewStartX
= 0; m_ViewStartY
= 0;
141 m_DoPopupMenu
= true;
142 m_PopupMenu
= MakeFormatMenu();
143 m_memDC
= new wxMemoryDC
;
144 m_bitmap
= new wxBitmap(4,4);
145 m_bitmapSize
= wxPoint(4,4);
146 m_llist
= new wxLayoutList();
148 m_ScrollToCursor
= false;
151 // no scrollbars initially
153 m_hasVScrollbar
= false;
157 #ifdef WXLAYOUT_USE_CARET
158 // FIXME cursor size shouldn't be hardcoded
159 wxCaret
*caret
= new wxCaret(this, 2, 20);
161 m_llist
->SetCaret(caret
);
162 #endif // WXLAYOUT_USE_CARET
165 m_HandCursor
= FALSE
;
166 m_CursorVisibility
= -1;
167 SetCursor(wxCURSOR_IBEAM
);
170 // at least under Windows, this should be the default behaviour
171 m_AutoDeleteSelection
= TRUE
;
174 wxLayoutWindow::~wxLayoutWindow()
176 delete m_memDC
; // deletes bitmap automatically (?)
180 SetBackgroundBitmap(NULL
);
184 wxLayoutWindow::Clear(int family
,
192 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
193 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
194 wxScrolledWindow::Clear();
195 ResizeScrollbars(true);
200 m_CursorVisibility
= 1;
202 #ifdef WXLAYOUT_USE_CARET
203 if ( m_CursorVisibility
== 1 )
205 #endif // WXLAYOUT_USE_CARET
207 DoPaint((wxRect
*)NULL
);
210 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
212 wxScrolledWindow::Refresh(eraseBackground
, rect
);
215 //FIXME is this needed? It causes problems... ScrollToCursor();
219 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
221 wxClientDC
dc( this );
224 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
227 // moving the mouse in a window shouldn't give it the focus!
228 // Oh yes! wxGTK's focus handling is so broken, that this is the
229 // only sensible way to go.
234 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
235 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
237 findPos
.x
-= WXLO_XOFFSET
;
238 findPos
.y
-= WXLO_YOFFSET
;
245 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
249 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
251 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
253 // has the mouse only been moved?
256 case WXLOWIN_MENU_MOUSEMOVE
:
258 // this variables is used to only erase the message in the status
259 // bar if we had put it there previously - otherwise empting status
260 // bar might be undesirable
261 static bool s_hasPutMessageInStatusBar
= false;
263 // found is only true if we are really over an object, not just
265 if(found
&& u
&& ! m_Selecting
)
268 SetCursor(wxCURSOR_HAND
);
270 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
272 const wxString
&label
= u
->GetLabel();
275 m_StatusBar
->SetStatusText(label
,
277 s_hasPutMessageInStatusBar
= true;
284 SetCursor(wxCURSOR_IBEAM
);
285 m_HandCursor
= FALSE
;
286 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
287 s_hasPutMessageInStatusBar
)
289 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
295 if ( event
.LeftIsDown() )
297 // m_Selecting might not be set if the button got pressed
298 // outside this window, so check for it:
301 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
302 DoPaint(); // TODO: we don't have to redraw everything!
313 case WXLOWIN_MENU_LDOWN
:
315 // always move cursor to mouse click:
318 // we have found the real position
319 m_llist
->MoveCursorTo(cursorPos
);
323 // // click beyond the end of the text
324 // m_llist->MoveCursorToEnd();
327 // clicking a mouse removes the selection
328 if ( m_llist
->HasSelection() )
330 m_llist
->DiscardSelection();
332 DoPaint(); // TODO: we don't have to redraw everything!
335 // Calculate where the top of the visible area is:
339 GetScrollPixelsPerUnit(&dx
, &dy
);
342 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
344 if(m_CursorVisibility
== -1)
345 m_CursorVisibility
= 1;
346 #ifdef WXLAYOUT_USE_CARET
347 if ( m_CursorVisibility
== 1 )
349 #endif // WXLAYOUT_USE_CARET
351 if(m_CursorVisibility
)
353 // draw a thick cursor for editable windows with focus
354 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
358 DoPaint(); // DoPaint suppresses flicker under GTK
362 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
367 case WXLOWIN_MENU_LUP
:
370 m_llist
->EndSelection();
373 DoPaint(); // TODO: we don't have to redraw everything!
377 case WXLOWIN_MENU_MDOWN
:
381 case WXLOWIN_MENU_DBLCLICK
:
382 // select a word under cursor
383 m_llist
->MoveCursorTo(cursorPos
);
384 m_llist
->MoveCursorWord(-1);
385 m_llist
->StartSelection();
386 m_llist
->MoveCursorWord(1, false);
387 m_llist
->EndSelection();
389 DoPaint(); // TODO: we don't have to redraw everything!
393 // notify about mouse events?
396 // only do the menu if activated, editable and not on a clickable object
397 if(eventId
== WXLOWIN_MENU_RCLICK
399 && (! obj
|| u
== NULL
))
401 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
406 // find the object at this position
409 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
410 commandEvent
.SetEventObject( this );
411 commandEvent
.SetClientData((char *)obj
);
412 GetEventHandler()->ProcessEvent(commandEvent
);
419 // ----------------------------------------------------------------------------
420 // keyboard handling.
421 // ----------------------------------------------------------------------------
424 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
426 int keyCode
= event
.KeyCode();
427 bool ctrlDown
= event
.ControlDown();
429 #ifdef WXLAYOUT_DEBUG
430 if(keyCode
== WXK_F1
)
437 // Force m_Selecting to be false if shift is no longer
438 // pressed. OnKeyUp() cannot catch all Shift-Up events.
439 if(m_Selecting
&& !event
.ShiftDown())
442 m_llist
->EndSelection();
445 // If we deleted the selection here, we must not execute the
446 // deletion in Delete/Backspace handling.
447 bool deletedSelection
= false;
448 // pressing any non-arrow key optionally replaces the selection:
449 if(m_AutoDeleteSelection
451 && m_llist
->HasSelection()
452 && ! IsDirectionKey(keyCode
)
453 && ! (event
.AltDown() || ctrlDown
)
456 m_llist
->DeleteSelection();
457 deletedSelection
= true;
460 // <Shift>+<arrow> starts selection
461 if ( IsDirectionKey(keyCode
) )
465 // just continue the old selection
466 if( event
.ShiftDown() )
467 m_llist
->ContinueSelection();
470 m_llist
->DiscardSelection();
474 else if( event
.ShiftDown() )
477 m_llist
->StartSelection();
482 // If needed, make cursor visible:
483 if(m_CursorVisibility
== -1)
484 m_CursorVisibility
= 1;
486 /* These two nested switches work like this:
487 The first one processes all non-editing keycodes, to move the
488 cursor, etc. It's default will process all keycodes causing
489 modifications to the buffer, but only if editing is allowed.
495 m_llist
->MoveCursorWord(1);
497 m_llist
->MoveCursorHorizontally(1);
501 m_llist
->MoveCursorWord(-1);
503 m_llist
->MoveCursorHorizontally(-1);
506 m_llist
->MoveCursorVertically(-1);
509 m_llist
->MoveCursorVertically(1);
512 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
515 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
519 m_llist
->MoveCursorTo(wxPoint(0, 0));
521 m_llist
->MoveCursorToBeginOfLine();
525 m_llist
->MoveCursorToEnd();
527 m_llist
->MoveCursorToEndOfLine();
531 if(keyCode
== 'c' && ctrlDown
)
533 // this should work even in read-only mode
536 else if( IsEditable() )
538 /* First, handle control keys */
539 if(ctrlDown
&& ! event
.AltDown())
547 if(! deletedSelection
)
548 m_llist
->DeleteWord();
551 if(! deletedSelection
) // already done
555 m_llist
->DeleteLines(1);
557 case 'h': // like backspace
558 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
561 m_llist
->DeleteToBeginOfLine();
564 m_llist
->DeleteToEndOfLine();
572 #ifdef WXLAYOUT_DEBUG
574 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
582 else if( event
.AltDown() && ! event
.ControlDown() )
588 m_llist
->DeleteWord();
595 else if ( ! event
.AltDown() && ! event
.ControlDown())
600 if(event
.ShiftDown())
604 if(event
.ShiftDown())
607 if(! deletedSelection
)
610 case WXK_BACK
: // backspace
611 if(! deletedSelection
)
612 if(m_llist
->MoveCursorHorizontally(-1))
617 m_llist
->WrapLine(m_WrapMargin
);
618 m_llist
->LineBreak();
622 if ( !event
.ShiftDown() )
624 // TODO should be configurable
625 static const int tabSize
= 8;
627 CoordType x
= m_llist
->GetCursorPos().x
;
628 size_t numSpaces
= tabSize
- x
% tabSize
;
629 m_llist
->Insert(wxString(' ', numSpaces
));
634 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
635 && (keyCode
< 256 && keyCode
>= 32)
638 if(m_WrapMargin
> 0 && isspace(keyCode
))
639 m_llist
->WrapLine(m_WrapMargin
);
640 m_llist
->Insert((char)keyCode
);
652 // continue selection to the current (new) cursor position
653 m_llist
->ContinueSelection();
656 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
657 // ne cursor position might be outside the current scrolllbar range
661 // refresh the screen
662 DoPaint(m_llist
->GetUpdateRect());
666 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
668 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
670 m_llist
->EndSelection();
679 wxLayoutWindow::ScrollToCursor(void)
681 wxClientDC
dc( this );
684 int x0
,y0
,x1
,y1
, dx
, dy
;
686 // Calculate where the top of the visible area is:
688 GetScrollPixelsPerUnit(&dx
, &dy
);
691 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
693 // Get the size of the visible window:
694 GetClientSize(&x1
, &y1
);
696 // update the cursor screen position
699 // Make sure that the scrollbars are at a position so that the cursor is
700 // visible if we are editing
701 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
702 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
704 // the cursor should be completely visible in both directions
705 wxPoint
cs(m_llist
->GetCursorSize());
708 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
715 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
722 if ( nx
!= -1 || ny
!= -1 )
724 // set new view start
725 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
728 m_ScrollToCursor
= false;
733 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
735 wxRect region
= GetUpdateRegion().GetBox();
736 InternalPaint(®ion
);
740 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
743 // Calling Refresh() causes bad flicker under wxGTK!!!
744 InternalPaint(updateRect
);
746 // shouldn't specify the update rectangle if it doesn't include all the
747 // changed locations - otherwise, they won't be repainted at all because
748 // the system clips the display to the update rect
749 Refresh(FALSE
); //, updateRect);
754 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
756 wxPaintDC
dc( this );
759 #ifdef WXLAYOUT_USE_CARET
760 // hide the caret before drawing anything
762 #endif // WXLAYOUT_USE_CARET
764 int x0
,y0
,x1
,y1
, dx
, dy
;
766 // Calculate where the top of the visible area is:
768 GetScrollPixelsPerUnit(&dx
, &dy
);
771 // Get the size of the visible window:
772 GetClientSize(&x1
,&y1
);
778 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
779 updateRect
->x
, updateRect
->y
,
780 updateRect
->x
+updateRect
->width
,
781 updateRect
->y
+updateRect
->height
));
789 /* Check whether the window has grown, if so, we need to reallocate
790 the bitmap to be larger. */
791 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
793 wxASSERT(m_bitmapSize
.x
> 0);
794 wxASSERT(m_bitmapSize
.y
> 0);
796 m_memDC
->SelectObject(wxNullBitmap
);
798 m_bitmapSize
= wxPoint(x1
,y1
);
799 m_bitmap
= new wxBitmap(x1
,y1
);
800 m_memDC
->SelectObject(*m_bitmap
);
803 m_memDC
->SetDeviceOrigin(0,0);
804 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
805 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
807 m_memDC
->SetLogicalFunction(wxCOPY
);
810 // fill the background with the background bitmap
815 w
= m_BGbitmap
->GetWidth(),
816 h
= m_BGbitmap
->GetHeight();
817 for(y
= 0; y
< y1
; y
+=h
)
818 for(x
= 0; x
< x1
; x
+=w
)
819 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
820 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
823 // This is the important bit: we tell the list to draw itself
827 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
828 updateRect
->x
, updateRect
->y
,
829 updateRect
->x
+updateRect
->width
,
830 updateRect
->y
+updateRect
->height
));
834 // Device origins on the memDC are suspect, we translate manually
835 // with the translate parameter of Draw().
836 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
837 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
839 // We start calculating a new update rect before drawing the
840 // cursor, so that the cursor coordinates get included in the next
841 // update rectangle (although they are drawn on the memDC, this is
842 // needed to erase it):
843 m_llist
->InvalidateUpdateRect();
844 if(m_CursorVisibility
!= 0)
846 // draw a thick cursor for editable windows with focus
847 m_llist
->DrawCursor(*m_memDC
,
848 m_HaveFocus
&& IsEditable(),
852 // Now copy everything to the screen:
854 // This somehow doesn't work, but even the following bit with the
855 // whole rect at once is still a bit broken I think.
856 wxRegionIterator
ri ( GetUpdateRegion() );
860 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
861 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
862 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
863 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
869 // FIXME: Trying to copy only the changed parts, but it does not seem
871 // x0 = updateRect->x; y0 = updateRect->y;
872 // if(updateRect->height < y1)
873 // y1 = updateRect->height;
874 // y1 += WXLO_YOFFSET; //FIXME might not be needed
875 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
878 #ifdef WXLAYOUT_USE_CARET
879 // show the caret back after everything is redrawn
881 #endif // WXLAYOUT_USE_CARET
884 m_ScrollToCursor
= false;
886 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
888 static wxPoint
s_oldCursorPos(-1, -1);
890 wxPoint
pos(m_llist
->GetCursorPos());
892 // avoid unnecessary status bar refreshes
893 if ( pos
!= s_oldCursorPos
)
895 s_oldCursorPos
= pos
;
898 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
899 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
905 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
915 // change the range and position of scrollbars
917 wxLayoutWindow::ResizeScrollbars(bool exact
)
919 wxPoint max
= m_llist
->GetSize();
920 wxSize size
= GetClientSize();
922 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
923 (long int)max
.x
, (long int) max
.y
));
925 // in the absence of scrollbars we should compare with the client size
926 if ( !m_hasHScrollbar
)
927 m_maxx
= size
.x
;// - WXLO_ROFFSET;
928 if ( !m_hasVScrollbar
)
929 m_maxy
= size
.y
;// - WXLO_BOFFSET;
931 // check if the text hasn't become too big
932 // TODO why do we set both at once? they're independent...
933 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
935 // text became too large
938 // add an extra bit to the sizes to avoid future updates
939 max
.x
+= WXLO_ROFFSET
;
940 max
.y
+= WXLO_BOFFSET
;
943 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
944 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
945 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
946 m_ViewStartX
, m_ViewStartY
,
950 m_hasVScrollbar
= true;
952 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
953 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
956 //FIXME: this code is pretty broken, producing "arithmetic
957 //exception" crashes (div by 0??)
960 // check if the window hasn't become too big, thus making the scrollbars
964 // add an extra bit to the sizes to avoid future updates
965 max
.x
-= WXLO_ROFFSET
;
966 max
.y
-= WXLO_BOFFSET
;
969 if ( m_hasHScrollbar
&& (max
.x
< m_maxx
) )
971 // remove the horizontal scrollbar
972 SetScrollbars(0, -1, 0, -1, 0, -1, true);
973 m_hasHScrollbar
= false;
976 if ( m_hasVScrollbar
&& (max
.y
< m_maxy
) )
978 // remove the vertical scrollbar
979 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
980 m_hasVScrollbar
= false;
986 // ----------------------------------------------------------------------------
987 // clipboard operations
989 // ----------------------------------------------------------------------------
992 wxLayoutWindow::Paste(bool primary
)
995 if (wxTheClipboard
->Open())
999 wxTheClipboard
->UsePrimarySelection();
1001 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1002 wxLayoutDataObject wxldo
;
1003 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1005 wxTheClipboard
->GetData(&wxldo
);
1008 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
1013 wxTextDataObject data
;
1014 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
1016 wxTheClipboard
->GetData(&data
);
1017 wxString text
= data
.GetText();
1018 wxLayoutImportText( m_llist
, text
);
1021 wxTheClipboard
->Close();
1026 wxLayoutWindow::Copy(bool invalidate
)
1028 // Calling GetSelection() will automatically do an EndSelection()
1029 // on the list, but we need to take a note of it, too:
1032 m_Selecting
= false;
1033 m_llist
->EndSelection();
1036 wxLayoutDataObject wldo
;
1037 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1040 // Export selection as text:
1042 wxLayoutExportObject
*export
;
1043 wxLayoutExportStatus
status(llist
);
1044 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1046 if(export
->type
== WXLO_EXPORT_TEXT
)
1047 text
<< *(export
->content
.text
);
1052 // The exporter always appends a newline, so we chop it off if it
1055 size_t len
= text
.Length();
1056 if(len
> 2 && text
[len
-2] == '\r') // Windows
1057 text
= text
.Mid(0,len
-2);
1058 else if(len
> 1 && text
[len
-1] == '\n')
1059 text
= text
.Mid(0,len
-1);
1063 if (wxTheClipboard
->Open())
1065 wxTextDataObject
*data
= new wxTextDataObject( text
);
1066 bool rc
= wxTheClipboard
->SetData( data
);
1067 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1068 rc
|= wxTheClipboard
->AddData( &wldo
);
1070 wxTheClipboard
->Close();
1078 wxLayoutWindow::Cut(void)
1080 if(Copy(false)) // do not invalidate selection after copy
1082 m_llist
->DeleteSelection();
1089 // ----------------------------------------------------------------------------
1091 // ----------------------------------------------------------------------------
1094 wxLayoutWindow::Find(const wxString
&needle
,
1095 wxPoint
* fromWhere
)
1099 if(fromWhere
== NULL
)
1100 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1102 found
= m_llist
->FindText(needle
, *fromWhere
);
1110 m_llist
->MoveCursorTo(found
);
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1122 wxLayoutWindow::MakeFormatMenu()
1124 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1126 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1127 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1128 m
->AppendSeparator();
1129 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1130 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1131 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1132 m
->AppendSeparator();
1133 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1134 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1135 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1140 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1142 event
.Check(m_llist
->IsFontUnderlined());
1145 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1147 event
.Check(m_llist
->IsFontBold());
1150 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1152 event
.Check(m_llist
->IsFontItalic());
1155 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1157 switch (event
.GetId())
1159 case WXLOWIN_MENU_LARGER
:
1160 m_llist
->SetFontLarger(); DoPaint(); break;
1161 case WXLOWIN_MENU_SMALLER
:
1162 m_llist
->SetFontSmaller(); DoPaint(); break;
1163 case WXLOWIN_MENU_UNDERLINE
:
1164 m_llist
->ToggleFontUnderline(); DoPaint(); break;
1165 case WXLOWIN_MENU_BOLD
:
1166 m_llist
->ToggleFontWeight(); DoPaint(); break;
1167 case WXLOWIN_MENU_ITALICS
:
1168 m_llist
->ToggleFontItalics(); DoPaint(); break;
1169 case WXLOWIN_MENU_ROMAN
:
1170 m_llist
->SetFontFamily(wxROMAN
); DoPaint(); break;
1171 case WXLOWIN_MENU_TYPEWRITER
:
1172 m_llist
->SetFontFamily(wxFIXED
); DoPaint(); break;
1173 case WXLOWIN_MENU_SANSSERIF
:
1174 m_llist
->SetFontFamily(wxSWISS
); DoPaint(); break;
1178 // ----------------------------------------------------------------------------
1180 // ----------------------------------------------------------------------------
1183 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1187 DoPaint(); // cursor must change
1191 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1193 m_HaveFocus
= false;
1195 DoPaint();// cursor must change
1198 // ----------------------------------------------------------------------------
1199 // private functions
1200 // ----------------------------------------------------------------------------
1202 static bool IsDirectionKey(long keyCode
)