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();
418 bool ctrlDown
= event
.ControlDown();
420 #ifdef WXLAYOUT_DEBUG
421 if(keyCode
== WXK_F1
)
428 // Force m_Selecting to be false if shift is no longer
429 // pressed. OnKeyUp() cannot catch all Shift-Up events.
430 if(!event
.ShiftDown())
433 // pressing any non-arrow key optionally replaces the selection:
434 if(m_AutoDeleteSelection
436 && m_llist
->HasSelection()
437 && ! IsDirectionKey(keyCode
)
438 && ! (event
.AltDown() || ctrlDown
)
440 m_llist
->DeleteSelection();
442 // <Shift>+<arrow> starts selection
443 if ( IsDirectionKey(keyCode
) )
448 m_llist
->StartSelection();
452 // just continue the old selection
453 if(! event
.ShiftDown() )
454 m_llist
->DiscardSelection();
458 // If needed, make cursor visible:
459 if(m_CursorVisibility
== -1)
460 m_CursorVisibility
= 1;
462 /* These two nested switches work like this:
463 The first one processes all non-editing keycodes, to move the
464 cursor, etc. It's default will process all keycodes causing
465 modifications to the buffer, but only if editing is allowed.
471 m_llist
->MoveCursorWord(1);
473 m_llist
->MoveCursorHorizontally(1);
477 m_llist
->MoveCursorWord(-1);
479 m_llist
->MoveCursorHorizontally(-1);
482 m_llist
->MoveCursorVertically(-1);
485 m_llist
->MoveCursorVertically(1);
488 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
491 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
495 m_llist
->MoveCursorTo(wxPoint(0, 0));
497 m_llist
->MoveCursorToBeginOfLine();
501 m_llist
->MoveCursorToEnd();
503 m_llist
->MoveCursorToEndOfLine();
507 if(keyCode
== 'c' && ctrlDown
)
509 // this should work even in read-only mode
512 else if( IsEditable() )
514 /* First, handle control keys */
515 if(ctrlDown
&& ! event
.AltDown())
527 m_llist
->DeleteLines(1);
529 case 'h': // like backspace
530 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
533 m_llist
->DeleteToBeginOfLine();
536 m_llist
->DeleteToEndOfLine();
544 #ifdef WXLAYOUT_DEBUG
546 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
554 else if( event
.AltDown() && ! event
.ControlDown() )
560 m_llist
->DeleteWord();
567 else if ( ! event
.AltDown() && ! event
.ControlDown())
572 if(event
.ShiftDown())
576 if(event
.ShiftDown())
581 case WXK_BACK
: // backspace
582 if(m_llist
->MoveCursorHorizontally(-1))
587 m_llist
->WrapLine(m_WrapMargin
);
588 m_llist
->LineBreak();
593 // TODO should be configurable
594 static const int tabSize
= 8;
596 CoordType x
= m_llist
->GetCursorPos().x
;
597 size_t numSpaces
= tabSize
- x
% tabSize
;
598 m_llist
->Insert(wxString(' ', numSpaces
));
603 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
604 && (keyCode
< 256 && keyCode
>= 32)
607 if(m_WrapMargin
> 0 && isspace(keyCode
))
608 m_llist
->WrapLine(m_WrapMargin
);
609 m_llist
->Insert((char)keyCode
);
621 // continue selection to the current (new) cursor position
622 m_llist
->ContinueSelection();
625 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
626 // ne cursor position might be outside the current scrolllbar range
630 // refresh the screen
631 DoPaint(m_llist
->GetUpdateRect());
635 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
637 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
639 m_llist
->EndSelection();
648 wxLayoutWindow::ScrollToCursor(void)
650 wxClientDC
dc( this );
653 int x0
,y0
,x1
,y1
, dx
, dy
;
655 // Calculate where the top of the visible area is:
657 GetScrollPixelsPerUnit(&dx
, &dy
);
660 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
662 // Get the size of the visible window:
663 GetClientSize(&x1
, &y1
);
665 // update the cursor screen position
668 // Make sure that the scrollbars are at a position so that the cursor is
669 // visible if we are editing
670 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
671 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
673 // the cursor should be completely visible in both directions
674 wxPoint
cs(m_llist
->GetCursorSize());
677 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
684 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
691 if ( nx
!= -1 || ny
!= -1 )
693 // set new view start
694 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
697 m_ScrollToCursor
= false;
702 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
704 wxRect region
= GetUpdateRegion().GetBox();
705 InternalPaint(®ion
);
709 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
712 InternalPaint(updateRect
);
713 #else // Causes bad flicker under wxGTK!!!
714 Refresh(FALSE
); //, updateRect);
716 if ( !::UpdateWindow(GetHwnd()) )
717 wxLogLastError("UpdateWindow");
722 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
724 wxPaintDC
dc( this );
727 #ifdef WXLAYOUT_USE_CARET
728 // hide the caret before drawing anything
730 #endif // WXLAYOUT_USE_CARET
732 int x0
,y0
,x1
,y1
, dx
, dy
;
734 // Calculate where the top of the visible area is:
736 GetScrollPixelsPerUnit(&dx
, &dy
);
739 // Get the size of the visible window:
740 GetClientSize(&x1
,&y1
);
746 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
747 updateRect
->x
, updateRect
->y
,
748 updateRect
->x
+updateRect
->width
,
749 updateRect
->y
+updateRect
->height
));
756 /* Check whether the window has grown, if so, we need to reallocate
757 the bitmap to be larger. */
758 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
760 wxASSERT(m_bitmapSize
.x
> 0);
761 wxASSERT(m_bitmapSize
.y
> 0);
763 m_memDC
->SelectObject(wxNullBitmap
);
765 m_bitmapSize
= wxPoint(x1
,y1
);
766 m_bitmap
= new wxBitmap(x1
,y1
);
767 m_memDC
->SelectObject(*m_bitmap
);
770 m_memDC
->SetDeviceOrigin(0,0);
771 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
772 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
774 m_memDC
->SetLogicalFunction(wxCOPY
);
777 // fill the background with the background bitmap
782 w
= m_BGbitmap
->GetWidth(),
783 h
= m_BGbitmap
->GetHeight();
784 for(y
= 0; y
< y1
; y
+=h
)
785 for(x
= 0; x
< x1
; x
+=w
)
786 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
787 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
790 // This is the important bit: we tell the list to draw itself
794 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
795 updateRect
->x
, updateRect
->y
,
796 updateRect
->x
+updateRect
->width
,
797 updateRect
->y
+updateRect
->height
));
801 // Device origins on the memDC are suspect, we translate manually
802 // with the translate parameter of Draw().
803 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
804 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
806 // We start calculating a new update rect before drawing the
807 // cursor, so that the cursor coordinates get included in the next
808 // update rectangle (although they are drawn on the memDC, this is
809 // needed to erase it):
810 m_llist
->InvalidateUpdateRect();
811 if(m_CursorVisibility
!= 0)
813 // draw a thick cursor for editable windows with focus
814 m_llist
->DrawCursor(*m_memDC
,
815 m_HaveFocus
&& IsEditable(),
819 // Now copy everything to the screen:
821 // This somehow doesn't work, but even the following bit with the
822 // whole rect at once is still a bit broken I think.
823 wxRegionIterator
ri ( GetUpdateRegion() );
827 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
828 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
829 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
830 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
836 // FIXME: Trying to copy only the changed parts, but it does not seem
838 // x0 = updateRect->x; y0 = updateRect->y;
839 // if(updateRect->height < y1)
840 // y1 = updateRect->height;
841 // y1 += WXLO_YOFFSET; //FIXME might not be needed
842 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
845 #ifdef WXLAYOUT_USE_CARET
846 // show the caret back after everything is redrawn
848 #endif // WXLAYOUT_USE_CARET
851 m_ScrollToCursor
= false;
853 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
855 static wxPoint
s_oldCursorPos(-1, -1);
857 wxPoint
pos(m_llist
->GetCursorPos());
859 // avoid unnecessary status bar refreshes
860 if ( pos
!= s_oldCursorPos
)
862 s_oldCursorPos
= pos
;
865 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
866 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
872 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
882 // change the range and position of scrollbars
884 wxLayoutWindow::ResizeScrollbars(bool exact
)
886 wxPoint max
= m_llist
->GetSize();
887 wxSize size
= GetClientSize();
889 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
890 (long int)max
.x
, (long int) max
.y
));
892 // in the absence of scrollbars we should compare with the client size
893 if ( !m_hasHScrollbar
)
894 m_maxx
= size
.x
- WXLO_ROFFSET
;
895 if ( !m_hasVScrollbar
)
896 m_maxy
= size
.y
- WXLO_BOFFSET
;
898 // check if the text hasn't become too big
899 // TODO why do we set both at once? they're independent...
900 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
902 // text became too large
905 // add an extra bit to the sizes to avoid future updates
906 max
.x
+= WXLO_ROFFSET
;
907 max
.y
+= WXLO_BOFFSET
;
910 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
911 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
912 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
913 m_ViewStartX
, m_ViewStartY
,
917 m_hasVScrollbar
= true;
919 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
920 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
925 // check if the window hasn't become too big, thus making the scrollbars
927 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
929 // remove the horizontal scrollbar
930 SetScrollbars(0, -1, 0, -1, 0, -1, true);
931 m_hasHScrollbar
= false;
934 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
936 // remove the vertical scrollbar
937 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
938 m_hasVScrollbar
= false;
944 // ----------------------------------------------------------------------------
945 // clipboard operations
947 // ----------------------------------------------------------------------------
950 wxLayoutWindow::Paste(bool primary
)
953 if (wxTheClipboard
->Open())
957 wxTheClipboard
->UsePrimarySelection();
959 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
960 wxLayoutDataObject wxldo
;
961 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
963 wxTheClipboard
->GetData(&wxldo
);
966 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
971 wxTextDataObject data
;
972 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
974 wxTheClipboard
->GetData(&data
);
975 wxString text
= data
.GetText();
976 wxLayoutImportText( m_llist
, text
);
979 wxTheClipboard
->Close();
984 wxLayoutWindow::Copy(bool invalidate
)
986 // Calling GetSelection() will automatically do an EndSelection()
987 // on the list, but we need to take a note of it, too:
991 m_llist
->EndSelection();
994 wxLayoutDataObject wldo
;
995 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
998 // Export selection as text:
1000 wxLayoutExportObject
*export
;
1001 wxLayoutExportStatus
status(llist
);
1002 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1004 if(export
->type
== WXLO_EXPORT_TEXT
)
1005 text
<< *(export
->content
.text
);
1010 // The exporter always appends a newline, so we chop it off if it
1013 size_t len
= text
.Length();
1014 if(len
> 2 && text
[len
-2] == '\r') // Windows
1015 text
= text
.Mid(0,len
-2);
1016 else if(len
> 1 && text
[len
-1] == '\n')
1017 text
= text
.Mid(0,len
-1);
1021 if (wxTheClipboard
->Open())
1023 wxTextDataObject
*data
= new wxTextDataObject( text
);
1024 bool rc
= wxTheClipboard
->SetData( data
);
1025 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1026 rc
|= wxTheClipboard
->AddData( &wldo
);
1028 wxTheClipboard
->Close();
1036 wxLayoutWindow::Cut(void)
1038 if(Copy(false)) // do not invalidate selection after copy
1040 m_llist
->DeleteSelection();
1047 // ----------------------------------------------------------------------------
1049 // ----------------------------------------------------------------------------
1052 wxLayoutWindow::Find(const wxString
&needle
,
1053 wxPoint
* fromWhere
)
1057 if(fromWhere
== NULL
)
1058 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1060 found
= m_llist
->FindText(needle
, *fromWhere
);
1068 m_llist
->MoveCursorTo(found
);
1075 // ----------------------------------------------------------------------------
1077 // ----------------------------------------------------------------------------
1080 wxLayoutWindow::MakeFormatMenu()
1082 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1084 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1085 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1086 m
->AppendSeparator();
1087 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1088 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1089 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1090 m
->AppendSeparator();
1091 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1092 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1093 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1098 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1100 event
.Check(m_llist
->IsFontUnderlined());
1103 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1105 event
.Check(m_llist
->IsFontBold());
1108 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1110 event
.Check(m_llist
->IsFontItalic());
1113 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1115 switch (event
.GetId())
1117 case WXLOWIN_MENU_LARGER
:
1118 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1119 case WXLOWIN_MENU_SMALLER
:
1120 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1121 case WXLOWIN_MENU_UNDERLINE
:
1122 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1123 case WXLOWIN_MENU_BOLD
:
1124 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1125 case WXLOWIN_MENU_ITALICS
:
1126 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1127 case WXLOWIN_MENU_ROMAN
:
1128 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1129 case WXLOWIN_MENU_TYPEWRITER
:
1130 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1131 case WXLOWIN_MENU_SANSSERIF
:
1132 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1136 // ----------------------------------------------------------------------------
1138 // ----------------------------------------------------------------------------
1141 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1148 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1150 m_HaveFocus
= false;
1154 // ----------------------------------------------------------------------------
1155 // private functions
1156 // ----------------------------------------------------------------------------
1158 static bool IsDirectionKey(long keyCode
)