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
|
145 SetStatusBar(NULL
); // don't use statusbar
147 m_doSendEvents
= false;
148 m_ViewStartX
= 0; m_ViewStartY
= 0;
149 m_DoPopupMenu
= true;
150 m_PopupMenu
= MakeFormatMenu();
151 m_memDC
= new wxMemoryDC
;
152 m_bitmap
= new wxBitmap(4,4);
153 m_bitmapSize
= wxPoint(4,4);
154 m_llist
= new wxLayoutList();
157 m_ScrollToCursor
= false;
159 wxPoint max
= m_llist
->GetSize();
160 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
161 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1);
162 EnableScrolling(true, true);
163 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
164 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
166 // no scrollbars initially (BTW, why then we do all the stuff above?)
168 m_hasVScrollbar
= false;
172 #ifdef WXLAYOUT_USE_CARET
173 // FIXME cursor size shouldn't be hardcoded
174 wxCaret
*caret
= new wxCaret(this, 2, 20);
176 m_llist
->SetCaret(caret
);
178 #endif // WXLAYOUT_USE_CARET
180 m_HandCursor
= FALSE
;
181 m_CursorVisibility
= -1;
182 SetCursor(wxCURSOR_IBEAM
);
186 wxLayoutWindow::~wxLayoutWindow()
188 delete m_memDC
; // deletes bitmap automatically (?)
192 SetBackgroundBitmap(NULL
);
196 wxLayoutWindow::Clear(int family
,
204 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
205 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
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!
233 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
234 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
236 findPos
.x
-= WXLO_XOFFSET
;
237 findPos
.y
-= WXLO_YOFFSET
;
244 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
248 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
250 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
252 // has the mouse only been moved?
255 case WXLOWIN_MENU_MOUSEMOVE
:
256 // found is only true if we are really over an object, not just
258 if(found
&& u
&& ! m_Selecting
)
261 SetCursor(wxCURSOR_HAND
);
263 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
265 const wxString
&label
= u
->GetLabel();
267 m_StatusBar
->SetStatusText(label
,
274 SetCursor(wxCURSOR_IBEAM
);
275 m_HandCursor
= FALSE
;
276 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
277 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
281 if ( event
.LeftIsDown() )
283 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
285 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
286 DoPaint(); // TODO: we don't have to redraw everything!
296 case WXLOWIN_MENU_LDOWN
:
298 // always move cursor to mouse click:
301 // we have found the real position
302 m_llist
->MoveCursorTo(cursorPos
);
306 // click beyond the end of the text
307 m_llist
->MoveCursorTo(m_llist
->GetSize());
310 // clicking a mouse removes the selection
311 if ( m_llist
->HasSelection() )
313 m_llist
->DiscardSelection();
314 DoPaint(); // TODO: we don't have to redraw everything!
317 // Calculate where the top of the visible area is:
321 GetScrollPixelsPerUnit(&dx
, &dy
);
324 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
326 if(m_CursorVisibility
== -1)
327 m_CursorVisibility
= 1;
329 if(m_CursorVisibility
!= 0)
331 // draw a thick cursor for editable windows with focus
332 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
335 // VZ: this should be unnecessary because mouse can only click on a
336 // visible part of the canvas
342 DoPaint(); // DoPaint suppresses flicker under GTK
346 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
351 case WXLOWIN_MENU_LUP
:
354 m_llist
->EndSelection();
357 DoPaint(); // TODO: we don't have to redraw everything!
361 case WXLOWIN_MENU_MDOWN
:
365 case WXLOWIN_MENU_DBLCLICK
:
366 // select a word under cursor
367 m_llist
->MoveCursorTo(cursorPos
);
368 m_llist
->MoveCursorWord(-1);
369 m_llist
->StartSelection();
370 m_llist
->MoveCursorWord(1, false);
371 m_llist
->EndSelection();
373 DoPaint(); // TODO: we don't have to redraw everything!
377 // notify about mouse events?
380 // only do the menu if activated, editable and not on a clickable object
381 if(eventId
== WXLOWIN_MENU_RCLICK
383 && (! obj
|| u
== NULL
))
385 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
390 // find the object at this position
393 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
394 commandEvent
.SetEventObject( this );
395 commandEvent
.SetClientData((char *)obj
);
396 GetEventHandler()->ProcessEvent(commandEvent
);
404 // ----------------------------------------------------------------------------
405 // keyboard handling.
406 // ----------------------------------------------------------------------------
409 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
411 int keyCode
= event
.KeyCode();
413 #ifdef WXLAYOUT_DEBUG
414 if(keyCode
== WXK_F1
)
421 wxASSERT_MSG( !m_Selecting
|| event
.ShiftDown(),
422 "m_Selecting is normally reset in OnKeyUp() when Shift "
425 if ( !m_Selecting
&& m_llist
->HasSelection() )
427 // pressing any non-arrow key replaces the selection
428 if ( !IsDirectionKey(keyCode
) )
430 m_llist
->DeleteSelection();
432 else if ( !event
.ShiftDown() )
434 m_llist
->DiscardSelection();
438 // <Shift>+<arrow> starts selection
439 if ( event
.ShiftDown() && IsDirectionKey(keyCode
) )
444 m_llist
->StartSelection();
446 //else: just continue the old selection
449 // If needed, make cursor visible:
450 if(m_CursorVisibility
== -1)
451 m_CursorVisibility
= 1;
453 /* These two nested switches work like this:
454 The first one processes all non-editing keycodes, to move the
455 cursor, etc. It's default will process all keycodes causing
456 modifications to the buffer, but only if editing is allowed.
458 bool ctrlDown
= event
.ControlDown();
463 m_llist
->MoveCursorWord(1);
465 m_llist
->MoveCursorHorizontally(1);
469 m_llist
->MoveCursorWord(-1);
471 m_llist
->MoveCursorHorizontally(-1);
474 m_llist
->MoveCursorVertically(-1);
477 m_llist
->MoveCursorVertically(1);
480 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
483 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
487 m_llist
->MoveCursorTo(wxPoint(0, 0));
489 m_llist
->MoveCursorToBeginOfLine();
493 m_llist
->MoveCursorTo(m_llist
->GetSize());
495 m_llist
->MoveCursorToEndOfLine();
499 if(keyCode
== 'c' && ctrlDown
)
501 // this should work even in read-only mode
504 else if( IsEditable() )
506 /* First, handle control keys */
507 if(event
.ControlDown() && ! event
.AltDown())
519 m_llist
->DeleteLines(1);
521 case 'h': // like backspace
522 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
525 m_llist
->DeleteToBeginOfLine();
528 m_llist
->DeleteToEndOfLine();
536 #ifdef WXLAYOUT_DEBUG
538 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
546 else if( event
.AltDown() && ! event
.ControlDown() )
552 m_llist
->DeleteWord();
559 else if ( ! event
.AltDown() && ! event
.ControlDown())
564 if(event
.ShiftDown())
568 if(event
.ShiftDown())
573 case WXK_BACK
: // backspace
574 if(m_llist
->MoveCursorHorizontally(-1))
579 m_llist
->WrapLine(m_WrapMargin
);
580 m_llist
->LineBreak();
583 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
584 && (keyCode
< 256 && keyCode
>= 32)
587 if(m_WrapMargin
> 0 && isspace(keyCode
))
588 m_llist
->WrapLine(m_WrapMargin
);
589 m_llist
->Insert((char)keyCode
);
601 // continue selection to the current (new) cursor position
602 m_llist
->ContinueSelection();
605 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
606 // ne cursor position might be outside the current scrolllbar range
610 // refresh the screen
611 DoPaint(m_llist
->GetUpdateRect());
615 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
617 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
619 m_llist
->EndSelection();
628 wxLayoutWindow::ScrollToCursor(void)
630 wxClientDC
dc( this );
633 int x0
,y0
,x1
,y1
, dx
, dy
;
635 // Calculate where the top of the visible area is:
637 GetScrollPixelsPerUnit(&dx
, &dy
);
640 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
642 // Get the size of the visible window:
643 GetClientSize(&x1
,&y1
);
645 // notice that the client size may be (0, 0)...
646 wxASSERT(x1
>= 0 && y1
>= 0);
648 // VZ: I think this is false - if you do it here, ResizeScrollbars() won't
649 // call SetScrollbars() later
651 // As we have the values anyway, use them to avoid unnecessary scrollbar
653 if(x1
> m_maxx
) m_maxx
= x1
;
654 if(y1
> m_maxy
) m_maxy
= y1
;
657 // Make sure that the scrollbars are at a position so that the cursor is
658 // visible if we are editing
659 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
660 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
662 // the cursor should be completely visible in both directions
663 wxPoint
cs(m_llist
->GetCursorSize());
666 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
673 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
680 if ( nx
!= -1 || ny
!= -1 )
682 // set new view start
683 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
686 m_ScrollToCursor
= false;
691 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
693 wxRect region
= GetUpdateRegion().GetBox();
694 InternalPaint(®ion
);
698 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
701 InternalPaint(updateRect
);
702 #else // Causes bad flicker under wxGTK!!!
703 Refresh(FALSE
); //, updateRect);
705 if ( !::UpdateWindow(GetHwnd()) )
706 wxLogLastError("UpdateWindow");
711 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
713 wxPaintDC
dc( this );
716 #ifdef WXLAYOUT_USE_CARET
717 // hide the caret before drawing anything
719 #endif // WXLAYOUT_USE_CARET
721 int x0
,y0
,x1
,y1
, dx
, dy
;
723 // Calculate where the top of the visible area is:
725 GetScrollPixelsPerUnit(&dx
, &dy
);
728 // Get the size of the visible window:
729 GetClientSize(&x1
,&y1
);
735 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
736 updateRect
->x
, updateRect
->y
,
737 updateRect
->x
+updateRect
->width
,
738 updateRect
->y
+updateRect
->height
));
745 /* Check whether the window has grown, if so, we need to reallocate
746 the bitmap to be larger. */
747 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
749 wxASSERT(m_bitmapSize
.x
> 0);
750 wxASSERT(m_bitmapSize
.y
> 0);
752 m_memDC
->SelectObject(wxNullBitmap
);
754 m_bitmapSize
= wxPoint(x1
,y1
);
755 m_bitmap
= new wxBitmap(x1
,y1
);
756 m_memDC
->SelectObject(*m_bitmap
);
759 m_memDC
->SetDeviceOrigin(0,0);
760 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
761 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
763 m_memDC
->SetLogicalFunction(wxCOPY
);
766 // fill the background with the background bitmap
771 w
= m_BGbitmap
->GetWidth(),
772 h
= m_BGbitmap
->GetHeight();
773 for(y
= 0; y
< y1
; y
+=h
)
774 for(x
= 0; x
< x1
; x
+=w
)
775 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
776 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
779 // This is the important bit: we tell the list to draw itself
783 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
784 updateRect
->x
, updateRect
->y
,
785 updateRect
->x
+updateRect
->width
,
786 updateRect
->y
+updateRect
->height
));
790 // Device origins on the memDC are suspect, we translate manually
791 // with the translate parameter of Draw().
792 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
793 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
795 // We start calculating a new update rect before drawing the
796 // cursor, so that the cursor coordinates get included in the next
797 // update rectangle (although they are drawn on the memDC, this is
798 // needed to erase it):
799 m_llist
->InvalidateUpdateRect();
800 if(m_CursorVisibility
!= 0)
802 // draw a thick cursor for editable windows with focus
803 m_llist
->DrawCursor(*m_memDC
,
804 m_HaveFocus
&& IsEditable(),
808 // Now copy everything to the screen:
810 // This somehow doesn't work, but even the following bit with the
811 // whole rect at once is still a bit broken I think.
812 wxRegionIterator
ri ( GetUpdateRegion() );
816 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
817 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
818 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
819 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
825 // FIXME: Trying to copy only the changed parts, but it does not seem
827 // x0 = updateRect->x; y0 = updateRect->y;
828 // if(updateRect->height < y1)
829 // y1 = updateRect->height;
830 // y1 += WXLO_YOFFSET; //FIXME might not be needed
831 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
834 #ifdef WXLAYOUT_USE_CARET
835 // show the caret back after everything is redrawn
837 #endif // WXLAYOUT_USE_CARET
840 m_ScrollToCursor
= false;
842 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
844 static wxPoint
s_oldCursorPos(-1, -1);
846 wxPoint
pos(m_llist
->GetCursorPos());
848 // avoid unnecessary status bar refreshes
849 if ( pos
!= s_oldCursorPos
)
851 s_oldCursorPos
= pos
;
854 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
855 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
861 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
868 // change the range and position of scrollbars
870 wxLayoutWindow::ResizeScrollbars(bool exact
)
872 wxPoint max
= m_llist
->GetSize();
873 wxSize size
= GetClientSize();
875 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
876 (long int)max
.x
, (long int) max
.y
));
878 // in the absence of scrollbars we should compare with the client size
879 if ( !m_hasHScrollbar
)
880 m_maxx
= size
.x
- WXLO_ROFFSET
;
881 if ( !m_hasVScrollbar
)
882 m_maxy
= size
.y
- WXLO_BOFFSET
;
884 // check if the text hasn't become too big
885 // TODO why do we set both at once? they're independent...
886 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
888 // text became too large
891 // add an extra bit to the sizes to avoid future updates
892 max
.x
+= WXLO_ROFFSET
;
893 max
.y
+= WXLO_BOFFSET
;
896 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
897 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
898 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
899 m_ViewStartX
, m_ViewStartY
,
903 m_hasVScrollbar
= true;
905 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
906 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
911 // check if the window hasn't become too big, thus making the scrollbars
913 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
915 // remove the horizontal scrollbar
916 SetScrollbars(0, -1, 0, -1, 0, -1, true);
917 m_hasHScrollbar
= false;
920 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
922 // remove the vertical scrollbar
923 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
924 m_hasVScrollbar
= false;
930 // ----------------------------------------------------------------------------
931 // clipboard operations
933 // ----------------------------------------------------------------------------
936 wxLayoutWindow::Paste(bool primary
)
939 if (wxTheClipboard
->Open())
943 wxTheClipboard
->UsePrimarySelection();
945 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
946 wxLayoutDataObject wxldo
;
947 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
949 wxTheClipboard
->GetData(&wxldo
);
952 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
957 wxTextDataObject data
;
958 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
960 wxTheClipboard
->GetData(&data
);
961 wxString text
= data
.GetText();
962 wxLayoutImportText( m_llist
, text
);
965 wxTheClipboard
->Close();
969 /* My attempt to get the primary selection, but it does not
971 if(text
.Length() == 0)
973 wxTextCtrl
tmp_tctrl(this,-1);
975 text
+= tmp_tctrl
.GetValue();
981 wxLayoutWindow::Copy(bool invalidate
)
983 // Calling GetSelection() will automatically do an EndSelection()
984 // on the list, but we need to take a note of it, too:
988 m_llist
->EndSelection();
991 wxLayoutDataObject wldo
;
992 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
995 // Export selection as text:
997 wxLayoutExportObject
*export
;
998 wxLayoutExportStatus
status(llist
);
999 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1001 if(export
->type
== WXLO_EXPORT_TEXT
)
1002 text
<< *(export
->content
.text
);
1007 // The exporter always appends a newline, so we chop it off if it
1010 size_t len
= text
.Length();
1011 if(len
> 2 && text
[len
-2] == '\r') // Windows
1012 text
= text
.Mid(0,len
-2);
1013 else if(len
> 1 && text
[len
-1] == '\n')
1014 text
= text
.Mid(0,len
-1);
1018 if (wxTheClipboard
->Open())
1020 wxTextDataObject
*data
= new wxTextDataObject( text
);
1021 bool rc
= wxTheClipboard
->SetData( data
);
1022 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1023 rc
|= wxTheClipboard
->AddData( &wldo
);
1025 wxTheClipboard
->Close();
1033 wxLayoutWindow::Cut(void)
1035 if(Copy(false)) // do not invalidate selection after copy
1037 m_llist
->DeleteSelection();
1044 // ----------------------------------------------------------------------------
1046 // ----------------------------------------------------------------------------
1049 wxLayoutWindow::Find(const wxString
&needle
,
1050 wxPoint
* fromWhere
)
1054 if(fromWhere
== NULL
)
1055 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1057 found
= m_llist
->FindText(needle
, *fromWhere
);
1065 m_llist
->MoveCursorTo(found
);
1072 // ----------------------------------------------------------------------------
1074 // ----------------------------------------------------------------------------
1077 wxLayoutWindow::MakeFormatMenu()
1079 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1081 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1082 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1083 m
->AppendSeparator();
1084 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1085 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1086 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1087 m
->AppendSeparator();
1088 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1089 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1090 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1095 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1097 event
.Check(m_llist
->IsFontUnderlined());
1100 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1102 event
.Check(m_llist
->IsFontBold());
1105 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1107 event
.Check(m_llist
->IsFontItalic());
1110 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1112 switch (event
.GetId())
1114 case WXLOWIN_MENU_LARGER
:
1115 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1116 case WXLOWIN_MENU_SMALLER
:
1117 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1118 case WXLOWIN_MENU_UNDERLINE
:
1119 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1120 case WXLOWIN_MENU_BOLD
:
1121 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1122 case WXLOWIN_MENU_ITALICS
:
1123 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1124 case WXLOWIN_MENU_ROMAN
:
1125 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1126 case WXLOWIN_MENU_TYPEWRITER
:
1127 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1128 case WXLOWIN_MENU_SANSSERIF
:
1129 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1133 // ----------------------------------------------------------------------------
1135 // ----------------------------------------------------------------------------
1138 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1145 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1147 m_HaveFocus
= false;
1151 // ----------------------------------------------------------------------------
1152 // private functions
1153 // ----------------------------------------------------------------------------
1155 static bool IsDirectionKey(long keyCode
)