]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.cpp
Dialog Editor edits
[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 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)
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 long keyCode = event.KeyCode();
64
65 switch(event.KeyCode())
66 {
67 case WXK_RIGHT:
68 m_llist.MoveCursor(1);
69 break;
70 case WXK_LEFT:
71 m_llist.MoveCursor(-1);
72 break;
73 case WXK_UP:
74 m_llist.MoveCursor(0,-1);
75 break;
76 case WXK_DOWN:
77 m_llist.MoveCursor(0,1);
78 break;
79 case WXK_PRIOR:
80 m_llist.MoveCursor(0,-20);
81 break;
82 case WXK_NEXT:
83 m_llist.MoveCursor(0,20);
84 break;
85 case WXK_DELETE :
86 m_llist.Delete(1);
87 break;
88 case WXK_BACK: // backspace
89 m_llist.MoveCursor(-1);
90 m_llist.Delete(1);
91 break;
92 case WXK_RETURN:
93 m_llist.LineBreak();
94 break;
95 #ifdef WXLAYOUT_DEBUG
96 case WXK_F1:
97 m_llist.Debug();
98 break;
99 #endif
100 default:
101 if(keyCode < 256 && keyCode >= 32)
102 {
103 String tmp;
104 tmp += keyCode;
105 m_llist.Insert(tmp);
106 }
107 break;
108 }
109 Refresh();
110 UpdateScrollbars();
111 }
112
113 void
114 wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)w) // or: OnDraw(wxDC& dc)
115 {
116 wxPaintDC dc( this ); // only when used as OnPaint for OnDraw we
117 PrepareDC( dc ); // can skip the first two lines
118
119 if(m_EventId) // look for keyclicks
120 m_FoundObject = m_llist.Draw(dc,true,m_FindPos);
121 else
122 m_llist.Draw(dc);
123 if(! m_ScrollbarsSet)
124 {
125 m_ScrollbarsSet = true; // avoid recursion
126 UpdateScrollbars();
127 }
128 }
129
130 void
131 wxLayoutWindow::UpdateScrollbars(void)
132 {
133 CoordType
134 max_x, max_y, lineHeight;
135
136 m_llist.GetSize(&max_x, &max_y, &lineHeight);
137 SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1);
138 EnableScrolling(true,true);
139 }
140
141 void
142 wxLayoutWindow::Print(void)
143 {
144 VAR(wxThePrintSetupData);
145
146 wxPostScriptDC dc("layout.ps",true,this);
147 if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
148 {
149 //dc.SetUserScale(1.0, 1.0);
150 m_llist.Draw(dc);
151 dc.EndDoc();
152 }
153 }