deleted by list. See the constructor for more details.
@param ownsflag if true, list will own entries
*/
- void ownsObjects(bool ownsflag = true)
+ void ownsObjects(bool ownsflag)
{ ownsEntries = ownsflag; }
/** Query whether list owns entries.
param iterator i
*/
inline void deleteContent(iterator i)
- { if(ownsEntries) delete *i; }
+ {
+ iterator *i_ptr = &i;
+ if(ownsEntries) delete i_ptr;
+ }
private:
#endif
#include "wxLayout.h"
-#include <wx/textfile.h>
-#include <wx/image.h>
+#include "wx/textfile.h"
+#include "wx/image.h"
#if wxUSE_IOSTREAMH
#include <iostream.h>
#include <iostream>
#endif
-#include "Micon.xpm"
+#include "wx/wfstream.h"
+#include "wx/txtstrm.h"
+
+#include "Micon.xpm"
//-----------------------------------------------------------------------------
END_EVENT_TABLE()
-MyFrame::MyFrame(void) :
- wxFrame( (wxFrame *) NULL, -1, _T("wxLayout"),
- wxPoint(880,100), wxSize(256,256) )
+MyFrame::MyFrame() :
+ wxFrame( (wxFrame *) NULL, wxID_ANY, _T("wxLayout"),
+ wxDefaultPosition, wxDefaultSize )
{
CreateStatusBar( 2 );
menu_bar->Append(edit_menu, _T("&Edit") );
#ifndef __WXMSW__
- menu_bar->Show( TRUE );
+ menu_bar->Show(true);
#endif // MSW
SetMenuBar( menu_bar );
#endif // 0
};
-void
-MyFrame::AddSampleText(wxLayoutList *llist)
+void MyFrame::AddSampleText(wxLayoutList *llist)
{
llist->Clear(wxSWISS,16,wxNORMAL,wxNORMAL, false);
llist->SetFont(-1,-1,-1,-1,-1,_T("blue"));
llist->Insert(_T("blue"));
+ llist->LineBreak();
+
llist->SetFont(-1,-1,-1,-1,-1,_T("black"));
llist->Insert(_T("The quick brown fox jumps over the lazy dog."));
llist->LineBreak();
llist->SetFont(wxROMAN);
llist->Insert(_T("The quick brown fox jumps over the lazy dog."));
llist->LineBreak();
- llist->Insert(_T("Hello "));
+
+ llist->Insert(_T("Hello "));
+ wxBitmap *icon =
#if wxICON_IS_BITMAP
- llist->Insert(new wxLayoutObjectIcon(new wxICON(Micon)));
+ new wxIcon(Micon_xpm)
#else
- llist->Insert(new wxLayoutObjectIcon(new wxBitmap (wxICON(Micon))));
+ new wxBitmap (wxIcon(Micon_xpm))
#endif
- llist->SetFontWeight(wxBOLD);
- llist->Insert(_T("World! "));
- llist->SetFontWeight(wxNORMAL);
- llist->Insert(_T("The quick brown fox jumps..."));
- llist->LineBreak();
- llist->Insert(_T("over the lazy dog."));
- llist->SetFont(-1,-1,-1,-1,true);
- llist->Insert(_T("underlined"));
- llist->SetFont(-1,-1,-1,-1,false);
- llist->SetFont(wxROMAN);
- llist->Insert(_T("This is "));
- llist->SetFont(-1,-1,-1,wxBOLD); llist->Insert(_T("BOLD ")); llist->SetFont(-1,-1,-1,wxNORMAL);
- llist->Insert(_T("and "));
- llist->SetFont(-1,-1,wxITALIC);
- llist->Insert(_T("italics "));
- llist->SetFont(-1,-1,wxNORMAL);
- llist->LineBreak();
- llist->Insert(_T("and "));
- llist->SetFont(-1,-1,wxSLANT);
- llist->Insert(_T("slanted"));
- llist->SetFont(-1,-1,wxNORMAL);
- llist->Insert(_T(" text."));
- llist->LineBreak();
- llist->Insert(_T("and "));
- llist->SetFont(-1,-1,-1,-1,-1,_T("blue"));
- llist->Insert(_T("blue"));
- llist->SetFont(-1,-1,-1,-1,-1,_T("black"));
- llist->Insert(_T(" and "));
- llist->SetFont(-1,-1,-1,-1,-1,_T("green"),_T("black"));
- llist->Insert(_T("green on black"));
- llist->SetFont(-1,-1,-1,-1,-1,_T("black"),_T("white"));
- llist->Insert(_T(" text."));
- llist->LineBreak();
-
- llist->SetFont(-1,-1,wxSLANT);
- llist->Insert(_T("Slanted"));
- llist->SetFont(-1,-1,wxNORMAL);
- llist->Insert(_T(" and normal text and "));
- llist->SetFont(-1,-1,wxSLANT);
- llist->Insert(_T("slanted"));
- llist->SetFont(-1,-1,wxNORMAL);
- llist->Insert(_T(" again."));
- llist->LineBreak();
-
- // add some more text for testing:
- llist->Insert(_T("And here the source for the test program:"));
- llist->LineBreak();
- llist->SetFont(wxTELETYPE,16);
- llist->Insert(_T("And here the source for the test program:"));
- llist->LineBreak();
- llist->Insert(_T("And here the source for the test program:"));
- llist->LineBreak();
- llist->Insert(_T("And here the source for the test program:"));
- wxFile file( _T("wxLayout.cpp") );
- if ( file.IsOpened() )
- {
- off_t len = file.Length();
- wxChar *data = (wxChar *)malloc(2*len);
- if ( file.Read(data, len) == len )
- {
- wxLayoutImportText(llist, data);
- }
- free(data);
- }
+ ;
+
+ llist->Insert(new wxLayoutObjectIcon(icon));
+ llist->SetFontWeight(wxBOLD);
+ llist->Insert(_T("World! "));
+ llist->SetFontWeight(wxNORMAL);
+ llist->Insert(_T("The quick brown fox jumps..."));
+ llist->LineBreak();
+
+ llist->Insert(_T("over the lazy dog."));
+ llist->SetFont(-1,-1,-1,-1,true);
+ llist->Insert(_T("underlined"));
+ llist->SetFont(-1,-1,-1,-1,false);
+ llist->SetFont(wxROMAN);
+ llist->Insert(_T("This is "));
+ llist->SetFont(-1,-1,-1,wxBOLD);
+ llist->Insert(_T("BOLD "));
+ llist->SetFont(-1,-1,-1,wxNORMAL);
+ llist->Insert(_T("and "));
+ llist->SetFont(-1,-1,wxITALIC);
+ llist->Insert(_T("italics "));
+ llist->SetFont(-1,-1,wxNORMAL);
+ llist->LineBreak();
+
+ llist->Insert(_T("and "));
+ llist->SetFont(-1,-1,wxSLANT);
+ llist->Insert(_T("slanted"));
+ llist->SetFont(-1,-1,wxNORMAL);
+ llist->Insert(_T(" text."));
+ llist->LineBreak();
+
+ llist->Insert(_T("and "));
+ llist->SetFont(-1,-1,-1,-1,-1,_T("blue"));
+ llist->Insert(_T("blue"));
+ llist->SetFont(-1,-1,-1,-1,-1,_T("black"));
+ llist->Insert(_T(" and "));
+ llist->SetFont(-1,-1,-1,-1,-1,_T("green"),_T("black"));
+ llist->Insert(_T("green on black"));
+ llist->SetFont(-1,-1,-1,-1,-1,_T("black"),_T("white"));
+ llist->Insert(_T(" text."));
+ llist->LineBreak();
+
+ llist->SetFont(-1,-1,wxSLANT);
+ llist->Insert(_T("Slanted"));
+ llist->SetFont(-1,-1,wxNORMAL);
+ llist->Insert(_T(" and normal text and "));
+ llist->SetFont(-1,-1,wxSLANT);
+ llist->Insert(_T("slanted"));
+ llist->SetFont(-1,-1,wxNORMAL);
+ llist->Insert(_T(" again."));
+ llist->LineBreak();
+
+ // add some more text for testing:
+ llist->Insert(_T("And here the source for the test program:"));
+ llist->LineBreak();
+
+ llist->SetFont(wxTELETYPE,16);
+ llist->Insert(_T("And here the source for the test program:"));
+ llist->LineBreak();
+
+ wxTextFile file(_T("wxLayout.cpp"));
+ if ( file.Open() )
+ {
+ for ( wxString s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
+ {
+ wxString line;
+ llist->Insert(line.Format(_T("%6u: %s"),file.GetCurrentLine()+1,s.c_str()));
+ llist->LineBreak();
+ }
+ }
- llist->MoveCursorTo(wxPoint(0,0));
- m_lwin->SetDirty();
- m_lwin->Refresh();
+ llist->MoveCursorTo(wxPoint(0,0));
+ m_lwin->SetDirty();
+ m_lwin->Refresh();
}
-void
-MyFrame::Clear(void)
+void MyFrame::Clear()
{
- wxColour colBg(0, 0, 0);
+ wxColour colBg(0, 0, 0);
- m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false, wxRED, &colBg);
+ m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false, wxRED, &colBg);
}
switch (event.GetId())
{
case ID_QUIT:
- Close( TRUE );
+ Close(true);
break;
case ID_PRINT:
{
wxPrinter printer;
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
- if (! printer.Print(this, &printout, TRUE))
+ if (! printer.Print(this, &printout, true))
{
// Had to remove the split up strings that used to be below, and
// put them into one long strong. Otherwise MSVC would give an
Clear();
break;
case ID_CLICK:
- cerr << "Received click event." << endl;
+ wxLogError( _T("Received click event.") );
break;
case ID_PASTE:
- m_lwin->Paste(TRUE);
- m_lwin->Refresh(FALSE);
+ m_lwin->Paste(true);
+ m_lwin->Refresh(false);
break;
#ifdef __WXGTK__
case ID_PASTE_PRIMARY:
// text only from primary:
- m_lwin->Paste(FALSE, TRUE);
- m_lwin->Refresh(FALSE);
+ m_lwin->Paste(false, true);
+ m_lwin->Refresh(false);
break;
case ID_COPY_PRIMARY:
// copy text-only to primary selection:
- m_lwin->Copy(FALSE,FALSE,TRUE);
- m_lwin->Refresh(FALSE);
+ m_lwin->Copy(false, false, true);
+ m_lwin->Refresh(false);
break;
#endif
case ID_COPY:
- m_lwin->Copy(TRUE,TRUE,FALSE);
- m_lwin->Refresh(FALSE);
+ m_lwin->Copy(true, true, false);
+ m_lwin->Refresh(false);
break;
case ID_CUT:
m_lwin->Cut();
- m_lwin->Refresh(FALSE);
+ m_lwin->Refresh(false);
break;
#ifdef M_BASEDIR
case ID_FIND:
m_lwin->Find("void");
- m_lwin->Refresh(FALSE);
+ m_lwin->Refresh(false);
break;
#endif
case ID_HTML:
{
+ wxFileDialog
+ HTML_dialog( this,
+ _T("Save As HTML..."),
+ wxEmptyString,
+ wxEmptyString,
+ _T("HTML file (*.html)|*.html|Text file (*.txt)|*.txt|Any file (*)|*"),
+ wxSAVE|wxOVERWRITE_PROMPT
+ );
+ if (HTML_dialog.ShowModal() == wxID_OK)
+ {
+ wxFFileOutputStream output( HTML_dialog.GetPath() );
+ wxTextOutputStream textout( output );
+
wxLayoutExportObject *export0;
+ wxString object;
wxLayoutExportStatus status(m_lwin->GetLayoutList());
-
- cout << "<HTML>" << endl;
- while((export0 = wxLayoutExport( &status,
- WXLO_EXPORT_AS_HTML)) != NULL)
+ while((export0 = wxLayoutExport( &status, WXLO_EXPORT_AS_HTML)) != NULL)
{
if(export0->type == WXLO_EXPORT_HTML)
- cout << *(export0->content.text);
+ object = *(export0->content.text);
else
- ; // ignore itcout << "<!--UNKNOWN OBJECT>";
-
+ ; // ignore "<!--UNKNOWN OBJECT>";
delete export0;
+ textout << object;
+ }
}
break;
}
case ID_TEXT:
{
+ wxFileDialog
+ TEXT_dialog( this,
+ _T("Save As TXT..."),
+ wxEmptyString,
+ wxEmptyString,
+ _T("Text file (*.txt)|*.txt|Any file (*)|*"),
+ wxSAVE|wxOVERWRITE_PROMPT
+ );
+ if (TEXT_dialog.ShowModal() == wxID_OK)
+ {
+ wxFFileOutputStream output( TEXT_dialog.GetPath() );
+ wxTextOutputStream textout( output );
+
wxLayoutExportObject *export0;
+ wxString object;
wxLayoutExportStatus status(m_lwin->GetLayoutList());
-
while((export0 = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
{
if(export0->type == WXLO_EXPORT_TEXT)
- cout << *(export0->content.text);
+ object = *(export0->content.text);
else
- cout << "<!--UNKNOWN OBJECT>";
-
+ object = _T("<!--UNKNOWN OBJECT>");
delete export0;
+ textout << object;
+ }
}
-
break;
}
-
case ID_LONG_TEST:
{
wxString line;
// wxLayoutWindow should have a flag m_highlightUrls and do it itself
// (instead of doing it manually like M does now)
m_lwin->GetLayoutList()->Insert(_T("http://www.wxwindows.org/"));
+ m_lwin->Refresh();
}
};
#endif
wxPrinter printer;
wxLayoutPrintout printout( m_lwin->GetLayoutList(), _T("Printout from wxLayout"));
- if (! printer.Print(this, &printout, TRUE))
+ if (! printer.Print(this, &printout, true))
wxMessageBox(
_T("There was a problem printing.\nPerhaps your current printer is not set correctly?"),
_T("Printing"), wxOK);
#ifdef OS_UNIX
wxPostScriptPrinter printer;
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
- printer.Print(this, &printout, TRUE);
+ printer.Print(this, &printout, true);
#endif
}
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
frame->Centre(wxBOTH);
frame->Initialize();
- frame->Show(TRUE);
+ frame->Show(true);
}
void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
frame->Centre(wxBOTH);
frame->Initialize();
- frame->Show(TRUE);
+ frame->Show(true);
}
void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
// MyApp
//-----------------------------------------------------------------------------
-MyApp::MyApp(void) :
+MyApp::MyApp() :
wxApp( )
{
};
-bool MyApp::OnInit(void)
+bool MyApp::OnInit()
{
wxFrame *frame = new MyFrame();
wxInitAllImageHandlers();
- frame->Show( TRUE );
+ frame->Show( true );
// wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
- return TRUE;
+ return true;
};
#pragma interface
#endif
-#include <wx/wx.h>
+#include "wx/wx.h"
#include "wxllist.h"
#include "wxlwindow.h"
class MyFrame: public wxFrame
{
- DECLARE_DYNAMIC_CLASS(MyFrame)
- public:
-
- MyFrame(void);
- void AddSampleText(wxLayoutList *llist);
- void Clear(void);
- void OnCommand( wxCommandEvent &event );
+public:
+
+ MyFrame();
+ void AddSampleText(wxLayoutList *llist);
+ void Clear();
+ void OnCommand( wxCommandEvent &event );
void OnPrint(wxCommandEvent& event);
void OnPrintPreview(wxCommandEvent& event);
void OnPrintSetupPS(wxCommandEvent& event);
void OnPageSetupPS(wxCommandEvent& event);
- DECLARE_EVENT_TABLE()
private:
- wxLayoutWindow *m_lwin;
- wxPrintData m_PrintData;
+ wxLayoutWindow *m_lwin;
+ wxPrintData m_PrintData;
+
+ DECLARE_DYNAMIC_CLASS(MyFrame)
+
+ DECLARE_EVENT_TABLE()
};
//-----------------------------------------------------------------------------
class MyApp: public wxApp
{
- public:
-
- MyApp(void);
- virtual bool OnInit(void);
+public:
+
+ MyApp();
+
+ virtual bool OnInit();
+
};
#endif // __WXCONVERTH__
+
#include <iostream>
#endif
-# include <wx/dc.h>
-# include <wx/dcps.h>
-# include <wx/print.h>
-# include <wx/log.h>
-# include <wx/filefn.h>
+# include "wx/dc.h"
+# include "wx/dcps.h"
+# include "wx/print.h"
+# include "wx/log.h"
+# include "wx/filefn.h"
#endif
#ifdef WXLAYOUT_USE_CARET
-# include <wx/caret.h>
+# include "wx/caret.h"
#endif // WXLAYOUT_USE_CARET
#include <ctype.h>
_T("invalid"), _T("text"), _T("cmd"), _T("icon")
};
wxString
- wxLayoutObject::DebugDump(void) const
+ wxLayoutObject::DebugDump() const
{
wxString str;
str.Printf(wxT("%s"), g_aTypeStrings[GetType()]);
return wxLayoutObjectCmd::Read(istr);
case WXLO_TYPE_ICON:
return wxLayoutObjectIcon::Read(istr);
- default:
- return NULL;
}
+
+ return NULL;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
}
wxLayoutObject *
-wxLayoutObjectText::Copy(void)
+wxLayoutObjectText::Copy()
{
wxLayoutObjectText *obj = new wxLayoutObjectText(m_Text);
obj->m_Width = m_Width;
#ifdef WXLAYOUT_DEBUG
wxString
-wxLayoutObjectText::DebugDump(void) const
+wxLayoutObjectText::DebugDump() const
{
wxString str;
str = wxLayoutObject::DebugDump();
delete obj;
return NULL;
}
- else
- return obj;
+
+ return obj;
}
wxLayoutObject *
-wxLayoutObjectIcon::Copy(void)
+wxLayoutObjectIcon::Copy()
{
wxLayoutObjectIcon *obj = new wxLayoutObjectIcon(new
wxBitmap(*m_Icon));
CoordType WXUNUSED(begin), CoordType WXUNUSED(len) )
{
dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(),
- (m_Icon->GetMask() == NULL) ? FALSE : TRUE);
+ (m_Icon->GetMask() == NULL) ? false : true);
}
void
}
wxLayoutObject *
-wxLayoutObjectCmd::Copy(void)
+wxLayoutObjectCmd::Copy()
{
wxLayoutObjectCmd *obj = new wxLayoutObjectCmd(
m_StyleInfo->family,
}
wxLayoutStyleInfo *
-wxLayoutObjectCmd::GetStyle(void) const
+wxLayoutObjectCmd::GetStyle() const
{
return m_StyleInfo;
}
CoordType
wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const
{
- int
- cpos = 0,
- relpos = -1;
+ int cpos = 0;
wxString const *text;
for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++)
if((**i).GetType() == WXLO_TYPE_TEXT)
{
text = & ((wxLayoutObjectText*)(*i))->GetText();
- relpos = text->Find(needle);
+ int relpos = text->Find(needle);
if(relpos >= cpos-xpos) // -1 if not found
{
return cpos+relpos;
if(highlight == -1) // partially highlight line
{
// parts of the line need highlighting
- xpos+(**i).GetLength();
+
+ // Next line commented, code has no effect
+ // xpos+(**i).GetLength();
(**i).Draw(dc, pos, llist, from-xpos, to-xpos);
}
else
bool cursorFound = false;
RecalculatePosition(llist);
-
+
if(cursorPos)
{
*cursorPos = m_Position;
cursorSize->x = width;
cursorSize->y = height;
}
-
+
cursorFound = true; // no more checks
}
else
{
m_Next->MarkDirty();
}
-
+
// We need to check whether we found a valid cursor size:
if(cursorPos && cursorSize)
{
wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist)
{
if(GetLength() < wrapmargin)
- return FALSE; // nothing to do
-
+ return false; // nothing to do
+
// find the object which covers the wrapmargin:
CoordType offset;
wxLOiterator i = FindObject(wrapmargin, &offset);
- wxCHECK_MSG( i != NULLIT, FALSE,
+ wxCHECK_MSG( i != NULLIT, false,
wxT("Cannot find object covering wrapmargin."));
-
+
// from this object on, the rest of the line must be copied to the
// next one:
wxLOiterator copyObject = NULLIT;
size_t shorter = 0;
// remember cursor location of object
size_t objectCursorPos = 0;
-
+
size_t breakpos = offset;
if( (**i).GetType() != WXLO_TYPE_TEXT )
}
else
{
- bool foundSpace = FALSE;
+ bool foundSpace = false;
do
{
// while(i != NULLIT && (**i).GetType() != WXLO_TYPE_TEXT)
if(! foundSpace) // breakpos == 0!
{
if(i == m_ObjectList.begin())
- return FALSE; // could not break line
+ return false; // could not break line
else
{
i--;
(void) new wxLayoutLine(this, llist);
wxASSERT(m_Next);
// We need to move this and all following objects to the next
- // line. Starting from the end of line, to keep the order right.
+ // line. Starting from the end of line, to keep the order right.
if(copyObject != NULLIT)
{
wxLOiterator j;
}
}
m_Length -= shorter;
-
+
if(prependText.Length() > 0)
m_Next->Insert(0, prependText);
#endif
llist->MoveCursorTo( wxPoint( xpos, m_Next->GetLineNumber()) );
}
- return TRUE; // we wrapped the line
+ return true; // we wrapped the line
}
void
-wxLayoutLine::ReNumber(void)
+wxLayoutLine::ReNumber()
{
CoordType lineNo = m_Previous ? m_Previous->m_LineNumber+1 : 0;
m_LineNumber = lineNo++;
-
+
for(wxLayoutLine *next = GetNextLine();
next; next = next->GetNextLine())
next->m_LineNumber = lineNo++;
#ifdef WXLAYOUT_DEBUG
void
-wxLayoutLine::Debug(void) const
+wxLayoutLine::Debug() const
{
wxPoint pos = GetPosition();
WXLO_DEBUG((wxT("Line %ld, Pos (%ld,%ld), Height %ld, BL %ld, Font: %d"),
m_numLines = 0;
m_FirstLine = NULL;
- SetAutoFormatting(TRUE);
- ForceTotalLayout(TRUE); // for the first time, do all
+ SetAutoFormatting(true);
+ ForceTotalLayout(true); // for the first time, do all
InvalidateUpdateRect();
Clear();
}
wxLayoutList::~wxLayoutList()
{
- SetAutoFormatting(FALSE);
+ SetAutoFormatting(false);
InternalClear();
Empty();
m_FirstLine->DeleteLine(false, this);
}
void
-wxLayoutList::Empty(void)
+wxLayoutList::Empty()
{
while(m_FirstLine)
m_FirstLine = m_FirstLine->DeleteLine(false, this);
void
-wxLayoutList::InternalClear(void)
+wxLayoutList::InternalClear()
{
m_Selection.m_selecting = false;
m_Selection.m_valid = false;
m_DefaultStyleInfo.style = wxNORMAL;
m_DefaultStyleInfo.weight = wxNORMAL;
m_DefaultStyleInfo.underline = 0;
- m_DefaultStyleInfo.m_fg_valid = TRUE;
+ m_DefaultStyleInfo.m_fg_valid = true;
m_DefaultStyleInfo.m_fg = *wxBLACK;
- m_DefaultStyleInfo.m_bg_valid = TRUE;
+ m_DefaultStyleInfo.m_bg_valid = true;
m_DefaultStyleInfo.m_bg = *wxWHITE;
m_CurrentStyleInfo = m_DefaultStyleInfo;
wxLayoutList::Insert(wxLayoutList *llist)
{
wxASSERT(llist);
- bool rc = TRUE;
+ bool rc = true;
for(wxLayoutLine *line = llist->GetFirstLine();
line;
}
bool
-wxLayoutList::LineBreak(void)
+wxLayoutList::LineBreak()
{
wxASSERT(m_CursorLine);
// The following code will produce a height which is guaranteed to
// be too high: old lineheight + the height of both new lines.
- // We can probably drop the old line height and start with height =
+ // We can probably drop the old line height and start with height =
// 0. FIXME
wxLayoutLine *prev = m_CursorLine->GetPreviousLine();
if(prev)
{
wxLayoutLine *line = m_FirstLine;
if(! line)
- return FALSE;
- bool rc = TRUE;
+ return false;
+ bool rc = true;
while(line && rc)
{
rc &= line->Wrap(column, this);
}
wxPoint
-wxLayoutList::GetCursorScreenPos(void) const
+wxLayoutList::GetCursorScreenPos() const
{
return m_CursorScreenPos;
}
*/
void
wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
- wxPoint *cpos, wxPoint *csize)
+ wxPoint *cpos, wxPoint *csize)
{
- // first, make sure everything is calculated - this might not be
- // needed, optimise it later
- ApplyStyle(m_DefaultStyleInfo, dc);
+ // first, make sure everything is calculated - this might not be
+ // needed, optimise it later
+ ApplyStyle(m_DefaultStyleInfo, dc);
-
- if(m_ReLayoutAll)
- {
- forceAll = TRUE;
- bottom = -1;
- }
- ForceTotalLayout(FALSE);
-
-
- // If one line was dirty, we need to re-calculate all
- // following lines, too.
- bool wasDirty = forceAll;
- // we need to layout until we reach at least the cursor line,
- // otherwise we won't be able to scroll to it
- bool cursorReached = false;
- wxLayoutLine *line = m_FirstLine;
- while(line)
- {
- if(! wasDirty)
- ApplyStyle(line->GetStyleInfo(), dc);
- if(
- // if any previous line was dirty, we need to layout all
- // following lines:
- wasDirty
- // go on until we find the cursorline
- || ! cursorReached
- // layout dirty lines:
- || line->IsDirty()
- // always layout the cursor line toupdate the cursor
- // position and size:
- || line == m_CursorLine
- // or if it's the line we are asked to look for:
- || (cpos && line->GetLineNumber() == cpos->y)
- // layout at least the desired region:
- || (bottom == -1 )
- || (line->GetPosition().y <= bottom)
- )
- {
- if(line->IsDirty())
- wasDirty = true;
-
- // The following Layout() calls will update our
- // m_CurrentStyleInfo if needed.
- if(line == m_CursorLine)
- {
- line->Layout(dc, this,
- (wxPoint *)&m_CursorScreenPos,
- (wxPoint *)&m_CursorSize,
- &m_CursorStyleInfo,
- m_CursorPos.x);
+
+ if(m_ReLayoutAll)
+ {
+ forceAll = true;
+ bottom = -1;
+ }
+
+ ForceTotalLayout(false);
+
+
+ // If one line was dirty, we need to re-calculate all
+ // following lines, too.
+ bool wasDirty = forceAll;
+ // we need to layout until we reach at least the cursor line,
+ // otherwise we won't be able to scroll to it
+ bool cursorReached = false;
+ wxLayoutLine *line = m_FirstLine;
+ while(line)
+ {
+ if(! wasDirty)
+ ApplyStyle(line->GetStyleInfo(), dc);
+ if(
+ // if any previous line was dirty, we need to layout all
+ // following lines:
+ wasDirty
+ // go on until we find the cursorline
+ || ! cursorReached
+ // layout dirty lines:
+ || line->IsDirty()
+ // always layout the cursor line toupdate the cursor
+ // position and size:
+ || line == m_CursorLine
+ // or if it's the line we are asked to look for:
+ || (cpos && line->GetLineNumber() == cpos->y)
+ // layout at least the desired region:
+ || (bottom == -1 )
+ || (line->GetPosition().y <= bottom)
+ )
+ {
+ if(line->IsDirty())
+ wasDirty = true;
+
+ // The following Layout() calls will update our
+ // m_CurrentStyleInfo if needed.
+ if(line == m_CursorLine)
+ {
+ line->Layout(dc, this,
+ (wxPoint *)&m_CursorScreenPos,
+ (wxPoint *)&m_CursorSize,
+ &m_CursorStyleInfo,
+ m_CursorPos.x);
// we cannot layout the line twice, so copy the coords:
if(cpos && line ->GetLineNumber() == cpos->y)
{
- *cpos = m_CursorScreenPos;
- if ( csize )
- *csize = m_CursorSize;
+ *cpos = m_CursorScreenPos;
+ if ( csize )
+ *csize = m_CursorSize;
}
- cursorReached = TRUE;
- }
+
+ cursorReached = true;
+ }
else
{
if(cpos && line->GetLineNumber() == cpos->y)
{
- line->Layout(dc, this,
- cpos,
- csize, NULL, cpos->x);
- cursorReached = TRUE;
+ line->Layout(dc, this,
+ cpos,
+ csize, NULL, cpos->x);
+ cursorReached = true;
}
else
- line->Layout(dc, this);
- }
- }
- line = line->GetNextLine();
- }
-
+ line->Layout(dc, this);
+ }
+ }
+
+ line = line->GetNextLine();
+ }
+
#ifndef WXLAYOUT_USE_CARET
- // can only be 0 if we are on the first line and have no next line
- wxASSERT(m_CursorSize.x != 0 || (m_CursorLine &&
- m_CursorLine->GetNextLine() == NULL &&
- m_CursorLine == m_FirstLine));
+ // can only be 0 if we are on the first line and have no next line
+ wxASSERT(m_CursorSize.x != 0 || (m_CursorLine &&
+ m_CursorLine->GetNextLine() == NULL &&
+ m_CursorLine == m_FirstLine));
#endif // WXLAYOUT_USE_CARET
- AddCursorPosToUpdateRect();
+
+ AddCursorPosToUpdateRect();
}
wxPoint
wxLayoutList::GetScreenPos(wxDC &dc, const wxPoint &cpos, wxPoint *csize)
{
- wxPoint pos = cpos;
- Layout(dc, -1, false, &pos, csize);
- return pos;
+ wxPoint pos = cpos;
+ Layout(dc, -1, false, &pos, csize);
+ return pos;
}
void
CoordType bottom,
bool clipStrictly)
{
- wxLayoutLine *line = m_FirstLine;
+ wxLayoutLine *line = m_FirstLine;
- if ( m_Selection.m_discarded )
- {
- // calculate them if we don't have them already
- if ( !m_Selection.HasValidScreenCoords() )
- {
- m_Selection.m_ScreenA = GetScreenPos(dc, m_Selection.m_CursorA);
- m_Selection.m_ScreenB = GetScreenPos(dc, m_Selection.m_CursorB);
- }
+ if ( m_Selection.m_discarded )
+ {
+ // calculate them if we don't have them already
+ if ( !m_Selection.HasValidScreenCoords() )
+ {
+ m_Selection.m_ScreenA = GetScreenPos(dc, m_Selection.m_CursorA);
+ m_Selection.m_ScreenB = GetScreenPos(dc, m_Selection.m_CursorB);
+ }
- // invalidate the area which was previousle selected - and which is not
- // selected any more
- SetUpdateRect(m_Selection.m_ScreenA);
- SetUpdateRect(m_Selection.m_ScreenB);
+ // invalidate the area which was previousle selected - and which is not
+ // selected any more
+ SetUpdateRect(m_Selection.m_ScreenA);
+ SetUpdateRect(m_Selection.m_ScreenB);
- m_Selection.m_discarded = false;
- }
+ m_Selection.m_discarded = false;
+ }
- /* This call to Layout() will re-calculate and update all lines
- marked as dirty.
- */
- Layout(dc, bottom);
-
- ApplyStyle(m_DefaultStyleInfo, dc);
- wxBrush brush(m_CurrentStyleInfo.m_bg, wxSOLID);
- dc.SetBrush(brush);
- dc.SetBackgroundMode(wxTRANSPARENT);
+ /* This call to Layout() will re-calculate and update all lines
+ marked as dirty.
+ */
+ Layout(dc, bottom);
- while(line)
- {
- // only draw if between top and bottom:
- if((top == -1 ||
- line->GetPosition().y + line->GetHeight() > top))
- {
- ApplyStyle(line->GetStyleInfo(), dc);
- // little condition to speed up redrawing:
- if( bottom != -1
- && line->GetPosition().y
+ ApplyStyle(m_DefaultStyleInfo, dc);
+ wxBrush brush(m_CurrentStyleInfo.m_bg, wxSOLID);
+ dc.SetBrush(brush);
+ dc.SetBackgroundMode(wxTRANSPARENT);
+
+ while(line)
+ {
+ // only draw if between top and bottom:
+ if((top == -1 ||
+ line->GetPosition().y + line->GetHeight() > top))
+ {
+ ApplyStyle(line->GetStyleInfo(), dc);
+ // little condition to speed up redrawing:
+ if( bottom != -1
+ && line->GetPosition().y
+(clipStrictly ? line->GetHeight() : 0) >= bottom)
- break;
- line->Draw(dc, this, offset);
- }
- line = line->GetNextLine();
- }
- InvalidateUpdateRect();
+ break;
+
+ line->Draw(dc, this, offset);
+ }
+
+ line = line->GetNextLine();
+ }
- WXLO_DEBUG((wxT("Selection is %s : %ld,%ld/%ld,%ld"),
- m_Selection.m_valid ? wxT("valid") : wxT("invalid"),
- m_Selection.m_CursorA.x, m_Selection.m_CursorA.y,
- m_Selection.m_CursorB.x, m_Selection.m_CursorB.y));
+ InvalidateUpdateRect();
+
+ WXLO_DEBUG((wxT("Selection is %s : %d,%d/%d,%d"),
+ m_Selection.m_valid ? wxT("valid") : wxT("invalid"),
+ m_Selection.m_CursorA.x, m_Selection.m_CursorA.y,
+ m_Selection.m_CursorB.x, m_Selection.m_CursorB.y));
}
wxLayoutObject *
wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos,
- wxPoint *cursorPos,
- bool *found)
+ wxPoint *cursorPos, bool *found)
{
- // First, find the right line:
- wxLayoutLine
- *line = m_FirstLine,
- *lastline = m_FirstLine;
- wxPoint p;
+ // First, find the right line:
+ wxLayoutLine
+ *line = m_FirstLine,
+ *lastline = m_FirstLine;
+ wxPoint p;
- ApplyStyle(m_DefaultStyleInfo, dc);
- while(line)
- {
- p = line->GetPosition();
- if(p.y <= pos.y && p.y+line->GetHeight() >= pos.y)
- break;
- lastline = line;
- line = line->GetNextLine();
- }
+ ApplyStyle(m_DefaultStyleInfo, dc);
+ while(line)
+ {
+ p = line->GetPosition();
+ if(p.y <= pos.y && p.y+line->GetHeight() >= pos.y)
+ break;
+ lastline = line;
+ line = line->GetNextLine();
+ }
- bool didFind = line != NULL;
+ bool didFind = line != NULL;
- if ( !line )
- {
- // use the last line:
- line = lastline;
- }
+ if ( !line )
+ {
+ // use the last line:
+ line = lastline;
+ }
- if ( cursorPos )
- cursorPos->y = line->GetLineNumber();
+ if ( cursorPos )
+ cursorPos->y = line->GetLineNumber();
- bool foundinline = true;
- long cx = 0;
+ bool foundinline = true;
+ long cx = 0;
- // Now, find the object in the line:
- wxLOiterator i;
+ // Now, find the object in the line:
+ wxLOiterator i;
- if (cursorPos)
- {
- i = line->FindObjectScreen(dc, this,
- pos.x,
- &cx,
- &foundinline);
- cursorPos->x = cx;
- }
- else
- i = line->FindObjectScreen(dc, this,
- pos.x,
- NULL,
- &foundinline);
- if ( found )
- *found = didFind && foundinline;
+ if (cursorPos)
+ {
+ i = line->FindObjectScreen(dc, this,
+ pos.x,
+ &cx,
+ &foundinline);
+ cursorPos->x = cx;
+ }
+ else
+ i = line->FindObjectScreen(dc, this,
+ pos.x,
+ NULL,
+ &foundinline);
- return (i == NULLIT) ? NULL : *i;
+ if ( found )
+ *found = didFind && foundinline;
+
+ return (i == NULLIT) ? NULL : *i;
}
wxPoint
-wxLayoutList::GetSize(void) const
+wxLayoutList::GetSize() const
{
wxLayoutLine
*line = m_FirstLine,
void
wxLayoutList::DrawCursor(wxDC &
- #ifdef WXLAYOUT_USE_CARET
- WXUNUSED(dc)
- #else
- dc
- #endif
- , bool
- #ifdef WXLAYOUT_USE_CARET
- WXUNUSED(active)
- #else
- active
- #endif
- , wxPoint const &translate)
-{
- if ( m_movedCursor )
- m_movedCursor = false;
-
- wxPoint coords(m_CursorScreenPos);
- coords += translate;
+#ifdef WXLAYOUT_USE_CARET
+ WXUNUSED(dc)
+#else
+ dc
+#endif
+ , bool
+#ifdef WXLAYOUT_USE_CARET
+ WXUNUSED(active)
+#else
+ active
+#endif
+ , wxPoint const &translate)
+{
+ if ( m_movedCursor )
+ m_movedCursor = false;
+
+ wxPoint coords(m_CursorScreenPos);
+ coords += translate;
#ifdef WXLAYOUT_DEBUG
- WXLO_DEBUG((wxT("Drawing cursor (%ld,%ld) at %ld,%ld, size %ld,%ld, line: %ld, len %ld"),
- (long)m_CursorPos.x, (long)m_CursorPos.y,
- (long)coords.x, (long)coords.y,
- (long)m_CursorSize.x, (long)m_CursorSize.y,
- (long)m_CursorLine->GetLineNumber(),
- (long)m_CursorLine->GetLength()));
-
- wxLogStatus(wxT("Cursor is at (%d, %d)"), m_CursorPos.x, m_CursorPos.y);
+ WXLO_DEBUG((wxT("Drawing cursor (%ld,%ld) at %ld,%ld, size %ld,%ld, line: %ld, len %ld"),
+ (long)m_CursorPos.x, (long)m_CursorPos.y,
+ (long)coords.x, (long)coords.y,
+ (long)m_CursorSize.x, (long)m_CursorSize.y,
+ (long)m_CursorLine->GetLineNumber(),
+ (long)m_CursorLine->GetLength()));
+
+ wxLogStatus(wxT("Cursor is at (%d, %d)"), m_CursorPos.x, m_CursorPos.y);
#endif
#ifdef WXLAYOUT_USE_CARET
- m_caret->Move(coords);
+ m_caret->Move(coords);
#else // !WXLAYOUT_USE_CARET
- wxASSERT(m_CursorSize.x >= WXLO_MINIMUM_CURSOR_WIDTH);
- dc.SetBrush(*wxWHITE_BRUSH);
- //FIXME: wxGTK XOR is borken at the moment!!!dc.SetLogicalFunction(wxXOR);
- dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
- if(active)
- {
- dc.SetLogicalFunction(wxXOR);
- dc.DrawRectangle(coords.x, coords.y,
- m_CursorSize.x, m_CursorSize.y);
- SetUpdateRect(coords.x, coords.y);
- SetUpdateRect(coords.x+m_CursorSize.x,
- coords.y+m_CursorSize.y);
- }
- else
- {
- dc.SetLogicalFunction(wxCOPY);
- dc.DrawLine(coords.x, coords.y+m_CursorSize.y-1,
- coords.x, coords.y);
- SetUpdateRect(coords.x, coords.y+m_CursorSize.y-1);
- SetUpdateRect(coords.x, coords.y);
- }
- dc.SetLogicalFunction(wxCOPY);
- //dc.SetBrush(wxNullBrush);
+ wxASSERT(m_CursorSize.x >= WXLO_MINIMUM_CURSOR_WIDTH);
+ dc.SetBrush(*wxWHITE_BRUSH);
+ //FIXME: wxGTK XOR is borken at the moment!!!dc.SetLogicalFunction(wxXOR);
+ dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
+ if(active)
+ {
+ dc.SetLogicalFunction(wxXOR);
+ dc.DrawRectangle(coords.x, coords.y,
+ m_CursorSize.x, m_CursorSize.y);
+ SetUpdateRect(coords.x, coords.y);
+ SetUpdateRect(coords.x+m_CursorSize.x,
+ coords.y+m_CursorSize.y);
+ }
+ else
+ {
+ dc.SetLogicalFunction(wxCOPY);
+ dc.DrawLine(coords.x, coords.y+m_CursorSize.y-1,
+ coords.x, coords.y);
+ SetUpdateRect(coords.x, coords.y+m_CursorSize.y-1);
+ SetUpdateRect(coords.x, coords.y);
+ }
+
+ dc.SetLogicalFunction(wxCOPY);
+ //dc.SetBrush(wxNullBrush);
#endif // WXLAYOUT_USE_CARET/!WXLAYOUT_USE_CARET
}
void
wxLayoutList::SetUpdateRect(CoordType x, CoordType y)
{
- if(m_UpdateRectValid)
- GrowRect(m_UpdateRect, x, y);
- else
- {
- m_UpdateRect.x = x;
- m_UpdateRect.y = y;
- m_UpdateRect.width = 4; // large enough to avoid surprises from
- m_UpdateRect.height = 4;// wxGTK :-)
- m_UpdateRectValid = true;
- }
+ if(m_UpdateRectValid)
+ {
+ GrowRect(m_UpdateRect, x, y);
+ }
+ else
+ {
+ m_UpdateRect.x = x;
+ m_UpdateRect.y = y;
+ m_UpdateRect.width = 4; // large enough to avoid surprises from
+ m_UpdateRect.height = 4;// wxGTK :-)
+ m_UpdateRectValid = true;
+ }
}
void
wxLayoutList::StartSelection(const wxPoint& cposOrig, const wxPoint& spos)
{
- wxPoint cpos(cposOrig);
- if ( cpos.x == -1 )
- cpos = m_CursorPos;
- WXLO_DEBUG((wxT("Starting selection at %ld/%ld"), cpos.x, cpos.y));
- m_Selection.m_CursorA = cpos;
- m_Selection.m_CursorB = cpos;
- m_Selection.m_ScreenA = spos;
- m_Selection.m_ScreenB = spos;
- m_Selection.m_selecting = true;
- m_Selection.m_valid = false;
+ wxPoint cpos(cposOrig);
+ if ( cpos.x == -1 )
+ cpos = m_CursorPos;
+
+ WXLO_DEBUG((wxT("Starting selection at %d/%d"), cpos.x, cpos.y));
+
+ m_Selection.m_CursorA = cpos;
+ m_Selection.m_CursorB = cpos;
+ m_Selection.m_ScreenA = spos;
+ m_Selection.m_ScreenB = spos;
+ m_Selection.m_selecting = true;
+ m_Selection.m_valid = false;
}
void
wxASSERT(m_Selection.m_selecting == true);
wxASSERT(m_Selection.m_valid == false);
- WXLO_DEBUG((wxT("Continuing selection at %ld/%ld"), cpos.x, cpos.y));
+ WXLO_DEBUG((wxT("Continuing selection at %d/%d"), cpos.x, cpos.y));
m_Selection.m_ScreenB = spos;
m_Selection.m_CursorB = cpos;
void
wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos)
{
- wxPoint cpos(cposOrig);
- if(cpos.x == -1) cpos = m_CursorPos;
- ContinueSelection(cpos, spos);
- WXLO_DEBUG((wxT("Ending selection at %ld/%ld"), cpos.x, cpos.y));
- // we always want m_CursorA <= m_CursorB!
- if( m_Selection.m_CursorA > m_Selection.m_CursorB )
- {
- // exchange the start/end points
- wxPoint help = m_Selection.m_CursorB;
- m_Selection.m_CursorB = m_Selection.m_CursorA;
- m_Selection.m_CursorA = help;
-
- help = m_Selection.m_ScreenB;
- m_Selection.m_ScreenB = m_Selection.m_ScreenA;
- m_Selection.m_ScreenA = help;
- }
- m_Selection.m_selecting = false;
- m_Selection.m_valid = true;
- /// In case we just clicked somewhere, the selection will have zero
- /// size, so we discard it immediately.
- if(m_Selection.m_CursorA == m_Selection.m_CursorB)
- DiscardSelection();
+ wxPoint cpos(cposOrig);
+
+ if(cpos.x == -1) cpos = m_CursorPos;
+
+ ContinueSelection(cpos, spos);
+
+ WXLO_DEBUG((wxT("Ending selection at %d/%d"), cpos.x, cpos.y));
+
+ // we always want m_CursorA <= m_CursorB!
+ if( m_Selection.m_CursorA > m_Selection.m_CursorB )
+ {
+ // exchange the start/end points
+ wxPoint help = m_Selection.m_CursorB;
+ m_Selection.m_CursorB = m_Selection.m_CursorA;
+ m_Selection.m_CursorA = help;
+
+ help = m_Selection.m_ScreenB;
+ m_Selection.m_ScreenB = m_Selection.m_ScreenA;
+ m_Selection.m_ScreenA = help;
+ }
+
+ m_Selection.m_selecting = false;
+ m_Selection.m_valid = true;
+ /// In case we just clicked somewhere, the selection will have zero
+ /// size, so we discard it immediately.
+ if(m_Selection.m_CursorA == m_Selection.m_CursorB)
+ {
+ DiscardSelection();
+ }
}
void
wxLayoutList::DiscardSelection()
{
- if ( !HasSelection() )
- return;
+ if ( !HasSelection() )
+ return;
- m_Selection.m_valid =
- m_Selection.m_selecting = false;
- m_Selection.m_discarded = true;
+ m_Selection.m_valid =
+ m_Selection.m_selecting = false;
+ m_Selection.m_discarded = true;
}
bool
-wxLayoutList::IsSelecting(void) const
+wxLayoutList::IsSelecting() const
{
- return m_Selection.m_selecting;
+ return m_Selection.m_selecting;
}
bool
wxLayoutList::IsSelected(const wxPoint &cursor) const
{
- if ( !HasSelection() )
- return false;
+ if ( !HasSelection() )
+ return false;
- return (
- (m_Selection.m_CursorA <= cursor
- && cursor <= m_Selection.m_CursorB)
- || (m_Selection.m_CursorB <= cursor
- && cursor <= m_Selection.m_CursorA)
- );
+ return (
+ (m_Selection.m_CursorA <= cursor
+ && cursor <= m_Selection.m_CursorB)
+ || (m_Selection.m_CursorB <= cursor
+ && cursor <= m_Selection.m_CursorA)
+ );
}
*/
int
wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
- CoordType *to)
+ CoordType *to)
{
- wxASSERT(line); wxASSERT(to); wxASSERT(from);
+ wxASSERT(line); wxASSERT(to); wxASSERT(from);
- if(! m_Selection.m_valid && ! m_Selection.m_selecting)
- return 0;
+ if(! m_Selection.m_valid && ! m_Selection.m_selecting)
+ return 0;
- CoordType y = line->GetLineNumber();
- if(
- (m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
- || (m_Selection.m_CursorB.y < y && m_Selection.m_CursorA.y > y)
- )
- return 1;
- else if(m_Selection.m_CursorA.y == y)
- {
- *from = m_Selection.m_CursorA.x;
- if(m_Selection.m_CursorB.y == y)
- *to = m_Selection.m_CursorB.x;
- else
- {
- if(m_Selection.m_CursorB > m_Selection.m_CursorA)
- *to = line->GetLength();
- else
- *to = 0;
- }
- if(*to < *from)
- {
- CoordType help = *to;
- *to = *from;
- *from = help;
- }
- return -1;
- }
- else if(m_Selection.m_CursorB.y == y)
- {
- *to = m_Selection.m_CursorB.x;
- if(m_Selection.m_CursorA.y == y)
- *from = m_Selection.m_CursorA.x;
- else
- {
- if(m_Selection.m_CursorB > m_Selection.m_CursorA)
- *from = 0;
- else
- *from = line->GetLength();
- }
- if(*to < *from)
- {
- CoordType help = *to;
- *to = *from;
- *from = help;
- }
- return -1;
- }
- else
- return 0;
+ CoordType y = line->GetLineNumber();
+ if ( (m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
+ || (m_Selection.m_CursorB.y < y && m_Selection.m_CursorA.y > y) )
+ {
+ return 1;
+ }
+ else if (m_Selection.m_CursorA.y == y)
+ {
+ *from = m_Selection.m_CursorA.x;
+ if(m_Selection.m_CursorB.y == y)
+ {
+ *to = m_Selection.m_CursorB.x;
+ }
+ else
+ {
+ if(m_Selection.m_CursorB > m_Selection.m_CursorA)
+ *to = line->GetLength();
+ else
+ *to = 0;
+ }
+
+ if(*to < *from)
+ {
+ CoordType help = *to;
+ *to = *from;
+ *from = help;
+ }
+
+ return -1;
+ }
+ else if (m_Selection.m_CursorB.y == y)
+ {
+ *to = m_Selection.m_CursorB.x;
+ if (m_Selection.m_CursorA.y == y)
+ {
+ *from = m_Selection.m_CursorA.x;
+ }
+ else
+ {
+ if(m_Selection.m_CursorB > m_Selection.m_CursorA)
+ *from = 0;
+ else
+ *from = line->GetLength();
+ }
+
+ if(*to < *from)
+ {
+ CoordType help = *to;
+ *to = *from;
+ *from = help;
+ }
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
}
void
-wxLayoutList::DeleteSelection(void)
+wxLayoutList::DeleteSelection()
{
- if(! m_Selection.m_valid)
- return;
+ if (! m_Selection.m_valid)
+ return;
- m_Selection.m_valid = false;
+ m_Selection.m_valid = false;
- // Only delete part of the current line?
- if(m_Selection.m_CursorA.y == m_Selection.m_CursorB.y)
- {
- MoveCursorTo(m_Selection.m_CursorA);
- Delete(m_Selection.m_CursorB.x - m_Selection.m_CursorA.x);
- return;
- }
+ // Only delete part of the current line?
+ if (m_Selection.m_CursorA.y == m_Selection.m_CursorB.y)
+ {
+ MoveCursorTo(m_Selection.m_CursorA);
+ Delete(m_Selection.m_CursorB.x - m_Selection.m_CursorA.x);
+ return;
+ }
// We now know that the two lines are different:
- wxLayoutLine
- * firstLine = GetLine(m_Selection.m_CursorA.y),
- * lastLine = GetLine(m_Selection.m_CursorB.y);
- // be a bit paranoid:
- if(! firstLine || ! lastLine)
- return;
-
- // First, delete what's left of this line:
- MoveCursorTo(m_Selection.m_CursorA);
- DeleteToEndOfLine();
+ wxLayoutLine
+ * firstLine = GetLine(m_Selection.m_CursorA.y),
+ * lastLine = GetLine(m_Selection.m_CursorB.y);
- wxLayoutLine *prevLine = firstLine->GetPreviousLine(),
- *nextLine = firstLine->GetNextLine();
- while(nextLine && nextLine != lastLine)
- nextLine = nextLine->DeleteLine(false, this);
+ // be a bit paranoid:
+ if(! firstLine || ! lastLine)
+ return;
- // Now nextLine = lastLine;
- Delete(1); // This joins firstLine and nextLine
- Delete(m_Selection.m_CursorB.x); // This deletes the first x positions
+ // First, delete what's left of this line:
+ MoveCursorTo(m_Selection.m_CursorA);
+ DeleteToEndOfLine();
- // Recalculate the line positions and numbers but notice that firstLine
- // might not exist any more - it could be deleted by Delete(1) above
- wxLayoutLine *firstLine2 = prevLine ? prevLine->GetNextLine() : m_FirstLine;
- firstLine2->MarkDirty();
+ wxLayoutLine *prevLine = firstLine->GetPreviousLine(),
+ *nextLine = firstLine->GetNextLine();
+
+ while(nextLine && nextLine != lastLine)
+ {
+ nextLine = nextLine->DeleteLine(false, this);
+ }
+
+ // Now nextLine = lastLine;
+ Delete(1); // This joins firstLine and nextLine
+ Delete(m_Selection.m_CursorB.x); // This deletes the first x positions
+
+ // Recalculate the line positions and numbers but notice that firstLine
+ // might not exist any more - it could be deleted by Delete(1) above
+ wxLayoutLine *firstLine2 = prevLine ? prevLine->GetNextLine() : m_FirstLine;
+ firstLine2->MarkDirty();
}
/// Starts highlighting the selection
wxLayoutLine *
wxLayoutList::GetLine(CoordType index) const
{
- wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines),
- wxT("invalid index") );
+ wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines),
+ wxT("invalid index") );
- wxLayoutLine *line;
- CoordType n = index;
+ wxLayoutLine *line;
+ CoordType n = index;
#ifdef DEBUG
- CoordType lineNo = 0;
+ CoordType lineNo = 0;
#endif
-
- for ( line = m_FirstLine; line && n-- > 0; line =
- line->GetNextLine() )
- {
+
+ for ( line = m_FirstLine; line && n-- > 0; line = line->GetNextLine() )
+ {
#ifdef DEBUG
-wxASSERT(line->GetLineNumber() == lineNo );
- lineNo++;
+ wxASSERT(line->GetLineNumber() == lineNo );
+ lineNo++;
#endif
-}
+ }
- if ( line )
- {
- // should be the right one
- wxASSERT( line->GetLineNumber() == index );
- }
+ if ( line )
+ {
+ // should be the right one
+ wxASSERT( line->GetLineNumber() == index );
+ }
- return line;
+ return line;
}
wxLayoutList *
wxLayoutList::Copy(const wxPoint &from,
- const wxPoint &to)
+ const wxPoint &to)
{
- wxLayoutLine
- * firstLine = NULL,
- * lastLine = NULL;
-
- for(firstLine = m_FirstLine;
- firstLine && firstLine->GetLineNumber() < from.y;
- firstLine=firstLine->GetNextLine())
- ;
- if(!firstLine || firstLine->GetLineNumber() != from.y)
- return NULL;
+ wxLayoutLine
+ * firstLine,
+ * lastLine;
- for(lastLine = m_FirstLine;
- lastLine && lastLine->GetLineNumber() < to.y;
- lastLine=lastLine->GetNextLine())
- ;
- if(!lastLine || lastLine->GetLineNumber() != to.y)
- return NULL;
+ for(firstLine = m_FirstLine;
+ firstLine && firstLine->GetLineNumber() < from.y;
+ firstLine=firstLine->GetNextLine())
+ ;
- if(to <= from)
- {
- wxLayoutLine *tmp = firstLine;
- firstLine = lastLine;
- lastLine = tmp;
- }
+ if(!firstLine || firstLine->GetLineNumber() != from.y)
+ return NULL;
- wxLayoutList *llist = new wxLayoutList();
+ for(lastLine = m_FirstLine;
+ lastLine && lastLine->GetLineNumber() < to.y;
+ lastLine=lastLine->GetNextLine())
+ ;
- if(firstLine == lastLine)
- {
- firstLine->Copy(llist, from.x, to.x);
- }
- else
- {
- // Extract objects from first line
- firstLine->Copy(llist, from.x);
- llist->LineBreak();
- // Extract all lines between
- for(wxLayoutLine *line = firstLine->GetNextLine();
- line != lastLine;
- line = line->GetNextLine())
- {
- line->Copy(llist);
- llist->LineBreak();
- }
- // Extract objects from last line
- lastLine->Copy(llist, 0, to.x);
- }
- return llist;
+ if(!lastLine || lastLine->GetLineNumber() != to.y)
+ return NULL;
+
+ if(to <= from)
+ {
+ wxLayoutLine *tmp = firstLine;
+ firstLine = lastLine;
+ lastLine = tmp;
+ }
+
+ wxLayoutList *llist = new wxLayoutList();
+
+ if(firstLine == lastLine)
+ {
+ firstLine->Copy(llist, from.x, to.x);
+ }
+ else
+ {
+ // Extract objects from first line
+ firstLine->Copy(llist, from.x);
+ llist->LineBreak();
+ // Extract all lines between
+ for ( wxLayoutLine *line = firstLine->GetNextLine();
+ line != lastLine;
+ line = line->GetNextLine() )
+ {
+ line->Copy(llist);
+ llist->LineBreak();
+ }
+
+ // Extract objects from last line
+ lastLine->Copy(llist, 0, to.x);
+ }
+
+ return llist;
}
wxLayoutList *
wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate)
{
- if(! m_Selection.m_valid)
- {
- if(m_Selection.m_selecting)
- EndSelection();
- else
- return NULL;
- }
+ if(! m_Selection.m_valid)
+ {
+ if(m_Selection.m_selecting)
+ EndSelection();
+ else
+ return NULL;
+ }
- if(invalidate) m_Selection.m_valid = false;
+ if(invalidate) m_Selection.m_valid = false;
- wxLayoutList *llist = Copy( m_Selection.m_CursorA,
- m_Selection.m_CursorB );
+ wxLayoutList *llist = Copy( m_Selection.m_CursorA,
+ m_Selection.m_CursorB );
- if(llist && wxlo) // export as data object, too
- {
- wxString string;
+ if(llist && wxlo) // export as data object, too
+ {
+ wxString string;
- wxLayoutExportObject *exp;
- wxLayoutExportStatus status(llist);
- while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_OBJECTS)) != NULL)
- {
- if(exp->type == WXLO_EXPORT_EMPTYLINE)
- string << (int) WXLO_TYPE_LINEBREAK << '\n';
- else
- exp->content.object->Write(string);
- delete exp;
- }
- wxlo->SetLayoutData(string);
- }
- return llist;
+ wxLayoutExportObject *exp;
+ wxLayoutExportStatus status(llist);
+ while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_OBJECTS)) != NULL)
+ {
+ if(exp->type == WXLO_EXPORT_EMPTYLINE)
+ string << (int) WXLO_TYPE_LINEBREAK << '\n';
+ else
+ exp->content.object->Write(string);
+ delete exp;
+ }
+
+ wxlo->SetLayoutData(string);
+ }
+
+ return llist;
}
-#define COPY_SI(what) if(si.what != -1) { m_CurrentStyleInfo.what = si.what; fontChanged = TRUE; }
+#define COPY_SI(what) if(si.what != -1) { m_CurrentStyleInfo.what = si.what; fontChanged = true; }
void
wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc)
{
- bool fontChanged = FALSE;
- COPY_SI(family);
- COPY_SI(size);
- COPY_SI(style);
- COPY_SI(weight);
- COPY_SI(underline);
- if(fontChanged)
- dc.SetFont( m_FontCache.GetFont(m_CurrentStyleInfo) );
+ bool fontChanged = false;
+ COPY_SI(family);
+ COPY_SI(size);
+ COPY_SI(style);
+ COPY_SI(weight);
+ COPY_SI(underline);
+ if(fontChanged)
+ dc.SetFont( m_FontCache.GetFont(m_CurrentStyleInfo) );
- if(si.m_fg_valid)
- {
- m_CurrentStyleInfo.m_fg = si.m_fg;
- m_CurrentStyleInfo.m_fg_valid = true;
- dc.SetTextForeground(m_CurrentStyleInfo.m_fg);
- }
- if(si.m_bg_valid)
- {
- m_CurrentStyleInfo.m_bg = si.m_bg;
- m_CurrentStyleInfo.m_bg_valid = true;
- dc.SetTextBackground(m_CurrentStyleInfo.m_bg);
- }
+ if(si.m_fg_valid)
+ {
+ m_CurrentStyleInfo.m_fg = si.m_fg;
+ m_CurrentStyleInfo.m_fg_valid = true;
+ dc.SetTextForeground(m_CurrentStyleInfo.m_fg);
+ }
+
+ if(si.m_bg_valid)
+ {
+ m_CurrentStyleInfo.m_bg = si.m_bg;
+ m_CurrentStyleInfo.m_bg_valid = true;
+ dc.SetTextBackground(m_CurrentStyleInfo.m_bg);
+ }
}
#ifdef WXLAYOUT_DEBUG
void
-wxLayoutList::Debug(void)
+wxLayoutList::Debug()
{
- WXLO_DEBUG((wxT("Cursor is in line %d, screen pos = (%d, %d)"),
- m_CursorLine->GetLineNumber(),
- m_CursorScreenPos.x, m_CursorScreenPos.y));
+ WXLO_DEBUG((wxT("Cursor is in line %d, screen pos = (%d, %d)"),
+ (int)m_CursorLine->GetLineNumber(),
+ m_CursorScreenPos.x, m_CursorScreenPos.y));
- wxLayoutLine *line;
- for(line = m_FirstLine; line; line = line->GetNextLine())
- {
- line->Debug();
- }
+ wxLayoutLine *line;
+ for(line = m_FirstLine; line; line = line->GetNextLine())
+ {
+ line->Debug();
+ }
}
#endif
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
wxLayoutPrintout::wxLayoutPrintout(wxLayoutList *llist,
- wxString const & title)
-:wxPrintout(title)
+ wxString const & title)
+ :wxPrintout(title)
{
- m_llist = llist;
- m_title = title;
- // remove any highlighting which could interfere with printing:
- m_llist->StartSelection();
- m_llist->EndSelection();
- // force a full layout of the list:
- m_llist->ForceTotalLayout();
- // layout is called in ScaleDC() when we have a DC
+ m_llist = llist;
+ m_title = title;
+ // remove any highlighting which could interfere with printing:
+ m_llist->StartSelection();
+ m_llist->EndSelection();
+ // force a full layout of the list:
+ m_llist->ForceTotalLayout();
+ // layout is called in ScaleDC() when we have a DC
}
wxLayoutPrintout::~wxLayoutPrintout()
float
wxLayoutPrintout::ScaleDC(wxDC *dc)
{
- // The following bit is taken from the printing sample, let's see
- // whether it works for us.
+ // The following bit is taken from the printing sample, let's see
+ // whether it works for us.
- /* You might use THIS code to set the printer DC to ROUGHLY reflect
- * the screen text size. This page also draws lines of actual length 5cm
- * on the page.
- */
- // Get the logical pixels per inch of screen and printer
- int ppiScreenX, ppiScreenY;
- GetPPIScreen(&ppiScreenX, &ppiScreenY);
- int ppiPrinterX, ppiPrinterY;
- GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
+ /* You might use THIS code to set the printer DC to ROUGHLY reflect
+ * the screen text size. This page also draws lines of actual length 5cm
+ * on the page.
+ */
- if(ppiScreenX == 0) // not yet set, need to guess
- {
- ppiScreenX = 100;
- ppiScreenY = 100;
- }
- if(ppiPrinterX == 0) // not yet set, need to guess
- {
- ppiPrinterX = 72;
- ppiPrinterY = 72;
- }
+ // Get the logical pixels per inch of screen and printer
+ int ppiScreenX, ppiScreenY;
+ GetPPIScreen(&ppiScreenX, &ppiScreenY);
+ int ppiPrinterX, ppiPrinterY;
+ GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
+
+ if(ppiScreenX == 0) // not yet set, need to guess
+ {
+ ppiScreenX = 100;
+ ppiScreenY = 100;
+ }
+ wxUnusedVar(ppiScreenY);
+
+ if(ppiPrinterX == 0) // not yet set, need to guess
+ {
+ ppiPrinterX = 72;
+ ppiPrinterY = 72;
+ }
+ wxUnusedVar(ppiPrinterY);
+
+ // This scales the DC so that the printout roughly represents the
+ // the screen scaling. The text point size _should_ be the right size
+ // but in fact is too small for some reason. This is a detail that will
+ // need to be addressed at some point but can be fudged for the
+ // moment.
+ float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
+
+ // Now we have to check in case our real page size is reduced
+ // (e.g. because we're drawing to a print preview memory DC)
+ int pageWidth, pageHeight;
+ int w, h;
+ dc->GetSize(&w, &h);
+ GetPageSizePixels(&pageWidth, &pageHeight);
+ wxUnusedVar(pageHeight);
+ if(pageWidth != 0) // doesn't work always
+ {
+ // If printer pageWidth == current DC width, then this doesn't
+ // change. But w might be the preview bitmap width, so scale down.
+ scale = scale * (float)(w/(float)pageWidth);
+ }
- // This scales the DC so that the printout roughly represents the
- // the screen scaling. The text point size _should_ be the right size
- // but in fact is too small for some reason. This is a detail that will
- // need to be addressed at some point but can be fudged for the
- // moment.
- float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
-
- // Now we have to check in case our real page size is reduced
- // (e.g. because we're drawing to a print preview memory DC)
- int pageWidth, pageHeight;
- int w, h;
- dc->GetSize(&w, &h);
- GetPageSizePixels(&pageWidth, &pageHeight);
- if(pageWidth != 0) // doesn't work always
- {
- // If printer pageWidth == current DC width, then this doesn't
- // change. But w might be the preview bitmap width, so scale down.
- scale = scale * (float)(w/(float)pageWidth);
- }
- dc->SetUserScale(scale, scale);
- return scale;
+ dc->SetUserScale(scale, scale);
+ return scale;
}
bool wxLayoutPrintout::OnPrintPage(int page)
{
- wxDC *dc = GetDC();
+ wxDC *dc = GetDC();
- ScaleDC(dc);
+ ScaleDC(dc);
- if (dc)
- {
- int top, bottom;
- top = (page - 1)*m_PrintoutHeight;
- bottom = top + m_PrintoutHeight;
-
- WXLO_DEBUG((wxT("OnPrintPage(%d) printing from %d to %d"), page, top,
- bottom));
- // SetDeviceOrigin() doesn't work here, so we need to manually
- // translate all coordinates.
- wxPoint translate(m_Offset.x,m_Offset.y-top);
- m_llist->Draw(*dc, translate, top, bottom, TRUE /* clip strictly
- */);
- return true;
+ if (dc)
+ {
+ int top, bottom;
+ top = (page - 1)*m_PrintoutHeight;
+ bottom = top + m_PrintoutHeight;
+
+ WXLO_DEBUG((wxT("OnPrintPage(%d) printing from %d to %d"), page, top,
+ bottom));
+
+ // SetDeviceOrigin() doesn't work here, so we need to manually
+ // translate all coordinates.
+ wxPoint translate(m_Offset.x,m_Offset.y-top);
+ m_llist->Draw(*dc, translate, top, bottom, true /* clip strictly */);
+ return true;
}
else
+ {
return false;
+ }
}
void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
#include "kbList.h"
-#include <wx/wx.h>
-#include <wx/print.h>
-#include <wx/printdlg.h>
-#include <wx/generic/printps.h>
-#include <wx/generic/prntdlgg.h>
-#include <wx/dataobj.h>
+#include "wx/wx.h"
+#include "wx/print.h"
+#include "wx/printdlg.h"
+#include "wx/generic/printps.h"
+#include "wx/generic/prntdlgg.h"
+#include "wx/dataobj.h"
// skip the following defines if embedded in M application
#ifndef M_BASEDIR
/// Types of currently supported layout objects.
enum wxLayoutObjectType
{
- /// illegal object type, should never appear
- WXLO_TYPE_INVALID = 0,
- /// text object, containing normal text
- WXLO_TYPE_TEXT,
- /// command object, containing font or colour changes
- WXLO_TYPE_CMD,
- /// icon object, any kind of image
- WXLO_TYPE_ICON,
- /// a linebreak, does not exist as an object
- WXLO_TYPE_LINEBREAK
+ /// illegal object type, should never appear
+ WXLO_TYPE_INVALID = 0,
+
+ /// text object, containing normal text
+ WXLO_TYPE_TEXT,
+
+ /// command object, containing font or colour changes
+ WXLO_TYPE_CMD,
+
+ /// icon object, any kind of image
+ WXLO_TYPE_ICON,
+
+ /// a linebreak, does not exist as an object
+ WXLO_TYPE_LINEBREAK
};
/// Type used for coordinates in drawing. Must be signed.
#endif
{
public:
- /** This structure can be used to contain data associated with the
- object.
- It is refcounted, so the caller has to do a DecRef() on it
- instead of a delete.
- */
- struct UserData
- {
- UserData() { m_refcount = 1; }
- inline void IncRef(void) { m_refcount++; }
- inline void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
- inline void SetLabel(const wxString &l) { m_label = l; }
- inline const wxString & GetLabel(void) const { return m_label; }
- private:
- int m_refcount;
- wxString m_label;
- protected:
- virtual ~UserData() { wxASSERT(m_refcount == 0); }
- /// prevents gcc from generating stupid warnings
- friend class dummy_UserData;
- };
-
- /// return the type of this object
- virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; }
- /** Calculates the size of an object.
- @param dc the wxDC to draw on
- @param llist the wxLayoutList
- */
- virtual void Layout(wxDC &dc, wxLayoutList *llist) = 0;
-
- /** Draws an object.
- @param dc the wxDC to draw on
- @param coords where to draw the baseline of the object.
- @param wxllist pointer to wxLayoutList
- @param begin if !=-1, from which position on to highlight it
- @param end if begin !=-1, how many positions to highlight it
- */
- virtual void Draw(wxDC & /* dc */,
- wxPoint const & /* coords */,
- wxLayoutList *wxllist,
- CoordType begin = -1,
- CoordType end = -1) { }
-
- /** Calculates and returns the size of the object.
- @param top where to store height above baseline
- @param bottom where to store height below baseline
- @return the size of the object's box in pixels
- */
- virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const
- { *top = 0; *bottom = 0; return wxPoint(0,0); }
-
- /// Return just the width of the object on the screen.
- virtual CoordType GetWidth(void) const { return 0; }
- /// returns the number of cursor positions occupied by this object
- virtual CoordType GetLength(void) const { return 1; }
- /** Returns the cursor offset relating to the screen x position
- relative to begin of object.
- @param dc the wxDC to use for calculations
- @param xpos relative x position from head of object
- @return cursor coordinate offset
- */
- virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; }
-
- /// constructor
- wxLayoutObject() { m_UserData = NULL; }
- /// delete the user data
- virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
+ /** This structure can be used to contain data associated with the
+ object.
+ It is refcounted, so the caller has to do a DecRef() on it
+ instead of a delete.
+ */
+ struct UserData
+ {
+ UserData() { m_refcount = 1; }
+ inline void IncRef() { m_refcount++; }
+ inline void DecRef() { m_refcount--; if(m_refcount == 0) delete this;}
+ inline void SetLabel(const wxString &l) { m_label = l; }
+ inline const wxString & GetLabel() const { return m_label; }
+ private:
+ int m_refcount;
+ wxString m_label;
+ protected:
+ virtual ~UserData() { wxASSERT(m_refcount == 0); }
+ /// prevents gcc from generating stupid warnings
+ friend class dummy_UserData;
+ };
+
+ /// return the type of this object
+ virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_INVALID; }
+ /** Calculates the size of an object.
+ @param dc the wxDC to draw on
+ @param llist the wxLayoutList
+ */
+ virtual void Layout(wxDC &dc, wxLayoutList *llist) = 0;
+
+ /** Draws an object.
+ @param dc the wxDC to draw on
+ @param coords where to draw the baseline of the object.
+ @param wxllist pointer to wxLayoutList
+ @param begin if !=-1, from which position on to highlight it
+ @param end if begin !=-1, how many positions to highlight it
+ */
+ virtual void Draw(wxDC & /* dc */,
+ wxPoint const & /* coords */,
+ wxLayoutList *WXUNUSED(wxllist),
+ CoordType WXUNUSED(begin) = -1,
+ CoordType WXUNUSED(end) = -1) { }
+
+ /** Calculates and returns the size of the object.
+ @param top where to store height above baseline
+ @param bottom where to store height below baseline
+ @return the size of the object's box in pixels
+ */
+ virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const
+ { *top = 0; *bottom = 0; return wxPoint(0,0); }
+
+ /// Return just the width of the object on the screen.
+ virtual CoordType GetWidth() const { return 0; }
+
+ /// returns the number of cursor positions occupied by this object
+ virtual CoordType GetLength() const { return 1; }
+
+ /** Returns the cursor offset relating to the screen x position
+ relative to begin of object.
+ @param dc the wxDC to use for calculations
+ @param xpos relative x position from head of object
+ @return cursor coordinate offset
+ */
+ virtual CoordType GetOffsetScreen( wxDC & WXUNUSED(dc),
+ CoordType WXUNUSED(xpos) ) const
+ {
+ return 0;
+ }
+
+ /// constructor
+ wxLayoutObject() { m_UserData = NULL; }
+
+ /// delete the user data
+ virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
#ifdef WXLAYOUT_DEBUG
- virtual wxString DebugDump(void) const;
+ virtual wxString DebugDump() const;
#endif
- /** Tells the object about some user data. This data is associated
- with the object and will be deleted at destruction time.
- It is reference counted.
- */
- void SetUserData(UserData *data)
- {
- if(m_UserData)
+ /** Tells the object about some user data. This data is associated
+ with the object and will be deleted at destruction time.
+ It is reference counted.
+ */
+ void SetUserData(UserData *data)
+ {
+ if(m_UserData)
m_UserData->DecRef();
- m_UserData = data;
- if(m_UserData)
+
+ m_UserData = data;
+
+ if(m_UserData)
m_UserData->IncRef();
- }
+ }
- /** Return the user data.
- Increments the object's reference count. When no longer needed,
- caller must call DecRef() on the pointer returned.
- */
- UserData * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
+ /** Return the user data.
+ Increments the object's reference count. When no longer needed,
+ caller must call DecRef() on the pointer returned.
+ */
+ UserData * GetUserData() const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
- /** Makes a copy of this object.
+ /** Makes a copy of this object.
*/
- virtual wxLayoutObject *Copy(void) = 0;
+ virtual wxLayoutObject *Copy() = 0;
+
+ /** Clipboard support function. Read and write objects to
+ strings. */
+ //@{
+ /// Writes the object to the string.
+ virtual void Write(wxString &ostr) = 0;
- /** Clipboard support function. Read and write objects to
- strings. */
- //@{
- /// Writes the object to the string.
- virtual void Write(wxString &ostr) = 0;
- /** Reads an object.
- @param str stream to read from, will bee changed
- @return true on success
- */
- static wxLayoutObject *Read(wxString &istr);
- //@}
+ /** Reads an object.
+ @param str stream to read from, will bee changed
+ @return true on success
+ */
+ static wxLayoutObject *Read(wxString &istr);
+ //@}
- /// returns TRUE if the object is shown on the screen (i.e. not cmd object)
- bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD; }
+ /// returns true if the object is shown on the screen (i.e. not cmd object)
+ bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD; }
protected:
- /// optional data for application's use
- UserData *m_UserData;
+ /// optional data for application's use
+ UserData *m_UserData;
#if defined (M_BASEDIR) && defined (DEBUG)
- MOBJECT_NAME(wxLayoutObject)
+ MOBJECT_NAME(wxLayoutObject)
#endif
};
/// An illegal iterator to save typing.
#define NULLIT (wxLayoutObjectList::iterator(NULL))
+
/// The iterator type.
typedef wxLayoutObjectList::iterator wxLOiterator;
class wxLayoutObjectText : public wxLayoutObject
{
public:
- wxLayoutObjectText(const wxString &txt = wxEmptyString);
-
- virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
- virtual void Layout(wxDC &dc, wxLayoutList *llist);
- virtual void Draw(wxDC &dc, wxPoint const &coords,
- wxLayoutList *wxllist,
- CoordType begin = -1,
- CoordType end = -1);
- /** Calculates and returns the size of the object.
- @param top where to store height above baseline
- @param bottom where to store height below baseline
- @return the size of the object's box in pixels
- */
- virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
- /// Return just the width of the object on the screen.
- virtual CoordType GetWidth(void) const { return m_Width; }
- /** Returns the cursor offset relating to the screen x position
- relative to begin of object.
- @param dc the wxDC to use for calculations
- @param xpos relative x position from head of object
- @return cursor coordinate offset
- */
- virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
-
- virtual void Write(wxString &ostr);
- static wxLayoutObjectText *Read(wxString &istr);
+ wxLayoutObjectText(const wxString &txt = wxEmptyString);
+
+ virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_TEXT; }
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ wxLayoutList *wxllist,
+ CoordType begin = -1,
+ CoordType end = -1);
+
+ /** Calculates and returns the size of the object.
+ @param top where to store height above baseline
+ @param bottom where to store height below baseline
+ @return the size of the object's box in pixels
+ */
+ virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
+
+ /// Return just the width of the object on the screen.
+ virtual CoordType GetWidth() const { return m_Width; }
+
+ /** Returns the cursor offset relating to the screen x position
+ relative to begin of object.
+ @param dc the wxDC to use for calculations
+ @param xpos relative x position from head of object
+ @return cursor coordinate offset
+ */
+ virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
+
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectText *Read(wxString &istr);
#ifdef WXLAYOUT_DEBUG
- virtual wxString DebugDump(void) const;
+ virtual wxString DebugDump() const;
#endif
- virtual CoordType GetLength(void) const { return wxStrlen(m_Text.c_str()); }
+ virtual CoordType GetLength() const { return wxStrlen(m_Text.c_str()); }
+
+ // for editing:
+ wxString & GetText() { return m_Text; }
- // for editing:
- wxString & GetText(void) { return m_Text; }
- void SetText(wxString const &text) { m_Text = text; }
- /** Makes a copy of this object.
+ void SetText(wxString const &text) { m_Text = text; }
+ /** Makes a copy of this object.
*/
- virtual wxLayoutObject *Copy(void);
+ virtual wxLayoutObject *Copy();
+
private:
- wxString m_Text;
- /// size of the box containing text
- long m_Width, m_Height;
- /// Height above baseline.
- long m_Top;
- /// Height below baseline.
- long m_Bottom;
+ wxString m_Text;
+
+ /// size of the box containing text
+ long m_Width, m_Height;
+
+ /// Height above baseline.
+ long m_Top;
+
+ /// Height below baseline.
+ long m_Bottom;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutObjectIcon : public wxLayoutObject
{
public:
- wxLayoutObjectIcon(wxBitmap *icon = NULL);
- wxLayoutObjectIcon(wxBitmap const &icon);
-
- ~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; }
-
- virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
- virtual void Layout(wxDC &dc, wxLayoutList *llist);
- virtual void Draw(wxDC &dc, wxPoint const &coords,
- wxLayoutList *wxllist,
- CoordType begin = -1,
- CoordType end = -1);
-
- /** Calculates and returns the size of the object.
- @param top where to store height above baseline
- @param bottom where to store height below baseline
- @return the size of the object's box in pixels
- */
- virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
- /// Return just the width of the object on the screen.
- virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); }
- // return a pointer to the icon
- wxBitmap *GetIcon(void) const { return m_Icon; }
- /** Makes a copy of this object.
- */
- virtual wxLayoutObject *Copy(void);
- virtual void Write(wxString &ostr);
- static wxLayoutObjectIcon *Read(wxString &istr);
+ wxLayoutObjectIcon(wxBitmap *icon = NULL);
+ wxLayoutObjectIcon(wxBitmap const &icon);
+
+ ~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; }
+
+ virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_ICON; }
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ wxLayoutList *wxllist,
+ CoordType begin = -1,
+ CoordType end = -1);
+
+ /** Calculates and returns the size of the object.
+ @param top where to store height above baseline
+ @param bottom where to store height below baseline
+ @return the size of the object's box in pixels
+ */
+ virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
+
+ /// Return just the width of the object on the screen.
+ virtual CoordType GetWidth() const { return m_Icon->GetWidth(); }
+
+ // return a pointer to the icon
+ wxBitmap *GetIcon() const { return m_Icon; }
+
+ /** Makes a copy of this object.
+ */
+ virtual wxLayoutObject *Copy();
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectIcon *Read(wxString &istr);
+
private:
- wxBitmap *m_Icon;
+ wxBitmap *m_Icon;
};
/** This structure holds all formatting information.
*/
struct wxLayoutStyleInfo
{
- wxLayoutStyleInfo(int ifamily = -1,
- int isize = -1,
- int istyle = -1,
- int iweight = -1,
- int iul = -1,
- wxColour *fg = NULL,
- wxColour *bg = NULL);
- wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
-
- wxColour & GetBGColour() { return m_bg; }
-
- /// Font change parameters.
- int size, family, style, weight, underline;
- /// Colours
- wxColour m_bg, m_fg;
- int m_fg_valid, m_bg_valid; // bool, but must be int!
+ wxLayoutStyleInfo(int ifamily = -1,
+ int isize = -1,
+ int istyle = -1,
+ int iweight = -1,
+ int iul = -1,
+ wxColour *fg = NULL,
+ wxColour *bg = NULL);
+
+ wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
+
+ wxColour & GetBGColour() { return m_bg; }
+
+ /// Font change parameters.
+ int size, family, style, weight, underline;
+
+ /// Colours
+ wxColour m_bg, m_fg;
+ int m_fg_valid, m_bg_valid; // bool, but must be int!
};
/// a cached font
class wxFontCacheEntry
{
public:
- wxFontCacheEntry(int family, int size, int style, int weight,
- bool underline)
- {
- m_Family = family; m_Size = size; m_Style = style;
- m_Weight = weight; m_Underline = underline;
- m_Font = new wxFont(m_Size, m_Family,
- m_Style, m_Weight, m_Underline);
- }
- bool Matches(int family, int size, int style, int weight,
- bool underline) const
- {
- return size == m_Size && family == m_Family
+ wxFontCacheEntry(int family, int size, int style, int weight,
+ bool underline)
+ {
+ m_Family = family; m_Size = size; m_Style = style;
+ m_Weight = weight; m_Underline = underline;
+ m_Font = new wxFont(m_Size, m_Family,
+ m_Style, m_Weight, m_Underline);
+ }
+
+ bool Matches(int family, int size, int style, int weight,
+ bool underline) const
+ {
+ return size == m_Size && family == m_Family
&& style == m_Style && weight == m_Weight
&& underline == m_Underline;
- }
- wxFont & GetFont(void) { return *m_Font; }
- ~wxFontCacheEntry()
- {
- delete m_Font;
- }
+ }
+
+ wxFont & GetFont() { return *m_Font; }
+ ~wxFontCacheEntry()
+ {
+ delete m_Font;
+ }
+
private:
- wxFont *m_Font;
+ wxFont *m_Font;
- // VZ: I wonder why it doesn't use wxLayoutStyleInfo instead of those?
- int m_Family, m_Size, m_Style, m_Weight;
- bool m_Underline;
+ // VZ: I wonder why it doesn't use wxLayoutStyleInfo instead of those?
+ int m_Family, m_Size, m_Style, m_Weight;
+ bool m_Underline;
};
KBLIST_DEFINE(wxFCEList, wxFontCacheEntry);
class wxFontCache
{
public:
- wxFont & GetFont(int family, int size, int style, int weight,
- bool underline);
- wxFont & GetFont(wxLayoutStyleInfo const &si)
- {
- return GetFont(si.family, si.size, si.style, si.weight,
- si.underline != 0);
- }
+ wxFont & GetFont(int family, int size, int style, int weight,
+ bool underline);
+
+ wxFont & GetFont(wxLayoutStyleInfo const &si)
+ {
+ return GetFont(si.family, si.size, si.style, si.weight,
+ si.underline != 0);
+ }
+
private:
- wxFCEList m_FontList;
+ wxFCEList m_FontList;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutObjectCmd : public wxLayoutObject
{
public:
- virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
- virtual void Layout(wxDC &dc, wxLayoutList *llist);
- virtual void Draw(wxDC &dc, wxPoint const &coords,
- wxLayoutList *wxllist,
- CoordType begin = -1,
- CoordType end = -1);
- wxLayoutObjectCmd(int family = -1,
- int size = -1,
- int style = -1,
- int weight = -1,
- int underline = -1,
- wxColour *fg = NULL,
- wxColour *bg = NULL);
- wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
- ~wxLayoutObjectCmd();
- /** Stores the current style in the styleinfo structure */
- wxLayoutStyleInfo * GetStyle(void) const;
- /** Makes a copy of this object.
- */
- virtual wxLayoutObject *Copy(void);
- virtual void Write(wxString &ostr);
- static wxLayoutObjectCmd *Read(wxString &istr);
+ virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_CMD; }
+ virtual void Layout(wxDC &dc, wxLayoutList *llist);
+ virtual void Draw(wxDC &dc, wxPoint const &coords,
+ wxLayoutList *wxllist,
+ CoordType begin = -1,
+ CoordType end = -1);
+
+ wxLayoutObjectCmd(int family = -1,
+ int size = -1,
+ int style = -1,
+ int weight = -1,
+ int underline = -1,
+ wxColour *fg = NULL,
+ wxColour *bg = NULL);
+
+ wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
+ ~wxLayoutObjectCmd();
+ /** Stores the current style in the styleinfo structure */
+ wxLayoutStyleInfo * GetStyle() const;
+ /** Makes a copy of this object.
+ */
+ virtual wxLayoutObject *Copy();
+ virtual void Write(wxString &ostr);
+ static wxLayoutObjectCmd *Read(wxString &istr);
+
private:
- wxLayoutStyleInfo *m_StyleInfo;
+ wxLayoutStyleInfo *m_StyleInfo;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutLine
{
public:
- /** Constructor.
- @param prev pointer to previous line or NULL
- @param next pointer to following line or NULL
- @param llist pointer to layout list
- */
- wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist);
- /** This function inserts a new object at cursor position xpos.
- @param xpos where to insert new object
- @param obj the object to insert
- @return true if that xpos existed and the object was inserted
- */
- bool Insert(CoordType xpos, wxLayoutObject *obj);
-
- /** This function inserts text at cursor position xpos.
- @param xpos where to insert
- @param text the text to insert
- @return true if that xpos existed and the object was inserted
- */
- bool Insert(CoordType xpos, const wxString& text);
-
- /** This function appends an object to the line.
- @param obj the object to insert
- */
- void Append(wxLayoutObject * obj)
- {
- wxASSERT(obj);
- m_ObjectList.push_back(obj);
- m_Length += obj->GetLength();
- }
-
- /** This function prepends an object to the line. */
- void Prepend(wxLayoutObject * obj)
- {
- wxASSERT(obj);
- m_ObjectList.push_front(obj);
- m_Length += obj->GetLength();
- }
-
- /** This function appens the next line to this, i.e. joins the two
- lines into one.
- */
- void MergeNextLine(wxLayoutList *llist);
-
- /** This function deletes npos cursor positions from position xpos.
- @param xpos where to delete
- @param npos how many positions
- @return number of positions still to be deleted
- */
- CoordType Delete(CoordType xpos, CoordType npos);
-
- /** This function breaks the line at a given cursor position.
- @param xpos where to break it
- @return pointer to the new line object replacing the old one
- */
- wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
-
- /** This function wraps the line: breaks it at a suitable point
- and merges it with the next.
- @param wrapmargin
- @return TRUE if broken
- */
- bool Wrap(CoordType wrapmargin, wxLayoutList *llist);
-
- /** Deletes the next word from this position, including leading
- whitespace.
- This function does not delete over font changes, i.e. a word
- with formatting instructions in the middle of it is treated as
- two (three actually!) words. In fact, if the cursor is on a non-text object, that
- one is treated as a word.
- @param xpos from where to delete
- @return true if a word was deleted
- */
- bool DeleteWord(CoordType npos);
-
- /** Finds a suitable position left to the given column to break the
- line.
- @param column we want to break the line to the left of this
- @return column for breaking line or -1 if no suitable location found
- */
- CoordType GetWrapPosition(CoordType column);
-
- /** Finds the object which covers the cursor position xpos in this
- line.
- @param xpos the column number
- @param offset where to store the difference between xpos and
- the object's head
- @return iterator to the object or NULLIT
- */
- wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
- *offset) const ;
-
- /** Finds the object which covers the screen position xpos in this
- line.
- @param dc the wxDC to use for calculations
- @param llist the layout list to which this line belongs
- @param xpos the screen x coordinate
- @param offset where to store the difference between xpos and
- the object's head
- @return iterator to the object or NULLIT
- */
- wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
- wxLayoutList *llist,
- CoordType xpos,
- CoordType *offset,
- bool *found = NULL) const ;
-
- /** Finds text in this line.
- @param needle the text to find
- @param xpos the position where to start the search
- @return the cursoor coord where it was found or -1
- */
- CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
-
- /** Get the first object in the list. This is used by the wxlparser
- functions to export the list.
- @return iterator to the first object
- */
- wxLayoutObjectList::iterator GetFirstObject(void) const
- {
- return m_ObjectList.begin();
- }
-
- /** Get the last object in the list.
- */
- wxLayoutObjectList::iterator GetLastObject(void) const
- {
- return m_ObjectList.tail();
- }
-
- /** Deletes this line, returns pointer to next line.
- @param update If true, update all following lines.
- */
- wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist);
-
- /**@name Cursor Management */
- //@{
- /** Return the line number of this line.
- @return the line number
- */
- inline CoordType GetLineNumber(void) const { return m_LineNumber; }
- /** Return the length of the line.
- @return line lenght in cursor positions
- */
- inline CoordType GetLength(void) const { return m_Length; }
- //@}
-
- /**@name Drawing and Layout */
- //@{
- /** Draws the line on a wxDC.
- @param dc the wxDC to draw on
- @param llist the wxLayoutList
- @param offset an optional offset to shift printout
- */
- void Draw(wxDC &dc,
- wxLayoutList *llist,
- const wxPoint &offset = wxPoint(0,0)) const;
-
- /** Recalculates the positions of objects and the height of the
- line.
- @param dc the wxDC to draw on
- @param llist th e wxLayoutList
- @param cursorPos if not NULL, set cursor screen position in there
- @param cursorSize if not cursorPos != NULL, set cursor size in there
- @param cursorStyle if non NULL where to store styleinfo for cursor pos
- @param cx if cursorPos != NULL, the cursor x position
- @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo
- */
- void Layout(wxDC &dc,
- wxLayoutList *llist,
- wxPoint *cursorPos = NULL,
- wxPoint *cursorSize = NULL,
- wxLayoutStyleInfo *cursorStyle = NULL,
- int cx = 0,
- bool suppressStyleUpdate = FALSE);
- /** This function finds an object belonging to a given cursor
- position. It assumes that Layout() has been called before.
- @param dc the wxDC to use for calculations
- @param xpos screen x position
- @param found if non-NULL set to false if we return the last
- object before the cursor, to true if we really have an object
- for that position
- @return pointer to the object
- */
- wxLayoutObject * FindObjectScreen(wxDC &dc,
- CoordType xpos,
- bool *found = NULL);
- /** This sets the style info for the beginning of this line.
- @param si styleinfo structure
- */
- void ApplyStyle(const wxLayoutStyleInfo &si)
- { m_StyleInfo = si; }
-
- //@}
-
- /**@name List traversal */
- //@{
- /// Returns pointer to next line.
- wxLayoutLine *GetNextLine(void) const { return m_Next; }
- /// Returns pointer to previous line.
- wxLayoutLine *GetPreviousLine(void) const { return m_Previous; }
- /// Sets the link to the next line.
- void SetNext(wxLayoutLine *next)
- { m_Next = next; if(next) next->m_Previous = this; }
- /// Sets the link to the previous line.
- void SetPrevious(wxLayoutLine *previous)
- { m_Previous = previous; if(previous) previous->m_Next = this; }
- //@}
-
- /// Returns the position of this line on the canvas.
- wxPoint GetPosition(void) const { return m_Position; }
- /// Returns the height of this line.
- CoordType GetHeight(void) const { return m_Height; }
- /// Returns the width of this line.
- CoordType GetWidth(void) const { return m_Width; }
- /// Recalculates the position of this line on the canvas.
- wxPoint RecalculatePosition(wxLayoutList *llist);
-
- /** Copies the contents of this line to another wxLayoutList
- @param llist the wxLayoutList destination
- @param from x cursor coordinate where to start
- @param to x cursor coordinate where to stop, -1 for end of line
- */
- void Copy(wxLayoutList *llist,
- CoordType from = 0,
- CoordType to = -1);
+ /** Constructor.
+ @param prev pointer to previous line or NULL
+ @param next pointer to following line or NULL
+ @param llist pointer to layout list
+ */
+ wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist);
+ /** This function inserts a new object at cursor position xpos.
+ @param xpos where to insert new object
+ @param obj the object to insert
+ @return true if that xpos existed and the object was inserted
+ */
+ bool Insert(CoordType xpos, wxLayoutObject *obj);
+
+ /** This function inserts text at cursor position xpos.
+ @param xpos where to insert
+ @param text the text to insert
+ @return true if that xpos existed and the object was inserted
+ */
+ bool Insert(CoordType xpos, const wxString& text);
+
+ /** This function appends an object to the line.
+ @param obj the object to insert
+ */
+ void Append(wxLayoutObject * obj)
+ {
+ wxASSERT(obj);
+ m_ObjectList.push_back(obj);
+ m_Length += obj->GetLength();
+ }
+
+ /** This function prepends an object to the line. */
+ void Prepend(wxLayoutObject * obj)
+ {
+ wxASSERT(obj);
+ m_ObjectList.push_front(obj);
+ m_Length += obj->GetLength();
+ }
+
+ /** This function appens the next line to this, i.e. joins the two
+ lines into one.
+ */
+ void MergeNextLine(wxLayoutList *llist);
+
+ /** This function deletes npos cursor positions from position xpos.
+ @param xpos where to delete
+ @param npos how many positions
+ @return number of positions still to be deleted
+ */
+ CoordType Delete(CoordType xpos, CoordType npos);
+
+ /** This function breaks the line at a given cursor position.
+ @param xpos where to break it
+ @return pointer to the new line object replacing the old one
+ */
+ wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
+
+ /** This function wraps the line: breaks it at a suitable point
+ and merges it with the next.
+ @param wrapmargin
+ @return true if broken
+ */
+ bool Wrap(CoordType wrapmargin, wxLayoutList *llist);
+
+ /** Deletes the next word from this position, including leading
+ whitespace.
+ This function does not delete over font changes, i.e. a word
+ with formatting instructions in the middle of it is treated as
+ two (three actually!) words. In fact, if the cursor is on a non-text object, that
+ one is treated as a word.
+ @param xpos from where to delete
+ @return true if a word was deleted
+ */
+ bool DeleteWord(CoordType npos);
+
+ /** Finds a suitable position left to the given column to break the
+ line.
+ @param column we want to break the line to the left of this
+ @return column for breaking line or -1 if no suitable location found
+ */
+ CoordType GetWrapPosition(CoordType column);
+
+ /** Finds the object which covers the cursor position xpos in this
+ line.
+ @param xpos the column number
+ @param offset where to store the difference between xpos and
+ the object's head
+ @return iterator to the object or NULLIT
+ */
+ wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
+ *offset) const ;
+
+ /** Finds the object which covers the screen position xpos in this
+ line.
+ @param dc the wxDC to use for calculations
+ @param llist the layout list to which this line belongs
+ @param xpos the screen x coordinate
+ @param offset where to store the difference between xpos and
+ the object's head
+ @return iterator to the object or NULLIT
+ */
+ wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
+ wxLayoutList *llist,
+ CoordType xpos,
+ CoordType *offset,
+ bool *found = NULL) const ;
+
+ /** Finds text in this line.
+ @param needle the text to find
+ @param xpos the position where to start the search
+ @return the cursoor coord where it was found or -1
+ */
+ CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
+
+ /** Get the first object in the list. This is used by the wxlparser
+ functions to export the list.
+ @return iterator to the first object
+ */
+ wxLayoutObjectList::iterator GetFirstObject() const
+ {
+ return m_ObjectList.begin();
+ }
+
+ /// Get the last object in the list.
+ wxLayoutObjectList::iterator GetLastObject() const
+ {
+ return m_ObjectList.tail();
+ }
+
+ /** Deletes this line, returns pointer to next line.
+ @param update If true, update all following lines.
+ */
+ wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist);
+
+ /**@name Cursor Management */
+ //@{
+ /** Return the line number of this line.
+ @return the line number
+ */
+ inline CoordType GetLineNumber() const { return m_LineNumber; }
+
+ /** Return the length of the line.
+ @return line lenght in cursor positions
+ */
+ inline CoordType GetLength() const { return m_Length; }
+ //@}
+
+ /**@name Drawing and Layout */
+ //@{
+ /** Draws the line on a wxDC.
+ @param dc the wxDC to draw on
+ @param llist the wxLayoutList
+ @param offset an optional offset to shift printout
+ */
+ void Draw(wxDC &dc,
+ wxLayoutList *llist,
+ const wxPoint &offset = wxPoint(0,0)) const;
+
+ /** Recalculates the positions of objects and the height of the
+ line.
+ @param dc the wxDC to draw on
+ @param llist th e wxLayoutList
+ @param cursorPos if not NULL, set cursor screen position in there
+ @param cursorSize if not cursorPos != NULL, set cursor size in there
+ @param cursorStyle if non NULL where to store styleinfo for cursor pos
+ @param cx if cursorPos != NULL, the cursor x position
+ @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo
+ */
+ void Layout(wxDC &dc,
+ wxLayoutList *llist,
+ wxPoint *cursorPos = NULL,
+ wxPoint *cursorSize = NULL,
+ wxLayoutStyleInfo *cursorStyle = NULL,
+ int cx = 0,
+ bool suppressStyleUpdate = false);
+
+ /** This function finds an object belonging to a given cursor
+ position. It assumes that Layout() has been called before.
+ @param dc the wxDC to use for calculations
+ @param xpos screen x position
+ @param found if non-NULL set to false if we return the last
+ object before the cursor, to true if we really have an object
+ for that position
+ @return pointer to the object
+ */
+ wxLayoutObject * FindObjectScreen(wxDC &dc,
+ CoordType xpos,
+ bool *found = NULL);
+
+ /** This sets the style info for the beginning of this line.
+ @param si styleinfo structure
+ */
+ void ApplyStyle(const wxLayoutStyleInfo &si)
+ { m_StyleInfo = si; }
+
+ //@}
+
+ /**@name List traversal */
+ //@{
+ /// Returns pointer to next line.
+ wxLayoutLine *GetNextLine() const { return m_Next; }
+
+ /// Returns pointer to previous line.
+ wxLayoutLine *GetPreviousLine() const { return m_Previous; }
+
+ /// Sets the link to the next line.
+ void SetNext(wxLayoutLine *next)
+ { m_Next = next; if(next) next->m_Previous = this; }
+
+ /// Sets the link to the previous line.
+ void SetPrevious(wxLayoutLine *previous)
+ { m_Previous = previous; if(previous) previous->m_Next = this; }
+ //@}
+
+ /// Returns the position of this line on the canvas.
+ wxPoint GetPosition() const { return m_Position; }
+
+ /// Returns the height of this line.
+ CoordType GetHeight() const { return m_Height; }
+
+ /// Returns the width of this line.
+ CoordType GetWidth() const { return m_Width; }
+
+ /// Recalculates the position of this line on the canvas.
+ wxPoint RecalculatePosition(wxLayoutList *llist);
+
+ /** Copies the contents of this line to another wxLayoutList
+ @param llist the wxLayoutList destination
+ @param from x cursor coordinate where to start
+ @param to x cursor coordinate where to stop, -1 for end of line
+ */
+ void Copy(wxLayoutList *llist,
+ CoordType from = 0,
+ CoordType to = -1);
#ifdef WXLAYOUT_DEBUG
- void Debug(void) const;
+ void Debug() const;
#endif
- wxLayoutStyleInfo const & GetStyleInfo() const { return m_StyleInfo; }
-
- /// Returns dirty state
- bool IsDirty(void) const { return m_Dirty; }
- /** Marks this line as diry.
- @param left xpos from where it is dirty or -1 for all
- */
- void MarkDirty(CoordType left = -1)
- {
- if ( left != -1 )
- {
- if ( m_updateLeft == -1 || left < m_updateLeft )
- m_updateLeft = left;
- }
-
- m_Dirty = true;
- if(m_Next) m_Next->MarkDirty();
- }
- /// Reset the dirty flag
- void MarkClean() { m_Dirty = false; m_updateLeft = -1; }
+ wxLayoutStyleInfo const & GetStyleInfo() const { return m_StyleInfo; }
+
+ /// Returns dirty state
+ bool IsDirty() const { return m_Dirty; }
+
+ /** Marks this line as diry.
+ @param left xpos from where it is dirty or -1 for all
+ */
+ void MarkDirty(CoordType left = -1)
+ {
+ if ( left != -1 )
+ {
+ if ( m_updateLeft == -1 || left < m_updateLeft )
+ m_updateLeft = left;
+ }
+
+ m_Dirty = true;
+ if(m_Next) m_Next->MarkDirty();
+ }
+
+ /// Reset the dirty flag
+ void MarkClean() { m_Dirty = false; m_updateLeft = -1; }
private:
- /// Destructor is private. Use DeleteLine() to remove it.
- ~wxLayoutLine();
-
- /**@name Functions to let the lines synchronise with each other. */
- //@{
- /** Sets the height of this line. Will mark following lines as
- dirty.
- @param height new height
- */
- void SetHeight(CoordType height, wxLayoutList *llist)
- { m_Height = height; MarkDirty(); }
-
- /** Updates the line numbers. */
- void ReNumber(void);
- //@}
+ /// Destructor is private. Use DeleteLine() to remove it.
+ ~wxLayoutLine();
+
+ /**@name Functions to let the lines synchronise with each other. */
+ //@{
+ /** Sets the height of this line. Will mark following lines as
+ dirty.
+ @param height new height
+ */
+ void SetHeight( CoordType height, wxLayoutList * WXUNUSED(llist) )
+ {
+ m_Height = height; MarkDirty();
+ }
+
+ /** Updates the line numbers. */
+ void ReNumber();
+ //@}
+
private:
- /// The line number.
- CoordType m_LineNumber;
- /// The line length in cursor positions.
- CoordType m_Length;
- /// The total height of the line.
- CoordType m_Height;
- /// The total width of the line on screen.
- CoordType m_Width;
- /// The baseline for drawing objects
- CoordType m_BaseLine;
- /// The position on the canvas.
- wxPoint m_Position;
- /// The list of objects
- wxLayoutObjectList m_ObjectList;
- /// Have we been changed since the last layout?
- bool m_Dirty;
- /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
- CoordType m_updateLeft;
- /// Pointer to previous line if it exists.
- wxLayoutLine *m_Previous;
- /// Pointer to next line if it exists.
- wxLayoutLine *m_Next;
- /// A StyleInfo structure, holding the current settings.
- wxLayoutStyleInfo m_StyleInfo;
- /// Just to suppress gcc compiler warnings.
- friend class dummy;
+ /// The line number.
+ CoordType m_LineNumber;
+
+ /// The line length in cursor positions.
+ CoordType m_Length;
+
+ /// The total height of the line.
+ CoordType m_Height;
+
+ /// The total width of the line on screen.
+ CoordType m_Width;
+
+ /// The baseline for drawing objects
+ CoordType m_BaseLine;
+
+ /// The position on the canvas.
+ wxPoint m_Position;
+
+ /// The list of objects
+ wxLayoutObjectList m_ObjectList;
+
+ /// Have we been changed since the last layout?
+ bool m_Dirty;
+
+ /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
+ CoordType m_updateLeft;
+
+ /// Pointer to previous line if it exists.
+ wxLayoutLine *m_Previous;
+
+ /// Pointer to next line if it exists.
+ wxLayoutLine *m_Next;
+
+ /// A StyleInfo structure, holding the current settings.
+ wxLayoutStyleInfo m_StyleInfo;
+
+ /// Just to suppress gcc compiler warnings.
+ friend class dummy;
+
private:
- wxLayoutLine(const wxLayoutLine &);
+ wxLayoutLine(const wxLayoutLine &);
};
class wxLayoutList
{
public:
- /// Constructor.
- wxLayoutList();
- /// Destructor.
- ~wxLayoutList();
+ /// Constructor.
+ wxLayoutList();
+
+ /// Destructor.
+ ~wxLayoutList();
#ifdef WXLAYOUT_USE_CARET
- /// give us the pointer to the caret to use
- void SetCaret(wxCaret *caret) { m_caret = caret; }
+ /// give us the pointer to the caret to use
+ void SetCaret(wxCaret *caret) { m_caret = caret; }
#endif // WXLAYOUT_USE_CARET
- /// Clear the list.
- void Clear(int family = wxROMAN,
- int size=WXLO_DEFAULTFONTSIZE,
- int style=wxNORMAL,
- int weight=wxNORMAL,
- int underline=0,
- wxColour *fg=NULL,
- wxColour *bg=NULL);
- /// Empty: clear the list but leave font settings.
- void Empty(void);
-
- /** Enable or disable auto-formatting. Normally, while editing this
- should be enabled which is the default. While
- inserting/deleting lots of text, it makes sense to temporarily
- disable this.
- @param enable TRUE to enable, FALSE to disable
- */
- void SetAutoFormatting(bool enable = TRUE)
- { m_AutoFormat = enable; }
- /**@name Cursor Management */
- //@{
- /** Set new cursor position.
- @param p new position
- @return bool if it could be set
- */
- bool MoveCursorTo(wxPoint const &p);
- /** Move cursor up or down.
- @param n
- @return bool if it could be moved
- */
- bool MoveCursorVertically(int n);
- /** Move cursor left or right.
- @param n = number of positions to move
- @return bool if it could be moved
- */
- bool MoveCursorHorizontally(int n);
- /** Move cursor to the left or right counting in words
- @param n = number of positions in words
- @param untilNext: puts the cursor at the start of the next word if true,
+ /// Clear the list.
+ void Clear(int family = wxROMAN,
+ int size=WXLO_DEFAULTFONTSIZE,
+ int style=wxNORMAL,
+ int weight=wxNORMAL,
+ int underline=0,
+ wxColour *fg=NULL,
+ wxColour *bg=NULL);
+
+ /// Empty: clear the list but leave font settings.
+ void Empty();
+
+ /** Enable or disable auto-formatting. Normally, while editing this
+ should be enabled which is the default. While
+ inserting/deleting lots of text, it makes sense to temporarily
+ disable this.
+ @param enable true to enable, false to disable
+ */
+
+ void SetAutoFormatting(bool enable = true)
+ { m_AutoFormat = enable; }
+
+ /**@name Cursor Management */
+ //@{
+ /** Set new cursor position.
+ @param p new position
+ @return bool if it could be set
+ */
+ bool MoveCursorTo(wxPoint const &p);
+
+ /** Move cursor up or down.
+ @param n
+ @return bool if it could be moved
+ */
+ bool MoveCursorVertically(int n);
+
+ /** Move cursor left or right.
+ @param n = number of positions to move
+ @return bool if it could be moved
+ */
+ bool MoveCursorHorizontally(int n);
+
+ /** Move cursor to the left or right counting in words
+ @param n = number of positions in words
+ @param untilNext: puts the cursor at the start of the next word if true,
leaves it at the end of the current one otherwise
- @return bool if it could be moved
- */
- bool MoveCursorWord(int n, bool untilNext = true);
-
- /// Move cursor to end of line.
- void MoveCursorToEndOfLine(void)
- {
- wxASSERT(m_CursorLine);
- MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
- }
-
- /// Move cursor to the start of line.
- void MoveCursorToBeginOfLine(void)
- { MoveCursorHorizontally(-m_CursorPos.x); }
-
- /// get the number of lines in the list
- size_t GetNumLines() const { return m_numLines; }
-
- /// Returns current cursor position.
- const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; }
- const wxPoint &GetCursorPos() const { return m_CursorPos; }
- wxLayoutLine * GetCursorLine(void) { return m_CursorLine; }
-
- /// move cursor to the end of text
- void MoveCursorToEnd(void)
- {
- MoveCursorTo(wxPoint(0, GetNumLines() - 1));
- MoveCursorToEndOfLine();
- }
-
- //@}
-
- /**@name Editing functions.
- All of these functions return true on success and false on
- failure. */
- //@{
- /// Insert text at current cursor position.
- bool Insert(wxString const &text);
- /// Insert some other object at current cursor position.
- bool Insert(wxLayoutObject *obj);
- /// Inserts objects at current cursor positions
- bool Insert(wxLayoutList *llist);
-
- /// Inserts a linebreak at current cursor position.
- bool LineBreak(void);
- /** Wraps the current line. Searches to the left of the cursor to
- break the line. Does nothing if the cursor position is before
- the break position parameter.
- @param column the break position for the line, maximum length
- @return true if line got broken
- */
- bool WrapLine(CoordType column);
-
- /** Wraps the complete buffer.
- @param column the break position for the line, maximum length
- @return true if line got broken
- */
- bool WrapAll(CoordType column);
- /** This function deletes npos cursor positions.
- @param npos how many positions
- @return true if everything got deleted
- */
- bool Delete(CoordType npos);
-
- /** Delete the next n lines.
- @param n how many lines to delete
- @return how many it could not delete
- */
- int DeleteLines(int n);
-
- /// Delete to end of line.
- void DeleteToEndOfLine(void)
- {
- wxASSERT(m_CursorLine);
- Delete(m_CursorLine->GetLength()-m_CursorPos.x);
- }
- /// Delete to begin of line.
- void DeleteToBeginOfLine(void)
- {
- wxASSERT(m_CursorLine);
- CoordType n = m_CursorPos.x;
+ @return bool if it could be moved
+ */
+ bool MoveCursorWord(int n, bool untilNext = true);
+
+ /// Move cursor to end of line.
+ void MoveCursorToEndOfLine()
+ {
+ wxASSERT(m_CursorLine);
+ MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
+ }
+
+ /// Move cursor to the start of line.
+ void MoveCursorToBeginOfLine()
+ { MoveCursorHorizontally(-m_CursorPos.x); }
+
+ /// get the number of lines in the list
+ size_t GetNumLines() const { return m_numLines; }
+
+ /// Returns current cursor position.
+ const wxPoint &GetCursorPos(wxDC & WXUNUSED(dc) ) const
+ { return m_CursorPos; }
+ const wxPoint &GetCursorPos() const { return m_CursorPos; }
+ wxLayoutLine * GetCursorLine() { return m_CursorLine; }
+
+ /// move cursor to the end of text
+ void MoveCursorToEnd()
+ {
+ MoveCursorTo(wxPoint(0, GetNumLines() - 1));
+ MoveCursorToEndOfLine();
+ }
+
+ //@}
+
+ /**@name Editing functions.
+ All of these functions return true on success and false on
+ failure. */
+ //@{
+ /// Insert text at current cursor position.
+ bool Insert(wxString const &text);
+
+ /// Insert some other object at current cursor position.
+ bool Insert(wxLayoutObject *obj);
+
+ /// Inserts objects at current cursor positions
+ bool Insert(wxLayoutList *llist);
+
+ /// Inserts a linebreak at current cursor position.
+ bool LineBreak();
+ /** Wraps the current line. Searches to the left of the cursor to
+ break the line. Does nothing if the cursor position is before
+ the break position parameter.
+ @param column the break position for the line, maximum length
+ @return true if line got broken
+ */
+ bool WrapLine(CoordType column);
+
+ /** Wraps the complete buffer.
+ @param column the break position for the line, maximum length
+ @return true if line got broken
+ */
+ bool WrapAll(CoordType column);
+ /** This function deletes npos cursor positions.
+ @param npos how many positions
+ @return true if everything got deleted
+ */
+ bool Delete(CoordType npos);
+
+ /** Delete the next n lines.
+ @param n how many lines to delete
+ @return how many it could not delete
+ */
+ int DeleteLines(int n);
+
+ /// Delete to end of line.
+ void DeleteToEndOfLine()
+ {
+ wxASSERT(m_CursorLine);
+ Delete(m_CursorLine->GetLength()-m_CursorPos.x);
+ }
+
+ /// Delete to begin of line.
+ void DeleteToBeginOfLine()
+ {
+ wxASSERT(m_CursorLine);
+ CoordType n = m_CursorPos.x;
#ifdef WXLAYOUT_DEBUG
- wxASSERT(MoveCursorHorizontally(-n));
+ wxASSERT(MoveCursorHorizontally(-n));
#else
- MoveCursorHorizontally(-n);
+ MoveCursorHorizontally(-n);
#endif
- Delete(n);
- }
-
- /** Delete the next word.
- */
- void DeleteWord(void)
- {
- wxASSERT(m_CursorLine);
- m_CursorLine->DeleteWord(m_CursorPos.x);
- }
-
- //@}
-
- /** Finds text in this list.
- @param needle the text to find
- @param cpos the position where to start the search
- @return the cursor coord where it was found or (-1,-1)
- */
- wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
-
- /**@name Formatting options */
- //@{
- /// sets font parameters
- void SetFont(int family, int size, int style,
- int weight, int underline,
- wxColour *fg,
- wxColour *bg);
- /// sets font parameters, colours by name
- void SetFont(int family=-1, int size = -1, int style=-1,
- int weight=-1, int underline = -1,
- wxChar const *fg = NULL,
- wxChar const *bg = NULL);
- /// changes to the next larger font size
- inline void SetFontLarger(void)
- { SetFont(-1,(12*m_CurrentStyleInfo.size)/10); }
- /// changes to the next smaller font size
- inline void SetFontSmaller(void)
- { SetFont(-1,(10*m_CurrentStyleInfo.size)/12); }
-
- /// set font family
- inline void SetFontFamily(int family) { SetFont(family); }
- /// set font size
- inline void SetFontSize(int size) { SetFont(-1,size); }
- /// set font style
- inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
- /// set font weight
- inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
- /// toggle underline flag
- inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
- /// set font colours by name
- inline void SetFontColour(wxChar const *fg, wxChar const *bg = NULL)
- { SetFont(-1,-1,-1,-1,-1,fg,bg); }
- /// set font colours by colour
- inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
- { SetFont(-1,-1,-1,-1,-1,fg,bg); }
-
- /**
- Returns a pointer to the default settings.
- This is only valid temporarily and should not be stored
- anywhere.
- @return the default settings of the list
- */
- wxLayoutStyleInfo &GetDefaultStyleInfo(void) { return m_DefaultStyleInfo ; }
- wxLayoutStyleInfo &GetStyleInfo(void) { return m_CurrentStyleInfo ; }
- const wxLayoutStyleInfo &GetStyleInfo(void) const { return m_CurrentStyleInfo ; }
- const wxLayoutStyleInfo &GetCursorStyleInfo(void) const { return m_CursorStyleInfo ; }
-
- /// is the current font underlined?
- bool IsFontUnderlined() const { return GetCursorStyleInfo().underline != 0; }
- /// is the current font bold?
- bool IsFontBold() const { return GetCursorStyleInfo().weight == wxBOLD; }
- /// is the current font italic?
- bool IsFontItalic() const { return GetCursorStyleInfo().style == wxITALIC; }
-
- /// set underline if it was off, turn it off if it was on
- void ToggleFontUnderline()
- { SetFontUnderline(!IsFontUnderlined()); }
-
- /// make font bold if it was normal or make it normal if it was bold
- void ToggleFontWeight()
- { SetFontWeight(IsFontBold() ? wxNORMAL : wxBOLD); }
-
- /// make font italic if it was normal or make it normal if it was italic
- void ToggleFontItalics()
- { SetFontStyle(IsFontItalic() ? wxNORMAL : wxITALIC); }
-
- //@}
-
- /**@name Drawing */
- //@{
- /** Draws the complete list on a wxDC.
- @param dc the wxDC to draw on
- @param offset an optional offset to shift printout
- @param top optional y coordinate where to start drawing
- @param bottom optional y coordinate where to stop drawing
- @param clipStrictly if set, do not draw objects which reach
- beyond "bottom". Set this when printing.
- */
- void Draw(wxDC &dc,
- const wxPoint &offset = wxPoint(0,0),
- CoordType top = -1, CoordType bottom = -1,
- bool clipStrictly = false);
-
- /** Calculates new layout for the list, like Draw() but does not
- actually draw it.
- @param dc the wxDC to draw on
- @param bottom optional y coordinate where to stop calculating
- @param forceAll force re-layout of all lines
- @param cpos Can hold a cursorposition, and will be overwritten
- with the corresponding DC position.
- @param csize Will hold the cursor size relating to cpos.
- */
- void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false,
- wxPoint *cpos = NULL,
- wxPoint *csize = NULL);
-
- /** Ensure that the whole list will be recalculate on the next call
- to Layout() or Draw().
- @param redrawAll TRUE or FALSE to reset it
- */
- void ForceTotalLayout(bool redrawAll = TRUE)
- { m_ReLayoutAll = redrawAll; }
-
- /** Returns the screen coordinates relating to a given cursor
- position and the size of the cursor at that position.
- @param dc for which to calculate it
- @param cpos Cursor position to look for.
- @param csize If non-NULL, will be set to the cursor size.
- @return The cursor position on the DC.
- */
- wxPoint GetScreenPos(wxDC &dc, const wxPoint &cpos, wxPoint *csize = NULL);
-
- /** Calculates new sizes for everything in the list, like Layout()
- but this is needed after the list got changed.
- @param dc the wxDC to draw on
- @param bottom optional y coordinate where to stop calculating
- */
- void Recalculate(wxDC &dc, CoordType bottom = -1);
-
- /** Returns the size of the list in screen coordinates.
- The return value only makes sense after the list has been
- drawn.
- @return a wxPoint holding the maximal x/y coordinates used for
- drawing
- */
- wxPoint GetSize(void) const;
-
- /** Returns the cursor position on the screen.
- */
- wxPoint GetCursorScreenPos(void) const;
-
- /** Draws the cursor.
- @param active If true, draw a bold cursor to mark window as
- active.
- @param translate optional translation of cursor coords on screen
- */
- void DrawCursor(wxDC &dc,
- bool active = true,
- const wxPoint & translate = wxPoint(0,0));
-
- /** This function finds an object belonging to a given screen
- position. It assumes that Layout() has been called before.
- @param pos screen position
- @param cursorPos if non NULL, store cursor position in there
- @param found if used, set this to true if we really found an
- object, to false if we had to take the object near to it
- @return pointer to the object
- */
- wxLayoutObject * FindObjectScreen(wxDC &dc,
- wxPoint const pos,
- wxPoint *cursorPos = NULL,
- bool *found = NULL);
-
- /** Called by the objects to update the update rectangle.
- @param x horizontal coordinate to include in rectangle
- @param y vertical coordinate to include in rectangle
- */
- void SetUpdateRect(CoordType x, CoordType y);
- /** Called by the objects to update the update rectangle.
- @param p a point to include in it
- */
- void SetUpdateRect(const wxPoint &p)
- { SetUpdateRect(p.x,p.y); }
- /// adds the cursor position to the update rectangle
- void AddCursorPosToUpdateRect()
- {
+ Delete(n);
+ }
+
+ /** Delete the next word.
+ */
+ void DeleteWord()
+ {
+ wxASSERT(m_CursorLine);
+ m_CursorLine->DeleteWord(m_CursorPos.x);
+ }
+
+ //@}
+
+ /** Finds text in this list.
+ @param needle the text to find
+ @param cpos the position where to start the search
+ @return the cursor coord where it was found or (-1,-1)
+ */
+ wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
+
+ /**@name Formatting options */
+ //@{
+ /// sets font parameters
+ void SetFont(int family, int size, int style,
+ int weight, int underline,
+ wxColour *fg,
+ wxColour *bg);
+
+ /// sets font parameters, colours by name
+ void SetFont(int family=-1, int size = -1, int style=-1,
+ int weight=-1, int underline = -1,
+ wxChar const *fg = NULL,
+ wxChar const *bg = NULL);
+
+ /// changes to the next larger font size
+ inline void SetFontLarger()
+ { SetFont(-1,(12*m_CurrentStyleInfo.size)/10); }
+
+ /// changes to the next smaller font size
+ inline void SetFontSmaller()
+ { SetFont(-1,(10*m_CurrentStyleInfo.size)/12); }
+
+ /// set font family
+ inline void SetFontFamily(int family) { SetFont(family); }
+
+ /// set font size
+ inline void SetFontSize(int size) { SetFont(-1,size); }
+
+ /// set font style
+ inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
+
+ /// set font weight
+ inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
+
+ /// toggle underline flag
+ inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
+
+ /// set font colours by name
+ inline void SetFontColour(wxChar const *fg, wxChar const *bg = NULL)
+ { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+
+ /// set font colours by colour
+ inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
+ { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+
+ /**
+ Returns a pointer to the default settings.
+ This is only valid temporarily and should not be stored
+ anywhere.
+ @return the default settings of the list
+ */
+ wxLayoutStyleInfo &GetDefaultStyleInfo() { return m_DefaultStyleInfo ; }
+ wxLayoutStyleInfo &GetStyleInfo() { return m_CurrentStyleInfo ; }
+ const wxLayoutStyleInfo &GetStyleInfo() const { return m_CurrentStyleInfo ; }
+ const wxLayoutStyleInfo &GetCursorStyleInfo() const { return m_CursorStyleInfo ; }
+
+ /// is the current font underlined?
+ bool IsFontUnderlined() const { return GetCursorStyleInfo().underline != 0; }
+
+ /// is the current font bold?
+ bool IsFontBold() const { return GetCursorStyleInfo().weight == wxBOLD; }
+
+ /// is the current font italic?
+ bool IsFontItalic() const { return GetCursorStyleInfo().style == wxITALIC; }
+
+ /// set underline if it was off, turn it off if it was on
+ void ToggleFontUnderline()
+ { SetFontUnderline(!IsFontUnderlined()); }
+
+ /// make font bold if it was normal or make it normal if it was bold
+ void ToggleFontWeight()
+ { SetFontWeight(IsFontBold() ? wxNORMAL : wxBOLD); }
+
+ /// make font italic if it was normal or make it normal if it was italic
+ void ToggleFontItalics()
+ { SetFontStyle(IsFontItalic() ? wxNORMAL : wxITALIC); }
+
+ //@}
+
+ /**@name Drawing */
+ //@{
+ /** Draws the complete list on a wxDC.
+ @param dc the wxDC to draw on
+ @param offset an optional offset to shift printout
+ @param top optional y coordinate where to start drawing
+ @param bottom optional y coordinate where to stop drawing
+ @param clipStrictly if set, do not draw objects which reach
+ beyond "bottom". Set this when printing.
+ */
+ void Draw(wxDC &dc,
+ const wxPoint &offset = wxPoint(0,0),
+ CoordType top = -1, CoordType bottom = -1,
+ bool clipStrictly = false);
+
+ /** Calculates new layout for the list, like Draw() but does not
+ actually draw it.
+ @param dc the wxDC to draw on
+ @param bottom optional y coordinate where to stop calculating
+ @param forceAll force re-layout of all lines
+ @param cpos Can hold a cursorposition, and will be overwritten
+ with the corresponding DC position.
+ @param csize Will hold the cursor size relating to cpos.
+ */
+ void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false,
+ wxPoint *cpos = NULL,
+ wxPoint *csize = NULL);
+
+ /** Ensure that the whole list will be recalculate on the next call
+ to Layout() or Draw().
+ @param redrawAll true or false to reset it
+ */
+ void ForceTotalLayout(bool redrawAll = true)
+ { m_ReLayoutAll = redrawAll; }
+
+ /** Returns the screen coordinates relating to a given cursor
+ position and the size of the cursor at that position.
+ @param dc for which to calculate it
+ @param cpos Cursor position to look for.
+ @param csize If non-NULL, will be set to the cursor size.
+ @return The cursor position on the DC.
+ */
+ wxPoint GetScreenPos(wxDC &dc, const wxPoint &cpos, wxPoint *csize = NULL);
+
+ /** Calculates new sizes for everything in the list, like Layout()
+ but this is needed after the list got changed.
+ @param dc the wxDC to draw on
+ @param bottom optional y coordinate where to stop calculating
+ */
+ void Recalculate(wxDC &dc, CoordType bottom = -1);
+
+ /** Returns the size of the list in screen coordinates.
+ The return value only makes sense after the list has been
+ drawn.
+ @return a wxPoint holding the maximal x/y coordinates used for
+ drawing
+ */
+ wxPoint GetSize() const;
+
+ /** Returns the cursor position on the screen.
+ */
+ wxPoint GetCursorScreenPos() const;
+
+ /** Draws the cursor.
+ @param active If true, draw a bold cursor to mark window as
+ active.
+ @param translate optional translation of cursor coords on screen
+ */
+ void DrawCursor(wxDC &dc,
+ bool active = true,
+ const wxPoint & translate = wxPoint(0,0));
+
+ /** This function finds an object belonging to a given screen
+ position. It assumes that Layout() has been called before.
+ @param pos screen position
+ @param cursorPos if non NULL, store cursor position in there
+ @param found if used, set this to true if we really found an
+ object, to false if we had to take the object near to it
+ @return pointer to the object
+ */
+ wxLayoutObject * FindObjectScreen(wxDC &dc,
+ wxPoint const pos,
+ wxPoint *cursorPos = NULL,
+ bool *found = NULL);
+
+ /** Called by the objects to update the update rectangle.
+ @param x horizontal coordinate to include in rectangle
+ @param y vertical coordinate to include in rectangle
+ */
+ void SetUpdateRect(CoordType x, CoordType y);
+
+ /** Called by the objects to update the update rectangle.
+ @param p a point to include in it
+ */
+ void SetUpdateRect(const wxPoint &p)
+ { SetUpdateRect(p.x,p.y); }
+
+ /// adds the cursor position to the update rectangle
+ void AddCursorPosToUpdateRect()
+ {
#ifndef WXLAYOUT_USE_CARET
- SetUpdateRect(m_CursorScreenPos);
- SetUpdateRect(m_CursorScreenPos+m_CursorSize);
- //#else - the caret will take care of refreshing itself
+ SetUpdateRect(m_CursorScreenPos);
+ SetUpdateRect(m_CursorScreenPos+m_CursorSize);
+//#else - the caret will take care of refreshing itself
#endif // !WXLAYOUT_USE_CARET
- }
- /// Invalidates the update rectangle.
- void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
- /// Returns the update rectangle.
- const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; }
- //@}
-
- /// get the current cursor size
- const wxPoint& GetCursorSize() const { return m_CursorSize; }
-
- /**@name For exporting one object after another. */
- //@{
- /** Returns a pointer to the first line in the list. */
- wxLayoutLine *GetFirstLine(void)
- {
- wxASSERT(m_FirstLine);
- return m_FirstLine;
- }
- //@}
-
- /// Begin selecting text
- void StartSelection(const wxPoint& cpos = wxPoint(-1,-1),
- const wxPoint& spos = wxPoint(-1,-1));
- // Continue selecting text
- void ContinueSelection(const wxPoint& cpos = wxPoint(-1,-1),
- const wxPoint& spos = wxPoint(-1,-1));
- /// End selecting text.
- void EndSelection(const wxPoint& cpos = wxPoint(-1,-1),
- const wxPoint& spos = wxPoint(-1,-1));
- /// Discard the current selection
- void DiscardSelection();
- /// Are we still selecting text?
- bool IsSelecting(void) const;
- /// Is the given point (text coords) selected?
- bool IsSelected(const wxPoint &cursor) const;
- /// Do we have a non null selection?
- bool HasSelection() const
- { return m_Selection.m_valid || m_Selection.m_selecting; }
-
- /** Return the selection as a wxLayoutList.
- @param invalidate if true, the selection will be invalidated after this and can no longer be used.
- @return Another layout list object holding the selection, must be freed by caller
- */
- wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = TRUE);
- /// Delete selected bit
- void DeleteSelection(void);
-
- wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
- const wxPoint &to = wxPoint(-1,-1));
-
- /// starts highlighting of text for selections
- void StartHighlighting(wxDC &dc);
- /// ends highlighting of text for selections
- void EndHighlighting(wxDC &dc);
+ }
- /** Tests whether this layout line is selected and needs
- highlighting.
- @param line to test for
- @param from set to first cursorpos to be highlighted (for returncode == -1)
- @param to set to last cursorpos to be highlighted (for returncode == -1)
- @return 0 = not selected, 1 = fully selected, -1 = partially
- selected
+ /// Invalidates the update rectangle.
+ void InvalidateUpdateRect() { m_UpdateRectValid = false; }
+
+ /// Returns the update rectangle.
+ const wxRect *GetUpdateRect() const { return &m_UpdateRect; }
+ //@}
+
+ /// get the current cursor size
+ const wxPoint& GetCursorSize() const { return m_CursorSize; }
+
+ /**@name For exporting one object after another. */
+ //@{
+ /** Returns a pointer to the first line in the list. */
+ wxLayoutLine *GetFirstLine()
+ {
+ wxASSERT(m_FirstLine);
+ return m_FirstLine;
+ }
+ //@}
+
+ /// Begin selecting text
+ void StartSelection(const wxPoint& cpos = wxPoint(-1,-1),
+ const wxPoint& spos = wxPoint(-1,-1));
+
+ // Continue selecting text
+ void ContinueSelection(const wxPoint& cpos = wxPoint(-1,-1),
+ const wxPoint& spos = wxPoint(-1,-1));
+
+ /// End selecting text.
+ void EndSelection(const wxPoint& cpos = wxPoint(-1,-1),
+ const wxPoint& spos = wxPoint(-1,-1));
+
+ /// Discard the current selection
+ void DiscardSelection();
+
+ /// Are we still selecting text?
+ bool IsSelecting() const;
+
+ /// Is the given point (text coords) selected?
+ bool IsSelected(const wxPoint &cursor) const;
+
+ /// Do we have a non null selection?
+ bool HasSelection() const
+ { return m_Selection.m_valid || m_Selection.m_selecting; }
+
+ /** Return the selection as a wxLayoutList.
+ @param invalidate if true, the selection will be invalidated after this and can no longer be used.
+ @return Another layout list object holding the selection, must be freed by caller
+ */
+ wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = true);
- */
- int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
+ /// Delete selected bit
+ void DeleteSelection();
- void ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc);
+ wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
+ const wxPoint &to = wxPoint(-1,-1));
+
+ /// starts highlighting of text for selections
+ void StartHighlighting(wxDC &dc);
+
+ /// ends highlighting of text for selections
+ void EndHighlighting(wxDC &dc);
+
+ /** Tests whether this layout line is selected and needs
+ highlighting.
+ @param line to test for
+ @param from set to first cursorpos to be highlighted (for returncode == -1)
+ @param to set to last cursorpos to be highlighted (for returncode == -1)
+ @return 0 = not selected, 1 = fully selected, -1 = partially
+ selected
+ */
+ int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
+
+ void ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG
- void Debug(void);
+ void Debug();
#endif
- // for wxLayoutLine usage only
- void IncNumLines() { m_numLines++; }
- void DecNumLines() { m_numLines--; }
+ // for wxLayoutLine usage only
+ void IncNumLines() { m_numLines++; }
+ void DecNumLines() { m_numLines--; }
- /// get the line by number
- wxLayoutLine *GetLine(CoordType index) const;
+ /// get the line by number
+ wxLayoutLine *GetLine(CoordType index) const;
- /** Reads objects from a string and inserts them. Returns NULL if
- string is empty or a linebreak was found.
- @param istr stream to read from, will bee changed
- */
- void Read(wxString &istr);
+ /** Reads objects from a string and inserts them. Returns NULL if
+ string is empty or a linebreak was found.
+ @param istr stream to read from, will bee changed
+ */
+ void Read(wxString &istr);
private:
- /// Clear the list.
- void InternalClear(void);
-
- /// The list of lines.
- wxLayoutLine *m_FirstLine;
- /// The number of lines in the list (store instead recalculating for speed)
- size_t m_numLines;
-
- /// The update rectangle which needs to be refreshed:
- wxRect m_UpdateRect;
- /// Is the update rectangle valid?
- bool m_UpdateRectValid;
-
- /// Shall we auto-format?
- bool m_AutoFormat;
- /// Shall we re-layout everything?
- bool m_ReLayoutAll;
- /**@name Cursor Management */
- //@{
- /// Where the text cursor (column,line) is.
- wxPoint m_CursorPos;
- /// Where the cursor should be drawn.
- wxPoint m_CursorScreenPos;
- /// The line where the cursor is.
- wxLayoutLine *m_CursorLine;
- /// The size of the cursor.
- wxPoint m_CursorSize;
- /// Has the cursor moved (is m_CursorScreenPos up to date)?
- bool m_movedCursor;
+ /// Clear the list.
+ void InternalClear();
+
+ /// The list of lines.
+ wxLayoutLine *m_FirstLine;
+
+ /// The number of lines in the list (store instead recalculating for speed)
+ size_t m_numLines;
+
+ /// The update rectangle which needs to be refreshed:
+ wxRect m_UpdateRect;
+
+ /// Is the update rectangle valid?
+ bool m_UpdateRectValid;
+
+ /// Shall we auto-format?
+ bool m_AutoFormat;
+
+ /// Shall we re-layout everything?
+ bool m_ReLayoutAll;
+
+ /**@name Cursor Management */
+ //@{
+ /// Where the text cursor (column,line) is.
+ wxPoint m_CursorPos;
+
+ /// Where the cursor should be drawn.
+ wxPoint m_CursorScreenPos;
+
+ /// The line where the cursor is.
+ wxLayoutLine *m_CursorLine;
+
+ /// The size of the cursor.
+ wxPoint m_CursorSize;
+
+ /// Has the cursor moved (is m_CursorScreenPos up to date)?
+ bool m_movedCursor;
+
#ifdef WXLAYOUT_USE_CARET
- /// the caret
- wxCaret *m_caret;
+ /// the caret
+ wxCaret *m_caret;
#endif // WXLAYOUT_USE_CARET
- //@}
-
- /// selection.state and begin/end coordinates
- struct Selection
- {
- Selection() { m_valid = m_selecting = m_discarded = false; }
-
- bool m_valid;
- bool m_selecting;
- bool m_discarded; // may be TRUE only until the next redraw
-
- // returns true if we already have the screen coordinates of the
- // selection start and end
- bool HasValidScreenCoords() const
- { return m_ScreenA.x != -1 && m_ScreenB.x != -1; }
-
- // the start and end of the selection coordinates in pixels
- wxPoint m_ScreenA, m_ScreenB;
-
- // these coordinates are in text positions, not in pixels
- wxPoint m_CursorA, m_CursorB;
- } m_Selection;
- /** @name Font parameters. */
- //@{
- /// this object manages the fonts for us
- wxFontCache m_FontCache;
- /// the default setting:
- wxLayoutStyleInfo m_DefaultStyleInfo;
- /// the current setting:
- wxLayoutStyleInfo m_CurrentStyleInfo;
- /// the current setting:
- wxLayoutStyleInfo m_CursorStyleInfo;
- //@}
+ //@}
+
+ /// selection.state and begin/end coordinates
+ struct Selection
+ {
+ Selection() { m_valid = m_selecting = m_discarded = false; }
+
+ bool m_valid;
+ bool m_selecting;
+ bool m_discarded; // may be true only until the next redraw
+
+ // returns true if we already have the screen coordinates of the
+ // selection start and end
+ bool HasValidScreenCoords() const
+ { return m_ScreenA.x != -1 && m_ScreenB.x != -1; }
+
+ // the start and end of the selection coordinates in pixels
+ wxPoint m_ScreenA, m_ScreenB;
+
+ // these coordinates are in text positions, not in pixels
+ wxPoint m_CursorA, m_CursorB;
+ } m_Selection;
+ /** @name Font parameters. */
+ //@{
+ /// this object manages the fonts for us
+ wxFontCache m_FontCache;
+
+ /// the default setting:
+ wxLayoutStyleInfo m_DefaultStyleInfo;
+
+ /// the current setting:
+ wxLayoutStyleInfo m_CurrentStyleInfo;
+
+ /// the current setting:
+ wxLayoutStyleInfo m_CursorStyleInfo;
+ //@}
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutDataObject : public wxCustomDataObject
{
public:
- wxLayoutDataObject()
- {
- SetFormat(wxT("application/wxlayoutlist"));
- }
-
- // type safe wrappers
- void SetLayoutData(const wxString& text)
- { SetData(text.length() + 1, text.c_str()); }
- const wxChar *GetLayoutData() const { return (const wxChar *)GetData(); }
+ wxLayoutDataObject()
+ {
+ SetFormat(wxT("application/wxlayoutlist"));
+ }
+
+ // type safe wrappers
+ void SetLayoutData(const wxString& text)
+ { SetData(text.length() + 1, text.c_str()); }
+
+ const wxChar *GetLayoutData() const { return (const wxChar *)GetData(); }
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
class wxLayoutPrintout: public wxPrintout
{
public:
- /** Constructor.
- @param llist pointer to the wxLayoutList to be printed
- @param title title for PS file or windows
- */
- wxLayoutPrintout(wxLayoutList *llist,
- wxString const & title =
- _T("wxLayout Printout"));
- /// Destructor.
- ~wxLayoutPrintout();
-
- /** Function which prints the n-th page.
- @param page the page number to print
- @return bool true if we are not at end of document yet
- */
- bool OnPrintPage(int page);
- /** Checks whether page exists in document.
- @param page number of page
- @return true if page exists
- */
- bool HasPage(int page);
-
- /** Gets called from wxWindows to find out which pages are existing.
- I'm not totally sure about the parameters though.
- @param minPage the first page in the document
- @param maxPage the last page in the document
- @param selPageFrom the first page to be printed
- @param selPageTo the last page to be printed
- */
- void GetPageInfo(int *minPage, int *maxPage,
- int *selPageFrom, int *selPageTo);
+ /** Constructor.
+ @param llist pointer to the wxLayoutList to be printed
+ @param title title for PS file or windows
+ */
+ wxLayoutPrintout(wxLayoutList *llist,
+ wxString const & title =
+ _T("wxLayout Printout"));
+
+ /// Destructor.
+ ~wxLayoutPrintout();
+
+ /** Function which prints the n-th page.
+ @param page the page number to print
+ @return bool true if we are not at end of document yet
+ */
+ bool OnPrintPage(int page);
+ /** Checks whether page exists in document.
+ @param page number of page
+ @return true if page exists
+ */
+ bool HasPage(int page);
+
+ /** Gets called from wxWindows to find out which pages are existing.
+ I'm not totally sure about the parameters though.
+ @param minPage the first page in the document
+ @param maxPage the last page in the document
+ @param selPageFrom the first page to be printed
+ @param selPageTo the last page to be printed
+ */
+ void GetPageInfo(int *minPage, int *maxPage,
+ int *selPageFrom, int *selPageTo);
protected:
- /** This little function scales the DC so that the printout has
- roughly the same size as the output on screen.
- @param dc the wxDC to scale
- @return the scale that was applied
- */
- float ScaleDC(wxDC *dc);
-
- /* no longer used
- virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
- */
+ /** This little function scales the DC so that the printout has
+ roughly the same size as the output on screen.
+ @param dc the wxDC to scale
+ @return the scale that was applied
+ */
+ float ScaleDC(wxDC *dc);
+
+ /* no longer used
+ virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
+ */
+
private:
- /// The list to print.
- wxLayoutList *m_llist;
- /// Title for PS file or window.
- wxString m_title;
- /// The real paper size.
- int m_PageHeight, m_PageWidth;
- /// How much we actually print per page.
- int m_PrintoutHeight;
- /// How many pages we need to print.
- int m_NumOfPages;
- /// Top left corner where we start printing.
- wxPoint m_Offset;
+ /// The list to print.
+ wxLayoutList *m_llist;
+
+ /// Title for PS file or window.
+ wxString m_title;
+
+ /// The real paper size.
+ int m_PageHeight, m_PageWidth;
+
+ /// How much we actually print per page.
+ int m_PrintoutHeight;
+
+ /// How many pages we need to print.
+ int m_NumOfPages;
+
+ /// Top left corner where we start printing.
+ wxPoint m_Offset;
};
// VZ: I still don't like it... the string data may be shared...
wxChar * cptr = (wxChar *)str.c_str(); // const_cast
const wxChar * begin = cptr;
+ wxUnusedVar(begin);
wxChar backup;
for(;;)
m_si = list->GetDefaultStyleInfo();
m_line = list->GetFirstLine();
m_iterator = m_line->GetFirstObject();
- m_FirstTime = TRUE;
+ m_FirstTime = true;
}
else
type = WXLO_TYPE_TEXT;
}
+ wxUnusedVar(type);
wxString *str = new wxString();
// text must be concatenated
*str += wxLayoutExportCmdAsHTML(
*(wxLayoutObjectCmd const *)*status->m_iterator,
& status->m_si, status->m_FirstTime);
- status->m_FirstTime = FALSE;
+ status->m_FirstTime = false;
break;
default: // ignore icons
;
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-# pragma hdrstop
+# pragma hdrstop
#endif
#include "Mpch.h"
#ifdef M_BASEDIR
# ifndef USE_PCH
-# include "Mcommon.h"
-# include "gui/wxMenuDefs.h"
-# include "gui/wxMApp.h"
+# include "Mcommon.h"
+# include "gui/wxMenuDefs.h"
+# include "gui/wxMApp.h"
# endif // USE_PCH
# include "gui/wxlwindow.h"
# include "gui/wxlparser.h"
# include "strutil.h"
#else
# ifdef __WXMSW__
-# include <wx/msw/private.h>
+# include "wx/msw/private.h"
# endif
# include "wxlwindow.h"
# include "wxlparser.h"
#endif
-#include <wx/clipbrd.h>
-#include <wx/textctrl.h>
-#include <wx/dataobj.h>
+#include "wx/clipbrd.h"
+#include "wx/textctrl.h"
+#include "wx/dataobj.h"
#ifdef WXLAYOUT_USE_CARET
-# include <wx/caret.h>
+# include "wx/caret.h"
#endif // WXLAYOUT_USE_CARET
#include <ctype.h>
// ----------------------------------------------------------------------------
#ifdef DEBUG
-# define WXLO_DEBUG(x) wxLogDebug x
+# define WXLO_DEBUG(x) wxLogDebug x
#else
-# define WXLO_DEBUG(x)
+# define WXLO_DEBUG(x)
#endif
// for profiling in debug mode:
// function prototypes
// ----------------------------------------------------------------------------
-/// returns TRUE if keyCode is one of arrows/home/end/page{up|down} keys
+/// returns true if keyCode is one of arrows/home/end/page{up|down} keys
static bool IsDirectionKey(long keyCode);
// ============================================================================
wxWANTS_CHARS),
m_llist(NULL)
{
- SetStatusBar(NULL); // don't use statusbar
- m_Editable = false;
- m_doSendEvents = false;
- m_ViewStartX = 0; m_ViewStartY = 0;
- m_DoPopupMenu = true;
- m_PopupMenu = MakeFormatMenu();
- m_memDC = new wxMemoryDC;
- m_bitmap = new wxBitmap(4,4);
- m_bitmapSize = wxPoint(4,4);
- m_llist = new wxLayoutList();
- m_BGbitmap = NULL;
- m_ScrollToCursor = false;
+ SetStatusBar(NULL); // don't use statusbar
+ m_Editable = false;
+ m_doSendEvents = false;
+ m_ViewStartX = 0; m_ViewStartY = 0;
+ m_DoPopupMenu = true;
+ m_PopupMenu = MakeFormatMenu();
+ m_memDC = new wxMemoryDC;
+ m_bitmap = new wxBitmap(4,4);
+ m_bitmapSize = wxPoint(4,4);
+ m_llist = new wxLayoutList();
+ m_BGbitmap = NULL;
+ m_ScrollToCursor = false;
#ifndef __WXMSW__
- m_FocusFollowMode = false;
+ m_FocusFollowMode = false;
#endif
- SetWordWrap(false);
- SetWrapMargin(0);
+ SetWordWrap(false);
+ SetWrapMargin(0);
- // no scrollbars initially
- m_hasHScrollbar =
- m_hasVScrollbar = false;
+ // no scrollbars initially
+ m_hasHScrollbar =
+ m_hasVScrollbar = false;
- m_Selecting = false;
+ m_Selecting = false;
#ifdef WXLAYOUT_USE_CARET
- // FIXME cursor size shouldn't be hardcoded
- wxCaret *caret = new wxCaret(this, 2, 20);
- SetCaret(caret);
- m_llist->SetCaret(caret);
+ // FIXME cursor size shouldn't be hardcoded
+ wxCaret *caret = new wxCaret(this, 2, 20);
+ SetCaret(caret);
+ m_llist->SetCaret(caret);
#endif // WXLAYOUT_USE_CARET
- m_HaveFocus = FALSE;
- m_HandCursor = FALSE;
- m_CursorVisibility = -1;
- SetCursor(wxCURSOR_IBEAM);
- SetDirty();
+ m_HaveFocus = false;
+ m_HandCursor = false;
+ m_CursorVisibility = -1;
+ SetCursor(wxCURSOR_IBEAM);
+ SetDirty();
- // at least under Windows, this should be the default behaviour
- m_AutoDeleteSelection = TRUE;
+ // at least under Windows, this should be the default behaviour
+ m_AutoDeleteSelection = true;
}
wxLayoutWindow::~wxLayoutWindow()
{
- delete m_memDC; // deletes bitmap automatically (?)
- delete m_bitmap;
- delete m_llist;
- delete m_PopupMenu;
- SetBackgroundBitmap(NULL);
+ delete m_memDC; // deletes bitmap automatically (?)
+ delete m_bitmap;
+ delete m_llist;
+ delete m_PopupMenu;
+ SetBackgroundBitmap(NULL);
}
void
wxLayoutWindow::Clear(int family,
- int size,
- int style,
- int weight,
- int underline,
- wxColour *fg,
- wxColour *bg)
+ int size,
+ int style,
+ int weight,
+ int underline,
+ wxColour *fg,
+ wxColour *bg)
{
- GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
- SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
- //wxScrolledWindow::Clear();
- ResizeScrollbars(true);
- SetDirty();
- SetModified(FALSE);
- if ( m_Editable )
- m_CursorVisibility = 1;
+ GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
+ SetBackgroundColour(GetLayoutList()->GetDefaultStyleInfo().GetBGColour());
+ //wxScrolledWindow::Clear();
+ ResizeScrollbars(true);
+ SetDirty();
+ SetModified(false);
+ if ( m_Editable )
+ m_CursorVisibility = 1;
#ifdef WXLAYOUT_USE_CARET
- if ( m_CursorVisibility == 1 )
- GetCaret()->Show();
+ if ( m_CursorVisibility == 1 )
+ GetCaret()->Show();
#endif // WXLAYOUT_USE_CARET
- RequestUpdate((wxRect *)NULL);
+ RequestUpdate((wxRect *)NULL);
}
void wxLayoutWindow::Refresh(bool eraseBackground, const wxRect *rect)
{
- wxScrolledWindow::Refresh(eraseBackground, rect);
+ wxScrolledWindow::Refresh(eraseBackground, rect);
}
void
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{
- wxClientDC dc( this );
- PrepareDC( dc );
- if ( (eventId != WXLOWIN_MENU_MOUSEMOVE
+ wxClientDC dc( this );
+ PrepareDC( dc );
+ if ( (eventId != WXLOWIN_MENU_MOUSEMOVE
#ifndef __WXMSW__
|| m_FocusFollowMode
#endif
- ) && (wxWindow::FindFocus() != this)
- )
- SetFocus();
-
- wxPoint findPos;
- findPos.x = dc.DeviceToLogicalX(event.GetX());
- findPos.y = dc.DeviceToLogicalY(event.GetY());
-
- findPos.x -= WXLO_XOFFSET;
- findPos.y -= WXLO_YOFFSET;
-
- if(findPos.x < 0)
- findPos.x = 0;
- if(findPos.y < 0)
- findPos.y = 0;
-
- m_ClickPosition = wxPoint(event.GetX(), event.GetY());
-
- // Scroll the window if the mouse is at the end of it:
- if(m_Selecting && eventId == WXLOWIN_MENU_MOUSEMOVE)
- {
- //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
- int left, top;
- GetViewStart(&left, &top);
- wxSize size = GetClientSize();
- int xdelta, ydelta;
-
- if(event.GetX() < WXLO_SCROLLMARGIN_X)
- xdelta = -(WXLO_SCROLLMARGIN_X-event.GetX());
- else if(event.GetX() > size.x-WXLO_SCROLLMARGIN_X)
- xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X;
- else
- xdelta = 0;
- if(event.GetY() < WXLO_SCROLLMARGIN_Y)
- ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY());
- else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y)
- ydelta = event.GetY()-size.y+WXLO_SCROLLMARGIN_Y;
- else
- ydelta = 0;
-
- //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
- if(xdelta != 0 || ydelta != 0)
- {
- top += ydelta; if(top < 0) top = 0;
- left += xdelta; if(left < 0) left = 0;
- Scroll(left, top);
- }
- }
-
- wxPoint cursorPos;
- bool found;
- wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos,
- &cursorPos, &found);
- wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL;
-
- // has the mouse only been moved?
- switch ( eventId )
- {
- case WXLOWIN_MENU_MOUSEMOVE:
- {
- // this variables is used to only erase the message in the status
- // bar if we had put it there previously - otherwise empting status
- // bar might be undesirable
- static bool s_hasPutMessageInStatusBar = false;
-
- // found is only true if we are really over an object, not just
- // behind it
- if(found && u && ! m_Selecting)
- {
- if(!m_HandCursor)
- SetCursor(wxCURSOR_HAND);
- m_HandCursor = TRUE;
- if(m_StatusBar && m_StatusFieldLabel != -1)
- {
- const wxString &label = u->GetLabel();
- if(label.Length())
+ )
+ && (wxWindow::FindFocus() != this) )
+ {
+ SetFocus();
+ }
+
+ wxPoint findPos;
+ findPos.x = dc.DeviceToLogicalX(event.GetX());
+ findPos.y = dc.DeviceToLogicalY(event.GetY());
+
+ findPos.x -= WXLO_XOFFSET;
+ findPos.y -= WXLO_YOFFSET;
+
+ if(findPos.x < 0)
+ findPos.x = 0;
+
+ if(findPos.y < 0)
+ findPos.y = 0;
+
+ m_ClickPosition = wxPoint(event.GetX(), event.GetY());
+
+ // Scroll the window if the mouse is at the end of it:
+ if(m_Selecting && eventId == WXLOWIN_MENU_MOUSEMOVE)
+ {
+ //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY()));
+ int left, top;
+ GetViewStart(&left, &top);
+ wxSize size = GetClientSize();
+ int xdelta, ydelta;
+
+ if(event.GetX() < WXLO_SCROLLMARGIN_X)
+ xdelta = -(WXLO_SCROLLMARGIN_X-event.GetX());
+ else if(event.GetX() > size.x-WXLO_SCROLLMARGIN_X)
+ xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X;
+ else
+ xdelta = 0;
+
+ if(event.GetY() < WXLO_SCROLLMARGIN_Y)
+ ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY());
+ else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y)
+ ydelta = event.GetY()-size.y+WXLO_SCROLLMARGIN_Y;
+ else
+ ydelta = 0;
+
+ //WXLO_DEBUG(("xdelta: %d", (int) xdelta));
+ if(xdelta != 0 || ydelta != 0)
+ {
+ top += ydelta; if(top < 0) top = 0;
+ left += xdelta; if(left < 0) left = 0;
+ Scroll(left, top);
+ }
+ }
+
+ wxPoint cursorPos;
+ bool found;
+ wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos,
+ &cursorPos, &found);
+ wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL;
+
+ // has the mouse only been moved?
+ switch ( eventId )
+ {
+ case WXLOWIN_MENU_MOUSEMOVE:
+ {
+ // this variables is used to only erase the message in the status
+ // bar if we had put it there previously - otherwise empting status
+ // bar might be undesirable
+ static bool s_hasPutMessageInStatusBar = false;
+
+ // found is only true if we are really over an object, not just
+ // behind it
+ if(found && u && ! m_Selecting)
+ {
+ if(!m_HandCursor)
+ SetCursor(wxCURSOR_HAND);
+ m_HandCursor = true;
+ if(m_StatusBar && m_StatusFieldLabel != -1)
{
- m_StatusBar->SetStatusText(label,
- m_StatusFieldLabel);
- s_hasPutMessageInStatusBar = true;
+ const wxString &label = u->GetLabel();
+ if(label.Length())
+ {
+ m_StatusBar->SetStatusText(label,
+ m_StatusFieldLabel);
+ s_hasPutMessageInStatusBar = true;
+ }
}
- }
- }
- else
- {
- if(m_HandCursor)
- SetCursor(wxCURSOR_IBEAM);
- m_HandCursor = FALSE;
- if( m_StatusBar && m_StatusFieldLabel != -1 &&
- s_hasPutMessageInStatusBar )
- {
- m_StatusBar->SetStatusText(wxEmptyString, m_StatusFieldLabel);
- }
- }
- }
-
- // selecting?
- if ( event.LeftIsDown() )
- {
- // m_Selecting might not be set if the button got pressed
- // outside this window, so check for it:
- if( m_Selecting )
- {
- m_llist->ContinueSelection(cursorPos, m_ClickPosition);
- RequestUpdate(); // TODO: we don't have to redraw everything!
- }
- }
-
- if ( u )
- {
- u->DecRef();
- u = NULL;
- }
- break;
-
- case WXLOWIN_MENU_LDOWN:
- {
- // always move cursor to mouse click:
- m_llist->MoveCursorTo(cursorPos);
-
- // clicking a mouse removes the selection
- if ( m_llist->HasSelection() )
- {
- m_llist->DiscardSelection();
- m_Selecting = false;
- RequestUpdate(); // TODO: we don't have to redraw everything!
- }
-
- // Calculate where the top of the visible area is:
- int x0, y0;
- GetViewStart(&x0,&y0);
- int dx, dy;
- GetScrollPixelsPerUnit(&dx, &dy);
- x0 *= dx; y0 *= dy;
-
- wxPoint offset(-x0+WXLO_XOFFSET, -y0+WXLO_YOFFSET);
-
- if(m_CursorVisibility == -1)
- m_CursorVisibility = 1;
+ }
+ else
+ {
+ if(m_HandCursor)
+ SetCursor(wxCURSOR_IBEAM);
+ m_HandCursor = false;
+ if( m_StatusBar && m_StatusFieldLabel != -1 &&
+ s_hasPutMessageInStatusBar )
+ {
+ m_StatusBar->SetStatusText(wxEmptyString, m_StatusFieldLabel);
+ }
+ }
+ }
+
+ // selecting?
+ if ( event.LeftIsDown() )
+ {
+ // m_Selecting might not be set if the button got pressed
+ // outside this window, so check for it:
+ if( m_Selecting )
+ {
+ m_llist->ContinueSelection(cursorPos, m_ClickPosition);
+ RequestUpdate(); // TODO: we don't have to redraw everything!
+ }
+ }
+
+ if ( u )
+ {
+ u->DecRef();
+ u = NULL;
+ }
+ break;
+
+ case WXLOWIN_MENU_LDOWN:
+ {
+ // always move cursor to mouse click:
+ m_llist->MoveCursorTo(cursorPos);
+
+ // clicking a mouse removes the selection
+ if ( m_llist->HasSelection() )
+ {
+ m_llist->DiscardSelection();
+ m_Selecting = false;
+ RequestUpdate(); // TODO: we don't have to redraw everything!
+ }
+
+ // Calculate where the top of the visible area is:
+ int x0, y0;
+ GetViewStart(&x0,&y0);
+ int dx, dy;
+ GetScrollPixelsPerUnit(&dx, &dy);
+ x0 *= dx; y0 *= dy;
+
+ wxPoint offset(-x0+WXLO_XOFFSET, -y0+WXLO_YOFFSET);
+
+ if(m_CursorVisibility == -1)
+ m_CursorVisibility = 1;
+
#ifdef WXLAYOUT_USE_CARET
- if ( m_CursorVisibility == 1 )
- GetCaret()->Show();
+ if ( m_CursorVisibility == 1 )
+ GetCaret()->Show();
#endif // WXLAYOUT_USE_CARET
- if(m_CursorVisibility)
- {
- // draw a thick cursor for editable windows with focus
- m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset);
- }
+ if(m_CursorVisibility)
+ {
+ // draw a thick cursor for editable windows with focus
+ m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset);
+ }
#ifdef __WXGTK__
- RequestUpdate(); // RequestUpdate suppresses flicker under GTK
+ RequestUpdate(); // RequestUpdate suppresses flicker under GTK
#endif // wxGTK
- // start selection
- m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition);
- m_Selecting = true;
- }
- break;
-
- case WXLOWIN_MENU_LUP:
- if ( m_Selecting )
- {
- // end selection at the cursor position corresponding to the
- // current mouse position, but don´t move cursor there.
- m_llist->EndSelection(cursorPos,m_ClickPosition);
- m_Selecting = false;
-
- RequestUpdate(); // TODO: we don't have to redraw everything!
- }
- break;
-
- case WXLOWIN_MENU_MDOWN:
- Paste(TRUE);
- break;
-
- case WXLOWIN_MENU_DBLCLICK:
- // select a word under cursor
- m_llist->MoveCursorTo(cursorPos);
- m_llist->MoveCursorWord(-1);
- m_llist->StartSelection();
- m_llist->MoveCursorWord(1, false);
- m_llist->EndSelection();
- m_Selecting = false;
- RequestUpdate(); // TODO: we don't have to redraw everything!
- break;
- }
-
- // notify about mouse events?
- if( m_doSendEvents )
- {
- // only do the menu if activated, editable and not on a clickable object
- if(eventId == WXLOWIN_MENU_RCLICK
- && IsEditable()
- && (! obj || u == NULL))
- {
- PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y);
- if(u) u->DecRef();
- return;
- }
-
- // find the object at this position
- if(obj)
- {
- wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
- commandEvent.SetEventObject( this );
- commandEvent.SetClientData((char *)obj);
- GetEventHandler()->ProcessEvent(commandEvent);
- }
- }
-
- if( u ) u->DecRef();
+ // start selection
+ m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition);
+ m_Selecting = true;
+ }
+ break;
+
+ case WXLOWIN_MENU_LUP:
+ if ( m_Selecting )
+ {
+ // end selection at the cursor position corresponding to the
+ // current mouse position, but don´t move cursor there.
+ m_llist->EndSelection(cursorPos,m_ClickPosition);
+ m_Selecting = false;
+
+ RequestUpdate(); // TODO: we don't have to redraw everything!
+ }
+ break;
+
+ case WXLOWIN_MENU_MDOWN:
+ Paste(true);
+ break;
+
+ case WXLOWIN_MENU_DBLCLICK:
+ // select a word under cursor
+ m_llist->MoveCursorTo(cursorPos);
+ m_llist->MoveCursorWord(-1);
+ m_llist->StartSelection();
+ m_llist->MoveCursorWord(1, false);
+ m_llist->EndSelection();
+ m_Selecting = false;
+ RequestUpdate(); // TODO: we don't have to redraw everything!
+ break;
+ }
+
+ // notify about mouse events?
+ if( m_doSendEvents )
+ {
+ // only do the menu if activated, editable and not on a clickable object
+ if(eventId == WXLOWIN_MENU_RCLICK
+ && IsEditable()
+ && (! obj || u == NULL))
+ {
+ PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y);
+ if(u) u->DecRef();
+ return;
+ }
+
+ // find the object at this position
+ if(obj)
+ {
+ wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
+ commandEvent.SetEventObject( this );
+ commandEvent.SetClientData((char *)obj);
+ GetEventHandler()->ProcessEvent(commandEvent);
+ }
+ }
+
+ if( u ) u->DecRef();
}
// ----------------------------------------------------------------------------
void
wxLayoutWindow::OnChar(wxKeyEvent& event)
{
- int keyCode = event.KeyCode();
- bool ctrlDown = event.ControlDown();
+ int keyCode = event.GetKeyCode();
+ bool ctrlDown = event.ControlDown();
#ifdef WXLAYOUT_DEBUG
- if(keyCode == WXK_F1)
- {
- m_llist->Debug();
- return;
- }
+ if(keyCode == WXK_F1)
+ {
+ m_llist->Debug();
+ return;
+ }
#endif
- // Force m_Selecting to be false if shift is no longer
- // pressed. OnKeyUp() cannot catch all Shift-Up events.
- if(m_Selecting && !event.ShiftDown())
- {
- m_Selecting = false;
- m_llist->EndSelection();
- m_llist->DiscardSelection(); //FIXME: correct?
- }
-
- // If we deleted the selection here, we must not execute the
- // deletion in Delete/Backspace handling.
- bool deletedSelection = false;
- // pressing any non-arrow key optionally replaces the selection:
- if(m_AutoDeleteSelection
- && IsEditable()
- && !m_Selecting
- && m_llist->HasSelection()
- && ! IsDirectionKey(keyCode)
- && ! (event.AltDown() || ctrlDown)
- )
- {
- m_llist->DeleteSelection();
- deletedSelection = true;
- SetDirty();
- }
-
- // <Shift>+<arrow> starts selection
- if ( IsDirectionKey(keyCode) )
- {
- // just continue the old selection
- if ( m_Selecting && event.ShiftDown() )
+ // Force m_Selecting to be false if shift is no longer
+ // pressed. OnKeyUp() cannot catch all Shift-Up events.
+ if(m_Selecting && !event.ShiftDown())
+ {
+ m_Selecting = false;
+ m_llist->EndSelection();
+ m_llist->DiscardSelection(); //FIXME: correct?
+ }
+
+ // If we deleted the selection here, we must not execute the
+ // deletion in Delete/Backspace handling.
+ bool deletedSelection = false;
+ // pressing any non-arrow key optionally replaces the selection:
+ if(m_AutoDeleteSelection
+ && IsEditable()
+ && !m_Selecting
+ && m_llist->HasSelection()
+ && ! IsDirectionKey(keyCode)
+ && ! (event.AltDown() || ctrlDown) )
+ {
+ m_llist->DeleteSelection();
+ deletedSelection = true;
+ SetDirty();
+ }
+
+ // <Shift>+<arrow> starts selection
+ if ( IsDirectionKey(keyCode) )
+ {
+ // just continue the old selection
+ if ( m_Selecting && event.ShiftDown() )
+ {
m_llist->ContinueSelection();
- else
- {
- m_llist->DiscardSelection();
- m_Selecting = false;
- if( event.ShiftDown() )
- {
- m_Selecting = true;
- m_llist->StartSelection();
- }
- }
- }
-
- // If needed, make cursor visible:
- if(m_CursorVisibility == -1)
- m_CursorVisibility = 1;
-
- /* These two nested switches work like this:
- The first one processes all non-editing keycodes, to move the
- cursor, etc. It's default will process all keycodes causing
- modifications to the buffer, but only if editing is allowed.
- */
- switch(keyCode)
- {
- case WXK_RIGHT:
- if ( ctrlDown )
- m_llist->MoveCursorWord(1);
- else
- m_llist->MoveCursorHorizontally(1);
- break;
- case WXK_LEFT:
- if ( ctrlDown )
- m_llist->MoveCursorWord(-1);
- else
- m_llist->MoveCursorHorizontally(-1);
- break;
- case WXK_UP:
- m_llist->MoveCursorVertically(-1);
- break;
- case WXK_DOWN:
- m_llist->MoveCursorVertically(1);
- break;
- case WXK_PRIOR:
- m_llist->MoveCursorVertically(-Y_SCROLL_PAGE);
- break;
- case WXK_NEXT:
- m_llist->MoveCursorVertically(Y_SCROLL_PAGE);
- break;
- case WXK_HOME:
- if ( ctrlDown )
- m_llist->MoveCursorTo(wxPoint(0, 0));
- else
- m_llist->MoveCursorToBeginOfLine();
- break;
- case WXK_END:
- if ( ctrlDown )
- m_llist->MoveCursorToEnd();
- else
- m_llist->MoveCursorToEndOfLine();
- break;
- default:
-
- if(ctrlDown && ! IsEditable())
- switch(keyCode)
- {
- case 'c':
- // this should work even in read-only mode
- Copy(TRUE, TRUE);
- break;
- case 's': // search
- Find(wxEmptyString);
- break;
- case 't': // search again
- FindAgain();
- break;
- default:
- // we don't handle it, maybe an accelerator?
- event.Skip();
- ;
- }
- else if( IsEditable() )
- {
- /* First, handle control keys */
- if(ctrlDown && ! event.AltDown())
- {
- if(keyCode >= 'A' && keyCode <= 'Z')
- keyCode = tolower(keyCode);
+ }
+ else
+ {
+ m_llist->DiscardSelection();
+ m_Selecting = false;
+ if( event.ShiftDown() )
+ {
+ m_Selecting = true;
+ m_llist->StartSelection();
+ }
+ }
+ }
+
+ // If needed, make cursor visible:
+ if(m_CursorVisibility == -1)
+ m_CursorVisibility = 1;
+
+ /* These two nested switches work like this:
+ The first one processes all non-editing keycodes, to move the
+ cursor, etc. It's default will process all keycodes causing
+ modifications to the buffer, but only if editing is allowed.
+ */
+ switch(keyCode)
+ {
+
+ case WXK_RIGHT:
+ if ( ctrlDown )
+ m_llist->MoveCursorWord(1);
+ else
+ m_llist->MoveCursorHorizontally(1);
+ break;
+
+ case WXK_LEFT:
+ if ( ctrlDown )
+ m_llist->MoveCursorWord(-1);
+ else
+ m_llist->MoveCursorHorizontally(-1);
+
+ break;
+
+ case WXK_UP:
+ m_llist->MoveCursorVertically(-1);
+ break;
+
+ case WXK_DOWN:
+ m_llist->MoveCursorVertically(1);
+ break;
+
+ case WXK_PRIOR:
+ m_llist->MoveCursorVertically(-Y_SCROLL_PAGE);
+ break;
+
+ case WXK_NEXT:
+ m_llist->MoveCursorVertically(Y_SCROLL_PAGE);
+ break;
+
+ case WXK_HOME:
+ if ( ctrlDown )
+ m_llist->MoveCursorTo(wxPoint(0, 0));
+ else
+ m_llist->MoveCursorToBeginOfLine();
+ break;
+
+ case WXK_END:
+ if ( ctrlDown )
+ m_llist->MoveCursorToEnd();
+ else
+ m_llist->MoveCursorToEndOfLine();
+ break;
+
+ default:
+
+ if(ctrlDown && ! IsEditable())
+ {
switch(keyCode)
{
- case WXK_INSERT:
- Copy();
- break;
- case WXK_DELETE :
- if(! deletedSelection)
- {
- m_llist->DeleteWord();
- SetDirty();
- }
- break;
- case 'd':
- if(! deletedSelection) // already done
- {
- m_llist->Delete(1);
- SetDirty();
- }
- break;
- case 'y':
- m_llist->DeleteLines(1);
- SetDirty();
- break;
- case 'h': // like backspace
- if(m_llist->MoveCursorHorizontally(-1))
- {
- m_llist->Delete(1);
- SetDirty();
- }
- break;
+
+ case 'c':
+ // this should work even in read-only mode
+ Copy(true, true);
+ break;
+
case 's': // search
- Find(wxEmptyString);
- break;
+ Find(wxEmptyString);
+ break;
+
case 't': // search again
- FindAgain();
- break;
- case 'u':
- m_llist->DeleteToBeginOfLine();
- SetDirty();
- break;
- case 'k':
- m_llist->DeleteToEndOfLine();
- SetDirty();
- break;
- case 'c':
- Copy(TRUE, TRUE);
- break;
- case 'v':
- Paste( TRUE );
- break;
- case 'x':
- Cut();
- break;
- case 'w':
- if(m_WrapMargin > 0)
- m_llist->WrapLine(m_WrapMargin);
- break;
- case 'q':
- if(m_WrapMargin > 0)
- m_llist->WrapAll(m_WrapMargin);
- break;
+ FindAgain();
+ break;
+
+ default:
+ // we don't handle it, maybe an accelerator?
+ event.Skip();
+ ;
+ }
+ }
+ else if( IsEditable() )
+ {
+ /* First, handle control keys */
+ if(ctrlDown && ! event.AltDown())
+ {
+ if(keyCode >= 'A' && keyCode <= 'Z')
+ keyCode = tolower(keyCode);
+
+ switch(keyCode)
+ {
+
+ case WXK_INSERT:
+ Copy();
+ break;
+
+ case WXK_DELETE :
+ if(! deletedSelection)
+ {
+ m_llist->DeleteWord();
+ SetDirty();
+ }
+ break;
+
+ case 'd':
+ if(! deletedSelection) // already done
+ {
+ m_llist->Delete(1);
+ SetDirty();
+ }
+ break;
+
+ case 'y':
+ m_llist->DeleteLines(1);
+ SetDirty();
+ break;
+
+ case 'h': // like backspace
+ if(m_llist->MoveCursorHorizontally(-1))
+ {
+ m_llist->Delete(1);
+ SetDirty();
+ }
+ break;
+
+ case 's': // search
+ Find(wxEmptyString);
+ break;
+
+ case 't': // search again
+ FindAgain();
+ break;
+
+ case 'u':
+ m_llist->DeleteToBeginOfLine();
+ SetDirty();
+ break;
+
+ case 'k':
+ m_llist->DeleteToEndOfLine();
+ SetDirty();
+ break;
+
+ case 'c':
+ Copy(true, true);
+ break;
+
+ case 'v':
+ Paste(true);
+ break;
+
+ case 'x':
+ Cut();
+ break;
+
+ case 'w':
+ if(m_WrapMargin > 0)
+ m_llist->WrapLine(m_WrapMargin);
+ break;
+
+ case 'q':
+ if(m_WrapMargin > 0)
+ m_llist->WrapAll(m_WrapMargin);
+ break;
+
#ifdef WXLAYOUT_DEBUG
- case WXK_F1:
- m_llist->SetFont(-1,-1,-1,-1,true); // underlined
- break;
- case 'l':
- Refresh(TRUE);
- break;
+ case WXK_F1:
+ m_llist->SetFont(-1,-1,-1,-1,true); // underlined
+ break;
+
+ case 'l':
+ Refresh(true);
+ break;
#endif
- default:
- // we don't handle it, maybe an accelerator?
- event.Skip();
+
+ default:
+ // we don't handle it, maybe an accelerator?
+ event.Skip();
+ }
}
- }
- // ALT only:
- else if( event.AltDown() && ! event.ControlDown() )
- {
- switch(keyCode)
+ // ALT only:
+ else if( event.AltDown() && ! event.ControlDown() )
{
- case WXK_DELETE:
- case 'd':
- m_llist->DeleteWord();
- SetDirty();
- break;
- default:
- // we don't handle it, maybe an accelerator?
- event.Skip();
+ switch(keyCode)
+ {
+ case WXK_DELETE:
+ case 'd':
+ m_llist->DeleteWord();
+ SetDirty();
+ break;
+
+ default:
+ // we don't handle it, maybe an accelerator?
+ event.Skip();
+ }
}
- }
- // no control keys:
- else if ( ! event.AltDown() && ! event.ControlDown())
- {
- switch(keyCode)
+ // no control keys:
+ else if ( ! event.AltDown() && ! event.ControlDown())
{
- case WXK_INSERT:
- if(event.ShiftDown())
- Paste();
- break;
- case WXK_DELETE :
- if(event.ShiftDown())
- Cut();
- else
- if(! deletedSelection)
- {
- m_llist->Delete(1);
- SetDirty();
- }
- break;
- case WXK_BACK: // backspace
- if(! deletedSelection)
- if(m_llist->MoveCursorHorizontally(-1))
- {
- m_llist->Delete(1);
- SetDirty();
- }
- break;
- case WXK_RETURN:
- if(m_DoWordWrap &&
- m_WrapMargin > 0
- && m_llist->GetCursorPos().x > m_WrapMargin)
- m_llist->WrapLine(m_WrapMargin);
- m_llist->LineBreak();
- SetDirty();
- break;
-
- case WXK_TAB:
- if ( !event.ShiftDown() )
- {
- // TODO should be configurable
- static const int tabSize = 8;
-
- CoordType x = m_llist->GetCursorPos().x;
- size_t numSpaces = tabSize - x % tabSize;
- m_llist->Insert(wxString(' ', numSpaces));
- SetDirty();
- }
- break;
-
- default:
- if((!(event.ControlDown() || event.AltDown()
- ))
- && (keyCode < 256 && keyCode >= 32)
- )
- {
- if(m_DoWordWrap
- && m_WrapMargin > 0
- && m_llist->GetCursorPos().x > m_WrapMargin
- && isspace(keyCode))
- {
- m_llist->WrapLine(m_WrapMargin);
- }
-
- m_llist->Insert((wxChar)keyCode);
- SetDirty();
- }
- else
- // we don't handle it, maybe an accelerator?
- event.Skip();
- break;
+ switch(keyCode)
+ {
+ case WXK_INSERT:
+ if(event.ShiftDown())
+ Paste();
+ break;
+
+ case WXK_DELETE :
+ if(event.ShiftDown())
+ {
+ Cut();
+ }
+ else if(! deletedSelection)
+ {
+ m_llist->Delete(1);
+ SetDirty();
+ }
+ break;
+
+ case WXK_BACK: // backspace
+ if(! deletedSelection)
+ {
+ if(m_llist->MoveCursorHorizontally(-1))
+ {
+ m_llist->Delete(1);
+ SetDirty();
+ }
+ }
+ break;
+
+ case WXK_RETURN:
+ if (m_DoWordWrap &&
+ m_WrapMargin > 0
+ && m_llist->GetCursorPos().x > m_WrapMargin )
+ {
+ m_llist->WrapLine(m_WrapMargin);
+ }
+
+ m_llist->LineBreak();
+ SetDirty();
+ break;
+
+ case WXK_TAB:
+ if ( !event.ShiftDown() )
+ {
+ // TODO should be configurable
+ static const int tabSize = 8;
+
+ CoordType x = m_llist->GetCursorPos().x;
+ size_t numSpaces = tabSize - x % tabSize;
+ m_llist->Insert(wxString(' ', numSpaces));
+ SetDirty();
+ }
+ break;
+
+ default:
+ if ( ( !(event.ControlDown() || event.AltDown()) )
+ && (keyCode < 256 && keyCode >= 32) )
+ {
+ if ( m_DoWordWrap
+ && m_WrapMargin > 0
+ && m_llist->GetCursorPos().x > m_WrapMargin
+ && isspace(keyCode) )
+ {
+ m_llist->WrapLine(m_WrapMargin);
+ }
+
+ m_llist->Insert((wxChar)keyCode);
+ SetDirty();
+ }
+ else
+ {
+ // we don't handle it, maybe an accelerator?
+ event.Skip();
+ }
+ break;
+ }
+
}
- }
- }// if(IsEditable())
- else
- // we don't handle it, maybe an accelerator?
- event.Skip();
- }// first switch()
-
- if ( m_Selecting )
- {
- // continue selection to the current (new) cursor position
- m_llist->ContinueSelection();
- }
- ScrollToCursor();
- // refresh the screen
- RequestUpdate(m_llist->GetUpdateRect());
+ }// if(IsEditable())
+ else
+ {
+ // we don't handle it, maybe an accelerator?
+ event.Skip();
+ }
+ }// first switch()
+
+ if ( m_Selecting )
+ {
+ // continue selection to the current (new) cursor position
+ m_llist->ContinueSelection();
+ }
+
+ ScrollToCursor();
+ // refresh the screen
+ RequestUpdate(m_llist->GetUpdateRect());
}
void
wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
{
- if ( event.KeyCode() == WXK_SHIFT && m_Selecting )
- {
- m_llist->EndSelection();
- m_Selecting = false;
- }
+ if ( event.GetKeyCode() == WXK_SHIFT && m_Selecting )
+ {
+ m_llist->EndSelection();
+ m_Selecting = false;
+ }
- event.Skip();
+ event.Skip();
}
void
-wxLayoutWindow::ScrollToCursor(void)
+wxLayoutWindow::ScrollToCursor()
{
- //is always needed to make sure we know where the cursor is
- //if(IsDirty())
- //RequestUpdate(m_llist->GetUpdateRect());
-
-
- ResizeScrollbars();
-
- int x0,y0,x1,y1, dx, dy;
-
- // Calculate where the top of the visible area is:
- GetViewStart(&x0,&y0);
- GetScrollPixelsPerUnit(&dx, &dy);
- x0 *= dx; y0 *= dy;
-
- WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0, y0));
-
- // Get the size of the visible window:
- GetClientSize(&x1, &y1);
-
- // Make sure that the scrollbars are at a position so that the cursor is
- // visible if we are editing
- WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor));
- wxPoint cc = m_llist->GetCursorScreenPos();
-
- // the cursor should be completely visible in both directions
- wxPoint cs(m_llist->GetCursorSize());
- int nx = -1,
- ny = -1;
- if ( cc.x < x0 || cc.x >= x0 + x1 - cs.x )
- {
- nx = cc.x - x1/2;
- if ( nx < 0 )
- nx = 0;
- }
-
- if ( cc.y < y0 || cc.y >= y0 + y1 - cs.y )
- {
- ny = cc.y - y1/2;
- if ( ny < 0)
- ny = 0;
- }
-
- if( nx != -1 || ny != -1 )
- {
- // set new view start
- Scroll(nx == -1 ? -1 : (nx+dx-1)/dx, ny == -1 ? -1 : (ny+dy-1)/dy);
- // avoid recursion
- m_ScrollToCursor = false;
- RequestUpdate();
- }
+ //is always needed to make sure we know where the cursor is
+ //if(IsDirty())
+ //RequestUpdate(m_llist->GetUpdateRect());
+
+
+ ResizeScrollbars();
+
+ int x0,y0,x1,y1, dx, dy;
+
+ // Calculate where the top of the visible area is:
+ GetViewStart(&x0,&y0);
+ GetScrollPixelsPerUnit(&dx, &dy);
+ x0 *= dx; y0 *= dy;
+
+ WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0, y0));
+
+ // Get the size of the visible window:
+ GetClientSize(&x1, &y1);
+
+ // Make sure that the scrollbars are at a position so that the cursor is
+ // visible if we are editing
+ WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor));
+ wxPoint cc = m_llist->GetCursorScreenPos();
+
+ // the cursor should be completely visible in both directions
+ wxPoint cs(m_llist->GetCursorSize());
+ int nx = -1,
+ ny = -1;
+
+ if ( cc.x < x0 || cc.x >= x0 + x1 - cs.x )
+ {
+ nx = cc.x - x1/2;
+ if ( nx < 0 )
+ nx = 0;
+ }
+
+ if ( cc.y < y0 || cc.y >= y0 + y1 - cs.y )
+ {
+ ny = cc.y - y1/2;
+ if ( ny < 0)
+ ny = 0;
+ }
+
+ if( nx != -1 || ny != -1 )
+ {
+ // set new view start
+ Scroll(nx == -1 ? -1 : (nx+dx-1)/dx, ny == -1 ? -1 : (ny+dy-1)/dy);
+ // avoid recursion
+ m_ScrollToCursor = false;
+ RequestUpdate();
+ }
}
void
wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event))
{
- wxRect region = GetUpdateRegion().GetBox();
- InternalPaint(®ion);
+ wxRect region = GetUpdateRegion().GetBox();
+ InternalPaint(®ion);
}
void
wxLayoutWindow::RequestUpdate(const wxRect *
- #ifdef __WXGTK__
- updateRect
- #else
- WXUNUSED(updateRect)
- #endif
- )
+#ifdef __WXGTK__
+ updateRect
+#else
+ WXUNUSED(updateRect)
+#endif
+)
{
#ifdef __WXGTK__
- // Calling Refresh() causes bad flicker under wxGTK!!!
- InternalPaint(updateRect);
+ // Calling Refresh() causes bad flicker under wxGTK!!!
+ InternalPaint(updateRect);
#else
- // shouldn't specify the update rectangle if it doesn't include all the
- // changed locations - otherwise, they won't be repainted at all because
- // the system clips the display to the update rect
- Refresh(FALSE); //, updateRect);
+ // shouldn't specify the update rectangle if it doesn't include all the
+ // changed locations - otherwise, they won't be repainted at all because
+ // the system clips the display to the update rect
+ Refresh(false); //, updateRect);
#endif
}
wxLayoutWindow::InternalPaint(const wxRect *updateRect)
{
- wxPaintDC dc( this );
- PrepareDC( dc );
+ wxPaintDC dc( this );
+ PrepareDC( dc );
#ifdef WXLAYOUT_USE_CARET
- // hide the caret before drawing anything
- GetCaret()->Hide();
+ // hide the caret before drawing anything
+ GetCaret()->Hide();
#endif // WXLAYOUT_USE_CARET
- int x0,y0,x1,y1, dx, dy;
-
- // Calculate where the top of the visible area is:
- GetViewStart(&x0,&y0);
- GetScrollPixelsPerUnit(&dx, &dy);
- x0 *= dx; y0 *= dy;
-
- // Get the size of the visible window:
- GetClientSize(&x1,&y1);
- wxASSERT(x1 >= 0);
- wxASSERT(y1 >= 0);
-
- if(updateRect)
- {
- WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
- updateRect->x, updateRect->y,
- updateRect->x+updateRect->width,
- updateRect->y+updateRect->height));
- }
-
- ResizeScrollbars(true);
-
- WXLO_TIMER_START(TmpTimer);
- /* Check whether the window has grown, if so, we need to reallocate
- the bitmap to be larger. */
- 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->SetBackground(wxBrush(m_llist->GetDefaultStyleInfo().GetBGColour(),wxSOLID));
- m_memDC->SetPen(wxPen(m_llist->GetDefaultStyleInfo().GetBGColour(),
- 0,wxTRANSPARENT));
- m_memDC->SetLogicalFunction(wxCOPY);
- m_memDC->Clear();
- WXLO_TIMER_STOP(TmpTimer);
-
- // fill the background with the background bitmap
- if(m_BGbitmap)
- {
- CoordType
- y, x,
- w = m_BGbitmap->GetWidth(),
- h = m_BGbitmap->GetHeight();
- for(y = 0; y < y1; y+=h)
- for(x = 0; x < x1; x+=w)
- m_memDC->DrawBitmap(*m_BGbitmap, x, y);
- m_memDC->SetBackgroundMode(wxTRANSPARENT);
- }
-
- // This is the important bit: we tell the list to draw itself
+ int x0,y0,x1,y1, dx, dy;
+
+ // Calculate where the top of the visible area is:
+ GetViewStart(&x0,&y0);
+ GetScrollPixelsPerUnit(&dx, &dy);
+ x0 *= dx; y0 *= dy;
+
+ // Get the size of the visible window:
+ GetClientSize(&x1,&y1);
+ wxASSERT(x1 >= 0);
+ wxASSERT(y1 >= 0);
+
+ if(updateRect)
+ {
+ WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
+ updateRect->x, updateRect->y,
+ updateRect->x+updateRect->width,
+ updateRect->y+updateRect->height));
+ }
+
+ ResizeScrollbars(true);
+
+ WXLO_TIMER_START(TmpTimer);
+ /* Check whether the window has grown, if so, we need to reallocate
+ the bitmap to be larger. */
+ 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->SetBackground(wxBrush(m_llist->GetDefaultStyleInfo().GetBGColour(),wxSOLID));
+ m_memDC->SetPen(wxPen(m_llist->GetDefaultStyleInfo().GetBGColour(),
+ 0,wxTRANSPARENT));
+ m_memDC->SetLogicalFunction(wxCOPY);
+ m_memDC->Clear();
+ WXLO_TIMER_STOP(TmpTimer);
+
+ // fill the background with the background bitmap
+ if(m_BGbitmap)
+ {
+ CoordType
+ y, x,
+ w = m_BGbitmap->GetWidth(),
+ h = m_BGbitmap->GetHeight();
+ for(y = 0; y < y1; y+=h)
+ {
+ for(x = 0; x < x1; x+=w)
+ {
+ m_memDC->DrawBitmap(*m_BGbitmap, x, y);
+ }
+ }
+
+ m_memDC->SetBackgroundMode(wxTRANSPARENT);
+ }
+
+ // This is the important bit: we tell the list to draw itself
#if WXLO_DEBUG_URECT
- if(updateRect)
- {
- WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
- updateRect->x, updateRect->y,
- updateRect->x+updateRect->width,
- updateRect->y+updateRect->height));
- }
+ if(updateRect)
+ {
+ WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld",
+ updateRect->x, updateRect->y,
+ updateRect->x+updateRect->width,
+ updateRect->y+updateRect->height));
+ }
#endif
- // Device origins on the memDC are suspect, we translate manually
- // with the translate parameter of Draw().
- wxPoint offset(-x0+WXLO_XOFFSET,-y0+WXLO_YOFFSET);
- m_llist->Draw(*m_memDC,offset, y0, y0+y1);
-
- // We start calculating a new update rect before drawing the
- // cursor, so that the cursor coordinates get included in the next
- // update rectangle (although they are drawn on the memDC, this is
- // needed to erase it):
- m_llist->InvalidateUpdateRect();
- if(m_CursorVisibility == 1)
- {
- // draw a thick cursor for editable windows with focus
- m_llist->DrawCursor(*m_memDC,
- m_HaveFocus && IsEditable(),
- offset);
- }
-
- WXLO_TIMER_START(BlitTimer);
+ // Device origins on the memDC are suspect, we translate manually
+ // with the translate parameter of Draw().
+ wxPoint offset(-x0+WXLO_XOFFSET,-y0+WXLO_YOFFSET);
+ m_llist->Draw(*m_memDC,offset, y0, y0+y1);
+
+ // We start calculating a new update rect before drawing the
+ // cursor, so that the cursor coordinates get included in the next
+ // update rectangle (although they are drawn on the memDC, this is
+ // needed to erase it):
+ m_llist->InvalidateUpdateRect();
+ if(m_CursorVisibility == 1)
+ {
+ // draw a thick cursor for editable windows with focus
+ m_llist->DrawCursor(*m_memDC,
+ m_HaveFocus && IsEditable(),
+ offset);
+ }
+
+ WXLO_TIMER_START(BlitTimer);
// Now copy everything to the screen:
#if 0
- // This somehow doesn't work, but even the following bit with the
- // whole rect at once is still a bit broken I think.
- wxRegionIterator ri ( GetUpdateRegion() );
- if(ri)
- while(ri)
- {
- WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
- ri.GetX(),ri.GetY(),ri.GetW(),ri.GetH()));
- dc.Blit(x0+ri.GetX(),y0+ri.GetY(),ri.GetW(),ri.GetH(),
- m_memDC,ri.GetX(),ri.GetY(),wxCOPY,FALSE);
- ri++;
- }
- else
+ // This somehow doesn't work, but even the following bit with the
+ // whole rect at once is still a bit broken I think.
+ wxRegionIterator ri ( GetUpdateRegion() );
+ if(ri)
+ while(ri)
+ {
+ WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
+ ri.GetX(),ri.GetY(),ri.GetW(),ri.GetH()));
+
+ dc.Blit(x0+ri.GetX(),y0+ri.GetY(),ri.GetW(),ri.GetH(),
+ m_memDC,ri.GetX(),ri.GetY(),wxCOPY,false);
+ ri++;
+ }
+ else
#endif
- {
- // FIXME: Trying to copy only the changed parts, but it does not seem
- // to work:
+ {
+ // FIXME: Trying to copy only the changed parts, but it does not seem
+ // to work:
// x0 = updateRect->x; y0 = updateRect->y;
// if(updateRect->height < y1)
// y1 = updateRect->height;
// y1 += WXLO_YOFFSET; //FIXME might not be needed
- dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
- }
- WXLO_TIMER_STOP(BlitTimer);
+ dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,false);
+ }
+
+ WXLO_TIMER_STOP(BlitTimer);
#ifdef WXLAYOUT_USE_CARET
- // show the caret back after everything is redrawn
- GetCaret()->Show();
+ // show the caret back after everything is redrawn
+ GetCaret()->Show();
#endif // WXLAYOUT_USE_CARET
- ResetDirty();
+ ResetDirty();
- if ( m_StatusBar && m_StatusFieldCursor != -1 )
- {
- static wxPoint s_oldCursorPos(-1, -1);
+ if ( m_StatusBar && m_StatusFieldCursor != -1 )
+ {
+ static wxPoint s_oldCursorPos(-1, -1);
- wxPoint pos(m_llist->GetCursorPos());
+ wxPoint pos(m_llist->GetCursorPos());
- // avoid unnecessary status bar refreshes
- if ( pos != s_oldCursorPos )
- {
- s_oldCursorPos = pos;
+ // avoid unnecessary status bar refreshes
+ if ( pos != s_oldCursorPos )
+ {
+ s_oldCursorPos = pos;
- wxString label;
- label.Printf(_("Ln:%d Col:%d"), pos.y + 1, pos.x + 1);
- m_StatusBar->SetStatusText(label, m_StatusFieldCursor);
- }
- }
+ wxString label;
+ label.Printf(_("Ln:%d Col:%d"), pos.y + 1, pos.x + 1);
+ m_StatusBar->SetStatusText(label, m_StatusFieldCursor);
+ }
+ }
- WXLO_TIMER_PRINT(LayoutTimer);
- WXLO_TIMER_PRINT(BlitTimer);
- WXLO_TIMER_PRINT(TmpTimer);
+ WXLO_TIMER_PRINT(LayoutTimer);
+ WXLO_TIMER_PRINT(BlitTimer);
+ WXLO_TIMER_PRINT(TmpTimer);
}
void
wxLayoutWindow::OnSize(wxSizeEvent &event)
{
- if ( m_llist )
- ResizeScrollbars();
+ if ( m_llist )
+ ResizeScrollbars();
- event.Skip();
+ event.Skip();
}
/*
Change the range and position of scrollbars. Has evolved into a
generic Update function which will at some time later cause a repaint
-as needed.
+as needed.
*/
void
wxLayoutWindow::ResizeScrollbars(bool exact)
{
- wxClientDC dc( this );
- PrepareDC( dc );
+ wxClientDC dc( this );
+ PrepareDC( dc );
// m_llist->ForceTotalLayout();
- if(! IsDirty())
- {
- // we are laying out just the minimum, but always up to the
- // cursor line, so the cursor position is updated.
- m_llist->Layout(dc, 0);
- return;
- }
- WXLO_TIMER_START(LayoutTimer);
- m_llist->Layout(dc, -1);
- WXLO_TIMER_STOP(LayoutTimer);
- ResetDirty();
-
- wxPoint max = m_llist->GetSize();
- wxSize size = GetClientSize();
-
- WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
- (long int)max.x, (long int) max.y));
-
- // in the absence of scrollbars we should compare with the client size
- if ( !m_hasHScrollbar )
- m_maxx = size.x;// - WXLO_ROFFSET;
- if ( !m_hasVScrollbar )
- m_maxy = size.y;// - WXLO_BOFFSET;
-
- // check if the text hasn't become too big
- // TODO why do we set both at once? they're independent...
- if( max.x > m_maxx - WXLO_ROFFSET
- || max.y > m_maxy - WXLO_BOFFSET
- || (max.x < m_maxx - X_SCROLL_PAGE)
- || (max.y < m_maxy - Y_SCROLL_PAGE)
- || exact )
- {
- // text became too large
- if ( !exact )
- {
- // add an extra bit to the sizes to avoid future updates
- max.x += WXLO_ROFFSET;
- max.y += WXLO_BOFFSET;
- }
-
- bool done = FALSE;
- if(max.x < X_SCROLL_PAGE && m_hasHScrollbar)
- {
- SetScrollbars(0,-1,0,-1,0,-1,true);
- m_hasHScrollbar = FALSE;
- done = TRUE;
- }
- if(max.y < Y_SCROLL_PAGE && m_hasVScrollbar)
- {
- SetScrollbars(-1,0,-1,0,-1,0,true);
- m_hasVScrollbar = FALSE;
- done = TRUE;
- }
- if(! done &&
+ if(! IsDirty())
+ {
+ // we are laying out just the minimum, but always up to the
+ // cursor line, so the cursor position is updated.
+ m_llist->Layout(dc, 0);
+ return;
+ }
+
+ WXLO_TIMER_START(LayoutTimer);
+ m_llist->Layout(dc, -1);
+ WXLO_TIMER_STOP(LayoutTimer);
+ ResetDirty();
+
+ wxPoint max = m_llist->GetSize();
+ wxSize size = GetClientSize();
+
+ WXLO_DEBUG(("ResizeScrollbars: max size = (%ld, %ld)",
+ (long int)max.x, (long int) max.y));
+
+ // in the absence of scrollbars we should compare with the client size
+ if ( !m_hasHScrollbar )
+ m_maxx = size.x;// - WXLO_ROFFSET;
+
+ if ( !m_hasVScrollbar )
+ m_maxy = size.y;// - WXLO_BOFFSET;
+
+ // check if the text hasn't become too big
+ // TODO why do we set both at once? they're independent...
+ if( max.x > m_maxx - WXLO_ROFFSET
+ || max.y > m_maxy - WXLO_BOFFSET
+ || (max.x < m_maxx - X_SCROLL_PAGE)
+ || (max.y < m_maxy - Y_SCROLL_PAGE)
+ || exact )
+ {
+ // text became too large
+ if ( !exact )
+ {
+ // add an extra bit to the sizes to avoid future updates
+ max.x += WXLO_ROFFSET;
+ max.y += WXLO_BOFFSET;
+ }
+
+ bool done = false;
+
+ if(max.x < X_SCROLL_PAGE && m_hasHScrollbar)
+ {
+ SetScrollbars(0,-1,0,-1,0,-1,true);
+ m_hasHScrollbar = false;
+ done = true;
+ }
+
+ if(max.y < Y_SCROLL_PAGE && m_hasVScrollbar)
+ {
+ SetScrollbars(-1,0,-1,0,-1,0,true);
+ m_hasVScrollbar = false;
+ done = true;
+ }
+
+ if (! done &&
// (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE)
- (max.x > size.x - X_SCROLL_PAGE|| max.y > size.y - Y_SCROLL_PAGE)
- )
- {
- GetViewStart(&m_ViewStartX, &m_ViewStartY);
- SetScrollbars(X_SCROLL_PAGE,
- Y_SCROLL_PAGE,
- max.x / X_SCROLL_PAGE + 2,
- max.y / Y_SCROLL_PAGE + 2,
- m_ViewStartX,
- m_ViewStartY,
- true);
- m_hasHScrollbar =
+ (max.x > size.x - X_SCROLL_PAGE|| max.y > size.y - Y_SCROLL_PAGE) )
+ {
+ GetViewStart(&m_ViewStartX, &m_ViewStartY);
+
+ SetScrollbars(X_SCROLL_PAGE,
+ Y_SCROLL_PAGE,
+ max.x / X_SCROLL_PAGE + 2,
+ max.y / Y_SCROLL_PAGE + 2,
+ m_ViewStartX,
+ m_ViewStartY,
+ true);
+
+ m_hasHScrollbar =
m_hasVScrollbar = true;
// ScrollToCursor();
- }
-
- m_maxx = max.x + X_SCROLL_PAGE;
- m_maxy = max.y + Y_SCROLL_PAGE;
- }
+ }
+
+ m_maxx = max.x + X_SCROLL_PAGE;
+ m_maxy = max.y + Y_SCROLL_PAGE;
+ }
}
// ----------------------------------------------------------------------------
void
wxLayoutWindow::Paste(bool usePrivate, bool primary)
{
- // this only has an effect under X11:
- wxTheClipboard->UsePrimarySelection(primary);
- // Read some text
- if (wxTheClipboard->Open())
- {
- if(usePrivate)
- {
- wxLayoutDataObject wxldo;
- if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
- {
- if(wxTheClipboard->GetData(wxldo))
+ // this only has an effect under X11:
+ wxTheClipboard->UsePrimarySelection(primary);
+ // Read some text
+ if (wxTheClipboard->Open())
+ {
+ if(usePrivate)
+ {
+ wxLayoutDataObject wxldo;
+ if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
{
- wxTheClipboard->Close();
- wxString str = wxldo.GetLayoutData();
- m_llist->Read(str);
- SetDirty();
- RequestUpdate();
- return;
+ if(wxTheClipboard->GetData(wxldo))
+ {
+ wxTheClipboard->Close();
+ wxString str = wxldo.GetLayoutData();
+ m_llist->Read(str);
+ SetDirty();
+ RequestUpdate();
+ return;
+ }
}
- }
- }
- wxTextDataObject data;
- if (wxTheClipboard->IsSupported( data.GetFormat() )
- && wxTheClipboard->GetData(data) )
- {
- wxTheClipboard->Close();
- wxString text = data.GetText();
- wxLayoutImportText( m_llist, text);
- SetDirty();
- RequestUpdate();
- return;
- }
- }
- // if everything failed we can still try the primary:
- wxTheClipboard->Close();
- if(! primary) // not tried before
- {
- wxTheClipboard->UsePrimarySelection();
- if (wxTheClipboard->Open())
- {
- wxTextDataObject data;
- if (wxTheClipboard->IsSupported( data.GetFormat() )
- && wxTheClipboard->GetData(data) )
- {
+ }
+
+ wxTextDataObject data;
+ if (wxTheClipboard->IsSupported( data.GetFormat() )
+ && wxTheClipboard->GetData(data) )
+ {
+ wxTheClipboard->Close();
wxString text = data.GetText();
wxLayoutImportText( m_llist, text);
SetDirty();
RequestUpdate();
- }
- wxTheClipboard->Close();
- }
- }
+ return;
+ }
+ }
+ // if everything failed we can still try the primary:
+ wxTheClipboard->Close();
+ if(! primary) // not tried before
+ {
+ wxTheClipboard->UsePrimarySelection();
+ if (wxTheClipboard->Open())
+ {
+ wxTextDataObject data;
+ if (wxTheClipboard->IsSupported( data.GetFormat() )
+ && wxTheClipboard->GetData(data) )
+ {
+ wxString text = data.GetText();
+ wxLayoutImportText( m_llist, text);
+ SetDirty();
+ RequestUpdate();
+ }
+ wxTheClipboard->Close();
+ }
+ }
}
bool
wxLayoutWindow::Copy(bool invalidate, bool privateFormat, bool primary)
{
- // Calling GetSelection() will automatically do an EndSelection()
- // on the list, but we need to take a note of it, too:
- if(m_Selecting)
- {
- m_Selecting = false;
- m_llist->EndSelection();
- }
-
- wxLayoutDataObject *wldo = new wxLayoutDataObject;
- wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate);
- if(! llist)
- return FALSE;
- // Export selection as text:
- wxString text;
- wxLayoutExportObject *exp;
- wxLayoutExportStatus status(llist);
- while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
- {
- if(exp->type == WXLO_EXPORT_TEXT)
- text << *(exp->content.text);
- delete exp;
- }
- delete llist;
-
- // The exporter always appends a newline, so we chop it off if it
- // is there:
- {
- size_t len = text.Length();
- if(len > 2 && text[len-2] == '\r') // Windows
- text = text.Mid(0,len-2);
- else if(len > 1 && text[len-1] == '\n')
- text = text.Mid(0,len-1);
- }
+ // Calling GetSelection() will automatically do an EndSelection()
+ // on the list, but we need to take a note of it, too:
+ if(m_Selecting)
+ {
+ m_Selecting = false;
+ m_llist->EndSelection();
+ }
+
+ wxLayoutDataObject *wldo = new wxLayoutDataObject;
+ wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate);
+ if(! llist)
+ return false;
+ // Export selection as text:
+ wxString text;
+ wxLayoutExportObject *exp;
+ wxLayoutExportStatus status(llist);
+ while((exp = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
+ {
+ if(exp->type == WXLO_EXPORT_TEXT)
+ text << *(exp->content.text);
+
+ delete exp;
+ }
+
+ delete llist;
+
+ // The exporter always appends a newline, so we chop it off if it
+ // is there:
+ {
+ size_t len = text.Length();
+ if(len > 2 && text[len-2] == '\r') // Windows
+ text = text.Mid(0,len-2);
+ else if(len > 1 && text[len-1] == '\n')
+ text = text.Mid(0,len-1);
+ }
#if 0
-if(! primary) // always copy as text-only to primary selection
- {
- wxTheClipboard->UsePrimarySelection();
- if (wxTheClipboard->Open())
- {
- wxTextDataObject *data = new wxTextDataObject( text );
- wxTheClipboard->SetData( data );
- wxTheClipboard->Close();
- }
- }
+ if(! primary) // always copy as text-only to primary selection
+ {
+ wxTheClipboard->UsePrimarySelection();
+ if (wxTheClipboard->Open())
+ {
+ wxTextDataObject *data = new wxTextDataObject( text );
+ wxTheClipboard->SetData( data );
+ wxTheClipboard->Close();
+ }
+ }
#endif
- wxTheClipboard->UsePrimarySelection(primary);
- if (wxTheClipboard->Open())
- {
- wxTextDataObject *data = new wxTextDataObject( text );
- bool rc;
-
- rc = wxTheClipboard->SetData( data );
- if(privateFormat)
- rc |= wxTheClipboard->SetData( wldo );
- wxTheClipboard->Close();
- return rc;
- }
- else
- delete wldo;
-
- return FALSE;
+ wxTheClipboard->UsePrimarySelection(primary);
+ if (wxTheClipboard->Open())
+ {
+ wxTextDataObject *data = new wxTextDataObject( text );
+ bool rc = wxTheClipboard->SetData( data );
+
+ if(privateFormat)
+ rc |= wxTheClipboard->SetData( wldo );
+
+ wxTheClipboard->Close();
+ return rc;
+ }
+ else
+ {
+ delete wldo;
+ }
+
+ return false;
}
bool
wxLayoutWindow::Cut(bool privateFormat, bool usePrimary)
{
- if(Copy(false, privateFormat, usePrimary)) // do not invalidate selection after copy
- {
- m_llist->DeleteSelection();
- SetDirty();
- return TRUE;
- }
- else
- return FALSE;
+ if(Copy(false, privateFormat, usePrimary)) // do not invalidate selection after copy
+ {
+ m_llist->DeleteSelection();
+ SetDirty();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
bool
-wxLayoutWindow::Find(const wxString &
- #ifdef M_BASEDIR
- needle
- #else
- WXUNUSED(needle)
- #endif
- ,
- wxPoint *
- #ifdef M_BASEDIR
- fromWhere
- #else
- WXUNUSED(fromWhere)
- #endif
- ,
- const wxString &
- #ifdef M_BASEDIR
- configPath
- #else
- WXUNUSED(configPath)
- #endif
- )
+wxLayoutWindow::Find(
+#ifdef M_BASEDIR
+ const wxString &needle,
+ wxPoint * fromWhere,
+ const wxString &configPath
+#else
+ const wxString & WXUNUSED(needle),
+ wxPoint * WXUNUSED(fromWhere),
+ const wxString & WXUNUSED(configPath)
+#endif
+)
{
#ifdef M_BASEDIR
- wxPoint found;
-
- if(needle.Length() == 0)
- {
- if( ! MInputBox(&m_FindString,
- _("Find text"),
- _(" Find:"),
- this,
- configPath, "")
- || strutil_isempty(m_FindString))
- return true;
- }
- else
- m_FindString = needle;
-
- if(fromWhere == NULL)
- found = m_llist->FindText(m_FindString, m_llist->GetCursorPos());
- else
- found = m_llist->FindText(m_FindString, *fromWhere);
- if(found.x != -1)
- {
- if(fromWhere)
- {
- *fromWhere = found;
- fromWhere->x ++;
- }
- m_llist->MoveCursorTo(found);
- ScrollToCursor();
- RequestUpdate();
- return true;
- }
+ wxPoint found;
+
+ if(needle.Length() == 0)
+ {
+ if( ! MInputBox(&m_FindString,
+ _("Find text"),
+ _(" Find:"),
+ this,
+ configPath, "")
+ || strutil_isempty(m_FindString))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ m_FindString = needle;
+ }
+
+ if(fromWhere == NULL)
+ found = m_llist->FindText(m_FindString, m_llist->GetCursorPos());
+ else
+ found = m_llist->FindText(m_FindString, *fromWhere);
+
+ if(found.x != -1)
+ {
+ if(fromWhere)
+ {
+ *fromWhere = found;
+ fromWhere->x ++;
+ }
+
+ m_llist->MoveCursorTo(found);
+ ScrollToCursor();
+ RequestUpdate();
+
+ return true;
+ }
#endif
- return false;
+
+ return false;
}
bool
-wxLayoutWindow::FindAgain(void)
+wxLayoutWindow::FindAgain()
{
- bool rc = Find(m_FindString);
- return rc;
+ bool rc = Find(m_FindString);
+ return rc;
}
// ----------------------------------------------------------------------------
wxMenu *
wxLayoutWindow::MakeFormatMenu()
{
- wxMenu *m = new wxMenu(_("Layout Menu"));
-
- 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"),_("Underline mode."), true);
- m->Append(WXLOWIN_MENU_BOLD, _("&Bold"),_("Bold mode."), true);
- m->Append(WXLOWIN_MENU_ITALICS, _("&Italics"),_("Italics mode."), true);
- m->AppendSeparator();
- m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."), false);
- m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."), false);
- m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."), false);
-
- return m;
+ wxMenu *m = new wxMenu(_("Layout Menu"));
+
+ m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."));
+ m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."));
+ m->AppendSeparator();
+ m->Append(WXLOWIN_MENU_UNDERLINE, _("&Underline"),_("Underline mode."), wxITEM_CHECK);
+ m->Append(WXLOWIN_MENU_BOLD, _("&Bold"),_("Bold mode."), wxITEM_CHECK);
+ m->Append(WXLOWIN_MENU_ITALICS, _("&Italics"),_("Italics mode."), wxITEM_CHECK);
+ m->AppendSeparator();
+ m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."));
+ m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."));
+ m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."));
+
+ return m;
}
void wxLayoutWindow::OnUpdateMenuUnderline(wxUpdateUIEvent& event)
{
- event.Check(m_llist->IsFontUnderlined());
+ event.Check(m_llist->IsFontUnderlined());
}
void wxLayoutWindow::OnUpdateMenuBold(wxUpdateUIEvent& event)
{
- event.Check(m_llist->IsFontBold());
+ event.Check(m_llist->IsFontBold());
}
void wxLayoutWindow::OnUpdateMenuItalic(wxUpdateUIEvent& event)
{
- event.Check(m_llist->IsFontItalic());
+ event.Check(m_llist->IsFontItalic());
}
void wxLayoutWindow::OnMenu(wxCommandEvent& event)
{
- switch (event.GetId())
- {
- case WXLOWIN_MENU_LARGER:
- m_llist->SetFontLarger(); RequestUpdate(); break;
- case WXLOWIN_MENU_SMALLER:
- m_llist->SetFontSmaller(); RequestUpdate(); break;
- case WXLOWIN_MENU_UNDERLINE:
- m_llist->ToggleFontUnderline(); RequestUpdate(); break;
- case WXLOWIN_MENU_BOLD:
- m_llist->ToggleFontWeight(); RequestUpdate(); break;
- case WXLOWIN_MENU_ITALICS:
- m_llist->ToggleFontItalics(); RequestUpdate(); break;
- case WXLOWIN_MENU_ROMAN:
- m_llist->SetFontFamily(wxROMAN); RequestUpdate(); break;
- case WXLOWIN_MENU_TYPEWRITER:
- m_llist->SetFontFamily(wxFIXED); RequestUpdate(); break;
- case WXLOWIN_MENU_SANSSERIF:
- m_llist->SetFontFamily(wxSWISS); RequestUpdate(); break;
- }
+ switch (event.GetId())
+ {
+ case WXLOWIN_MENU_LARGER:
+ m_llist->SetFontLarger(); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_SMALLER:
+ m_llist->SetFontSmaller(); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_UNDERLINE:
+ m_llist->ToggleFontUnderline(); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_BOLD:
+ m_llist->ToggleFontWeight(); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_ITALICS:
+ m_llist->ToggleFontItalics(); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_ROMAN:
+ m_llist->SetFontFamily(wxROMAN); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_TYPEWRITER:
+ m_llist->SetFontFamily(wxFIXED); RequestUpdate(); break;
+
+ case WXLOWIN_MENU_SANSSERIF:
+ m_llist->SetFontFamily(wxSWISS); RequestUpdate(); break;
+ }
}
// ----------------------------------------------------------------------------
void
wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
{
- m_HaveFocus = true;
- ev.Skip();
- RequestUpdate(); // cursor must change
+ m_HaveFocus = true;
+ ev.Skip();
+ RequestUpdate(); // cursor must change
}
void
wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
{
- m_HaveFocus = false;
- ev.Skip();
- RequestUpdate();// cursor must change
+ m_HaveFocus = false;
+ ev.Skip();
+ RequestUpdate();// cursor must change
}
// ----------------------------------------------------------------------------
static bool IsDirectionKey(long keyCode)
{
- switch(keyCode)
- {
- case WXK_UP:
- case WXK_DOWN:
- case WXK_RIGHT:
- case WXK_LEFT:
- case WXK_PRIOR:
- case WXK_NEXT:
- case WXK_HOME:
- case WXK_END:
- return true;
-
- default:
- return false;
- }
+ switch(keyCode)
+ {
+ case WXK_UP:
+ case WXK_DOWN:
+ case WXK_RIGHT:
+ case WXK_LEFT:
+ case WXK_PRIOR:
+ case WXK_NEXT:
+ case WXK_HOME:
+ case WXK_END:
+ return true;
+
+ default:
+ return false;
+ }
}
+
#endif
#ifndef USE_PCH
-# include <wx/wx.h>
+# include "wx/wx.h"
#endif
#include "wxllist.h"
enum
{
- WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
- WXLOWIN_MENU_SMALLER,
- WXLOWIN_MENU_UNDERLINE,
- WXLOWIN_MENU_BOLD,
- WXLOWIN_MENU_ITALICS,
- WXLOWIN_MENU_ROMAN,
- WXLOWIN_MENU_TYPEWRITER,
- WXLOWIN_MENU_SANSSERIF,
- WXLOWIN_MENU_RCLICK,
- WXLOWIN_MENU_DBLCLICK,
- WXLOWIN_MENU_MDOWN,
- WXLOWIN_MENU_LDOWN,
- WXLOWIN_MENU_LCLICK = WXLOWIN_MENU_LDOWN,
- WXLOWIN_MENU_LUP,
- WXLOWIN_MENU_MOUSEMOVE,
- WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
+ WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
+ WXLOWIN_MENU_SMALLER,
+ WXLOWIN_MENU_UNDERLINE,
+ WXLOWIN_MENU_BOLD,
+ WXLOWIN_MENU_ITALICS,
+ WXLOWIN_MENU_ROMAN,
+ WXLOWIN_MENU_TYPEWRITER,
+ WXLOWIN_MENU_SANSSERIF,
+ WXLOWIN_MENU_RCLICK,
+ WXLOWIN_MENU_DBLCLICK,
+ WXLOWIN_MENU_MDOWN,
+ WXLOWIN_MENU_LDOWN,
+ WXLOWIN_MENU_LCLICK = WXLOWIN_MENU_LDOWN,
+ WXLOWIN_MENU_LUP,
+ WXLOWIN_MENU_MOUSEMOVE,
+ WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
};
/**
- This class is a rich text editing widget.
+ This class is a rich text editing widget.
*/
class wxLayoutWindow : public wxScrolledWindow
{
public:
- /** Constructor.
- @param parent parent window to display this panel in
- */
- wxLayoutWindow(wxWindow *parent);
-
- /// Destructor.
- virtual ~wxLayoutWindow();
-
- /**@name Editing functionality */
- //@{
- /// Clears the window and sets default parameters.
- void Clear(int family = wxROMAN,
- int size=12,
- int style=wxNORMAL,
- int weight=wxNORMAL,
- int underline=0,
- wxColour *fg=NULL,
- wxColour *bg=NULL);
-
- /// override base class virtual to also refresh the scrollbar position
- virtual void Refresh(bool eraseBackground = TRUE,
- const wxRect *rect = (const wxRect *)NULL);
-
- /** Sets a background image, only used on screen, not on printouts.
- @param bitmap a pointer to a wxBitmap or NULL to remove it
- */
- void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
- {
- if(m_BGbitmap) delete m_BGbitmap;
- m_BGbitmap = bitmap;
- }
- /// Enable or disable editing, i.e. processing of keystrokes.
- void SetEditable(bool toggle)
- { m_Editable = toggle; SetCursorVisibility(toggle); }
- /// Query whether list can be edited by user.
- bool IsEditable(void) const { return m_Editable; }
- /** Sets cursor visibility, visible=1, invisible=0,
- visible-on-demand=-1, to hide it until moved.
- @param visibility -1,0 or 1
- @return the old visibility
- */
- inline int SetCursorVisibility(int visibility = -1)
- { int v =m_CursorVisibility;
- m_CursorVisibility = visibility; return v;}
-
- /// Pastes text from clipboard.
- void Paste(bool privateFormat = FALSE, bool usePrimarySelection = FALSE);
- /** Copies selection to clipboard.
- @param invalidate used internally, see wxllist.h for details
- */
- bool Copy(bool invalidate = true, bool privateFormat = FALSE, bool primary = FALSE);
- /// Copies selection to clipboard and deletes it.
- bool Cut(bool privateFormat = FALSE, bool usePrimary = FALSE);
- //@}
-
- /// find string in buffer
- bool Find(const wxString &needle,
- wxPoint * fromWhere = NULL,
- const wxString &configPath = _T("MsgViewFindString"));
- /// find the same string again
- bool FindAgain(void);
-
- void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
-
- /** Sets the wrap margin.
- @param margin set this to 0 to disable it
- */
- void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
-
- /** Toggle wordwrap as we type.
- @param on true to activate word wrap
- */
- void SetWordWrap(bool on = true) { m_DoWordWrap = on; }
-
- /** Redraws the window.
- Internally, this stores the parameter and calls a refresh on
- wxMSW, draws directly on wxGTK.
- */
- void RequestUpdate(const wxRect *updateRect = NULL);
-
- /// if exact == false, assume 50% extra size for the future
- void ResizeScrollbars(bool exact = false); // don't change this to true!
-
- /// if the flag is true, we send events when user clicks on embedded objects
- inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
-
- /* Returns a pointer to the wxLayoutList object.
- @return the list
- */
- wxLayoutList * GetLayoutList(void) { return m_llist; }
-
- /**@name Callbacks */
- //@{
- void OnSize(wxSizeEvent &event);
- void OnPaint(wxPaintEvent &event);
- void OnChar(wxKeyEvent& event);
- void OnKeyUp(wxKeyEvent& event);
- void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
- void OnUpdateMenuBold(wxUpdateUIEvent& event);
- void OnUpdateMenuItalic(wxUpdateUIEvent& event);
- void OnMenu(wxCommandEvent& event);
- void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
- void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
- void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
- void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
- void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
- void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
- void OnSetFocus(wxFocusEvent &ev);
- void OnKillFocus(wxFocusEvent &ev);
- //@}
-
- /// Creates a wxMenu for use as a format popup.
- static wxMenu * MakeFormatMenu(void);
- /// Redraws the window, used by RequestUpdate() or OnPaint().
- void InternalPaint(const wxRect *updateRect);
-
- /** Tell window to update a wxStatusBar with UserData labels and
- cursor positions.
- @param bar wxStatusBar pointer
- @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
- @param cursorfield field to use for cursor position, or -1 to disable
- */
- void SetStatusBar(class wxStatusBar *bar,
- int labelfield = -1,
- int cursorfield = -1)
- {
- m_StatusBar = bar; m_StatusFieldLabel = labelfield;
- m_StatusFieldCursor = cursorfield;
- }
+ /** Constructor.
+ @param parent parent window to display this panel in
+ */
+ wxLayoutWindow(wxWindow *parent);
+
+ /// Destructor.
+ virtual ~wxLayoutWindow();
+
+ /**@name Editing functionality */
+ //@{
+ /// Clears the window and sets default parameters.
+ void Clear(int family = wxROMAN,
+ int size = 12,
+ int style = wxNORMAL,
+ int weight = wxNORMAL,
+ int underline = 0,
+ wxColour *fg = NULL,
+ wxColour *bg = NULL);
+
+ /// override base class virtual to also refresh the scrollbar position
+ virtual void Refresh(bool eraseBackground = true,
+ const wxRect *rect = (const wxRect *)NULL);
+
+ /** Sets a background image, only used on screen, not on printouts.
+ @param bitmap a pointer to a wxBitmap or NULL to remove it
+ */
+ void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
+ {
+ if(m_BGbitmap) delete m_BGbitmap;
+ m_BGbitmap = bitmap;
+ }
+
+ /// Enable or disable editing, i.e. processing of keystrokes.
+ void SetEditable(bool toggle)
+ {
+ m_Editable = toggle;
+ SetCursorVisibility(toggle);
+ }
+
+ /// Query whether list can be edited by user.
+ bool IsEditable() const { return m_Editable; }
+
+ /** Sets cursor visibility, visible=1, invisible=0,
+ visible-on-demand=-1, to hide it until moved.
+ @param visibility -1,0 or 1
+ @return the old visibility
+ */
+ inline int SetCursorVisibility(int visibility = -1)
+ {
+ int v =m_CursorVisibility;
+ m_CursorVisibility = visibility; return v;
+ }
+
+ /// Pastes text from clipboard.
+ void Paste(bool privateFormat = false, bool usePrimarySelection = false);
+
+ /** Copies selection to clipboard.
+ @param invalidate used internally, see wxllist.h for details
+ */
+ bool Copy(bool invalidate = true, bool privateFormat = false, bool primary = false);
+
+ /// Copies selection to clipboard and deletes it.
+ bool Cut(bool privateFormat = false, bool usePrimary = false);
+ //@}
+
+ /// find string in buffer
+ bool Find(const wxString &needle,
+ wxPoint * fromWhere = NULL,
+ const wxString &configPath = _T("MsgViewFindString"));
+
+ /// find the same string again
+ bool FindAgain();
+
+ void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
+
+ /** Sets the wrap margin.
+ @param margin set this to 0 to disable it
+ */
+ void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
+
+ /** Toggle wordwrap as we type.
+ @param on true to activate word wrap
+ */
+ void SetWordWrap(bool on = true) { m_DoWordWrap = on; }
+
+ /** Redraws the window.
+ Internally, this stores the parameter and calls a refresh on
+ wxMSW, draws directly on wxGTK.
+ */
+ void RequestUpdate(const wxRect *updateRect = NULL);
+
+ /// if exact == false, assume 50% extra size for the future
+ void ResizeScrollbars(bool exact = false); // don't change this to true!
+
+ /// if the flag is true, we send events when user clicks on embedded objects
+ inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
+
+ /** Returns a pointer to the wxLayoutList object.
+ @return the list
+ */
+ wxLayoutList * GetLayoutList() { return m_llist; }
+
+ /**@name Callbacks */
+ //@{
+ void OnSize(wxSizeEvent &event);
+ void OnPaint(wxPaintEvent &event);
+ void OnChar(wxKeyEvent& event);
+ void OnKeyUp(wxKeyEvent& event);
+ void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
+ void OnUpdateMenuBold(wxUpdateUIEvent& event);
+ void OnUpdateMenuItalic(wxUpdateUIEvent& event);
+ void OnMenu(wxCommandEvent& event);
+ void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
+ void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
+ void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
+ void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
+ void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
+ void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
+ void OnSetFocus(wxFocusEvent &ev);
+ void OnKillFocus(wxFocusEvent &ev);
+ //@}
+
+ /// Creates a wxMenu for use as a format popup.
+ static wxMenu * MakeFormatMenu();
+
+ /// Redraws the window, used by RequestUpdate() or OnPaint().
+ void InternalPaint(const wxRect *updateRect);
+
+ /** Tell window to update a wxStatusBar with UserData labels and
+ cursor positions.
+ @param bar wxStatusBar pointer
+ @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
+ @param cursorfield field to use for cursor position, or -1 to disable
+ */
+ void SetStatusBar(class wxStatusBar *bar,
+ int labelfield = -1,
+ int cursorfield = -1)
+ {
+ m_StatusBar = bar; m_StatusFieldLabel = labelfield;
+ m_StatusFieldCursor = cursorfield;
+ }
+
#ifndef __WXMSW__
- /// Enable or disable focus follow mode under non-MSW
- void SetFocusFollowMode(bool enable = TRUE)
- { m_FocusFollowMode = enable; }
+ /// Enable or disable focus follow mode under non-MSW
+ void SetFocusFollowMode(bool enable = true)
+ {
+ m_FocusFollowMode = enable;
+ }
#endif
- /**@name Modified flag handling, will not get reset by list unless
- in Clear() */
- //@{
- /// Set dirty flag.
- void SetModified(bool modified = TRUE) { m_Modified = modified; }
- /// Query whether window needs redrawing.
- bool IsModified(void) const { return m_Modified; }
- //@}
-
- /**@name Dirty flag handling for optimisations.
- Normally one should only need to call SetDirty(), e.g. when
- manipulating the wxLayoutList directly, so the window will update
- itself. ResetDirty() and IsDirty() should only be used
- internally. */
- //@{
- /// Set dirty flag.
- void SetDirty(void) { m_Dirty = true; m_Modified = true; }
- /// Query whether window needs redrawing.
- bool IsDirty(void) const { return m_Dirty; }
- /// Reset dirty flag.
- void ResetDirty(void) { m_Dirty = false; }
- //@}
-
-
+ /** @name Modified flag handling, will not get reset by list unless
+ in Clear() */
+ //@{
+ /// Set dirty flag.
+ void SetModified(bool modified = true) { m_Modified = modified; }
+
+ /// Query whether window needs redrawing.
+ bool IsModified() const { return m_Modified; }
+ //@}
+
+ /**
+ @name Dirty flag handling for optimisations.
+ Normally one should only need to call SetDirty(), e.g. when
+ manipulating the wxLayoutList directly, so the window will update
+ itself. ResetDirty() and IsDirty() should only be used
+ internally. */
+ //@{
+ /// Set dirty flag.
+ void SetDirty() { m_Dirty = true; m_Modified = true; }
+
+ /// Query whether window needs redrawing.
+ bool IsDirty() const { return m_Dirty; }
+
+ /// Reset dirty flag.
+ void ResetDirty() { m_Dirty = false; }
+ //@}
+
+
protected:
- /// generic function for mouse events processing
- void OnMouse(int eventId, wxMouseEvent& event);
- /// as the name says
- void ScrollToCursor(void);
- /// for sending events
- wxWindow *m_Parent;
- /// Shall we send events?
- bool m_doSendEvents;
- /// Where does the current view start?
- int m_ViewStartX; int m_ViewStartY;
- /// Do we currently have the focus?
- bool m_HaveFocus;
- /// do we handle clicks of the right mouse button?
- bool m_DoPopupMenu;
- /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
- bool m_ScrollToCursor;
- /// Do we currently have a non-standard cursor?
- bool m_HandCursor;
- /// 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;
- /// do we want automatic word wrap?
- bool m_DoWordWrap;
- /// wrap margin
- CoordType m_WrapMargin;
-
- /// do we have the corresponding scrollbar?
- bool m_hasHScrollbar,
+ /// generic function for mouse events processing
+ void OnMouse(int eventId, wxMouseEvent& event);
+
+ /// as the name says
+ void ScrollToCursor();
+
+ /// for sending events
+ wxWindow *m_Parent;
+
+ /// Shall we send events?
+ bool m_doSendEvents;
+
+ /// Where does the current view start?
+ int m_ViewStartX; int m_ViewStartY;
+
+ /// Do we currently have the focus?
+ bool m_HaveFocus;
+
+ /// do we handle clicks of the right mouse button?
+ bool m_DoPopupMenu;
+
+ /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
+ bool m_ScrollToCursor;
+
+ /// Do we currently have a non-standard cursor?
+ bool m_HandCursor;
+
+ /// 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;
+
+ /// do we want automatic word wrap?
+ bool m_DoWordWrap;
+
+ /// wrap margin
+ CoordType m_WrapMargin;
+
+ /// do we have the corresponding scrollbar?
+ bool m_hasHScrollbar,
m_hasVScrollbar;
- /** Visibility parameter for cursor. 0/1 as expected, -1: visible
- on demand.
- */
- int m_CursorVisibility;
-
- bool SetAutoDeleteSelection(bool enable = TRUE)
- {
- bool old = m_AutoDeleteSelection;
- m_AutoDeleteSelection = enable;
- return old;
- }
+ /** Visibility parameter for cursor. 0/1 as expected, -1: visible
+ on demand.
+ */
+ int m_CursorVisibility;
+
+ bool SetAutoDeleteSelection(bool enable = true)
+ {
+ bool old = m_AutoDeleteSelection;
+ m_AutoDeleteSelection = enable;
+ return old;
+ }
private:
- /// The layout list to be displayed.
- wxLayoutList *m_llist;
- /// Can user edit the window?
- bool m_Editable;
- /// Are we currently building a selection with the keyboard?
- bool m_Selecting;
- /// Has list changed since last redraw, e.g. in size?
- bool m_Dirty;
- /// Has the list ever been modified?
- bool m_Modified;
- wxMemoryDC *m_memDC;
- wxBitmap *m_bitmap;
- wxPoint m_bitmapSize;
- /// A frame's statusbar to update
- class wxStatusBar *m_StatusBar;
- /// statusbar field for labels
- int m_StatusFieldLabel;
- /// statusbar field for cursor positions
- int m_StatusFieldCursor;
- /// a pointer to a bitmap for the background
- wxBitmap *m_BGbitmap;
- /**@name Some configuration options */
- //@{
- /// Do we want to auto-replace the selection with new text?
- bool m_AutoDeleteSelection;
+ /// The layout list to be displayed.
+ wxLayoutList *m_llist;
+
+ /// Can user edit the window?
+ bool m_Editable;
+
+ /// Are we currently building a selection with the keyboard?
+ bool m_Selecting;
+
+ /// Has list changed since last redraw, e.g. in size?
+ bool m_Dirty;
+
+ /// Has the list ever been modified?
+ bool m_Modified;
+
+ wxMemoryDC *m_memDC;
+ wxBitmap *m_bitmap;
+ wxPoint m_bitmapSize;
+
+ /// A frame's statusbar to update
+ class wxStatusBar *m_StatusBar;
+
+ /// statusbar field for labels
+ int m_StatusFieldLabel;
+
+ /// statusbar field for cursor positions
+ int m_StatusFieldCursor;
+
+ /// a pointer to a bitmap for the background
+ wxBitmap *m_BGbitmap;
+
+ /**@name Some configuration options */
+ //@{
+ /// Do we want to auto-replace the selection with new text?
+ bool m_AutoDeleteSelection;
+
#ifndef __WXMSW__
- /// Do we want the focus to follow the mouse?
- bool m_FocusFollowMode;
+ /// Do we want the focus to follow the mouse?
+ bool m_FocusFollowMode;
#endif
- /// For finding text and finding it again:
- wxString m_FindString;
+ /// For finding text and finding it again:
+ wxString m_FindString;
//@}
- DECLARE_EVENT_TABLE()
+
+ DECLARE_EVENT_TABLE()
};
#endif