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
== -1) // nothing to do
36 m_FindPos
.x
= event
.GetX();
37 m_FindPos
.y
= event
.GetY();
41 cerr
<< "OnMouse: " << m_FindPos
.x
<< ',' << m_FindPos
.y
<< endl
;
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
);
58 * some simple keyboard handling
61 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
63 if(! m_llist
.IsEditable()) // do nothing
69 long keyCode
= event
.KeyCode();
73 switch(event
.KeyCode())
76 m_llist
.MoveCursor(1);
79 m_llist
.MoveCursor(-1);
82 m_llist
.MoveCursor(0,-1);
85 m_llist
.MoveCursor(0,1);
88 m_llist
.MoveCursor(0,-20);
91 m_llist
.MoveCursor(0,20);
94 p
= m_llist
.GetCursor();
99 p
= m_llist
.GetCursor();
100 p
.x
= m_llist
.GetLineLength(m_llist
.FindCurrentObject(NULL
));
101 m_llist
.SetCursor(p
);
104 if(event
.ControlDown()) // delete to end of line
106 help
= m_llist
.GetLineLength(
107 m_llist
.FindCurrentObject(NULL
))
108 - m_llist
.GetCursor().x
;
109 m_llist
.Delete(help
? help
: 1);
114 case WXK_BACK
: // backspace
115 if(m_llist
.MoveCursor(-1))
121 #ifdef WXLAYOUT_DEBUG
127 if(keyCode
< 256 && keyCode
>= 32)
140 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
)w
) // or: OnDraw(wxDC& dc)
142 wxPaintDC
dc( this ); // only when used as OnPaint for OnDraw we
143 PrepareDC( dc
); // can skip the first two lines
145 if(m_EventId
!= -1) // look for keyclicks
146 m_FoundObject
= m_llist
.Draw(dc
,true,m_FindPos
);
149 if(! m_ScrollbarsSet
)
151 m_ScrollbarsSet
= true; // avoid recursion
157 wxLayoutWindow::UpdateScrollbars(void)
160 max_x
, max_y
, lineHeight
;
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);
168 wxLayoutWindow::Print(void)
170 VAR(wxThePrintSetupData
);
172 wxPostScriptDC
dc("layout.ps",true,this);
173 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
175 //dc.SetUserScale(1.0, 1.0);