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
|
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
//#include "Mpch.h"
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
#ifdef M_BASEDIR
|
|
|
|
|
# ifndef USE_PCH
|
|
|
|
|
# include "Mcommon.h"
|
|
|
|
|
# include "gui/wxMenuDefs.h"
|
|
|
|
|
# endif // USE_PCH
|
|
|
|
|
# include "gui/wxlwindow.h"
|
|
|
|
|
#else
|
1998-10-28 16:47:16 -05:00
|
|
|
|
# ifdef __WXMSW__
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
|
|
|
|
|
# undef FindWindow
|
|
|
|
|
# undef GetCharWidth
|
|
|
|
|
# undef StartDoc
|
|
|
|
|
# endif
|
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
# include "wxlwindow.h"
|
|
|
|
|
# define TRACEMESSAGE(x)
|
|
|
|
|
#endif
|
|
|
|
|
# define WXL_VAR(x) cerr << #x " = " << x ;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
1998-08-13 06:03:26 -04:00
|
|
|
|
EVT_PAINT (wxLayoutWindow::OnPaint)
|
|
|
|
|
EVT_CHAR (wxLayoutWindow::OnChar)
|
1998-10-24 14:08:20 -04:00
|
|
|
|
|
|
|
|
|
EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick)
|
|
|
|
|
EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
|
|
|
|
|
EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
|
1998-10-30 05:14:58 -05:00
|
|
|
|
EVT_MENU(WXLOWIN_MENU_LARGER, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_SMALLER, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_UNDERLINE, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_BOLD, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_ITALICS, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_ROMAN, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_TYPEWRITER, wxLayoutWindow::OnMenu)
|
|
|
|
|
EVT_MENU(WXLOWIN_MENU_SANSSERIF, wxLayoutWindow::OnMenu)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
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-10-24 14:08:20 -04:00
|
|
|
|
m_doSendEvents = false;
|
|
|
|
|
m_ViewStartX = 0; m_ViewStartY = 0;
|
1998-10-30 05:14:58 -05:00
|
|
|
|
m_DoPopupMenu = true;
|
|
|
|
|
m_PopupMenu = NULL;
|
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
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);
|
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-10-24 14:08:20 -04:00
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::Update(void)
|
|
|
|
|
{
|
|
|
|
|
wxClientDC dc(this);
|
|
|
|
|
PrepareDC(dc);
|
|
|
|
|
if(IsDirty())
|
|
|
|
|
{
|
|
|
|
|
DoPaint(dc);
|
|
|
|
|
UpdateScrollbars();
|
|
|
|
|
ResetDirty();
|
|
|
|
|
}
|
|
|
|
|
m_llist.DrawCursor(dc);
|
|
|
|
|
}
|
1998-08-13 06:03:26 -04:00
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
void
|
1998-10-24 14:08:20 -04:00
|
|
|
|
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1998-10-24 14:08:20 -04:00
|
|
|
|
if(!m_doSendEvents) // nothing to do
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wxPaintDC dc( this );
|
|
|
|
|
PrepareDC( dc );
|
1998-08-13 06:03:26 -04:00
|
|
|
|
SetFocus();
|
1998-10-30 05:14:58 -05:00
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
wxPoint findPos;
|
|
|
|
|
findPos.x = dc.DeviceToLogicalX(event.GetX());
|
|
|
|
|
findPos.y = dc.DeviceToLogicalY(event.GetY());
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
TRACEMESSAGE(("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
|
|
|
|
|
event.GetX(), event.GetY(), findPos.x, findPos.y));
|
|
|
|
|
|
1998-10-30 05:14:58 -05:00
|
|
|
|
if(eventId == WXLOWIN_MENU_RCLICK && m_DoPopupMenu && m_llist.IsEditable())
|
|
|
|
|
{
|
|
|
|
|
// when does this menu get freed?
|
|
|
|
|
// how do we handle toggling? FIXME
|
|
|
|
|
PopupMenu(MakeFormatMenu(), event.GetX(), event.GetY());
|
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-24 14:08:20 -04:00
|
|
|
|
// find the object at this position
|
|
|
|
|
wxLayoutObjectBase *obj = m_llist.Find(findPos);
|
|
|
|
|
if(obj)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1998-10-24 14:08:20 -04:00
|
|
|
|
wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, eventId);
|
|
|
|
|
commandEvent.SetEventObject( this );
|
|
|
|
|
commandEvent.SetClientData((char *)obj);
|
|
|
|
|
GetEventHandler()->ProcessEvent(commandEvent);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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-11-19 15:34:59 -05:00
|
|
|
|
p.x = m_llist.GetLineLength(m_llist.GetCurrentObject());
|
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-11-19 15:34:59 -05:00
|
|
|
|
m_llist.GetCurrentObject())
|
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-10-24 14:08:20 -04:00
|
|
|
|
if(m_llist.MoveCursor(-1)) {
|
1998-08-12 12:14:15 -04:00
|
|
|
|
m_llist.Delete(1);
|
1998-10-24 14:08:20 -04:00
|
|
|
|
}
|
1998-06-29 08:44:36 -04:00
|
|
|
|
break;
|
|
|
|
|
case WXK_RETURN:
|
|
|
|
|
m_llist.LineBreak();
|
|
|
|
|
break;
|
1998-10-24 14:08:20 -04:00
|
|
|
|
|
|
|
|
|
#ifdef WXLAYOUT_DEBUG
|
1998-06-29 08:44:36 -04:00
|
|
|
|
case WXK_F1:
|
|
|
|
|
m_llist.Debug();
|
|
|
|
|
break;
|
1998-11-19 15:34:59 -05:00
|
|
|
|
case WXK_F2:
|
|
|
|
|
m_llist.WrapLine();
|
|
|
|
|
break;
|
1998-10-24 14:08:20 -04:00
|
|
|
|
#endif
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
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);
|
1998-11-19 15:34:59 -05:00
|
|
|
|
m_llist.WrapLine();
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-10-24 14:08:20 -04:00
|
|
|
|
|
|
|
|
|
/** Scroll so that cursor is visible! */
|
|
|
|
|
int x0,y0,x1,y1,ux,uy;
|
|
|
|
|
ViewStart(&x0,&y0);
|
|
|
|
|
GetScrollPixelsPerUnit(&ux,&uy);
|
|
|
|
|
x0*=ux; y0*=uy;
|
|
|
|
|
GetClientSize(&x1,&y1);
|
|
|
|
|
|
|
|
|
|
wxPoint cc = m_llist.GetCursorCoords();
|
|
|
|
|
int nx = x0, ny = y0;
|
|
|
|
|
// when within 10% of borders, scroll to center
|
|
|
|
|
if(cc.y > y0+(9*y1)/10)
|
|
|
|
|
ny = cc.y - y1/5;
|
|
|
|
|
else if (cc.y < y0+y1/10)
|
|
|
|
|
{
|
|
|
|
|
ny = cc.y-y1/2;
|
|
|
|
|
if(ny < 0) ny = 0;
|
|
|
|
|
}
|
|
|
|
|
if(cc.x > x0+(9*x1)/10)
|
|
|
|
|
nx = cc.x - x1/5;
|
|
|
|
|
else if (cc.x < x0+x1/10)
|
|
|
|
|
{
|
|
|
|
|
nx = cc.x-x1/2;
|
|
|
|
|
if(nx < 0) nx = 0;
|
|
|
|
|
}
|
|
|
|
|
Scroll(nx,ny);
|
|
|
|
|
|
|
|
|
|
Update();
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1998-10-24 14:08:20 -04:00
|
|
|
|
wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)) // or: OnDraw(wxDC& dc)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1998-10-24 14:08:20 -04:00
|
|
|
|
wxPaintDC dc( this );
|
|
|
|
|
PrepareDC( dc );
|
|
|
|
|
|
|
|
|
|
DoPaint(dc);
|
|
|
|
|
|
|
|
|
|
// wxGTK: wxMemoryDC broken?
|
|
|
|
|
#if 0
|
|
|
|
|
int x0,y0,x1,y1;
|
|
|
|
|
ViewStart(&x0,&y0);
|
|
|
|
|
GetSize(&x1,&y1);
|
|
|
|
|
WXL_VAR(x0); WXL_VAR(y0);
|
|
|
|
|
WXL_VAR(x1); WXL_VAR(y1);
|
|
|
|
|
|
|
|
|
|
wxMemoryDC(memdc);
|
|
|
|
|
wxBitmap bm(x1,y1);
|
|
|
|
|
memdc.SelectObject(bm);
|
|
|
|
|
|
|
|
|
|
// make temporary copy and edit this
|
|
|
|
|
memdc.SetDeviceOrigin(x0,y0);
|
|
|
|
|
memdc.Blit(x0,y0,x1,y1,&dc,x0,y0,wxCOPY,FALSE);
|
|
|
|
|
DoPaint(memdc);
|
|
|
|
|
// blit it back
|
|
|
|
|
dc.Blit(x0,y0,x1,y1,&memdc,x0,y0,wxCOPY,FALSE);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// does the actual painting
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::DoPaint(wxDC &dc)
|
|
|
|
|
{
|
|
|
|
|
m_llist.EraseAndDraw(dc);
|
|
|
|
|
m_llist.DrawCursor(dc);
|
|
|
|
|
// FIXME: not strictly correct, this does only work for changes behind
|
|
|
|
|
// the cursor position, not complete redraws
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
if(! m_ScrollbarsSet)
|
|
|
|
|
{
|
|
|
|
|
m_ScrollbarsSet = true; // avoid recursion
|
|
|
|
|
UpdateScrollbars();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::UpdateScrollbars(void)
|
|
|
|
|
{
|
|
|
|
|
CoordType
|
|
|
|
|
max_x, max_y, lineHeight;
|
1998-10-24 14:08:20 -04:00
|
|
|
|
|
|
|
|
|
ViewStart(&m_ViewStartX, &m_ViewStartY);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
1998-10-24 14:08:20 -04:00
|
|
|
|
SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1,m_ViewStartX,m_ViewStartY,true);
|
|
|
|
|
//EnableScrolling(true,true);
|
|
|
|
|
//Scroll(m_ViewStartX, m_ViewStartY);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wxLayoutWindow::Print(void)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-30 05:14:58 -05:00
|
|
|
|
|
|
|
|
|
wxMenu *
|
|
|
|
|
wxLayoutWindow::MakeFormatMenu()
|
|
|
|
|
{
|
|
|
|
|
if(m_PopupMenu)
|
|
|
|
|
return m_PopupMenu;
|
|
|
|
|
|
|
|
|
|
wxMenu *m = new wxMenu();
|
|
|
|
|
|
|
|
|
|
m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."), false);
|
|
|
|
|
m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."), false);
|
|
|
|
|
m->AppendSeparator();
|
|
|
|
|
m->Append(WXLOWIN_MENU_UNDERLINE,_("&Underline"),_("Toggle underline mode."), true);
|
|
|
|
|
m->Append(WXLOWIN_MENU_BOLD ,_("&Bold"),_("Toggle bold mode."), true);
|
|
|
|
|
m->Append(WXLOWIN_MENU_ITALICS ,_("&Italics"),_("Toggle italics mode."), true);
|
|
|
|
|
m->AppendSeparator();
|
|
|
|
|
m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Toggle underline mode."), false);
|
|
|
|
|
m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Toggle bold mode."), false);
|
|
|
|
|
m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Toggle italics mode."), false);
|
|
|
|
|
|
|
|
|
|
return m_PopupMenu = m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLayoutWindow::OnMenu(wxCommandEvent& event)
|
|
|
|
|
{
|
|
|
|
|
if(! m_llist.IsEditable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (event.GetId())
|
|
|
|
|
{
|
|
|
|
|
case WXLOWIN_MENU_LARGER:
|
|
|
|
|
m_llist.SetFontLarger();
|
|
|
|
|
break;
|
|
|
|
|
case WXLOWIN_MENU_SMALLER:
|
|
|
|
|
m_llist.SetFontSmaller();
|
|
|
|
|
break;
|
|
|
|
|
case WXLOWIN_MENU_UNDERLINE:
|
|
|
|
|
m_llist.SetFontUnderline(
|
|
|
|
|
m_PopupMenu->IsChecked(WXLOWIN_MENU_UNDERLINE) ? false : true
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case WXLOWIN_MENU_BOLD:
|
|
|
|
|
m_llist.SetFontWeight(
|
|
|
|
|
m_PopupMenu->IsChecked(WXLOWIN_MENU_BOLD) ? wxNORMAL : wxBOLD
|
|
|
|
|
);
|
|
|
|
|
case WXLOWIN_MENU_ITALICS:
|
|
|
|
|
m_llist.SetFontStyle(
|
|
|
|
|
m_PopupMenu->IsChecked(WXLOWIN_MENU_ITALICS) ? wxNORMAL : wxITALIC
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case WXLOWIN_MENU_ROMAN:
|
|
|
|
|
m_llist.SetFontFamily(wxROMAN); break;
|
|
|
|
|
case WXLOWIN_MENU_TYPEWRITER:
|
|
|
|
|
m_llist.SetFontFamily(wxFIXED); break;
|
|
|
|
|
case WXLOWIN_MENU_SANSSERIF:
|
|
|
|
|
m_llist.SetFontFamily(wxSWISS); break;
|
|
|
|
|
}
|
|
|
|
|
}
|