]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.cpp
Looks like I've fixed the editing
[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 = -1;
28 }
29
30 void
31 wxLayoutWindow::OnMouse(wxMouseEvent& event)
32 {
33 if(m_EventId == -1) // 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 WXLAYOUT_DEBUG
41 cerr << "OnMouse: " << m_FindPos.x << ',' << m_FindPos.y << endl;
42 #endif
43 Refresh();
44 if(m_FoundObject)
45 {
46 if(m_EventId != -1)
47 {
48 wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, m_EventId);
49 commandEvent.SetEventObject( this );
50 commandEvent.SetClientData((char *)m_FoundObject);
51 m_ClickPosition = wxPoint(event.GetX(), event.GetY());
52 GetEventHandler()->ProcessEvent(commandEvent);
53 }
54 }
55 }
56
57 /*
58 * some simple keyboard handling
59 */
60 void
61 wxLayoutWindow::OnChar(wxKeyEvent& event)
62 {
63 if(! m_llist.IsEditable()) // do nothing
64 {
65 event.Skip();
66 return;
67 }
68
69 long keyCode = event.KeyCode();
70 wxPoint p;
71 CoordType help;
72
73 switch(event.KeyCode())
74 {
75 case WXK_RIGHT:
76 m_llist.MoveCursor(1);
77 break;
78 case WXK_LEFT:
79 m_llist.MoveCursor(-1);
80 break;
81 case WXK_UP:
82 m_llist.MoveCursor(0,-1);
83 break;
84 case WXK_DOWN:
85 m_llist.MoveCursor(0,1);
86 break;
87 case WXK_PRIOR:
88 m_llist.MoveCursor(0,-20);
89 break;
90 case WXK_NEXT:
91 m_llist.MoveCursor(0,20);
92 break;
93 case WXK_HOME:
94 p = m_llist.GetCursor();
95 p.x = 0;
96 m_llist.SetCursor(p);
97 break;
98 case WXK_END:
99 p = m_llist.GetCursor();
100 p.x = m_llist.GetLineLength(m_llist.FindCurrentObject(NULL));
101 m_llist.SetCursor(p);
102 break;
103 case WXK_DELETE :
104 if(event.ControlDown()) // delete to end of line
105 {
106 help = m_llist.GetLineLength(
107 m_llist.FindCurrentObject(NULL))
108 - m_llist.GetCursor().x;
109 m_llist.Delete(help ? help : 1);
110 }
111 else
112 m_llist.Delete(1);
113 break;
114 case WXK_BACK: // backspace
115 if(m_llist.MoveCursor(-1))
116 m_llist.Delete(1);
117 break;
118 case WXK_RETURN:
119 m_llist.LineBreak();
120 break;
121 #ifdef WXLAYOUT_DEBUG
122 case WXK_F1:
123 m_llist.Debug();
124 break;
125 #endif
126 default:
127 if(keyCode < 256 && keyCode >= 32)
128 {
129 String tmp;
130 tmp += keyCode;
131 m_llist.Insert(tmp);
132 }
133 break;
134 }
135 Refresh();
136 UpdateScrollbars();
137 }
138
139 void
140 wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)w) // or: OnDraw(wxDC& dc)
141 {
142 wxPaintDC dc( this ); // only when used as OnPaint for OnDraw we
143 PrepareDC( dc ); // can skip the first two lines
144
145 if(m_EventId != -1) // look for keyclicks
146 m_FoundObject = m_llist.Draw(dc,true,m_FindPos);
147 else
148 m_llist.Draw(dc);
149 if(! m_ScrollbarsSet)
150 {
151 m_ScrollbarsSet = true; // avoid recursion
152 UpdateScrollbars();
153 }
154 }
155
156 void
157 wxLayoutWindow::UpdateScrollbars(void)
158 {
159 CoordType
160 max_x, max_y, lineHeight;
161
162 m_llist.GetSize(&max_x, &max_y, &lineHeight);
163 SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1);
164 EnableScrolling(true,true);
165 }
166
167 void
168 wxLayoutWindow::Print(void)
169 {
170 VAR(wxThePrintSetupData);
171
172 wxPostScriptDC dc("layout.ps",true,this);
173 if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
174 {
175 //dc.SetUserScale(1.0, 1.0);
176 m_llist.Draw(dc);
177 dc.EndDoc();
178 }
179 }