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
);
214 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
216 wxClientDC
dc( this );
218 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
220 // moving the mouse in a window shouldn't give it the focus!
225 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
226 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
228 findPos
.x
-= WXLO_XOFFSET
;
229 findPos
.y
-= WXLO_YOFFSET
;
236 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
240 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
242 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
244 // has the mouse only been moved?
247 case WXLOWIN_MENU_MOUSEMOVE
:
248 // found is only true if we are really over an object, not just
250 if(found
&& u
&& ! m_Selecting
)
253 SetCursor(wxCURSOR_HAND
);
255 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
257 const wxString
&label
= u
->GetLabel();
259 m_StatusBar
->SetStatusText(label
,
266 SetCursor(wxCURSOR_IBEAM
);
267 m_HandCursor
= FALSE
;
268 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
269 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
273 if ( event
.LeftIsDown() )
275 wxASSERT_MSG( m_Selecting
, "should be set in OnMouseLeftDown" );
277 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
278 DoPaint(); // TODO: we don't have to redraw everything!
288 case WXLOWIN_MENU_LDOWN
:
290 // always move cursor to mouse click:
291 m_llist
->MoveCursorTo(cursorPos
);
293 // clicking a mouse removes the selection
294 if ( m_llist
->HasSelection() )
296 m_llist
->DiscardSelection();
297 DoPaint(); // TODO: we don't have to redraw everything!
300 // Calculate where the top of the visible area is:
304 GetScrollPixelsPerUnit(&dx
, &dy
);
307 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
309 if(m_CursorVisibility
== -1)
310 m_CursorVisibility
= 1;
312 if(m_CursorVisibility
!= 0)
314 // draw a thick cursor for editable windows with focus
315 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
318 // VZ: this should be unnecessary because mouse can only click on a
319 // visible part of the canvas
325 DoPaint(); // DoPaint suppresses flicker under GTK
329 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
334 case WXLOWIN_MENU_LUP
:
337 m_llist
->EndSelection();
340 DoPaint(); // TODO: we don't have to redraw everything!
344 case WXLOWIN_MENU_MDOWN
:
348 case WXLOWIN_MENU_DBLCLICK
:
349 // select a word under cursor
350 m_llist
->MoveCursorTo(cursorPos
);
351 m_llist
->MoveCursorWord(-1);
352 m_llist
->StartSelection();
353 m_llist
->MoveCursorWord(1, false);
354 m_llist
->EndSelection();
356 DoPaint(); // TODO: we don't have to redraw everything!
360 // notify about mouse events?
363 // only do the menu if activated, editable and not on a clickable object
364 if(eventId
== WXLOWIN_MENU_RCLICK
366 && (! obj
|| u
== NULL
))
368 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
373 // find the object at this position
376 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
377 commandEvent
.SetEventObject( this );
378 commandEvent
.SetClientData((char *)obj
);
379 GetEventHandler()->ProcessEvent(commandEvent
);
387 // ----------------------------------------------------------------------------
388 // keyboard handling.
389 // ----------------------------------------------------------------------------
392 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
394 int keyCode
= event
.KeyCode();
396 #ifdef WXLAYOUT_DEBUG
397 if(keyCode
== WXK_F1
)
404 wxASSERT_MSG( !m_Selecting
|| event
.ShiftDown(),
405 "m_Selecting is normally reset in OnKeyUp() when Shift "
408 if ( !m_Selecting
&& m_llist
->HasSelection() )
410 // pressing any non-arrow key replaces the selection
411 if ( !IsDirectionKey(keyCode
) )
413 m_llist
->DeleteSelection();
415 else if ( !event
.ShiftDown() )
417 m_llist
->DiscardSelection();
421 // <Shift>+<arrow> starts selection
422 if ( event
.ShiftDown() && IsDirectionKey(keyCode
) )
427 m_llist
->StartSelection();
429 //else: just continue the old selection
432 // If needed, make cursor visible:
433 if(m_CursorVisibility
== -1)
434 m_CursorVisibility
= 1;
436 /* These two nested switches work like this:
437 The first one processes all non-editing keycodes, to move the
438 cursor, etc. It's default will process all keycodes causing
439 modifications to the buffer, but only if editing is allowed.
441 bool ctrlDown
= event
.ControlDown();
446 m_llist
->MoveCursorWord(1);
448 m_llist
->MoveCursorHorizontally(1);
452 m_llist
->MoveCursorWord(-1);
454 m_llist
->MoveCursorHorizontally(-1);
457 m_llist
->MoveCursorVertically(-1);
460 m_llist
->MoveCursorVertically(1);
463 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
466 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
470 m_llist
->MoveCursorTo(wxPoint(0, 0));
472 m_llist
->MoveCursorToBeginOfLine();
476 m_llist
->MoveCursorTo(m_llist
->GetSize());
478 m_llist
->MoveCursorToEndOfLine();
482 if(keyCode
== 'c' && ctrlDown
)
484 // this should work even in read-only mode
487 else if( IsEditable() )
489 /* First, handle control keys */
490 if(event
.ControlDown() && ! event
.AltDown())
502 m_llist
->DeleteLines(1);
504 case 'h': // like backspace
505 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
508 m_llist
->DeleteToBeginOfLine();
511 m_llist
->DeleteToEndOfLine();
519 #ifdef WXLAYOUT_DEBUG
521 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
529 else if( event
.AltDown() && ! event
.ControlDown() )
535 m_llist
->DeleteWord();
542 else if ( ! event
.AltDown() && ! event
.ControlDown())
547 if(event
.ShiftDown())
551 if(event
.ShiftDown())
556 case WXK_BACK
: // backspace
557 if(m_llist
->MoveCursorHorizontally(-1))
562 m_llist
->WrapLine(m_WrapMargin
);
563 m_llist
->LineBreak();
566 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
567 && (keyCode
< 256 && keyCode
>= 32)
570 if(m_WrapMargin
> 0 && isspace(keyCode
))
571 m_llist
->WrapLine(m_WrapMargin
);
572 m_llist
->Insert((char)keyCode
);
584 // continue selection to the current (new) cursor position
585 m_llist
->ContinueSelection();
588 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
589 // ne cursor position might be outside the current scrolllbar range
593 // refresh the screen
594 DoPaint(m_llist
->GetUpdateRect());
598 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
600 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
602 m_llist
->EndSelection();
611 wxLayoutWindow::ScrollToCursor(void)
613 wxClientDC
dc( this );
616 int x0
,y0
,x1
,y1
, dx
, dy
;
618 // Calculate where the top of the visible area is:
620 GetScrollPixelsPerUnit(&dx
, &dy
);
623 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
625 // Get the size of the visible window:
626 GetClientSize(&x1
,&y1
);
628 // notice that the client size may be (0, 0)...
629 wxASSERT(x1
>= 0 && y1
>= 0);
631 // VZ: I think this is false - if you do it here, ResizeScrollbars() won't
632 // call SetScrollbars() later
634 // As we have the values anyway, use them to avoid unnecessary scrollbar
636 if(x1
> m_maxx
) m_maxx
= x1
;
637 if(y1
> m_maxy
) m_maxy
= y1
;
640 // Make sure that the scrollbars are at a position so that the cursor is
641 // visible if we are editing
642 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
643 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
645 // the cursor should be completely visible in both directions
646 wxPoint
cs(m_llist
->GetCursorSize());
649 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
656 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
663 if ( nx
!= -1 || ny
!= -1 )
665 // set new view start
666 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
669 m_ScrollToCursor
= false;
674 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
676 wxRect region
= GetUpdateRegion().GetBox();
677 InternalPaint(®ion
);
681 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
684 InternalPaint(updateRect
);
685 #else // Causes bad flicker under wxGTK!!!
686 Refresh(FALSE
); //, updateRect);
688 if ( !::UpdateWindow(GetHwnd()) )
689 wxLogLastError("UpdateWindow");
694 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
696 wxPaintDC
dc( this );
699 #ifdef WXLAYOUT_USE_CARET
700 // hide the caret before drawing anything
702 #endif // WXLAYOUT_USE_CARET
704 int x0
,y0
,x1
,y1
, dx
, dy
;
706 // Calculate where the top of the visible area is:
708 GetScrollPixelsPerUnit(&dx
, &dy
);
711 // Get the size of the visible window:
712 GetClientSize(&x1
,&y1
);
718 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
719 updateRect
->x
, updateRect
->y
,
720 updateRect
->x
+updateRect
->width
,
721 updateRect
->y
+updateRect
->height
));
728 /* Check whether the window has grown, if so, we need to reallocate
729 the bitmap to be larger. */
730 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
732 wxASSERT(m_bitmapSize
.x
> 0);
733 wxASSERT(m_bitmapSize
.y
> 0);
735 m_memDC
->SelectObject(wxNullBitmap
);
737 m_bitmapSize
= wxPoint(x1
,y1
);
738 m_bitmap
= new wxBitmap(x1
,y1
);
739 m_memDC
->SelectObject(*m_bitmap
);
742 m_memDC
->SetDeviceOrigin(0,0);
743 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
744 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
746 m_memDC
->SetLogicalFunction(wxCOPY
);
749 // fill the background with the background bitmap
754 w
= m_BGbitmap
->GetWidth(),
755 h
= m_BGbitmap
->GetHeight();
756 for(y
= 0; y
< y1
; y
+=h
)
757 for(x
= 0; x
< x1
; x
+=w
)
758 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
759 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
762 // This is the important bit: we tell the list to draw itself
766 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
767 updateRect
->x
, updateRect
->y
,
768 updateRect
->x
+updateRect
->width
,
769 updateRect
->y
+updateRect
->height
));
773 // Device origins on the memDC are suspect, we translate manually
774 // with the translate parameter of Draw().
775 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
776 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
778 // We start calculating a new update rect before drawing the
779 // cursor, so that the cursor coordinates get included in the next
780 // update rectangle (although they are drawn on the memDC, this is
781 // needed to erase it):
782 m_llist
->InvalidateUpdateRect();
783 if(m_CursorVisibility
!= 0)
785 // draw a thick cursor for editable windows with focus
786 m_llist
->DrawCursor(*m_memDC
,
787 m_HaveFocus
&& IsEditable(),
791 // Now copy everything to the screen:
793 // This somehow doesn't work, but even the following bit with the
794 // whole rect at once is still a bit broken I think.
795 wxRegionIterator
ri ( GetUpdateRegion() );
799 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
800 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
801 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
802 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
808 // FIXME: Trying to copy only the changed parts, but it does not seem
810 // x0 = updateRect->x; y0 = updateRect->y;
811 // if(updateRect->height < y1)
812 // y1 = updateRect->height;
813 // y1 += WXLO_YOFFSET; //FIXME might not be needed
814 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
817 #ifdef WXLAYOUT_USE_CARET
818 // show the caret back after everything is redrawn
820 #endif // WXLAYOUT_USE_CARET
823 m_ScrollToCursor
= false;
825 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
827 static wxPoint
s_oldCursorPos(-1, -1);
829 wxPoint
pos(m_llist
->GetCursorPos());
831 // avoid unnecessary status bar refreshes
832 if ( pos
!= s_oldCursorPos
)
834 s_oldCursorPos
= pos
;
837 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
838 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
844 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
851 // change the range and position of scrollbars
853 wxLayoutWindow::ResizeScrollbars(bool exact
)
855 wxPoint max
= m_llist
->GetSize();
856 wxSize size
= GetClientSize();
858 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
859 (long int)max
.x
, (long int) max
.y
));
861 // in the absence of scrollbars we should compare with the client size
862 if ( !m_hasHScrollbar
)
863 m_maxx
= size
.x
- WXLO_ROFFSET
;
864 if ( !m_hasVScrollbar
)
865 m_maxy
= size
.y
- WXLO_BOFFSET
;
867 // check if the text hasn't become too big
868 // TODO why do we set both at once? they're independent...
869 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
871 // text became too large
874 // add an extra bit to the sizes to avoid future updates
875 max
.x
+= WXLO_ROFFSET
;
876 max
.y
+= WXLO_BOFFSET
;
879 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
880 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
881 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
882 m_ViewStartX
, m_ViewStartY
,
886 m_hasVScrollbar
= true;
888 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
889 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
894 // check if the window hasn't become too big, thus making the scrollbars
896 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
898 // remove the horizontal scrollbar
899 SetScrollbars(0, -1, 0, -1, 0, -1, true);
900 m_hasHScrollbar
= false;
903 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
905 // remove the vertical scrollbar
906 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
907 m_hasVScrollbar
= false;
913 // ----------------------------------------------------------------------------
914 // clipboard operations
916 // ----------------------------------------------------------------------------
919 wxLayoutWindow::Paste(bool primary
)
922 if (wxTheClipboard
->Open())
926 wxTheClipboard
->UsePrimarySelection();
928 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
929 wxLayoutDataObject wxldo
;
930 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
932 wxTheClipboard
->GetData(&wxldo
);
935 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
940 wxTextDataObject data
;
941 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
943 wxTheClipboard
->GetData(&data
);
944 wxString text
= data
.GetText();
945 wxLayoutImportText( m_llist
, text
);
948 wxTheClipboard
->Close();
952 /* My attempt to get the primary selection, but it does not
954 if(text
.Length() == 0)
956 wxTextCtrl
tmp_tctrl(this,-1);
958 text
+= tmp_tctrl
.GetValue();
964 wxLayoutWindow::Copy(bool invalidate
)
966 // Calling GetSelection() will automatically do an EndSelection()
967 // on the list, but we need to take a note of it, too:
971 m_llist
->EndSelection();
974 wxLayoutDataObject wldo
;
975 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
978 // Export selection as text:
980 wxLayoutExportObject
*export
;
981 wxLayoutExportStatus
status(llist
);
982 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
984 if(export
->type
== WXLO_EXPORT_TEXT
)
985 text
<< *(export
->content
.text
);
990 // The exporter always appends a newline, so we chop it off if it
993 size_t len
= text
.Length();
994 if(len
> 2 && text
[len
-2] == '\r') // Windows
995 text
= text
.Mid(0,len
-2);
996 else if(len
> 1 && text
[len
-1] == '\n')
997 text
= text
.Mid(0,len
-1);
1001 if (wxTheClipboard
->Open())
1003 wxTextDataObject
*data
= new wxTextDataObject( text
);
1004 bool rc
= wxTheClipboard
->SetData( data
);
1005 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1006 rc
|= wxTheClipboard
->AddData( &wldo
);
1008 wxTheClipboard
->Close();
1016 wxLayoutWindow::Cut(void)
1018 if(Copy(false)) // do not invalidate selection after copy
1020 m_llist
->DeleteSelection();
1027 // ----------------------------------------------------------------------------
1029 // ----------------------------------------------------------------------------
1032 wxLayoutWindow::Find(const wxString
&needle
,
1033 wxPoint
* fromWhere
)
1037 if(fromWhere
== NULL
)
1038 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1040 found
= m_llist
->FindText(needle
, *fromWhere
);
1048 m_llist
->MoveCursorTo(found
);
1055 // ----------------------------------------------------------------------------
1057 // ----------------------------------------------------------------------------
1060 wxLayoutWindow::MakeFormatMenu()
1062 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1064 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1065 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1066 m
->AppendSeparator();
1067 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1068 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1069 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1070 m
->AppendSeparator();
1071 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1072 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1073 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1078 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1080 event
.Check(m_llist
->IsFontUnderlined());
1083 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1085 event
.Check(m_llist
->IsFontBold());
1088 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1090 event
.Check(m_llist
->IsFontItalic());
1093 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1095 switch (event
.GetId())
1097 case WXLOWIN_MENU_LARGER
:
1098 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1099 case WXLOWIN_MENU_SMALLER
:
1100 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1101 case WXLOWIN_MENU_UNDERLINE
:
1102 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1103 case WXLOWIN_MENU_BOLD
:
1104 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1105 case WXLOWIN_MENU_ITALICS
:
1106 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1107 case WXLOWIN_MENU_ROMAN
:
1108 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1109 case WXLOWIN_MENU_TYPEWRITER
:
1110 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1111 case WXLOWIN_MENU_SANSSERIF
:
1112 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1116 // ----------------------------------------------------------------------------
1118 // ----------------------------------------------------------------------------
1121 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1128 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1130 m_HaveFocus
= false;
1134 // ----------------------------------------------------------------------------
1135 // private functions
1136 // ----------------------------------------------------------------------------
1138 static bool IsDirectionKey(long keyCode
)