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 /* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
123 /// allows me to compare to wxPoints
124 static bool operator != (wxPoint
const &p1
, wxPoint
const &p2
)
126 return p1
.x
!= p2
.x
|| p1
.y
!= p2
.y
;
130 #ifndef wxWANTS_CHARS
131 #define wxWANTS_CHARS 0
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
139 : wxScrolledWindow(parent
, -1,
140 wxDefaultPosition
, wxDefaultSize
,
141 wxHSCROLL
| wxVSCROLL
|
146 SetStatusBar(NULL
); // don't use statusbar
148 m_doSendEvents
= false;
149 m_ViewStartX
= 0; m_ViewStartY
= 0;
150 m_DoPopupMenu
= true;
151 m_PopupMenu
= MakeFormatMenu();
152 m_memDC
= new wxMemoryDC
;
153 m_bitmap
= new wxBitmap(4,4);
154 m_bitmapSize
= wxPoint(4,4);
155 m_llist
= new wxLayoutList();
158 m_ScrollToCursor
= false;
161 // initially the list is empty, so why would we need the scrollbars?
163 wxPoint max
= m_llist
->GetSize();
164 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
165 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1);
166 EnableScrolling(true, true);
167 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
168 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
171 // no scrollbars initially
173 m_hasVScrollbar
= false;
177 #ifdef WXLAYOUT_USE_CARET
178 // FIXME cursor size shouldn't be hardcoded
179 wxCaret
*caret
= new wxCaret(this, 2, 20);
181 m_llist
->SetCaret(caret
);
183 #endif // WXLAYOUT_USE_CARET
185 m_HandCursor
= FALSE
;
186 m_CursorVisibility
= -1;
187 SetCursor(wxCURSOR_IBEAM
);
191 wxLayoutWindow::~wxLayoutWindow()
193 delete m_memDC
; // deletes bitmap automatically (?)
197 SetBackgroundBitmap(NULL
);
201 wxLayoutWindow::Clear(int family
,
209 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
210 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
211 wxScrolledWindow::Clear();
212 ResizeScrollbars(true);
215 wxScrolledWindow::Clear();
216 DoPaint((wxRect
*)NULL
);
219 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
221 wxScrolledWindow::Refresh(eraseBackground
, rect
);
228 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
230 wxClientDC
dc( this );
232 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
234 // moving the mouse in a window shouldn't give it the focus!
239 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
240 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
242 findPos
.x
-= WXLO_XOFFSET
;
243 findPos
.y
-= WXLO_YOFFSET
;
250 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
254 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
256 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
258 // has the mouse only been moved?
261 case WXLOWIN_MENU_MOUSEMOVE
:
262 // found is only true if we are really over an object, not just
264 if(found
&& u
&& ! m_Selecting
)
267 SetCursor(wxCURSOR_HAND
);
269 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
271 const wxString
&label
= u
->GetLabel();
273 m_StatusBar
->SetStatusText(label
,
280 SetCursor(wxCURSOR_IBEAM
);
281 m_HandCursor
= FALSE
;
282 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
283 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
287 if ( event
.LeftIsDown() )
289 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
291 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
292 DoPaint(); // TODO: we don't have to redraw everything!
302 case WXLOWIN_MENU_LDOWN
:
304 // always move cursor to mouse click:
307 // we have found the real position
308 m_llist
->MoveCursorTo(cursorPos
);
312 // click beyond the end of the text
313 m_llist
->MoveCursorToEnd();
316 // clicking a mouse removes the selection
317 if ( m_llist
->HasSelection() )
319 m_llist
->DiscardSelection();
320 DoPaint(); // TODO: we don't have to redraw everything!
323 // Calculate where the top of the visible area is:
327 GetScrollPixelsPerUnit(&dx
, &dy
);
330 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
332 if(m_CursorVisibility
== -1)
333 m_CursorVisibility
= 1;
335 if(m_CursorVisibility
!= 0)
337 // draw a thick cursor for editable windows with focus
338 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
341 // VZ: this should be unnecessary because mouse can only click on a
342 // visible part of the canvas
348 DoPaint(); // DoPaint suppresses flicker under GTK
352 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
357 case WXLOWIN_MENU_LUP
:
360 m_llist
->EndSelection();
363 DoPaint(); // TODO: we don't have to redraw everything!
367 case WXLOWIN_MENU_MDOWN
:
371 case WXLOWIN_MENU_DBLCLICK
:
372 // select a word under cursor
373 m_llist
->MoveCursorTo(cursorPos
);
374 m_llist
->MoveCursorWord(-1);
375 m_llist
->StartSelection();
376 m_llist
->MoveCursorWord(1, false);
377 m_llist
->EndSelection();
379 DoPaint(); // TODO: we don't have to redraw everything!
383 // notify about mouse events?
386 // only do the menu if activated, editable and not on a clickable object
387 if(eventId
== WXLOWIN_MENU_RCLICK
389 && (! obj
|| u
== NULL
))
391 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
396 // find the object at this position
399 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
400 commandEvent
.SetEventObject( this );
401 commandEvent
.SetClientData((char *)obj
);
402 GetEventHandler()->ProcessEvent(commandEvent
);
410 // ----------------------------------------------------------------------------
411 // keyboard handling.
412 // ----------------------------------------------------------------------------
415 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
417 int keyCode
= event
.KeyCode();
419 #ifdef WXLAYOUT_DEBUG
420 if(keyCode
== WXK_F1
)
427 wxASSERT_MSG( !m_Selecting
|| event
.ShiftDown(),
428 "m_Selecting is normally reset in OnKeyUp() when Shift "
431 if ( !m_Selecting
&& m_llist
->HasSelection() )
433 // pressing any non-arrow key replaces the selection
434 if ( !IsDirectionKey(keyCode
) )
436 m_llist
->DeleteSelection();
438 else if ( !event
.ShiftDown() )
440 m_llist
->DiscardSelection();
444 // <Shift>+<arrow> starts selection
445 if ( event
.ShiftDown() && IsDirectionKey(keyCode
) )
450 m_llist
->StartSelection();
452 //else: just continue the old selection
455 // If needed, make cursor visible:
456 if(m_CursorVisibility
== -1)
457 m_CursorVisibility
= 1;
459 /* These two nested switches work like this:
460 The first one processes all non-editing keycodes, to move the
461 cursor, etc. It's default will process all keycodes causing
462 modifications to the buffer, but only if editing is allowed.
464 bool ctrlDown
= event
.ControlDown();
469 m_llist
->MoveCursorWord(1);
471 m_llist
->MoveCursorHorizontally(1);
475 m_llist
->MoveCursorWord(-1);
477 m_llist
->MoveCursorHorizontally(-1);
480 m_llist
->MoveCursorVertically(-1);
483 m_llist
->MoveCursorVertically(1);
486 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
489 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
493 m_llist
->MoveCursorTo(wxPoint(0, 0));
495 m_llist
->MoveCursorToBeginOfLine();
499 m_llist
->MoveCursorToEnd();
501 m_llist
->MoveCursorToEndOfLine();
505 if(keyCode
== 'c' && ctrlDown
)
507 // this should work even in read-only mode
510 else if( IsEditable() )
512 /* First, handle control keys */
513 if(event
.ControlDown() && ! event
.AltDown())
525 m_llist
->DeleteLines(1);
527 case 'h': // like backspace
528 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
531 m_llist
->DeleteToBeginOfLine();
534 m_llist
->DeleteToEndOfLine();
542 #ifdef WXLAYOUT_DEBUG
544 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
552 else if( event
.AltDown() && ! event
.ControlDown() )
558 m_llist
->DeleteWord();
565 else if ( ! event
.AltDown() && ! event
.ControlDown())
570 if(event
.ShiftDown())
574 if(event
.ShiftDown())
579 case WXK_BACK
: // backspace
580 if(m_llist
->MoveCursorHorizontally(-1))
585 m_llist
->WrapLine(m_WrapMargin
);
586 m_llist
->LineBreak();
591 // TODO should be configurable
592 static const int tabSize
= 8;
594 CoordType x
= m_llist
->GetCursorPos().x
;
595 size_t numSpaces
= tabSize
- x
% tabSize
;
596 m_llist
->Insert(wxString(' ', numSpaces
));
601 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
602 && (keyCode
< 256 && keyCode
>= 32)
605 if(m_WrapMargin
> 0 && isspace(keyCode
))
606 m_llist
->WrapLine(m_WrapMargin
);
607 m_llist
->Insert((char)keyCode
);
619 // continue selection to the current (new) cursor position
620 m_llist
->ContinueSelection();
623 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
624 // ne cursor position might be outside the current scrolllbar range
628 // refresh the screen
629 DoPaint(m_llist
->GetUpdateRect());
633 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
635 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
637 m_llist
->EndSelection();
646 wxLayoutWindow::ScrollToCursor(void)
648 wxClientDC
dc( this );
651 int x0
,y0
,x1
,y1
, dx
, dy
;
653 // Calculate where the top of the visible area is:
655 GetScrollPixelsPerUnit(&dx
, &dy
);
658 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
660 // Get the size of the visible window:
661 GetClientSize(&x1
, &y1
);
663 // update the cursor screen position
666 // Make sure that the scrollbars are at a position so that the cursor is
667 // visible if we are editing
668 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
669 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
671 // the cursor should be completely visible in both directions
672 wxPoint
cs(m_llist
->GetCursorSize());
675 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
682 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
689 if ( nx
!= -1 || ny
!= -1 )
691 // set new view start
692 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
695 m_ScrollToCursor
= false;
700 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
702 wxRect region
= GetUpdateRegion().GetBox();
703 InternalPaint(®ion
);
707 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
710 InternalPaint(updateRect
);
711 #else // Causes bad flicker under wxGTK!!!
712 Refresh(FALSE
); //, updateRect);
714 if ( !::UpdateWindow(GetHwnd()) )
715 wxLogLastError("UpdateWindow");
720 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
722 wxPaintDC
dc( this );
725 #ifdef WXLAYOUT_USE_CARET
726 // hide the caret before drawing anything
728 #endif // WXLAYOUT_USE_CARET
730 int x0
,y0
,x1
,y1
, dx
, dy
;
732 // Calculate where the top of the visible area is:
734 GetScrollPixelsPerUnit(&dx
, &dy
);
737 // Get the size of the visible window:
738 GetClientSize(&x1
,&y1
);
744 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
745 updateRect
->x
, updateRect
->y
,
746 updateRect
->x
+updateRect
->width
,
747 updateRect
->y
+updateRect
->height
));
754 /* Check whether the window has grown, if so, we need to reallocate
755 the bitmap to be larger. */
756 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
758 wxASSERT(m_bitmapSize
.x
> 0);
759 wxASSERT(m_bitmapSize
.y
> 0);
761 m_memDC
->SelectObject(wxNullBitmap
);
763 m_bitmapSize
= wxPoint(x1
,y1
);
764 m_bitmap
= new wxBitmap(x1
,y1
);
765 m_memDC
->SelectObject(*m_bitmap
);
768 m_memDC
->SetDeviceOrigin(0,0);
769 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
770 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
772 m_memDC
->SetLogicalFunction(wxCOPY
);
775 // fill the background with the background bitmap
780 w
= m_BGbitmap
->GetWidth(),
781 h
= m_BGbitmap
->GetHeight();
782 for(y
= 0; y
< y1
; y
+=h
)
783 for(x
= 0; x
< x1
; x
+=w
)
784 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
785 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
788 // This is the important bit: we tell the list to draw itself
792 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
793 updateRect
->x
, updateRect
->y
,
794 updateRect
->x
+updateRect
->width
,
795 updateRect
->y
+updateRect
->height
));
799 // Device origins on the memDC are suspect, we translate manually
800 // with the translate parameter of Draw().
801 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
802 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
804 // We start calculating a new update rect before drawing the
805 // cursor, so that the cursor coordinates get included in the next
806 // update rectangle (although they are drawn on the memDC, this is
807 // needed to erase it):
808 m_llist
->InvalidateUpdateRect();
809 if(m_CursorVisibility
!= 0)
811 // draw a thick cursor for editable windows with focus
812 m_llist
->DrawCursor(*m_memDC
,
813 m_HaveFocus
&& IsEditable(),
817 // Now copy everything to the screen:
819 // This somehow doesn't work, but even the following bit with the
820 // whole rect at once is still a bit broken I think.
821 wxRegionIterator
ri ( GetUpdateRegion() );
825 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
826 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
827 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
828 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
834 // FIXME: Trying to copy only the changed parts, but it does not seem
836 // x0 = updateRect->x; y0 = updateRect->y;
837 // if(updateRect->height < y1)
838 // y1 = updateRect->height;
839 // y1 += WXLO_YOFFSET; //FIXME might not be needed
840 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
843 #ifdef WXLAYOUT_USE_CARET
844 // show the caret back after everything is redrawn
846 #endif // WXLAYOUT_USE_CARET
849 m_ScrollToCursor
= false;
851 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
853 static wxPoint
s_oldCursorPos(-1, -1);
855 wxPoint
pos(m_llist
->GetCursorPos());
857 // avoid unnecessary status bar refreshes
858 if ( pos
!= s_oldCursorPos
)
860 s_oldCursorPos
= pos
;
863 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
864 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
870 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
880 // change the range and position of scrollbars
882 wxLayoutWindow::ResizeScrollbars(bool exact
)
884 wxPoint max
= m_llist
->GetSize();
885 wxSize size
= GetClientSize();
887 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
888 (long int)max
.x
, (long int) max
.y
));
890 // in the absence of scrollbars we should compare with the client size
891 if ( !m_hasHScrollbar
)
892 m_maxx
= size
.x
- WXLO_ROFFSET
;
893 if ( !m_hasVScrollbar
)
894 m_maxy
= size
.y
- WXLO_BOFFSET
;
896 // check if the text hasn't become too big
897 // TODO why do we set both at once? they're independent...
898 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
900 // text became too large
903 // add an extra bit to the sizes to avoid future updates
904 max
.x
+= WXLO_ROFFSET
;
905 max
.y
+= WXLO_BOFFSET
;
908 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
909 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
910 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
911 m_ViewStartX
, m_ViewStartY
,
915 m_hasVScrollbar
= true;
917 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
918 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
923 // check if the window hasn't become too big, thus making the scrollbars
925 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
927 // remove the horizontal scrollbar
928 SetScrollbars(0, -1, 0, -1, 0, -1, true);
929 m_hasHScrollbar
= false;
932 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
934 // remove the vertical scrollbar
935 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
936 m_hasVScrollbar
= false;
942 // ----------------------------------------------------------------------------
943 // clipboard operations
945 // ----------------------------------------------------------------------------
948 wxLayoutWindow::Paste(bool primary
)
951 if (wxTheClipboard
->Open())
955 wxTheClipboard
->UsePrimarySelection();
957 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
958 wxLayoutDataObject wxldo
;
959 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
961 wxTheClipboard
->GetData(&wxldo
);
964 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
969 wxTextDataObject data
;
970 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
972 wxTheClipboard
->GetData(&data
);
973 wxString text
= data
.GetText();
974 wxLayoutImportText( m_llist
, text
);
977 wxTheClipboard
->Close();
981 /* My attempt to get the primary selection, but it does not
983 if(text
.Length() == 0)
985 wxTextCtrl
tmp_tctrl(this,-1);
987 text
+= tmp_tctrl
.GetValue();
993 wxLayoutWindow::Copy(bool invalidate
)
995 // Calling GetSelection() will automatically do an EndSelection()
996 // on the list, but we need to take a note of it, too:
1000 m_llist
->EndSelection();
1003 wxLayoutDataObject wldo
;
1004 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1007 // Export selection as text:
1009 wxLayoutExportObject
*export
;
1010 wxLayoutExportStatus
status(llist
);
1011 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1013 if(export
->type
== WXLO_EXPORT_TEXT
)
1014 text
<< *(export
->content
.text
);
1019 // The exporter always appends a newline, so we chop it off if it
1022 size_t len
= text
.Length();
1023 if(len
> 2 && text
[len
-2] == '\r') // Windows
1024 text
= text
.Mid(0,len
-2);
1025 else if(len
> 1 && text
[len
-1] == '\n')
1026 text
= text
.Mid(0,len
-1);
1030 if (wxTheClipboard
->Open())
1032 wxTextDataObject
*data
= new wxTextDataObject( text
);
1033 bool rc
= wxTheClipboard
->SetData( data
);
1034 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1035 rc
|= wxTheClipboard
->AddData( &wldo
);
1037 wxTheClipboard
->Close();
1045 wxLayoutWindow::Cut(void)
1047 if(Copy(false)) // do not invalidate selection after copy
1049 m_llist
->DeleteSelection();
1056 // ----------------------------------------------------------------------------
1058 // ----------------------------------------------------------------------------
1061 wxLayoutWindow::Find(const wxString
&needle
,
1062 wxPoint
* fromWhere
)
1066 if(fromWhere
== NULL
)
1067 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1069 found
= m_llist
->FindText(needle
, *fromWhere
);
1077 m_llist
->MoveCursorTo(found
);
1084 // ----------------------------------------------------------------------------
1086 // ----------------------------------------------------------------------------
1089 wxLayoutWindow::MakeFormatMenu()
1091 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1093 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1094 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1095 m
->AppendSeparator();
1096 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1097 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1098 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1099 m
->AppendSeparator();
1100 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1101 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1102 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1107 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1109 event
.Check(m_llist
->IsFontUnderlined());
1112 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1114 event
.Check(m_llist
->IsFontBold());
1117 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1119 event
.Check(m_llist
->IsFontItalic());
1122 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1124 switch (event
.GetId())
1126 case WXLOWIN_MENU_LARGER
:
1127 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1128 case WXLOWIN_MENU_SMALLER
:
1129 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1130 case WXLOWIN_MENU_UNDERLINE
:
1131 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1132 case WXLOWIN_MENU_BOLD
:
1133 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1134 case WXLOWIN_MENU_ITALICS
:
1135 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1136 case WXLOWIN_MENU_ROMAN
:
1137 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1138 case WXLOWIN_MENU_TYPEWRITER
:
1139 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1140 case WXLOWIN_MENU_SANSSERIF
:
1141 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1145 // ----------------------------------------------------------------------------
1147 // ----------------------------------------------------------------------------
1150 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1157 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1159 m_HaveFocus
= false;
1163 // ----------------------------------------------------------------------------
1164 // private functions
1165 // ----------------------------------------------------------------------------
1167 static bool IsDirectionKey(long keyCode
)