updated wxLayout
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1645 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
eebb848a85
commit
b38142f370
@ -223,7 +223,15 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
Close( TRUE );
|
||||
break;
|
||||
case ID_PRINT:
|
||||
m_lwin->Print();
|
||||
{
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
_("There was a problem with printing the message:\n"
|
||||
"perhaps your current printer is not set up correctly?"),
|
||||
_("Printing"), wxOK);
|
||||
}
|
||||
break;
|
||||
case ID_NOWRAP:
|
||||
case ID_WRAP:
|
||||
|
@ -20,12 +20,15 @@
|
||||
is four cursor positions long. This makes sure that cursor
|
||||
positions are "as expected", i.e. in "abc\ndef" the 'd' would be
|
||||
at positions (x=0,y=1).
|
||||
|
||||
|
||||
The redrawing of the cursor no longer erases it at the last
|
||||
position, because the list gets redrawn anyway.
|
||||
*/
|
||||
|
||||
/*
|
||||
TODO:
|
||||
|
||||
- cursor redraw problems
|
||||
- blinking cursor
|
||||
- mouse click positions cursor
|
||||
- selection (SetMark(), GetSelection())
|
||||
@ -33,18 +36,13 @@
|
||||
- wxlwindow: formatting menu: problem with checked/unchecked consistency gtk bug?
|
||||
*/
|
||||
|
||||
/*
|
||||
Known wxGTK bugs:
|
||||
- MaxX()/MaxY() don't get set
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "wxllist.h"
|
||||
#endif
|
||||
|
||||
//#include "Mpch.h"
|
||||
#ifdef M_BASEDIR
|
||||
#ifdef M_PREFIX
|
||||
# include "gui/wxllist.h"
|
||||
#else
|
||||
# include "wxllist.h"
|
||||
@ -244,7 +242,8 @@ wxLayoutList::wxLayoutList()
|
||||
m_DefaultSetting = NULL;
|
||||
m_WrapMargin = -1;
|
||||
m_Editable = FALSE;
|
||||
|
||||
m_boldCursor = FALSE;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
@ -259,7 +258,6 @@ void
|
||||
wxLayoutList::LineBreak(void)
|
||||
{
|
||||
Insert(new wxLayoutObjectLineBreak);
|
||||
// m_CursorPos.x = 0; m_CursorPos.y++;
|
||||
}
|
||||
|
||||
void
|
||||
@ -420,7 +418,7 @@ wxLayoutList::Draw(wxDC &dc,
|
||||
iterator start,
|
||||
wxPoint const &translate)
|
||||
{
|
||||
Layout(dc); // FIXME just for now
|
||||
//Layout(dc); // FIXME just for now
|
||||
|
||||
ResetSettings(dc);
|
||||
|
||||
@ -449,7 +447,7 @@ wxLayoutList::Draw(wxDC &dc,
|
||||
|
||||
/** Erase at least to end of line */
|
||||
void
|
||||
wxLayoutList::EraseAndDraw(wxDC &dc, iterator start)
|
||||
wxLayoutList::EraseAndDraw(wxDC &dc, iterator start, wxPoint const &translate)
|
||||
{
|
||||
//look for begin of line
|
||||
while(start != end() && start != begin() && (**start).GetType() !=
|
||||
@ -468,7 +466,7 @@ wxLayoutList::EraseAndDraw(wxDC &dc, iterator start)
|
||||
dc.SetBrush(wxBrush(*m_ColourBG, wxSOLID));
|
||||
dc.SetPen(wxPen(*m_ColourBG,0,wxTRANSPARENT));
|
||||
dc.DrawRectangle(p.x,p.y,2000,2000); //dc.MaxX(),dc.MaxY());
|
||||
Draw(dc,-1,-1,start,wxPoint(0,0));
|
||||
Draw(dc,-1,-1,start,translate);
|
||||
//dc.DrawRectangle(p.x,p.y,2000,2000); //dc.MaxX(),dc.MaxY());
|
||||
}
|
||||
|
||||
@ -476,13 +474,18 @@ wxLayoutList::EraseAndDraw(wxDC &dc, iterator start)
|
||||
void
|
||||
wxLayoutList::CalculateCursor(wxDC &dc)
|
||||
{
|
||||
if(! m_CursorMoved)
|
||||
return;
|
||||
|
||||
CoordType width, height, descent;
|
||||
CoordType baseLineSkip = 20; //FIXME
|
||||
|
||||
int cursorWidth = m_boldCursor ? 4 : 2;
|
||||
|
||||
if( m_CursorObject == iterator(NULL)) // empty list
|
||||
{
|
||||
m_CursorCoords = wxPoint(0,0);
|
||||
m_CursorSize = wxPoint(2,baseLineSkip);
|
||||
m_CursorSize = wxPoint(cursorWidth,baseLineSkip);
|
||||
m_CursorMoved = false; // coords are valid
|
||||
return;
|
||||
}
|
||||
@ -497,14 +500,14 @@ wxLayoutList::CalculateCursor(wxDC &dc)
|
||||
dc.GetTextExtent(sstr,&width,&height,&descent);
|
||||
m_CursorCoords = wxPoint(m_CursorCoords.x+width,
|
||||
m_CursorCoords.y);
|
||||
m_CursorSize = wxPoint(2,height);
|
||||
m_CursorSize = wxPoint(cursorWidth,height);
|
||||
}
|
||||
else if(obj.GetType() == WXLO_TYPE_LINEBREAK)
|
||||
{
|
||||
if(m_CursorOffset == 1) // behind linebreak
|
||||
m_CursorCoords = wxPoint(0, m_CursorCoords.y + baseLineSkip);
|
||||
//m_CursorCoords = wxPoint(0, m_CursorCoords.y);
|
||||
m_CursorSize = wxPoint(2,baseLineSkip);
|
||||
m_CursorSize = wxPoint(cursorWidth,baseLineSkip);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -512,43 +515,52 @@ wxLayoutList::CalculateCursor(wxDC &dc)
|
||||
//cursorPosition = wxPoint(position.x, position.y);
|
||||
//cursorSize = wxPoint(size.x > 0 ? size.x : 1,size.y > 0 ? size.y : baseLineSkip);
|
||||
m_CursorCoords = wxPoint(m_CursorCoords.x+obj.GetSize().x, m_CursorCoords.y);
|
||||
m_CursorSize = wxPoint(2, obj.GetSize().y);
|
||||
m_CursorSize = wxPoint(cursorWidth, obj.GetSize().y);
|
||||
if(m_CursorSize.y < 1) m_CursorSize.y = baseLineSkip;
|
||||
}
|
||||
m_CursorMoved = false; // coords are valid
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutList::DrawCursor(wxDC &dc, bool erase)
|
||||
wxLayoutList::DrawCursor(wxDC &dc, bool erase, wxPoint const &translate)
|
||||
{
|
||||
if(! m_Editable)
|
||||
return;
|
||||
|
||||
if(erase)
|
||||
{
|
||||
//dc.SetBrush(*wxWHITE_BRUSH);
|
||||
//dc.SetPen(wxPen(*wxWHITE,1,wxSOLID));
|
||||
//dc.DrawRectangle(m_CursorCoords.x, m_CursorCoords.y, m_CursorSize.x, m_CursorSize.y);
|
||||
dc.Blit(m_CursorCoords.x, m_CursorCoords.y, m_CursorSize.x,
|
||||
m_CursorSize.y, &m_CursorMemDC,
|
||||
0, 0, 0, 0);
|
||||
}
|
||||
;
|
||||
#if 0
|
||||
dc.Blit(m_CursorCoords.x+translate.x,
|
||||
m_CursorCoords.y+translate.y,
|
||||
m_CursorSize.x,m_CursorSize.y,
|
||||
&m_CursorMemDC,
|
||||
0, 0, 0, 0);
|
||||
#endif
|
||||
else
|
||||
{
|
||||
// erase it at the old position:
|
||||
if(IsDirty() || CursorMoved())
|
||||
{
|
||||
DrawCursor(dc,true);
|
||||
// We don't need to erase the cursor because the screen gets
|
||||
// redrawn completely.
|
||||
// DrawCursor(dc,true);
|
||||
// this is needed to update the cursor coordinates
|
||||
Layout(dc);
|
||||
}
|
||||
// Save background:
|
||||
#if 0
|
||||
// Save background:
|
||||
wxBitmap bm(m_CursorSize.x+1,m_CursorSize.y+1);
|
||||
m_CursorMemDC.SelectObject(bm);
|
||||
m_CursorMemDC.Blit(0, 0, m_CursorSize.x, m_CursorSize.y,
|
||||
&dc, m_CursorCoords.x,
|
||||
m_CursorCoords.y, 0, 0);
|
||||
m_CursorMemDC.Blit(0, 0,
|
||||
m_CursorSize.x, m_CursorSize.y,
|
||||
&dc,
|
||||
m_CursorCoords.x+translate.x,
|
||||
m_CursorCoords.y+translate.y, 0, 0);
|
||||
#endif
|
||||
// draw it:
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
|
||||
dc.DrawRectangle(m_CursorCoords.x, m_CursorCoords.y,
|
||||
dc.DrawRectangle(m_CursorCoords.x+translate.x, m_CursorCoords.y+translate.y,
|
||||
m_CursorSize.x, m_CursorSize.y);
|
||||
}
|
||||
}
|
||||
@ -713,6 +725,11 @@ wxLayoutList::MoveCursor(int dx, int dy)
|
||||
if(newPos.y < 0) newPos.y = 0;
|
||||
else if(newPos.y > m_MaxLine) newPos.y = m_MaxLine;
|
||||
|
||||
//FIXME: quick and dirty hack: as last object in buffer should be a
|
||||
// linebreak, we don't allow to go there
|
||||
if(newPos.y >= m_MaxLine)
|
||||
return false;
|
||||
|
||||
if(newPos.y > m_CursorPos.y ||
|
||||
newPos.y == m_CursorPos.y &&
|
||||
newPos.x >= m_CursorPos.x)
|
||||
@ -720,7 +737,12 @@ wxLayoutList::MoveCursor(int dx, int dy)
|
||||
else
|
||||
direction = up;
|
||||
|
||||
wxASSERT(m_CursorObject);
|
||||
if ( !m_CursorObject )
|
||||
{
|
||||
// list is empty
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// now move cursor forwards until at the new position:
|
||||
|
||||
// first, go to the right line:
|
||||
@ -758,6 +780,12 @@ wxLayoutList::MoveCursor(int dx, int dy)
|
||||
newPos.y = m_CursorPos.y; // exited by break
|
||||
|
||||
// now line is right, go to right column:
|
||||
if(dx == 0) // we are moving up or down only
|
||||
{
|
||||
int max_x = GetLineLength(m_CursorObject);
|
||||
if(max_x <= newPos.x) // ... so we don't want to cross linebreaks
|
||||
newPos.x = max_x-1; // but just go to the right column
|
||||
}
|
||||
direction = newPos.x >= m_CursorPos.x ? down : up;
|
||||
while(newPos.x != m_CursorPos.x)
|
||||
{
|
||||
@ -819,8 +847,16 @@ wxLayoutList::MoveCursor(int dx, int dy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // FIXME: when return what?
|
||||
}
|
||||
void
|
||||
wxLayoutList::SetCursor(wxPoint const &p)
|
||||
{
|
||||
m_CursorPos = p;
|
||||
m_CursorObject = FindObjectCursor(&m_CursorPos, &m_CursorOffset);
|
||||
m_CursorMoved = true;
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutList::Delete(CoordType count)
|
||||
@ -842,8 +878,8 @@ wxLayoutList::Delete(CoordType count)
|
||||
if(i == end())
|
||||
return; // we cannot delete anything more
|
||||
|
||||
/* Here we need to treat linebreaks differently.
|
||||
If m_CursorOffset==0 we are before the linebreak, otherwise behind. */
|
||||
/* Here we need to treat linebreaks differently.
|
||||
If m_CursorOffset==0 we are before the linebreak, otherwise behind. */
|
||||
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
|
||||
{
|
||||
if(m_CursorOffset == 0)
|
||||
@ -866,26 +902,32 @@ wxLayoutList::Delete(CoordType count)
|
||||
{
|
||||
wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
|
||||
CoordType len = tobj->CountPositions();
|
||||
// If we find the end of a text object, this means that we
|
||||
// have to delete from the object following it.
|
||||
/* If we find the end of a text object, this means that we
|
||||
have to delete from the object following it. */
|
||||
if(len == m_CursorOffset)
|
||||
{
|
||||
i++;
|
||||
m_CursorOffset = 0;
|
||||
goto startover;
|
||||
}
|
||||
else if(len <= count) // delete this object
|
||||
{
|
||||
count -= len;
|
||||
erase(i);
|
||||
m_CursorObject = i;
|
||||
m_CursorOffset = 0;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = count;
|
||||
tobj->GetText().erase(m_CursorOffset,len);
|
||||
if(m_CursorOffset == 0 && len <= count) // delete this object
|
||||
{
|
||||
count -= len;
|
||||
erase(i);
|
||||
m_CursorObject = i;
|
||||
m_CursorOffset = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
int todelete = count;
|
||||
if(todelete > len-m_CursorOffset)
|
||||
todelete = len-m_CursorOffset;
|
||||
|
||||
len = len - todelete;
|
||||
tobj->GetText().erase(m_CursorOffset,todelete);
|
||||
count -= todelete;
|
||||
// cursor unchanged
|
||||
return; // we are done
|
||||
}
|
||||
@ -915,6 +957,7 @@ wxLayoutList::Delete(CoordType count)
|
||||
while(count && i != end());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wxLayoutList::Insert(wxLayoutObjectBase *obj)
|
||||
{
|
||||
@ -1074,7 +1117,10 @@ wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i, CoordType offs)
|
||||
CoordType len = 0;
|
||||
|
||||
if(offs == 0 && (**i).GetType() == WXLO_TYPE_LINEBREAK)
|
||||
i--;
|
||||
if(i != begin())
|
||||
i--;
|
||||
else
|
||||
return 0; // at begin of buffer in front of a linebreak
|
||||
|
||||
// search backwards for beginning of line:
|
||||
while(i != begin() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
|
||||
@ -1100,7 +1146,7 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
|
||||
m_dirty = true; // force redraw/recalc
|
||||
wxLayoutObjectList::iterator i = begin();
|
||||
|
||||
wxBitmap bm(1,1);
|
||||
wxBitmap bm(4,4);
|
||||
m_CursorMemDC.SelectObject(bm);
|
||||
|
||||
while(i != end()) // == while valid
|
||||
@ -1124,7 +1170,7 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
|
||||
m_CursorOffset = 0;
|
||||
m_CursorSize = wxPoint(2,(BASELINESTRETCH*m_FontPtSize)/10);
|
||||
|
||||
m_MaxLine = 1;
|
||||
m_MaxLine = 0;
|
||||
m_LineHeight = (BASELINESTRETCH*m_FontPtSize)/10;
|
||||
m_MaxX = 0; m_MaxY = 0;
|
||||
|
||||
@ -1211,8 +1257,8 @@ wxLayoutList::WrapLine(void)
|
||||
for(; offset > 0; offset--)
|
||||
if(t.GetText().c_str()[offset] == ' ' || t.GetText().c_str()[offset] == '\t')
|
||||
{
|
||||
String left = t.GetText().substr(0,offset-1); // get part before cursor
|
||||
t.GetText() = t.GetText().substr(offset,t.CountPositions()-offset); // keeps the right halve
|
||||
String left = t.GetText().substr(0,offset); // get part before cursor
|
||||
t.GetText() = t.GetText().substr(offset+1,t.CountPositions()-offset-1); // keeps the right halve
|
||||
insert(i,new wxLayoutObjectLineBreak);
|
||||
insert(i,new wxLayoutObjectText(left)); // inserts before
|
||||
break;
|
||||
@ -1322,10 +1368,9 @@ wxLayoutPrintout::DrawHeader(wxDC &dc,
|
||||
int pageno)
|
||||
{
|
||||
// make backups of all essential parameters
|
||||
wxBrush &brush = dc.GetBrush();
|
||||
wxPen &pen = dc.GetPen();
|
||||
wxFont &font = dc.GetFont(),
|
||||
*myfont;
|
||||
const wxBrush& brush = dc.GetBrush();
|
||||
const wxPen& pen = dc.GetPen();
|
||||
const wxFont& font = dc.GetFont();
|
||||
|
||||
dc.SetBrush(*wxWHITE_BRUSH);
|
||||
dc.SetPen(wxPen(*wxBLACK,0,wxSOLID));
|
||||
@ -1333,8 +1378,9 @@ wxLayoutPrintout::DrawHeader(wxDC &dc,
|
||||
topleft.y,bottomright.x-topleft.x,
|
||||
bottomright.y-topleft.y);
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
myfont = new wxFont((WXLO_DEFAULTFONTSIZE*12)/10,wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica");
|
||||
dc.SetFont(*myfont);
|
||||
wxFont myfont = wxFont((WXLO_DEFAULTFONTSIZE*12)/10,
|
||||
wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica");
|
||||
dc.SetFont(myfont);
|
||||
|
||||
wxString page;
|
||||
page = "9999/9999 "; // many pages...
|
||||
@ -1349,8 +1395,6 @@ wxLayoutPrintout::DrawHeader(wxDC &dc,
|
||||
dc.SetPen(pen);
|
||||
dc.SetBrush(brush);
|
||||
dc.SetFont(font);
|
||||
|
||||
delete myfont;
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
* *
|
||||
* $Id$
|
||||
*******************************************************************/
|
||||
|
||||
|
||||
#ifndef WXLLIST_H
|
||||
#define WXLLIST_H
|
||||
|
||||
@ -23,7 +25,7 @@
|
||||
// skip the following defines if embedded in M application
|
||||
#ifdef M_BASEDIR
|
||||
# ifdef DEBUG
|
||||
//# define WXLAYOUT_DEBUG
|
||||
# define WXLAYOUT_DEBUG
|
||||
# endif
|
||||
#else
|
||||
// for testing only:
|
||||
@ -328,7 +330,8 @@ public:
|
||||
wxPoint const &translate = wxPoint(0,0));
|
||||
|
||||
/** Deletes at least to the end of line and redraws */
|
||||
void EraseAndDraw(wxDC &dc, iterator start = iterator(NULL));
|
||||
void EraseAndDraw(wxDC &dc, iterator start = iterator(NULL),
|
||||
wxPoint const &translate = wxPoint(0,0));
|
||||
|
||||
/** Finds the object occupying a certain screen position.
|
||||
@return pointer to wxLayoutObjectBase or NULL if not found
|
||||
@ -360,9 +363,8 @@ public:
|
||||
bool IsEditable(void) const { return m_Editable; }
|
||||
/// move cursor, returns true if it could move to the desired position
|
||||
bool MoveCursor(int dx = 0, int dy = 0);
|
||||
void SetCursor(wxPoint const &p) { m_CursorPos = p; }
|
||||
void DrawCursor(wxDC &dc, bool erase = false);
|
||||
|
||||
void SetCursor(wxPoint const &p);
|
||||
void DrawCursor(wxDC &dc, bool erase = false,wxPoint const &translate = wxPoint(0,0));
|
||||
/// Get current cursor position cursor coords
|
||||
wxPoint GetCursor(void) const { return m_CursorPos; }
|
||||
/// Gets graphical coordinates of cursor
|
||||
@ -391,6 +393,13 @@ public:
|
||||
|
||||
/// Return maximum X,Y coordinates
|
||||
wxPoint GetSize(void) const { return wxPoint(m_MaxX, m_MaxY); }
|
||||
|
||||
/// calculates current cursor coordinates, called in Layout()
|
||||
void CalculateCursor(wxDC &dc);
|
||||
|
||||
/// toggle normal/bold cursor
|
||||
void SetBoldCursor(bool bold = true)
|
||||
{ m_boldCursor = bold; m_CursorMoved = true;}
|
||||
//@}
|
||||
protected:
|
||||
/// font parameters:
|
||||
@ -431,7 +440,7 @@ protected:
|
||||
/// object iterator for current cursor position:
|
||||
iterator m_CursorObject;
|
||||
/// position of cursor within m_CursorObject:
|
||||
int m_CursorOffset;
|
||||
CoordType m_CursorOffset;
|
||||
|
||||
/// to store content overwritten by cursor
|
||||
wxMemoryDC m_CursorMemDC;
|
||||
@ -450,14 +459,14 @@ protected:
|
||||
private:
|
||||
/// Resets the font settings etc to default values
|
||||
void ResetSettings(wxDC &dc);
|
||||
/// calculates current cursor coordinates, called in Layout()
|
||||
void CalculateCursor(wxDC &dc);
|
||||
/// remembers the last cursor position for which FindObjectCursor was called
|
||||
wxPoint m_FoundCursor;
|
||||
/// remembers the iterator to the object related to m_FoundCursor
|
||||
wxLayoutObjectList::iterator m_FoundIterator;
|
||||
/// the wrap margin
|
||||
long m_WrapMargin;
|
||||
/// draw a bold cursor?
|
||||
bool m_boldCursor;
|
||||
};
|
||||
|
||||
class wxLayoutPrintout: public wxPrintout
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*-*- c++ -*-********************************************************
|
||||
* wxlparser.h : parsers, import/export for wxLayoutList *
|
||||
* *
|
||||
* (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* (C) 1998,1999 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* *
|
||||
* $Id$
|
||||
*******************************************************************/
|
||||
@ -11,7 +11,7 @@
|
||||
#endif
|
||||
|
||||
//#include "Mpch.h"
|
||||
#ifdef M_BASEDIR
|
||||
#ifdef M_PREFIX
|
||||
# include "gui/wxllist.h"
|
||||
# include "gui/wxlparser.h"
|
||||
#else
|
||||
@ -21,18 +21,18 @@
|
||||
|
||||
#define BASE_SIZE 12
|
||||
|
||||
inline static bool IsEndOfLine(const char *p)
|
||||
inline static bool IsEndOfLine(const char *p, int mode)
|
||||
{
|
||||
// in addition to Unix EOL convention we also (but not instead) understand
|
||||
// the DOS one under Windows
|
||||
return
|
||||
#ifdef OS_WIN
|
||||
((*p == '\r') && (*(p + 1) == '\n')) ||
|
||||
#endif
|
||||
(*p == '\n');
|
||||
((mode & WXLO_EXPORT_WITH_MASK) == WXLO_EXPORT_WITH_CRLF) ?
|
||||
((*p == '\r') && (*(p + 1) == '\n'))
|
||||
:
|
||||
(((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
|
||||
}
|
||||
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str)
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str, int withflag)
|
||||
{
|
||||
char * cptr = (char *)str.c_str(); // string gets changed only temporarily
|
||||
const char * begin = cptr;
|
||||
@ -41,7 +41,7 @@ void wxLayoutImportText(wxLayoutList &list, String const &str)
|
||||
for(;;)
|
||||
{
|
||||
begin = cptr;
|
||||
while( *cptr && !IsEndOfLine(cptr) )
|
||||
while( *cptr && !IsEndOfLine(cptr, withflag) )
|
||||
cptr++;
|
||||
backup = *cptr;
|
||||
*cptr = '\0';
|
||||
@ -49,7 +49,7 @@ void wxLayoutImportText(wxLayoutList &list, String const &str)
|
||||
*cptr = backup;
|
||||
|
||||
// check if it's the end of this line
|
||||
if ( IsEndOfLine(cptr) )
|
||||
if ( IsEndOfLine(cptr, withflag) )
|
||||
{
|
||||
// if it was "\r\n", skip the following '\n'
|
||||
if ( *cptr == '\r' )
|
||||
@ -64,7 +64,7 @@ void wxLayoutImportText(wxLayoutList &list, String const &str)
|
||||
|
||||
static
|
||||
String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
wxLayoutStyleInfo **lastStylePtr)
|
||||
wxLayoutStyleInfo **lastStylePtr)
|
||||
{
|
||||
static char buffer[20];
|
||||
String html;
|
||||
@ -152,13 +152,13 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
#define WXLO_IS_TEXT(type) \
|
||||
( (type == WXLO_TYPE_TEXT || type == WXLO_TYPE_LINEBREAK) \
|
||||
|| (type == WXLO_TYPE_CMD \
|
||||
&& mode == WXLO_EXPORT_AS_HTML))
|
||||
&& (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML))
|
||||
|
||||
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
wxLayoutExportMode mode)
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
int mode)
|
||||
{
|
||||
if(from == list.end())
|
||||
return NULL;
|
||||
@ -168,7 +168,7 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
|
||||
static wxLayoutStyleInfo *s_si = NULL;
|
||||
|
||||
if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
|
||||
if( (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
|
||||
{
|
||||
export->type = WXLO_EXPORT_OBJECT;
|
||||
export->content.object = *from;
|
||||
@ -187,12 +187,15 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
*str += ((wxLayoutObjectText *)*from)->GetText();
|
||||
break;
|
||||
case WXLO_TYPE_LINEBREAK:
|
||||
if(mode == WXLO_EXPORT_AS_HTML)
|
||||
if((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
||||
*str += "<br>";
|
||||
*str += '\n';
|
||||
if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
|
||||
*str += "\r\n";
|
||||
else
|
||||
*str += '\n';
|
||||
break;
|
||||
case WXLO_TYPE_CMD:
|
||||
wxASSERT_MSG( mode == WXLO_EXPORT_AS_HTML,
|
||||
wxASSERT_MSG( (mode&WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML,
|
||||
"reached cmd object in text mode" );
|
||||
|
||||
*str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
|
||||
@ -205,7 +208,7 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
if(from != list.end())
|
||||
type = (*from)->GetType();
|
||||
}
|
||||
export->type = (mode == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
export->content.text = str;
|
||||
return export;
|
||||
}
|
||||
|
@ -25,10 +25,15 @@ enum wxLayoutExportType
|
||||
|
||||
enum wxLayoutExportMode
|
||||
{
|
||||
WXLO_EXPORT_AS_TEXT,
|
||||
WXLO_EXPORT_AS_TEXT_AND_COMMANDS,
|
||||
WXLO_EXPORT_AS_HTML,
|
||||
WXLO_EXPORT_AS_OBJECTS
|
||||
WXLO_EXPORT_AS_MASK = 0x0f,
|
||||
WXLO_EXPORT_AS_TEXT = 0x00,
|
||||
WXLO_EXPORT_AS_TEXT_AND_COMMANDS = 0x01,
|
||||
WXLO_EXPORT_AS_HTML = 0x02,
|
||||
WXLO_EXPORT_AS_OBJECTS = 0x03,
|
||||
|
||||
WXLO_EXPORT_WITH_MASK = 0xf0,
|
||||
WXLO_EXPORT_WITH_CRLF = 0x00,
|
||||
WXLO_EXPORT_WITH_LF_ONLY = 0x10
|
||||
};
|
||||
|
||||
struct wxLayoutExportObject
|
||||
@ -46,12 +51,22 @@ struct wxLayoutExportObject
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef OS_WIN
|
||||
/// import text into a wxLayoutList (including linefeeds):
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str);
|
||||
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str,
|
||||
int withflag = WXLO_EXPORT_WITH_CRLF);
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
wxLayoutExportMode WXLO_EXPORT_AS_TEXT);
|
||||
int mode = WXLO_EXPORT_AS_TEXT|WXLO_EXPORT_WITH_CRLF);
|
||||
#else
|
||||
/// import text into a wxLayoutList (including linefeeds):
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str,
|
||||
int withflag = WXLO_EXPORT_WITH_LF_ONLY);
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
int mode = WXLO_EXPORT_AS_TEXT|WXLO_EXPORT_WITH_LF_ONLY);
|
||||
#endif
|
||||
|
||||
#endif //WXLPARSER_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*-*- c++ -*-********************************************************
|
||||
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
|
||||
* *
|
||||
* (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* *
|
||||
* $Id$
|
||||
*******************************************************************/
|
||||
@ -12,10 +12,11 @@
|
||||
|
||||
//#include "Mpch.h"
|
||||
|
||||
#ifdef M_BASEDIR
|
||||
#ifdef M_PREFIX
|
||||
# ifndef USE_PCH
|
||||
# include "Mcommon.h"
|
||||
# include "gui/wxMenuDefs.h"
|
||||
# include "gui/wxMApp.h"
|
||||
# endif // USE_PCH
|
||||
# include "gui/wxlwindow.h"
|
||||
#else
|
||||
@ -30,7 +31,7 @@
|
||||
# include "wxlwindow.h"
|
||||
# define TRACEMESSAGE(x)
|
||||
#endif
|
||||
# define WXL_VAR(x) cerr << #x " = " << x ;
|
||||
# define WXL_VAR(x) { wxString s; s << #x " = " << x; wxLogDebug(s); }
|
||||
|
||||
BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
||||
EVT_PAINT (wxLayoutWindow::OnPaint)
|
||||
@ -47,6 +48,8 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
||||
EVT_MENU(WXLOWIN_MENU_ROMAN, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_TYPEWRITER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_SANSSERIF, wxLayoutWindow::OnMenu)
|
||||
EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus)
|
||||
EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
|
||||
@ -54,24 +57,34 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
|
||||
wxHSCROLL | wxVSCROLL | wxBORDER)
|
||||
|
||||
{
|
||||
m_ScrollbarsSet = false;
|
||||
m_doSendEvents = false;
|
||||
m_ViewStartX = 0; m_ViewStartY = 0;
|
||||
m_DoPopupMenu = true;
|
||||
m_PopupMenu = NULL;
|
||||
m_memDC = new wxMemoryDC;
|
||||
m_bitmap = new wxBitmap(4,4);
|
||||
m_bitmapSize = wxPoint(4,4);
|
||||
|
||||
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);
|
||||
m_maxx = max_x; m_maxy = max_y; m_lineHeight = lineHeight;
|
||||
}
|
||||
|
||||
wxLayoutWindow::~wxLayoutWindow()
|
||||
{
|
||||
delete m_memDC; // deletes bitmap automatically (?)
|
||||
delete m_bitmap;
|
||||
if(m_PopupMenu) delete m_PopupMenu;
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
long
|
||||
wxLayoutWindow::MSWGetDlgCode()
|
||||
{
|
||||
// if we don't return this, we won't get OnChar() events
|
||||
// if we don't return this, we won't get OnChar() events for TABs and ENTER
|
||||
return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_WANTMESSAGE;
|
||||
}
|
||||
#endif //MSW
|
||||
@ -79,15 +92,14 @@ wxLayoutWindow::MSWGetDlgCode()
|
||||
void
|
||||
wxLayoutWindow::Update(void)
|
||||
{
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
if(IsDirty())
|
||||
{
|
||||
DoPaint(dc);
|
||||
UpdateScrollbars();
|
||||
ResetDirty();
|
||||
DoPaint();
|
||||
}
|
||||
m_llist.DrawCursor(dc);
|
||||
else
|
||||
DoPaint(true); // only the cursor
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
@ -107,7 +119,14 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
||||
TRACEMESSAGE(("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
|
||||
event.GetX(), event.GetY(), findPos.x, findPos.y));
|
||||
|
||||
if(eventId == WXLOWIN_MENU_RCLICK && m_DoPopupMenu && m_llist.IsEditable())
|
||||
m_ClickPosition = findPos;
|
||||
wxLayoutObjectBase *obj = m_llist.Find(findPos);
|
||||
|
||||
// only do the menu if activated, editable and not on a clickable object
|
||||
if(eventId == WXLOWIN_MENU_RCLICK
|
||||
&& m_DoPopupMenu
|
||||
&& m_llist.IsEditable()
|
||||
&& obj && obj->GetUserData() == NULL)
|
||||
{
|
||||
// when does this menu get freed?
|
||||
// how do we handle toggling? FIXME
|
||||
@ -115,16 +134,85 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
||||
return;
|
||||
}
|
||||
// find the object at this position
|
||||
wxLayoutObjectBase *obj = m_llist.Find(findPos);
|
||||
if(obj)
|
||||
{
|
||||
wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, eventId);
|
||||
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
|
||||
commandEvent.SetEventObject( this );
|
||||
commandEvent.SetClientData((char *)obj);
|
||||
GetEventHandler()->ProcessEvent(commandEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteToEndOfLine(void)
|
||||
{
|
||||
int help = m_llist.GetLineLength(
|
||||
m_llist.GetCurrentObject())
|
||||
- m_llist.GetCursor().x;
|
||||
m_llist.Delete(help>1 ? help-1 : 1);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::GotoEndOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
p.x = m_llist.GetLineLength(m_llist.GetCurrentObject());
|
||||
if(p.x > 0) p.x --; // do not count the linebreak
|
||||
m_llist.SetCursor(p);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::GotoBeginOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
p.x = 0;
|
||||
m_llist.SetCursor(p);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteLine(void)
|
||||
{
|
||||
GotoBeginOfLine();
|
||||
DeleteToEndOfLine();
|
||||
m_llist.Delete(1); // newline
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteToBeginOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
int count = p.x;
|
||||
if(count > 0)
|
||||
{
|
||||
p.x = 0;
|
||||
m_llist.SetCursor(p);
|
||||
m_llist.Delete(count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wxLayoutWindow::ScrollToCursor(void)
|
||||
{
|
||||
/** 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();
|
||||
|
||||
if(cc.x < x0 || cc.y < y0
|
||||
|| cc.x >= x0+(9*x1)/10 || cc.y >= y0+(9*y1/10)) // (9*x)/10 == 90%
|
||||
{
|
||||
int nx, ny;
|
||||
nx = cc.x - (8*x1)/10; if(nx < 0) nx = 0;
|
||||
ny = cc.y - (8*y1)/10; if(ny < 0) ny = 0;
|
||||
Scroll(nx/ux,ny/uy);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* some simple keyboard handling
|
||||
*/
|
||||
@ -138,171 +226,178 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||
}
|
||||
|
||||
long keyCode = event.KeyCode();
|
||||
wxPoint p;
|
||||
CoordType help;
|
||||
|
||||
switch(event.KeyCode())
|
||||
|
||||
/* First, handle control keys */
|
||||
if(event.ControlDown())
|
||||
{
|
||||
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;
|
||||
case WXK_HOME:
|
||||
p = m_llist.GetCursor();
|
||||
p.x = 0;
|
||||
m_llist.SetCursor(p);
|
||||
break;
|
||||
case WXK_END:
|
||||
p = m_llist.GetCursor();
|
||||
p.x = m_llist.GetLineLength(m_llist.GetCurrentObject());
|
||||
m_llist.SetCursor(p);
|
||||
break;
|
||||
case WXK_DELETE :
|
||||
if(event.ControlDown()) // delete to end of line
|
||||
switch(event.KeyCode())
|
||||
{
|
||||
help = m_llist.GetLineLength(
|
||||
m_llist.GetCurrentObject())
|
||||
- m_llist.GetCursor().x;
|
||||
m_llist.Delete(help ? help : 1);
|
||||
case WXK_DELETE :
|
||||
case 'k':
|
||||
DeleteToEndOfLine(); break;
|
||||
case 'd':
|
||||
m_llist.Delete(1); break;
|
||||
case 'y':
|
||||
DeleteLine(); break;
|
||||
case 'h': // like backspace
|
||||
if(m_llist.MoveCursor(-1))
|
||||
m_llist.Delete(1);
|
||||
break;
|
||||
case 'u':
|
||||
DeleteToBeginOfLine(); break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
else
|
||||
m_llist.Delete(1);
|
||||
break;
|
||||
case WXK_BACK: // backspace
|
||||
if(m_llist.MoveCursor(-1)) {
|
||||
m_llist.Delete(1);
|
||||
}
|
||||
break;
|
||||
case WXK_RETURN:
|
||||
m_llist.LineBreak();
|
||||
break;
|
||||
}
|
||||
else // no control keys
|
||||
{
|
||||
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;
|
||||
case WXK_HOME:
|
||||
GotoBeginOfLine();
|
||||
break;
|
||||
case WXK_END:
|
||||
GotoEndOfLine();
|
||||
break;
|
||||
case WXK_DELETE :
|
||||
if(event.ControlDown()) // delete to end of line
|
||||
DeleteToEndOfLine();
|
||||
else
|
||||
m_llist.Delete(1);
|
||||
break;
|
||||
case WXK_BACK: // backspace
|
||||
if(m_llist.MoveCursor(-1)) {
|
||||
m_llist.Delete(1);
|
||||
}
|
||||
break;
|
||||
case WXK_RETURN:
|
||||
m_llist.LineBreak();
|
||||
break;
|
||||
|
||||
#ifdef WXLAYOUT_DEBUG
|
||||
case WXK_F1:
|
||||
m_llist.Debug();
|
||||
break;
|
||||
case WXK_F2:
|
||||
m_llist.WrapLine();
|
||||
break;
|
||||
case WXK_F1:
|
||||
m_llist.Debug();
|
||||
break;
|
||||
case WXK_F2:
|
||||
m_llist.WrapLine();
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
if(keyCode < 256 && keyCode >= 32)
|
||||
{
|
||||
String tmp;
|
||||
tmp += keyCode;
|
||||
m_llist.Insert(tmp);
|
||||
m_llist.WrapLine();
|
||||
default:
|
||||
if((!(event.ControlDown() || event.AltDown() || event.MetaDown()))
|
||||
&& (keyCode < 256 && keyCode >= 32)
|
||||
)
|
||||
{
|
||||
String tmp;
|
||||
tmp += keyCode;
|
||||
m_llist.Insert(tmp);
|
||||
m_llist.WrapLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
||||
ScrollToCursor();
|
||||
Update();
|
||||
ScrollToCursor();
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)) // or: OnDraw(wxDC& dc)
|
||||
{
|
||||
DoPaint();
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DoPaint(bool cursorOnly) // or: OnDraw(wxDC& dc)
|
||||
{
|
||||
wxPaintDC dc( this );
|
||||
PrepareDC( dc );
|
||||
|
||||
DoPaint(dc);
|
||||
|
||||
// wxGTK: wxMemoryDC broken?
|
||||
#if 0
|
||||
int x0,y0,x1,y1;
|
||||
// wxGTK: wxMemoryDC broken? YES!!
|
||||
int x0,y0,x1,y1, dx, dy;
|
||||
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);
|
||||
GetClientSize(&x1,&y1); // this is the size of the visible window
|
||||
wxASSERT(x1 > 0);
|
||||
wxASSERT(y1 > 0);
|
||||
GetScrollPixelsPerUnit(&dx, &dy);
|
||||
x0 *= dx; y0 *= dy;
|
||||
//FIXME: trying an offset for small border:
|
||||
wxPoint offset(-x0+4,-y0+4);
|
||||
|
||||
// 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
|
||||
|
||||
//Blit() doesn't work on scrolled window!
|
||||
// So we have to draw the cursor on the memdc.
|
||||
//if(! cursorOnly)
|
||||
{
|
||||
if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y)
|
||||
{
|
||||
wxASSERT(m_bitmapSize.x > 0);
|
||||
wxASSERT(m_bitmapSize.y > 0);
|
||||
|
||||
m_memDC->SelectObject(wxNullBitmap);
|
||||
delete m_bitmap;
|
||||
m_bitmapSize = wxPoint(x1,y1);
|
||||
m_bitmap = new wxBitmap(x1,y1);
|
||||
m_memDC->SelectObject(*m_bitmap);
|
||||
}
|
||||
m_memDC->SetDeviceOrigin(0,0);
|
||||
m_memDC->Clear();
|
||||
if(IsDirty() || m_llist.CursorMoved())
|
||||
m_llist.Layout(dc);
|
||||
|
||||
m_llist.EraseAndDraw(*m_memDC,
|
||||
wxLayoutObjectList::iterator(NULL),offset);
|
||||
m_llist.DrawCursor(*m_memDC,false,offset);
|
||||
dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
|
||||
}
|
||||
|
||||
//FIXME obsolete? ResetDirty();
|
||||
UpdateScrollbars();
|
||||
}
|
||||
|
||||
// does the actual painting
|
||||
// change the range and position of scroll bars
|
||||
void
|
||||
wxLayoutWindow::DoPaint(wxDC &dc)
|
||||
wxLayoutWindow::UpdateScrollbars(bool exact)
|
||||
{
|
||||
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
|
||||
CoordType
|
||||
max_x, max_y, lineHeight;
|
||||
|
||||
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
||||
|
||||
if(! m_ScrollbarsSet)
|
||||
if(max_x > m_maxx || max_y > m_maxy || exact)
|
||||
{
|
||||
m_ScrollbarsSet = true; // avoid recursion
|
||||
UpdateScrollbars();
|
||||
if(! exact) // add an extra 50% to the sizes to avoid future updates
|
||||
{
|
||||
max_x = (3*max_x)/2;
|
||||
max_y = (3*max_y)/2;
|
||||
}
|
||||
ViewStart(&m_ViewStartX, &m_ViewStartY);
|
||||
SetScrollbars(10, 20, max_x/10+1,max_y/20+1,m_ViewStartX,m_ViewStartY,true);
|
||||
m_maxx = max_x; m_maxy = max_y;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::UpdateScrollbars(void)
|
||||
wxLayoutWindow::Print(wxDC &dc)
|
||||
{
|
||||
CoordType
|
||||
max_x, max_y, lineHeight;
|
||||
|
||||
ViewStart(&m_ViewStartX, &m_ViewStartY);
|
||||
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
||||
SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1,m_ViewStartX,m_ViewStartY,true);
|
||||
//EnableScrolling(true,true);
|
||||
//Scroll(m_ViewStartX, m_ViewStartY);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::Print(void)
|
||||
{
|
||||
wxPostScriptDC dc("layout.ps",true,this);
|
||||
if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
|
||||
{
|
||||
//dc.SetUserScale(1.0, 1.0);
|
||||
@ -368,3 +463,17 @@ void wxLayoutWindow::OnMenu(wxCommandEvent& event)
|
||||
m_llist.SetFontFamily(wxSWISS); break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
|
||||
{
|
||||
m_llist.SetBoldCursor(true);
|
||||
DoPaint(true);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
|
||||
{
|
||||
m_llist.SetBoldCursor(false);
|
||||
Update();
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ public:
|
||||
*/
|
||||
wxLayoutWindow(wxWindow *parent);
|
||||
|
||||
/// Destructor.
|
||||
virtual ~wxLayoutWindow();
|
||||
|
||||
/* Returns a reference to the wxLayoutList object.
|
||||
@return the list
|
||||
*/
|
||||
@ -54,14 +57,13 @@ public:
|
||||
{
|
||||
GetLayoutList().Clear(family,size,style,weight,underline,fg,bg);
|
||||
SetBackgroundColour( *GetLayoutList().GetDefaults()->GetBGColour());
|
||||
|
||||
Update();
|
||||
m_bDirty = FALSE;
|
||||
}
|
||||
|
||||
// callbacks
|
||||
// NB: these functions are used as event handlers and must not be virtual
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
|
||||
void OnLeftMouseClick(wxMouseEvent& event)
|
||||
{ OnMouse(WXLOWIN_MENU_LCLICK, event); }
|
||||
void OnRightMouseClick(wxMouseEvent& event)
|
||||
@ -74,29 +76,42 @@ public:
|
||||
|
||||
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
|
||||
/// gets called by either Update() or OnPaint()
|
||||
void DoPaint(wxDC &dc);
|
||||
void DoPaint(bool cursoronly = false);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
virtual long MSWGetDlgCode();
|
||||
#endif //MSW
|
||||
|
||||
void UpdateScrollbars(void);
|
||||
void Print(void);
|
||||
wxMenu * wxLayoutWindow::MakeFormatMenu(void);
|
||||
/// if exact == false, assume 50% extra size for the future
|
||||
void UpdateScrollbars(bool exact = false); // don't change this to true!
|
||||
void Print(wxDC &dc);
|
||||
wxMenu * MakeFormatMenu(void);
|
||||
|
||||
/// if the flag is true, we send events when user clicks on embedded objects
|
||||
inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
|
||||
|
||||
virtual ~wxLayoutWindow() { if(m_PopupMenu) delete m_PopupMenu; }
|
||||
|
||||
// dirty flag access
|
||||
bool IsDirty() const { return m_llist.IsDirty(); }
|
||||
void ResetDirty() { m_llist.ResetDirty(); }
|
||||
|
||||
void OnSetFocus(wxFocusEvent &ev);
|
||||
void OnKillFocus(wxFocusEvent &ev);
|
||||
protected:
|
||||
/// Deletes from cursor to end of line.
|
||||
void DeleteToEndOfLine(void);
|
||||
/// Deletes everything left of cursor.
|
||||
void DeleteToBeginOfLine(void);
|
||||
/// Goto end of line.
|
||||
void GotoEndOfLine(void);
|
||||
/// Goto begin of line.
|
||||
void GotoBeginOfLine(void);
|
||||
/// Delete Line
|
||||
void DeleteLine(void);
|
||||
/// generic function for mouse events processing
|
||||
void OnMouse(int eventId, wxMouseEvent& event);
|
||||
|
||||
/// scroll to cursor
|
||||
void ScrollToCursor(void);
|
||||
|
||||
/// repaint if needed
|
||||
void Update(void);
|
||||
|
||||
@ -107,8 +122,6 @@ protected:
|
||||
/// the layout list to be displayed
|
||||
wxLayoutList m_llist;
|
||||
|
||||
/// have we already set the scrollbars?
|
||||
bool m_ScrollbarsSet;
|
||||
/// Where does the current view start?
|
||||
int m_ViewStartX; int m_ViewStartY;
|
||||
|
||||
@ -119,7 +132,17 @@ protected:
|
||||
bool m_DoPopupMenu;
|
||||
/// the menu
|
||||
wxMenu * m_PopupMenu;
|
||||
/// for derived classes, set when mouse is clicked
|
||||
wxPoint m_ClickPosition;
|
||||
/// for scrollbar calculations:
|
||||
int m_maxx;
|
||||
int m_maxy;
|
||||
int m_lineHeight;
|
||||
private:
|
||||
wxMemoryDC *m_memDC;
|
||||
wxBitmap *m_bitmap;
|
||||
wxPoint m_bitmapSize;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user