]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.cpp
cc63534cb7654499e71aee39cd813400a0a01cf1
[wxWidgets.git] / user / wxLayout / wxlwindow.cpp
1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
3 * *
4 * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8
9 #ifdef __GNUG__
10 # pragma implementation "wxlwindow.h"
11 #endif
12
13 #include "wx/wxprec.h"
14 #ifdef __BORLANDC__
15 # pragma hdrstop
16 #endif
17
18
19 #include "Mpch.h"
20 #ifdef M_BASEDIR
21 # ifndef USE_PCH
22 # include "Mcommon.h"
23 # include "gui/wxMenuDefs.h"
24 # include "gui/wxMApp.h"
25 # endif // USE_PCH
26 # include "gui/wxlwindow.h"
27 # include "gui/wxlparser.h"
28 #else
29 # ifdef __WXMSW__
30 # include <windows.h>
31 # undef FindWindow
32 # undef GetCharWidth
33 # undef StartDoc
34 # endif
35
36 # include "wxlwindow.h"
37 # include "wxlparser.h"
38 #endif
39
40 #include <wx/clipbrd.h>
41 #include <wx/textctrl.h>
42 #include <wx/dataobj.h>
43
44 #include <ctype.h>
45
46 #ifdef WXLAYOUT_DEBUG
47 # define WXLO_DEBUG(x) wxLogDebug x
48 #else
49 # define WXLO_DEBUG(x)
50 #endif
51
52 /// offsets to put a nice frame around text
53 #define WXLO_XOFFSET 4
54 #define WXLO_YOFFSET 4
55
56 /// offset to the right and bottom for when to redraw scrollbars
57 #define WXLO_ROFFSET 20
58 #define WXLO_BOFFSET 20
59
60 BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
61 EVT_PAINT (wxLayoutWindow::OnPaint)
62 EVT_CHAR (wxLayoutWindow::OnChar)
63 EVT_KEY_UP (wxLayoutWindow::OnKeyUp)
64 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick)
65 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
66 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
67 EVT_MOTION (wxLayoutWindow::OnMouseMove)
68 EVT_MENU_RANGE(WXLOWIN_MENU_FIRST, WXLOWIN_MENU_LAST, wxLayoutWindow::OnMenu)
69 EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus)
70 EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
71 END_EVENT_TABLE()
72
73 wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
74 : wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
75 wxHSCROLL | wxVSCROLL | wxBORDER)
76
77 {
78 m_Editable = false;
79 m_doSendEvents = false;
80 m_ViewStartX = 0; m_ViewStartY = 0;
81 m_DoPopupMenu = true;
82 m_PopupMenu = MakeFormatMenu();
83 m_memDC = new wxMemoryDC;
84 m_bitmap = new wxBitmap(4,4);
85 m_bitmapSize = wxPoint(4,4);
86 m_llist = new wxLayoutList();
87 m_BGbitmap = NULL;
88 m_ScrollToCursor = false;
89 SetWrapMargin(0);
90 wxPoint max = m_llist->GetSize();
91 SetScrollbars(10, 20 /*lineHeight*/, max.x/10+1, max.y/20+1);
92 EnableScrolling(true,true);
93 m_maxx = max.x; m_maxy = max.y;
94 m_Selecting = false;
95 SetCursorVisibility(-1);
96 SetCursor(wxCURSOR_IBEAM);
97 SetDirty();
98 }
99
100 wxLayoutWindow::~wxLayoutWindow()
101 {
102 delete m_memDC; // deletes bitmap automatically (?)
103 delete m_bitmap;
104 delete m_llist;
105 delete m_PopupMenu;
106 SetBackgroundBitmap(NULL);
107 }
108
109 void
110 wxLayoutWindow::Clear(int family,
111 int size,
112 int style,
113 int weight,
114 int underline,
115 wxColour *fg,
116 wxColour *bg)
117 {
118 GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
119 SetBackgroundColour(GetLayoutList()->GetDefaults()->GetBGColour());
120 ResizeScrollbars(true);
121 SetDirty();
122 SetModified(false);
123 wxRect r;
124 int w,h;
125 r.x = r.y = 0; GetSize(&w,&h);
126 r.width = w;
127 r.height = h;
128 DoPaint(&r);
129 }
130
131 #ifdef __WXMSW__
132 long
133 wxLayoutWindow::MSWGetDlgCode()
134 {
135 // if we don't return this, we won't get OnChar() events for TABs and ENTER
136 return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_WANTMESSAGE;
137 }
138 #endif //MSW
139
140 void
141 wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
142 {
143 wxPaintDC dc( this );
144 PrepareDC( dc );
145 SetFocus();
146
147 wxPoint findPos;
148 findPos.x = dc.DeviceToLogicalX(event.GetX());
149 findPos.y = dc.DeviceToLogicalY(event.GetY());
150
151 findPos.x -= WXLO_XOFFSET;
152 findPos.y -= WXLO_YOFFSET;
153
154 if(findPos.x < 0) findPos.x = 0;
155 if(findPos.y < 0) findPos.y = 0;
156
157 m_ClickPosition = wxPoint(event.GetX(), event.GetY());
158
159 wxPoint cursorPos;
160 bool found;
161 wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos,
162 &cursorPos, &found);
163
164 //has the mouse only been moved?
165 if(eventId == WXLOWIN_MENU_MOUSEMOVE)
166 {
167 // found is only true if we are really over an object, not just
168 // behind it
169 if(found && obj && obj->GetUserData() != NULL)
170 {
171 if(!m_HandCursor)
172 SetCursor(wxCURSOR_HAND);
173 m_HandCursor = TRUE;
174 }
175 else
176 {
177 if(m_HandCursor)
178 SetCursor(wxCURSOR_IBEAM);
179 m_HandCursor = FALSE;
180 }
181 if(event.LeftIsDown())
182 {
183 if(! m_Selecting)
184 {
185 m_llist->StartSelection();
186 m_Selecting = true;
187 DoPaint(FALSE);
188 }
189 else
190 {
191 m_llist->ContinueSelection(cursorPos);
192 DoPaint(FALSE);
193 }
194 }
195 if(m_Selecting && ! event.LeftIsDown())
196 {
197 m_llist->EndSelection(cursorPos);
198 m_Selecting = false;
199 DoPaint(FALSE);
200 }
201 return;
202 }
203
204 // always move cursor to mouse click:
205 if(obj && eventId == WXLOWIN_MENU_LCLICK)
206 {
207 m_llist->MoveCursorTo(cursorPos);
208 if(m_CursorVisibility == -1)
209 m_CursorVisibility = 1;
210 ScrollToCursor();
211 DoPaint(FALSE); // DoPaint suppresses flicker under GTK
212 }
213 if(!m_doSendEvents) // nothing to do
214 return;
215
216 // only do the menu if activated, editable and not on a clickable object
217 if(eventId == WXLOWIN_MENU_RCLICK
218 && IsEditable()
219 && (! obj || (obj && obj->GetUserData() == NULL))
220 )
221 {
222 PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y);
223 return;
224 }
225 // find the object at this position
226 if(obj)
227 {
228 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
229 commandEvent.SetEventObject( this );
230 commandEvent.SetClientData((char *)obj);
231 GetEventHandler()->ProcessEvent(commandEvent);
232 }
233 }
234
235 /*
236 * Some simple keyboard handling.
237 */
238 void
239 wxLayoutWindow::OnChar(wxKeyEvent& event)
240 {
241 int keyCode = event.KeyCode();
242
243 #ifdef WXLAYOUT_DEBUG
244 if(keyCode == WXK_F1)
245 {
246 m_llist->Debug();
247 return;
248 }
249 #endif
250
251 if(! m_Selecting && event.ShiftDown())
252 {
253 switch(keyCode)
254 {
255 case WXK_UP:
256 case WXK_DOWN:
257 case WXK_RIGHT:
258 case WXK_LEFT:
259 case WXK_PRIOR:
260 case WXK_NEXT:
261 case WXK_HOME:
262 case WXK_END:
263 m_Selecting = true;
264 m_llist->StartSelection();
265 break;
266 default:
267 ;
268 }
269 }
270
271 // If needed, make cursor visible:
272 if(m_CursorVisibility == -1)
273 m_CursorVisibility = 1;
274
275 /* These two nested switches work like this:
276 The first one processes all non-editing keycodes, to move the
277 cursor, etc. It's default will process all keycodes causing
278 modifications to the buffer, but only if editing is allowed.
279 */
280 switch(keyCode)
281 {
282 case WXK_RIGHT:
283 m_llist->MoveCursorHorizontally(1);
284 break;
285 case WXK_LEFT:
286 m_llist->MoveCursorHorizontally(-1);
287 break;
288 case WXK_UP:
289 m_llist->MoveCursorVertically(-1);
290 break;
291 case WXK_DOWN:
292 m_llist->MoveCursorVertically(1);
293 break;
294 case WXK_PRIOR:
295 m_llist->MoveCursorVertically(-20);
296 break;
297 case WXK_NEXT:
298 m_llist->MoveCursorVertically(20);
299 break;
300 case WXK_HOME:
301 m_llist->MoveCursorToBeginOfLine();
302 break;
303 case WXK_END:
304 m_llist->MoveCursorToEndOfLine();
305 break;
306 default:
307 if(keyCode == 'c' && event.ControlDown())
308 Copy();
309 if( IsEditable() )
310 {
311 /* First, handle control keys */
312 if(event.ControlDown() && ! event.AltDown())
313 {
314 switch(keyCode)
315 {
316 case WXK_DELETE :
317 case 'd':
318 m_llist->Delete(1);
319 break;
320 case 'y':
321 m_llist->DeleteLines(1);
322 break;
323 case 'h': // like backspace
324 if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1);
325 break;
326 case 'u':
327 m_llist->DeleteToBeginOfLine();
328 break;
329 case 'k':
330 m_llist->DeleteToEndOfLine();
331 break;
332 case 'v':
333 Paste();
334 break;
335 #ifdef WXLAYOUT_DEBUG
336 case WXK_F1:
337 m_llist->SetFont(-1,-1,-1,-1,true); // underlined
338 break;
339 #endif
340 default:
341 ;
342 }
343 }
344 // ALT only:
345 else if( event.AltDown() && ! event.ControlDown() )
346 {
347 switch(keyCode)
348 {
349 case WXK_DELETE:
350 case 'd':
351 m_llist->DeleteWord();
352 break;
353 default:
354 ;
355 }
356 }
357 // no control keys:
358 else if ( ! event.AltDown() && ! event.ControlDown())
359 {
360 switch(keyCode)
361 {
362 case WXK_INSERT:
363 if(event.ShiftDown())
364 Paste();
365 break;
366 case WXK_DELETE :
367 m_llist->Delete(1);
368 break;
369 case WXK_BACK: // backspace
370 if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1);
371 break;
372 case WXK_RETURN:
373 if(m_WrapMargin > 0)
374 m_llist->WrapLine(m_WrapMargin);
375 m_llist->LineBreak();
376 break;
377 default:
378 if((!(event.ControlDown() || event.AltDown() || event.MetaDown()))
379 && (keyCode < 256 && keyCode >= 32)
380 )
381 {
382 wxString tmp;
383 tmp += keyCode;
384 if(m_WrapMargin > 0 && isspace(keyCode))
385 m_llist->WrapLine(m_WrapMargin);
386 m_llist->Insert(tmp);
387 }
388 break;
389 }
390 }
391 SetDirty();
392 SetModified();
393 }// if(IsEditable())
394 }// first switch()
395 if(m_Selecting)
396 {
397 if(event.ShiftDown())
398 m_llist->ContinueSelection();
399 else
400 {
401 m_llist->EndSelection();
402 m_Selecting = false;
403 }
404 }
405
406 ScrollToCursor();
407 wxRect r = *m_llist->GetUpdateRect();
408 DoPaint(&r);
409 }
410
411 void
412 wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
413 {
414 if(event.KeyCode() == WXK_SHIFT && m_llist->IsSelecting())
415 m_llist->EndSelection();
416 event.Skip();
417 }
418
419
420 void
421 wxLayoutWindow::ScrollToCursor(void)
422 {
423 wxClientDC dc( this );
424 PrepareDC( dc );
425
426 int x0,y0,x1,y1, dx, dy;
427
428 // Calculate where the top of the visible area is:
429 ViewStart(&x0,&y0);
430 GetScrollPixelsPerUnit(&dx, &dy);
431 x0 *= dx; y0 *= dy;
432
433 WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0, y0));
434
435 // Get the size of the visible window:
436 GetClientSize(&x1,&y1);
437 wxASSERT(x1 > 0);
438 wxASSERT(y1 > 0);
439 // As we have the values anyway, use them to avoid unnecessary
440 // scrollbar updates.
441 if(x1 > m_maxx) m_maxx = x1;
442 if(y1 > m_maxy) m_maxy = y1;
443 /* Make sure that the scrollbars are at a position so that the
444 cursor is visible if we are editing. */
445 /** Scroll so that cursor is visible! */
446 WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor));
447 wxPoint cc = m_llist->GetCursorScreenPos(*m_memDC);
448 if(cc.x < x0 || cc.y < y0
449 || cc.x >= x0+(9*x1)/10 || cc.y >= y0+(9*y1/10)) // (9*x)/10 == 90%
450 {
451 int nx, ny;
452 nx = cc.x - x1/2; if(nx < 0) nx = 0;
453 ny = cc.y - y1/2; if(ny < 0) ny = 0;
454 Scroll(nx/dx,ny/dy); // new view start
455 x0 = nx; y0 = ny;
456 m_ScrollToCursor = false; // avoid recursion
457 }
458 }
459
460 void
461 wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)) // or: OnDraw(wxDC& dc)
462 {
463 wxRect region = GetUpdateRegion().GetBox();
464 InternalPaint(& region);
465 }
466
467 void
468 wxLayoutWindow::DoPaint(const wxRect *updateRect)
469 {
470 #ifdef __WXGTK__
471 InternalPaint(updateRect);
472 #else
473 Refresh(FALSE, updateRect); // Causes bad flicker under wxGTK!!!
474 #endif
475 }
476
477 void
478 wxLayoutWindow::InternalPaint(const wxRect *updateRect)
479 {
480 wxPaintDC dc( this );
481 PrepareDC( dc );
482
483 int x0,y0,x1,y1, dx, dy;
484
485 // Calculate where the top of the visible area is:
486 ViewStart(&x0,&y0);
487 GetScrollPixelsPerUnit(&dx, &dy);
488 x0 *= dx; y0 *= dy;
489
490 // Get the size of the visible window:
491 GetClientSize(&x1,&y1);
492 wxASSERT(x1 > 0);
493 wxASSERT(y1 > 0);
494 // As we have the values anyway, use them to avoid unnecessary
495 // scrollbar updates.
496 if(x1 > m_maxx) m_maxx = x1;
497 if(y1 > m_maxy) m_maxy = y1;
498
499
500 if(updateRect)
501 {
502 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
503 updateRect->x, updateRect->y,
504 updateRect->x+updateRect->width,
505 updateRect->y+updateRect->height));
506 }
507 if(IsDirty())
508 {
509 m_llist->Layout(dc);
510 ResizeScrollbars();
511 }
512 /* Check whether the window has grown, if so, we need to reallocate
513 the bitmap to be larger. */
514 if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y)
515 {
516 wxASSERT(m_bitmapSize.x > 0);
517 wxASSERT(m_bitmapSize.y > 0);
518
519 m_memDC->SelectObject(wxNullBitmap);
520 delete m_bitmap;
521 m_bitmapSize = wxPoint(x1,y1);
522 m_bitmap = new wxBitmap(x1,y1);
523 m_memDC->SelectObject(*m_bitmap);
524 }
525
526 m_memDC->SetDeviceOrigin(0,0);
527 m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(),wxSOLID));
528 m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),
529 0,wxTRANSPARENT));
530 m_memDC->SetLogicalFunction(wxCOPY);
531
532 /* Either fill the background with the background bitmap, or clear
533 it. */
534 if(m_BGbitmap)
535 {
536 CoordType
537 y, x,
538 w = m_BGbitmap->GetWidth(),
539 h = m_BGbitmap->GetHeight();
540 for(y = 0; y < y1; y+=h)
541 for(x = 0; x < x1; x+=w)
542 m_memDC->DrawBitmap(*m_BGbitmap, x, y);
543 m_memDC->SetBackgroundMode(wxTRANSPARENT);
544 }
545 else
546 {
547 // clear the background: (must not be done if we use the update rectangle!)
548 m_memDC->SetBackgroundMode(wxSOLID);
549 m_memDC->DrawRectangle(0,0,x1, y1);
550 }
551
552
553 /* This is the important bit: we tell the list to draw itself: */
554 #if WXLO_DEBUG_URECT
555 if(updateRect)
556 {
557 WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
558 updateRect->x, updateRect->y,
559 updateRect->x+updateRect->width,
560 updateRect->y+updateRect->height));
561 }
562 #endif
563
564 // Device origins on the memDC are suspect, we translate manually
565 // with the translate parameter of Draw().
566 wxPoint offset(-x0+WXLO_XOFFSET,-y0+WXLO_YOFFSET);
567 m_llist->Draw(*m_memDC,offset, y0, y0+y1);
568
569 // We start calculating a new update rect before drawing the
570 // cursor, so that the cursor coordinates get included in the next
571 // update rectangle (although they are drawn on the memDC, this is
572 // needed to erase it):
573 m_llist->InvalidateUpdateRect();
574 if(m_CursorVisibility == 1)
575 m_llist->DrawCursor(*m_memDC,
576 m_HaveFocus && IsEditable(), // draw a thick
577 // cursor for editable windows with focus
578 offset);
579
580 // Now copy everything to the screen:
581 #if 0
582 // This somehow doesn't work, but even the following bit with the
583 // whole rect at once is still a bit broken I think.
584 wxRegionIterator ri ( GetUpdateRegion() );
585 if(ri)
586 while(ri)
587 {
588 WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
589 ri.GetX(),ri.GetY(),ri.GetW(),ri.GetH()));
590 dc.Blit(x0+ri.GetX(),y0+ri.GetY(),ri.GetW(),ri.GetH(),
591 m_memDC,ri.GetX(),ri.GetY(),wxCOPY,FALSE);
592 ri++;
593 }
594 else
595 #endif
596 {
597 // FIXME: Trying to copy only the changed parts, but it does not seem
598 // to work:
599 // x0 = updateRect->x; y0 = updateRect->y;
600 // if(updateRect->height < y1)
601 // y1 = updateRect->height;
602 // y1 += WXLO_YOFFSET; //FIXME might not be needed
603 dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
604 }
605
606 ResetDirty();
607 m_ScrollToCursor = false;
608 }
609
610 // change the range and position of scrollbars
611 void
612 wxLayoutWindow::ResizeScrollbars(bool exact)
613 {
614 wxPoint max = m_llist->GetSize();
615
616 WXLO_DEBUG(("ResizeScrollbars: GetSize: %ld, %ld", (long int)max.x,
617 (long int) max.y));
618 if(max.x > m_maxx || max.y > m_maxy
619 || max.x > m_maxx-WXLO_ROFFSET || max.y > m_maxy-WXLO_BOFFSET
620 || exact)
621 {
622 if(! exact)
623 {
624 // add an extra bit to the sizes to avoid future updates
625 max.x = max.x+WXLO_ROFFSET;
626 max.y = max.y+WXLO_BOFFSET;
627 }
628 ViewStart(&m_ViewStartX, &m_ViewStartY);
629 SetScrollbars(10, 20, max.x/10+1,max.y/20+1,m_ViewStartX,m_ViewStartY,true);
630 m_maxx = max.x; m_maxy = max.y;
631 }
632 }
633
634 void
635 wxLayoutWindow::Paste(void)
636 {
637 // Read some text
638 if (wxTheClipboard->Open())
639 {
640 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
641 wxLayoutDataObject wxldo;
642 if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
643 {
644 wxTheClipboard->GetData(&wxldo);
645 {
646 }
647 //FIXME: missing functionality m_llist->Insert(wxldo.GetList());
648 }
649 else
650 #endif
651 {
652 wxTextDataObject data;
653 if (wxTheClipboard->IsSupported( data.GetFormat() ))
654 {
655 wxTheClipboard->GetData(&data);
656 wxString text = data.GetText();
657 wxLayoutImportText( m_llist, text);
658 }
659 }
660 wxTheClipboard->Close();
661 }
662 #if 0
663 /* My attempt to get the primary selection, but it does not
664 work. :-( */
665 if(text.Length() == 0)
666 {
667 wxTextCtrl tmp_tctrl(this,-1);
668 tmp_tctrl.Paste();
669 text += tmp_tctrl.GetValue();
670 }
671 #endif
672 }
673
674 bool
675 wxLayoutWindow::Copy(bool invalidate)
676 {
677 // Calling GetSelection() will automatically do an EndSelection()
678 // on the list, but we need to take a note of it, too:
679 if(m_Selecting)
680 {
681 m_Selecting = false;
682 m_llist->EndSelection();
683 }
684
685 wxLayoutDataObject wldo;
686 wxLayoutList *llist = m_llist->GetSelection(&wldo, invalidate);
687 if(! llist)
688 return FALSE;
689 // Export selection as text:
690 wxString text;
691 wxLayoutExportObject *export;
692 wxLayoutExportStatus status(llist);
693 while((export = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
694 {
695 if(export->type == WXLO_EXPORT_TEXT)
696 text << *(export->content.text);
697 delete export;
698 }
699 delete llist;
700
701 // The exporter always appends a newline, so we chop it off if it
702 // is there:
703 {
704 size_t len = text.Length();
705 if(len > 2 && text[len-2] == '\r') // Windows
706 text = text.Mid(0,len-2);
707 else if(len > 1 && text[len-1] == '\n')
708 text = text.Mid(0,len-1);
709 }
710
711
712 if (wxTheClipboard->Open())
713 {
714 wxTextDataObject *data = new wxTextDataObject( text );
715 bool rc = wxTheClipboard->SetData( data );
716 #if wxUSE_PRIVATE_CLIPBOARD_FORMAT
717 rc |= wxTheClipboard->AddData( &wldo );
718 #endif
719 wxTheClipboard->Close();
720 return rc;
721 }
722 return FALSE;
723 }
724
725 bool
726 wxLayoutWindow::Cut(void)
727 {
728 if(Copy(false)) // do not invalidate selection after copy
729 {
730 m_llist->DeleteSelection();
731 return TRUE;
732 }
733 else
734 return FALSE;
735 }
736 bool
737 wxLayoutWindow::Find(const wxString &needle,
738 wxPoint * fromWhere)
739 {
740 wxPoint found;
741
742 if(fromWhere == NULL)
743 found = m_llist->FindText(needle, m_llist->GetCursorPos());
744 else
745 found = m_llist->FindText(needle, *fromWhere);
746 if(found.x != -1)
747 {
748 if(fromWhere)
749 {
750 *fromWhere = found;
751 fromWhere->x ++;
752 }
753 m_llist->MoveCursorTo(found);
754 ScrollToCursor();
755 return true;
756 }
757 return false;
758 }
759
760 wxMenu *
761 wxLayoutWindow::MakeFormatMenu()
762 {
763 wxMenu *m = new wxMenu(_("Layout Menu"));
764
765 m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."), false);
766 m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."), false);
767 m->AppendSeparator();
768 m->Append(WXLOWIN_MENU_UNDERLINE_ON, _("&Underline on"),_("Activate underline mode."), false);
769 m->Append(WXLOWIN_MENU_UNDERLINE_OFF,_("&Underline off"),_("Deactivate underline mode."), false);
770 m->Append(WXLOWIN_MENU_BOLD_ON ,_("&Bold on"),_("Activate bold mode."), false);
771 m->Append(WXLOWIN_MENU_BOLD_OFF ,_("&Bold off"),_("Deactivate bold mode."), false);
772 m->Append(WXLOWIN_MENU_ITALICS_ON ,_("&Italics on"),_("Activate italics mode."), false);
773 m->Append(WXLOWIN_MENU_ITALICS_OFF ,_("&Italics off"),_("Deactivate italics mode."), false);
774 m->AppendSeparator();
775 m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."), false);
776 m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."), false);
777 m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."), false);
778 return m;
779 }
780
781 void wxLayoutWindow::OnMenu(wxCommandEvent& event)
782 {
783 switch (event.GetId())
784 {
785 case WXLOWIN_MENU_LARGER:
786 m_llist->SetFontLarger(); break;
787 case WXLOWIN_MENU_SMALLER:
788 m_llist->SetFontSmaller(); break;
789 case WXLOWIN_MENU_UNDERLINE_ON:
790 m_llist->SetFontUnderline(true); break;
791 case WXLOWIN_MENU_UNDERLINE_OFF:
792 m_llist->SetFontUnderline(false); break;
793 case WXLOWIN_MENU_BOLD_ON:
794 m_llist->SetFontWeight(wxBOLD); break;
795 case WXLOWIN_MENU_BOLD_OFF:
796 m_llist->SetFontWeight(wxNORMAL); break;
797 case WXLOWIN_MENU_ITALICS_ON:
798 m_llist->SetFontStyle(wxITALIC); break;
799 case WXLOWIN_MENU_ITALICS_OFF:
800 m_llist->SetFontStyle(wxNORMAL); break;
801 case WXLOWIN_MENU_ROMAN:
802 m_llist->SetFontFamily(wxROMAN); break;
803 case WXLOWIN_MENU_TYPEWRITER:
804 m_llist->SetFontFamily(wxFIXED); break;
805 case WXLOWIN_MENU_SANSSERIF:
806 m_llist->SetFontFamily(wxSWISS); break;
807 }
808 }
809
810 void
811 wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
812 {
813 m_HaveFocus = true;
814 //FIXME: need argument DoPaint(); // to repaint the cursor
815 }
816
817 void
818 wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
819 {
820 m_HaveFocus = false;
821 //FIXME: need argument DoPaint(); // to repaint the cursor
822 }