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"
13 #include "wxlwindow.h"
15 #define VAR(x) cout << #x"=" << x << endl;
17 BEGIN_EVENT_TABLE(wxLayoutWindow
,wxScrolledWindow
)
18 EVT_PAINT (wxLayoutWindow::OnPaint
)
19 EVT_CHAR (wxLayoutWindow::OnChar
)
20 EVT_LEFT_DOWN(wxLayoutWindow::OnMouse
)
23 wxLayoutWindow::wxLayoutWindow(wxWindow
*parent
)
24 : wxScrolledWindow(parent
)
26 m_ScrollbarsSet
= false;
31 wxLayoutWindow::OnMouse(wxMouseEvent
& event
)
33 if(m_EventId
== 0) // nothing to do
36 // this is unintuitive
40 m_FindPos
.x
= dc
.DeviceToLogicalX( event
.GetX() );
41 m_FindPos
.y
= dc
.DeviceToLogicalY( event
.GetY() );
46 cerr
<< "OnMouse: " << m_FindPos
.x
<< ',' << m_FindPos
.y
<< endl
;
53 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, m_EventId
);
54 commandEvent
.SetEventObject( this );
55 commandEvent
.SetClientData((char *)m_FoundObject
);
56 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
57 GetEventHandler()->ProcessEvent(commandEvent
);
63 * some simple keyboard handling
66 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
68 if(! m_llist
.IsEditable()) // do nothing
74 long keyCode
= event
.KeyCode();
77 switch(event
.KeyCode())
80 m_llist
.MoveCursor(1);
83 m_llist
.MoveCursor(-1);
86 m_llist
.MoveCursor(0,-1);
89 m_llist
.MoveCursor(0,1);
92 m_llist
.MoveCursor(0,-20);
95 m_llist
.MoveCursor(0,20);
98 p
= m_llist
.GetCursor();
100 m_llist
.SetCursor(p
);
103 p
= m_llist
.GetCursor();
104 p
.x
= m_llist
.GetLineLength(m_llist
.FindCurrentObject(NULL
));
105 m_llist
.SetCursor(p
);
110 case WXK_BACK
: // backspace
111 m_llist
.MoveCursor(-1);
117 #ifdef WXLAYOUT_DEBUG
123 if(keyCode
< 256 && keyCode
>= 32)
136 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
)w
) // or: OnDraw(wxDC& dc)
138 wxPaintDC
dc( this ); // only when used as OnPaint for OnDraw we
139 PrepareDC( dc
); // can skip the first two lines
141 if(m_EventId
) // look for keyclicks
142 m_FoundObject
= m_llist
.Draw(dc
,true,m_FindPos
);
145 if(! m_ScrollbarsSet
)
147 m_ScrollbarsSet
= true; // avoid recursion
153 wxLayoutWindow::UpdateScrollbars(void)
156 max_x
, max_y
, lineHeight
;
158 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
159 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1);
160 EnableScrolling(true,true);
164 wxLayoutWindow::Print(void)
166 VAR(wxThePrintSetupData
);
168 wxPostScriptDC
dc("layout.ps",true,this);
169 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
171 //dc.SetUserScale(1.0, 1.0);