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 m_ScrollToCursor
= false;
160 // no scrollbars initially
162 m_hasVScrollbar
= false;
166 #ifdef WXLAYOUT_USE_CARET
167 // FIXME cursor size shouldn't be hardcoded
168 wxCaret
*caret
= new wxCaret(this, 2, 20);
170 m_llist
->SetCaret(caret
);
171 #endif // WXLAYOUT_USE_CARET
174 m_HandCursor
= FALSE
;
175 m_CursorVisibility
= -1;
176 SetCursor(wxCURSOR_IBEAM
);
179 // at least under Windows, this should be the default behaviour
181 m_AutoDeleteSelection
= TRUE
;
183 m_AutoDeleteSelection
= FALSE
;
187 wxLayoutWindow::~wxLayoutWindow()
189 delete m_memDC
; // deletes bitmap automatically (?)
193 SetBackgroundBitmap(NULL
);
197 wxLayoutWindow::Clear(int family
,
205 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
206 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
207 wxScrolledWindow::Clear();
208 ResizeScrollbars(true);
212 #ifdef WXLAYOUT_USE_CARET
213 if ( m_CursorVisibility
== 1 )
215 #endif // WXLAYOUT_USE_CARET
217 DoPaint((wxRect
*)NULL
);
220 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
222 wxScrolledWindow::Refresh(eraseBackground
, rect
);
229 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
231 wxClientDC
dc( this );
233 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
235 // moving the mouse in a window shouldn't give it the focus!
236 // Oh yes! wxGTK's focus handling is so broken, that this is the
237 // only sensible way to go.
242 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
243 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
245 findPos
.x
-= WXLO_XOFFSET
;
246 findPos
.y
-= WXLO_YOFFSET
;
253 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
257 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
259 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
261 // has the mouse only been moved?
264 case WXLOWIN_MENU_MOUSEMOVE
:
265 // found is only true if we are really over an object, not just
267 if(found
&& u
&& ! m_Selecting
)
270 SetCursor(wxCURSOR_HAND
);
272 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
274 const wxString
&label
= u
->GetLabel();
276 m_StatusBar
->SetStatusText(label
,
283 SetCursor(wxCURSOR_IBEAM
);
284 m_HandCursor
= FALSE
;
285 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
286 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
290 if ( event
.LeftIsDown() )
292 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
294 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
295 DoPaint(); // TODO: we don't have to redraw everything!
305 case WXLOWIN_MENU_LDOWN
:
307 // always move cursor to mouse click:
310 // we have found the real position
311 m_llist
->MoveCursorTo(cursorPos
);
315 // click beyond the end of the text
316 m_llist
->MoveCursorToEnd();
319 // clicking a mouse removes the selection
320 if ( m_llist
->HasSelection() )
322 m_llist
->DiscardSelection();
324 DoPaint(); // TODO: we don't have to redraw everything!
327 // Calculate where the top of the visible area is:
331 GetScrollPixelsPerUnit(&dx
, &dy
);
334 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
336 if(m_CursorVisibility
== -1)
337 m_CursorVisibility
= 1;
339 if(m_CursorVisibility
!= 0)
341 // draw a thick cursor for editable windows with focus
342 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
346 DoPaint(); // DoPaint suppresses flicker under GTK
350 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
355 case WXLOWIN_MENU_LUP
:
358 m_llist
->EndSelection();
361 DoPaint(); // TODO: we don't have to redraw everything!
365 case WXLOWIN_MENU_MDOWN
:
369 case WXLOWIN_MENU_DBLCLICK
:
370 // select a word under cursor
371 m_llist
->MoveCursorTo(cursorPos
);
372 m_llist
->MoveCursorWord(-1);
373 m_llist
->StartSelection();
374 m_llist
->MoveCursorWord(1, false);
375 m_llist
->EndSelection();
377 DoPaint(); // TODO: we don't have to redraw everything!
381 // notify about mouse events?
384 // only do the menu if activated, editable and not on a clickable object
385 if(eventId
== WXLOWIN_MENU_RCLICK
387 && (! obj
|| u
== NULL
))
389 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
394 // find the object at this position
397 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
398 commandEvent
.SetEventObject( this );
399 commandEvent
.SetClientData((char *)obj
);
400 GetEventHandler()->ProcessEvent(commandEvent
);
408 // ----------------------------------------------------------------------------
409 // keyboard handling.
410 // ----------------------------------------------------------------------------
413 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
415 int keyCode
= event
.KeyCode();
416 bool ctrlDown
= event
.ControlDown();
418 #ifdef WXLAYOUT_DEBUG
419 if(keyCode
== WXK_F1
)
427 // Force m_Selecting to be false if shift is no longer
428 // pressed. OnKeyUp() cannot catch all Shift-Up events.
429 if(m_Selecting
&& !event
.ShiftDown())
432 m_llist
->EndSelection();
436 // If we deleted the selection here, we must not execute the
437 // deletion in Delete/Backspace handling.
438 bool deletedSelection
= false;
439 // pressing any non-arrow key optionally replaces the selection:
440 if(m_AutoDeleteSelection
442 && m_llist
->HasSelection()
443 && ! IsDirectionKey(keyCode
)
444 && ! (event
.AltDown() || ctrlDown
)
447 m_llist
->DeleteSelection();
448 deletedSelection
= true;
451 // <Shift>+<arrow> starts selection
452 if ( IsDirectionKey(keyCode
) )
456 // just continue the old selection
457 if( event
.ShiftDown() )
458 m_llist
->ContinueSelection();
461 m_llist
->DiscardSelection();
465 else if( event
.ShiftDown() )
468 m_llist
->StartSelection();
473 // If needed, make cursor visible:
474 if(m_CursorVisibility
== -1)
475 m_CursorVisibility
= 1;
477 /* These two nested switches work like this:
478 The first one processes all non-editing keycodes, to move the
479 cursor, etc. It's default will process all keycodes causing
480 modifications to the buffer, but only if editing is allowed.
486 m_llist
->MoveCursorWord(1);
488 m_llist
->MoveCursorHorizontally(1);
492 m_llist
->MoveCursorWord(-1);
494 m_llist
->MoveCursorHorizontally(-1);
497 m_llist
->MoveCursorVertically(-1);
500 m_llist
->MoveCursorVertically(1);
503 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
506 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
510 m_llist
->MoveCursorTo(wxPoint(0, 0));
512 m_llist
->MoveCursorToBeginOfLine();
516 m_llist
->MoveCursorToEnd();
518 m_llist
->MoveCursorToEndOfLine();
522 if(keyCode
== 'c' && ctrlDown
)
524 // this should work even in read-only mode
527 else if( IsEditable() )
529 /* First, handle control keys */
530 if(ctrlDown
&& ! event
.AltDown())
539 if(! deletedSelection
) // already done
543 m_llist
->DeleteLines(1);
545 case 'h': // like backspace
546 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
549 m_llist
->DeleteToBeginOfLine();
552 m_llist
->DeleteToEndOfLine();
560 #ifdef WXLAYOUT_DEBUG
562 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
570 else if( event
.AltDown() && ! event
.ControlDown() )
576 m_llist
->DeleteWord();
583 else if ( ! event
.AltDown() && ! event
.ControlDown())
588 if(event
.ShiftDown())
592 if(event
.ShiftDown())
595 if(! deletedSelection
)
598 case WXK_BACK
: // backspace
599 if(! deletedSelection
)
600 if(m_llist
->MoveCursorHorizontally(-1))
605 m_llist
->WrapLine(m_WrapMargin
);
606 m_llist
->LineBreak();
611 // TODO should be configurable
612 static const int tabSize
= 8;
614 CoordType x
= m_llist
->GetCursorPos().x
;
615 size_t numSpaces
= tabSize
- x
% tabSize
;
616 m_llist
->Insert(wxString(' ', numSpaces
));
621 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
622 && (keyCode
< 256 && keyCode
>= 32)
625 if(m_WrapMargin
> 0 && isspace(keyCode
))
626 m_llist
->WrapLine(m_WrapMargin
);
627 m_llist
->Insert((char)keyCode
);
639 // continue selection to the current (new) cursor position
640 m_llist
->ContinueSelection();
643 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
644 // ne cursor position might be outside the current scrolllbar range
648 // refresh the screen
649 DoPaint(m_llist
->GetUpdateRect());
653 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
655 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
657 m_llist
->EndSelection();
666 wxLayoutWindow::ScrollToCursor(void)
668 wxClientDC
dc( this );
671 int x0
,y0
,x1
,y1
, dx
, dy
;
673 // Calculate where the top of the visible area is:
675 GetScrollPixelsPerUnit(&dx
, &dy
);
678 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
680 // Get the size of the visible window:
681 GetClientSize(&x1
, &y1
);
683 // update the cursor screen position
686 // Make sure that the scrollbars are at a position so that the cursor is
687 // visible if we are editing
688 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
689 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
691 // the cursor should be completely visible in both directions
692 wxPoint
cs(m_llist
->GetCursorSize());
695 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
702 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
709 if ( nx
!= -1 || ny
!= -1 )
711 // set new view start
712 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
715 m_ScrollToCursor
= false;
720 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
722 wxRect region
= GetUpdateRegion().GetBox();
723 InternalPaint(®ion
);
727 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
730 // Calling Refresh() causes bad flicker under wxGTK!!!
731 InternalPaint(updateRect
);
733 // shouldn't specify the update rectangle if it doesn't include all the
734 // changed locations - otherwise, they won't be repainted at all because
735 // the system clips the display to the update rect
736 Refresh(FALSE
); //, updateRect);
741 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
743 wxPaintDC
dc( this );
746 #ifdef WXLAYOUT_USE_CARET
747 // hide the caret before drawing anything
749 #endif // WXLAYOUT_USE_CARET
751 int x0
,y0
,x1
,y1
, dx
, dy
;
753 // Calculate where the top of the visible area is:
755 GetScrollPixelsPerUnit(&dx
, &dy
);
758 // Get the size of the visible window:
759 GetClientSize(&x1
,&y1
);
765 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
766 updateRect
->x
, updateRect
->y
,
767 updateRect
->x
+updateRect
->width
,
768 updateRect
->y
+updateRect
->height
));
776 /* Check whether the window has grown, if so, we need to reallocate
777 the bitmap to be larger. */
778 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
780 wxASSERT(m_bitmapSize
.x
> 0);
781 wxASSERT(m_bitmapSize
.y
> 0);
783 m_memDC
->SelectObject(wxNullBitmap
);
785 m_bitmapSize
= wxPoint(x1
,y1
);
786 m_bitmap
= new wxBitmap(x1
,y1
);
787 m_memDC
->SelectObject(*m_bitmap
);
790 m_memDC
->SetDeviceOrigin(0,0);
791 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
792 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
794 m_memDC
->SetLogicalFunction(wxCOPY
);
797 // fill the background with the background bitmap
802 w
= m_BGbitmap
->GetWidth(),
803 h
= m_BGbitmap
->GetHeight();
804 for(y
= 0; y
< y1
; y
+=h
)
805 for(x
= 0; x
< x1
; x
+=w
)
806 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
807 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
810 // This is the important bit: we tell the list to draw itself
814 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
815 updateRect
->x
, updateRect
->y
,
816 updateRect
->x
+updateRect
->width
,
817 updateRect
->y
+updateRect
->height
));
821 // Device origins on the memDC are suspect, we translate manually
822 // with the translate parameter of Draw().
823 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
824 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
826 // We start calculating a new update rect before drawing the
827 // cursor, so that the cursor coordinates get included in the next
828 // update rectangle (although they are drawn on the memDC, this is
829 // needed to erase it):
830 m_llist
->InvalidateUpdateRect();
831 if(m_CursorVisibility
!= 0)
833 // draw a thick cursor for editable windows with focus
834 m_llist
->DrawCursor(*m_memDC
,
835 m_HaveFocus
&& IsEditable(),
839 // Now copy everything to the screen:
841 // This somehow doesn't work, but even the following bit with the
842 // whole rect at once is still a bit broken I think.
843 wxRegionIterator
ri ( GetUpdateRegion() );
847 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
848 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
849 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
850 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
856 // FIXME: Trying to copy only the changed parts, but it does not seem
858 // x0 = updateRect->x; y0 = updateRect->y;
859 // if(updateRect->height < y1)
860 // y1 = updateRect->height;
861 // y1 += WXLO_YOFFSET; //FIXME might not be needed
862 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
865 #ifdef WXLAYOUT_USE_CARET
866 // show the caret back after everything is redrawn
868 #endif // WXLAYOUT_USE_CARET
871 m_ScrollToCursor
= false;
873 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
875 static wxPoint
s_oldCursorPos(-1, -1);
877 wxPoint
pos(m_llist
->GetCursorPos());
879 // avoid unnecessary status bar refreshes
880 if ( pos
!= s_oldCursorPos
)
882 s_oldCursorPos
= pos
;
885 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
886 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
892 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
902 // change the range and position of scrollbars
904 wxLayoutWindow::ResizeScrollbars(bool exact
)
906 wxPoint max
= m_llist
->GetSize();
907 wxSize size
= GetClientSize();
909 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
910 (long int)max
.x
, (long int) max
.y
));
912 // in the absence of scrollbars we should compare with the client size
913 if ( !m_hasHScrollbar
)
914 m_maxx
= size
.x
- WXLO_ROFFSET
;
915 if ( !m_hasVScrollbar
)
916 m_maxy
= size
.y
- WXLO_BOFFSET
;
918 // check if the text hasn't become too big
919 // TODO why do we set both at once? they're independent...
920 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
922 // text became too large
925 // add an extra bit to the sizes to avoid future updates
926 max
.x
+= WXLO_ROFFSET
;
927 max
.y
+= WXLO_BOFFSET
;
930 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
931 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
932 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
933 m_ViewStartX
, m_ViewStartY
,
937 m_hasVScrollbar
= true;
939 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
940 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
945 // check if the window hasn't become too big, thus making the scrollbars
947 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
949 // remove the horizontal scrollbar
950 SetScrollbars(0, -1, 0, -1, 0, -1, true);
951 m_hasHScrollbar
= false;
954 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
956 // remove the vertical scrollbar
957 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
958 m_hasVScrollbar
= false;
964 // ----------------------------------------------------------------------------
965 // clipboard operations
967 // ----------------------------------------------------------------------------
970 wxLayoutWindow::Paste(bool primary
)
973 if (wxTheClipboard
->Open())
977 wxTheClipboard
->UsePrimarySelection();
979 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
980 wxLayoutDataObject wxldo
;
981 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
983 wxTheClipboard
->GetData(&wxldo
);
986 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
991 wxTextDataObject data
;
992 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
994 wxTheClipboard
->GetData(&data
);
995 wxString text
= data
.GetText();
996 wxLayoutImportText( m_llist
, text
);
999 wxTheClipboard
->Close();
1004 wxLayoutWindow::Copy(bool invalidate
)
1006 // Calling GetSelection() will automatically do an EndSelection()
1007 // on the list, but we need to take a note of it, too:
1010 m_Selecting
= false;
1011 m_llist
->EndSelection();
1014 wxLayoutDataObject wldo
;
1015 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1018 // Export selection as text:
1020 wxLayoutExportObject
*export
;
1021 wxLayoutExportStatus
status(llist
);
1022 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1024 if(export
->type
== WXLO_EXPORT_TEXT
)
1025 text
<< *(export
->content
.text
);
1030 // The exporter always appends a newline, so we chop it off if it
1033 size_t len
= text
.Length();
1034 if(len
> 2 && text
[len
-2] == '\r') // Windows
1035 text
= text
.Mid(0,len
-2);
1036 else if(len
> 1 && text
[len
-1] == '\n')
1037 text
= text
.Mid(0,len
-1);
1041 if (wxTheClipboard
->Open())
1043 wxTextDataObject
*data
= new wxTextDataObject( text
);
1044 bool rc
= wxTheClipboard
->SetData( data
);
1045 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1046 rc
|= wxTheClipboard
->AddData( &wldo
);
1048 wxTheClipboard
->Close();
1056 wxLayoutWindow::Cut(void)
1058 if(Copy(false)) // do not invalidate selection after copy
1060 m_llist
->DeleteSelection();
1067 // ----------------------------------------------------------------------------
1069 // ----------------------------------------------------------------------------
1072 wxLayoutWindow::Find(const wxString
&needle
,
1073 wxPoint
* fromWhere
)
1077 if(fromWhere
== NULL
)
1078 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1080 found
= m_llist
->FindText(needle
, *fromWhere
);
1088 m_llist
->MoveCursorTo(found
);
1095 // ----------------------------------------------------------------------------
1097 // ----------------------------------------------------------------------------
1100 wxLayoutWindow::MakeFormatMenu()
1102 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1104 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1105 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1106 m
->AppendSeparator();
1107 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1108 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1109 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1110 m
->AppendSeparator();
1111 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1112 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1113 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1118 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1120 event
.Check(m_llist
->IsFontUnderlined());
1123 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1125 event
.Check(m_llist
->IsFontBold());
1128 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1130 event
.Check(m_llist
->IsFontItalic());
1133 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1135 switch (event
.GetId())
1137 case WXLOWIN_MENU_LARGER
:
1138 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1139 case WXLOWIN_MENU_SMALLER
:
1140 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1141 case WXLOWIN_MENU_UNDERLINE
:
1142 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1143 case WXLOWIN_MENU_BOLD
:
1144 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1145 case WXLOWIN_MENU_ITALICS
:
1146 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1147 case WXLOWIN_MENU_ROMAN
:
1148 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1149 case WXLOWIN_MENU_TYPEWRITER
:
1150 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1151 case WXLOWIN_MENU_SANSSERIF
:
1152 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1156 // ----------------------------------------------------------------------------
1158 // ----------------------------------------------------------------------------
1161 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1168 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1170 m_HaveFocus
= false;
1174 // ----------------------------------------------------------------------------
1175 // private functions
1176 // ----------------------------------------------------------------------------
1178 static bool IsDirectionKey(long keyCode
)