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();
157 SetAutoDeleteSelection(true);
159 SetAutoDeleteSelection(false);
162 m_ScrollToCursor
= false;
165 // no scrollbars initially
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 wxScrolledWindow::Clear();
206 ResizeScrollbars(true);
209 wxScrolledWindow::Clear();
210 DoPaint((wxRect
*)NULL
);
213 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
215 wxScrolledWindow::Refresh(eraseBackground
, rect
);
222 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
224 wxClientDC
dc( this );
226 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
228 // moving the mouse in a window shouldn't give it the focus!
229 // Oh yes! wxGTK's focus handling is so broken, that this is the
230 // only sensible way to go.
235 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
236 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
238 findPos
.x
-= WXLO_XOFFSET
;
239 findPos
.y
-= WXLO_YOFFSET
;
246 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
250 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
252 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
254 // has the mouse only been moved?
257 case WXLOWIN_MENU_MOUSEMOVE
:
258 // found is only true if we are really over an object, not just
260 if(found
&& u
&& ! m_Selecting
)
263 SetCursor(wxCURSOR_HAND
);
265 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
267 const wxString
&label
= u
->GetLabel();
269 m_StatusBar
->SetStatusText(label
,
276 SetCursor(wxCURSOR_IBEAM
);
277 m_HandCursor
= FALSE
;
278 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
279 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
283 if ( event
.LeftIsDown() )
285 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
287 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
288 DoPaint(); // TODO: we don't have to redraw everything!
298 case WXLOWIN_MENU_LDOWN
:
300 // always move cursor to mouse click:
303 // we have found the real position
304 m_llist
->MoveCursorTo(cursorPos
);
308 // click beyond the end of the text
309 m_llist
->MoveCursorToEnd();
312 // clicking a mouse removes the selection
313 if ( m_llist
->HasSelection() )
315 m_llist
->DiscardSelection();
317 DoPaint(); // TODO: we don't have to redraw everything!
320 // Calculate where the top of the visible area is:
324 GetScrollPixelsPerUnit(&dx
, &dy
);
327 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
329 if(m_CursorVisibility
== -1)
330 m_CursorVisibility
= 1;
332 if(m_CursorVisibility
!= 0)
334 // draw a thick cursor for editable windows with focus
335 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
339 DoPaint(); // DoPaint suppresses flicker under GTK
343 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
348 case WXLOWIN_MENU_LUP
:
351 m_llist
->EndSelection();
354 DoPaint(); // TODO: we don't have to redraw everything!
358 case WXLOWIN_MENU_MDOWN
:
362 case WXLOWIN_MENU_DBLCLICK
:
363 // select a word under cursor
364 m_llist
->MoveCursorTo(cursorPos
);
365 m_llist
->MoveCursorWord(-1);
366 m_llist
->StartSelection();
367 m_llist
->MoveCursorWord(1, false);
368 m_llist
->EndSelection();
370 DoPaint(); // TODO: we don't have to redraw everything!
374 // notify about mouse events?
377 // only do the menu if activated, editable and not on a clickable object
378 if(eventId
== WXLOWIN_MENU_RCLICK
380 && (! obj
|| u
== NULL
))
382 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
387 // find the object at this position
390 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
391 commandEvent
.SetEventObject( this );
392 commandEvent
.SetClientData((char *)obj
);
393 GetEventHandler()->ProcessEvent(commandEvent
);
401 // ----------------------------------------------------------------------------
402 // keyboard handling.
403 // ----------------------------------------------------------------------------
406 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
408 int keyCode
= event
.KeyCode();
409 bool ctrlDown
= event
.ControlDown();
411 #ifdef WXLAYOUT_DEBUG
412 if(keyCode
== WXK_F1
)
420 // Force m_Selecting to be false if shift is no longer
421 // pressed. OnKeyUp() cannot catch all Shift-Up events.
422 if(m_Selecting
&& !event
.ShiftDown())
425 m_llist
->EndSelection();
429 // If we deleted the selection here, we must not execute the
430 // deletion in Delete/Backspace handling.
431 bool deletedSelection
= false;
432 // pressing any non-arrow key optionally replaces the selection:
433 if(m_AutoDeleteSelection
435 && m_llist
->HasSelection()
436 && ! IsDirectionKey(keyCode
)
437 && ! (event
.AltDown() || ctrlDown
)
440 m_llist
->DeleteSelection();
441 deletedSelection
= true;
444 // <Shift>+<arrow> starts selection
445 if ( IsDirectionKey(keyCode
) )
449 // just continue the old selection
450 if( event
.ShiftDown() )
451 m_llist
->ContinueSelection();
454 m_llist
->DiscardSelection();
458 else if( event
.ShiftDown() )
461 m_llist
->StartSelection();
466 // If needed, make cursor visible:
467 if(m_CursorVisibility
== -1)
468 m_CursorVisibility
= 1;
470 /* These two nested switches work like this:
471 The first one processes all non-editing keycodes, to move the
472 cursor, etc. It's default will process all keycodes causing
473 modifications to the buffer, but only if editing is allowed.
479 m_llist
->MoveCursorWord(1);
481 m_llist
->MoveCursorHorizontally(1);
485 m_llist
->MoveCursorWord(-1);
487 m_llist
->MoveCursorHorizontally(-1);
490 m_llist
->MoveCursorVertically(-1);
493 m_llist
->MoveCursorVertically(1);
496 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
499 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
503 m_llist
->MoveCursorTo(wxPoint(0, 0));
505 m_llist
->MoveCursorToBeginOfLine();
509 m_llist
->MoveCursorToEnd();
511 m_llist
->MoveCursorToEndOfLine();
515 if(keyCode
== 'c' && ctrlDown
)
517 // this should work even in read-only mode
520 else if( IsEditable() )
522 /* First, handle control keys */
523 if(ctrlDown
&& ! event
.AltDown())
532 if(! deletedSelection
) // already done
536 m_llist
->DeleteLines(1);
538 case 'h': // like backspace
539 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
542 m_llist
->DeleteToBeginOfLine();
545 m_llist
->DeleteToEndOfLine();
553 #ifdef WXLAYOUT_DEBUG
555 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
563 else if( event
.AltDown() && ! event
.ControlDown() )
569 m_llist
->DeleteWord();
576 else if ( ! event
.AltDown() && ! event
.ControlDown())
581 if(event
.ShiftDown())
585 if(event
.ShiftDown())
588 if(! deletedSelection
)
591 case WXK_BACK
: // backspace
592 if(! deletedSelection
)
593 if(m_llist
->MoveCursorHorizontally(-1))
598 m_llist
->WrapLine(m_WrapMargin
);
599 m_llist
->LineBreak();
604 // TODO should be configurable
605 static const int tabSize
= 8;
607 CoordType x
= m_llist
->GetCursorPos().x
;
608 size_t numSpaces
= tabSize
- x
% tabSize
;
609 m_llist
->Insert(wxString(' ', numSpaces
));
614 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
615 && (keyCode
< 256 && keyCode
>= 32)
618 if(m_WrapMargin
> 0 && isspace(keyCode
))
619 m_llist
->WrapLine(m_WrapMargin
);
620 m_llist
->Insert((char)keyCode
);
632 // continue selection to the current (new) cursor position
633 m_llist
->ContinueSelection();
636 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
637 // ne cursor position might be outside the current scrolllbar range
641 // refresh the screen
642 DoPaint(m_llist
->GetUpdateRect());
646 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
648 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
650 m_llist
->EndSelection();
659 wxLayoutWindow::ScrollToCursor(void)
661 wxClientDC
dc( this );
664 int x0
,y0
,x1
,y1
, dx
, dy
;
666 // Calculate where the top of the visible area is:
668 GetScrollPixelsPerUnit(&dx
, &dy
);
671 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
673 // Get the size of the visible window:
674 GetClientSize(&x1
, &y1
);
676 // update the cursor screen position
679 // Make sure that the scrollbars are at a position so that the cursor is
680 // visible if we are editing
681 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
682 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
684 // the cursor should be completely visible in both directions
685 wxPoint
cs(m_llist
->GetCursorSize());
688 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
695 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
702 if ( nx
!= -1 || ny
!= -1 )
704 // set new view start
705 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
708 m_ScrollToCursor
= false;
713 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
715 wxRect region
= GetUpdateRegion().GetBox();
716 InternalPaint(®ion
);
720 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
723 InternalPaint(updateRect
);
724 #else // Causes bad flicker under wxGTK!!!
725 Refresh(FALSE
); //, updateRect);
727 if ( !::UpdateWindow(GetHwnd()) )
728 wxLogLastError("UpdateWindow");
733 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
735 wxPaintDC
dc( this );
738 #ifdef WXLAYOUT_USE_CARET
739 // hide the caret before drawing anything
741 #endif // WXLAYOUT_USE_CARET
743 int x0
,y0
,x1
,y1
, dx
, dy
;
745 // Calculate where the top of the visible area is:
747 GetScrollPixelsPerUnit(&dx
, &dy
);
750 // Get the size of the visible window:
751 GetClientSize(&x1
,&y1
);
757 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
758 updateRect
->x
, updateRect
->y
,
759 updateRect
->x
+updateRect
->width
,
760 updateRect
->y
+updateRect
->height
));
767 /* Check whether the window has grown, if so, we need to reallocate
768 the bitmap to be larger. */
769 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
771 wxASSERT(m_bitmapSize
.x
> 0);
772 wxASSERT(m_bitmapSize
.y
> 0);
774 m_memDC
->SelectObject(wxNullBitmap
);
776 m_bitmapSize
= wxPoint(x1
,y1
);
777 m_bitmap
= new wxBitmap(x1
,y1
);
778 m_memDC
->SelectObject(*m_bitmap
);
781 m_memDC
->SetDeviceOrigin(0,0);
782 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
783 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
785 m_memDC
->SetLogicalFunction(wxCOPY
);
788 // fill the background with the background bitmap
793 w
= m_BGbitmap
->GetWidth(),
794 h
= m_BGbitmap
->GetHeight();
795 for(y
= 0; y
< y1
; y
+=h
)
796 for(x
= 0; x
< x1
; x
+=w
)
797 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
798 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
801 // This is the important bit: we tell the list to draw itself
805 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
806 updateRect
->x
, updateRect
->y
,
807 updateRect
->x
+updateRect
->width
,
808 updateRect
->y
+updateRect
->height
));
812 // Device origins on the memDC are suspect, we translate manually
813 // with the translate parameter of Draw().
814 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
815 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
817 // We start calculating a new update rect before drawing the
818 // cursor, so that the cursor coordinates get included in the next
819 // update rectangle (although they are drawn on the memDC, this is
820 // needed to erase it):
821 m_llist
->InvalidateUpdateRect();
822 if(m_CursorVisibility
!= 0)
824 // draw a thick cursor for editable windows with focus
825 m_llist
->DrawCursor(*m_memDC
,
826 m_HaveFocus
&& IsEditable(),
830 // Now copy everything to the screen:
832 // This somehow doesn't work, but even the following bit with the
833 // whole rect at once is still a bit broken I think.
834 wxRegionIterator
ri ( GetUpdateRegion() );
838 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
839 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
840 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
841 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
847 // FIXME: Trying to copy only the changed parts, but it does not seem
849 // x0 = updateRect->x; y0 = updateRect->y;
850 // if(updateRect->height < y1)
851 // y1 = updateRect->height;
852 // y1 += WXLO_YOFFSET; //FIXME might not be needed
853 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
856 #ifdef WXLAYOUT_USE_CARET
857 // show the caret back after everything is redrawn
859 #endif // WXLAYOUT_USE_CARET
862 m_ScrollToCursor
= false;
864 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
866 static wxPoint
s_oldCursorPos(-1, -1);
868 wxPoint
pos(m_llist
->GetCursorPos());
870 // avoid unnecessary status bar refreshes
871 if ( pos
!= s_oldCursorPos
)
873 s_oldCursorPos
= pos
;
876 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
877 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
883 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
893 // change the range and position of scrollbars
895 wxLayoutWindow::ResizeScrollbars(bool exact
)
897 wxPoint max
= m_llist
->GetSize();
898 wxSize size
= GetClientSize();
900 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
901 (long int)max
.x
, (long int) max
.y
));
903 // in the absence of scrollbars we should compare with the client size
904 if ( !m_hasHScrollbar
)
905 m_maxx
= size
.x
- WXLO_ROFFSET
;
906 if ( !m_hasVScrollbar
)
907 m_maxy
= size
.y
- WXLO_BOFFSET
;
909 // check if the text hasn't become too big
910 // TODO why do we set both at once? they're independent...
911 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
913 // text became too large
916 // add an extra bit to the sizes to avoid future updates
917 max
.x
+= WXLO_ROFFSET
;
918 max
.y
+= WXLO_BOFFSET
;
921 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
922 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
923 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
924 m_ViewStartX
, m_ViewStartY
,
928 m_hasVScrollbar
= true;
930 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
931 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
936 // check if the window hasn't become too big, thus making the scrollbars
938 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
940 // remove the horizontal scrollbar
941 SetScrollbars(0, -1, 0, -1, 0, -1, true);
942 m_hasHScrollbar
= false;
945 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
947 // remove the vertical scrollbar
948 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
949 m_hasVScrollbar
= false;
955 // ----------------------------------------------------------------------------
956 // clipboard operations
958 // ----------------------------------------------------------------------------
961 wxLayoutWindow::Paste(bool primary
)
964 if (wxTheClipboard
->Open())
968 wxTheClipboard
->UsePrimarySelection();
970 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
971 wxLayoutDataObject wxldo
;
972 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
974 wxTheClipboard
->GetData(&wxldo
);
977 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
982 wxTextDataObject data
;
983 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
985 wxTheClipboard
->GetData(&data
);
986 wxString text
= data
.GetText();
987 wxLayoutImportText( m_llist
, text
);
990 wxTheClipboard
->Close();
995 wxLayoutWindow::Copy(bool invalidate
)
997 // Calling GetSelection() will automatically do an EndSelection()
998 // on the list, but we need to take a note of it, too:
1001 m_Selecting
= false;
1002 m_llist
->EndSelection();
1005 wxLayoutDataObject wldo
;
1006 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1009 // Export selection as text:
1011 wxLayoutExportObject
*export
;
1012 wxLayoutExportStatus
status(llist
);
1013 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1015 if(export
->type
== WXLO_EXPORT_TEXT
)
1016 text
<< *(export
->content
.text
);
1021 // The exporter always appends a newline, so we chop it off if it
1024 size_t len
= text
.Length();
1025 if(len
> 2 && text
[len
-2] == '\r') // Windows
1026 text
= text
.Mid(0,len
-2);
1027 else if(len
> 1 && text
[len
-1] == '\n')
1028 text
= text
.Mid(0,len
-1);
1032 if (wxTheClipboard
->Open())
1034 wxTextDataObject
*data
= new wxTextDataObject( text
);
1035 bool rc
= wxTheClipboard
->SetData( data
);
1036 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1037 rc
|= wxTheClipboard
->AddData( &wldo
);
1039 wxTheClipboard
->Close();
1047 wxLayoutWindow::Cut(void)
1049 if(Copy(false)) // do not invalidate selection after copy
1051 m_llist
->DeleteSelection();
1058 // ----------------------------------------------------------------------------
1060 // ----------------------------------------------------------------------------
1063 wxLayoutWindow::Find(const wxString
&needle
,
1064 wxPoint
* fromWhere
)
1068 if(fromWhere
== NULL
)
1069 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1071 found
= m_llist
->FindText(needle
, *fromWhere
);
1079 m_llist
->MoveCursorTo(found
);
1086 // ----------------------------------------------------------------------------
1088 // ----------------------------------------------------------------------------
1091 wxLayoutWindow::MakeFormatMenu()
1093 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1095 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1096 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1097 m
->AppendSeparator();
1098 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1099 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1100 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1101 m
->AppendSeparator();
1102 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1103 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1104 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1109 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1111 event
.Check(m_llist
->IsFontUnderlined());
1114 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1116 event
.Check(m_llist
->IsFontBold());
1119 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1121 event
.Check(m_llist
->IsFontItalic());
1124 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1126 switch (event
.GetId())
1128 case WXLOWIN_MENU_LARGER
:
1129 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1130 case WXLOWIN_MENU_SMALLER
:
1131 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1132 case WXLOWIN_MENU_UNDERLINE
:
1133 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1134 case WXLOWIN_MENU_BOLD
:
1135 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1136 case WXLOWIN_MENU_ITALICS
:
1137 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1138 case WXLOWIN_MENU_ROMAN
:
1139 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1140 case WXLOWIN_MENU_TYPEWRITER
:
1141 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1142 case WXLOWIN_MENU_SANSSERIF
:
1143 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1147 // ----------------------------------------------------------------------------
1149 // ----------------------------------------------------------------------------
1152 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1159 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1161 m_HaveFocus
= false;
1165 // ----------------------------------------------------------------------------
1166 // private functions
1167 // ----------------------------------------------------------------------------
1169 static bool IsDirectionKey(long keyCode
)