1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrolledWindow sample
4 // Author: Robert Roebling
6 // Copyright: (C) 1998 Robert Roebling, 2002 Ron Lee, 2003 Matt Gregory
7 // (C) 2008 Vadim Zeitlin
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 // MySimpleCanvas: a scrolled window which draws a simple rectangle
29 class MySimpleCanvas
: public wxScrolledWindow
34 // these numbers are not multiple of 10 (our scroll step) to test for
35 // the absence of rounding errors (e.g. we should have one more page
36 // than WIDTH/10 to show the right side of the rectangle)
41 MySimpleCanvas(wxWindow
*parent
)
42 : wxScrolledWindow(parent
, wxID_ANY
)
44 SetScrollRate( 10, 10 );
45 SetVirtualSize( WIDTH
, HEIGHT
);
46 SetBackgroundColour( *wxWHITE
);
48 Connect(wxEVT_PAINT
, wxPaintEventHandler(MySimpleCanvas::OnPaint
));
52 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
56 // this call is vital: it adjusts the dc to account for the current
60 dc
.SetPen( *wxRED_PEN
);
61 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
62 dc
.DrawRectangle( 0, 0, WIDTH
, HEIGHT
);
67 // MySimpleFrame: a frame which contains a MySimpleCanvas
68 class MySimpleFrame
: public wxFrame
71 MySimpleFrame(wxWindow
*parent
)
72 : wxFrame(parent
, wxID_ANY
, "MySimpleCanvas")
74 new MySimpleCanvas(this);
76 // ensure that we have scrollbars initially
77 SetClientSize(MySimpleCanvas::WIDTH
/2, MySimpleCanvas::HEIGHT
/2);
83 // ----------------------------------------------------------------------
84 // a more complex example
85 // ----------------------------------------------------------------------
88 class MyCanvas
: public wxScrolledWindow
91 MyCanvas(wxWindow
*parent
);
94 void OnPaint(wxPaintEvent
& event
);
95 void OnQueryPosition(wxCommandEvent
& event
);
96 void OnAddButton(wxCommandEvent
& event
);
97 void OnDeleteButton(wxCommandEvent
& event
);
98 void OnMoveButton(wxCommandEvent
& event
);
99 void OnScrollWin(wxCommandEvent
& event
);
100 void OnMouseRightDown(wxMouseEvent
& event
);
101 void OnMouseWheel(wxMouseEvent
& event
);
105 DECLARE_EVENT_TABLE()
108 class MyCanvasFrame
: public wxFrame
111 MyCanvasFrame(wxWindow
*parent
)
112 : wxFrame(parent
, wxID_ANY
, "MyCanvas")
114 m_canvas
= new MyCanvas(this);
116 wxMenu
*menuFile
= new wxMenu();
117 menuFile
->Append(wxID_DELETE
, "&Delete all");
118 menuFile
->Append(wxID_NEW
, "Insert &new");
120 wxMenuBar
*mbar
= new wxMenuBar();
121 mbar
->Append(menuFile
, "&File");
124 Connect(wxID_DELETE
, wxEVT_COMMAND_MENU_SELECTED
,
125 wxCommandEventHandler(MyCanvasFrame::OnDeleteAll
));
126 Connect(wxID_NEW
, wxEVT_COMMAND_MENU_SELECTED
,
127 wxCommandEventHandler(MyCanvasFrame::OnInsertNew
));
133 void OnDeleteAll(wxCommandEvent
& WXUNUSED(event
))
135 m_canvas
->DestroyChildren();
138 void OnInsertNew(wxCommandEvent
& WXUNUSED(event
))
140 (void)new wxButton(m_canvas
, wxID_ANY
, "Hello", wxPoint(100,100));
146 // ----------------------------------------------------------------------------
147 // example using sizers with wxScrolledWindow
148 // ----------------------------------------------------------------------------
150 const wxSize
SMALL_BUTTON( 100, 50 );
151 const wxSize
LARGE_BUTTON( 300, 200 );
153 class MySizerScrolledWindow
: public wxScrolledWindow
156 MySizerScrolledWindow(wxWindow
*parent
);
159 // this button can be clicked to change its own size in the handler below,
160 // the window size will be automatically adjusted to fit the button
163 void OnResizeClick(wxCommandEvent
& event
);
166 class MySizerFrame
: public wxFrame
169 MySizerFrame(wxWindow
*parent
)
170 : wxFrame(parent
, wxID_ANY
, "MySizerScrolledWindow")
172 new MySizerScrolledWindow(this);
174 // ensure that the scrollbars appear when the button becomes large
175 SetClientSize(LARGE_BUTTON
/2);
180 // ----------------------------------------------------------------------------
181 // example showing scrolling only part of the window
182 // ----------------------------------------------------------------------------
184 // this window consists of an empty space in its corner, column labels window
185 // along its top, row labels window along its left hand side and a canvas in
186 // the remaining space
188 class MySubColLabels
: public wxWindow
191 MySubColLabels(wxScrolledWindow
*parent
)
192 : wxWindow(parent
, wxID_ANY
)
196 Connect(wxEVT_PAINT
, wxPaintEventHandler(MySubColLabels::OnPaint
));
200 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
204 // This is wrong.. it will translate both x and y if the
205 // window is scrolled, the label windows are active in one
206 // direction only. Do the action below instead -- RL.
207 //m_owner->PrepareDC( dc );
209 int xScrollUnits
, xOrigin
;
211 m_owner
->GetViewStart( &xOrigin
, 0 );
212 m_owner
->GetScrollPixelsPerUnit( &xScrollUnits
, 0 );
213 dc
.SetDeviceOrigin( -xOrigin
* xScrollUnits
, 0 );
215 dc
.DrawText("Column 1", 5, 5);
216 dc
.DrawText("Column 2", 105, 5);
217 dc
.DrawText("Column 3", 205, 5);
220 wxScrolledWindow
*m_owner
;
223 class MySubRowLabels
: public wxWindow
226 MySubRowLabels(wxScrolledWindow
*parent
)
227 : wxWindow(parent
, wxID_ANY
)
231 Connect(wxEVT_PAINT
, wxPaintEventHandler(MySubRowLabels::OnPaint
));
235 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
239 // This is wrong.. it will translate both x and y if the
240 // window is scrolled, the label windows are active in one
241 // direction only. Do the action below instead -- RL.
242 //m_owner->PrepareDC( dc );
244 int yScrollUnits
, yOrigin
;
246 m_owner
->GetViewStart( 0, &yOrigin
);
247 m_owner
->GetScrollPixelsPerUnit( 0, &yScrollUnits
);
248 dc
.SetDeviceOrigin( 0, -yOrigin
* yScrollUnits
);
250 dc
.DrawText("Row 1", 5, 5);
251 dc
.DrawText("Row 2", 5, 30);
252 dc
.DrawText("Row 3", 5, 55);
253 dc
.DrawText("Row 4", 5, 80);
254 dc
.DrawText("Row 5", 5, 105);
255 dc
.DrawText("Row 6", 5, 130);
258 wxScrolledWindow
*m_owner
;
261 class MySubCanvas
: public wxPanel
264 MySubCanvas(wxScrolledWindow
*parent
, wxWindow
*cols
, wxWindow
*rows
)
265 : wxPanel(parent
, wxID_ANY
)
271 (void)new wxButton(this, wxID_ANY
, "Hallo I",
272 wxPoint(0,50), wxSize(100,25) );
273 (void)new wxButton(this, wxID_ANY
, "Hallo II",
274 wxPoint(200,50), wxSize(100,25) );
276 (void)new wxTextCtrl(this, wxID_ANY
, "Text I",
277 wxPoint(0,100), wxSize(100,25) );
278 (void)new wxTextCtrl(this, wxID_ANY
, "Text II",
279 wxPoint(200,100), wxSize(100,25) );
281 (void)new wxComboBox(this, wxID_ANY
, "ComboBox I",
282 wxPoint(0,150), wxSize(100,25));
283 (void)new wxComboBox(this, wxID_ANY
, "ComboBox II",
284 wxPoint(200,150), wxSize(100,25));
286 SetBackgroundColour("WHEAT");
288 Connect(wxEVT_PAINT
, wxPaintEventHandler(MySubCanvas::OnPaint
));
291 // override the base class function so that when this window is scrolled,
292 // the labels are scrolled in sync
293 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
295 wxPanel::ScrollWindow( dx
, dy
, rect
);
296 m_colLabels
->ScrollWindow( dx
, 0, rect
);
297 m_rowLabels
->ScrollWindow( 0, dy
, rect
);
301 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
303 wxPaintDC
dc( this );
304 m_owner
->PrepareDC( dc
);
306 dc
.SetPen( *wxBLACK_PEN
);
308 // OK, let's assume we are a grid control and we have two
309 // grid cells. Here in OnPaint we want to know which cell
310 // to redraw so that we prevent redrawing cells that don't
311 // need to get redrawn. We have one cell at (0,0) and one
312 // more at (200,0), both having a size of (100,25).
314 // We can query how much the window has been scrolled
315 // by calling CalcUnscrolledPosition()
319 m_owner
->CalcUnscrolledPosition( scroll_x
, scroll_y
, &scroll_x
, &scroll_y
);
321 // We also need to know the size of the window to see which
322 // cells are completely hidden and not get redrawn
326 GetClientSize( &size_x
, &size_y
);
328 // First cell: (0,0)(100,25)
330 if ((0+100-scroll_x
> 0) && (0+25-scroll_y
> 0) &&
331 (0-scroll_x
< size_x
) && (0-scroll_y
< size_y
))
333 // Has the region on screen been exposed?
334 if (IsExposed(0,0,100,25))
336 dc
.DrawRectangle( 0, 0, 100, 25 );
337 dc
.DrawText("First Cell", 5, 5);
342 // Second cell: (0,200)(100,25)
344 if ((200+100-scroll_x
> 0) && (0+25-scroll_y
> 0) &&
345 (200-scroll_x
< size_x
) && (0-scroll_y
< size_y
))
347 // Has the region on screen been exposed?
348 if (IsExposed(200,0,100,25))
350 dc
.DrawRectangle( 200, 0, 100, 25 );
351 dc
.DrawText("Second Cell", 205, 5);
356 wxScrolledWindow
*m_owner
;
357 wxWindow
*m_colLabels
,
361 class MySubScrolledWindow
: public wxScrolledWindow
370 MySubScrolledWindow(wxWindow
*parent
)
371 : wxScrolledWindow(parent
, wxID_ANY
)
373 // create the children
374 MySubColLabels
*cols
= new MySubColLabels(this);
375 MySubRowLabels
*rows
= new MySubRowLabels(this);
377 m_canvas
= new MySubCanvas(this, cols
, rows
);
380 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 2, 10, 10);
381 sizer
->Add(CORNER_WIDTH
, CORNER_HEIGHT
); // just a spacer
382 sizer
->Add(cols
, wxSizerFlags().Expand());
383 sizer
->Add(rows
, wxSizerFlags().Expand());
384 sizer
->Add(m_canvas
, wxSizerFlags().Expand());
385 sizer
->AddGrowableRow(1);
386 sizer
->AddGrowableCol(1);
389 // this is the key call: it means that only m_canvas will be scrolled
390 // and not this window itself
391 SetTargetWindow(m_canvas
);
393 SetScrollbars(10, 10, 50, 50);
395 Connect(wxEVT_SIZE
, wxSizeEventHandler(MySubScrolledWindow::OnSize
));
399 // scrolled windows which use scroll target different from the window
400 // itself must override this virtual method
401 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
)
403 // decrease the total size by the size of the non-scrollable parts
404 // above/to the left of the canvas
405 wxSize
sizeCanvas(size
);
412 void OnSize(wxSizeEvent
& WXUNUSED(event
))
414 // We need to override OnSize so that our scrolled
415 // window a) does call Layout() to use sizers for
416 // positioning the controls but b) does not query
417 // the sizer for their size and use that for setting
418 // the scrollable area as set that ourselves by
419 // calling SetScrollbar() further down.
426 MySubCanvas
*m_canvas
;
429 class MySubFrame
: public wxFrame
432 MySubFrame(wxWindow
*parent
)
433 : wxFrame(parent
, wxID_ANY
, "MySubScrolledWindow")
435 new MySubScrolledWindow(this);
441 // ----------------------------------------------------------------------------
442 // more simple examples of wxScrolledWindow usage
443 // ----------------------------------------------------------------------------
445 // base class for both of them
446 class MyScrolledWindowBase
: public wxScrolledWindow
449 MyScrolledWindowBase(wxWindow
*parent
)
450 : wxScrolledWindow(parent
, wxID_ANY
,
451 wxDefaultPosition
, wxDefaultSize
,
456 dc
.GetTextExtent("Line 17", NULL
, &m_hLine
);
460 // the height of one line on screen
463 // the number of lines we draw
467 // this class does "stupid" redrawing - it redraws everything each time
468 // and sets the scrollbar extent directly.
470 class MyScrolledWindowDumb
: public MyScrolledWindowBase
473 MyScrolledWindowDumb(wxWindow
*parent
) : MyScrolledWindowBase(parent
)
476 SetScrollbars(0, m_hLine
, 0, m_nLines
+ 1, 0, 0, true /* no refresh */);
479 virtual void OnDraw(wxDC
& dc
);
482 // this class does "smart" redrawing - only redraws the lines which must be
483 // redrawn and sets the scroll rate and virtual size to affect the
486 // Note that this class should produce identical results to the one above.
488 class MyScrolledWindowSmart
: public MyScrolledWindowBase
491 MyScrolledWindowSmart(wxWindow
*parent
) : MyScrolledWindowBase(parent
)
494 SetScrollRate( 0, m_hLine
);
495 SetVirtualSize( wxDefaultCoord
, ( m_nLines
+ 1 ) * m_hLine
);
498 virtual void OnDraw(wxDC
& dc
);
501 // ----------------------------------------------------------------------------
502 // implements a text viewer with simple block selection to test auto-scrolling
504 // ----------------------------------------------------------------------------
506 class MyAutoScrollingWindow
: public wxScrolledWindow
509 MyAutoScrollingWindow( wxWindow
* parent
);
510 wxRect
DeviceCoordsToGraphicalChars(wxRect updRect
) const;
511 wxPoint
DeviceCoordsToGraphicalChars(wxPoint pos
) const;
512 wxPoint
GraphicalCharToDeviceCoords(wxPoint pos
) const;
513 wxRect
LogicalCoordsToGraphicalChars(wxRect updRect
) const;
514 wxPoint
LogicalCoordsToGraphicalChars(wxPoint pos
) const;
515 wxPoint
GraphicalCharToLogicalCoords(wxPoint pos
) const;
517 bool IsSelected(int chX
, int chY
) const;
518 static bool IsInside(int k
, int bound1
, int bound2
);
519 static wxRect
DCNormalize(int x
, int y
, int w
, int h
);
523 void OnDraw(wxDC
& dc
);
524 void OnMouseLeftDown(wxMouseEvent
& event
);
525 void OnMouseLeftUp(wxMouseEvent
& event
);
526 void OnMouseMove(wxMouseEvent
& event
);
527 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& event
);
528 void OnScroll(wxScrollWinEvent
& event
);
530 // test data variables
531 static const char* sm_testData
;
532 static const int sm_lineCnt
; // line count
533 static const int sm_lineLen
; // line length in characters
534 // sizes for graphical data
535 int m_fontH
, m_fontW
;
536 // selection tracking
537 wxPoint m_selStart
; // beginning of blockwise selection
538 wxPoint m_cursor
; // end of blockwise selection (mouse position)
544 DECLARE_EVENT_TABLE()
547 class MyAutoFrame
: public wxFrame
550 MyAutoFrame(wxWindow
*parent
)
551 : wxFrame(parent
, wxID_ANY
, "MyAutoScrollingWindow")
553 new MyAutoScrollingWindow(this);
560 // ----------------------------------------------------------------------------
561 // MyFrame: the main application frame showing all the classes above
562 // ----------------------------------------------------------------------------
564 class MyFrame
: public wxFrame
570 void OnAbout(wxCommandEvent
& event
);
571 void OnQuit(wxCommandEvent
& event
);
573 void OnTestSimple(wxCommandEvent
& WXUNUSED(event
)) { new MySimpleFrame(this); }
574 void OnTestCanvas(wxCommandEvent
& WXUNUSED(event
)) { new MyCanvasFrame(this); }
575 void OnTestSizer(wxCommandEvent
& WXUNUSED(event
)) { new MySizerFrame(this); }
576 void OnTestSub(wxCommandEvent
& WXUNUSED(event
)) { new MySubFrame(this); }
577 void OnTestAuto(wxCommandEvent
& WXUNUSED(event
)) { new MyAutoFrame(this); }
579 DECLARE_EVENT_TABLE()
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
586 class MyApp
: public wxApp
589 virtual bool OnInit();
593 // ============================================================================
595 // ============================================================================
597 // ----------------------------------------------------------------------------
599 // ----------------------------------------------------------------------------
601 const wxWindowID ID_ADDBUTTON
= wxWindow::NewControlId();
602 const wxWindowID ID_DELBUTTON
= wxWindow::NewControlId();
603 const wxWindowID ID_MOVEBUTTON
= wxWindow::NewControlId();
604 const wxWindowID ID_SCROLLWIN
= wxWindow::NewControlId();
605 const wxWindowID ID_QUERYPOS
= wxWindow::NewControlId();
607 const wxWindowID ID_NEWBUTTON
= wxWindow::NewControlId();
609 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
610 EVT_PAINT( MyCanvas::OnPaint
)
611 EVT_RIGHT_DOWN( MyCanvas::OnMouseRightDown
)
612 EVT_MOUSEWHEEL( MyCanvas::OnMouseWheel
)
613 EVT_BUTTON( ID_QUERYPOS
, MyCanvas::OnQueryPosition
)
614 EVT_BUTTON( ID_ADDBUTTON
, MyCanvas::OnAddButton
)
615 EVT_BUTTON( ID_DELBUTTON
, MyCanvas::OnDeleteButton
)
616 EVT_BUTTON( ID_MOVEBUTTON
, MyCanvas::OnMoveButton
)
617 EVT_BUTTON( ID_SCROLLWIN
, MyCanvas::OnScrollWin
)
620 MyCanvas::MyCanvas(wxWindow
*parent
)
621 : wxScrolledWindow(parent
, wxID_ANY
,
622 wxDefaultPosition
, wxDefaultSize
,
623 wxSUNKEN_BORDER
| wxTAB_TRAVERSAL
)
625 // you can use either a single SetScrollbars() call or these 2 functions,
626 // usually using them is better because you normally won't need to change
627 // the scroll rate in the future and the sizer can be used to update the
628 // virtual size automatically
629 SetScrollRate( 10, 10 );
630 SetVirtualSize( 500, 1000 );
632 (void) new wxButton( this, ID_ADDBUTTON
, "add button", wxPoint(10,10) );
633 (void) new wxButton( this, ID_DELBUTTON
, "del button", wxPoint(10,40) );
634 (void) new wxButton( this, ID_MOVEBUTTON
, "move button", wxPoint(150,10) );
635 (void) new wxButton( this, ID_SCROLLWIN
, "scroll win", wxPoint(250,10) );
637 wxPanel
*test
= new wxPanel( this, wxID_ANY
,
638 wxPoint(10, 110), wxSize(130,50),
639 wxSIMPLE_BORDER
| wxTAB_TRAVERSAL
);
640 test
->SetBackgroundColour( "WHEAT" );
642 SetBackgroundColour( "BLUE" );
645 void MyCanvas::OnMouseRightDown( wxMouseEvent
&event
)
647 wxPoint
pt( event
.GetPosition() );
649 CalcUnscrolledPosition( pt
.x
, pt
.y
, &x
, &y
);
650 wxLogMessage("Mouse down event at: %d %d, scrolled: %d %d",
654 void MyCanvas::OnMouseWheel( wxMouseEvent
&event
)
656 wxPoint
pt( event
.GetPosition() );
658 CalcUnscrolledPosition( pt
.x
, pt
.y
, &x
, &y
);
659 wxLogMessage( "Mouse wheel event at: %d %d, scrolled: %d %d\n"
660 "Rotation: %d, delta = %d",
662 event
.GetWheelRotation(), event
.GetWheelDelta() );
667 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
669 wxPaintDC
dc( this );
672 dc
.DrawText( "Press right mouse button to test calculations!", 160, 50 );
674 dc
.DrawText( "Some text", 140, 140 );
676 dc
.DrawRectangle( 100, 160, 200, 200 );
679 void MyCanvas::OnQueryPosition( wxCommandEvent
&WXUNUSED(event
) )
681 wxPoint
pt( m_button
->GetPosition() );
682 wxLogMessage( "Position of \"Query position\" is %d %d", pt
.x
, pt
.y
);
683 pt
= ClientToScreen( pt
);
684 wxLogMessage("Position of \"Query position\" on screen is %d %d",
688 void MyCanvas::OnAddButton( wxCommandEvent
&WXUNUSED(event
) )
690 wxLogMessage( "Inserting button at position 10,70..." );
691 wxButton
*button
= new wxButton( this, ID_NEWBUTTON
, "new button",
692 wxPoint(10,70), wxSize(80,25) );
693 wxPoint
pt( button
->GetPosition() );
694 wxLogMessage( "-> Position after inserting %d %d", pt
.x
, pt
.y
);
697 void MyCanvas::OnDeleteButton( wxCommandEvent
&WXUNUSED(event
) )
699 wxLogMessage( "Deleting button inserted with \"Add button\"..." );
700 wxWindow
*win
= FindWindow( ID_NEWBUTTON
);
704 wxLogMessage( "-> No window with id = ID_NEWBUTTON found." );
707 void MyCanvas::OnMoveButton( wxCommandEvent
&event
)
709 wxLogMessage( "Moving button 10 pixels downward.." );
710 wxWindow
*win
= FindWindow( event
.GetId() );
711 wxPoint
pt( win
->GetPosition() );
712 wxLogMessage( "-> Position before move is %d %d", pt
.x
, pt
.y
);
713 win
->Move( wxDefaultCoord
, pt
.y
+ 10 );
714 pt
= win
->GetPosition();
715 wxLogMessage( "-> Position after move is %d %d", pt
.x
, pt
.y
);
718 void MyCanvas::OnScrollWin( wxCommandEvent
&WXUNUSED(event
) )
720 wxLogMessage("Scrolling 2 units up.\n"
721 "The white square and the controls should move equally!");
723 GetViewStart( &x
, &y
);
724 Scroll( wxDefaultCoord
, y
+2 );
727 // ----------------------------------------------------------------------------
728 // MySizerScrolledWindow
729 // ----------------------------------------------------------------------------
731 MySizerScrolledWindow::MySizerScrolledWindow(wxWindow
*parent
)
732 : wxScrolledWindow(parent
)
734 SetBackgroundColour( "GREEN" );
736 // Set the rate we'd like for scrolling.
738 SetScrollRate( 5, 5 );
740 // Populate a sizer with a 'resizing' button and some other static
743 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2);
745 m_button
= new wxButton( this, wxID_RESIZE_FRAME
, "Press me",
746 wxDefaultPosition
, SMALL_BUTTON
);
748 sizer
->Add(m_button
, wxSizerFlags().Centre().Border(20));
749 sizer
->Add(new wxStaticText(this, wxID_ANY
, "This is just"),
750 wxSizerFlags().Centre());
751 sizer
->Add(new wxStaticText(this, wxID_ANY
, "some decoration"),
752 wxSizerFlags().Centre());
753 sizer
->Add(new wxStaticText(this, wxID_ANY
, "for you to scroll..."),
754 wxSizerFlags().Centre());
756 // Then use the sizer to set the scrolled region size.
760 Connect(wxID_RESIZE_FRAME
, wxEVT_COMMAND_BUTTON_CLICKED
,
761 wxCommandEventHandler(MySizerScrolledWindow::OnResizeClick
));
764 void MySizerScrolledWindow::OnResizeClick(wxCommandEvent
&WXUNUSED(event
))
766 // Arbitrarily resize the button to change the minimum size of
767 // the (scrolled) sizer.
769 if ( m_button
->GetSize() == SMALL_BUTTON
)
770 m_button
->SetSizeHints(LARGE_BUTTON
);
772 m_button
->SetSizeHints(SMALL_BUTTON
);
774 // Force update layout and scrollbars, since nothing we do here
775 // necessarily generates a size event which would do it for us.
779 // ----------------------------------------------------------------------------
781 // ----------------------------------------------------------------------------
783 const wxWindowID Scroll_Test_Simple
= wxWindow::NewControlId();
784 const wxWindowID Scroll_Test_Canvas
= wxWindow::NewControlId();
785 const wxWindowID Scroll_Test_Sizers
= wxWindow::NewControlId();
786 const wxWindowID Scroll_Test_Sub
= wxWindow::NewControlId();
787 const wxWindowID Scroll_Test_Auto
= wxWindow::NewControlId();
789 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
790 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
791 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
793 EVT_MENU(Scroll_Test_Simple
, MyFrame::OnTestSimple
)
794 EVT_MENU(Scroll_Test_Canvas
, MyFrame::OnTestCanvas
)
795 EVT_MENU(Scroll_Test_Sizers
, MyFrame::OnTestSizer
)
796 EVT_MENU(Scroll_Test_Sub
, MyFrame::OnTestSub
)
797 EVT_MENU(Scroll_Test_Auto
, MyFrame::OnTestAuto
)
801 : wxFrame(NULL
, wxID_ANY
, "wxWidgets scroll sample")
803 wxMenu
*menuFile
= new wxMenu
;
804 menuFile
->Append(wxID_ABOUT
, "&About..");
805 menuFile
->AppendSeparator();
806 menuFile
->Append(wxID_EXIT
, "E&xit\tAlt-X");
808 wxMenu
*menuTest
= new wxMenu
;
809 menuTest
->Append(Scroll_Test_Simple
, "&Simple scroll window\tF1",
810 "Simplest possible scrolled window test.");
811 menuTest
->Append(Scroll_Test_Canvas
, "Scrolled window with &children\tF2",
812 "Scrolled window with controls on it.");
813 menuTest
->Append(Scroll_Test_Sizers
, "Scrolled window with si&zer\tF3",
814 "Scrolled window with children managed by sizer.");
815 menuTest
->Append(Scroll_Test_Sub
, "Scrolled s&ub-window\tF4",
816 "Window only part of which is scrolled.");
817 menuTest
->Append(Scroll_Test_Auto
, "&Auto-scrolled window\tF5",
818 "Window which scrolls when the mouse is held pressed "
821 wxMenuBar
*mbar
= new wxMenuBar
;
822 mbar
->Append(menuFile
, "&File");
823 mbar
->Append(menuTest
, "&Test");
828 const wxSizerFlags
flagsExpand(wxSizerFlags(1).Expand());
830 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
831 topsizer
->Add(new wxStaticText(this, wxID_ANY
,
832 "The windows below should behave in the same way, even though\n"
833 "they're implemented quite differently, see the code for details.\n"
835 "The lines redrawn during odd/even repaint iterations are drawn in\n"
836 "red/blue colour to allow seeing immediately how much is repainted,\n"
837 "don't be surprised by this."),
838 wxSizerFlags().Centre().Border());
840 wxSizer
*sizerBtm
= new wxBoxSizer(wxHORIZONTAL
);
841 sizerBtm
->Add(new MyScrolledWindowDumb(this), flagsExpand
);
842 sizerBtm
->Add(new MyScrolledWindowSmart(this), flagsExpand
);
843 topsizer
->Add(sizerBtm
, flagsExpand
);
851 void MyFrame::OnQuit(wxCommandEvent
&WXUNUSED(event
))
856 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
858 (void)wxMessageBox( "wxScrolledWindow sample\n"
860 "Robert Roebling (c) 1998\n"
861 "Vadim Zeitlin (c) 2008\n"
862 "Autoscrolling examples\n"
864 "Auto-timed-scrolling example\n"
865 "Matt Gregory (c) 2003\n",
866 "About wxWidgets scroll sample",
867 wxICON_INFORMATION
| wxOK
);
870 // ----------------------------------------------------------------------------
872 // ----------------------------------------------------------------------------
878 if ( !wxApp::OnInit() )
886 // ----------------------------------------------------------------------------
887 // MyScrolledWindowXXX
888 // ----------------------------------------------------------------------------
890 void MyScrolledWindowDumb::OnDraw(wxDC
& dc
)
892 // this is useful to see which lines are redrawn
893 static size_t s_redrawCount
= 0;
894 dc
.SetTextForeground(s_redrawCount
++ % 2 ? *wxRED
: *wxBLUE
);
897 for ( size_t line
= 0; line
< m_nLines
; line
++ )
900 CalcScrolledPosition(0, y
, NULL
, &yPhys
);
902 dc
.DrawText(wxString::Format("Line %u (logical %d, physical %d)",
903 unsigned(line
), y
, yPhys
), 0, y
);
908 void MyScrolledWindowSmart::OnDraw(wxDC
& dc
)
910 // this is useful to see which lines are redrawn
911 static size_t s_redrawCount
= 0;
912 dc
.SetTextForeground(s_redrawCount
++ % 2 ? *wxRED
: *wxBLUE
);
914 // update region is always in device coords, translate to logical ones
915 wxRect rectUpdate
= GetUpdateRegion().GetBox();
916 CalcUnscrolledPosition(rectUpdate
.x
, rectUpdate
.y
,
917 &rectUpdate
.x
, &rectUpdate
.y
);
919 size_t lineFrom
= rectUpdate
.y
/ m_hLine
,
920 lineTo
= rectUpdate
.GetBottom() / m_hLine
;
922 if ( lineTo
> m_nLines
- 1)
923 lineTo
= m_nLines
- 1;
925 int y
= lineFrom
*m_hLine
;
926 for ( size_t line
= lineFrom
; line
<= lineTo
; line
++ )
929 CalcScrolledPosition(0, y
, NULL
, &yPhys
);
931 dc
.DrawText(wxString::Format("Line %u (logical %d, physical %d)",
932 unsigned(line
), y
, yPhys
), 0, y
);
937 // ----------------------------------------------------------------------------
938 // MyAutoScrollingWindow
939 // ----------------------------------------------------------------------------
941 BEGIN_EVENT_TABLE(MyAutoScrollingWindow
, wxScrolledWindow
)
942 EVT_LEFT_DOWN(MyAutoScrollingWindow::OnMouseLeftDown
)
943 EVT_LEFT_UP(MyAutoScrollingWindow::OnMouseLeftUp
)
944 EVT_MOTION(MyAutoScrollingWindow::OnMouseMove
)
945 EVT_MOUSE_CAPTURE_LOST(MyAutoScrollingWindow::OnMouseCaptureLost
)
946 EVT_SCROLLWIN(MyAutoScrollingWindow::OnScroll
)
949 MyAutoScrollingWindow::MyAutoScrollingWindow(wxWindow
* parent
)
950 : wxScrolledWindow(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
951 wxVSCROLL
| wxHSCROLL
| wxSUNKEN_BORDER
),
954 m_font(9, wxFONTFAMILY_TELETYPE
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
)
957 // query dc for text size
959 dc
.GetTextExtent(wxString("A"), &m_fontW
, &m_fontH
);
960 // set up the virtual window
961 SetScrollbars(m_fontW
, m_fontH
, sm_lineLen
, sm_lineCnt
);
965 MyAutoScrollingWindow::DeviceCoordsToGraphicalChars(wxRect updRect
) const
967 wxPoint
pos(updRect
.GetPosition());
968 pos
= DeviceCoordsToGraphicalChars(pos
);
971 updRect
.width
/= m_fontW
;
972 updRect
.height
/= m_fontH
;
973 // the *CoordsToGraphicalChars() funcs round down to upper-left corner,
974 // so an off-by-one correction is needed
975 ++updRect
.width
; // kludge
976 ++updRect
.height
; // kludge
981 MyAutoScrollingWindow::DeviceCoordsToGraphicalChars(wxPoint pos
) const
986 GetViewStart(&vX
, &vY
);
993 MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos
) const
996 GetViewStart(&vX
, &vY
);
1005 MyAutoScrollingWindow::LogicalCoordsToGraphicalChars(wxRect updRect
) const
1007 wxPoint
pos(updRect
.GetPosition());
1008 pos
= LogicalCoordsToGraphicalChars(pos
);
1011 updRect
.width
/= m_fontW
;
1012 updRect
.height
/= m_fontH
;
1013 // the *CoordsToGraphicalChars() funcs round down to upper-left corner,
1014 // so an off-by-one correction is needed
1015 ++updRect
.width
; // kludge
1016 ++updRect
.height
; // kludge
1021 MyAutoScrollingWindow::LogicalCoordsToGraphicalChars(wxPoint pos
) const
1029 MyAutoScrollingWindow::GraphicalCharToLogicalCoords(wxPoint pos
) const
1036 void MyAutoScrollingWindow::MyRefresh()
1038 static wxPoint
lastSelStart(-1, -1), lastCursor(-1, -1);
1039 // refresh last selected area (to deselect previously selected text)
1041 GraphicalCharToDeviceCoords(lastSelStart
),
1042 GraphicalCharToDeviceCoords(lastCursor
)
1044 // off-by-one corrections, necessary because it's not possible to know
1045 // when to round up until rect is normalized by lastUpdRect constructor
1046 lastUpdRect
.width
+= m_fontW
; // kludge
1047 lastUpdRect
.height
+= m_fontH
; // kludge
1048 // refresh currently selected (to select previously unselected text)
1050 GraphicalCharToDeviceCoords(m_selStart
),
1051 GraphicalCharToDeviceCoords(m_cursor
)
1053 // off-by-one corrections
1054 updRect
.width
+= m_fontW
; // kludge
1055 updRect
.height
+= m_fontH
; // kludge
1056 // find necessary refresh areas
1057 int rx
= lastUpdRect
.x
;
1058 int ry
= lastUpdRect
.y
;
1059 int rw
= updRect
.x
- lastUpdRect
.x
;
1060 int rh
= lastUpdRect
.height
;
1062 RefreshRect(DCNormalize(rx
, ry
, rw
, rh
));
1065 ry
= updRect
.y
+ updRect
.height
;
1067 rh
= (lastUpdRect
.y
+ lastUpdRect
.height
) - (updRect
.y
+ updRect
.height
);
1069 RefreshRect(DCNormalize(rx
, ry
, rw
, rh
));
1071 rx
= updRect
.x
+ updRect
.width
;
1073 rw
= (lastUpdRect
.x
+ lastUpdRect
.width
) - (updRect
.x
+ updRect
.width
);
1074 rh
= lastUpdRect
.height
;
1076 RefreshRect(DCNormalize(rx
, ry
, rw
, rh
));
1081 rh
= updRect
.y
- lastUpdRect
.y
;
1083 RefreshRect(DCNormalize(rx
, ry
, rw
, rh
));
1086 lastSelStart
= m_selStart
;
1087 lastCursor
= m_cursor
;
1090 bool MyAutoScrollingWindow::IsSelected(int chX
, int chY
) const
1092 if (IsInside(chX
, m_selStart
.x
, m_cursor
.x
)
1093 && IsInside(chY
, m_selStart
.y
, m_cursor
.y
)) {
1099 bool MyAutoScrollingWindow::IsInside(int k
, int bound1
, int bound2
)
1101 if ((k
>= bound1
&& k
<= bound2
) || (k
>= bound2
&& k
<= bound1
)) {
1108 MyAutoScrollingWindow::DCNormalize(int x
, int y
, int w
, int h
)
1110 // this is needed to get rid of the graphical remnants from the selection
1111 // I think it's because DrawRectangle() excludes a pixel in either direction
1112 const int kludge
= 1;
1113 // make (x, y) the top-left corner
1128 return wxRect(x
, y
, w
, h
);
1131 void MyAutoScrollingWindow::OnDraw(wxDC
& dc
)
1134 wxBrush
normBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)
1136 wxBrush
selBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
)
1138 dc
.SetPen(*wxTRANSPARENT_PEN
);
1139 const wxString str
= sm_testData
;
1140 size_t strLength
= str
.length();
1141 wxString::const_iterator str_i
;
1143 // draw the characters
1144 // 1. for each update region
1145 for (wxRegionIterator
upd(GetUpdateRegion()); upd
; ++upd
) {
1146 wxRect updRect
= upd
.GetRect();
1147 wxRect
updRectInGChars(DeviceCoordsToGraphicalChars(updRect
));
1148 // 2. for each row of chars in the update region
1149 for (int chY
= updRectInGChars
.y
1150 ; chY
<= updRectInGChars
.y
+ updRectInGChars
.height
; ++chY
) {
1151 // 3. for each character in the row
1152 bool isFirstX
= true;
1153 for (int chX
= updRectInGChars
.x
1154 ; chX
<= updRectInGChars
.x
+ updRectInGChars
.width
1157 if (IsSelected(chX
, chY
)) {
1158 dc
.SetBrush(selBrush
);
1159 dc
.SetTextForeground( wxSystemSettings::GetColour
1160 (wxSYS_COLOUR_HIGHLIGHTTEXT
));
1162 dc
.SetBrush(normBrush
);
1163 dc
.SetTextForeground( wxSystemSettings::GetColour
1164 (wxSYS_COLOUR_WINDOWTEXT
));
1166 // 5. find position info
1167 wxPoint charPos
= GraphicalCharToLogicalCoords(wxPoint
1170 dc
.DrawRectangle(charPos
.x
, charPos
.y
, m_fontW
, m_fontH
);
1171 size_t charIndex
= chY
* sm_lineLen
+ chX
;
1172 if (chY
< sm_lineCnt
&&
1174 charIndex
< strLength
)
1178 str_i
= str
.begin() + charIndex
;
1181 dc
.DrawText(*str_i
, charPos
.x
, charPos
.y
);
1189 void MyAutoScrollingWindow::OnMouseLeftDown(wxMouseEvent
& event
)
1191 // initial press of mouse button sets the beginning of the selection
1192 m_selStart
= DeviceCoordsToGraphicalChars(event
.GetPosition());
1193 // set the cursor to the same position
1194 m_cursor
= m_selStart
;
1195 // draw/erase selection
1199 void MyAutoScrollingWindow::OnMouseLeftUp(wxMouseEvent
& WXUNUSED(event
))
1201 // this test is necessary
1208 void MyAutoScrollingWindow::OnMouseMove(wxMouseEvent
& event
)
1210 // if user is dragging
1211 if (event
.Dragging() && event
.LeftIsDown()) {
1212 // set the new cursor position
1213 m_cursor
= DeviceCoordsToGraphicalChars(event
.GetPosition());
1214 // draw/erase selection
1216 // capture mouse to activate auto-scrolling
1217 if (!HasCapture()) {
1224 MyAutoScrollingWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
&
1227 // we only capture mouse for timed scrolling, so nothing is needed here
1228 // other than making sure to not call event.Skip()
1231 void MyAutoScrollingWindow::OnScroll(wxScrollWinEvent
& event
)
1233 // need to move the cursor when autoscrolling
1234 // FIXME: the cursor also moves when the scrollbar arrows are clicked
1236 if (event
.GetOrientation() == wxHORIZONTAL
) {
1237 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
) {
1239 } else if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
) {
1242 } else if (event
.GetOrientation() == wxVERTICAL
) {
1243 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
) {
1245 } else if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
) {
1254 const int MyAutoScrollingWindow::sm_lineCnt
= 125;
1255 const int MyAutoScrollingWindow::sm_lineLen
= 79;
1256 const char *MyAutoScrollingWindow::sm_testData
=
1257 "162 Cult of the genius out of vanity. Because we think well of ourselves, but "
1258 "nonetheless never suppose ourselves capable of producing a painting like one of "
1259 "Raphael's or a dramatic scene like one of Shakespeare's, we convince ourselves "
1260 "that the capacity to do so is quite extraordinarily marvelous, a wholly "
1261 "uncommon accident, or, if we are still religiously inclined, a mercy from on "
1262 "high. Thus our vanity, our self-love, promotes the cult of the genius: for only "
1263 "if we think of him as being very remote from us, as a miraculum, does he not "
1264 "aggrieve us (even Goethe, who was without envy, called Shakespeare his star of "
1265 "the most distant heights [\"William! Stern der schonsten Ferne\": from Goethe's, "
1266 "\"Between Two Worlds\"]; in regard to which one might recall the lines: \"the "
1267 "stars, these we do not desire\" [from Goethe's, \"Comfort in Tears\"]). But, aside "
1268 "from these suggestions of our vanity, the activity of the genius seems in no "
1269 "way fundamentally different from the activity of the inventor of machines, the "
1270 "scholar of astronomy or history, the master of tactics. All these activities "
1271 "are explicable if one pictures to oneself people whose thinking is active in "
1272 "one direction, who employ everything as material, who always zealously observe "
1273 "their own inner life and that of others, who perceive everywhere models and "
1274 "incentives, who never tire of combining together the means available to them. "
1275 "Genius too does nothing except learn first how to lay bricks then how to build, "
1276 "except continually seek for material and continually form itself around it. "
1277 "Every activity of man is amazingly complicated, not only that of the genius: "
1278 "but none is a \"miracle.\" Whence, then, the belief that genius exists only in "
1279 "the artist, orator and philosopher? that only they have \"intuition\"? (Whereby "
1280 "they are supposed to possess a kind of miraculous eyeglass with which they can "
1281 "see directly into \"the essence of the thing\"!) It is clear that people speak of "
1282 "genius only where the effects of the great intellect are most pleasant to them "
1283 "and where they have no desire to feel envious. To call someone \"divine\" means: "
1284 "\"here there is no need for us to compete.\" Then, everything finished and "
1285 "complete is regarded with admiration, everything still becoming is undervalued. "
1286 "But no one can see in the work of the artist how it has become; that is its "
1287 "advantage, for wherever one can see the act of becoming one grows somewhat "
1288 "cool. The finished and perfect art of representation repulses all thinking as "
1289 "to how it has become; it tyrannizes as present completeness and perfection. "
1290 "That is why the masters of the art of representation count above all as gifted "
1291 "with genius and why men of science do not. In reality, this evaluation of the "
1292 "former and undervaluation of the latter is only a piece of childishness in the "
1295 "163 The serious workman. Do not talk about giftedness, inborn talents! One can "
1296 "name great men of all kinds who were very little gifted. The acquired "
1297 "greatness, became \"geniuses\" (as we put it), through qualities the lack of "
1298 "which no one who knew what they were would boast of: they all possessed that "
1299 "seriousness of the efficient workman which first learns to construct the parts "
1300 "properly before it ventures to fashion a great whole; they allowed themselves "
1301 "time for it, because they took more pleasure in making the little, secondary "
1302 "things well than in the effect of a dazzling whole. the recipe for becoming a "
1303 "good novelist, for example, is easy to give, but to carry it out presupposes "
1304 "qualities one is accustomed to overlook when one says \"I do not have enough "
1305 "talent.\" One has only to make a hundred or so sketches for novels, none longer "
1306 "than two pages but of such distinctness that every word in them is necessary; "
1307 "one should write down anecdotes each day until one has learned how to give them "
1308 "the most pregnant and effective form; one should be tireless in collecting and "
1309 "describing human types and characters; one should above all relate things to "
1310 "others and listen to others relate, keeping one's eyes and ears open for the "
1311 "effect produced on those present, one should travel like a landscape painter or "
1312 "costume designer; one should excerpt for oneself out of the individual sciences "
1313 "everything that will produce an artistic effect when it is well described, one "
1314 "should, finally, reflect on the motives of human actions, disdain no signpost "
1315 "to instruction about them and be a collector of these things by day and night. "
1316 "One should continue in this many-sided exercise some ten years: what is then "
1317 "created in the workshop, however, will be fit to go out into the world. What, "
1318 "however, do most people do? They begin, not with the parts, but with the whole. "
1319 "Perhaps they chance to strike a right note, excite attention and from then on "
1320 "strike worse and worse notes, for good, natural reasons. Sometimes, when the "
1321 "character and intellect needed to formulate such a life-plan are lacking, fate "
1322 "and need take their place and lead the future master step by step through all "
1323 "the stipulations of his trade. "
1325 "164 Peril and profit in the cult of the genius. The belief in great, superior, "
1326 "fruitful spirits is not necessarily, yet nonetheless is very frequently "
1327 "associated with that religious or semi-religious superstition that these "
1328 "spirits are of supra-human origin and possess certain miraculous abilities by "
1329 "virtue of which they acquire their knowledge by quite other means than the rest "
1330 "of mankind. One ascribes to them, it seems, a direct view of the nature of the "
1331 "world, as it were a hole in the cloak of appearance, and believes that, by "
1332 "virtue of this miraculous seer's vision, they are able to communicate something "
1333 "conclusive and decisive about man and the world without the toil and "
1334 "rigorousness required by science. As long as there continue to be those who "
1335 "believe in the miraculous in the domain of knowledge one can perhaps concede "
1336 "that these people themselves derive some benefit from their belief, inasmuch as "
1337 "through their unconditional subjection to the great spirits they create for "
1338 "their own spirit during its time of development the finest form of discipline "
1339 "and schooling. On the other hand, it is at least questionable whether the "
1340 "superstitious belief in genius, in its privileges and special abilities, is of "
1341 "benefit to the genius himself if it takes root in him. It is in any event a "
1342 "dangerous sign when a man is assailed by awe of himself, whether it be the "
1343 "celebrated Caesar's awe of Caesar or the awe of one's own genius now under "
1344 "consideration; when the sacrificial incense which is properly rendered only to "
1345 "a god penetrates the brain of the genius, so that his head begins to swim and "
1346 "he comes to regard himself as something supra-human. The consequences that "
1347 "slowly result are: the feeling of irresponsibility, of exceptional rights, the "
1348 "belief that he confers a favor by his mere presence, insane rage when anyone "
1349 "attempts even to compare him with others, let alone to rate him beneath them, "
1350 "or to draw attention to lapses in his work. Because he ceases to practice "
1351 "criticism of himself, at last one pinion after the other falls out of his "
1352 "plumage: that superstitious eats at the roots of his powers and perhaps even "
1353 "turns him into a hypocrite after his powers have fled from him. For the great "
1354 "spirits themselves it is therefore probably more beneficial if they acquire an "
1355 "insight into the nature and origin of their powers, if they grasp, that is to "
1356 "say, what purely human qualities have come together in them and what fortunate "
1357 "circumstances attended them: in the first place undiminished energy, resolute "
1358 "application to individual goals, great personal courage, then the good fortune "
1359 "to receive an upbringing which offered in the early years the finest teachers, "
1360 "models and methods. To be sure, when their goal is the production of the "
1361 "greatest possible effect, unclarity with regard to oneself and that "
1362 "semi-insanity superadded to it has always achieved much; for what has been "
1363 "admired and envied at all times has been that power in them by virtue of which "
1364 "they render men will-less and sweep them away into the delusion that the "
1365 "leaders they are following are supra-natural. Indeed, it elevates and inspires "
1366 "men to believe that someone is in possession of supra-natural powers: to this "
1367 "extent Plato was right to say [Plato: Phaedrus, 244a] that madness has brought "
1368 "the greatest of blessings upon mankind. In rare individual cases this portion "
1369 "of madness may, indeed, actually have been the means by which such a nature, "
1370 "excessive in all directions, was held firmly together: in the life of "
1371 "individuals, too, illusions that are in themselves poisons often play the role "
1372 "of healers; yet, in the end, in the case of every \"genius\" who believes in his "
1373 "own divinity the poison shows itself to the same degree as his \"genius\" grows "
1374 "old: one may recall, for example, the case of Napoleon, whose nature certainly "
1375 "grew into the mighty unity that sets him apart from all men of modern times "
1376 "precisely through his belief in himself and his star and through the contempt "
1377 "for men that flowed from it; until in the end, however, this same belief went "
1378 "over into an almost insane fatalism, robbed him of his acuteness and swiftness "
1379 "of perception, and became the cause of his destruction.";