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 #ifndef wxWANTS_CHARS
122 #define wxWANTS_CHARS 0
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
130 : wxScrolledWindow(parent
, -1,
131 wxDefaultPosition
, wxDefaultSize
,
132 wxHSCROLL
| wxVSCROLL
|
137 SetStatusBar(NULL
); // don't use statusbar
139 m_doSendEvents
= false;
140 m_ViewStartX
= 0; m_ViewStartY
= 0;
141 m_DoPopupMenu
= true;
142 m_PopupMenu
= MakeFormatMenu();
143 m_memDC
= new wxMemoryDC
;
144 m_bitmap
= new wxBitmap(4,4);
145 m_bitmapSize
= wxPoint(4,4);
146 m_llist
= new wxLayoutList();
148 m_ScrollToCursor
= false;
151 // no scrollbars initially
153 m_hasVScrollbar
= false;
157 #ifdef WXLAYOUT_USE_CARET
158 // FIXME cursor size shouldn't be hardcoded
159 wxCaret
*caret
= new wxCaret(this, 2, 20);
161 m_llist
->SetCaret(caret
);
162 #endif // WXLAYOUT_USE_CARET
165 m_HandCursor
= FALSE
;
166 m_CursorVisibility
= -1;
167 SetCursor(wxCURSOR_IBEAM
);
170 // at least under Windows, this should be the default behaviour
171 m_AutoDeleteSelection
= TRUE
;
174 wxLayoutWindow::~wxLayoutWindow()
176 delete m_memDC
; // deletes bitmap automatically (?)
180 SetBackgroundBitmap(NULL
);
184 wxLayoutWindow::Clear(int family
,
192 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
193 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
194 wxScrolledWindow::Clear();
195 ResizeScrollbars(true);
200 m_CursorVisibility
= 1;
202 #ifdef WXLAYOUT_USE_CARET
203 if ( m_CursorVisibility
== 1 )
205 #endif // WXLAYOUT_USE_CARET
207 DoPaint((wxRect
*)NULL
);
210 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
212 wxScrolledWindow::Refresh(eraseBackground
, rect
);
215 //FIXME is this needed? It causes problems... ScrollToCursor();
219 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
221 wxClientDC
dc( this );
224 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
)
227 // moving the mouse in a window shouldn't give it the focus!
228 // Oh yes! wxGTK's focus handling is so broken, that this is the
229 // only sensible way to go.
234 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
235 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
237 findPos
.x
-= WXLO_XOFFSET
;
238 findPos
.y
-= WXLO_YOFFSET
;
245 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
249 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
251 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
253 // has the mouse only been moved?
256 case WXLOWIN_MENU_MOUSEMOVE
:
258 // this variables is used to only erase the message in the status
259 // bar if we had put it there previously - otherwise empting status
260 // bar might be undesirable
261 static bool s_hasPutMessageInStatusBar
= false;
263 // found is only true if we are really over an object, not just
265 if(found
&& u
&& ! m_Selecting
)
268 SetCursor(wxCURSOR_HAND
);
270 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
272 const wxString
&label
= u
->GetLabel();
275 m_StatusBar
->SetStatusText(label
,
277 s_hasPutMessageInStatusBar
= true;
284 SetCursor(wxCURSOR_IBEAM
);
285 m_HandCursor
= FALSE
;
286 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
287 s_hasPutMessageInStatusBar
)
289 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
295 if ( event
.LeftIsDown() )
297 // m_Selecting might not be set if the button got pressed
298 // outside this window, so check for it:
301 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
302 DoPaint(); // TODO: we don't have to redraw everything!
313 case WXLOWIN_MENU_LDOWN
:
315 // always move cursor to mouse click:
318 // we have found the real position
319 m_llist
->MoveCursorTo(cursorPos
);
323 // click beyond the end of the text
324 m_llist
->MoveCursorToEnd();
327 // clicking a mouse removes the selection
328 if ( m_llist
->HasSelection() )
330 m_llist
->DiscardSelection();
332 DoPaint(); // TODO: we don't have to redraw everything!
335 // Calculate where the top of the visible area is:
339 GetScrollPixelsPerUnit(&dx
, &dy
);
342 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
344 if(m_CursorVisibility
== -1)
345 m_CursorVisibility
= 1;
346 #ifdef WXLAYOUT_USE_CARET
347 if ( m_CursorVisibility
== 1 )
349 #endif // WXLAYOUT_USE_CARET
351 if(m_CursorVisibility
)
353 // draw a thick cursor for editable windows with focus
354 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
358 DoPaint(); // DoPaint suppresses flicker under GTK
362 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
367 case WXLOWIN_MENU_LUP
:
370 m_llist
->EndSelection();
373 DoPaint(); // TODO: we don't have to redraw everything!
377 case WXLOWIN_MENU_MDOWN
:
381 case WXLOWIN_MENU_DBLCLICK
:
382 // select a word under cursor
383 m_llist
->MoveCursorTo(cursorPos
);
384 m_llist
->MoveCursorWord(-1);
385 m_llist
->StartSelection();
386 m_llist
->MoveCursorWord(1, false);
387 m_llist
->EndSelection();
389 DoPaint(); // TODO: we don't have to redraw everything!
393 // notify about mouse events?
396 // only do the menu if activated, editable and not on a clickable object
397 if(eventId
== WXLOWIN_MENU_RCLICK
399 && (! obj
|| u
== NULL
))
401 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
406 // find the object at this position
409 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
410 commandEvent
.SetEventObject( this );
411 commandEvent
.SetClientData((char *)obj
);
412 GetEventHandler()->ProcessEvent(commandEvent
);
419 // ----------------------------------------------------------------------------
420 // keyboard handling.
421 // ----------------------------------------------------------------------------
424 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
426 int keyCode
= event
.KeyCode();
427 bool ctrlDown
= event
.ControlDown();
429 #ifdef WXLAYOUT_DEBUG
430 if(keyCode
== WXK_F1
)
437 // Force m_Selecting to be false if shift is no longer
438 // pressed. OnKeyUp() cannot catch all Shift-Up events.
439 if(m_Selecting
&& !event
.ShiftDown())
442 m_llist
->EndSelection();
445 // If we deleted the selection here, we must not execute the
446 // deletion in Delete/Backspace handling.
447 bool deletedSelection
= false;
448 // pressing any non-arrow key optionally replaces the selection:
449 if(m_AutoDeleteSelection
451 && m_llist
->HasSelection()
452 && ! IsDirectionKey(keyCode
)
453 && ! (event
.AltDown() || ctrlDown
)
456 m_llist
->DeleteSelection();
457 deletedSelection
= true;
460 // <Shift>+<arrow> starts selection
461 if ( IsDirectionKey(keyCode
) )
465 // just continue the old selection
466 if( event
.ShiftDown() )
467 m_llist
->ContinueSelection();
470 m_llist
->DiscardSelection();
474 else if( event
.ShiftDown() )
477 m_llist
->StartSelection();
482 // If needed, make cursor visible:
483 if(m_CursorVisibility
== -1)
484 m_CursorVisibility
= 1;
486 /* These two nested switches work like this:
487 The first one processes all non-editing keycodes, to move the
488 cursor, etc. It's default will process all keycodes causing
489 modifications to the buffer, but only if editing is allowed.
495 m_llist
->MoveCursorWord(1);
497 m_llist
->MoveCursorHorizontally(1);
501 m_llist
->MoveCursorWord(-1);
503 m_llist
->MoveCursorHorizontally(-1);
506 m_llist
->MoveCursorVertically(-1);
509 m_llist
->MoveCursorVertically(1);
512 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
515 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
519 m_llist
->MoveCursorTo(wxPoint(0, 0));
521 m_llist
->MoveCursorToBeginOfLine();
525 m_llist
->MoveCursorToEnd();
527 m_llist
->MoveCursorToEndOfLine();
531 if(keyCode
== 'c' && ctrlDown
)
533 // this should work even in read-only mode
536 else if( IsEditable() )
538 /* First, handle control keys */
539 if(ctrlDown
&& ! event
.AltDown())
548 if(! deletedSelection
) // already done
552 m_llist
->DeleteLines(1);
554 case 'h': // like backspace
555 if(m_llist
->MoveCursorHorizontally(-1)) m_llist
->Delete(1);
558 m_llist
->DeleteToBeginOfLine();
561 m_llist
->DeleteToEndOfLine();
569 #ifdef WXLAYOUT_DEBUG
571 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
579 else if( event
.AltDown() && ! event
.ControlDown() )
585 m_llist
->DeleteWord();
592 else if ( ! event
.AltDown() && ! event
.ControlDown())
597 if(event
.ShiftDown())
601 if(event
.ShiftDown())
604 if(! deletedSelection
)
607 case WXK_BACK
: // backspace
608 if(! deletedSelection
)
609 if(m_llist
->MoveCursorHorizontally(-1))
614 m_llist
->WrapLine(m_WrapMargin
);
615 m_llist
->LineBreak();
619 if ( !event
.ShiftDown() )
621 // TODO should be configurable
622 static const int tabSize
= 8;
624 CoordType x
= m_llist
->GetCursorPos().x
;
625 size_t numSpaces
= tabSize
- x
% tabSize
;
626 m_llist
->Insert(wxString(' ', numSpaces
));
631 if((!(event
.ControlDown() || event
.AltDown() || event
.MetaDown()))
632 && (keyCode
< 256 && keyCode
>= 32)
635 if(m_WrapMargin
> 0 && isspace(keyCode
))
636 m_llist
->WrapLine(m_WrapMargin
);
637 m_llist
->Insert((char)keyCode
);
649 // continue selection to the current (new) cursor position
650 m_llist
->ContinueSelection();
653 // we must call ResizeScrollbars() before ScrollToCursor(), otherwise the
654 // ne cursor position might be outside the current scrolllbar range
658 // refresh the screen
659 DoPaint(m_llist
->GetUpdateRect());
663 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
665 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
667 m_llist
->EndSelection();
676 wxLayoutWindow::ScrollToCursor(void)
678 wxClientDC
dc( this );
681 int x0
,y0
,x1
,y1
, dx
, dy
;
683 // Calculate where the top of the visible area is:
685 GetScrollPixelsPerUnit(&dx
, &dy
);
688 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
690 // Get the size of the visible window:
691 GetClientSize(&x1
, &y1
);
693 // update the cursor screen position
696 // Make sure that the scrollbars are at a position so that the cursor is
697 // visible if we are editing
698 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
699 wxPoint cc
= m_llist
->GetCursorScreenPos(dc
);
701 // the cursor should be completely visible in both directions
702 wxPoint
cs(m_llist
->GetCursorSize());
705 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
712 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
719 if ( nx
!= -1 || ny
!= -1 )
721 // set new view start
722 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
725 m_ScrollToCursor
= false;
730 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
732 wxRect region
= GetUpdateRegion().GetBox();
733 InternalPaint(®ion
);
737 wxLayoutWindow::DoPaint(const wxRect
*updateRect
)
740 // Calling Refresh() causes bad flicker under wxGTK!!!
741 InternalPaint(updateRect
);
743 // shouldn't specify the update rectangle if it doesn't include all the
744 // changed locations - otherwise, they won't be repainted at all because
745 // the system clips the display to the update rect
746 Refresh(FALSE
); //, updateRect);
751 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
753 wxPaintDC
dc( this );
756 #ifdef WXLAYOUT_USE_CARET
757 // hide the caret before drawing anything
759 #endif // WXLAYOUT_USE_CARET
761 int x0
,y0
,x1
,y1
, dx
, dy
;
763 // Calculate where the top of the visible area is:
765 GetScrollPixelsPerUnit(&dx
, &dy
);
768 // Get the size of the visible window:
769 GetClientSize(&x1
,&y1
);
775 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
776 updateRect
->x
, updateRect
->y
,
777 updateRect
->x
+updateRect
->width
,
778 updateRect
->y
+updateRect
->height
));
786 /* Check whether the window has grown, if so, we need to reallocate
787 the bitmap to be larger. */
788 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
790 wxASSERT(m_bitmapSize
.x
> 0);
791 wxASSERT(m_bitmapSize
.y
> 0);
793 m_memDC
->SelectObject(wxNullBitmap
);
795 m_bitmapSize
= wxPoint(x1
,y1
);
796 m_bitmap
= new wxBitmap(x1
,y1
);
797 m_memDC
->SelectObject(*m_bitmap
);
800 m_memDC
->SetDeviceOrigin(0,0);
801 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
802 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
804 m_memDC
->SetLogicalFunction(wxCOPY
);
807 // fill the background with the background bitmap
812 w
= m_BGbitmap
->GetWidth(),
813 h
= m_BGbitmap
->GetHeight();
814 for(y
= 0; y
< y1
; y
+=h
)
815 for(x
= 0; x
< x1
; x
+=w
)
816 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
817 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
820 // This is the important bit: we tell the list to draw itself
824 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
825 updateRect
->x
, updateRect
->y
,
826 updateRect
->x
+updateRect
->width
,
827 updateRect
->y
+updateRect
->height
));
831 // Device origins on the memDC are suspect, we translate manually
832 // with the translate parameter of Draw().
833 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
834 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
836 // We start calculating a new update rect before drawing the
837 // cursor, so that the cursor coordinates get included in the next
838 // update rectangle (although they are drawn on the memDC, this is
839 // needed to erase it):
840 m_llist
->InvalidateUpdateRect();
841 if(m_CursorVisibility
!= 0)
843 // draw a thick cursor for editable windows with focus
844 m_llist
->DrawCursor(*m_memDC
,
845 m_HaveFocus
&& IsEditable(),
849 // Now copy everything to the screen:
851 // This somehow doesn't work, but even the following bit with the
852 // whole rect at once is still a bit broken I think.
853 wxRegionIterator
ri ( GetUpdateRegion() );
857 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
858 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
859 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
860 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
866 // FIXME: Trying to copy only the changed parts, but it does not seem
868 // x0 = updateRect->x; y0 = updateRect->y;
869 // if(updateRect->height < y1)
870 // y1 = updateRect->height;
871 // y1 += WXLO_YOFFSET; //FIXME might not be needed
872 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
875 #ifdef WXLAYOUT_USE_CARET
876 // show the caret back after everything is redrawn
878 #endif // WXLAYOUT_USE_CARET
881 m_ScrollToCursor
= false;
883 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
885 static wxPoint
s_oldCursorPos(-1, -1);
887 wxPoint
pos(m_llist
->GetCursorPos());
889 // avoid unnecessary status bar refreshes
890 if ( pos
!= s_oldCursorPos
)
892 s_oldCursorPos
= pos
;
895 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
896 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
902 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
912 // change the range and position of scrollbars
914 wxLayoutWindow::ResizeScrollbars(bool exact
)
916 wxPoint max
= m_llist
->GetSize();
917 wxSize size
= GetClientSize();
919 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
920 (long int)max
.x
, (long int) max
.y
));
922 // in the absence of scrollbars we should compare with the client size
923 if ( !m_hasHScrollbar
)
924 m_maxx
= size
.x
;// - WXLO_ROFFSET;
925 if ( !m_hasVScrollbar
)
926 m_maxy
= size
.y
;// - WXLO_BOFFSET;
928 // check if the text hasn't become too big
929 // TODO why do we set both at once? they're independent...
930 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
932 // text became too large
935 // add an extra bit to the sizes to avoid future updates
936 max
.x
+= WXLO_ROFFSET
;
937 max
.y
+= WXLO_BOFFSET
;
940 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
941 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
942 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
943 m_ViewStartX
, m_ViewStartY
,
947 m_hasVScrollbar
= true;
949 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
950 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
953 //FIXME: this code is pretty broken, producing "arithmetic
954 //exception" crashes (div by 0??)
957 // check if the window hasn't become too big, thus making the scrollbars
961 // add an extra bit to the sizes to avoid future updates
962 max
.x
-= WXLO_ROFFSET
;
963 max
.y
-= WXLO_BOFFSET
;
966 if ( m_hasHScrollbar
&& (max
.x
< m_maxx
) )
968 // remove the horizontal scrollbar
969 SetScrollbars(0, -1, 0, -1, 0, -1, true);
970 m_hasHScrollbar
= false;
973 if ( m_hasVScrollbar
&& (max
.y
< m_maxy
) )
975 // remove the vertical scrollbar
976 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
977 m_hasVScrollbar
= false;
983 // ----------------------------------------------------------------------------
984 // clipboard operations
986 // ----------------------------------------------------------------------------
989 wxLayoutWindow::Paste(bool primary
)
992 if (wxTheClipboard
->Open())
996 wxTheClipboard
->UsePrimarySelection();
998 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
999 wxLayoutDataObject wxldo
;
1000 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1002 wxTheClipboard
->GetData(&wxldo
);
1005 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
1010 wxTextDataObject data
;
1011 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
1013 wxTheClipboard
->GetData(&data
);
1014 wxString text
= data
.GetText();
1015 wxLayoutImportText( m_llist
, text
);
1018 wxTheClipboard
->Close();
1023 wxLayoutWindow::Copy(bool invalidate
)
1025 // Calling GetSelection() will automatically do an EndSelection()
1026 // on the list, but we need to take a note of it, too:
1029 m_Selecting
= false;
1030 m_llist
->EndSelection();
1033 wxLayoutDataObject wldo
;
1034 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1037 // Export selection as text:
1039 wxLayoutExportObject
*export
;
1040 wxLayoutExportStatus
status(llist
);
1041 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1043 if(export
->type
== WXLO_EXPORT_TEXT
)
1044 text
<< *(export
->content
.text
);
1049 // The exporter always appends a newline, so we chop it off if it
1052 size_t len
= text
.Length();
1053 if(len
> 2 && text
[len
-2] == '\r') // Windows
1054 text
= text
.Mid(0,len
-2);
1055 else if(len
> 1 && text
[len
-1] == '\n')
1056 text
= text
.Mid(0,len
-1);
1060 if (wxTheClipboard
->Open())
1062 wxTextDataObject
*data
= new wxTextDataObject( text
);
1063 bool rc
= wxTheClipboard
->SetData( data
);
1064 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1065 rc
|= wxTheClipboard
->AddData( &wldo
);
1067 wxTheClipboard
->Close();
1075 wxLayoutWindow::Cut(void)
1077 if(Copy(false)) // do not invalidate selection after copy
1079 m_llist
->DeleteSelection();
1086 // ----------------------------------------------------------------------------
1088 // ----------------------------------------------------------------------------
1091 wxLayoutWindow::Find(const wxString
&needle
,
1092 wxPoint
* fromWhere
)
1096 if(fromWhere
== NULL
)
1097 found
= m_llist
->FindText(needle
, m_llist
->GetCursorPos());
1099 found
= m_llist
->FindText(needle
, *fromWhere
);
1107 m_llist
->MoveCursorTo(found
);
1114 // ----------------------------------------------------------------------------
1116 // ----------------------------------------------------------------------------
1119 wxLayoutWindow::MakeFormatMenu()
1121 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1123 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1124 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1125 m
->AppendSeparator();
1126 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1127 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1128 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1129 m
->AppendSeparator();
1130 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1131 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1132 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1137 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1139 event
.Check(m_llist
->IsFontUnderlined());
1142 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1144 event
.Check(m_llist
->IsFontBold());
1147 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1149 event
.Check(m_llist
->IsFontItalic());
1152 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1154 switch (event
.GetId())
1156 case WXLOWIN_MENU_LARGER
:
1157 m_llist
->SetFontLarger(); Refresh(FALSE
); break;
1158 case WXLOWIN_MENU_SMALLER
:
1159 m_llist
->SetFontSmaller(); Refresh(FALSE
); break;
1160 case WXLOWIN_MENU_UNDERLINE
:
1161 m_llist
->ToggleFontUnderline(); Refresh(FALSE
); break;
1162 case WXLOWIN_MENU_BOLD
:
1163 m_llist
->ToggleFontWeight(); Refresh(FALSE
); break;
1164 case WXLOWIN_MENU_ITALICS
:
1165 m_llist
->ToggleFontItalics(); Refresh(FALSE
); break;
1166 case WXLOWIN_MENU_ROMAN
:
1167 m_llist
->SetFontFamily(wxROMAN
); Refresh(FALSE
); break;
1168 case WXLOWIN_MENU_TYPEWRITER
:
1169 m_llist
->SetFontFamily(wxFIXED
); Refresh(FALSE
); break;
1170 case WXLOWIN_MENU_SANSSERIF
:
1171 m_llist
->SetFontFamily(wxSWISS
); Refresh(FALSE
); break;
1175 // ----------------------------------------------------------------------------
1177 // ----------------------------------------------------------------------------
1180 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1184 Refresh(FALSE
); // cursor must change
1188 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1190 m_HaveFocus
= false;
1192 Refresh(FALSE
);// cursor must change
1195 // ----------------------------------------------------------------------------
1196 // private functions
1197 // ----------------------------------------------------------------------------
1199 static bool IsDirectionKey(long keyCode
)