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"
22 # include "wxlwindow.h"
23 # define TRACEMESSAGE(x)
25 # define WXL_VAR(x) cerr << #x " = " << x ;
27 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
28 EVT_PAINT (wxLayoutWindow::OnPaint
)
29 EVT_CHAR (wxLayoutWindow::OnChar
)
31 EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick
)
32 EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick
)
33 EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick
)
36 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
37 : wxScrolledWindow(parent
, -1, wxDefaultPosition
, wxDefaultSize
,
38 wxHSCROLL
| wxVSCROLL
| wxBORDER
)
41 m_ScrollbarsSet
= false;
42 m_doSendEvents
= false;
43 m_ViewStartX
= 0; m_ViewStartY
= 0;
47 max_x
, max_y
, lineHeight
;
48 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
49 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1);
50 EnableScrolling(true,true);
55 wxLayoutWindow::MSWGetDlgCode()
57 // if we don't return this, we won't get OnChar() events
58 return DLGC_WANTCHARS
| DLGC_WANTARROWS
| DLGC_WANTMESSAGE
;
63 wxLayoutWindow::Update(void)
73 m_llist
.DrawCursor(dc
);
77 wxLayoutWindow::OnMouse(int eventId
, wxMouseEvent
& event
)
79 if(!m_doSendEvents
) // nothing to do
87 findPos
.x
= dc
.DeviceToLogicalX(event
.GetX());
88 findPos
.y
= dc
.DeviceToLogicalY(event
.GetY());
90 TRACEMESSAGE(("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
91 event
.GetX(), event
.GetY(), findPos
.x
, findPos
.y
));
93 // find the object at this position
94 wxLayoutObjectBase
*obj
= m_llist
.Find(findPos
);
97 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, eventId
);
98 commandEvent
.SetEventObject( this );
99 commandEvent
.SetClientData((char *)obj
);
100 GetEventHandler()->ProcessEvent(commandEvent
);
105 * some simple keyboard handling
108 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
110 if(! m_llist
.IsEditable()) // do nothing
116 long keyCode
= event
.KeyCode();
120 switch(event
.KeyCode())
123 m_llist
.MoveCursor(1);
126 m_llist
.MoveCursor(-1);
129 m_llist
.MoveCursor(0,-1);
132 m_llist
.MoveCursor(0,1);
135 m_llist
.MoveCursor(0,-20);
138 m_llist
.MoveCursor(0,20);
141 p
= m_llist
.GetCursor();
143 m_llist
.SetCursor(p
);
146 p
= m_llist
.GetCursor();
147 p
.x
= m_llist
.GetLineLength(m_llist
.FindCurrentObject(NULL
));
148 m_llist
.SetCursor(p
);
151 if(event
.ControlDown()) // delete to end of line
153 help
= m_llist
.GetLineLength(
154 m_llist
.FindCurrentObject(NULL
))
155 - m_llist
.GetCursor().x
;
156 m_llist
.Delete(help
? help
: 1);
161 case WXK_BACK
: // backspace
162 if(m_llist
.MoveCursor(-1)) {
170 #ifdef WXLAYOUT_DEBUG
177 if(keyCode
< 256 && keyCode
>= 32)
186 /** Scroll so that cursor is visible! */
187 int x0
,y0
,x1
,y1
,ux
,uy
;
189 GetScrollPixelsPerUnit(&ux
,&uy
);
191 GetClientSize(&x1
,&y1
);
193 wxPoint cc
= m_llist
.GetCursorCoords();
194 int nx
= x0
, ny
= y0
;
195 // when within 10% of borders, scroll to center
196 if(cc
.y
> y0
+(9*y1
)/10)
198 else if (cc
.y
< y0
+y1
/10)
203 if(cc
.x
> x0
+(9*x1
)/10)
205 else if (cc
.x
< x0
+x1
/10)
216 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
)) // or: OnDraw(wxDC& dc)
218 wxPaintDC
dc( this );
223 // wxGTK: wxMemoryDC broken?
228 WXL_VAR(x0
); WXL_VAR(y0
);
229 WXL_VAR(x1
); WXL_VAR(y1
);
233 memdc
.SelectObject(bm
);
235 // make temporary copy and edit this
236 memdc
.SetDeviceOrigin(x0
,y0
);
237 memdc
.Blit(x0
,y0
,x1
,y1
,&dc
,x0
,y0
,wxCOPY
,FALSE
);
240 dc
.Blit(x0
,y0
,x1
,y1
,&memdc
,x0
,y0
,wxCOPY
,FALSE
);
245 // does the actual painting
247 wxLayoutWindow::DoPaint(wxDC
&dc
)
249 m_llist
.EraseAndDraw(dc
);
250 m_llist
.DrawCursor(dc
);
251 // FIXME: not strictly correct, this does only work for changes behind
252 // the cursor position, not complete redraws
254 if(! m_ScrollbarsSet
)
256 m_ScrollbarsSet
= true; // avoid recursion
262 wxLayoutWindow::UpdateScrollbars(void)
265 max_x
, max_y
, lineHeight
;
267 ViewStart(&m_ViewStartX
, &m_ViewStartY
);
268 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
269 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1,m_ViewStartX
,m_ViewStartY
,true);
270 //EnableScrolling(true,true);
271 //Scroll(m_ViewStartX, m_ViewStartY);
275 wxLayoutWindow::Print(void)
277 wxPostScriptDC
dc("layout.ps",true,this);
278 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
280 //dc.SetUserScale(1.0, 1.0);