1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998-2000 by Karsten Ballüder (ballueder@gmx.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"
38 # include "MDialogs.h"
42 # include "wx/msw/private.h"
45 # include "wxlwindow.h"
46 # include "wxlparser.h"
49 #include "wx/clipbrd.h"
50 #include "wx/textctrl.h"
51 #include "wx/dataobj.h"
53 #ifdef WXLAYOUT_USE_CARET
54 # include "wx/caret.h"
55 #endif // WXLAYOUT_USE_CARET
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
65 # define WXLO_DEBUG(x) wxLogDebug x
67 # define WXLO_DEBUG(x)
70 // for profiling in debug mode:
71 WXLO_TIMER_DEFINE(UpdateTimer
);
72 WXLO_TIMER_DEFINE(BlitTimer
);
73 WXLO_TIMER_DEFINE(LayoutTimer
);
74 WXLO_TIMER_DEFINE(TmpTimer
);
75 WXLO_TIMER_DEFINE(DrawTimer
);
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 /// offsets to put a nice frame around text
82 #define WXLO_XOFFSET 4
83 #define WXLO_YOFFSET 4
85 /// offset to the right and bottom for when to redraw scrollbars
86 #define WXLO_ROFFSET 20
87 #define WXLO_BOFFSET 20
89 /// scroll margins when selecting with the mouse
90 #define WXLO_SCROLLMARGIN_X 10
91 #define WXLO_SCROLLMARGIN_Y 10
93 /// the size of one scrollbar page in pixels
94 static const int X_SCROLL_PAGE
= 10;
95 static const int Y_SCROLL_PAGE
= 20;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
104 EVT_SIZE (wxLayoutWindow::OnSize
)
106 EVT_PAINT (wxLayoutWindow::OnPaint
)
108 EVT_CHAR (wxLayoutWindow::OnChar
)
109 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
111 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
112 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
113 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
114 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
115 EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown
)
116 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
118 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
119 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
120 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
121 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
123 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
124 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
126 // EVT_IDLE(wxLayoutWindow::ResizeScrollbars)
129 // ----------------------------------------------------------------------------
130 // function prototypes
131 // ----------------------------------------------------------------------------
133 /// returns true if keyCode is one of arrows/home/end/page{up|down} keys
134 static bool IsDirectionKey(long keyCode
);
136 // ============================================================================
138 // ============================================================================
140 #ifndef wxWANTS_CHARS
141 # define wxWANTS_CHARS 0
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
149 : wxScrolledWindow(parent
, wxID_ANY
,
150 wxDefaultPosition
, wxDefaultSize
,
151 wxHSCROLL
| wxVSCROLL
|
157 SetStatusBar(NULL
); // don't use statusbar
158 #endif // wxUSE_STATUSBAR
160 m_doSendEvents
= false;
161 m_ViewStartX
= 0; m_ViewStartY
= 0;
162 m_DoPopupMenu
= true;
163 m_PopupMenu
= MakeFormatMenu();
164 m_memDC
= new wxMemoryDC
;
165 m_bitmap
= new wxBitmap(4,4);
166 m_bitmapSize
= wxPoint(4,4);
167 m_llist
= new wxLayoutList();
169 m_ScrollToCursor
= false;
171 m_FocusFollowMode
= false;
176 // no scrollbars initially
178 m_hasVScrollbar
= false;
182 #ifdef WXLAYOUT_USE_CARET
183 // FIXME cursor size shouldn't be hardcoded
184 wxCaret
*caret
= new wxCaret(this, 2, 20);
186 m_llist
->SetCaret(caret
);
187 #endif // WXLAYOUT_USE_CARET
190 m_HandCursor
= false;
191 m_CursorVisibility
= -1;
192 SetCursor(wxCURSOR_IBEAM
);
195 // at least under Windows, this should be the default behaviour
196 m_AutoDeleteSelection
= true;
199 wxLayoutWindow::~wxLayoutWindow()
201 delete m_memDC
; // deletes bitmap automatically (?)
205 SetBackgroundBitmap(NULL
);
209 wxLayoutWindow::Clear(int family
,
217 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
218 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
219 //wxScrolledWindow::Clear();
220 ResizeScrollbars(true);
224 m_CursorVisibility
= 1;
226 #ifdef WXLAYOUT_USE_CARET
227 if ( m_CursorVisibility
== 1 )
229 #endif // WXLAYOUT_USE_CARET
231 RequestUpdate((wxRect
*)NULL
);
234 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
236 wxScrolledWindow::Refresh(eraseBackground
, rect
);
240 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
242 wxClientDC
dc( this );
244 if ( (eventId
!= WXLOWIN_MENU_MOUSEMOVE
249 && (wxWindow::FindFocus() != this) )
255 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
256 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
258 findPos
.x
-= WXLO_XOFFSET
;
259 findPos
.y
-= WXLO_YOFFSET
;
267 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
269 // Scroll the window if the mouse is at the end of it:
270 if(m_Selecting
&& eventId
== WXLOWIN_MENU_MOUSEMOVE
)
272 //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
274 GetViewStart(&left
, &top
);
275 wxSize size
= GetClientSize();
278 if(event
.GetX() < WXLO_SCROLLMARGIN_X
)
279 xdelta
= -(WXLO_SCROLLMARGIN_X
-event
.GetX());
280 else if(event
.GetX() > size
.x
-WXLO_SCROLLMARGIN_X
)
281 xdelta
= event
.GetX()-size
.x
+WXLO_SCROLLMARGIN_X
;
285 if(event
.GetY() < WXLO_SCROLLMARGIN_Y
)
286 ydelta
= -(WXLO_SCROLLMARGIN_Y
-event
.GetY());
287 else if(event
.GetY() > size
.y
-WXLO_SCROLLMARGIN_Y
)
288 ydelta
= event
.GetY()-size
.y
+WXLO_SCROLLMARGIN_Y
;
292 //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
293 if(xdelta
!= 0 || ydelta
!= 0)
295 top
+= ydelta
; if(top
< 0) top
= 0;
296 left
+= xdelta
; if(left
< 0) left
= 0;
303 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
305 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
307 // has the mouse only been moved?
310 case WXLOWIN_MENU_MOUSEMOVE
:
312 // this variables is used to only erase the message in the status
313 // bar if we had put it there previously - otherwise empting status
314 // bar might be undesirable
316 static bool s_hasPutMessageInStatusBar
= false;
317 #endif // wxUSE_STATUSBAR
319 // found is only true if we are really over an object, not just
321 if(found
&& u
&& ! m_Selecting
)
324 SetCursor(wxCURSOR_HAND
);
327 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
329 const wxString
&label
= u
->GetLabel();
332 m_StatusBar
->SetStatusText(label
,m_StatusFieldLabel
);
333 s_hasPutMessageInStatusBar
= true;
336 #endif // wxUSE_STATUSBAR
341 SetCursor(wxCURSOR_IBEAM
);
342 m_HandCursor
= false;
344 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
345 s_hasPutMessageInStatusBar
)
347 m_StatusBar
->SetStatusText(wxEmptyString
, m_StatusFieldLabel
);
349 #endif // wxUSE_STATUSBAR
354 if ( event
.LeftIsDown() )
356 // m_Selecting might not be set if the button got pressed
357 // outside this window, so check for it:
360 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
361 RequestUpdate(); // TODO: we don't have to redraw everything!
372 case WXLOWIN_MENU_LDOWN
:
374 // always move cursor to mouse click:
375 m_llist
->MoveCursorTo(cursorPos
);
377 // clicking a mouse removes the selection
378 if ( m_llist
->HasSelection() )
380 m_llist
->DiscardSelection();
382 RequestUpdate(); // TODO: we don't have to redraw everything!
385 // Calculate where the top of the visible area is:
387 GetViewStart(&x0
,&y0
);
389 GetScrollPixelsPerUnit(&dx
, &dy
);
392 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
394 if(m_CursorVisibility
== -1)
395 m_CursorVisibility
= 1;
397 #ifdef WXLAYOUT_USE_CARET
398 if ( m_CursorVisibility
== 1 )
400 #endif // WXLAYOUT_USE_CARET
402 if(m_CursorVisibility
)
404 // draw a thick cursor for editable windows with focus
405 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
409 RequestUpdate(); // RequestUpdate suppresses flicker under GTK
413 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
418 case WXLOWIN_MENU_LUP
:
421 // end selection at the cursor position corresponding to the
422 // current mouse position, but don´t move cursor there.
423 m_llist
->EndSelection(cursorPos
,m_ClickPosition
);
426 RequestUpdate(); // TODO: we don't have to redraw everything!
430 case WXLOWIN_MENU_MDOWN
:
434 case WXLOWIN_MENU_DBLCLICK
:
435 // select a word under cursor
436 m_llist
->MoveCursorTo(cursorPos
);
437 m_llist
->MoveCursorWord(-1);
438 m_llist
->StartSelection();
439 m_llist
->MoveCursorWord(1, false);
440 m_llist
->EndSelection();
442 RequestUpdate(); // TODO: we don't have to redraw everything!
446 // notify about mouse events?
449 // only do the menu if activated, editable and not on a clickable object
450 if(eventId
== WXLOWIN_MENU_RCLICK
452 && (! obj
|| u
== NULL
))
454 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
459 // find the object at this position
462 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
463 commandEvent
.SetEventObject( this );
464 commandEvent
.SetClientData((char *)obj
);
465 GetEventHandler()->ProcessEvent(commandEvent
);
472 // ----------------------------------------------------------------------------
473 // keyboard handling.
474 // ----------------------------------------------------------------------------
477 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
479 int keyCode
= event
.GetKeyCode();
480 bool ctrlDown
= event
.ControlDown();
482 #ifdef WXLAYOUT_DEBUG
483 if(keyCode
== WXK_F1
)
490 // Force m_Selecting to be false if shift is no longer
491 // pressed. OnKeyUp() cannot catch all Shift-Up events.
492 if(m_Selecting
&& !event
.ShiftDown())
495 m_llist
->EndSelection();
496 m_llist
->DiscardSelection(); //FIXME: correct?
499 // If we deleted the selection here, we must not execute the
500 // deletion in Delete/Backspace handling.
501 bool deletedSelection
= false;
502 // pressing any non-arrow key optionally replaces the selection:
503 if(m_AutoDeleteSelection
506 && m_llist
->HasSelection()
507 && ! IsDirectionKey(keyCode
)
508 && ! (event
.AltDown() || ctrlDown
) )
510 m_llist
->DeleteSelection();
511 deletedSelection
= true;
515 // <Shift>+<arrow> starts selection
516 if ( IsDirectionKey(keyCode
) )
518 // just continue the old selection
519 if ( m_Selecting
&& event
.ShiftDown() )
521 m_llist
->ContinueSelection();
525 m_llist
->DiscardSelection();
527 if( event
.ShiftDown() )
530 m_llist
->StartSelection();
535 // If needed, make cursor visible:
536 if(m_CursorVisibility
== -1)
537 m_CursorVisibility
= 1;
539 /* These two nested switches work like this:
540 The first one processes all non-editing keycodes, to move the
541 cursor, etc. It's default will process all keycodes causing
542 modifications to the buffer, but only if editing is allowed.
549 m_llist
->MoveCursorWord(1);
551 m_llist
->MoveCursorHorizontally(1);
556 m_llist
->MoveCursorWord(-1);
558 m_llist
->MoveCursorHorizontally(-1);
563 m_llist
->MoveCursorVertically(-1);
567 m_llist
->MoveCursorVertically(1);
571 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
575 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
580 m_llist
->MoveCursorTo(wxPoint(0, 0));
582 m_llist
->MoveCursorToBeginOfLine();
587 m_llist
->MoveCursorToEnd();
589 m_llist
->MoveCursorToEndOfLine();
594 if(ctrlDown
&& ! IsEditable())
600 // this should work even in read-only mode
608 case 't': // search again
613 // we don't handle it, maybe an accelerator?
618 else if( IsEditable() )
620 /* First, handle control keys */
621 if(ctrlDown
&& ! event
.AltDown())
623 if(keyCode
>= 'A' && keyCode
<= 'Z')
624 keyCode
= tolower(keyCode
);
634 if(! deletedSelection
)
636 m_llist
->DeleteWord();
642 if(! deletedSelection
) // already done
650 m_llist
->DeleteLines(1);
654 case 'h': // like backspace
655 if(m_llist
->MoveCursorHorizontally(-1))
666 case 't': // search again
671 m_llist
->DeleteToBeginOfLine();
676 m_llist
->DeleteToEndOfLine();
694 m_llist
->WrapLine(m_WrapMargin
);
699 m_llist
->WrapAll(m_WrapMargin
);
702 #ifdef WXLAYOUT_DEBUG
704 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
713 // we don't handle it, maybe an accelerator?
718 else if( event
.AltDown() && ! event
.ControlDown() )
724 m_llist
->DeleteWord();
729 // we don't handle it, maybe an accelerator?
734 else if ( ! event
.AltDown() && ! event
.ControlDown())
739 if(event
.ShiftDown())
744 if(event
.ShiftDown())
748 else if(! deletedSelection
)
755 case WXK_BACK
: // backspace
756 if(! deletedSelection
)
758 if(m_llist
->MoveCursorHorizontally(-1))
769 && m_llist
->GetCursorPos().x
> m_WrapMargin
)
771 m_llist
->WrapLine(m_WrapMargin
);
774 m_llist
->LineBreak();
779 if ( !event
.ShiftDown() )
781 // TODO should be configurable
782 static const int tabSize
= 8;
784 CoordType x
= m_llist
->GetCursorPos().x
;
785 size_t numSpaces
= tabSize
- x
% tabSize
;
786 m_llist
->Insert(wxString(' ', numSpaces
));
792 if ( ( !(event
.ControlDown() || event
.AltDown()) )
793 && (keyCode
< 256 && keyCode
>= 32) )
797 && m_llist
->GetCursorPos().x
> m_WrapMargin
798 && isspace(keyCode
) )
800 m_llist
->WrapLine(m_WrapMargin
);
803 m_llist
->Insert((wxChar
)keyCode
);
808 // we don't handle it, maybe an accelerator?
818 // we don't handle it, maybe an accelerator?
825 // continue selection to the current (new) cursor position
826 m_llist
->ContinueSelection();
830 // refresh the screen
831 RequestUpdate(m_llist
->GetUpdateRect());
835 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
837 if ( event
.GetKeyCode() == WXK_SHIFT
&& m_Selecting
)
839 m_llist
->EndSelection();
848 wxLayoutWindow::ScrollToCursor()
850 //is always needed to make sure we know where the cursor is
852 //RequestUpdate(m_llist->GetUpdateRect());
857 int x0
,y0
,x1
,y1
, dx
, dy
;
859 // Calculate where the top of the visible area is:
860 GetViewStart(&x0
,&y0
);
861 GetScrollPixelsPerUnit(&dx
, &dy
);
864 WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0
, y0
));
866 // Get the size of the visible window:
867 GetClientSize(&x1
, &y1
);
869 // Make sure that the scrollbars are at a position so that the cursor is
870 // visible if we are editing
871 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
872 wxPoint cc
= m_llist
->GetCursorScreenPos();
874 // the cursor should be completely visible in both directions
875 wxPoint
cs(m_llist
->GetCursorSize());
879 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
886 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
893 if( nx
!= -1 || ny
!= -1 )
895 // set new view start
896 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
898 m_ScrollToCursor
= false;
904 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
906 wxRect region
= GetUpdateRegion().GetBox();
907 InternalPaint(®ion
);
911 wxLayoutWindow::RequestUpdate(const wxRect
*
920 // Calling Refresh() causes bad flicker under wxGTK!!!
921 InternalPaint(updateRect
);
923 // shouldn't specify the update rectangle if it doesn't include all the
924 // changed locations - otherwise, they won't be repainted at all because
925 // the system clips the display to the update rect
926 Refresh(false); //, updateRect);
931 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
934 wxPaintDC
dc( this );
937 #ifdef WXLAYOUT_USE_CARET
938 // hide the caret before drawing anything
940 #endif // WXLAYOUT_USE_CARET
942 int x0
,y0
,x1
,y1
, dx
, dy
;
944 // Calculate where the top of the visible area is:
945 GetViewStart(&x0
,&y0
);
946 GetScrollPixelsPerUnit(&dx
, &dy
);
949 // Get the size of the visible window:
950 GetClientSize(&x1
,&y1
);
956 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
957 updateRect
->x
, updateRect
->y
,
958 updateRect
->x
+updateRect
->width
,
959 updateRect
->y
+updateRect
->height
));
962 ResizeScrollbars(true);
964 WXLO_TIMER_START(TmpTimer
);
965 /* Check whether the window has grown, if so, we need to reallocate
966 the bitmap to be larger. */
967 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
969 wxASSERT(m_bitmapSize
.x
> 0);
970 wxASSERT(m_bitmapSize
.y
> 0);
972 m_memDC
->SelectObject(wxNullBitmap
);
974 m_bitmapSize
= wxPoint(x1
,y1
);
975 m_bitmap
= new wxBitmap(x1
,y1
);
976 m_memDC
->SelectObject(*m_bitmap
);
979 m_memDC
->SetDeviceOrigin(0,0);
980 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
981 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
983 m_memDC
->SetLogicalFunction(wxCOPY
);
985 WXLO_TIMER_STOP(TmpTimer
);
987 // fill the background with the background bitmap
992 w
= m_BGbitmap
->GetWidth(),
993 h
= m_BGbitmap
->GetHeight();
994 for(y
= 0; y
< y1
; y
+=h
)
996 for(x
= 0; x
< x1
; x
+=w
)
998 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
1002 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
1005 // This is the important bit: we tell the list to draw itself
1006 #if WXLO_DEBUG_URECT
1009 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
1010 updateRect
->x
, updateRect
->y
,
1011 updateRect
->x
+updateRect
->width
,
1012 updateRect
->y
+updateRect
->height
));
1016 // Device origins on the memDC are suspect, we translate manually
1017 // with the translate parameter of Draw().
1018 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
1019 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
1021 // We start calculating a new update rect before drawing the
1022 // cursor, so that the cursor coordinates get included in the next
1023 // update rectangle (although they are drawn on the memDC, this is
1024 // needed to erase it):
1025 m_llist
->InvalidateUpdateRect();
1026 if(m_CursorVisibility
== 1)
1028 // draw a thick cursor for editable windows with focus
1029 m_llist
->DrawCursor(*m_memDC
,
1030 m_HaveFocus
&& IsEditable(),
1034 WXLO_TIMER_START(BlitTimer
);
1035 // Now copy everything to the screen:
1037 // This somehow doesn't work, but even the following bit with the
1038 // whole rect at once is still a bit broken I think.
1039 wxRegionIterator
ri ( GetUpdateRegion() );
1043 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
1044 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
1046 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
1047 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,false);
1053 // FIXME: Trying to copy only the changed parts, but it does not seem
1055 // x0 = updateRect->x; y0 = updateRect->y;
1056 // if(updateRect->height < y1)
1057 // y1 = updateRect->height;
1058 // y1 += WXLO_YOFFSET; //FIXME might not be needed
1059 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,false);
1062 WXLO_TIMER_STOP(BlitTimer
);
1065 #ifdef WXLAYOUT_USE_CARET
1066 // show the caret back after everything is redrawn
1068 #endif // WXLAYOUT_USE_CARET
1073 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
1075 static wxPoint
s_oldCursorPos(-1, -1);
1077 wxPoint
pos(m_llist
->GetCursorPos());
1079 // avoid unnecessary status bar refreshes
1080 if ( pos
!= s_oldCursorPos
)
1082 s_oldCursorPos
= pos
;
1085 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
1086 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
1089 #endif // wxUSE_STATUSBAR
1091 WXLO_TIMER_PRINT(LayoutTimer
);
1092 WXLO_TIMER_PRINT(BlitTimer
);
1093 WXLO_TIMER_PRINT(TmpTimer
);
1097 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
1106 Change the range and position of scrollbars. Has evolved into a
1107 generic Update function which will at some time later cause a repaint
1112 wxLayoutWindow::ResizeScrollbars(bool exact
)
1114 wxClientDC
dc( this );
1116 // m_llist->ForceTotalLayout();
1120 // we are laying out just the minimum, but always up to the
1121 // cursor line, so the cursor position is updated.
1122 m_llist
->Layout(dc
, 0);
1126 WXLO_TIMER_START(LayoutTimer
);
1127 m_llist
->Layout(dc
, -1);
1128 WXLO_TIMER_STOP(LayoutTimer
);
1131 wxPoint max
= m_llist
->GetSize();
1132 wxSize size
= GetClientSize();
1134 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
1135 (long int)max
.x
, (long int) max
.y
));
1137 // in the absence of scrollbars we should compare with the client size
1138 if ( !m_hasHScrollbar
)
1139 m_maxx
= size
.x
;// - WXLO_ROFFSET;
1141 if ( !m_hasVScrollbar
)
1142 m_maxy
= size
.y
;// - WXLO_BOFFSET;
1144 // check if the text hasn't become too big
1145 // TODO why do we set both at once? they're independent...
1146 if( max
.x
> m_maxx
- WXLO_ROFFSET
1147 || max
.y
> m_maxy
- WXLO_BOFFSET
1148 || (max
.x
< m_maxx
- X_SCROLL_PAGE
)
1149 || (max
.y
< m_maxy
- Y_SCROLL_PAGE
)
1152 // text became too large
1155 // add an extra bit to the sizes to avoid future updates
1156 max
.x
+= WXLO_ROFFSET
;
1157 max
.y
+= WXLO_BOFFSET
;
1162 if(max
.x
< X_SCROLL_PAGE
&& m_hasHScrollbar
)
1164 SetScrollbars(0,-1,0,-1,0,-1,true);
1165 m_hasHScrollbar
= false;
1169 if(max
.y
< Y_SCROLL_PAGE
&& m_hasVScrollbar
)
1171 SetScrollbars(-1,0,-1,0,-1,0,true);
1172 m_hasVScrollbar
= false;
1177 // (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE)
1178 (max
.x
> size
.x
- X_SCROLL_PAGE
|| max
.y
> size
.y
- Y_SCROLL_PAGE
) )
1180 GetViewStart(&m_ViewStartX
, &m_ViewStartY
);
1182 SetScrollbars(X_SCROLL_PAGE
,
1184 max
.x
/ X_SCROLL_PAGE
+ 2,
1185 max
.y
/ Y_SCROLL_PAGE
+ 2,
1191 m_hasVScrollbar
= true;
1192 // ScrollToCursor();
1195 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
1196 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
1200 // ----------------------------------------------------------------------------
1202 // clipboard operations
1204 // ----------------------------------------------------------------------------
1207 wxLayoutWindow::Paste(bool usePrivate
, bool primary
)
1209 // this only has an effect under X11:
1210 wxTheClipboard
->UsePrimarySelection(primary
);
1212 if (wxTheClipboard
->Open())
1216 wxLayoutDataObject wxldo
;
1217 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1219 if(wxTheClipboard
->GetData(wxldo
))
1221 wxTheClipboard
->Close();
1222 wxString str
= wxldo
.GetLayoutData();
1231 wxTextDataObject data
;
1232 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1233 && wxTheClipboard
->GetData(data
) )
1235 wxTheClipboard
->Close();
1236 wxString text
= data
.GetText();
1237 wxLayoutImportText( m_llist
, text
);
1243 // if everything failed we can still try the primary:
1244 wxTheClipboard
->Close();
1245 if(! primary
) // not tried before
1247 wxTheClipboard
->UsePrimarySelection();
1248 if (wxTheClipboard
->Open())
1250 wxTextDataObject data
;
1251 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1252 && wxTheClipboard
->GetData(data
) )
1254 wxString text
= data
.GetText();
1255 wxLayoutImportText( m_llist
, text
);
1259 wxTheClipboard
->Close();
1265 wxLayoutWindow::Copy(bool invalidate
, bool privateFormat
, bool primary
)
1267 // Calling GetSelection() will automatically do an EndSelection()
1268 // on the list, but we need to take a note of it, too:
1271 m_Selecting
= false;
1272 m_llist
->EndSelection();
1275 wxLayoutDataObject
*wldo
= new wxLayoutDataObject
;
1276 wxLayoutList
*llist
= m_llist
->GetSelection(wldo
, invalidate
);
1279 // Export selection as text:
1281 wxLayoutExportObject
*exp
;
1282 wxLayoutExportStatus
status(llist
);
1283 while((exp
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1285 if(exp
->type
== WXLO_EXPORT_TEXT
)
1286 text
<< *(exp
->content
.text
);
1293 // The exporter always appends a newline, so we chop it off if it
1296 size_t len
= text
.Length();
1297 if(len
> 2 && text
[len
-2] == '\r') // Windows
1298 text
= text
.Mid(0,len
-2);
1299 else if(len
> 1 && text
[len
-1] == '\n')
1300 text
= text
.Mid(0,len
-1);
1304 if(! primary
) // always copy as text-only to primary selection
1306 wxTheClipboard
->UsePrimarySelection();
1307 if (wxTheClipboard
->Open())
1309 wxTextDataObject
*data
= new wxTextDataObject( text
);
1310 wxTheClipboard
->SetData( data
);
1311 wxTheClipboard
->Close();
1316 wxTheClipboard
->UsePrimarySelection(primary
);
1317 if (wxTheClipboard
->Open())
1319 wxTextDataObject
*data
= new wxTextDataObject( text
);
1320 bool rc
= wxTheClipboard
->SetData( data
);
1323 rc
|= wxTheClipboard
->SetData( wldo
);
1325 wxTheClipboard
->Close();
1337 wxLayoutWindow::Cut(bool privateFormat
, bool usePrimary
)
1339 if(Copy(false, privateFormat
, usePrimary
)) // do not invalidate selection after copy
1341 m_llist
->DeleteSelection();
1351 // ----------------------------------------------------------------------------
1353 // ----------------------------------------------------------------------------
1356 wxLayoutWindow::Find(
1358 const wxString
&needle
,
1359 wxPoint
* fromWhere
,
1360 const wxString
&configPath
1362 const wxString
& WXUNUSED(needle
),
1363 wxPoint
* WXUNUSED(fromWhere
),
1364 const wxString
& WXUNUSED(configPath
)
1371 if(needle
.Length() == 0)
1373 if( ! MInputBox(&m_FindString
,
1378 || strutil_isempty(m_FindString
))
1385 m_FindString
= needle
;
1388 if(fromWhere
== NULL
)
1389 found
= m_llist
->FindText(m_FindString
, m_llist
->GetCursorPos());
1391 found
= m_llist
->FindText(m_FindString
, *fromWhere
);
1401 m_llist
->MoveCursorTo(found
);
1414 wxLayoutWindow::FindAgain()
1416 bool rc
= Find(m_FindString
);
1420 // ----------------------------------------------------------------------------
1422 // ----------------------------------------------------------------------------
1425 wxLayoutWindow::MakeFormatMenu()
1427 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1429 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."));
1430 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."));
1431 m
->AppendSeparator();
1432 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), wxITEM_CHECK
);
1433 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), wxITEM_CHECK
);
1434 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), wxITEM_CHECK
);
1435 m
->AppendSeparator();
1436 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."));
1437 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."));
1438 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."));
1443 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1445 event
.Check(m_llist
->IsFontUnderlined());
1448 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1450 event
.Check(m_llist
->IsFontBold());
1453 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1455 event
.Check(m_llist
->IsFontItalic());
1458 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1460 switch (event
.GetId())
1462 case WXLOWIN_MENU_LARGER
:
1463 m_llist
->SetFontLarger(); RequestUpdate(); break;
1465 case WXLOWIN_MENU_SMALLER
:
1466 m_llist
->SetFontSmaller(); RequestUpdate(); break;
1468 case WXLOWIN_MENU_UNDERLINE
:
1469 m_llist
->ToggleFontUnderline(); RequestUpdate(); break;
1471 case WXLOWIN_MENU_BOLD
:
1472 m_llist
->ToggleFontWeight(); RequestUpdate(); break;
1474 case WXLOWIN_MENU_ITALICS
:
1475 m_llist
->ToggleFontItalics(); RequestUpdate(); break;
1477 case WXLOWIN_MENU_ROMAN
:
1478 m_llist
->SetFontFamily(wxROMAN
); RequestUpdate(); break;
1480 case WXLOWIN_MENU_TYPEWRITER
:
1481 m_llist
->SetFontFamily(wxFIXED
); RequestUpdate(); break;
1483 case WXLOWIN_MENU_SANSSERIF
:
1484 m_llist
->SetFontFamily(wxSWISS
); RequestUpdate(); break;
1488 // ----------------------------------------------------------------------------
1490 // ----------------------------------------------------------------------------
1493 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1497 RequestUpdate(); // cursor must change
1501 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1503 m_HaveFocus
= false;
1505 RequestUpdate();// cursor must change
1508 // ----------------------------------------------------------------------------
1509 // private functions
1510 // ----------------------------------------------------------------------------
1512 static bool IsDirectionKey(long keyCode
)