]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.cpp
Cleared up DEBUG define mess, defines are now called __WXDEBUG__ and WXDEBUG.
[wxWidgets.git] / user / wxLayout / wxlwindow.cpp
1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
3 * *
4 * (C) 1998 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 "wxlwindow.h"
14
15 #define VAR(x) cout << #x"=" << x << endl;
16
17 BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
18 EVT_PAINT (wxLayoutWindow::OnPaint)
19 EVT_CHAR (wxLayoutWindow::OnChar)
20 EVT_LEFT_DOWN(wxLayoutWindow::OnMouse)
21 END_EVENT_TABLE()
22
23 wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
24 : wxScrolledWindow(parent)
25 {
26 m_ScrollbarsSet = false;
27 m_EventId = 0;
28 }
29
30 void
31 wxLayoutWindow::OnMouse(wxMouseEvent& event)
32 {
33 if(m_EventId == 0) // nothing to do
34 return;
35
36 m_FindPos.x = event.GetX();
37 m_FindPos.y = event.GetY();
38 m_FoundObject = NULL;
39
40 #ifdef WXDEBUG
41 cerr << "OnMouse: " << m_FindPos.x << ',' << m_FindPos.y << endl;
42 #endif
43 Refresh();
44 if(m_FoundObject)
45 {
46 if(m_EventId)
47 {
48 wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, m_EventId);
49 commandEvent.SetEventObject( this );
50 GetEventHandler()->ProcessEvent(commandEvent);
51 }
52 }
53 }
54
55 /*
56 * some simple keyboard handling
57 */
58 void
59 wxLayoutWindow::OnChar(wxKeyEvent& event)
60 {
61 long keyCode = event.KeyCode();
62
63 switch(event.KeyCode())
64 {
65 case WXK_RIGHT:
66 m_llist.MoveCursor(1);
67 break;
68 case WXK_LEFT:
69 m_llist.MoveCursor(-1);
70 break;
71 case WXK_UP:
72 m_llist.MoveCursor(0,-1);
73 break;
74 case WXK_DOWN:
75 m_llist.MoveCursor(0,1);
76 break;
77 case WXK_PRIOR:
78 m_llist.MoveCursor(0,-20);
79 break;
80 case WXK_NEXT:
81 m_llist.MoveCursor(0,20);
82 break;
83 case WXK_DELETE :
84 m_llist.Delete(1);
85 break;
86 case WXK_BACK: // backspace
87 m_llist.MoveCursor(-1);
88 m_llist.Delete(1);
89 break;
90 case WXK_RETURN:
91 m_llist.LineBreak();
92 break;
93 #ifdef WXDEBUG
94 case WXK_F1:
95 m_llist.Debug();
96 break;
97 #endif
98 default:
99 if(keyCode < 256 && keyCode >= 32)
100 {
101 wxString tmp;
102 tmp += keyCode;
103 m_llist.Insert(tmp);
104 }
105 break;
106 }
107 Refresh();
108 UpdateScrollbars();
109 }
110
111 void
112 wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)w) // or: OnDraw(wxDC& dc)
113 {
114 wxPaintDC dc( this ); // only when used as OnPaint for OnDraw we
115 PrepareDC( dc ); // can skip the first two lines
116
117 if(m_EventId) // look for keyclicks
118 m_FoundObject = m_llist.Draw(dc,true,m_FindPos);
119 else
120 m_llist.Draw(dc);
121 if(! m_ScrollbarsSet)
122 {
123 m_ScrollbarsSet = true; // avoid recursion
124 UpdateScrollbars();
125 }
126 }
127
128 void
129 wxLayoutWindow::UpdateScrollbars(void)
130 {
131 CoordType
132 max_x, max_y, lineHeight;
133
134 m_llist.GetSize(&max_x, &max_y, &lineHeight);
135 SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1);
136 EnableScrolling(true,true);
137 }
138
139 void
140 wxLayoutWindow::Print(void)
141 {
142 wxPostScriptDC dc("layout.ps",true,this);
143 if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
144 {
145 //dc.SetUserScale(1.0, 1.0);
146 m_llist.Draw(dc);
147 dc.EndDoc();
148 }
149 }