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
, -1,
150 wxDefaultPosition
, wxDefaultSize
,
151 wxHSCROLL
| wxVSCROLL
|
156 SetStatusBar(NULL
); // don't use statusbar
158 m_doSendEvents
= false;
159 m_ViewStartX
= 0; m_ViewStartY
= 0;
160 m_DoPopupMenu
= true;
161 m_PopupMenu
= MakeFormatMenu();
162 m_memDC
= new wxMemoryDC
;
163 m_bitmap
= new wxBitmap(4,4);
164 m_bitmapSize
= wxPoint(4,4);
165 m_llist
= new wxLayoutList();
167 m_ScrollToCursor
= false;
169 m_FocusFollowMode
= false;
174 // no scrollbars initially
176 m_hasVScrollbar
= false;
180 #ifdef WXLAYOUT_USE_CARET
181 // FIXME cursor size shouldn't be hardcoded
182 wxCaret
*caret
= new wxCaret(this, 2, 20);
184 m_llist
->SetCaret(caret
);
185 #endif // WXLAYOUT_USE_CARET
188 m_HandCursor
= false;
189 m_CursorVisibility
= -1;
190 SetCursor(wxCURSOR_IBEAM
);
193 // at least under Windows, this should be the default behaviour
194 m_AutoDeleteSelection
= true;
197 wxLayoutWindow::~wxLayoutWindow()
199 delete m_memDC
; // deletes bitmap automatically (?)
203 SetBackgroundBitmap(NULL
);
207 wxLayoutWindow::Clear(int family
,
215 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
216 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
217 //wxScrolledWindow::Clear();
218 ResizeScrollbars(true);
222 m_CursorVisibility
= 1;
224 #ifdef WXLAYOUT_USE_CARET
225 if ( m_CursorVisibility
== 1 )
227 #endif // WXLAYOUT_USE_CARET
229 RequestUpdate((wxRect
*)NULL
);
232 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
234 wxScrolledWindow::Refresh(eraseBackground
, rect
);
238 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
240 wxClientDC
dc( this );
242 if ( (eventId
!= WXLOWIN_MENU_MOUSEMOVE
247 && (wxWindow::FindFocus() != this) )
253 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
254 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
256 findPos
.x
-= WXLO_XOFFSET
;
257 findPos
.y
-= WXLO_YOFFSET
;
265 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
267 // Scroll the window if the mouse is at the end of it:
268 if(m_Selecting
&& eventId
== WXLOWIN_MENU_MOUSEMOVE
)
270 //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
272 GetViewStart(&left
, &top
);
273 wxSize size
= GetClientSize();
276 if(event
.GetX() < WXLO_SCROLLMARGIN_X
)
277 xdelta
= -(WXLO_SCROLLMARGIN_X
-event
.GetX());
278 else if(event
.GetX() > size
.x
-WXLO_SCROLLMARGIN_X
)
279 xdelta
= event
.GetX()-size
.x
+WXLO_SCROLLMARGIN_X
;
283 if(event
.GetY() < WXLO_SCROLLMARGIN_Y
)
284 ydelta
= -(WXLO_SCROLLMARGIN_Y
-event
.GetY());
285 else if(event
.GetY() > size
.y
-WXLO_SCROLLMARGIN_Y
)
286 ydelta
= event
.GetY()-size
.y
+WXLO_SCROLLMARGIN_Y
;
290 //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
291 if(xdelta
!= 0 || ydelta
!= 0)
293 top
+= ydelta
; if(top
< 0) top
= 0;
294 left
+= xdelta
; if(left
< 0) left
= 0;
301 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
303 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
305 // has the mouse only been moved?
308 case WXLOWIN_MENU_MOUSEMOVE
:
310 // this variables is used to only erase the message in the status
311 // bar if we had put it there previously - otherwise empting status
312 // bar might be undesirable
313 static bool s_hasPutMessageInStatusBar
= false;
315 // found is only true if we are really over an object, not just
317 if(found
&& u
&& ! m_Selecting
)
320 SetCursor(wxCURSOR_HAND
);
322 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
324 const wxString
&label
= u
->GetLabel();
327 m_StatusBar
->SetStatusText(label
,
329 s_hasPutMessageInStatusBar
= true;
336 SetCursor(wxCURSOR_IBEAM
);
337 m_HandCursor
= false;
338 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
339 s_hasPutMessageInStatusBar
)
341 m_StatusBar
->SetStatusText(wxEmptyString
, m_StatusFieldLabel
);
347 if ( event
.LeftIsDown() )
349 // m_Selecting might not be set if the button got pressed
350 // outside this window, so check for it:
353 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
354 RequestUpdate(); // TODO: we don't have to redraw everything!
365 case WXLOWIN_MENU_LDOWN
:
367 // always move cursor to mouse click:
368 m_llist
->MoveCursorTo(cursorPos
);
370 // clicking a mouse removes the selection
371 if ( m_llist
->HasSelection() )
373 m_llist
->DiscardSelection();
375 RequestUpdate(); // TODO: we don't have to redraw everything!
378 // Calculate where the top of the visible area is:
380 GetViewStart(&x0
,&y0
);
382 GetScrollPixelsPerUnit(&dx
, &dy
);
385 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
387 if(m_CursorVisibility
== -1)
388 m_CursorVisibility
= 1;
390 #ifdef WXLAYOUT_USE_CARET
391 if ( m_CursorVisibility
== 1 )
393 #endif // WXLAYOUT_USE_CARET
395 if(m_CursorVisibility
)
397 // draw a thick cursor for editable windows with focus
398 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
402 RequestUpdate(); // RequestUpdate suppresses flicker under GTK
406 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
411 case WXLOWIN_MENU_LUP
:
414 // end selection at the cursor position corresponding to the
415 // current mouse position, but don´t move cursor there.
416 m_llist
->EndSelection(cursorPos
,m_ClickPosition
);
419 RequestUpdate(); // TODO: we don't have to redraw everything!
423 case WXLOWIN_MENU_MDOWN
:
427 case WXLOWIN_MENU_DBLCLICK
:
428 // select a word under cursor
429 m_llist
->MoveCursorTo(cursorPos
);
430 m_llist
->MoveCursorWord(-1);
431 m_llist
->StartSelection();
432 m_llist
->MoveCursorWord(1, false);
433 m_llist
->EndSelection();
435 RequestUpdate(); // TODO: we don't have to redraw everything!
439 // notify about mouse events?
442 // only do the menu if activated, editable and not on a clickable object
443 if(eventId
== WXLOWIN_MENU_RCLICK
445 && (! obj
|| u
== NULL
))
447 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
452 // find the object at this position
455 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
456 commandEvent
.SetEventObject( this );
457 commandEvent
.SetClientData((char *)obj
);
458 GetEventHandler()->ProcessEvent(commandEvent
);
465 // ----------------------------------------------------------------------------
466 // keyboard handling.
467 // ----------------------------------------------------------------------------
470 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
472 int keyCode
= event
.GetKeyCode();
473 bool ctrlDown
= event
.ControlDown();
475 #ifdef WXLAYOUT_DEBUG
476 if(keyCode
== WXK_F1
)
483 // Force m_Selecting to be false if shift is no longer
484 // pressed. OnKeyUp() cannot catch all Shift-Up events.
485 if(m_Selecting
&& !event
.ShiftDown())
488 m_llist
->EndSelection();
489 m_llist
->DiscardSelection(); //FIXME: correct?
492 // If we deleted the selection here, we must not execute the
493 // deletion in Delete/Backspace handling.
494 bool deletedSelection
= false;
495 // pressing any non-arrow key optionally replaces the selection:
496 if(m_AutoDeleteSelection
499 && m_llist
->HasSelection()
500 && ! IsDirectionKey(keyCode
)
501 && ! (event
.AltDown() || ctrlDown
) )
503 m_llist
->DeleteSelection();
504 deletedSelection
= true;
508 // <Shift>+<arrow> starts selection
509 if ( IsDirectionKey(keyCode
) )
511 // just continue the old selection
512 if ( m_Selecting
&& event
.ShiftDown() )
514 m_llist
->ContinueSelection();
518 m_llist
->DiscardSelection();
520 if( event
.ShiftDown() )
523 m_llist
->StartSelection();
528 // If needed, make cursor visible:
529 if(m_CursorVisibility
== -1)
530 m_CursorVisibility
= 1;
532 /* These two nested switches work like this:
533 The first one processes all non-editing keycodes, to move the
534 cursor, etc. It's default will process all keycodes causing
535 modifications to the buffer, but only if editing is allowed.
542 m_llist
->MoveCursorWord(1);
544 m_llist
->MoveCursorHorizontally(1);
549 m_llist
->MoveCursorWord(-1);
551 m_llist
->MoveCursorHorizontally(-1);
556 m_llist
->MoveCursorVertically(-1);
560 m_llist
->MoveCursorVertically(1);
564 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
568 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
573 m_llist
->MoveCursorTo(wxPoint(0, 0));
575 m_llist
->MoveCursorToBeginOfLine();
580 m_llist
->MoveCursorToEnd();
582 m_llist
->MoveCursorToEndOfLine();
587 if(ctrlDown
&& ! IsEditable())
593 // this should work even in read-only mode
601 case 't': // search again
606 // we don't handle it, maybe an accelerator?
611 else if( IsEditable() )
613 /* First, handle control keys */
614 if(ctrlDown
&& ! event
.AltDown())
616 if(keyCode
>= 'A' && keyCode
<= 'Z')
617 keyCode
= tolower(keyCode
);
627 if(! deletedSelection
)
629 m_llist
->DeleteWord();
635 if(! deletedSelection
) // already done
643 m_llist
->DeleteLines(1);
647 case 'h': // like backspace
648 if(m_llist
->MoveCursorHorizontally(-1))
659 case 't': // search again
664 m_llist
->DeleteToBeginOfLine();
669 m_llist
->DeleteToEndOfLine();
687 m_llist
->WrapLine(m_WrapMargin
);
692 m_llist
->WrapAll(m_WrapMargin
);
695 #ifdef WXLAYOUT_DEBUG
697 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
706 // we don't handle it, maybe an accelerator?
711 else if( event
.AltDown() && ! event
.ControlDown() )
717 m_llist
->DeleteWord();
722 // we don't handle it, maybe an accelerator?
727 else if ( ! event
.AltDown() && ! event
.ControlDown())
732 if(event
.ShiftDown())
737 if(event
.ShiftDown())
741 else if(! deletedSelection
)
748 case WXK_BACK
: // backspace
749 if(! deletedSelection
)
751 if(m_llist
->MoveCursorHorizontally(-1))
762 && m_llist
->GetCursorPos().x
> m_WrapMargin
)
764 m_llist
->WrapLine(m_WrapMargin
);
767 m_llist
->LineBreak();
772 if ( !event
.ShiftDown() )
774 // TODO should be configurable
775 static const int tabSize
= 8;
777 CoordType x
= m_llist
->GetCursorPos().x
;
778 size_t numSpaces
= tabSize
- x
% tabSize
;
779 m_llist
->Insert(wxString(' ', numSpaces
));
785 if ( ( !(event
.ControlDown() || event
.AltDown()) )
786 && (keyCode
< 256 && keyCode
>= 32) )
790 && m_llist
->GetCursorPos().x
> m_WrapMargin
791 && isspace(keyCode
) )
793 m_llist
->WrapLine(m_WrapMargin
);
796 m_llist
->Insert((wxChar
)keyCode
);
801 // we don't handle it, maybe an accelerator?
811 // we don't handle it, maybe an accelerator?
818 // continue selection to the current (new) cursor position
819 m_llist
->ContinueSelection();
823 // refresh the screen
824 RequestUpdate(m_llist
->GetUpdateRect());
828 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
830 if ( event
.GetKeyCode() == WXK_SHIFT
&& m_Selecting
)
832 m_llist
->EndSelection();
841 wxLayoutWindow::ScrollToCursor()
843 //is always needed to make sure we know where the cursor is
845 //RequestUpdate(m_llist->GetUpdateRect());
850 int x0
,y0
,x1
,y1
, dx
, dy
;
852 // Calculate where the top of the visible area is:
853 GetViewStart(&x0
,&y0
);
854 GetScrollPixelsPerUnit(&dx
, &dy
);
857 WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0
, y0
));
859 // Get the size of the visible window:
860 GetClientSize(&x1
, &y1
);
862 // Make sure that the scrollbars are at a position so that the cursor is
863 // visible if we are editing
864 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
865 wxPoint cc
= m_llist
->GetCursorScreenPos();
867 // the cursor should be completely visible in both directions
868 wxPoint
cs(m_llist
->GetCursorSize());
872 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
879 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
886 if( nx
!= -1 || ny
!= -1 )
888 // set new view start
889 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
891 m_ScrollToCursor
= false;
897 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
899 wxRect region
= GetUpdateRegion().GetBox();
900 InternalPaint(®ion
);
904 wxLayoutWindow::RequestUpdate(const wxRect
*
913 // Calling Refresh() causes bad flicker under wxGTK!!!
914 InternalPaint(updateRect
);
916 // shouldn't specify the update rectangle if it doesn't include all the
917 // changed locations - otherwise, they won't be repainted at all because
918 // the system clips the display to the update rect
919 Refresh(false); //, updateRect);
924 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
927 wxPaintDC
dc( this );
930 #ifdef WXLAYOUT_USE_CARET
931 // hide the caret before drawing anything
933 #endif // WXLAYOUT_USE_CARET
935 int x0
,y0
,x1
,y1
, dx
, dy
;
937 // Calculate where the top of the visible area is:
938 GetViewStart(&x0
,&y0
);
939 GetScrollPixelsPerUnit(&dx
, &dy
);
942 // Get the size of the visible window:
943 GetClientSize(&x1
,&y1
);
949 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
950 updateRect
->x
, updateRect
->y
,
951 updateRect
->x
+updateRect
->width
,
952 updateRect
->y
+updateRect
->height
));
955 ResizeScrollbars(true);
957 WXLO_TIMER_START(TmpTimer
);
958 /* Check whether the window has grown, if so, we need to reallocate
959 the bitmap to be larger. */
960 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
962 wxASSERT(m_bitmapSize
.x
> 0);
963 wxASSERT(m_bitmapSize
.y
> 0);
965 m_memDC
->SelectObject(wxNullBitmap
);
967 m_bitmapSize
= wxPoint(x1
,y1
);
968 m_bitmap
= new wxBitmap(x1
,y1
);
969 m_memDC
->SelectObject(*m_bitmap
);
972 m_memDC
->SetDeviceOrigin(0,0);
973 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
974 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
976 m_memDC
->SetLogicalFunction(wxCOPY
);
978 WXLO_TIMER_STOP(TmpTimer
);
980 // fill the background with the background bitmap
985 w
= m_BGbitmap
->GetWidth(),
986 h
= m_BGbitmap
->GetHeight();
987 for(y
= 0; y
< y1
; y
+=h
)
989 for(x
= 0; x
< x1
; x
+=w
)
991 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
995 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
998 // This is the important bit: we tell the list to draw itself
1002 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
1003 updateRect
->x
, updateRect
->y
,
1004 updateRect
->x
+updateRect
->width
,
1005 updateRect
->y
+updateRect
->height
));
1009 // Device origins on the memDC are suspect, we translate manually
1010 // with the translate parameter of Draw().
1011 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
1012 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
1014 // We start calculating a new update rect before drawing the
1015 // cursor, so that the cursor coordinates get included in the next
1016 // update rectangle (although they are drawn on the memDC, this is
1017 // needed to erase it):
1018 m_llist
->InvalidateUpdateRect();
1019 if(m_CursorVisibility
== 1)
1021 // draw a thick cursor for editable windows with focus
1022 m_llist
->DrawCursor(*m_memDC
,
1023 m_HaveFocus
&& IsEditable(),
1027 WXLO_TIMER_START(BlitTimer
);
1028 // Now copy everything to the screen:
1030 // This somehow doesn't work, but even the following bit with the
1031 // whole rect at once is still a bit broken I think.
1032 wxRegionIterator
ri ( GetUpdateRegion() );
1036 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
1037 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
1039 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
1040 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,false);
1046 // FIXME: Trying to copy only the changed parts, but it does not seem
1048 // x0 = updateRect->x; y0 = updateRect->y;
1049 // if(updateRect->height < y1)
1050 // y1 = updateRect->height;
1051 // y1 += WXLO_YOFFSET; //FIXME might not be needed
1052 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,false);
1055 WXLO_TIMER_STOP(BlitTimer
);
1058 #ifdef WXLAYOUT_USE_CARET
1059 // show the caret back after everything is redrawn
1061 #endif // WXLAYOUT_USE_CARET
1065 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
1067 static wxPoint
s_oldCursorPos(-1, -1);
1069 wxPoint
pos(m_llist
->GetCursorPos());
1071 // avoid unnecessary status bar refreshes
1072 if ( pos
!= s_oldCursorPos
)
1074 s_oldCursorPos
= pos
;
1077 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
1078 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
1082 WXLO_TIMER_PRINT(LayoutTimer
);
1083 WXLO_TIMER_PRINT(BlitTimer
);
1084 WXLO_TIMER_PRINT(TmpTimer
);
1088 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
1097 Change the range and position of scrollbars. Has evolved into a
1098 generic Update function which will at some time later cause a repaint
1103 wxLayoutWindow::ResizeScrollbars(bool exact
)
1105 wxClientDC
dc( this );
1107 // m_llist->ForceTotalLayout();
1111 // we are laying out just the minimum, but always up to the
1112 // cursor line, so the cursor position is updated.
1113 m_llist
->Layout(dc
, 0);
1117 WXLO_TIMER_START(LayoutTimer
);
1118 m_llist
->Layout(dc
, -1);
1119 WXLO_TIMER_STOP(LayoutTimer
);
1122 wxPoint max
= m_llist
->GetSize();
1123 wxSize size
= GetClientSize();
1125 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
1126 (long int)max
.x
, (long int) max
.y
));
1128 // in the absence of scrollbars we should compare with the client size
1129 if ( !m_hasHScrollbar
)
1130 m_maxx
= size
.x
;// - WXLO_ROFFSET;
1132 if ( !m_hasVScrollbar
)
1133 m_maxy
= size
.y
;// - WXLO_BOFFSET;
1135 // check if the text hasn't become too big
1136 // TODO why do we set both at once? they're independent...
1137 if( max
.x
> m_maxx
- WXLO_ROFFSET
1138 || max
.y
> m_maxy
- WXLO_BOFFSET
1139 || (max
.x
< m_maxx
- X_SCROLL_PAGE
)
1140 || (max
.y
< m_maxy
- Y_SCROLL_PAGE
)
1143 // text became too large
1146 // add an extra bit to the sizes to avoid future updates
1147 max
.x
+= WXLO_ROFFSET
;
1148 max
.y
+= WXLO_BOFFSET
;
1153 if(max
.x
< X_SCROLL_PAGE
&& m_hasHScrollbar
)
1155 SetScrollbars(0,-1,0,-1,0,-1,true);
1156 m_hasHScrollbar
= false;
1160 if(max
.y
< Y_SCROLL_PAGE
&& m_hasVScrollbar
)
1162 SetScrollbars(-1,0,-1,0,-1,0,true);
1163 m_hasVScrollbar
= false;
1168 // (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE)
1169 (max
.x
> size
.x
- X_SCROLL_PAGE
|| max
.y
> size
.y
- Y_SCROLL_PAGE
) )
1171 GetViewStart(&m_ViewStartX
, &m_ViewStartY
);
1173 SetScrollbars(X_SCROLL_PAGE
,
1175 max
.x
/ X_SCROLL_PAGE
+ 2,
1176 max
.y
/ Y_SCROLL_PAGE
+ 2,
1182 m_hasVScrollbar
= true;
1183 // ScrollToCursor();
1186 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
1187 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
1191 // ----------------------------------------------------------------------------
1193 // clipboard operations
1195 // ----------------------------------------------------------------------------
1198 wxLayoutWindow::Paste(bool usePrivate
, bool primary
)
1200 // this only has an effect under X11:
1201 wxTheClipboard
->UsePrimarySelection(primary
);
1203 if (wxTheClipboard
->Open())
1207 wxLayoutDataObject wxldo
;
1208 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1210 if(wxTheClipboard
->GetData(wxldo
))
1212 wxTheClipboard
->Close();
1213 wxString str
= wxldo
.GetLayoutData();
1222 wxTextDataObject data
;
1223 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1224 && wxTheClipboard
->GetData(data
) )
1226 wxTheClipboard
->Close();
1227 wxString text
= data
.GetText();
1228 wxLayoutImportText( m_llist
, text
);
1234 // if everything failed we can still try the primary:
1235 wxTheClipboard
->Close();
1236 if(! primary
) // not tried before
1238 wxTheClipboard
->UsePrimarySelection();
1239 if (wxTheClipboard
->Open())
1241 wxTextDataObject data
;
1242 if (wxTheClipboard
->IsSupported( data
.GetFormat() )
1243 && wxTheClipboard
->GetData(data
) )
1245 wxString text
= data
.GetText();
1246 wxLayoutImportText( m_llist
, text
);
1250 wxTheClipboard
->Close();
1256 wxLayoutWindow::Copy(bool invalidate
, bool privateFormat
, bool primary
)
1258 // Calling GetSelection() will automatically do an EndSelection()
1259 // on the list, but we need to take a note of it, too:
1262 m_Selecting
= false;
1263 m_llist
->EndSelection();
1266 wxLayoutDataObject
*wldo
= new wxLayoutDataObject
;
1267 wxLayoutList
*llist
= m_llist
->GetSelection(wldo
, invalidate
);
1270 // Export selection as text:
1272 wxLayoutExportObject
*exp
;
1273 wxLayoutExportStatus
status(llist
);
1274 while((exp
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1276 if(exp
->type
== WXLO_EXPORT_TEXT
)
1277 text
<< *(exp
->content
.text
);
1284 // The exporter always appends a newline, so we chop it off if it
1287 size_t len
= text
.Length();
1288 if(len
> 2 && text
[len
-2] == '\r') // Windows
1289 text
= text
.Mid(0,len
-2);
1290 else if(len
> 1 && text
[len
-1] == '\n')
1291 text
= text
.Mid(0,len
-1);
1295 if(! primary
) // always copy as text-only to primary selection
1297 wxTheClipboard
->UsePrimarySelection();
1298 if (wxTheClipboard
->Open())
1300 wxTextDataObject
*data
= new wxTextDataObject( text
);
1301 wxTheClipboard
->SetData( data
);
1302 wxTheClipboard
->Close();
1307 wxTheClipboard
->UsePrimarySelection(primary
);
1308 if (wxTheClipboard
->Open())
1310 wxTextDataObject
*data
= new wxTextDataObject( text
);
1311 bool rc
= wxTheClipboard
->SetData( data
);
1314 rc
|= wxTheClipboard
->SetData( wldo
);
1316 wxTheClipboard
->Close();
1328 wxLayoutWindow::Cut(bool privateFormat
, bool usePrimary
)
1330 if(Copy(false, privateFormat
, usePrimary
)) // do not invalidate selection after copy
1332 m_llist
->DeleteSelection();
1342 // ----------------------------------------------------------------------------
1344 // ----------------------------------------------------------------------------
1347 wxLayoutWindow::Find(
1349 const wxString
&needle
,
1350 wxPoint
* fromWhere
,
1351 const wxString
&configPath
1353 const wxString
& WXUNUSED(needle
),
1354 wxPoint
* WXUNUSED(fromWhere
),
1355 const wxString
& WXUNUSED(configPath
)
1362 if(needle
.Length() == 0)
1364 if( ! MInputBox(&m_FindString
,
1369 || strutil_isempty(m_FindString
))
1376 m_FindString
= needle
;
1379 if(fromWhere
== NULL
)
1380 found
= m_llist
->FindText(m_FindString
, m_llist
->GetCursorPos());
1382 found
= m_llist
->FindText(m_FindString
, *fromWhere
);
1392 m_llist
->MoveCursorTo(found
);
1405 wxLayoutWindow::FindAgain()
1407 bool rc
= Find(m_FindString
);
1411 // ----------------------------------------------------------------------------
1413 // ----------------------------------------------------------------------------
1416 wxLayoutWindow::MakeFormatMenu()
1418 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1420 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."));
1421 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."));
1422 m
->AppendSeparator();
1423 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), wxITEM_CHECK
);
1424 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), wxITEM_CHECK
);
1425 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), wxITEM_CHECK
);
1426 m
->AppendSeparator();
1427 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."));
1428 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."));
1429 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."));
1434 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1436 event
.Check(m_llist
->IsFontUnderlined());
1439 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1441 event
.Check(m_llist
->IsFontBold());
1444 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1446 event
.Check(m_llist
->IsFontItalic());
1449 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1451 switch (event
.GetId())
1453 case WXLOWIN_MENU_LARGER
:
1454 m_llist
->SetFontLarger(); RequestUpdate(); break;
1456 case WXLOWIN_MENU_SMALLER
:
1457 m_llist
->SetFontSmaller(); RequestUpdate(); break;
1459 case WXLOWIN_MENU_UNDERLINE
:
1460 m_llist
->ToggleFontUnderline(); RequestUpdate(); break;
1462 case WXLOWIN_MENU_BOLD
:
1463 m_llist
->ToggleFontWeight(); RequestUpdate(); break;
1465 case WXLOWIN_MENU_ITALICS
:
1466 m_llist
->ToggleFontItalics(); RequestUpdate(); break;
1468 case WXLOWIN_MENU_ROMAN
:
1469 m_llist
->SetFontFamily(wxROMAN
); RequestUpdate(); break;
1471 case WXLOWIN_MENU_TYPEWRITER
:
1472 m_llist
->SetFontFamily(wxFIXED
); RequestUpdate(); break;
1474 case WXLOWIN_MENU_SANSSERIF
:
1475 m_llist
->SetFontFamily(wxSWISS
); RequestUpdate(); break;
1479 // ----------------------------------------------------------------------------
1481 // ----------------------------------------------------------------------------
1484 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1488 RequestUpdate(); // cursor must change
1492 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1494 m_HaveFocus
= false;
1496 RequestUpdate();// cursor must change
1499 // ----------------------------------------------------------------------------
1500 // private functions
1501 // ----------------------------------------------------------------------------
1503 static bool IsDirectionKey(long keyCode
)