1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 # pragma implementation "wxlwindow.h"
21 #include "wx/wxprec.h"
32 # include "gui/wxMenuDefs.h"
33 # include "gui/wxMApp.h"
35 # include "gui/wxlwindow.h"
36 # include "gui/wxlparser.h"
39 # include <wx/msw/private.h>
42 # include "wxlwindow.h"
43 # include "wxlparser.h"
46 #include <wx/clipbrd.h>
47 #include <wx/textctrl.h>
48 #include <wx/dataobj.h>
50 #ifdef WXLAYOUT_USE_CARET
51 # include <wx/caret.h>
52 #endif // WXLAYOUT_USE_CARET
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
61 # define WXLO_DEBUG(x) wxLogDebug x
63 # define WXLO_DEBUG(x)
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 /// offsets to put a nice frame around text
71 #define WXLO_XOFFSET 4
72 #define WXLO_YOFFSET 4
74 /// offset to the right and bottom for when to redraw scrollbars
75 #define WXLO_ROFFSET 20
76 #define WXLO_BOFFSET 20
78 /// the size of one scrollbar page in pixels
79 static const int X_SCROLL_PAGE
= 10;
80 static const int Y_SCROLL_PAGE
= 20;
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
87 EVT_SIZE (wxLayoutWindow::OnSize
)
89 EVT_PAINT (wxLayoutWindow::OnPaint
)
91 EVT_CHAR (wxLayoutWindow::OnChar
)
92 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
94 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
95 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
96 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
97 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
98 EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown
)
99 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
101 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
102 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
103 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
104 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
106 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
107 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
110 // ----------------------------------------------------------------------------
111 // function prototypes
112 // ----------------------------------------------------------------------------
114 /// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
115 static bool IsDirectionKey(long keyCode
);
117 // ============================================================================
119 // ============================================================================
121 /* LEAVE IT HERE UNTIL WXGTK WORKS AGAIN!!! */
123 /// allows me to compare to wxPoints
124 static bool operator != (wxPoint
const &p1
, wxPoint
const &p2
)
126 return p1
.x
!= p2
.x
|| p1
.y
!= p2
.y
;
130 #ifndef wxWANTS_CHARS
131 #define wxWANTS_CHARS 0
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
139 : wxScrolledWindow(parent
, -1,
140 wxDefaultPosition
, wxDefaultSize
,
141 wxHSCROLL
| wxVSCROLL
|
146 SetStatusBar(NULL
); // don't use statusbar
148 m_doSendEvents
= false;
149 m_ViewStartX
= 0; m_ViewStartY
= 0;
150 m_DoPopupMenu
= true;
151 m_PopupMenu
= MakeFormatMenu();
152 m_memDC
= new wxMemoryDC
;
153 m_bitmap
= new wxBitmap(4,4);
154 m_bitmapSize
= wxPoint(4,4);
155 m_llist
= new wxLayoutList();
157 SetAutoDeleteSelection(true);
159 SetAutoDeleteSelection(false);
162 m_ScrollToCursor
= false;
165 // no scrollbars initially
167 m_hasVScrollbar
= false;
171 #ifdef WXLAYOUT_USE_CARET
172 // FIXME cursor size shouldn't be hardcoded
173 wxCaret
*caret
= new wxCaret(this, 2, 20);
175 m_llist
->SetCaret(caret
);
177 #endif // WXLAYOUT_USE_CARET
179 m_HandCursor
= FALSE
;
180 m_CursorVisibility
= -1;
181 SetCursor(wxCURSOR_IBEAM
);
185 wxLayoutWindow::~wxLayoutWindow()
187 delete m_memDC
; // deletes bitmap automatically (?)
191 SetBackgroundBitmap(NULL
);
195 wxLayoutWindow::Clear(int family
,
203 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
204 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
205 wxScrolledWindow::Clear();
206 ResizeScrollbars(true);
209 wxScrolledWindow::Clear();
210 DoPaint((wxRect
*)NULL
);
213 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
215 wxScrolledWindow::Refresh(eraseBackground
, rect
);
222 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
224 wxClientDC
dc( this );
226 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
228 // moving the mouse in a window shouldn't give it the focus!
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
->MoveCursorToEnd();
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
);
336 DoPaint(); // DoPaint suppresses flicker under GTK
340 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
345 case WXLOWIN_MENU_LUP
:
348 m_llist
->EndSelection();
351 DoPaint(); // TODO: we don't have to redraw everything!
355 case WXLOWIN_MENU_MDOWN
:
359 case WXLOWIN_MENU_DBLCLICK
:
360 // select a word under cursor
361 m_llist
->MoveCursorTo(cursorPos
);
362 m_llist
->MoveCursorWord(-1);
363 m_llist
->StartSelection();
364 m_llist
->MoveCursorWord(1, false);
365 m_llist
->EndSelection();
367 DoPaint(); // TODO: we don't have to redraw everything!
371 // notify about mouse events?
374 // only do the menu if activated, editable and not on a clickable object
375 if(eventId
== WXLOWIN_MENU_RCLICK
377 && (! obj
|| u
== NULL
))
379 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
384 // find the object at this position
387 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
388 commandEvent
.SetEventObject( this );
389 commandEvent
.SetClientData((char *)obj
);
390 GetEventHandler()->ProcessEvent(commandEvent
);
398 // ----------------------------------------------------------------------------
399 // keyboard handling.
400 // ----------------------------------------------------------------------------
403 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
405 int keyCode
= event
.KeyCode();
406 bool ctrlDown
= event
.ControlDown();
408 #ifdef WXLAYOUT_DEBUG
409 if(keyCode
== WXK_F1
)
416 // Force m_Selecting to be false if shift is no longer
417 // pressed. OnKeyUp() cannot catch all Shift-Up events.
418 if(!event
.ShiftDown())
421 // If we deleted the selection here, we must not execute the
422 // deletion in Delete/Backspace handling.
423 bool deletedSelection
= false;
424 // pressing any non-arrow key optionally replaces the selection:
425 if(m_AutoDeleteSelection
427 && m_llist
->HasSelection()
428 && ! IsDirectionKey(keyCode
)
429 && ! (event
.AltDown() || ctrlDown
)
432 m_llist
->DeleteSelection();
433 deletedSelection
= true;
436 // <Shift>+<arrow> starts selection
437 if ( IsDirectionKey(keyCode
) )
442 m_llist
->StartSelection();
446 // just continue the old selection
447 if(! event
.ShiftDown() )
448 m_llist
->DiscardSelection();
452 // If needed, make cursor visible:
453 if(m_CursorVisibility
== -1)
454 m_CursorVisibility
= 1;
456 /* These two nested switches work like this:
457 The first one processes all non-editing keycodes, to move the
458 cursor, etc. It's default will process all keycodes causing
459 modifications to the buffer, but only if editing is allowed.
465 m_llist
->MoveCursorWord(1);
467 m_llist
->MoveCursorHorizontally(1);
471 m_llist
->MoveCursorWord(-1);
473 m_llist
->MoveCursorHorizontally(-1);
476 m_llist
->MoveCursorVertically(-1);
479 m_llist
->MoveCursorVertically(1);
482 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
485 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
489 m_llist
->MoveCursorTo(wxPoint(0, 0));
491 m_llist
->MoveCursorToBeginOfLine();
495 m_llist
->MoveCursorToEnd();
497 m_llist
->MoveCursorToEndOfLine();
501 if(keyCode
== 'c' && ctrlDown
)
503 // this should work even in read-only mode
506 else if( IsEditable() )
508 /* First, handle control keys */
509 if(ctrlDown
&& ! event
.AltDown())
518 if(! deletedSelection
) // already done
522 m_llist
->DeleteLines(1);
524 case 'h': // like backspace
525 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
528 m_llist
->DeleteToBeginOfLine();
531 m_llist
->DeleteToEndOfLine();
539 #ifdef WXLAYOUT_DEBUG
541 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
549 else if( event
.AltDown() && ! event
.ControlDown() )
555 m_llist
->DeleteWord();
562 else if ( ! event
.AltDown() && ! event
.ControlDown())
567 if(event
.ShiftDown())
571 if(event
.ShiftDown())
574 if(! deletedSelection
)
577 case WXK_BACK
: // backspace
578 if(! deletedSelection
)
579 if(m_llist
->MoveCursorHorizontally(-1))
584 m_llist
->WrapLine(m_WrapMargin
);
585 m_llist
->LineBreak();
590 // TODO should be configurable
591 static const int tabSize
= 8;
593 CoordType x
= m_llist
->GetCursorPos().x
;
594 size_t numSpaces
= tabSize
- x
% tabSize
;
595 m_llist
->Insert(wxString(' ', numSpaces
));
600 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
601 && (keyCode
< 256 && keyCode
>= 32)
604 if(m_WrapMargin
> 0 && isspace(keyCode
))
605 m_llist
->WrapLine(m_WrapMargin
);
606 m_llist
->Insert((char)keyCode
);
618 // continue selection to the current (new) cursor position
619 m_llist
->ContinueSelection();
622 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
623 // ne cursor position might be outside the current scrolllbar range
627 // refresh the screen
628 DoPaint(m_llist
->GetUpdateRect());
632 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
634 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
636 m_llist
->EndSelection();
645 wxLayoutWindow::ScrollToCursor(void)
647 wxClientDC
dc( this );
650 int x0
,y0
,x1
,y1
, dx
, dy
;
652 // Calculate where the top of the visible area is:
654 GetScrollPixelsPerUnit(&dx
, &dy
);
657 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
659 // Get the size of the visible window:
660 GetClientSize(&x1
, &y1
);
662 // update the cursor screen position
665 // Make sure that the scrollbars are at a position so that the cursor is
666 // visible if we are editing
667 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
668 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
670 // the cursor should be completely visible in both directions
671 wxPoint
cs(m_llist
->GetCursorSize());
674 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
681 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
688 if ( nx
!= -1 || ny
!= -1 )
690 // set new view start
691 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
694 m_ScrollToCursor
= false;
699 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
701 wxRect region
= GetUpdateRegion().GetBox();
702 InternalPaint(®ion
);
706 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
709 InternalPaint(updateRect
);
710 #else // Causes bad flicker under wxGTK!!!
711 Refresh(FALSE
); //, updateRect);
713 if ( !::UpdateWindow(GetHwnd()) )
714 wxLogLastError("UpdateWindow");
719 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
721 wxPaintDC
dc( this );
724 #ifdef WXLAYOUT_USE_CARET
725 // hide the caret before drawing anything
727 #endif // WXLAYOUT_USE_CARET
729 int x0
,y0
,x1
,y1
, dx
, dy
;
731 // Calculate where the top of the visible area is:
733 GetScrollPixelsPerUnit(&dx
, &dy
);
736 // Get the size of the visible window:
737 GetClientSize(&x1
,&y1
);
743 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
744 updateRect
->x
, updateRect
->y
,
745 updateRect
->x
+updateRect
->width
,
746 updateRect
->y
+updateRect
->height
));
753 /* Check whether the window has grown, if so, we need to reallocate
754 the bitmap to be larger. */
755 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
757 wxASSERT(m_bitmapSize
.x
> 0);
758 wxASSERT(m_bitmapSize
.y
> 0);
760 m_memDC
->SelectObject(wxNullBitmap
);
762 m_bitmapSize
= wxPoint(x1
,y1
);
763 m_bitmap
= new wxBitmap(x1
,y1
);
764 m_memDC
->SelectObject(*m_bitmap
);
767 m_memDC
->SetDeviceOrigin(0,0);
768 m_memDC
->SetBrush(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
769 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
771 m_memDC
->SetLogicalFunction(wxCOPY
);
774 // fill the background with the background bitmap
779 w
= m_BGbitmap
->GetWidth(),
780 h
= m_BGbitmap
->GetHeight();
781 for(y
= 0; y
< y1
; y
+=h
)
782 for(x
= 0; x
< x1
; x
+=w
)
783 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
784 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
787 // This is the important bit: we tell the list to draw itself
791 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
792 updateRect
->x
, updateRect
->y
,
793 updateRect
->x
+updateRect
->width
,
794 updateRect
->y
+updateRect
->height
));
798 // Device origins on the memDC are suspect, we translate manually
799 // with the translate parameter of Draw().
800 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
801 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
803 // We start calculating a new update rect before drawing the
804 // cursor, so that the cursor coordinates get included in the next
805 // update rectangle (although they are drawn on the memDC, this is
806 // needed to erase it):
807 m_llist
->InvalidateUpdateRect();
808 if(m_CursorVisibility
!= 0)
810 // draw a thick cursor for editable windows with focus
811 m_llist
->DrawCursor(*m_memDC
,
812 m_HaveFocus
&& IsEditable(),
816 // Now copy everything to the screen:
818 // This somehow doesn't work, but even the following bit with the
819 // whole rect at once is still a bit broken I think.
820 wxRegionIterator
ri ( GetUpdateRegion() );
824 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
825 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
826 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
827 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
833 // FIXME: Trying to copy only the changed parts, but it does not seem
835 // x0 = updateRect->x; y0 = updateRect->y;
836 // if(updateRect->height < y1)
837 // y1 = updateRect->height;
838 // y1 += WXLO_YOFFSET; //FIXME might not be needed
839 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
842 #ifdef WXLAYOUT_USE_CARET
843 // show the caret back after everything is redrawn
845 #endif // WXLAYOUT_USE_CARET
848 m_ScrollToCursor
= false;
850 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
852 static wxPoint
s_oldCursorPos(-1, -1);
854 wxPoint
pos(m_llist
->GetCursorPos());
856 // avoid unnecessary status bar refreshes
857 if ( pos
!= s_oldCursorPos
)
859 s_oldCursorPos
= pos
;
862 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
863 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
869 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
879 // change the range and position of scrollbars
881 wxLayoutWindow::ResizeScrollbars(bool exact
)
883 wxPoint max
= m_llist
->GetSize();
884 wxSize size
= GetClientSize();
886 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
887 (long int)max
.x
, (long int) max
.y
));
889 // in the absence of scrollbars we should compare with the client size
890 if ( !m_hasHScrollbar
)
891 m_maxx
= size
.x
- WXLO_ROFFSET
;
892 if ( !m_hasVScrollbar
)
893 m_maxy
= size
.y
- WXLO_BOFFSET
;
895 // check if the text hasn't become too big
896 // TODO why do we set both at once? they're independent...
897 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
899 // text became too large
902 // add an extra bit to the sizes to avoid future updates
903 max
.x
+= WXLO_ROFFSET
;
904 max
.y
+= WXLO_BOFFSET
;
907 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
908 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
909 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
910 m_ViewStartX
, m_ViewStartY
,
914 m_hasVScrollbar
= true;
916 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
917 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
922 // check if the window hasn't become too big, thus making the scrollbars
924 if ( m_hasHScrollbar
&& (max
.x
< size
.x
) )
926 // remove the horizontal scrollbar
927 SetScrollbars(0, -1, 0, -1, 0, -1, true);
928 m_hasHScrollbar
= false;
931 if ( m_hasVScrollbar
&& (max
.y
< size
.y
) )
933 // remove the vertical scrollbar
934 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
935 m_hasVScrollbar
= false;
941 // ----------------------------------------------------------------------------
942 // clipboard operations
944 // ----------------------------------------------------------------------------
947 wxLayoutWindow::Paste(bool primary
)
950 if (wxTheClipboard
->Open())
954 wxTheClipboard
->UsePrimarySelection();
956 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
957 wxLayoutDataObject wxldo
;
958 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
960 wxTheClipboard
->GetData(&wxldo
);
963 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
968 wxTextDataObject data
;
969 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
971 wxTheClipboard
->GetData(&data
);
972 wxString text
= data
.GetText();
973 wxLayoutImportText( m_llist
, text
);
976 wxTheClipboard
->Close();
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
)