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_PAINT (wxLayoutWindow::OnPaint
)
89 EVT_CHAR (wxLayoutWindow::OnChar
)
90 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
92 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
93 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
94 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
95 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
96 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
98 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
99 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
100 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
101 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
103 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
104 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
107 // ----------------------------------------------------------------------------
108 // function prototypes
109 // ----------------------------------------------------------------------------
111 /// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
112 static bool IsDirectionKey(long keyCode
);
114 // ============================================================================
116 // ============================================================================
118 /* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
120 /// allows me to compare to wxPoints
121 static bool operator != (wxPoint
const &p1
, wxPoint
const &p2
)
123 return p1
.x
!= p2
.x
|| p1
.y
!= p2
.y
;
127 #ifndef wxWANTS_CHARS
128 #define wxWANTS_CHARS 0
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
136 : wxScrolledWindow(parent
, -1,
137 wxDefaultPosition
, wxDefaultSize
,
138 wxHSCROLL
| wxVSCROLL
|
142 SetStatusBar(NULL
); // don't use statusbar
144 m_doSendEvents
= false;
145 m_ViewStartX
= 0; m_ViewStartY
= 0;
146 m_DoPopupMenu
= true;
147 m_PopupMenu
= MakeFormatMenu();
148 m_memDC
= new wxMemoryDC
;
149 m_bitmap
= new wxBitmap(4,4);
150 m_bitmapSize
= wxPoint(4,4);
151 m_llist
= new wxLayoutList();
154 m_ScrollToCursor
= false;
156 wxPoint max
= m_llist
->GetSize();
157 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
158 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1);
159 EnableScrolling(true, true);
160 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
161 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
164 #ifdef WXLAYOUT_USE_CARET
165 // FIXME cursor size shouldn't be hardcoded
166 wxCaret
*caret
= new wxCaret(this, 2, 20);
168 m_llist
->SetCaret(caret
);
170 #endif // WXLAYOUT_USE_CARET
172 m_HandCursor
= FALSE
;
173 m_CursorVisibility
= -1;
174 SetCursor(wxCURSOR_IBEAM
);
178 wxLayoutWindow::~wxLayoutWindow()
180 delete m_memDC
; // deletes bitmap automatically (?)
184 SetBackgroundBitmap(NULL
);
188 wxLayoutWindow::Clear(int family
,
196 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
197 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
198 ResizeScrollbars(true);
201 wxScrolledWindow::Clear();
202 DoPaint((wxRect
*)NULL
);
206 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
208 wxClientDC
dc( this );
210 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
212 // moving the mouse in a window shouldn't give it the focus!
217 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
218 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
220 findPos
.x
-= WXLO_XOFFSET
;
221 findPos
.y
-= WXLO_YOFFSET
;
228 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
232 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
234 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
236 // has the mouse only been moved?
239 case WXLOWIN_MENU_MOUSEMOVE
:
240 // found is only true if we are really over an object, not just
242 if(found
&& u
&& ! m_Selecting
)
245 SetCursor(wxCURSOR_HAND
);
247 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
249 const wxString
&label
= u
->GetLabel();
251 m_StatusBar
->SetStatusText(label
,
258 SetCursor(wxCURSOR_IBEAM
);
259 m_HandCursor
= FALSE
;
260 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
261 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
265 if ( event
.LeftIsDown() )
267 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
269 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
270 DoPaint(); // TODO: we don't have to redraw everything!
280 case WXLOWIN_MENU_LDOWN
:
282 // always move cursor to mouse click:
283 m_llist
->MoveCursorTo(cursorPos
);
285 // clicking a mouse removes the selection
286 if ( m_llist
->HasSelection() )
288 m_llist
->DiscardSelection();
289 DoPaint(); // TODO: we don't have to redraw everything!
292 // Calculate where the top of the visible area is:
296 GetScrollPixelsPerUnit(&dx
, &dy
);
299 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
301 if(m_CursorVisibility
== -1)
302 m_CursorVisibility
= 1;
304 if(m_CursorVisibility
!= 0)
306 // draw a thick cursor for editable windows with focus
307 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
310 // VZ: this should be unnecessary because mouse can only click on a
311 // visible part of the canvas
317 DoPaint(); // DoPaint suppresses flicker under GTK
321 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
326 case WXLOWIN_MENU_LUP
:
329 m_llist
->EndSelection();
332 DoPaint(); // TODO: we don't have to redraw everything!
336 case WXLOWIN_MENU_DBLCLICK
:
337 // select a word under cursor
338 m_llist
->MoveCursorTo(cursorPos
);
339 m_llist
->MoveCursorWord(-1);
340 m_llist
->StartSelection();
341 m_llist
->MoveCursorWord(1, false);
342 m_llist
->EndSelection();
344 DoPaint(); // TODO: we don't have to redraw everything!
348 // notify about mouse events?
351 // only do the menu if activated, editable and not on a clickable object
352 if(eventId
== WXLOWIN_MENU_RCLICK
354 && (! obj
|| u
== NULL
))
356 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
361 // find the object at this position
364 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
365 commandEvent
.SetEventObject( this );
366 commandEvent
.SetClientData((char *)obj
);
367 GetEventHandler()->ProcessEvent(commandEvent
);
375 // ----------------------------------------------------------------------------
376 // keyboard handling.
377 // ----------------------------------------------------------------------------
380 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
382 int keyCode
= event
.KeyCode();
384 #ifdef WXLAYOUT_DEBUG
385 if(keyCode
== WXK_F1
)
392 wxASSERT_MSG( !m_Selecting
|| event
.ShiftDown(),
393 "m_Selecting is normally reset in OnKeyUp() when Shift "
396 if ( !m_Selecting
&& m_llist
->HasSelection() )
398 // pressing any non-arrow key replaces the selection
399 if ( !IsDirectionKey(keyCode
) )
401 m_llist
->DeleteSelection();
403 else if ( !event
.ShiftDown() )
405 m_llist
->DiscardSelection();
409 // <Shift>+<arrow> starts selection
410 if ( event
.ShiftDown() && IsDirectionKey(keyCode
) )
415 m_llist
->StartSelection();
417 //else: just continue the old selection
420 // If needed, make cursor visible:
421 if(m_CursorVisibility
== -1)
422 m_CursorVisibility
= 1;
424 /* These two nested switches work like this:
425 The first one processes all non-editing keycodes, to move the
426 cursor, etc. It's default will process all keycodes causing
427 modifications to the buffer, but only if editing is allowed.
429 bool ctrlDown
= event
.ControlDown();
434 m_llist
->MoveCursorWord(1);
436 m_llist
->MoveCursorHorizontally(1);
440 m_llist
->MoveCursorWord(-1);
442 m_llist
->MoveCursorHorizontally(-1);
445 m_llist
->MoveCursorVertically(-1);
448 m_llist
->MoveCursorVertically(1);
451 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
454 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
458 m_llist
->MoveCursorTo(wxPoint(0, 0));
460 m_llist
->MoveCursorToBeginOfLine();
464 m_llist
->MoveCursorTo(m_llist
->GetSize());
466 m_llist
->MoveCursorToEndOfLine();
470 if(keyCode
== 'c' && ctrlDown
)
472 // this should work even in read-only mode
475 else if( IsEditable() )
477 /* First, handle control keys */
478 if(event
.ControlDown() && ! event
.AltDown())
490 m_llist
->DeleteLines(1);
492 case 'h': // like backspace
493 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
496 m_llist
->DeleteToBeginOfLine();
499 m_llist
->DeleteToEndOfLine();
507 #ifdef WXLAYOUT_DEBUG
509 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
517 else if( event
.AltDown() && ! event
.ControlDown() )
523 m_llist
->DeleteWord();
530 else if ( ! event
.AltDown() && ! event
.ControlDown())
535 if(event
.ShiftDown())
539 if(event
.ShiftDown())
544 case WXK_BACK
: // backspace
545 if(m_llist
->MoveCursorHorizontally(-1))
550 m_llist
->WrapLine(m_WrapMargin
);
551 m_llist
->LineBreak();
554 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
555 && (keyCode
< 256 && keyCode
>= 32)
558 if(m_WrapMargin
> 0 && isspace(keyCode
))
559 m_llist
->WrapLine(m_WrapMargin
);
560 m_llist
->Insert((char)keyCode
);
572 // continue selection to the current (new) cursor position
573 m_llist
->ContinueSelection();
576 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
577 // ne cursor position might be outside the current scrolllbar range
581 // refresh the screen
582 DoPaint(m_llist
->GetUpdateRect());
586 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
588 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
590 m_llist
->EndSelection();
599 wxLayoutWindow::ScrollToCursor(void)
601 wxClientDC
dc( this );
604 int x0
,y0
,x1
,y1
, dx
, dy
;
606 // Calculate where the top of the visible area is:
608 GetScrollPixelsPerUnit(&dx
, &dy
);
611 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
613 // Get the size of the visible window:
614 GetClientSize(&x1
,&y1
);
616 // notice that the client size may be (0, 0)...
617 wxASSERT(x1
>= 0 && y1
>= 0);
619 // VZ: I think this is false - if you do it here, ResizeScrollbars() won't
620 // call SetScrollbars() later
622 // As we have the values anyway, use them to avoid unnecessary scrollbar
624 if(x1
> m_maxx
) m_maxx
= x1
;
625 if(y1
> m_maxy
) m_maxy
= y1
;
628 // Make sure that the scrollbars are at a position so that the cursor is
629 // visible if we are editing
630 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
631 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
633 // the cursor should be completely visible in both directions
634 wxPoint
cs(m_llist
->GetCursorSize());
637 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
644 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
651 if ( nx
!= -1 || ny
!= -1 )
653 // set new view start
654 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
657 m_ScrollToCursor
= false;
662 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
664 wxRect region
= GetUpdateRegion().GetBox();
665 InternalPaint(®ion
);
669 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
672 InternalPaint(updateRect
);
673 #else // Causes bad flicker under wxGTK!!!
674 Refresh(FALSE
); //, updateRect);
676 if ( !::UpdateWindow(GetHwnd()) )
677 wxLogLastError("UpdateWindow");
682 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
684 wxPaintDC
dc( this );
687 #ifdef WXLAYOUT_USE_CARET
688 // hide the caret before drawing anything
690 #endif // WXLAYOUT_USE_CARET
692 int x0
,y0
,x1
,y1
, dx
, dy
;
694 // Calculate where the top of the visible area is:
696 GetScrollPixelsPerUnit(&dx
, &dy
);
699 // Get the size of the visible window:
700 GetClientSize(&x1
,&y1
);
706 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
707 updateRect
->x
, updateRect
->y
,
708 updateRect
->x
+updateRect
->width
,
709 updateRect
->y
+updateRect
->height
));
716 /* Check whether the window has grown, if so, we need to reallocate
717 the bitmap to be larger. */
718 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
720 wxASSERT(m_bitmapSize
.x
> 0);
721 wxASSERT(m_bitmapSize
.y
> 0);
723 m_memDC
->SelectObject(wxNullBitmap
);
725 m_bitmapSize
= wxPoint(x1
,y1
);
726 m_bitmap
= new wxBitmap(x1
,y1
);
727 m_memDC
->SelectObject(*m_bitmap
);
730 m_memDC
->SetDeviceOrigin(0,0);
731 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
732 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
734 m_memDC
->SetLogicalFunction(wxCOPY
);
737 // fill the background with the background bitmap
742 w
= m_BGbitmap
->GetWidth(),
743 h
= m_BGbitmap
->GetHeight();
744 for(y
= 0; y
< y1
; y
+=h
)
745 for(x
= 0; x
< x1
; x
+=w
)
746 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
747 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
750 // This is the important bit: we tell the list to draw itself
754 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
755 updateRect
->x
, updateRect
->y
,
756 updateRect
->x
+updateRect
->width
,
757 updateRect
->y
+updateRect
->height
));
761 // Device origins on the memDC are suspect, we translate manually
762 // with the translate parameter of Draw().
763 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
764 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
766 // We start calculating a new update rect before drawing the
767 // cursor, so that the cursor coordinates get included in the next
768 // update rectangle (although they are drawn on the memDC, this is
769 // needed to erase it):
770 m_llist
->InvalidateUpdateRect();
771 if(m_CursorVisibility
!= 0)
773 // draw a thick cursor for editable windows with focus
774 m_llist
->DrawCursor(*m_memDC
,
775 m_HaveFocus
&& IsEditable(),
779 // Now copy everything to the screen:
781 // This somehow doesn't work, but even the following bit with the
782 // whole rect at once is still a bit broken I think.
783 wxRegionIterator
ri ( GetUpdateRegion() );
787 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
788 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
789 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
790 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
796 // FIXME: Trying to copy only the changed parts, but it does not seem
798 // x0 = updateRect->x; y0 = updateRect->y;
799 // if(updateRect->height < y1)
800 // y1 = updateRect->height;
801 // y1 += WXLO_YOFFSET; //FIXME might not be needed
802 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
805 #ifdef WXLAYOUT_USE_CARET
806 // show the caret back after everything is redrawn
808 #endif // WXLAYOUT_USE_CARET
811 m_ScrollToCursor
= false;
813 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
815 static wxPoint
s_oldCursorPos(-1, -1);
817 wxPoint
pos(m_llist
->GetCursorPos());
819 // avoid unnecessary status bar refreshes
820 if ( pos
!= s_oldCursorPos
)
822 s_oldCursorPos
= pos
;
825 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
826 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
831 // change the range and position of scrollbars
833 wxLayoutWindow::ResizeScrollbars(bool exact
)
835 wxPoint max
= m_llist
->GetSize();
837 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
838 (long int)max
.x
, (long int) max
.y
));
840 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
844 // add an extra bit to the sizes to avoid future updates
845 max
.x
+= WXLO_ROFFSET
;
846 max
.y
+= WXLO_BOFFSET
;
849 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
850 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
851 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
852 m_ViewStartX
, m_ViewStartY
,
855 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
856 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
860 // ----------------------------------------------------------------------------
861 // clipboard operations
862 // ----------------------------------------------------------------------------
865 wxLayoutWindow::Paste(void)
868 if (wxTheClipboard
->Open())
870 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
871 wxLayoutDataObject wxldo
;
872 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
874 wxTheClipboard
->GetData(&wxldo
);
877 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
882 wxTextDataObject data
;
883 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
885 wxTheClipboard
->GetData(&data
);
886 wxString text
= data
.GetText();
887 wxLayoutImportText( m_llist
, text
);
890 wxTheClipboard
->Close();
894 /* My attempt to get the primary selection, but it does not
896 if(text
.Length() == 0)
898 wxTextCtrl
tmp_tctrl(this,-1);
900 text
+= tmp_tctrl
.GetValue();
906 wxLayoutWindow::Copy(bool invalidate
)
908 // Calling GetSelection() will automatically do an EndSelection()
909 // on the list, but we need to take a note of it, too:
913 m_llist
->EndSelection();
916 wxLayoutDataObject wldo
;
917 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
920 // Export selection as text:
922 wxLayoutExportObject
*export
;
923 wxLayoutExportStatus
status(llist
);
924 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
926 if(export
->type
== WXLO_EXPORT_TEXT
)
927 text
<< *(export
->content
.text
);
932 // The exporter always appends a newline, so we chop it off if it
935 size_t len
= text
.Length();
936 if(len
> 2 && text
[len
-2] == '\r') // Windows
937 text
= text
.Mid(0,len
-2);
938 else if(len
> 1 && text
[len
-1] == '\n')
939 text
= text
.Mid(0,len
-1);
943 if (wxTheClipboard
->Open())
945 wxTextDataObject
*data
= new wxTextDataObject( text
);
946 bool rc
= wxTheClipboard
->SetData( data
);
947 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
948 rc
|= wxTheClipboard
->AddData( &wldo
);
950 wxTheClipboard
->Close();
958 wxLayoutWindow::Cut(void)
960 if(Copy(false)) // do not invalidate selection after copy
962 m_llist
->DeleteSelection();
969 // ----------------------------------------------------------------------------
971 // ----------------------------------------------------------------------------
974 wxLayoutWindow::Find(const wxString
&needle
,
979 if(fromWhere
== NULL
)
980 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
982 found
= m_llist
->FindText(needle
, *fromWhere
);
990 m_llist
->MoveCursorTo(found
);
997 // ----------------------------------------------------------------------------
999 // ----------------------------------------------------------------------------
1002 wxLayoutWindow::MakeFormatMenu()
1004 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1006 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1007 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1008 m
->AppendSeparator();
1009 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1010 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1011 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1012 m
->AppendSeparator();
1013 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1014 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1015 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1020 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1022 event
.Check(m_llist
->IsFontUnderlined());
1025 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1027 event
.Check(m_llist
->IsFontBold());
1030 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1032 event
.Check(m_llist
->IsFontItalic());
1035 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1037 switch (event
.GetId())
1039 case WXLOWIN_MENU_LARGER
:
1040 m_llist
->SetFontLarger();
1042 case WXLOWIN_MENU_SMALLER
:
1043 m_llist
->SetFontSmaller();
1046 case WXLOWIN_MENU_UNDERLINE
:
1047 m_llist
->ToggleFontUnderline();
1049 case WXLOWIN_MENU_BOLD
:
1050 m_llist
->ToggleFontWeight();
1052 case WXLOWIN_MENU_ITALICS
:
1053 m_llist
->ToggleFontItalics();
1056 case WXLOWIN_MENU_ROMAN
:
1057 m_llist
->SetFontFamily(wxROMAN
); break;
1058 case WXLOWIN_MENU_TYPEWRITER
:
1059 m_llist
->SetFontFamily(wxFIXED
); break;
1060 case WXLOWIN_MENU_SANSSERIF
:
1061 m_llist
->SetFontFamily(wxSWISS
); break;
1065 // ----------------------------------------------------------------------------
1067 // ----------------------------------------------------------------------------
1070 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1077 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1079 m_HaveFocus
= false;
1083 // ----------------------------------------------------------------------------
1084 // private functions
1085 // ----------------------------------------------------------------------------
1087 static bool IsDirectionKey(long keyCode
)