1998-06-29 08:44:36 -04:00
|
|
|
|
/*-*- c++ -*-********************************************************
|
|
|
|
|
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
|
|
|
|
|
* *
|
|
|
|
|
* (C) 1998 by Karsten Ball<EFBFBD>der (Ballueder@usa.net) *
|
|
|
|
|
* *
|
|
|
|
|
* $Id$
|
|
|
|
|
*******************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
# pragma implementation "wxlwindow.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "wxlwindow.h"
|
|
|
|
|
|
|
|
|
|
#define VAR(x) cout << #x"=" << x << endl;
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
1998-08-13 06:03:26 -04:00
|
|
|
|
EVT_PAINT (wxLayoutWindow::OnPaint)
|
|
|
|
|
EVT_CHAR (wxLayoutWindow::OnChar)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
EVT_LEFT_DOWN(wxLayoutWindow::OnMouse)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
|
1998-08-13 06:03:26 -04:00
|
|
|
|
: wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
|
|
|
|
|
wxHSCROLL | wxVSCROLL | wxBORDER)
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
m_ScrollbarsSet = false;
|
1998-08-12 04:33:34 -04:00
|
|
|
|
m_EventId = -1;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-13 06:03:26 -04:00
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
long
|
|
|
|
|
wxLayoutWindow::MSWGetDlgCode()
|
|
|
|
|
{
|
|
|
|
|
// if we don't return this, we won't get OnChar() events
|
|
|
|
|
return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_WANTMESSAGE;
|
|
|
|
|
}
|
|
|
|
|
#endif //MSW
|
|
|
|
|
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::OnMouse(wxMouseEvent& event)
|
|
|
|
|
{
|
1998-08-13 06:03:26 -04:00
|
|
|
|
SetFocus();
|
|
|
|
|
|
1998-08-12 04:33:34 -04:00
|
|
|
|
if(m_EventId == -1) // nothing to do
|
1998-06-29 08:44:36 -04:00
|
|
|
|
return;
|
|
|
|
|
|
1998-08-12 04:33:34 -04:00
|
|
|
|
m_FindPos.x = event.GetX();
|
|
|
|
|
m_FindPos.y = event.GetY();
|
1998-08-22 23:22:56 -04:00
|
|
|
|
m_FoundObject = (wxLayoutObjectBase *) NULL;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1998-07-12 11:02:44 -04:00
|
|
|
|
#ifdef WXLAYOUT_DEBUG
|
1998-08-13 06:03:26 -04:00
|
|
|
|
//doesn't work, undefined functions
|
|
|
|
|
//wxLogTrace("OnMouse: (%d, %d)", m_FindPos.x, m_FindPos.y);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
#endif
|
|
|
|
|
Refresh();
|
|
|
|
|
if(m_FoundObject)
|
|
|
|
|
{
|
1998-08-12 04:33:34 -04:00
|
|
|
|
if(m_EventId != -1)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, m_EventId);
|
|
|
|
|
commandEvent.SetEventObject( this );
|
1998-07-12 11:02:44 -04:00
|
|
|
|
commandEvent.SetClientData((char *)m_FoundObject);
|
|
|
|
|
m_ClickPosition = wxPoint(event.GetX(), event.GetY());
|
1998-06-29 08:44:36 -04:00
|
|
|
|
GetEventHandler()->ProcessEvent(commandEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* some simple keyboard handling
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|
|
|
|
{
|
1998-08-06 15:23:19 -04:00
|
|
|
|
if(! m_llist.IsEditable()) // do nothing
|
|
|
|
|
{
|
|
|
|
|
event.Skip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
long keyCode = event.KeyCode();
|
1998-08-06 15:23:19 -04:00
|
|
|
|
wxPoint p;
|
1998-08-12 12:14:15 -04:00
|
|
|
|
CoordType help;
|
1998-08-06 15:23:19 -04:00
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
switch(event.KeyCode())
|
|
|
|
|
{
|
|
|
|
|
case WXK_RIGHT:
|
|
|
|
|
m_llist.MoveCursor(1);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_LEFT:
|
|
|
|
|
m_llist.MoveCursor(-1);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_UP:
|
|
|
|
|
m_llist.MoveCursor(0,-1);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_DOWN:
|
|
|
|
|
m_llist.MoveCursor(0,1);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_PRIOR:
|
|
|
|
|
m_llist.MoveCursor(0,-20);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_NEXT:
|
|
|
|
|
m_llist.MoveCursor(0,20);
|
|
|
|
|
break;
|
1998-08-06 15:23:19 -04:00
|
|
|
|
case WXK_HOME:
|
|
|
|
|
p = m_llist.GetCursor();
|
|
|
|
|
p.x = 0;
|
|
|
|
|
m_llist.SetCursor(p);
|
|
|
|
|
break;
|
|
|
|
|
case WXK_END:
|
|
|
|
|
p = m_llist.GetCursor();
|
1998-08-22 23:22:56 -04:00
|
|
|
|
p.x = m_llist.GetLineLength(m_llist.FindCurrentObject((CoordType *) NULL));
|
1998-08-06 15:23:19 -04:00
|
|
|
|
m_llist.SetCursor(p);
|
|
|
|
|
break;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
case WXK_DELETE :
|
1998-08-12 12:14:15 -04:00
|
|
|
|
if(event.ControlDown()) // delete to end of line
|
|
|
|
|
{
|
|
|
|
|
help = m_llist.GetLineLength(
|
1998-08-22 23:22:56 -04:00
|
|
|
|
m_llist.FindCurrentObject((CoordType *) NULL))
|
1998-08-12 12:14:15 -04:00
|
|
|
|
- m_llist.GetCursor().x;
|
|
|
|
|
m_llist.Delete(help ? help : 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_llist.Delete(1);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
break;
|
|
|
|
|
case WXK_BACK: // backspace
|
1998-08-12 12:14:15 -04:00
|
|
|
|
if(m_llist.MoveCursor(-1))
|
|
|
|
|
m_llist.Delete(1);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
break;
|
|
|
|
|
case WXK_RETURN:
|
|
|
|
|
m_llist.LineBreak();
|
|
|
|
|
break;
|
1998-07-12 11:02:44 -04:00
|
|
|
|
#ifdef WXLAYOUT_DEBUG
|
1998-06-29 08:44:36 -04:00
|
|
|
|
case WXK_F1:
|
|
|
|
|
m_llist.Debug();
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
|
|
|
|
if(keyCode < 256 && keyCode >= 32)
|
|
|
|
|
{
|
1998-07-12 11:02:44 -04:00
|
|
|
|
String tmp;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
tmp += keyCode;
|
|
|
|
|
m_llist.Insert(tmp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Refresh();
|
|
|
|
|
UpdateScrollbars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)w) // or: OnDraw(wxDC& dc)
|
|
|
|
|
{
|
|
|
|
|
wxPaintDC dc( this ); // only when used as OnPaint for OnDraw we
|
|
|
|
|
PrepareDC( dc ); // can skip the first two lines
|
|
|
|
|
|
1998-08-12 04:33:34 -04:00
|
|
|
|
if(m_EventId != -1) // look for keyclicks
|
1998-06-29 08:44:36 -04:00
|
|
|
|
m_FoundObject = m_llist.Draw(dc,true,m_FindPos);
|
|
|
|
|
else
|
|
|
|
|
m_llist.Draw(dc);
|
|
|
|
|
if(! m_ScrollbarsSet)
|
|
|
|
|
{
|
|
|
|
|
m_ScrollbarsSet = true; // avoid recursion
|
|
|
|
|
UpdateScrollbars();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::UpdateScrollbars(void)
|
|
|
|
|
{
|
|
|
|
|
CoordType
|
|
|
|
|
max_x, max_y, lineHeight;
|
|
|
|
|
|
|
|
|
|
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
|
|
|
|
SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1);
|
|
|
|
|
EnableScrolling(true,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::Print(void)
|
|
|
|
|
{
|
1998-07-20 04:43:47 -04:00
|
|
|
|
VAR(wxThePrintSetupData);
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
wxPostScriptDC dc("layout.ps",true,this);
|
|
|
|
|
if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
|
|
|
|
|
{
|
|
|
|
|
//dc.SetUserScale(1.0, 1.0);
|
|
|
|
|
m_llist.Draw(dc);
|
|
|
|
|
dc.EndDoc();
|
|
|
|
|
}
|
|
|
|
|
}
|