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
, -1, wxDefaultPosition
, wxDefaultSize
,
25 wxHSCROLL
| wxVSCROLL
| wxBORDER
)
28 m_ScrollbarsSet
= false;
34 wxLayoutWindow::MSWGetDlgCode()
36 // if we don't return this, we won't get OnChar() events
37 return DLGC_WANTCHARS
| DLGC_WANTARROWS
| DLGC_WANTMESSAGE
;
43 wxLayoutWindow::OnMouse(wxMouseEvent
& event
)
47 if(m_EventId
== -1) // nothing to do
50 m_FindPos
.x
= event
.GetX();
51 m_FindPos
.y
= event
.GetY();
55 //doesn't work, undefined functions
56 //wxLogTrace("OnMouse: (%d, %d)", m_FindPos.x, m_FindPos.y);
63 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, m_EventId
);
64 commandEvent
.SetEventObject( this );
65 commandEvent
.SetClientData((char *)m_FoundObject
);
66 m_ClickPosition
= wxPoint(event
.GetX(), event
.GetY());
67 GetEventHandler()->ProcessEvent(commandEvent
);
73 * some simple keyboard handling
76 wxLayoutWindow::OnChar(wxKeyEvent
& event
)
78 if(! m_llist
.IsEditable()) // do nothing
84 long keyCode
= event
.KeyCode();
88 switch(event
.KeyCode())
91 m_llist
.MoveCursor(1);
94 m_llist
.MoveCursor(-1);
97 m_llist
.MoveCursor(0,-1);
100 m_llist
.MoveCursor(0,1);
103 m_llist
.MoveCursor(0,-20);
106 m_llist
.MoveCursor(0,20);
109 p
= m_llist
.GetCursor();
111 m_llist
.SetCursor(p
);
114 p
= m_llist
.GetCursor();
115 p
.x
= m_llist
.GetLineLength(m_llist
.FindCurrentObject(NULL
));
116 m_llist
.SetCursor(p
);
119 if(event
.ControlDown()) // delete to end of line
121 help
= m_llist
.GetLineLength(
122 m_llist
.FindCurrentObject(NULL
))
123 - m_llist
.GetCursor().x
;
124 m_llist
.Delete(help
? help
: 1);
129 case WXK_BACK
: // backspace
130 if(m_llist
.MoveCursor(-1))
136 #ifdef WXLAYOUT_DEBUG
142 if(keyCode
< 256 && keyCode
>= 32)
155 wxLayoutWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
)w
) // or: OnDraw(wxDC& dc)
157 wxPaintDC
dc( this ); // only when used as OnPaint for OnDraw we
158 PrepareDC( dc
); // can skip the first two lines
160 if(m_EventId
!= -1) // look for keyclicks
161 m_FoundObject
= m_llist
.Draw(dc
,true,m_FindPos
);
164 if(! m_ScrollbarsSet
)
166 m_ScrollbarsSet
= true; // avoid recursion
172 wxLayoutWindow::UpdateScrollbars(void)
175 max_x
, max_y
, lineHeight
;
177 m_llist
.GetSize(&max_x
, &max_y
, &lineHeight
);
178 SetScrollbars(10, lineHeight
, max_x
/10+1, max_y
/lineHeight
+1);
179 EnableScrolling(true,true);
183 wxLayoutWindow::Print(void)
185 VAR(wxThePrintSetupData
);
187 wxPostScriptDC
dc("layout.ps",true,this);
188 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
190 //dc.SetUserScale(1.0, 1.0);