1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
10 # pragma implementation "wxlwindow.h"
18 # include "gui/wxMenuDefs.h"
20 # include "gui/wxlwindow.h"
30 # include "wxlwindow.h"
31 # define TRACEMESSAGE(x)
33 # define WXL_VAR(x) cerr << #x " = " << x ;
35 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
36 EVT_PAINT (wxLayoutWindow::OnPaint
)
37 EVT_CHAR (wxLayoutWindow::OnChar
)
39 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick
)
40 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
41 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
44 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
45 : wxScrolledWindow(parent
, -1, wxDefaultPosition
, wxDefaultSize
,
46 wxHSCROLL
| wxVSCROLL
| wxBORDER
)
49 m_ScrollbarsSet
= false;
50 m_doSendEvents
= false;
51 m_ViewStartX
= 0; m_ViewStartY
= 0;
55 max_x
, max_y
, lineHeight
;
56 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
57 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1);
58 EnableScrolling(true,true);
63 wxLayoutWindow::MSWGetDlgCode()
65 // if we don't return this, we won't get OnChar() events
66 return DLGC_WANTCHARS
| DLGC_WANTARROWS
| DLGC_WANTMESSAGE
;
71 wxLayoutWindow::Update(void)
81 m_llist
.DrawCursor(dc
);
85 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
87 if(!m_doSendEvents
) // nothing to do
95 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
96 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
98 TRACEMESSAGE(("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
99 event
.GetX(), event
.GetY(), findPos
.x
, findPos
.y
));
101 // find the object at this position
102 wxLayoutObjectBase
*obj
= m_llist
.Find(findPos
);
105 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, eventId
);
106 commandEvent
.SetEventObject( this );
107 commandEvent
.SetClientData((char *)obj
);
108 GetEventHandler()->ProcessEvent(commandEvent
);
113 * some simple keyboard handling
116 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
118 if(! m_llist
.IsEditable()) // do nothing
124 long keyCode
= event
.KeyCode();
128 switch(event
.KeyCode())
131 m_llist
.MoveCursor(1);
134 m_llist
.MoveCursor(-1);
137 m_llist
.MoveCursor(0,-1);
140 m_llist
.MoveCursor(0,1);
143 m_llist
.MoveCursor(0,-20);
146 m_llist
.MoveCursor(0,20);
149 p
= m_llist
.GetCursor();
151 m_llist
.SetCursor(p
);
154 p
= m_llist
.GetCursor();
155 p
.x
= m_llist
.GetLineLength(m_llist
.FindCurrentObject(NULL
));
156 m_llist
.SetCursor(p
);
159 if(event
.ControlDown()) // delete to end of line
161 help
= m_llist
.GetLineLength(
162 m_llist
.FindCurrentObject(NULL
))
163 - m_llist
.GetCursor().x
;
164 m_llist
.Delete(help
? help
: 1);
169 case WXK_BACK
: // backspace
170 if(m_llist
.MoveCursor(-1)) {
178 #ifdef WXLAYOUT_DEBUG
185 if(keyCode
< 256 && keyCode
>= 32)
194 /** Scroll so that cursor is visible! */
195 int x0
,y0
,x1
,y1
,ux
,uy
;
197 GetScrollPixelsPerUnit(&ux
,&uy
);
199 GetClientSize(&x1
,&y1
);
201 wxPoint cc
= m_llist
.GetCursorCoords();
202 int nx
= x0
, ny
= y0
;
203 // when within 10% of borders, scroll to center
204 if(cc
.y
> y0
+(9*y1
)/10)
206 else if (cc
.y
< y0
+y1
/10)
211 if(cc
.x
> x0
+(9*x1
)/10)
213 else if (cc
.x
< x0
+x1
/10)
224 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
)) // or: OnDraw(wxDC& dc)
226 wxPaintDC
dc( this );
231 // wxGTK: wxMemoryDC broken?
236 WXL_VAR(x0
); WXL_VAR(y0
);
237 WXL_VAR(x1
); WXL_VAR(y1
);
241 memdc
.SelectObject(bm
);
243 // make temporary copy and edit this
244 memdc
.SetDeviceOrigin(x0
,y0
);
245 memdc
.Blit(x0
,y0
,x1
,y1
,&dc
,x0
,y0
,wxCOPY
,FALSE
);
248 dc
.Blit(x0
,y0
,x1
,y1
,&memdc
,x0
,y0
,wxCOPY
,FALSE
);
253 // does the actual painting
255 wxLayoutWindow::DoPaint(wxDC
&dc
)
257 m_llist
.EraseAndDraw(dc
);
258 m_llist
.DrawCursor(dc
);
259 // FIXME: not strictly correct, this does only work for changes behind
260 // the cursor position, not complete redraws
262 if(! m_ScrollbarsSet
)
264 m_ScrollbarsSet
= true; // avoid recursion
270 wxLayoutWindow::UpdateScrollbars(void)
273 max_x
, max_y
, lineHeight
;
275 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
276 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
277 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1,m_ViewStartX
,m_ViewStartY
,true);
278 //EnableScrolling(true,true);
279 //Scroll(m_ViewStartX, m_ViewStartY);
283 wxLayoutWindow::Print(void)
285 wxPostScriptDC
dc("layout.ps",true,this);
286 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
288 //dc.SetUserScale(1.0, 1.0);