1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998, 1999 by Karsten Ballüder (karsten@phy.hw.ac.uk) *
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
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
64 # define WXLO_DEBUG(x) wxLogDebug x
66 # define WXLO_DEBUG(x)
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 /// offsets to put a nice frame around text
74 #define WXLO_XOFFSET 4
75 #define WXLO_YOFFSET 4
77 /// offset to the right and bottom for when to redraw scrollbars
78 #define WXLO_ROFFSET 20
79 #define WXLO_BOFFSET 20
81 /// scroll margins when selecting with the mouse
82 #define WXLO_SCROLLMARGIN_X 10
83 #define WXLO_SCROLLMARGIN_Y 10
85 /// the size of one scrollbar page in pixels
86 static const int X_SCROLL_PAGE
= 10;
87 static const int Y_SCROLL_PAGE
= 20;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
94 EVT_SIZE (wxLayoutWindow::OnSize
)
96 EVT_PAINT (wxLayoutWindow::OnPaint
)
98 EVT_CHAR (wxLayoutWindow::OnChar
)
99 EVT_KEY_UP (wxLayoutWindow::OnKeyUp
)
101 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseDown
)
102 EVT_LEFT_UP(wxLayoutWindow::OnLeftMouseUp
)
103 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
104 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
105 EVT_MIDDLE_DOWN(wxLayoutWindow::OnMiddleMouseDown
)
106 EVT_MOTION (wxLayoutWindow::OnMouseMove
)
108 EVT_UPDATE_UI(WXLOWIN_MENU_UNDERLINE
, wxLayoutWindow::OnUpdateMenuUnderline
)
109 EVT_UPDATE_UI(WXLOWIN_MENU_BOLD
, wxLayoutWindow::OnUpdateMenuBold
)
110 EVT_UPDATE_UI(WXLOWIN_MENU_ITALICS
, wxLayoutWindow::OnUpdateMenuItalic
)
111 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST
, WXLOWIN_MENU_LAST
, wxLayoutWindow::OnMenu
)
113 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus
)
114 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus
)
116 // EVT_IDLE(wxLayoutWindow::ResizeScrollbars)
119 // ----------------------------------------------------------------------------
120 // function prototypes
121 // ----------------------------------------------------------------------------
123 /// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
124 static bool IsDirectionKey(long keyCode
);
126 // ============================================================================
128 // ============================================================================
130 #ifndef wxWANTS_CHARS
131 # define wxWANTS_CHARS 0
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
139 : wxScrolledWindow(parent
, -1,
140 wxDefaultPosition
, wxDefaultSize
,
141 wxHSCROLL
| wxVSCROLL
|
146 SetStatusBar(NULL
); // don't use statusbar
148 m_doSendEvents
= false;
149 m_ViewStartX
= 0; m_ViewStartY
= 0;
150 m_DoPopupMenu
= true;
151 m_PopupMenu
= MakeFormatMenu();
152 m_memDC
= new wxMemoryDC
;
153 m_bitmap
= new wxBitmap(4,4);
154 m_bitmapSize
= wxPoint(4,4);
155 m_llist
= new wxLayoutList();
157 m_ScrollToCursor
= false;
159 m_FocusFollowMode
= false;
163 // no scrollbars initially
165 m_hasVScrollbar
= false;
169 #ifdef WXLAYOUT_USE_CARET
170 // FIXME cursor size shouldn't be hardcoded
171 wxCaret
*caret
= new wxCaret(this, 2, 20);
173 m_llist
->SetCaret(caret
);
174 #endif // WXLAYOUT_USE_CARET
177 m_HandCursor
= FALSE
;
178 m_CursorVisibility
= -1;
179 SetCursor(wxCURSOR_IBEAM
);
182 // at least under Windows, this should be the default behaviour
183 m_AutoDeleteSelection
= TRUE
;
186 wxLayoutWindow::~wxLayoutWindow()
188 delete m_memDC
; // deletes bitmap automatically (?)
192 SetBackgroundBitmap(NULL
);
196 wxLayoutWindow::Clear(int family
,
204 GetLayoutList()->Clear(family
,size
,style
,weight
,underline
,fg
,bg
);
205 SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
206 wxScrolledWindow::Clear();
207 ResizeScrollbars(true);
211 m_CursorVisibility
= 1;
213 #ifdef WXLAYOUT_USE_CARET
214 if ( m_CursorVisibility
== 1 )
216 #endif // WXLAYOUT_USE_CARET
218 RequestUpdate((wxRect
*)NULL
);
221 void wxLayoutWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
223 wxScrolledWindow::Refresh(eraseBackground
, rect
);
227 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
229 wxClientDC
dc( this );
231 if ( eventId
!= WXLOWIN_MENU_MOUSEMOVE
239 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
240 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
242 findPos
.x
-= WXLO_XOFFSET
;
243 findPos
.y
-= WXLO_YOFFSET
;
250 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
252 // Scroll the window if the mouse is at the end of it:
253 if(m_Selecting
&& eventId
== WXLOWIN_MENU_MOUSEMOVE
)
255 //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
257 ViewStart(&left
, &top
);
258 wxSize size
= GetClientSize();
261 if(event
.GetX() < WXLO_SCROLLMARGIN_X
)
262 xdelta
= -(WXLO_SCROLLMARGIN_X
-event
.GetX());
263 else if(event
.GetX() > size
.x
-WXLO_SCROLLMARGIN_X
)
264 xdelta
= event
.GetX()-size
.x
+WXLO_SCROLLMARGIN_X
;
267 if(event
.GetY() < WXLO_SCROLLMARGIN_Y
)
268 ydelta
= -(WXLO_SCROLLMARGIN_Y
-event
.GetY());
269 else if(event
.GetY() > size
.y
-WXLO_SCROLLMARGIN_Y
)
270 ydelta
= event
.GetY()-size
.y
+WXLO_SCROLLMARGIN_Y
;
274 //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
275 if(xdelta
!= 0 || ydelta
!= 0)
277 top
+= ydelta
; if(top
< 0) top
= 0;
278 left
+= xdelta
; if(left
< 0) left
= 0;
285 wxLayoutObject
*obj
= m_llist
->FindObjectScreen(dc
, findPos
,
287 wxLayoutObject::UserData
*u
= obj
? obj
->GetUserData() : NULL
;
289 // has the mouse only been moved?
292 case WXLOWIN_MENU_MOUSEMOVE
:
294 // this variables is used to only erase the message in the status
295 // bar if we had put it there previously - otherwise empting status
296 // bar might be undesirable
297 static bool s_hasPutMessageInStatusBar
= false;
299 // found is only true if we are really over an object, not just
301 if(found
&& u
&& ! m_Selecting
)
304 SetCursor(wxCURSOR_HAND
);
306 if(m_StatusBar
&& m_StatusFieldLabel
!= -1)
308 const wxString
&label
= u
->GetLabel();
311 m_StatusBar
->SetStatusText(label
,
313 s_hasPutMessageInStatusBar
= true;
320 SetCursor(wxCURSOR_IBEAM
);
321 m_HandCursor
= FALSE
;
322 if( m_StatusBar
&& m_StatusFieldLabel
!= -1 &&
323 s_hasPutMessageInStatusBar
)
325 m_StatusBar
->SetStatusText("", m_StatusFieldLabel
);
331 if ( event
.LeftIsDown() )
333 // m_Selecting might not be set if the button got pressed
334 // outside this window, so check for it:
337 m_llist
->ContinueSelection(cursorPos
, m_ClickPosition
);
338 RequestUpdate(); // TODO: we don't have to redraw everything!
349 case WXLOWIN_MENU_LDOWN
:
351 // always move cursor to mouse click:
352 m_llist
->MoveCursorTo(cursorPos
);
354 // clicking a mouse removes the selection
355 if ( m_llist
->HasSelection() )
357 m_llist
->DiscardSelection();
359 RequestUpdate(); // TODO: we don't have to redraw everything!
362 // Calculate where the top of the visible area is:
366 GetScrollPixelsPerUnit(&dx
, &dy
);
369 wxPoint
offset(-x0
+WXLO_XOFFSET
, -y0
+WXLO_YOFFSET
);
371 if(m_CursorVisibility
== -1)
372 m_CursorVisibility
= 1;
373 #ifdef WXLAYOUT_USE_CARET
374 if ( m_CursorVisibility
== 1 )
376 #endif // WXLAYOUT_USE_CARET
378 if(m_CursorVisibility
)
380 // draw a thick cursor for editable windows with focus
381 m_llist
->DrawCursor(dc
, m_HaveFocus
&& IsEditable(), offset
);
385 RequestUpdate(); // RequestUpdate suppresses flicker under GTK
389 m_llist
->StartSelection(wxPoint(-1, -1), m_ClickPosition
);
394 case WXLOWIN_MENU_LUP
:
397 m_llist
->EndSelection();
400 RequestUpdate(); // TODO: we don't have to redraw everything!
404 case WXLOWIN_MENU_MDOWN
:
408 case WXLOWIN_MENU_DBLCLICK
:
409 // select a word under cursor
410 m_llist
->MoveCursorTo(cursorPos
);
411 m_llist
->MoveCursorWord(-1);
412 m_llist
->StartSelection();
413 m_llist
->MoveCursorWord(1, false);
414 m_llist
->EndSelection();
416 RequestUpdate(); // TODO: we don't have to redraw everything!
420 // notify about mouse events?
423 // only do the menu if activated, editable and not on a clickable object
424 if(eventId
== WXLOWIN_MENU_RCLICK
426 && (! obj
|| u
== NULL
))
428 PopupMenu(m_PopupMenu
, m_ClickPosition
.x
, m_ClickPosition
.y
);
433 // find the object at this position
436 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, eventId
);
437 commandEvent
.SetEventObject( this );
438 commandEvent
.SetClientData((char *)obj
);
439 GetEventHandler()->ProcessEvent(commandEvent
);
446 // ----------------------------------------------------------------------------
447 // keyboard handling.
448 // ----------------------------------------------------------------------------
451 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
453 int keyCode
= event
.KeyCode();
454 bool ctrlDown
= event
.ControlDown();
456 #ifdef WXLAYOUT_DEBUG
457 if(keyCode
== WXK_F1
)
465 // Force m_Selecting to be false if shift is no longer
466 // pressed. OnKeyUp() cannot catch all Shift-Up events.
467 if(m_Selecting
&& !event
.ShiftDown())
470 m_llist
->EndSelection();
471 m_llist
->DiscardSelection(); //FIXME: correct?
474 // If we deleted the selection here, we must not execute the
475 // deletion in Delete/Backspace handling.
476 bool deletedSelection
= false;
477 // pressing any non-arrow key optionally replaces the selection:
478 if(m_AutoDeleteSelection
480 && m_llist
->HasSelection()
481 && ! IsDirectionKey(keyCode
)
482 && ! (event
.AltDown() || ctrlDown
)
485 m_llist
->DeleteSelection();
486 deletedSelection
= true;
490 // <Shift>+<arrow> starts selection
491 if ( IsDirectionKey(keyCode
) )
493 // just continue the old selection
496 if( event
.ShiftDown() )
497 m_llist
->ContinueSelection();
500 m_llist
->DiscardSelection();
504 else if( event
.ShiftDown() )
507 m_llist
->StartSelection();
511 // If needed, make cursor visible:
512 if(m_CursorVisibility
== -1)
513 m_CursorVisibility
= 1;
515 /* These two nested switches work like this:
516 The first one processes all non-editing keycodes, to move the
517 cursor, etc. It's default will process all keycodes causing
518 modifications to the buffer, but only if editing is allowed.
524 m_llist
->MoveCursorWord(1);
526 m_llist
->MoveCursorHorizontally(1);
530 m_llist
->MoveCursorWord(-1);
532 m_llist
->MoveCursorHorizontally(-1);
535 m_llist
->MoveCursorVertically(-1);
538 m_llist
->MoveCursorVertically(1);
541 m_llist
->MoveCursorVertically(-Y_SCROLL_PAGE
);
544 m_llist
->MoveCursorVertically(Y_SCROLL_PAGE
);
548 m_llist
->MoveCursorTo(wxPoint(0, 0));
550 m_llist
->MoveCursorToBeginOfLine();
554 m_llist
->MoveCursorToEnd();
556 m_llist
->MoveCursorToEndOfLine();
560 if(ctrlDown
&& ! IsEditable())
564 // this should work even in read-only mode
570 case 't': // search again
576 else if( IsEditable() )
578 /* First, handle control keys */
579 if(ctrlDown
&& ! event
.AltDown())
581 if(keyCode
>= 'A' && keyCode
<= 'Z')
582 keyCode
= tolower(keyCode
);
589 if(! deletedSelection
)
591 m_llist
->DeleteWord();
596 if(! deletedSelection
) // already done
603 m_llist
->DeleteLines(1);
606 case 'h': // like backspace
607 if(m_llist
->MoveCursorHorizontally(-1))
616 case 't': // search again
620 m_llist
->DeleteToBeginOfLine();
624 m_llist
->DeleteToEndOfLine();
633 #ifdef WXLAYOUT_DEBUG
635 m_llist
->SetFont(-1,-1,-1,-1,true); // underlined
643 else if( event
.AltDown() && ! event
.ControlDown() )
649 m_llist
->DeleteWord();
657 else if ( ! event
.AltDown() && ! event
.ControlDown())
662 if(event
.ShiftDown())
666 if(event
.ShiftDown())
669 if(! deletedSelection
)
675 case WXK_BACK
: // backspace
676 if(! deletedSelection
)
677 if(m_llist
->MoveCursorHorizontally(-1))
685 m_llist
->WrapLine(m_WrapMargin
);
686 m_llist
->LineBreak();
691 if ( !event
.ShiftDown() )
693 // TODO should be configurable
694 static const int tabSize
= 8;
696 CoordType x
= m_llist
->GetCursorPos().x
;
697 size_t numSpaces
= tabSize
- x
% tabSize
;
698 m_llist
->Insert(wxString(' ', numSpaces
));
704 if((!(event
.ControlDown() || event
.AltDown()
706 ///FIXME: wxGTK reports MetaDown always
710 && (keyCode
< 256 && keyCode
>= 32)
713 if(m_WrapMargin
> 0 && isspace(keyCode
))
714 m_llist
->WrapLine(m_WrapMargin
);
715 m_llist
->Insert((char)keyCode
);
726 // continue selection to the current (new) cursor position
727 m_llist
->ContinueSelection();
730 // refresh the screen
731 RequestUpdate(m_llist
->GetUpdateRect());
736 wxLayoutWindow::OnKeyUp(wxKeyEvent
& event
)
738 if ( event
.KeyCode() == WXK_SHIFT
&& m_Selecting
)
740 m_llist
->EndSelection();
749 wxLayoutWindow::ScrollToCursor(void)
751 //is always needed to make sure we know where the cursor is
753 RequestUpdate(m_llist
->GetUpdateRect());
755 int x0
,y0
,x1
,y1
, dx
, dy
;
757 // Calculate where the top of the visible area is:
759 GetScrollPixelsPerUnit(&dx
, &dy
);
762 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0
, y0
));
764 // Get the size of the visible window:
765 GetClientSize(&x1
, &y1
);
767 // Make sure that the scrollbars are at a position so that the cursor is
768 // visible if we are editing
769 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor
));
770 wxPoint cc
= m_llist
->GetCursorScreenPos();
772 // the cursor should be completely visible in both directions
773 wxPoint
cs(m_llist
->GetCursorSize());
776 if ( cc
.x
< x0
|| cc
.x
>= x0
+ x1
- cs
.x
)
783 if ( cc
.y
< y0
|| cc
.y
>= y0
+ y1
- cs
.y
)
790 if ( nx
!= -1 || ny
!= -1 )
792 // set new view start
793 Scroll(nx
== -1 ? -1 : (nx
+dx
-1)/dx
, ny
== -1 ? -1 : (ny
+dy
-1)/dy
);
795 m_ScrollToCursor
= false;
801 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
))
803 wxRect region
= GetUpdateRegion().GetBox();
804 InternalPaint(®ion
);
808 wxLayoutWindow::RequestUpdate(const wxRect
*updateRect
)
811 // Calling Refresh() causes bad flicker under wxGTK!!!
812 InternalPaint(updateRect
);
814 // shouldn't specify the update rectangle if it doesn't include all the
815 // changed locations - otherwise, they won't be repainted at all because
816 // the system clips the display to the update rect
817 Refresh(FALSE
); //, updateRect);
822 wxLayoutWindow::InternalPaint(const wxRect
*updateRect
)
824 wxPaintDC
dc( this );
827 #ifdef WXLAYOUT_USE_CARET
828 // hide the caret before drawing anything
830 #endif // WXLAYOUT_USE_CARET
832 int x0
,y0
,x1
,y1
, dx
, dy
;
834 // Calculate where the top of the visible area is:
836 GetScrollPixelsPerUnit(&dx
, &dy
);
839 // Get the size of the visible window:
840 GetClientSize(&x1
,&y1
);
846 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
847 updateRect
->x
, updateRect
->y
,
848 updateRect
->x
+updateRect
->width
,
849 updateRect
->y
+updateRect
->height
));
853 WXLO_DEBUG(("InternalPaint, isdirty, list size: %ld,%ld",
854 (unsigned long) m_llist
->GetSize().x
,
855 (unsigned long) m_llist
->GetSize().y
));
856 // m_llist->ForceTotalLayout();
858 WXLO_DEBUG(("InternalPaint, isdirty, list size after layout: %ld,%ld",
859 (unsigned long) m_llist
->GetSize().x
,
860 (unsigned long) m_llist
->GetSize().y
));
865 /* Check whether the window has grown, if so, we need to reallocate
866 the bitmap to be larger. */
867 if(x1
> m_bitmapSize
.x
|| y1
> m_bitmapSize
.y
)
869 wxASSERT(m_bitmapSize
.x
> 0);
870 wxASSERT(m_bitmapSize
.y
> 0);
872 m_memDC
->SelectObject(wxNullBitmap
);
874 m_bitmapSize
= wxPoint(x1
,y1
);
875 m_bitmap
= new wxBitmap(x1
,y1
);
876 m_memDC
->SelectObject(*m_bitmap
);
879 m_memDC
->SetDeviceOrigin(0,0);
880 m_memDC
->SetBackground(wxBrush(m_llist
->GetDefaultStyleInfo().GetBGColour(),wxSOLID
));
881 m_memDC
->SetPen(wxPen(m_llist
->GetDefaultStyleInfo().GetBGColour(),
883 m_memDC
->SetLogicalFunction(wxCOPY
);
886 // fill the background with the background bitmap
891 w
= m_BGbitmap
->GetWidth(),
892 h
= m_BGbitmap
->GetHeight();
893 for(y
= 0; y
< y1
; y
+=h
)
894 for(x
= 0; x
< x1
; x
+=w
)
895 m_memDC
->DrawBitmap(*m_BGbitmap
, x
, y
);
896 m_memDC
->SetBackgroundMode(wxTRANSPARENT
);
899 // This is the important bit: we tell the list to draw itself
903 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
904 updateRect
->x
, updateRect
->y
,
905 updateRect
->x
+updateRect
->width
,
906 updateRect
->y
+updateRect
->height
));
910 // Device origins on the memDC are suspect, we translate manually
911 // with the translate parameter of Draw().
912 wxPoint
offset(-x0
+WXLO_XOFFSET
,-y0
+WXLO_YOFFSET
);
913 m_llist
->Draw(*m_memDC
,offset
, y0
, y0
+y1
);
915 // We start calculating a new update rect before drawing the
916 // cursor, so that the cursor coordinates get included in the next
917 // update rectangle (although they are drawn on the memDC, this is
918 // needed to erase it):
919 m_llist
->InvalidateUpdateRect();
920 if(m_CursorVisibility
!= 0)
922 // draw a thick cursor for editable windows with focus
923 m_llist
->DrawCursor(*m_memDC
,
924 m_HaveFocus
&& IsEditable(),
928 // Now copy everything to the screen:
930 // This somehow doesn't work, but even the following bit with the
931 // whole rect at once is still a bit broken I think.
932 wxRegionIterator
ri ( GetUpdateRegion() );
936 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
937 ri
.GetX(),ri
.GetY(),ri
.GetW(),ri
.GetH()));
938 dc
.Blit(x0
+ri
.GetX(),y0
+ri
.GetY(),ri
.GetW(),ri
.GetH(),
939 m_memDC
,ri
.GetX(),ri
.GetY(),wxCOPY
,FALSE
);
945 // FIXME: Trying to copy only the changed parts, but it does not seem
947 // x0 = updateRect->x; y0 = updateRect->y;
948 // if(updateRect->height < y1)
949 // y1 = updateRect->height;
950 // y1 += WXLO_YOFFSET; //FIXME might not be needed
951 dc
.Blit(x0
,y0
,x1
,y1
,m_memDC
,0,0,wxCOPY
,FALSE
);
954 #ifdef WXLAYOUT_USE_CARET
955 // show the caret back after everything is redrawn
957 #endif // WXLAYOUT_USE_CARET
961 if ( m_StatusBar
&& m_StatusFieldCursor
!= -1 )
963 static wxPoint
s_oldCursorPos(-1, -1);
965 wxPoint
pos(m_llist
->GetCursorPos());
967 // avoid unnecessary status bar refreshes
968 if ( pos
!= s_oldCursorPos
)
970 s_oldCursorPos
= pos
;
973 label
.Printf(_("Ln:%d Col:%d"), pos
.y
+ 1, pos
.x
+ 1);
974 m_StatusBar
->SetStatusText(label
, m_StatusFieldCursor
);
980 wxLayoutWindow::OnSize(wxSizeEvent
&event
)
988 // change the range and position of scrollbars
990 wxLayoutWindow::ResizeScrollbars(bool exact
)
995 wxClientDC
dc( this );
997 // m_llist->ForceTotalLayout();
1003 wxPoint max
= m_llist
->GetSize();
1004 wxSize size
= GetClientSize();
1006 WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
1007 (long int)max
.x
, (long int) max
.y
));
1009 // in the absence of scrollbars we should compare with the client size
1010 if ( !m_hasHScrollbar
)
1011 m_maxx
= size
.x
;// - WXLO_ROFFSET;
1012 if ( !m_hasVScrollbar
)
1013 m_maxy
= size
.y
;// - WXLO_BOFFSET;
1015 // check if the text hasn't become too big
1016 // TODO why do we set both at once? they're independent...
1017 if( max
.x
> m_maxx
- WXLO_ROFFSET
|| max
.y
> m_maxy
- WXLO_BOFFSET
|| exact
)
1019 // text became too large
1022 // add an extra bit to the sizes to avoid future updates
1023 max
.x
+= WXLO_ROFFSET
;
1024 max
.y
+= WXLO_BOFFSET
;
1027 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
1028 SetScrollbars(X_SCROLL_PAGE
, Y_SCROLL_PAGE
,
1029 max
.x
/ X_SCROLL_PAGE
+ 1, max
.y
/ Y_SCROLL_PAGE
+ 1,
1030 m_ViewStartX
, m_ViewStartY
,
1034 m_hasVScrollbar
= true;
1036 m_maxx
= max
.x
+ X_SCROLL_PAGE
;
1037 m_maxy
= max
.y
+ Y_SCROLL_PAGE
;
1040 //FIXME: this code is pretty broken, producing "arithmetic
1041 //exception" crashes (div by 0??)
1044 // check if the window hasn't become too big, thus making the scrollbars
1048 // add an extra bit to the sizes to avoid future updates
1049 max
.x
-= WXLO_ROFFSET
;
1050 max
.y
-= WXLO_BOFFSET
;
1053 if ( m_hasHScrollbar
&& (max
.x
< m_maxx
) )
1055 // remove the horizontal scrollbar
1056 SetScrollbars(0, -1, 0, -1, 0, -1, true);
1057 m_hasHScrollbar
= false;
1060 if ( m_hasVScrollbar
&& (max
.y
< m_maxy
) )
1062 // remove the vertical scrollbar
1063 SetScrollbars(-1, 0, -1, 0, -1, 0, true);
1064 m_hasVScrollbar
= false;
1070 // ----------------------------------------------------------------------------
1071 // clipboard operations
1073 // ----------------------------------------------------------------------------
1076 wxLayoutWindow::Paste(bool primary
)
1079 if (wxTheClipboard
->Open())
1083 wxTheClipboard
->UsePrimarySelection();
1085 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1086 wxLayoutDataObject wxldo
;
1087 if (wxTheClipboard
->IsSupported( wxldo
.GetFormat() ))
1089 wxTheClipboard
->GetData(&wxldo
);
1092 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
1097 #if 0 //RE_ENABLE FIXME!!
1098 wxTextDataObject data
;
1099 if (wxTheClipboard
->IsSupported( data
.GetFormat() ))
1101 wxTheClipboard
->GetData(&data
);
1102 wxString text
= data
.GetText();
1103 wxLayoutImportText( m_llist
, text
);
1108 wxTheClipboard
->Close();
1113 wxLayoutWindow::Copy(bool invalidate
)
1115 // Calling GetSelection() will automatically do an EndSelection()
1116 // on the list, but we need to take a note of it, too:
1119 m_Selecting
= false;
1120 m_llist
->EndSelection();
1123 #if 0 //FIXME CLIPBOARD
1124 wxLayoutDataObject wldo
;
1125 wxLayoutList
*llist
= m_llist
->GetSelection(&wldo
, invalidate
);
1128 // Export selection as text:
1130 wxLayoutExportObject
*exp
;
1131 wxLayoutExportStatus
status(llist
);
1132 while((exp
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
1134 if(exp
->type
== WXLO_EXPORT_TEXT
)
1135 text
<< *(exp
->content
.text
);
1140 // The exporter always appends a newline, so we chop it off if it
1143 size_t len
= text
.Length();
1144 if(len
> 2 && text
[len
-2] == '\r') // Windows
1145 text
= text
.Mid(0,len
-2);
1146 else if(len
> 1 && text
[len
-1] == '\n')
1147 text
= text
.Mid(0,len
-1);
1151 if (wxTheClipboard
->Open())
1153 wxTextDataObject
*data
= new wxTextDataObject( text
);
1154 bool rc
= wxTheClipboard
->SetData( data
);
1155 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
1156 rc
|= wxTheClipboard
->AddData( &wldo
);
1158 wxTheClipboard
->Close();
1161 #endif //FIXME CLIPBOARD
1167 wxLayoutWindow::Cut(void)
1169 if(Copy(false)) // do not invalidate selection after copy
1171 m_llist
->DeleteSelection();
1179 // ----------------------------------------------------------------------------
1181 // ----------------------------------------------------------------------------
1185 wxLayoutWindow::Find(const wxString
&needle
,
1186 wxPoint
* fromWhere
,
1187 const wxString
&configPath
)
1191 if(needle
.Length() == 0)
1193 if( ! MInputBox(&m_FindString
,
1198 || strutil_isempty(m_FindString
))
1202 m_FindString
= needle
;
1204 if(fromWhere
== NULL
)
1205 found
= m_llist
->FindText(m_FindString
, m_llist
->GetCursorPos());
1207 found
= m_llist
->FindText(m_FindString
, *fromWhere
);
1215 m_llist
->MoveCursorTo(found
);
1225 wxLayoutWindow::FindAgain(void)
1227 bool rc
= Find(m_FindString
);
1232 // ----------------------------------------------------------------------------
1234 // ----------------------------------------------------------------------------
1237 wxLayoutWindow::MakeFormatMenu()
1239 wxMenu
*m
= new wxMenu(_("Layout Menu"));
1241 m
->Append(WXLOWIN_MENU_LARGER
,_("&Larger"),_("Switch to larger font."), false);
1242 m
->Append(WXLOWIN_MENU_SMALLER
,_("&Smaller"),_("Switch to smaller font."), false);
1243 m
->AppendSeparator();
1244 m
->Append(WXLOWIN_MENU_UNDERLINE
, _("&Underline"),_("Underline mode."), true);
1245 m
->Append(WXLOWIN_MENU_BOLD
, _("&Bold"),_("Bold mode."), true);
1246 m
->Append(WXLOWIN_MENU_ITALICS
, _("&Italics"),_("Italics mode."), true);
1247 m
->AppendSeparator();
1248 m
->Append(WXLOWIN_MENU_ROMAN
,_("&Roman"),_("Switch to roman font."), false);
1249 m
->Append(WXLOWIN_MENU_TYPEWRITER
,_("&Typewriter"),_("Switch to typewriter font."), false);
1250 m
->Append(WXLOWIN_MENU_SANSSERIF
,_("&Sans Serif"),_("Switch to sans serif font."), false);
1255 void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent
& event
)
1257 event
.Check(m_llist
->IsFontUnderlined());
1260 void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent
& event
)
1262 event
.Check(m_llist
->IsFontBold());
1265 void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent
& event
)
1267 event
.Check(m_llist
->IsFontItalic());
1270 void wxLayoutWindow::OnMenu(wxCommandEvent
& event
)
1272 switch (event
.GetId())
1274 case WXLOWIN_MENU_LARGER
:
1275 m_llist
->SetFontLarger(); RequestUpdate(); break;
1276 case WXLOWIN_MENU_SMALLER
:
1277 m_llist
->SetFontSmaller(); RequestUpdate(); break;
1278 case WXLOWIN_MENU_UNDERLINE
:
1279 m_llist
->ToggleFontUnderline(); RequestUpdate(); break;
1280 case WXLOWIN_MENU_BOLD
:
1281 m_llist
->ToggleFontWeight(); RequestUpdate(); break;
1282 case WXLOWIN_MENU_ITALICS
:
1283 m_llist
->ToggleFontItalics(); RequestUpdate(); break;
1284 case WXLOWIN_MENU_ROMAN
:
1285 m_llist
->SetFontFamily(wxROMAN
); RequestUpdate(); break;
1286 case WXLOWIN_MENU_TYPEWRITER
:
1287 m_llist
->SetFontFamily(wxFIXED
); RequestUpdate(); break;
1288 case WXLOWIN_MENU_SANSSERIF
:
1289 m_llist
->SetFontFamily(wxSWISS
); RequestUpdate(); break;
1293 // ----------------------------------------------------------------------------
1295 // ----------------------------------------------------------------------------
1298 wxLayoutWindow::OnSetFocus(wxFocusEvent
&ev
)
1302 RequestUpdate(); // cursor must change
1306 wxLayoutWindow::OnKillFocus(wxFocusEvent
&ev
)
1308 m_HaveFocus
= false;
1310 RequestUpdate();// cursor must change
1313 // ----------------------------------------------------------------------------
1314 // private functions
1315 // ----------------------------------------------------------------------------
1317 static bool IsDirectionKey(long keyCode
)