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 // ----------------------------------------------------------------------------
17 #include "wx/wxprec.h"
28 # include "gui/wxMenuDefs.h"
29 # include "gui/wxMApp.h"
31 # include "gui/wxlwindow.h"
32 # include "gui/wxlparser.h"
34 # include "MDialogs.h"
38 # include "wx/msw/private.h"
41 # include "wxlwindow.h"
42 # include "wxlparser.h"
45 #include "wx/clipbrd.h"
46 #include "wx/textctrl.h"
47 #include "wx/dataobj.h"
49 #ifdef WXLAYOUT_USE_CARET
50 # include "wx/caret.h"
51 #endif // WXLAYOUT_USE_CARET
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
61 # define WXLO_DEBUG(x) wxLogDebug x
63 # define WXLO_DEBUG(x)
66 // for profiling in debug mode:
67 WXLO_TIMER_DEFINE(UpdateTimer
);
68 WXLO_TIMER_DEFINE(BlitTimer
);
69 WXLO_TIMER_DEFINE(LayoutTimer
);
70 WXLO_TIMER_DEFINE(TmpTimer
);
71 WXLO_TIMER_DEFINE(DrawTimer
);
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 /// offsets to put a nice frame around text
78 #define WXLO_XOFFSET 4
79 #define WXLO_YOFFSET 4
81 /// offset to the right and bottom for when to redraw scrollbars
82 #define WXLO_ROFFSET 20
83 #define WXLO_BOFFSET 20
85 /// scroll margins when selecting with the mouse
86 #define WXLO_SCROLLMARGIN_X 10
87 #define WXLO_SCROLLMARGIN_Y 10
89 /// the size of one scrollbar page in pixels
90 static const int X_SCROLL_PAGE
= 10;
91 static const int Y_SCROLL_PAGE
= 20;
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
100 EVT_SIZE (wxLayoutWindow::OnSize
)
102 EVT_PAINT (wxLayoutWindow::OnPaint
)
104 EVT_CHAR (wxLayoutWindow::OnChar
)
105 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
107 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
108 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
109 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
110 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
111 EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown
)
112 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
114 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
115 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
116 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
117 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
119 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
120 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
122 // EVT_IDLE(wxLayoutWindow::ResizeScrollbars)
125 // ----------------------------------------------------------------------------
126 // function prototypes
127 // ----------------------------------------------------------------------------
129 /// returns true if keyCode is one of arrows/home/end/page{up|down} keys
130 static bool IsDirectionKey(long keyCode
);
132 // ============================================================================
134 // ============================================================================
136 #ifndef wxWANTS_CHARS
137 # define wxWANTS_CHARS 0
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
145 : wxScrolledWindow(parent
, wxID_ANY
,
146 wxDefaultPosition
, wxDefaultSize
,
147 wxHSCROLL
| wxVSCROLL
|
153 SetStatusBar(NULL
); // don't use statusbar
154 #endif // wxUSE_STATUSBAR
156 m_doSendEvents
= false;
157 m_ViewStartX
= 0; m_ViewStartY
= 0;
158 m_DoPopupMenu
= true;
159 m_PopupMenu
= MakeFormatMenu();
160 m_memDC
= new wxMemoryDC
;
161 m_bitmap
= new wxBitmap(4,4);
162 m_bitmapSize
= wxPoint(4,4);
163 m_llist
= new wxLayoutList();
165 m_ScrollToCursor
= false;
167 m_FocusFollowMode
= false;
172 // no scrollbars initially
174 m_hasVScrollbar
= false;
178 #ifdef WXLAYOUT_USE_CARET
179 // FIXME cursor size shouldn't be hardcoded
180 wxCaret
*caret
= new wxCaret(this, 2, 20);
182 m_llist
->SetCaret(caret
);
183 #endif // WXLAYOUT_USE_CARET
186 m_HandCursor
= false;
187 m_CursorVisibility
= -1;
188 SetCursor(wxCURSOR_IBEAM
);
191 // at least under Windows, this should be the default behaviour
192 m_AutoDeleteSelection
= true;
195 wxLayoutWindow::~wxLayoutWindow()
197 delete m_memDC
; // deletes bitmap automatically (?)
201 SetBackgroundBitmap(NULL
);
205 wxLayoutWindow::Clear(int family
,
213 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
214 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
215 //wxScrolledWindow::Clear();
216 ResizeScrollbars(true);
220 m_CursorVisibility
= 1;
222 #ifdef WXLAYOUT_USE_CARET
223 if ( m_CursorVisibility
== 1 )
225 #endif // WXLAYOUT_USE_CARET
227 RequestUpdate((wxRect
*)NULL
);
230 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
232 wxScrolledWindow::Refresh(eraseBackground
, rect
);
236 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
238 wxClientDC
dc( this );
240 if ( (eventId
!= WXLOWIN_MENU_MOUSEMOVE
245 && (wxWindow::FindFocus() != this) )
251 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
252 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
254 findPos
.x
-= WXLO_XOFFSET
;
255 findPos
.y
-= WXLO_YOFFSET
;
263 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
265 // Scroll the window if the mouse is at the end of it:
266 if(m_Selecting
&& eventId
== WXLOWIN_MENU_MOUSEMOVE
)
268 //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
270 GetViewStart(&left
, &top
);
271 wxSize size
= GetClientSize();
274 if(event
.GetX() < WXLO_SCROLLMARGIN_X
)
275 xdelta
= -(WXLO_SCROLLMARGIN_X
-event
.GetX());
276 else if(event
.GetX() > size
.x
-WXLO_SCROLLMARGIN_X
)
277 xdelta
= event
.GetX()-size
.x
+WXLO_SCROLLMARGIN_X
;
281 if(event
.GetY() < WXLO_SCROLLMARGIN_Y
)
282 ydelta
= -(WXLO_SCROLLMARGIN_Y
-event
.GetY());
283 else if(event
.GetY() > size
.y
-WXLO_SCROLLMARGIN_Y
)
284 ydelta
= event
.GetY()-size
.y
+WXLO_SCROLLMARGIN_Y
;
288 //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
289 if(xdelta
!= 0 || ydelta
!= 0)
291 top
+= ydelta
; if(top
< 0) top
= 0;
292 left
+= xdelta
; if(left
< 0) left
= 0;
299 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
301 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
303 // has the mouse only been moved?
306 case WXLOWIN_MENU_MOUSEMOVE
:
308 // this variables is used to only erase the message in the status
309 // bar if we had put it there previously - otherwise empting status
310 // bar might be undesirable
312 static bool s_hasPutMessageInStatusBar
= false;
313 #endif // wxUSE_STATUSBAR
315 // found is only true if we are really over an object, not just
317 if(found
&& u
&& ! m_Selecting
)
320 SetCursor(wxCURSOR_HAND
);
323 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
325 const wxString
&label
= u
->GetLabel();
328 m_StatusBar
->SetStatusText(label
,m_StatusFieldLabel
);
329 s_hasPutMessageInStatusBar
= true;
332 #endif // wxUSE_STATUSBAR
337 SetCursor(wxCURSOR_IBEAM
);
338 m_HandCursor
= false;
340 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
341 s_hasPutMessageInStatusBar
)
343 m_StatusBar
->SetStatusText(wxEmptyString
, m_StatusFieldLabel
);
345 #endif // wxUSE_STATUSBAR
350 if ( event
.LeftIsDown() )
352 // m_Selecting might not be set if the button got pressed
353 // outside this window, so check for it:
356 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
357 RequestUpdate(); // TODO: we don't have to redraw everything!
368 case WXLOWIN_MENU_LDOWN
:
370 // always move cursor to mouse click:
371 m_llist
->MoveCursorTo(cursorPos
);
373 // clicking a mouse removes the selection
374 if ( m_llist
->HasSelection() )
376 m_llist
->DiscardSelection();
378 RequestUpdate(); // TODO: we don't have to redraw everything!
381 // Calculate where the top of the visible area is:
383 GetViewStart(&x0
,&y0
);
385 GetScrollPixelsPerUnit(&dx
, &dy
);
388 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
390 if(m_CursorVisibility
== -1)
391 m_CursorVisibility
= 1;
393 #ifdef WXLAYOUT_USE_CARET
394 if ( m_CursorVisibility
== 1 )
396 #endif // WXLAYOUT_USE_CARET
398 if(m_CursorVisibility
)
400 // draw a thick cursor for editable windows with focus
401 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
405 RequestUpdate(); // RequestUpdate suppresses flicker under GTK
409 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
414 case WXLOWIN_MENU_LUP
:
417 // end selection at the cursor position corresponding to the
418 // current mouse position, but don´t move cursor there.
419 m_llist
->EndSelection(cursorPos
,m_ClickPosition
);
422 RequestUpdate(); // TODO: we don't have to redraw everything!
426 case WXLOWIN_MENU_MDOWN
:
430 case WXLOWIN_MENU_DBLCLICK
:
431 // select a word under cursor
432 m_llist
->MoveCursorTo(cursorPos
);
433 m_llist
->MoveCursorWord(-1);
434 m_llist
->StartSelection();
435 m_llist
->MoveCursorWord(1, false);
436 m_llist
->EndSelection();
438 RequestUpdate(); // TODO: we don't have to redraw everything!
442 // notify about mouse events?
445 // only do the menu if activated, editable and not on a clickable object
446 if(eventId
== WXLOWIN_MENU_RCLICK
448 && (! obj
|| u
== NULL
))
450 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
455 // find the object at this position
458 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
459 commandEvent
.SetEventObject( this );
460 commandEvent
.SetClientData((char *)obj
);
461 GetEventHandler()->ProcessEvent(commandEvent
);
468 // ----------------------------------------------------------------------------
469 // keyboard handling.
470 // ----------------------------------------------------------------------------
473 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
475 int keyCode
= event
.GetKeyCode();
476 bool ctrlDown
= event
.ControlDown();
478 #ifdef WXLAYOUT_DEBUG
479 if(keyCode
== WXK_F1
)
486 // Force m_Selecting to be false if shift is no longer
487 // pressed. OnKeyUp() cannot catch all Shift-Up events.
488 if(m_Selecting
&& !event
.ShiftDown())
491 m_llist
->EndSelection();
492 m_llist
->DiscardSelection(); //FIXME: correct?
495 // If we deleted the selection here, we must not execute the
496 // deletion in Delete/Backspace handling.
497 bool deletedSelection
= false;
498 // pressing any non-arrow key optionally replaces the selection:
499 if(m_AutoDeleteSelection
502 && m_llist
->HasSelection()
503 && ! IsDirectionKey(keyCode
)
504 && ! (event
.AltDown() || ctrlDown
) )
506 m_llist
->DeleteSelection();
507 deletedSelection
= true;
511 // <Shift>+<arrow> starts selection
512 if ( IsDirectionKey(keyCode
) )
514 // just continue the old selection
515 if ( m_Selecting
&& event
.ShiftDown() )
517 m_llist
->ContinueSelection();
521 m_llist
->DiscardSelection();
523 if( event
.ShiftDown() )
526 m_llist
->StartSelection();
531 // If needed, make cursor visible:
532 if(m_CursorVisibility
== -1)
533 m_CursorVisibility
= 1;
535 /* These two nested switches work like this:
536 The first one processes all non-editing keycodes, to move the
537 cursor, etc. It's default will process all keycodes causing
538 modifications to the buffer, but only if editing is allowed.
545 m_llist
->MoveCursorWord(1);
547 m_llist
->MoveCursorHorizontally(1);
552 m_llist
->MoveCursorWord(-1);
554 m_llist
->MoveCursorHorizontally(-1);
559 m_llist
->MoveCursorVertically(-1);
563 m_llist
->MoveCursorVertically(1);
567 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
571 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
576 m_llist
->MoveCursorTo(wxPoint(0, 0));
578 m_llist
->MoveCursorToBeginOfLine();
583 m_llist
->MoveCursorToEnd();
585 m_llist
->MoveCursorToEndOfLine();
590 if(ctrlDown
&& ! IsEditable())
596 // this should work even in read-only mode
604 case 't': // search again
609 // we don't handle it, maybe an accelerator?
614 else if( IsEditable() )
616 /* First, handle control keys */
617 if(ctrlDown
&& ! event
.AltDown())
619 if(keyCode
>= 'A' && keyCode
<= 'Z')
620 keyCode
= tolower(keyCode
);
630 if(! deletedSelection
)
632 m_llist
->DeleteWord();
638 if(! deletedSelection
) // already done
646 m_llist
->DeleteLines(1);
650 case 'h': // like backspace
651 if(m_llist
->MoveCursorHorizontally(-1))
662 case 't': // search again
667 m_llist
->DeleteToBeginOfLine();
672 m_llist
->DeleteToEndOfLine();
690 m_llist
->WrapLine(m_WrapMargin
);
695 m_llist
->WrapAll(m_WrapMargin
);
698 #ifdef WXLAYOUT_DEBUG
700 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
709 // we don't handle it, maybe an accelerator?
714 else if( event
.AltDown() && ! event
.ControlDown() )
720 m_llist
->DeleteWord();
725 // we don't handle it, maybe an accelerator?
730 else if ( ! event
.AltDown() && ! event
.ControlDown())
735 if(event
.ShiftDown())
740 if(event
.ShiftDown())
744 else if(! deletedSelection
)
751 case WXK_BACK
: // backspace
752 if(! deletedSelection
)
754 if(m_llist
->MoveCursorHorizontally(-1))
765 && m_llist
->GetCursorPos().x
> m_WrapMargin
)
767 m_llist
->WrapLine(m_WrapMargin
);
770 m_llist
->LineBreak();
775 if ( !event
.ShiftDown() )
777 // TODO should be configurable
778 static const int tabSize
= 8;
780 CoordType x
= m_llist
->GetCursorPos().x
;
781 size_t numSpaces
= tabSize
- x
% tabSize
;
782 m_llist
->Insert(wxString(' ', numSpaces
));
788 if ( ( !(event
.ControlDown() || event
.AltDown()) )
789 && (keyCode
< 256 && keyCode
>= 32) )
793 && m_llist
->GetCursorPos().x
> m_WrapMargin
794 && isspace(keyCode
) )
796 m_llist
->WrapLine(m_WrapMargin
);
799 m_llist
->Insert((wxChar
)keyCode
);
804 // we don't handle it, maybe an accelerator?
814 // we don't handle it, maybe an accelerator?
821 // continue selection to the current (new) cursor position
822 m_llist
->ContinueSelection();
826 // refresh the screen
827 RequestUpdate(m_llist
->GetUpdateRect());
831 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
833 if ( event
.GetKeyCode() == WXK_SHIFT
&& m_Selecting
)
835 m_llist
->EndSelection();
844 wxLayoutWindow::ScrollToCursor()
846 //is always needed to make sure we know where the cursor is
848 //RequestUpdate(m_llist->GetUpdateRect());
853 int x0
,y0
,x1
,y1
, dx
, dy
;
855 // Calculate where the top of the visible area is:
856 GetViewStart(&x0
,&y0
);
857 GetScrollPixelsPerUnit(&dx
, &dy
);
860 WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0
, y0
));
862 // Get the size of the visible window:
863 GetClientSize(&x1
, &y1
);
865 // Make sure that the scrollbars are at a position so that the cursor is
866 // visible if we are editing
867 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
868 wxPoint cc
= m_llist
->GetCursorScreenPos();
870 // the cursor should be completely visible in both directions
871 wxPoint
cs(m_llist
->GetCursorSize());
875 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
882 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
889 if( nx
!= -1 || ny
!= -1 )
891 // set new view start
892 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
894 m_ScrollToCursor
= false;
900 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
902 wxRect region
= GetUpdateRegion().GetBox();
903 InternalPaint(®ion
);
907 wxLayoutWindow::RequestUpdate(const wxRect
*
916 // Calling Refresh() causes bad flicker under wxGTK!!!
917 InternalPaint(updateRect
);
919 // shouldn't specify the update rectangle if it doesn't include all the
920 // changed locations - otherwise, they won't be repainted at all because
921 // the system clips the display to the update rect
922 Refresh(false); //, updateRect);
927 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
930 wxPaintDC
dc( this );
933 #ifdef WXLAYOUT_USE_CARET
934 // hide the caret before drawing anything
936 #endif // WXLAYOUT_USE_CARET
938 int x0
,y0
,x1
,y1
, dx
, dy
;
940 // Calculate where the top of the visible area is:
941 GetViewStart(&x0
,&y0
);
942 GetScrollPixelsPerUnit(&dx
, &dy
);
945 // Get the size of the visible window:
946 GetClientSize(&x1
,&y1
);
952 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
953 updateRect
->x
, updateRect
->y
,
954 updateRect
->x
+updateRect
->width
,
955 updateRect
->y
+updateRect
->height
));
958 ResizeScrollbars(true);
960 WXLO_TIMER_START(TmpTimer
);
961 /* Check whether the window has grown, if so, we need to reallocate
962 the bitmap to be larger. */
963 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
965 wxASSERT(m_bitmapSize
.x
> 0);
966 wxASSERT(m_bitmapSize
.y
> 0);
968 m_memDC
->SelectObject(wxNullBitmap
);
970 m_bitmapSize
= wxPoint(x1
,y1
);
971 m_bitmap
= new wxBitmap(x1
,y1
);
972 m_memDC
->SelectObject(*m_bitmap
);
975 m_memDC
->SetDeviceOrigin(0,0);
976 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
977 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
979 m_memDC
->SetLogicalFunction(wxCOPY
);
981 WXLO_TIMER_STOP(TmpTimer
);
983 // fill the background with the background bitmap
988 w
= m_BGbitmap
->GetWidth(),
989 h
= m_BGbitmap
->GetHeight();
990 for(y
= 0; y
< y1
; y
+=h
)
992 for(x
= 0; x
< x1
; x
+=w
)
994 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
998 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
1001 // This is the important bit: we tell the list to draw itself
1002 #if WXLO_DEBUG_URECT
1005 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
1006 updateRect
->x
, updateRect
->y
,
1007 updateRect
->x
+updateRect
->width
,
1008 updateRect
->y
+updateRect
->height
));
1012 // Device origins on the memDC are suspect, we translate manually
1013 // with the translate parameter of Draw().
1014 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
1015 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
1017 // We start calculating a new update rect before drawing the
1018 // cursor, so that the cursor coordinates get included in the next
1019 // update rectangle (although they are drawn on the memDC, this is
1020 // needed to erase it):
1021 m_llist
->InvalidateUpdateRect();
1022 if(m_CursorVisibility
== 1)
1024 // draw a thick cursor for editable windows with focus
1025 m_llist
->DrawCursor(*m_memDC
,
1026 m_HaveFocus
&& IsEditable(),
1030 WXLO_TIMER_START(BlitTimer
);
1031 // Now copy everything to the screen:
1033 // This somehow doesn't work, but even the following bit with the
1034 // whole rect at once is still a bit broken I think.
1035 wxRegionIterator
ri ( GetUpdateRegion() );
1039 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
1040 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
1042 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
1043 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,false);
1049 // FIXME: Trying to copy only the changed parts, but it does not seem
1051 // x0 = updateRect->x; y0 = updateRect->y;
1052 // if(updateRect->height < y1)
1053 // y1 = updateRect->height;
1054 // y1 += WXLO_YOFFSET; //FIXME might not be needed
1055 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,false);
1058 WXLO_TIMER_STOP(BlitTimer
);
1061 #ifdef WXLAYOUT_USE_CARET
1062 // show the caret back after everything is redrawn
1064 #endif // WXLAYOUT_USE_CARET
1069 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
1071 static wxPoint
s_oldCursorPos(-1, -1);
1073 wxPoint
pos(m_llist
->GetCursorPos());
1075 // avoid unnecessary status bar refreshes
1076 if ( pos
!= s_oldCursorPos
)
1078 s_oldCursorPos
= pos
;
1081 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
1082 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
1085 #endif // wxUSE_STATUSBAR
1087 WXLO_TIMER_PRINT(LayoutTimer
);
1088 WXLO_TIMER_PRINT(BlitTimer
);
1089 WXLO_TIMER_PRINT(TmpTimer
);
1093 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
1102 Change the range and position of scrollbars. Has evolved into a
1103 generic Update function which will at some time later cause a repaint
1108 wxLayoutWindow::ResizeScrollbars(bool exact
)
1110 wxClientDC
dc( this );
1112 // m_llist->ForceTotalLayout();
1116 // we are laying out just the minimum, but always up to the
1117 // cursor line, so the cursor position is updated.
1118 m_llist
->Layout(dc
, 0);
1122 WXLO_TIMER_START(LayoutTimer
);
1123 m_llist
->Layout(dc
, -1);
1124 WXLO_TIMER_STOP(LayoutTimer
);
1127 wxPoint max
= m_llist
->GetSize();
1128 wxSize size
= GetClientSize();
1130 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
1131 (long int)max
.x
, (long int) max
.y
));
1133 // in the absence of scrollbars we should compare with the client size
1134 if ( !m_hasHScrollbar
)
1135 m_maxx
= size
.x
;// - WXLO_ROFFSET;
1137 if ( !m_hasVScrollbar
)
1138 m_maxy
= size
.y
;// - WXLO_BOFFSET;
1140 // check if the text hasn't become too big
1141 // TODO why do we set both at once? they're independent...
1142 if( max
.x
> m_maxx
- WXLO_ROFFSET
1143 || max
.y
> m_maxy
- WXLO_BOFFSET
1144 || (max
.x
< m_maxx
- X_SCROLL_PAGE
)
1145 || (max
.y
< m_maxy
- Y_SCROLL_PAGE
)
1148 // text became too large
1151 // add an extra bit to the sizes to avoid future updates
1152 max
.x
+= WXLO_ROFFSET
;
1153 max
.y
+= WXLO_BOFFSET
;
1158 if(max
.x
< X_SCROLL_PAGE
&& m_hasHScrollbar
)
1160 SetScrollbars(0,-1,0,-1,0,-1,true);
1161 m_hasHScrollbar
= false;
1165 if(max
.y
< Y_SCROLL_PAGE
&& m_hasVScrollbar
)
1167 SetScrollbars(-1,0,-1,0,-1,0,true);
1168 m_hasVScrollbar
= false;
1173 // (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE)
1174 (max
.x
> size
.x
- X_SCROLL_PAGE
|| max
.y
> size
.y
- Y_SCROLL_PAGE
) )
1176 GetViewStart(&m_ViewStartX
, &m_ViewStartY
);
1178 SetScrollbars(X_SCROLL_PAGE
,
1180 max
.x
/ X_SCROLL_PAGE
+ 2,
1181 max
.y
/ Y_SCROLL_PAGE
+ 2,
1187 m_hasVScrollbar
= true;
1188 // ScrollToCursor();
1191 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
1192 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
1196 // ----------------------------------------------------------------------------
1198 // clipboard operations
1200 // ----------------------------------------------------------------------------
1203 wxLayoutWindow::Paste(bool usePrivate
, bool primary
)
1205 // this only has an effect under X11:
1206 wxTheClipboard
->UsePrimarySelection(primary
);
1208 if (wxTheClipboard
->Open())
1212 wxLayoutDataObject wxldo
;
1213 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1215 if(wxTheClipboard
->GetData(wxldo
))
1217 wxTheClipboard
->Close();
1218 wxString str
= wxldo
.GetLayoutData();
1227 wxTextDataObject data
;
1228 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1229 && wxTheClipboard
->GetData(data
) )
1231 wxTheClipboard
->Close();
1232 wxString text
= data
.GetText();
1233 wxLayoutImportText( m_llist
, text
);
1239 // if everything failed we can still try the primary:
1240 wxTheClipboard
->Close();
1241 if(! primary
) // not tried before
1243 wxTheClipboard
->UsePrimarySelection();
1244 if (wxTheClipboard
->Open())
1246 wxTextDataObject data
;
1247 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1248 && wxTheClipboard
->GetData(data
) )
1250 wxString text
= data
.GetText();
1251 wxLayoutImportText( m_llist
, text
);
1255 wxTheClipboard
->Close();
1261 wxLayoutWindow::Copy(bool invalidate
, bool privateFormat
, bool primary
)
1263 // Calling GetSelection() will automatically do an EndSelection()
1264 // on the list, but we need to take a note of it, too:
1267 m_Selecting
= false;
1268 m_llist
->EndSelection();
1271 wxLayoutDataObject
*wldo
= new wxLayoutDataObject
;
1272 wxLayoutList
*llist
= m_llist
->GetSelection(wldo
, invalidate
);
1275 // Export selection as text:
1277 wxLayoutExportObject
*exp
;
1278 wxLayoutExportStatus
status(llist
);
1279 while((exp
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1281 if(exp
->type
== WXLO_EXPORT_TEXT
)
1282 text
<< *(exp
->content
.text
);
1289 // The exporter always appends a newline, so we chop it off if it
1292 size_t len
= text
.Length();
1293 if(len
> 2 && text
[len
-2] == '\r') // Windows
1294 text
= text
.Mid(0,len
-2);
1295 else if(len
> 1 && text
[len
-1] == '\n')
1296 text
= text
.Mid(0,len
-1);
1300 if(! primary
) // always copy as text-only to primary selection
1302 wxTheClipboard
->UsePrimarySelection();
1303 if (wxTheClipboard
->Open())
1305 wxTextDataObject
*data
= new wxTextDataObject( text
);
1306 wxTheClipboard
->SetData( data
);
1307 wxTheClipboard
->Close();
1312 wxTheClipboard
->UsePrimarySelection(primary
);
1313 if (wxTheClipboard
->Open())
1315 wxTextDataObject
*data
= new wxTextDataObject( text
);
1316 bool rc
= wxTheClipboard
->SetData( data
);
1319 rc
|= wxTheClipboard
->SetData( wldo
);
1321 wxTheClipboard
->Close();
1333 wxLayoutWindow::Cut(bool privateFormat
, bool usePrimary
)
1335 if(Copy(false, privateFormat
, usePrimary
)) // do not invalidate selection after copy
1337 m_llist
->DeleteSelection();
1347 // ----------------------------------------------------------------------------
1349 // ----------------------------------------------------------------------------
1352 wxLayoutWindow::Find(
1354 const wxString
&needle
,
1355 wxPoint
* fromWhere
,
1356 const wxString
&configPath
1358 const wxString
& WXUNUSED(needle
),
1359 wxPoint
* WXUNUSED(fromWhere
),
1360 const wxString
& WXUNUSED(configPath
)
1367 if(needle
.Length() == 0)
1369 if( ! MInputBox(&m_FindString
,
1374 || strutil_isempty(m_FindString
))
1381 m_FindString
= needle
;
1384 if(fromWhere
== NULL
)
1385 found
= m_llist
->FindText(m_FindString
, m_llist
->GetCursorPos());
1387 found
= m_llist
->FindText(m_FindString
, *fromWhere
);
1397 m_llist
->MoveCursorTo(found
);
1410 wxLayoutWindow::FindAgain()
1412 bool rc
= Find(m_FindString
);
1416 // ----------------------------------------------------------------------------
1418 // ----------------------------------------------------------------------------
1421 wxLayoutWindow::MakeFormatMenu()
1423 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1425 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."));
1426 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."));
1427 m
->AppendSeparator();
1428 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), wxITEM_CHECK
);
1429 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), wxITEM_CHECK
);
1430 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), wxITEM_CHECK
);
1431 m
->AppendSeparator();
1432 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."));
1433 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."));
1434 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."));
1439 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1441 event
.Check(m_llist
->IsFontUnderlined());
1444 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1446 event
.Check(m_llist
->IsFontBold());
1449 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1451 event
.Check(m_llist
->IsFontItalic());
1454 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1456 switch (event
.GetId())
1458 case WXLOWIN_MENU_LARGER
:
1459 m_llist
->SetFontLarger(); RequestUpdate(); break;
1461 case WXLOWIN_MENU_SMALLER
:
1462 m_llist
->SetFontSmaller(); RequestUpdate(); break;
1464 case WXLOWIN_MENU_UNDERLINE
:
1465 m_llist
->ToggleFontUnderline(); RequestUpdate(); break;
1467 case WXLOWIN_MENU_BOLD
:
1468 m_llist
->ToggleFontWeight(); RequestUpdate(); break;
1470 case WXLOWIN_MENU_ITALICS
:
1471 m_llist
->ToggleFontItalics(); RequestUpdate(); break;
1473 case WXLOWIN_MENU_ROMAN
:
1474 m_llist
->SetFontFamily(wxROMAN
); RequestUpdate(); break;
1476 case WXLOWIN_MENU_TYPEWRITER
:
1477 m_llist
->SetFontFamily(wxFIXED
); RequestUpdate(); break;
1479 case WXLOWIN_MENU_SANSSERIF
:
1480 m_llist
->SetFontFamily(wxSWISS
); RequestUpdate(); break;
1484 // ----------------------------------------------------------------------------
1486 // ----------------------------------------------------------------------------
1489 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1493 RequestUpdate(); // cursor must change
1497 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1499 m_HaveFocus
= false;
1501 RequestUpdate();// cursor must change
1504 // ----------------------------------------------------------------------------
1505 // private functions
1506 // ----------------------------------------------------------------------------
1508 static bool IsDirectionKey(long keyCode
)