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_MOTION (wxLayoutWindow::OnMouseMove
)
100 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
101 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
102 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
103 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
105 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
106 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
109 // ----------------------------------------------------------------------------
110 // function prototypes
111 // ----------------------------------------------------------------------------
113 /// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
114 static bool IsDirectionKey(long keyCode
);
116 // ============================================================================
118 // ============================================================================
120 /* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
122 /// allows me to compare to wxPoints
123 static bool operator != (wxPoint
const &p1
, wxPoint
const &p2
)
125 return p1
.x
!= p2
.x
|| p1
.y
!= p2
.y
;
129 #ifndef wxWANTS_CHARS
130 #define wxWANTS_CHARS 0
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
138 : wxScrolledWindow(parent
, -1,
139 wxDefaultPosition
, wxDefaultSize
,
140 wxHSCROLL
| wxVSCROLL
|
144 SetStatusBar(NULL
); // don't use statusbar
146 m_doSendEvents
= false;
147 m_ViewStartX
= 0; m_ViewStartY
= 0;
148 m_DoPopupMenu
= true;
149 m_PopupMenu
= MakeFormatMenu();
150 m_memDC
= new wxMemoryDC
;
151 m_bitmap
= new wxBitmap(4,4);
152 m_bitmapSize
= wxPoint(4,4);
153 m_llist
= new wxLayoutList();
156 m_ScrollToCursor
= false;
158 wxPoint max
= m_llist
->GetSize();
159 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
160 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1);
161 EnableScrolling(true, true);
162 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
163 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
165 // no scrollbars initially (BTW, why then we do all the stuff above?)
167 m_hasVScrollbar
= false;
171 #ifdef WXLAYOUT_USE_CARET
172 // FIXME cursor size shouldn't be hardcoded
173 wxCaret
*caret
= new wxCaret(this, 2, 20);
175 m_llist
->SetCaret(caret
);
177 #endif // WXLAYOUT_USE_CARET
179 m_HandCursor
= FALSE
;
180 m_CursorVisibility
= -1;
181 SetCursor(wxCURSOR_IBEAM
);
185 wxLayoutWindow::~wxLayoutWindow()
187 delete m_memDC
; // deletes bitmap automatically (?)
191 SetBackgroundBitmap(NULL
);
195 wxLayoutWindow::Clear(int family
,
203 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
204 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
205 ResizeScrollbars(true);
208 wxScrolledWindow::Clear();
209 DoPaint((wxRect
*)NULL
);
213 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
215 wxClientDC
dc( this );
217 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
219 // moving the mouse in a window shouldn't give it the focus!
224 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
225 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
227 findPos
.x
-= WXLO_XOFFSET
;
228 findPos
.y
-= WXLO_YOFFSET
;
235 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
239 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
241 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
243 // has the mouse only been moved?
246 case WXLOWIN_MENU_MOUSEMOVE
:
247 // found is only true if we are really over an object, not just
249 if(found
&& u
&& ! m_Selecting
)
252 SetCursor(wxCURSOR_HAND
);
254 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
256 const wxString
&label
= u
->GetLabel();
258 m_StatusBar
->SetStatusText(label
,
265 SetCursor(wxCURSOR_IBEAM
);
266 m_HandCursor
= FALSE
;
267 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
268 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
272 if ( event
.LeftIsDown() )
274 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
276 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
277 DoPaint(); // TODO: we don't have to redraw everything!
287 case WXLOWIN_MENU_LDOWN
:
289 // always move cursor to mouse click:
290 m_llist
->MoveCursorTo(cursorPos
);
292 // clicking a mouse removes the selection
293 if ( m_llist
->HasSelection() )
295 m_llist
->DiscardSelection();
296 DoPaint(); // TODO: we don't have to redraw everything!
299 // Calculate where the top of the visible area is:
303 GetScrollPixelsPerUnit(&dx
, &dy
);
306 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
308 if(m_CursorVisibility
== -1)
309 m_CursorVisibility
= 1;
311 if(m_CursorVisibility
!= 0)
313 // draw a thick cursor for editable windows with focus
314 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
317 // VZ: this should be unnecessary because mouse can only click on a
318 // visible part of the canvas
324 DoPaint(); // DoPaint suppresses flicker under GTK
328 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
333 case WXLOWIN_MENU_LUP
:
336 m_llist
->EndSelection();
339 DoPaint(); // TODO: we don't have to redraw everything!
343 case WXLOWIN_MENU_RCLICK
:
344 // remove the selection if mouse click is outside it (TODO)
347 case WXLOWIN_MENU_DBLCLICK
:
348 // select a word under cursor
349 m_llist
->MoveCursorTo(cursorPos
);
350 m_llist
->MoveCursorWord(-1);
351 m_llist
->StartSelection();
352 m_llist
->MoveCursorWord(1, false);
353 m_llist
->EndSelection();
355 DoPaint(); // TODO: we don't have to redraw everything!
359 // notify about mouse events?
362 // only do the menu if activated, editable and not on a clickable object
363 if(eventId
== WXLOWIN_MENU_RCLICK
365 && (! obj
|| u
== NULL
))
367 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
372 // find the object at this position
375 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
376 commandEvent
.SetEventObject( this );
377 commandEvent
.SetClientData((char *)obj
);
378 GetEventHandler()->ProcessEvent(commandEvent
);
386 // ----------------------------------------------------------------------------
387 // keyboard handling.
388 // ----------------------------------------------------------------------------
391 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
393 int keyCode
= event
.KeyCode();
395 #ifdef WXLAYOUT_DEBUG
396 if(keyCode
== WXK_F1
)
403 wxASSERT_MSG( !m_Selecting
|| event
.ShiftDown(),
404 "m_Selecting is normally reset in OnKeyUp() when Shift "
407 if ( !m_Selecting
&& m_llist
->HasSelection() )
409 // pressing any non-arrow key replaces the selection
410 if ( !IsDirectionKey(keyCode
) )
412 m_llist
->DeleteSelection();
414 else if ( !event
.ShiftDown() )
416 m_llist
->DiscardSelection();
420 // <Shift>+<arrow> starts selection
421 if ( event
.ShiftDown() && IsDirectionKey(keyCode
) )
426 m_llist
->StartSelection();
428 //else: just continue the old selection
431 // If needed, make cursor visible:
432 if(m_CursorVisibility
== -1)
433 m_CursorVisibility
= 1;
435 /* These two nested switches work like this:
436 The first one processes all non-editing keycodes, to move the
437 cursor, etc. It's default will process all keycodes causing
438 modifications to the buffer, but only if editing is allowed.
440 bool ctrlDown
= event
.ControlDown();
445 m_llist
->MoveCursorWord(1);
447 m_llist
->MoveCursorHorizontally(1);
451 m_llist
->MoveCursorWord(-1);
453 m_llist
->MoveCursorHorizontally(-1);
456 m_llist
->MoveCursorVertically(-1);
459 m_llist
->MoveCursorVertically(1);
462 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
465 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
469 m_llist
->MoveCursorTo(wxPoint(0, 0));
471 m_llist
->MoveCursorToBeginOfLine();
475 m_llist
->MoveCursorTo(m_llist
->GetSize());
477 m_llist
->MoveCursorToEndOfLine();
481 if(keyCode
== 'c' && ctrlDown
)
483 // this should work even in read-only mode
486 else if( IsEditable() )
488 /* First, handle control keys */
489 if(event
.ControlDown() && ! event
.AltDown())
501 m_llist
->DeleteLines(1);
503 case 'h': // like backspace
504 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
507 m_llist
->DeleteToBeginOfLine();
510 m_llist
->DeleteToEndOfLine();
518 #ifdef WXLAYOUT_DEBUG
520 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
528 else if( event
.AltDown() && ! event
.ControlDown() )
534 m_llist
->DeleteWord();
541 else if ( ! event
.AltDown() && ! event
.ControlDown())
546 if(event
.ShiftDown())
550 if(event
.ShiftDown())
555 case WXK_BACK
: // backspace
556 if(m_llist
->MoveCursorHorizontally(-1))
561 m_llist
->WrapLine(m_WrapMargin
);
562 m_llist
->LineBreak();
565 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
566 && (keyCode
< 256 && keyCode
>= 32)
569 if(m_WrapMargin
> 0 && isspace(keyCode
))
570 m_llist
->WrapLine(m_WrapMargin
);
571 m_llist
->Insert((char)keyCode
);
583 // continue selection to the current (new) cursor position
584 m_llist
->ContinueSelection();
587 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
588 // ne cursor position might be outside the current scrolllbar range
592 // refresh the screen
593 DoPaint(m_llist
->GetUpdateRect());
597 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
599 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
601 m_llist
->EndSelection();
610 wxLayoutWindow::ScrollToCursor(void)
612 wxClientDC
dc( this );
615 int x0
,y0
,x1
,y1
, dx
, dy
;
617 // Calculate where the top of the visible area is:
619 GetScrollPixelsPerUnit(&dx
, &dy
);
622 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
624 // Get the size of the visible window:
625 GetClientSize(&x1
,&y1
);
627 // notice that the client size may be (0, 0)...
628 wxASSERT(x1
>= 0 && y1
>= 0);
630 // VZ: I think this is false - if you do it here, ResizeScrollbars() won't
631 // call SetScrollbars() later
633 // As we have the values anyway, use them to avoid unnecessary scrollbar
635 if(x1
> m_maxx
) m_maxx
= x1
;
636 if(y1
> m_maxy
) m_maxy
= y1
;
639 // Make sure that the scrollbars are at a position so that the cursor is
640 // visible if we are editing
641 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
642 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
644 // the cursor should be completely visible in both directions
645 wxPoint
cs(m_llist
->GetCursorSize());
648 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
655 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
662 if ( nx
!= -1 || ny
!= -1 )
664 // set new view start
665 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
668 m_ScrollToCursor
= false;
673 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
675 wxRect region
= GetUpdateRegion().GetBox();
676 InternalPaint(®ion
);
680 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
683 InternalPaint(updateRect
);
684 #else // Causes bad flicker under wxGTK!!!
685 Refresh(FALSE
); //, updateRect);
687 if ( !::UpdateWindow(GetHwnd()) )
688 wxLogLastError("UpdateWindow");
693 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
695 wxPaintDC
dc( this );
698 #ifdef WXLAYOUT_USE_CARET
699 // hide the caret before drawing anything
701 #endif // WXLAYOUT_USE_CARET
703 int x0
,y0
,x1
,y1
, dx
, dy
;
705 // Calculate where the top of the visible area is:
707 GetScrollPixelsPerUnit(&dx
, &dy
);
710 // Get the size of the visible window:
711 GetClientSize(&x1
,&y1
);
717 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
718 updateRect
->x
, updateRect
->y
,
719 updateRect
->x
+updateRect
->width
,
720 updateRect
->y
+updateRect
->height
));
727 /* Check whether the window has grown, if so, we need to reallocate
728 the bitmap to be larger. */
729 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
731 wxASSERT(m_bitmapSize
.x
> 0);
732 wxASSERT(m_bitmapSize
.y
> 0);
734 m_memDC
->SelectObject(wxNullBitmap
);
736 m_bitmapSize
= wxPoint(x1
,y1
);
737 m_bitmap
= new wxBitmap(x1
,y1
);
738 m_memDC
->SelectObject(*m_bitmap
);
741 m_memDC
->SetDeviceOrigin(0,0);
742 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
743 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
745 m_memDC
->SetLogicalFunction(wxCOPY
);
748 // fill the background with the background bitmap
753 w
= m_BGbitmap
->GetWidth(),
754 h
= m_BGbitmap
->GetHeight();
755 for(y
= 0; y
< y1
; y
+=h
)
756 for(x
= 0; x
< x1
; x
+=w
)
757 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
758 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
761 // This is the important bit: we tell the list to draw itself
765 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
766 updateRect
->x
, updateRect
->y
,
767 updateRect
->x
+updateRect
->width
,
768 updateRect
->y
+updateRect
->height
));
772 // Device origins on the memDC are suspect, we translate manually
773 // with the translate parameter of Draw().
774 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
775 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
777 // We start calculating a new update rect before drawing the
778 // cursor, so that the cursor coordinates get included in the next
779 // update rectangle (although they are drawn on the memDC, this is
780 // needed to erase it):
781 m_llist
->InvalidateUpdateRect();
782 if(m_CursorVisibility
!= 0)
784 // draw a thick cursor for editable windows with focus
785 m_llist
->DrawCursor(*m_memDC
,
786 m_HaveFocus
&& IsEditable(),
790 // Now copy everything to the screen:
792 // This somehow doesn't work, but even the following bit with the
793 // whole rect at once is still a bit broken I think.
794 wxRegionIterator
ri ( GetUpdateRegion() );
798 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
799 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
800 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
801 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
807 // FIXME: Trying to copy only the changed parts, but it does not seem
809 // x0 = updateRect->x; y0 = updateRect->y;
810 // if(updateRect->height < y1)
811 // y1 = updateRect->height;
812 // y1 += WXLO_YOFFSET; //FIXME might not be needed
813 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
816 #ifdef WXLAYOUT_USE_CARET
817 // show the caret back after everything is redrawn
819 #endif // WXLAYOUT_USE_CARET
822 m_ScrollToCursor
= false;
824 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
826 static wxPoint
s_oldCursorPos(-1, -1);
828 wxPoint
pos(m_llist
->GetCursorPos());
830 // avoid unnecessary status bar refreshes
831 if ( pos
!= s_oldCursorPos
)
833 s_oldCursorPos
= pos
;
836 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
837 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
843 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
850 // change the range and position of scrollbars
852 wxLayoutWindow::ResizeScrollbars(bool exact
)
854 wxPoint max
= m_llist
->GetSize();
855 wxSize size
= GetClientSize();
857 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
858 (long int)max
.x
, (long int) max
.y
));
860 // in the absence of scrollbars we should compare with the client size
861 if ( !m_hasHScrollbar
)
862 m_maxx
= size
.x
- WXLO_ROFFSET
;
863 if ( !m_hasVScrollbar
)
864 m_maxy
= size
.y
- WXLO_BOFFSET
;
866 // check if the text hasn't become too big
867 // TODO why do we set both at once? they're independent...
868 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
870 // text became too large
873 // add an extra bit to the sizes to avoid future updates
874 max
.x
+= WXLO_ROFFSET
;
875 max
.y
+= WXLO_BOFFSET
;
878 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
879 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
880 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
881 m_ViewStartX
, m_ViewStartY
,
885 m_hasVScrollbar
= true;
887 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
888 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
893 // check if the window hasn't become too big, thus making the scrollbars
895 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
897 // remove the horizontal scrollbar
898 SetScrollbars(0, -1, 0, -1, 0, -1, true);
899 m_hasHScrollbar
= false;
902 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
904 // remove the vertical scrollbar
905 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
906 m_hasVScrollbar
= false;
912 // ----------------------------------------------------------------------------
913 // clipboard operations
914 // ----------------------------------------------------------------------------
917 wxLayoutWindow::Paste(void)
920 if (wxTheClipboard
->Open())
922 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
923 wxLayoutDataObject wxldo
;
924 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
926 wxTheClipboard
->GetData(&wxldo
);
929 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
934 wxTextDataObject data
;
935 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
937 wxTheClipboard
->GetData(&data
);
938 wxString text
= data
.GetText();
939 wxLayoutImportText( m_llist
, text
);
942 wxTheClipboard
->Close();
946 /* My attempt to get the primary selection, but it does not
948 if(text
.Length() == 0)
950 wxTextCtrl
tmp_tctrl(this,-1);
952 text
+= tmp_tctrl
.GetValue();
958 wxLayoutWindow::Copy(bool invalidate
)
960 // Calling GetSelection() will automatically do an EndSelection()
961 // on the list, but we need to take a note of it, too:
965 m_llist
->EndSelection();
968 wxLayoutDataObject wldo
;
969 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
972 // Export selection as text:
974 wxLayoutExportObject
*export
;
975 wxLayoutExportStatus
status(llist
);
976 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
978 if(export
->type
== WXLO_EXPORT_TEXT
)
979 text
<< *(export
->content
.text
);
984 // The exporter always appends a newline, so we chop it off if it
987 size_t len
= text
.Length();
988 if(len
> 2 && text
[len
-2] == '\r') // Windows
989 text
= text
.Mid(0,len
-2);
990 else if(len
> 1 && text
[len
-1] == '\n')
991 text
= text
.Mid(0,len
-1);
995 if (wxTheClipboard
->Open())
997 wxTextDataObject
*data
= new wxTextDataObject( text
);
998 bool rc
= wxTheClipboard
->SetData( data
);
999 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1000 rc
|= wxTheClipboard
->AddData( &wldo
);
1002 wxTheClipboard
->Close();
1010 wxLayoutWindow::Cut(void)
1012 if(Copy(false)) // do not invalidate selection after copy
1014 m_llist
->DeleteSelection();
1021 // ----------------------------------------------------------------------------
1023 // ----------------------------------------------------------------------------
1026 wxLayoutWindow::Find(const wxString
&needle
,
1027 wxPoint
* fromWhere
)
1031 if(fromWhere
== NULL
)
1032 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1034 found
= m_llist
->FindText(needle
, *fromWhere
);
1042 m_llist
->MoveCursorTo(found
);
1049 // ----------------------------------------------------------------------------
1051 // ----------------------------------------------------------------------------
1054 wxLayoutWindow::MakeFormatMenu()
1056 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1058 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1059 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1060 m
->AppendSeparator();
1061 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1062 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1063 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1064 m
->AppendSeparator();
1065 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1066 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1067 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1072 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1074 event
.Check(m_llist
->IsFontUnderlined());
1077 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1079 event
.Check(m_llist
->IsFontBold());
1082 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1084 event
.Check(m_llist
->IsFontItalic());
1087 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1089 switch (event
.GetId())
1091 case WXLOWIN_MENU_LARGER
:
1092 m_llist
->SetFontLarger();
1094 case WXLOWIN_MENU_SMALLER
:
1095 m_llist
->SetFontSmaller();
1098 case WXLOWIN_MENU_UNDERLINE
:
1099 m_llist
->ToggleFontUnderline();
1101 case WXLOWIN_MENU_BOLD
:
1102 m_llist
->ToggleFontWeight();
1104 case WXLOWIN_MENU_ITALICS
:
1105 m_llist
->ToggleFontItalics();
1108 case WXLOWIN_MENU_ROMAN
:
1109 m_llist
->SetFontFamily(wxROMAN
); break;
1110 case WXLOWIN_MENU_TYPEWRITER
:
1111 m_llist
->SetFontFamily(wxFIXED
); break;
1112 case WXLOWIN_MENU_SANSSERIF
:
1113 m_llist
->SetFontFamily(wxSWISS
); break;
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1122 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1129 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1131 m_HaveFocus
= false;
1135 // ----------------------------------------------------------------------------
1136 // private functions
1137 // ----------------------------------------------------------------------------
1139 static bool IsDirectionKey(long keyCode
)