Applied patch #845402 ("RichEdit sample fixing and cleaning"); In addition made compilation with MSVC (nearly) warning free+some more cleaning up.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24613 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Dimitri Schoolwerth
2003-11-20 17:43:57 +00:00
parent 6c3b4aae47
commit 62a1177692
8 changed files with 3286 additions and 2953 deletions

View File

@@ -136,7 +136,7 @@ public:
deleted by list. See the constructor for more details. deleted by list. See the constructor for more details.
@param ownsflag if true, list will own entries @param ownsflag if true, list will own entries
*/ */
void ownsObjects(bool ownsflag = true) void ownsObjects(bool ownsflag)
{ ownsEntries = ownsflag; } { ownsEntries = ownsflag; }
/** Query whether list owns entries. /** Query whether list owns entries.
@@ -236,7 +236,10 @@ protected:
param iterator i param iterator i
*/ */
inline void deleteContent(iterator i) inline void deleteContent(iterator i)
{ if(ownsEntries) delete *i; } {
iterator *i_ptr = &i;
if(ownsEntries) delete i_ptr;
}
private: private:

View File

@@ -17,8 +17,8 @@
#endif #endif
#include "wxLayout.h" #include "wxLayout.h"
#include <wx/textfile.h> #include "wx/textfile.h"
#include <wx/image.h> #include "wx/image.h"
#if wxUSE_IOSTREAMH #if wxUSE_IOSTREAMH
#include <iostream.h> #include <iostream.h>
@@ -26,6 +26,9 @@
#include <iostream> #include <iostream>
#endif #endif
#include "wx/wfstream.h"
#include "wx/txtstrm.h"
#include "Micon.xpm" #include "Micon.xpm"
@@ -69,9 +72,9 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
END_EVENT_TABLE() END_EVENT_TABLE()
MyFrame::MyFrame(void) : MyFrame::MyFrame() :
wxFrame( (wxFrame *) NULL, -1, _T("wxLayout"), wxFrame( (wxFrame *) NULL, wxID_ANY, _T("wxLayout"),
wxPoint(880,100), wxSize(256,256) ) wxDefaultPosition, wxDefaultSize )
{ {
CreateStatusBar( 2 ); CreateStatusBar( 2 );
@@ -119,7 +122,7 @@ MyFrame::MyFrame(void) :
menu_bar->Append(edit_menu, _T("&Edit") ); menu_bar->Append(edit_menu, _T("&Edit") );
#ifndef __WXMSW__ #ifndef __WXMSW__
menu_bar->Show( TRUE ); menu_bar->Show(true);
#endif // MSW #endif // MSW
SetMenuBar( menu_bar ); SetMenuBar( menu_bar );
@@ -157,12 +160,13 @@ MyFrame::MyFrame(void) :
#endif // 0 #endif // 0
}; };
void void MyFrame::AddSampleText(wxLayoutList *llist)
MyFrame::AddSampleText(wxLayoutList *llist)
{ {
llist->Clear(wxSWISS,16,wxNORMAL,wxNORMAL, false); llist->Clear(wxSWISS,16,wxNORMAL,wxNORMAL, false);
llist->SetFont(-1,-1,-1,-1,-1,_T("blue")); llist->SetFont(-1,-1,-1,-1,-1,_T("blue"));
llist->Insert(_T("blue")); llist->Insert(_T("blue"));
llist->LineBreak();
llist->SetFont(-1,-1,-1,-1,-1,_T("black")); llist->SetFont(-1,-1,-1,-1,-1,_T("black"));
llist->Insert(_T("The quick brown fox jumps over the lazy dog.")); llist->Insert(_T("The quick brown fox jumps over the lazy dog."));
llist->LineBreak(); llist->LineBreak();
@@ -174,35 +178,46 @@ MyFrame::AddSampleText(wxLayoutList *llist)
llist->SetFont(wxROMAN); llist->SetFont(wxROMAN);
llist->Insert(_T("The quick brown fox jumps over the lazy dog.")); llist->Insert(_T("The quick brown fox jumps over the lazy dog."));
llist->LineBreak(); llist->LineBreak();
llist->Insert(_T("Hello ")); llist->Insert(_T("Hello "));
wxBitmap *icon =
#if wxICON_IS_BITMAP #if wxICON_IS_BITMAP
llist->Insert(new wxLayoutObjectIcon(new wxICON(Micon))); new wxIcon(Micon_xpm)
#else #else
llist->Insert(new wxLayoutObjectIcon(new wxBitmap (wxICON(Micon)))); new wxBitmap (wxIcon(Micon_xpm))
#endif #endif
;
llist->Insert(new wxLayoutObjectIcon(icon));
llist->SetFontWeight(wxBOLD); llist->SetFontWeight(wxBOLD);
llist->Insert(_T("World! ")); llist->Insert(_T("World! "));
llist->SetFontWeight(wxNORMAL); llist->SetFontWeight(wxNORMAL);
llist->Insert(_T("The quick brown fox jumps...")); llist->Insert(_T("The quick brown fox jumps..."));
llist->LineBreak(); llist->LineBreak();
llist->Insert(_T("over the lazy dog.")); llist->Insert(_T("over the lazy dog."));
llist->SetFont(-1,-1,-1,-1,true); llist->SetFont(-1,-1,-1,-1,true);
llist->Insert(_T("underlined")); llist->Insert(_T("underlined"));
llist->SetFont(-1,-1,-1,-1,false); llist->SetFont(-1,-1,-1,-1,false);
llist->SetFont(wxROMAN); llist->SetFont(wxROMAN);
llist->Insert(_T("This is ")); llist->Insert(_T("This is "));
llist->SetFont(-1,-1,-1,wxBOLD); llist->Insert(_T("BOLD ")); llist->SetFont(-1,-1,-1,wxNORMAL); llist->SetFont(-1,-1,-1,wxBOLD);
llist->Insert(_T("BOLD "));
llist->SetFont(-1,-1,-1,wxNORMAL);
llist->Insert(_T("and ")); llist->Insert(_T("and "));
llist->SetFont(-1,-1,wxITALIC); llist->SetFont(-1,-1,wxITALIC);
llist->Insert(_T("italics ")); llist->Insert(_T("italics "));
llist->SetFont(-1,-1,wxNORMAL); llist->SetFont(-1,-1,wxNORMAL);
llist->LineBreak(); llist->LineBreak();
llist->Insert(_T("and ")); llist->Insert(_T("and "));
llist->SetFont(-1,-1,wxSLANT); llist->SetFont(-1,-1,wxSLANT);
llist->Insert(_T("slanted")); llist->Insert(_T("slanted"));
llist->SetFont(-1,-1,wxNORMAL); llist->SetFont(-1,-1,wxNORMAL);
llist->Insert(_T(" text.")); llist->Insert(_T(" text."));
llist->LineBreak(); llist->LineBreak();
llist->Insert(_T("and ")); llist->Insert(_T("and "));
llist->SetFont(-1,-1,-1,-1,-1,_T("blue")); llist->SetFont(-1,-1,-1,-1,-1,_T("blue"));
llist->Insert(_T("blue")); llist->Insert(_T("blue"));
@@ -227,23 +242,20 @@ MyFrame::AddSampleText(wxLayoutList *llist)
// add some more text for testing: // add some more text for testing:
llist->Insert(_T("And here the source for the test program:")); llist->Insert(_T("And here the source for the test program:"));
llist->LineBreak(); llist->LineBreak();
llist->SetFont(wxTELETYPE,16); llist->SetFont(wxTELETYPE,16);
llist->Insert(_T("And here the source for the test program:")); llist->Insert(_T("And here the source for the test program:"));
llist->LineBreak(); 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") ); wxTextFile file(_T("wxLayout.cpp"));
if ( file.IsOpened() ) if ( file.Open() )
{ {
off_t len = file.Length(); for ( wxString s = file.GetFirstLine(); !file.Eof(); s = file.GetNextLine() )
wxChar *data = (wxChar *)malloc(2*len);
if ( file.Read(data, len) == len )
{ {
wxLayoutImportText(llist, data); wxString line;
llist->Insert(line.Format(_T("%6u: %s"),file.GetCurrentLine()+1,s.c_str()));
llist->LineBreak();
} }
free(data);
} }
llist->MoveCursorTo(wxPoint(0,0)); llist->MoveCursorTo(wxPoint(0,0));
@@ -251,8 +263,7 @@ MyFrame::AddSampleText(wxLayoutList *llist)
m_lwin->Refresh(); m_lwin->Refresh();
} }
void void MyFrame::Clear()
MyFrame::Clear(void)
{ {
wxColour colBg(0, 0, 0); wxColour colBg(0, 0, 0);
@@ -265,13 +276,13 @@ void MyFrame::OnCommand( wxCommandEvent &event )
switch (event.GetId()) switch (event.GetId())
{ {
case ID_QUIT: case ID_QUIT:
Close( TRUE ); Close(true);
break; break;
case ID_PRINT: case ID_PRINT:
{ {
wxPrinter printer; wxPrinter printer;
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout")); 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 // Had to remove the split up strings that used to be below, and
// put them into one long strong. Otherwise MSVC would give an // put them into one long strong. Otherwise MSVC would give an
@@ -297,76 +308,100 @@ void MyFrame::OnCommand( wxCommandEvent &event )
Clear(); Clear();
break; break;
case ID_CLICK: case ID_CLICK:
cerr << "Received click event." << endl; wxLogError( _T("Received click event.") );
break; break;
case ID_PASTE: case ID_PASTE:
m_lwin->Paste(TRUE); m_lwin->Paste(true);
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
#ifdef __WXGTK__ #ifdef __WXGTK__
case ID_PASTE_PRIMARY: case ID_PASTE_PRIMARY:
// text only from primary: // text only from primary:
m_lwin->Paste(FALSE, TRUE); m_lwin->Paste(false, true);
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
case ID_COPY_PRIMARY: case ID_COPY_PRIMARY:
// copy text-only to primary selection: // copy text-only to primary selection:
m_lwin->Copy(FALSE,FALSE,TRUE); m_lwin->Copy(false, false, true);
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
#endif #endif
case ID_COPY: case ID_COPY:
m_lwin->Copy(TRUE,TRUE,FALSE); m_lwin->Copy(true, true, false);
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
case ID_CUT: case ID_CUT:
m_lwin->Cut(); m_lwin->Cut();
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
#ifdef M_BASEDIR #ifdef M_BASEDIR
case ID_FIND: case ID_FIND:
m_lwin->Find("void"); m_lwin->Find("void");
m_lwin->Refresh(FALSE); m_lwin->Refresh(false);
break; break;
#endif #endif
case ID_HTML: case ID_HTML:
{ {
wxLayoutExportObject *export0; wxFileDialog
wxLayoutExportStatus status(m_lwin->GetLayoutList()); 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 );
cout << "<HTML>" << endl; wxLayoutExportObject *export0;
while((export0 = wxLayoutExport( &status, wxString object;
WXLO_EXPORT_AS_HTML)) != NULL) wxLayoutExportStatus status(m_lwin->GetLayoutList());
while((export0 = wxLayoutExport( &status, WXLO_EXPORT_AS_HTML)) != NULL)
{ {
if(export0->type == WXLO_EXPORT_HTML) if(export0->type == WXLO_EXPORT_HTML)
cout << *(export0->content.text); object = *(export0->content.text);
else else
; // ignore itcout << "<!--UNKNOWN OBJECT>"; ; // ignore "<!--UNKNOWN OBJECT>";
delete export0; delete export0;
textout << object;
}
} }
break; break;
} }
case ID_TEXT: case ID_TEXT:
{ {
wxLayoutExportObject *export0; wxFileDialog
wxLayoutExportStatus status(m_lwin->GetLayoutList()); 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) while((export0 = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
{ {
if(export0->type == WXLO_EXPORT_TEXT) if(export0->type == WXLO_EXPORT_TEXT)
cout << *(export0->content.text); object = *(export0->content.text);
else else
cout << "<!--UNKNOWN OBJECT>"; object = _T("<!--UNKNOWN OBJECT>");
delete export0; delete export0;
textout << object;
}
} }
break; break;
} }
case ID_LONG_TEST: case ID_LONG_TEST:
{ {
wxString line; wxString line;
@@ -400,6 +435,7 @@ void MyFrame::OnCommand( wxCommandEvent &event )
// wxLayoutWindow should have a flag m_highlightUrls and do it itself // wxLayoutWindow should have a flag m_highlightUrls and do it itself
// (instead of doing it manually like M does now) // (instead of doing it manually like M does now)
m_lwin->GetLayoutList()->Insert(_T("http://www.wxwindows.org/")); m_lwin->GetLayoutList()->Insert(_T("http://www.wxwindows.org/"));
m_lwin->Refresh();
} }
}; };
@@ -412,7 +448,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
#endif #endif
wxPrinter printer; wxPrinter printer;
wxLayoutPrintout printout( m_lwin->GetLayoutList(), _T("Printout from wxLayout")); wxLayoutPrintout printout( m_lwin->GetLayoutList(), _T("Printout from wxLayout"));
if (! printer.Print(this, &printout, TRUE)) if (! printer.Print(this, &printout, true))
wxMessageBox( wxMessageBox(
_T("There was a problem printing.\nPerhaps your current printer is not set correctly?"), _T("There was a problem printing.\nPerhaps your current printer is not set correctly?"),
_T("Printing"), wxOK); _T("Printing"), wxOK);
@@ -425,7 +461,7 @@ void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
#ifdef OS_UNIX #ifdef OS_UNIX
wxPostScriptPrinter printer; wxPostScriptPrinter printer;
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout"); wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
printer.Print(this, &printout, TRUE); printer.Print(this, &printout, true);
#endif #endif
} }
@@ -452,7 +488,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650)); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
frame->Centre(wxBOTH); frame->Centre(wxBOTH);
frame->Initialize(); frame->Initialize();
frame->Show(TRUE); frame->Show(true);
} }
void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
@@ -466,7 +502,7 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650)); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
frame->Centre(wxBOTH); frame->Centre(wxBOTH);
frame->Initialize(); frame->Initialize();
frame->Show(TRUE); frame->Show(true);
} }
void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
@@ -531,18 +567,18 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
// MyApp // MyApp
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
MyApp::MyApp(void) : MyApp::MyApp() :
wxApp( ) wxApp( )
{ {
}; };
bool MyApp::OnInit(void) bool MyApp::OnInit()
{ {
wxFrame *frame = new MyFrame(); wxFrame *frame = new MyFrame();
wxInitAllImageHandlers(); wxInitAllImageHandlers();
frame->Show( TRUE ); frame->Show( true );
// wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/"); // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
return TRUE; return true;
}; };

View File

@@ -7,7 +7,7 @@
#pragma interface #pragma interface
#endif #endif
#include <wx/wx.h> #include "wx/wx.h"
#include "wxllist.h" #include "wxllist.h"
#include "wxlwindow.h" #include "wxlwindow.h"
@@ -26,13 +26,12 @@ class MyApp;
class MyFrame: public wxFrame class MyFrame: public wxFrame
{ {
DECLARE_DYNAMIC_CLASS(MyFrame)
public: public:
MyFrame(void); MyFrame();
void AddSampleText(wxLayoutList *llist); void AddSampleText(wxLayoutList *llist);
void Clear(void); void Clear();
void OnCommand( wxCommandEvent &event ); void OnCommand( wxCommandEvent &event );
void OnPrint(wxCommandEvent& event); void OnPrint(wxCommandEvent& event);
@@ -44,11 +43,14 @@ class MyFrame: public wxFrame
void OnPrintSetupPS(wxCommandEvent& event); void OnPrintSetupPS(wxCommandEvent& event);
void OnPageSetupPS(wxCommandEvent& event); void OnPageSetupPS(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
private: private:
wxLayoutWindow *m_lwin; wxLayoutWindow *m_lwin;
wxPrintData m_PrintData; wxPrintData m_PrintData;
DECLARE_DYNAMIC_CLASS(MyFrame)
DECLARE_EVENT_TABLE()
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -59,8 +61,11 @@ class MyApp: public wxApp
{ {
public: public:
MyApp(void); MyApp();
virtual bool OnInit(void);
virtual bool OnInit();
}; };
#endif // __WXCONVERTH__ #endif // __WXCONVERTH__

View File

@@ -51,15 +51,15 @@
#include <iostream> #include <iostream>
#endif #endif
# include <wx/dc.h> # include "wx/dc.h"
# include <wx/dcps.h> # include "wx/dcps.h"
# include <wx/print.h> # include "wx/print.h"
# include <wx/log.h> # include "wx/log.h"
# include <wx/filefn.h> # include "wx/filefn.h"
#endif #endif
#ifdef WXLAYOUT_USE_CARET #ifdef WXLAYOUT_USE_CARET
# include <wx/caret.h> # include "wx/caret.h"
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
#include <ctype.h> #include <ctype.h>
@@ -78,7 +78,7 @@
_T("invalid"), _T("text"), _T("cmd"), _T("icon") _T("invalid"), _T("text"), _T("cmd"), _T("icon")
}; };
wxString wxString
wxLayoutObject::DebugDump(void) const wxLayoutObject::DebugDump() const
{ {
wxString str; wxString str;
str.Printf(wxT("%s"), g_aTypeStrings[GetType()]); str.Printf(wxT("%s"), g_aTypeStrings[GetType()]);
@@ -213,9 +213,9 @@ wxLayoutObject::Read(wxString &istr)
return wxLayoutObjectCmd::Read(istr); return wxLayoutObjectCmd::Read(istr);
case WXLO_TYPE_ICON: case WXLO_TYPE_ICON:
return wxLayoutObjectIcon::Read(istr); return wxLayoutObjectIcon::Read(istr);
default:
return NULL;
} }
return NULL;
} }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -234,7 +234,7 @@ wxLayoutObjectText::wxLayoutObjectText(const wxString &txt)
} }
wxLayoutObject * wxLayoutObject *
wxLayoutObjectText::Copy(void) wxLayoutObjectText::Copy()
{ {
wxLayoutObjectText *obj = new wxLayoutObjectText(m_Text); wxLayoutObjectText *obj = new wxLayoutObjectText(m_Text);
obj->m_Width = m_Width; obj->m_Width = m_Width;
@@ -386,7 +386,7 @@ wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList *WXUNUSED(llist))
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
wxString wxString
wxLayoutObjectText::DebugDump(void) const wxLayoutObjectText::DebugDump() const
{ {
wxString str; wxString str;
str = wxLayoutObject::DebugDump(); str = wxLayoutObject::DebugDump();
@@ -450,12 +450,12 @@ wxLayoutObjectIcon::Read(wxString &istr)
delete obj; delete obj;
return NULL; return NULL;
} }
else
return obj; return obj;
} }
wxLayoutObject * wxLayoutObject *
wxLayoutObjectIcon::Copy(void) wxLayoutObjectIcon::Copy()
{ {
wxLayoutObjectIcon *obj = new wxLayoutObjectIcon(new wxLayoutObjectIcon *obj = new wxLayoutObjectIcon(new
wxBitmap(*m_Icon)); wxBitmap(*m_Icon));
@@ -476,7 +476,7 @@ wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords,
CoordType WXUNUSED(begin), CoordType WXUNUSED(len) ) CoordType WXUNUSED(begin), CoordType WXUNUSED(len) )
{ {
dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(), dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(),
(m_Icon->GetMask() == NULL) ? FALSE : TRUE); (m_Icon->GetMask() == NULL) ? false : true);
} }
void void
@@ -552,7 +552,7 @@ wxLayoutObjectCmd::wxLayoutObjectCmd(const wxLayoutStyleInfo &si)
} }
wxLayoutObject * wxLayoutObject *
wxLayoutObjectCmd::Copy(void) wxLayoutObjectCmd::Copy()
{ {
wxLayoutObjectCmd *obj = new wxLayoutObjectCmd( wxLayoutObjectCmd *obj = new wxLayoutObjectCmd(
m_StyleInfo->family, m_StyleInfo->family,
@@ -675,7 +675,7 @@ wxLayoutObjectCmd::~wxLayoutObjectCmd()
} }
wxLayoutStyleInfo * wxLayoutStyleInfo *
wxLayoutObjectCmd::GetStyle(void) const wxLayoutObjectCmd::GetStyle() const
{ {
return m_StyleInfo; return m_StyleInfo;
} }
@@ -851,9 +851,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc, wxLayoutList *llist,
CoordType CoordType
wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const
{ {
int int cpos = 0;
cpos = 0,
relpos = -1;
wxString const *text; wxString const *text;
for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++) for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++)
@@ -863,7 +861,7 @@ wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const
if((**i).GetType() == WXLO_TYPE_TEXT) if((**i).GetType() == WXLO_TYPE_TEXT)
{ {
text = & ((wxLayoutObjectText*)(*i))->GetText(); text = & ((wxLayoutObjectText*)(*i))->GetText();
relpos = text->Find(needle); int relpos = text->Find(needle);
if(relpos >= cpos-xpos) // -1 if not found if(relpos >= cpos-xpos) // -1 if not found
{ {
return cpos+relpos; return cpos+relpos;
@@ -1118,7 +1116,9 @@ wxLayoutLine::Draw(wxDC &dc,
if(highlight == -1) // partially highlight line if(highlight == -1) // partially highlight line
{ {
// parts of the line need highlighting // 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); (**i).Draw(dc, pos, llist, from-xpos, to-xpos);
} }
else else
@@ -1357,12 +1357,12 @@ bool
wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist) wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist)
{ {
if(GetLength() < wrapmargin) if(GetLength() < wrapmargin)
return FALSE; // nothing to do return false; // nothing to do
// find the object which covers the wrapmargin: // find the object which covers the wrapmargin:
CoordType offset; CoordType offset;
wxLOiterator i = FindObject(wrapmargin, &offset); wxLOiterator i = FindObject(wrapmargin, &offset);
wxCHECK_MSG( i != NULLIT, FALSE, wxCHECK_MSG( i != NULLIT, false,
wxT("Cannot find object covering wrapmargin.")); wxT("Cannot find object covering wrapmargin."));
// from this object on, the rest of the line must be copied to the // from this object on, the rest of the line must be copied to the
@@ -1387,7 +1387,7 @@ wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist)
} }
else else
{ {
bool foundSpace = FALSE; bool foundSpace = false;
do do
{ {
// while(i != NULLIT && (**i).GetType() != WXLO_TYPE_TEXT) // while(i != NULLIT && (**i).GetType() != WXLO_TYPE_TEXT)
@@ -1413,7 +1413,7 @@ wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist)
if(! foundSpace) // breakpos == 0! if(! foundSpace) // breakpos == 0!
{ {
if(i == m_ObjectList.begin()) if(i == m_ObjectList.begin())
return FALSE; // could not break line return false; // could not break line
else else
{ {
i--; i--;
@@ -1478,11 +1478,11 @@ wxLayoutLine::Wrap(CoordType wrapmargin, wxLayoutList *llist)
#endif #endif
llist->MoveCursorTo( wxPoint( xpos, m_Next->GetLineNumber()) ); llist->MoveCursorTo( wxPoint( xpos, m_Next->GetLineNumber()) );
} }
return TRUE; // we wrapped the line return true; // we wrapped the line
} }
void void
wxLayoutLine::ReNumber(void) wxLayoutLine::ReNumber()
{ {
CoordType lineNo = m_Previous ? m_Previous->m_LineNumber+1 : 0; CoordType lineNo = m_Previous ? m_Previous->m_LineNumber+1 : 0;
m_LineNumber = lineNo++; m_LineNumber = lineNo++;
@@ -1611,7 +1611,7 @@ wxLayoutLine::GetWrapPosition(CoordType column)
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
void void
wxLayoutLine::Debug(void) const wxLayoutLine::Debug() const
{ {
wxPoint pos = GetPosition(); wxPoint pos = GetPosition();
WXLO_DEBUG((wxT("Line %ld, Pos (%ld,%ld), Height %ld, BL %ld, Font: %d"), WXLO_DEBUG((wxT("Line %ld, Pos (%ld,%ld), Height %ld, BL %ld, Font: %d"),
@@ -1707,15 +1707,15 @@ wxLayoutList::wxLayoutList()
m_numLines = 0; m_numLines = 0;
m_FirstLine = NULL; m_FirstLine = NULL;
SetAutoFormatting(TRUE); SetAutoFormatting(true);
ForceTotalLayout(TRUE); // for the first time, do all ForceTotalLayout(true); // for the first time, do all
InvalidateUpdateRect(); InvalidateUpdateRect();
Clear(); Clear();
} }
wxLayoutList::~wxLayoutList() wxLayoutList::~wxLayoutList()
{ {
SetAutoFormatting(FALSE); SetAutoFormatting(false);
InternalClear(); InternalClear();
Empty(); Empty();
m_FirstLine->DeleteLine(false, this); m_FirstLine->DeleteLine(false, this);
@@ -1724,7 +1724,7 @@ wxLayoutList::~wxLayoutList()
} }
void void
wxLayoutList::Empty(void) wxLayoutList::Empty()
{ {
while(m_FirstLine) while(m_FirstLine)
m_FirstLine = m_FirstLine->DeleteLine(false, this); m_FirstLine = m_FirstLine->DeleteLine(false, this);
@@ -1740,7 +1740,7 @@ wxLayoutList::Empty(void)
void void
wxLayoutList::InternalClear(void) wxLayoutList::InternalClear()
{ {
m_Selection.m_selecting = false; m_Selection.m_selecting = false;
m_Selection.m_valid = false; m_Selection.m_valid = false;
@@ -1750,9 +1750,9 @@ wxLayoutList::InternalClear(void)
m_DefaultStyleInfo.style = wxNORMAL; m_DefaultStyleInfo.style = wxNORMAL;
m_DefaultStyleInfo.weight = wxNORMAL; m_DefaultStyleInfo.weight = wxNORMAL;
m_DefaultStyleInfo.underline = 0; m_DefaultStyleInfo.underline = 0;
m_DefaultStyleInfo.m_fg_valid = TRUE; m_DefaultStyleInfo.m_fg_valid = true;
m_DefaultStyleInfo.m_fg = *wxBLACK; m_DefaultStyleInfo.m_fg = *wxBLACK;
m_DefaultStyleInfo.m_bg_valid = TRUE; m_DefaultStyleInfo.m_bg_valid = true;
m_DefaultStyleInfo.m_bg = *wxWHITE; m_DefaultStyleInfo.m_bg = *wxWHITE;
m_CurrentStyleInfo = m_DefaultStyleInfo; m_CurrentStyleInfo = m_DefaultStyleInfo;
@@ -2216,7 +2216,7 @@ bool
wxLayoutList::Insert(wxLayoutList *llist) wxLayoutList::Insert(wxLayoutList *llist)
{ {
wxASSERT(llist); wxASSERT(llist);
bool rc = TRUE; bool rc = true;
for(wxLayoutLine *line = llist->GetFirstLine(); for(wxLayoutLine *line = llist->GetFirstLine();
line; line;
@@ -2233,7 +2233,7 @@ wxLayoutList::Insert(wxLayoutList *llist)
} }
bool bool
wxLayoutList::LineBreak(void) wxLayoutList::LineBreak()
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
@@ -2280,8 +2280,8 @@ wxLayoutList::WrapAll(CoordType column)
{ {
wxLayoutLine *line = m_FirstLine; wxLayoutLine *line = m_FirstLine;
if(! line) if(! line)
return FALSE; return false;
bool rc = TRUE; bool rc = true;
while(line && rc) while(line && rc)
{ {
rc &= line->Wrap(column, this); rc &= line->Wrap(column, this);
@@ -2422,7 +2422,7 @@ wxLayoutList::Recalculate(wxDC &dc, CoordType bottom)
} }
wxPoint wxPoint
wxLayoutList::GetCursorScreenPos(void) const wxLayoutList::GetCursorScreenPos() const
{ {
return m_CursorScreenPos; return m_CursorScreenPos;
} }
@@ -2442,10 +2442,11 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
if(m_ReLayoutAll) if(m_ReLayoutAll)
{ {
forceAll = TRUE; forceAll = true;
bottom = -1; bottom = -1;
} }
ForceTotalLayout(FALSE);
ForceTotalLayout(false);
// If one line was dirty, we need to re-calculate all // If one line was dirty, we need to re-calculate all
@@ -2496,7 +2497,8 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
if ( csize ) if ( csize )
*csize = m_CursorSize; *csize = m_CursorSize;
} }
cursorReached = TRUE;
cursorReached = true;
} }
else else
{ {
@@ -2505,12 +2507,13 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
line->Layout(dc, this, line->Layout(dc, this,
cpos, cpos,
csize, NULL, cpos->x); csize, NULL, cpos->x);
cursorReached = TRUE; cursorReached = true;
} }
else else
line->Layout(dc, this); line->Layout(dc, this);
} }
} }
line = line->GetNextLine(); line = line->GetNextLine();
} }
@@ -2520,6 +2523,7 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll,
m_CursorLine->GetNextLine() == NULL && m_CursorLine->GetNextLine() == NULL &&
m_CursorLine == m_FirstLine)); m_CursorLine == m_FirstLine));
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
AddCursorPosToUpdateRect(); AddCursorPosToUpdateRect();
} }
@@ -2579,13 +2583,16 @@ wxLayoutList::Draw(wxDC &dc,
&& line->GetPosition().y && line->GetPosition().y
+(clipStrictly ? line->GetHeight() : 0) >= bottom) +(clipStrictly ? line->GetHeight() : 0) >= bottom)
break; break;
line->Draw(dc, this, offset); line->Draw(dc, this, offset);
} }
line = line->GetNextLine(); line = line->GetNextLine();
} }
InvalidateUpdateRect(); InvalidateUpdateRect();
WXLO_DEBUG((wxT("Selection is %s : %ld,%ld/%ld,%ld"), WXLO_DEBUG((wxT("Selection is %s : %d,%d/%d,%d"),
m_Selection.m_valid ? wxT("valid") : wxT("invalid"), m_Selection.m_valid ? wxT("valid") : wxT("invalid"),
m_Selection.m_CursorA.x, m_Selection.m_CursorA.y, m_Selection.m_CursorA.x, m_Selection.m_CursorA.y,
m_Selection.m_CursorB.x, m_Selection.m_CursorB.y)); m_Selection.m_CursorB.x, m_Selection.m_CursorB.y));
@@ -2593,8 +2600,7 @@ wxLayoutList::Draw(wxDC &dc,
wxLayoutObject * wxLayoutObject *
wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos, wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos,
wxPoint *cursorPos, wxPoint *cursorPos, bool *found)
bool *found)
{ {
// First, find the right line: // First, find the right line:
wxLayoutLine wxLayoutLine
@@ -2642,6 +2648,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos,
pos.x, pos.x,
NULL, NULL,
&foundinline); &foundinline);
if ( found ) if ( found )
*found = didFind && foundinline; *found = didFind && foundinline;
@@ -2650,7 +2657,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos,
} }
wxPoint wxPoint
wxLayoutList::GetSize(void) const wxLayoutList::GetSize() const
{ {
wxLayoutLine wxLayoutLine
*line = m_FirstLine, *line = m_FirstLine,
@@ -2745,6 +2752,7 @@ wxLayoutList::DrawCursor(wxDC &
SetUpdateRect(coords.x, coords.y+m_CursorSize.y-1); SetUpdateRect(coords.x, coords.y+m_CursorSize.y-1);
SetUpdateRect(coords.x, coords.y); SetUpdateRect(coords.x, coords.y);
} }
dc.SetLogicalFunction(wxCOPY); dc.SetLogicalFunction(wxCOPY);
//dc.SetBrush(wxNullBrush); //dc.SetBrush(wxNullBrush);
#endif // WXLAYOUT_USE_CARET/!WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET/!WXLAYOUT_USE_CARET
@@ -2754,7 +2762,9 @@ void
wxLayoutList::SetUpdateRect(CoordType x, CoordType y) wxLayoutList::SetUpdateRect(CoordType x, CoordType y)
{ {
if(m_UpdateRectValid) if(m_UpdateRectValid)
{
GrowRect(m_UpdateRect, x, y); GrowRect(m_UpdateRect, x, y);
}
else else
{ {
m_UpdateRect.x = x; m_UpdateRect.x = x;
@@ -2771,7 +2781,9 @@ wxLayoutList::StartSelection(const wxPoint& cposOrig, const wxPoint& spos)
wxPoint cpos(cposOrig); wxPoint cpos(cposOrig);
if ( cpos.x == -1 ) if ( cpos.x == -1 )
cpos = m_CursorPos; cpos = m_CursorPos;
WXLO_DEBUG((wxT("Starting selection at %ld/%ld"), cpos.x, cpos.y));
WXLO_DEBUG((wxT("Starting selection at %d/%d"), cpos.x, cpos.y));
m_Selection.m_CursorA = cpos; m_Selection.m_CursorA = cpos;
m_Selection.m_CursorB = cpos; m_Selection.m_CursorB = cpos;
m_Selection.m_ScreenA = spos; m_Selection.m_ScreenA = spos;
@@ -2789,7 +2801,7 @@ wxLayoutList::ContinueSelection(const wxPoint& cposOrig, const wxPoint& spos)
wxASSERT(m_Selection.m_selecting == true); wxASSERT(m_Selection.m_selecting == true);
wxASSERT(m_Selection.m_valid == false); 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_ScreenB = spos;
m_Selection.m_CursorB = cpos; m_Selection.m_CursorB = cpos;
@@ -2799,9 +2811,13 @@ void
wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos) wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos)
{ {
wxPoint cpos(cposOrig); wxPoint cpos(cposOrig);
if(cpos.x == -1) cpos = m_CursorPos; if(cpos.x == -1) cpos = m_CursorPos;
ContinueSelection(cpos, spos); ContinueSelection(cpos, spos);
WXLO_DEBUG((wxT("Ending selection at %ld/%ld"), cpos.x, cpos.y));
WXLO_DEBUG((wxT("Ending selection at %d/%d"), cpos.x, cpos.y));
// we always want m_CursorA <= m_CursorB! // we always want m_CursorA <= m_CursorB!
if( m_Selection.m_CursorA > m_Selection.m_CursorB ) if( m_Selection.m_CursorA > m_Selection.m_CursorB )
{ {
@@ -2814,13 +2830,16 @@ wxLayoutList::EndSelection(const wxPoint& cposOrig, const wxPoint& spos)
m_Selection.m_ScreenB = m_Selection.m_ScreenA; m_Selection.m_ScreenB = m_Selection.m_ScreenA;
m_Selection.m_ScreenA = help; m_Selection.m_ScreenA = help;
} }
m_Selection.m_selecting = false; m_Selection.m_selecting = false;
m_Selection.m_valid = true; m_Selection.m_valid = true;
/// In case we just clicked somewhere, the selection will have zero /// In case we just clicked somewhere, the selection will have zero
/// size, so we discard it immediately. /// size, so we discard it immediately.
if(m_Selection.m_CursorA == m_Selection.m_CursorB) if(m_Selection.m_CursorA == m_Selection.m_CursorB)
{
DiscardSelection(); DiscardSelection();
} }
}
void void
wxLayoutList::DiscardSelection() wxLayoutList::DiscardSelection()
@@ -2834,7 +2853,7 @@ wxLayoutList::DiscardSelection()
} }
bool bool
wxLayoutList::IsSelecting(void) const wxLayoutList::IsSelecting() const
{ {
return m_Selection.m_selecting; return m_Selection.m_selecting;
} }
@@ -2870,16 +2889,18 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
return 0; return 0;
CoordType y = line->GetLineNumber(); CoordType y = line->GetLineNumber();
if( if ( (m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y) || (m_Selection.m_CursorB.y < y && m_Selection.m_CursorA.y > y) )
|| (m_Selection.m_CursorB.y < y && m_Selection.m_CursorA.y > y) {
)
return 1; return 1;
}
else if (m_Selection.m_CursorA.y == y) else if (m_Selection.m_CursorA.y == y)
{ {
*from = m_Selection.m_CursorA.x; *from = m_Selection.m_CursorA.x;
if(m_Selection.m_CursorB.y == y) if(m_Selection.m_CursorB.y == y)
{
*to = m_Selection.m_CursorB.x; *to = m_Selection.m_CursorB.x;
}
else else
{ {
if(m_Selection.m_CursorB > m_Selection.m_CursorA) if(m_Selection.m_CursorB > m_Selection.m_CursorA)
@@ -2887,19 +2908,23 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
else else
*to = 0; *to = 0;
} }
if(*to < *from) if(*to < *from)
{ {
CoordType help = *to; CoordType help = *to;
*to = *from; *to = *from;
*from = help; *from = help;
} }
return -1; return -1;
} }
else if (m_Selection.m_CursorB.y == y) else if (m_Selection.m_CursorB.y == y)
{ {
*to = m_Selection.m_CursorB.x; *to = m_Selection.m_CursorB.x;
if (m_Selection.m_CursorA.y == y) if (m_Selection.m_CursorA.y == y)
{
*from = m_Selection.m_CursorA.x; *from = m_Selection.m_CursorA.x;
}
else else
{ {
if(m_Selection.m_CursorB > m_Selection.m_CursorA) if(m_Selection.m_CursorB > m_Selection.m_CursorA)
@@ -2907,6 +2932,7 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
else else
*from = line->GetLength(); *from = line->GetLength();
} }
if(*to < *from) if(*to < *from)
{ {
CoordType help = *to; CoordType help = *to;
@@ -2916,11 +2942,13 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
return -1; return -1;
} }
else else
{
return 0; return 0;
} }
}
void void
wxLayoutList::DeleteSelection(void) wxLayoutList::DeleteSelection()
{ {
if (! m_Selection.m_valid) if (! m_Selection.m_valid)
return; return;
@@ -2940,6 +2968,7 @@ wxLayoutList::DeleteSelection(void)
wxLayoutLine wxLayoutLine
* firstLine = GetLine(m_Selection.m_CursorA.y), * firstLine = GetLine(m_Selection.m_CursorA.y),
* lastLine = GetLine(m_Selection.m_CursorB.y); * lastLine = GetLine(m_Selection.m_CursorB.y);
// be a bit paranoid: // be a bit paranoid:
if(! firstLine || ! lastLine) if(! firstLine || ! lastLine)
return; return;
@@ -2950,8 +2979,11 @@ wxLayoutList::DeleteSelection(void)
wxLayoutLine *prevLine = firstLine->GetPreviousLine(), wxLayoutLine *prevLine = firstLine->GetPreviousLine(),
*nextLine = firstLine->GetNextLine(); *nextLine = firstLine->GetNextLine();
while(nextLine && nextLine != lastLine) while(nextLine && nextLine != lastLine)
{
nextLine = nextLine->DeleteLine(false, this); nextLine = nextLine->DeleteLine(false, this);
}
// Now nextLine = lastLine; // Now nextLine = lastLine;
Delete(1); // This joins firstLine and nextLine Delete(1); // This joins firstLine and nextLine
@@ -2998,8 +3030,7 @@ wxLayoutList::GetLine(CoordType index) const
CoordType lineNo = 0; CoordType lineNo = 0;
#endif #endif
for ( line = m_FirstLine; line && n-- > 0; line = for ( line = m_FirstLine; line && n-- > 0; line = line->GetNextLine() )
line->GetNextLine() )
{ {
#ifdef DEBUG #ifdef DEBUG
wxASSERT(line->GetLineNumber() == lineNo ); wxASSERT(line->GetLineNumber() == lineNo );
@@ -3022,13 +3053,14 @@ wxLayoutList::Copy(const wxPoint &from,
const wxPoint &to) const wxPoint &to)
{ {
wxLayoutLine wxLayoutLine
* firstLine = NULL, * firstLine,
* lastLine = NULL; * lastLine;
for(firstLine = m_FirstLine; for(firstLine = m_FirstLine;
firstLine && firstLine->GetLineNumber() < from.y; firstLine && firstLine->GetLineNumber() < from.y;
firstLine=firstLine->GetNextLine()) firstLine=firstLine->GetNextLine())
; ;
if(!firstLine || firstLine->GetLineNumber() != from.y) if(!firstLine || firstLine->GetLineNumber() != from.y)
return NULL; return NULL;
@@ -3036,6 +3068,7 @@ wxLayoutList::Copy(const wxPoint &from,
lastLine && lastLine->GetLineNumber() < to.y; lastLine && lastLine->GetLineNumber() < to.y;
lastLine=lastLine->GetNextLine()) lastLine=lastLine->GetNextLine())
; ;
if(!lastLine || lastLine->GetLineNumber() != to.y) if(!lastLine || lastLine->GetLineNumber() != to.y)
return NULL; return NULL;
@@ -3065,9 +3098,11 @@ wxLayoutList::Copy(const wxPoint &from,
line->Copy(llist); line->Copy(llist);
llist->LineBreak(); llist->LineBreak();
} }
// Extract objects from last line // Extract objects from last line
lastLine->Copy(llist, 0, to.x); lastLine->Copy(llist, 0, to.x);
} }
return llist; return llist;
} }
@@ -3101,19 +3136,21 @@ wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate)
exp->content.object->Write(string); exp->content.object->Write(string);
delete exp; delete exp;
} }
wxlo->SetLayoutData(string); wxlo->SetLayoutData(string);
} }
return llist; 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 void
wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc) wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc)
{ {
bool fontChanged = FALSE; bool fontChanged = false;
COPY_SI(family); COPY_SI(family);
COPY_SI(size); COPY_SI(size);
COPY_SI(style); COPY_SI(style);
@@ -3128,6 +3165,7 @@ wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc)
m_CurrentStyleInfo.m_fg_valid = true; m_CurrentStyleInfo.m_fg_valid = true;
dc.SetTextForeground(m_CurrentStyleInfo.m_fg); dc.SetTextForeground(m_CurrentStyleInfo.m_fg);
} }
if(si.m_bg_valid) if(si.m_bg_valid)
{ {
m_CurrentStyleInfo.m_bg = si.m_bg; m_CurrentStyleInfo.m_bg = si.m_bg;
@@ -3140,10 +3178,10 @@ wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc)
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
void void
wxLayoutList::Debug(void) wxLayoutList::Debug()
{ {
WXLO_DEBUG((wxT("Cursor is in line %d, screen pos = (%d, %d)"), WXLO_DEBUG((wxT("Cursor is in line %d, screen pos = (%d, %d)"),
m_CursorLine->GetLineNumber(), (int)m_CursorLine->GetLineNumber(),
m_CursorScreenPos.x, m_CursorScreenPos.y)); m_CursorScreenPos.x, m_CursorScreenPos.y));
wxLayoutLine *line; wxLayoutLine *line;
@@ -3190,6 +3228,7 @@ wxLayoutPrintout::ScaleDC(wxDC *dc)
* the screen text size. This page also draws lines of actual length 5cm * the screen text size. This page also draws lines of actual length 5cm
* on the page. * on the page.
*/ */
// Get the logical pixels per inch of screen and printer // Get the logical pixels per inch of screen and printer
int ppiScreenX, ppiScreenY; int ppiScreenX, ppiScreenY;
GetPPIScreen(&ppiScreenX, &ppiScreenY); GetPPIScreen(&ppiScreenX, &ppiScreenY);
@@ -3201,11 +3240,14 @@ wxLayoutPrintout::ScaleDC(wxDC *dc)
ppiScreenX = 100; ppiScreenX = 100;
ppiScreenY = 100; ppiScreenY = 100;
} }
wxUnusedVar(ppiScreenY);
if(ppiPrinterX == 0) // not yet set, need to guess if(ppiPrinterX == 0) // not yet set, need to guess
{ {
ppiPrinterX = 72; ppiPrinterX = 72;
ppiPrinterY = 72; ppiPrinterY = 72;
} }
wxUnusedVar(ppiPrinterY);
// This scales the DC so that the printout roughly represents the // This scales the DC so that the printout roughly represents the
// the screen scaling. The text point size _should_ be the right size // the screen scaling. The text point size _should_ be the right size
@@ -3220,12 +3262,14 @@ wxLayoutPrintout::ScaleDC(wxDC *dc)
int w, h; int w, h;
dc->GetSize(&w, &h); dc->GetSize(&w, &h);
GetPageSizePixels(&pageWidth, &pageHeight); GetPageSizePixels(&pageWidth, &pageHeight);
wxUnusedVar(pageHeight);
if(pageWidth != 0) // doesn't work always if(pageWidth != 0) // doesn't work always
{ {
// If printer pageWidth == current DC width, then this doesn't // If printer pageWidth == current DC width, then this doesn't
// change. But w might be the preview bitmap width, so scale down. // change. But w might be the preview bitmap width, so scale down.
scale = scale * (float)(w/(float)pageWidth); scale = scale * (float)(w/(float)pageWidth);
} }
dc->SetUserScale(scale, scale); dc->SetUserScale(scale, scale);
return scale; return scale;
} }
@@ -3244,16 +3288,18 @@ bool wxLayoutPrintout::OnPrintPage(int page)
WXLO_DEBUG((wxT("OnPrintPage(%d) printing from %d to %d"), page, top, WXLO_DEBUG((wxT("OnPrintPage(%d) printing from %d to %d"), page, top,
bottom)); bottom));
// SetDeviceOrigin() doesn't work here, so we need to manually // SetDeviceOrigin() doesn't work here, so we need to manually
// translate all coordinates. // translate all coordinates.
wxPoint translate(m_Offset.x,m_Offset.y-top); wxPoint translate(m_Offset.x,m_Offset.y-top);
m_llist->Draw(*dc, translate, top, bottom, TRUE /* clip strictly m_llist->Draw(*dc, translate, top, bottom, true /* clip strictly */);
*/);
return true; return true;
} }
else else
{
return false; return false;
} }
}
void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
{ {

View File

@@ -16,12 +16,12 @@
#include "kbList.h" #include "kbList.h"
#include <wx/wx.h> #include "wx/wx.h"
#include <wx/print.h> #include "wx/print.h"
#include <wx/printdlg.h> #include "wx/printdlg.h"
#include <wx/generic/printps.h> #include "wx/generic/printps.h"
#include <wx/generic/prntdlgg.h> #include "wx/generic/prntdlgg.h"
#include <wx/dataobj.h> #include "wx/dataobj.h"
// skip the following defines if embedded in M application // skip the following defines if embedded in M application
#ifndef M_BASEDIR #ifndef M_BASEDIR
@@ -87,12 +87,16 @@ enum wxLayoutObjectType
{ {
/// illegal object type, should never appear /// illegal object type, should never appear
WXLO_TYPE_INVALID = 0, WXLO_TYPE_INVALID = 0,
/// text object, containing normal text /// text object, containing normal text
WXLO_TYPE_TEXT, WXLO_TYPE_TEXT,
/// command object, containing font or colour changes /// command object, containing font or colour changes
WXLO_TYPE_CMD, WXLO_TYPE_CMD,
/// icon object, any kind of image /// icon object, any kind of image
WXLO_TYPE_ICON, WXLO_TYPE_ICON,
/// a linebreak, does not exist as an object /// a linebreak, does not exist as an object
WXLO_TYPE_LINEBREAK WXLO_TYPE_LINEBREAK
}; };
@@ -134,10 +138,10 @@ public:
struct UserData struct UserData
{ {
UserData() { m_refcount = 1; } UserData() { m_refcount = 1; }
inline void IncRef(void) { m_refcount++; } inline void IncRef() { m_refcount++; }
inline void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;} inline void DecRef() { m_refcount--; if(m_refcount == 0) delete this;}
inline void SetLabel(const wxString &l) { m_label = l; } inline void SetLabel(const wxString &l) { m_label = l; }
inline const wxString & GetLabel(void) const { return m_label; } inline const wxString & GetLabel() const { return m_label; }
private: private:
int m_refcount; int m_refcount;
wxString m_label; wxString m_label;
@@ -148,7 +152,7 @@ public:
}; };
/// return the type of this object /// return the type of this object
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; } virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_INVALID; }
/** Calculates the size of an object. /** Calculates the size of an object.
@param dc the wxDC to draw on @param dc the wxDC to draw on
@param llist the wxLayoutList @param llist the wxLayoutList
@@ -164,9 +168,9 @@ public:
*/ */
virtual void Draw(wxDC & /* dc */, virtual void Draw(wxDC & /* dc */,
wxPoint const & /* coords */, wxPoint const & /* coords */,
wxLayoutList *wxllist, wxLayoutList *WXUNUSED(wxllist),
CoordType begin = -1, CoordType WXUNUSED(begin) = -1,
CoordType end = -1) { } CoordType WXUNUSED(end) = -1) { }
/** Calculates and returns the size of the object. /** Calculates and returns the size of the object.
@param top where to store height above baseline @param top where to store height above baseline
@@ -177,24 +181,31 @@ public:
{ *top = 0; *bottom = 0; return wxPoint(0,0); } { *top = 0; *bottom = 0; return wxPoint(0,0); }
/// Return just the width of the object on the screen. /// Return just the width of the object on the screen.
virtual CoordType GetWidth(void) const { return 0; } virtual CoordType GetWidth() const { return 0; }
/// returns the number of cursor positions occupied by this object /// returns the number of cursor positions occupied by this object
virtual CoordType GetLength(void) const { return 1; } virtual CoordType GetLength() const { return 1; }
/** Returns the cursor offset relating to the screen x position /** Returns the cursor offset relating to the screen x position
relative to begin of object. relative to begin of object.
@param dc the wxDC to use for calculations @param dc the wxDC to use for calculations
@param xpos relative x position from head of object @param xpos relative x position from head of object
@return cursor coordinate offset @return cursor coordinate offset
*/ */
virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; } virtual CoordType GetOffsetScreen( wxDC & WXUNUSED(dc),
CoordType WXUNUSED(xpos) ) const
{
return 0;
}
/// constructor /// constructor
wxLayoutObject() { m_UserData = NULL; } wxLayoutObject() { m_UserData = NULL; }
/// delete the user data /// delete the user data
virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); } virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
virtual wxString DebugDump(void) const; virtual wxString DebugDump() const;
#endif #endif
/** Tells the object about some user data. This data is associated /** Tells the object about some user data. This data is associated
@@ -205,7 +216,9 @@ public:
{ {
if(m_UserData) if(m_UserData)
m_UserData->DecRef(); m_UserData->DecRef();
m_UserData = data; m_UserData = data;
if(m_UserData) if(m_UserData)
m_UserData->IncRef(); m_UserData->IncRef();
} }
@@ -214,17 +227,18 @@ public:
Increments the object's reference count. When no longer needed, Increments the object's reference count. When no longer needed,
caller must call DecRef() on the pointer returned. caller must call DecRef() on the pointer returned.
*/ */
UserData * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; } 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 /** Clipboard support function. Read and write objects to
strings. */ strings. */
//@{ //@{
/// Writes the object to the string. /// Writes the object to the string.
virtual void Write(wxString &ostr) = 0; virtual void Write(wxString &ostr) = 0;
/** Reads an object. /** Reads an object.
@param str stream to read from, will bee changed @param str stream to read from, will bee changed
@return true on success @return true on success
@@ -232,7 +246,7 @@ public:
static wxLayoutObject *Read(wxString &istr); static wxLayoutObject *Read(wxString &istr);
//@} //@}
/// returns TRUE if the object is shown on the screen (i.e. not cmd object) /// returns true if the object is shown on the screen (i.e. not cmd object)
bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD; } bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD; }
protected: protected:
@@ -248,6 +262,7 @@ KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject);
/// An illegal iterator to save typing. /// An illegal iterator to save typing.
#define NULLIT (wxLayoutObjectList::iterator(NULL)) #define NULLIT (wxLayoutObjectList::iterator(NULL))
/// The iterator type. /// The iterator type.
typedef wxLayoutObjectList::iterator wxLOiterator; typedef wxLayoutObjectList::iterator wxLOiterator;
@@ -263,20 +278,23 @@ class wxLayoutObjectText : public wxLayoutObject
public: public:
wxLayoutObjectText(const wxString &txt = wxEmptyString); wxLayoutObjectText(const wxString &txt = wxEmptyString);
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
wxLayoutList *wxllist, wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1); CoordType end = -1);
/** Calculates and returns the size of the object. /** Calculates and returns the size of the object.
@param top where to store height above baseline @param top where to store height above baseline
@param bottom where to store height below baseline @param bottom where to store height below baseline
@return the size of the object's box in pixels @return the size of the object's box in pixels
*/ */
virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const; virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
/// Return just the width of the object on the screen. /// Return just the width of the object on the screen.
virtual CoordType GetWidth(void) const { return m_Width; } virtual CoordType GetWidth() const { return m_Width; }
/** Returns the cursor offset relating to the screen x position /** Returns the cursor offset relating to the screen x position
relative to begin of object. relative to begin of object.
@param dc the wxDC to use for calculations @param dc the wxDC to use for calculations
@@ -289,23 +307,28 @@ public:
static wxLayoutObjectText *Read(wxString &istr); static wxLayoutObjectText *Read(wxString &istr);
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
virtual wxString DebugDump(void) const; virtual wxString DebugDump() const;
#endif #endif
virtual CoordType GetLength(void) const { return wxStrlen(m_Text.c_str()); } virtual CoordType GetLength() const { return wxStrlen(m_Text.c_str()); }
// for editing: // for editing:
wxString & GetText(void) { return m_Text; } wxString & GetText() { return m_Text; }
void SetText(wxString const &text) { m_Text = text; } void SetText(wxString const &text) { m_Text = text; }
/** Makes a copy of this object. /** Makes a copy of this object.
*/ */
virtual wxLayoutObject *Copy(void); virtual wxLayoutObject *Copy();
private: private:
wxString m_Text; wxString m_Text;
/// size of the box containing text /// size of the box containing text
long m_Width, m_Height; long m_Width, m_Height;
/// Height above baseline. /// Height above baseline.
long m_Top; long m_Top;
/// Height below baseline. /// Height below baseline.
long m_Bottom; long m_Bottom;
}; };
@@ -325,7 +348,7 @@ public:
~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; } ~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; }
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
wxLayoutList *wxllist, wxLayoutList *wxllist,
@@ -338,15 +361,19 @@ public:
@return the size of the object's box in pixels @return the size of the object's box in pixels
*/ */
virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const; virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
/// Return just the width of the object on the screen. /// Return just the width of the object on the screen.
virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); } virtual CoordType GetWidth() const { return m_Icon->GetWidth(); }
// return a pointer to the icon // return a pointer to the icon
wxBitmap *GetIcon(void) const { return m_Icon; } wxBitmap *GetIcon() const { return m_Icon; }
/** Makes a copy of this object. /** Makes a copy of this object.
*/ */
virtual wxLayoutObject *Copy(void); virtual wxLayoutObject *Copy();
virtual void Write(wxString &ostr); virtual void Write(wxString &ostr);
static wxLayoutObjectIcon *Read(wxString &istr); static wxLayoutObjectIcon *Read(wxString &istr);
private: private:
wxBitmap *m_Icon; wxBitmap *m_Icon;
}; };
@@ -362,12 +389,14 @@ struct wxLayoutStyleInfo
int iul = -1, int iul = -1,
wxColour *fg = NULL, wxColour *fg = NULL,
wxColour *bg = NULL); wxColour *bg = NULL);
wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right); wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
wxColour & GetBGColour() { return m_bg; } wxColour & GetBGColour() { return m_bg; }
/// Font change parameters. /// Font change parameters.
int size, family, style, weight, underline; int size, family, style, weight, underline;
/// Colours /// Colours
wxColour m_bg, m_fg; wxColour m_bg, m_fg;
int m_fg_valid, m_bg_valid; // bool, but must be int! int m_fg_valid, m_bg_valid; // bool, but must be int!
@@ -385,6 +414,7 @@ public:
m_Font = new wxFont(m_Size, m_Family, m_Font = new wxFont(m_Size, m_Family,
m_Style, m_Weight, m_Underline); m_Style, m_Weight, m_Underline);
} }
bool Matches(int family, int size, int style, int weight, bool Matches(int family, int size, int style, int weight,
bool underline) const bool underline) const
{ {
@@ -392,11 +422,13 @@ public:
&& style == m_Style && weight == m_Weight && style == m_Style && weight == m_Weight
&& underline == m_Underline; && underline == m_Underline;
} }
wxFont & GetFont(void) { return *m_Font; }
wxFont & GetFont() { return *m_Font; }
~wxFontCacheEntry() ~wxFontCacheEntry()
{ {
delete m_Font; delete m_Font;
} }
private: private:
wxFont *m_Font; wxFont *m_Font;
@@ -412,11 +444,13 @@ class wxFontCache
public: public:
wxFont & GetFont(int family, int size, int style, int weight, wxFont & GetFont(int family, int size, int style, int weight,
bool underline); bool underline);
wxFont & GetFont(wxLayoutStyleInfo const &si) wxFont & GetFont(wxLayoutStyleInfo const &si)
{ {
return GetFont(si.family, si.size, si.style, si.weight, return GetFont(si.family, si.size, si.style, si.weight,
si.underline != 0); si.underline != 0);
} }
private: private:
wxFCEList m_FontList; wxFCEList m_FontList;
}; };
@@ -431,12 +465,13 @@ private:
class wxLayoutObjectCmd : public wxLayoutObject class wxLayoutObjectCmd : public wxLayoutObject
{ {
public: public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } virtual wxLayoutObjectType GetType() const { return WXLO_TYPE_CMD; }
virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Layout(wxDC &dc, wxLayoutList *llist);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
wxLayoutList *wxllist, wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1); CoordType end = -1);
wxLayoutObjectCmd(int family = -1, wxLayoutObjectCmd(int family = -1,
int size = -1, int size = -1,
int style = -1, int style = -1,
@@ -444,15 +479,17 @@ public:
int underline = -1, int underline = -1,
wxColour *fg = NULL, wxColour *fg = NULL,
wxColour *bg = NULL); wxColour *bg = NULL);
wxLayoutObjectCmd(const wxLayoutStyleInfo &si); wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
~wxLayoutObjectCmd(); ~wxLayoutObjectCmd();
/** Stores the current style in the styleinfo structure */ /** Stores the current style in the styleinfo structure */
wxLayoutStyleInfo * GetStyle(void) const; wxLayoutStyleInfo * GetStyle() const;
/** Makes a copy of this object. /** Makes a copy of this object.
*/ */
virtual wxLayoutObject *Copy(void); virtual wxLayoutObject *Copy();
virtual void Write(wxString &ostr); virtual void Write(wxString &ostr);
static wxLayoutObjectCmd *Read(wxString &istr); static wxLayoutObjectCmd *Read(wxString &istr);
private: private:
wxLayoutStyleInfo *m_StyleInfo; wxLayoutStyleInfo *m_StyleInfo;
}; };
@@ -531,7 +568,7 @@ public:
/** This function wraps the line: breaks it at a suitable point /** This function wraps the line: breaks it at a suitable point
and merges it with the next. and merges it with the next.
@param wrapmargin @param wrapmargin
@return TRUE if broken @return true if broken
*/ */
bool Wrap(CoordType wrapmargin, wxLayoutList *llist); bool Wrap(CoordType wrapmargin, wxLayoutList *llist);
@@ -589,14 +626,13 @@ public:
functions to export the list. functions to export the list.
@return iterator to the first object @return iterator to the first object
*/ */
wxLayoutObjectList::iterator GetFirstObject(void) const wxLayoutObjectList::iterator GetFirstObject() const
{ {
return m_ObjectList.begin(); return m_ObjectList.begin();
} }
/** Get the last object in the list. /// Get the last object in the list.
*/ wxLayoutObjectList::iterator GetLastObject() const
wxLayoutObjectList::iterator GetLastObject(void) const
{ {
return m_ObjectList.tail(); return m_ObjectList.tail();
} }
@@ -611,11 +647,12 @@ public:
/** Return the line number of this line. /** Return the line number of this line.
@return the line number @return the line number
*/ */
inline CoordType GetLineNumber(void) const { return m_LineNumber; } inline CoordType GetLineNumber() const { return m_LineNumber; }
/** Return the length of the line. /** Return the length of the line.
@return line lenght in cursor positions @return line lenght in cursor positions
*/ */
inline CoordType GetLength(void) const { return m_Length; } inline CoordType GetLength() const { return m_Length; }
//@} //@}
/**@name Drawing and Layout */ /**@name Drawing and Layout */
@@ -645,7 +682,8 @@ public:
wxPoint *cursorSize = NULL, wxPoint *cursorSize = NULL,
wxLayoutStyleInfo *cursorStyle = NULL, wxLayoutStyleInfo *cursorStyle = NULL,
int cx = 0, int cx = 0,
bool suppressStyleUpdate = FALSE); bool suppressStyleUpdate = false);
/** This function finds an object belonging to a given cursor /** This function finds an object belonging to a given cursor
position. It assumes that Layout() has been called before. position. It assumes that Layout() has been called before.
@param dc the wxDC to use for calculations @param dc the wxDC to use for calculations
@@ -658,6 +696,7 @@ public:
wxLayoutObject * FindObjectScreen(wxDC &dc, wxLayoutObject * FindObjectScreen(wxDC &dc,
CoordType xpos, CoordType xpos,
bool *found = NULL); bool *found = NULL);
/** This sets the style info for the beginning of this line. /** This sets the style info for the beginning of this line.
@param si styleinfo structure @param si styleinfo structure
*/ */
@@ -669,23 +708,29 @@ public:
/**@name List traversal */ /**@name List traversal */
//@{ //@{
/// Returns pointer to next line. /// Returns pointer to next line.
wxLayoutLine *GetNextLine(void) const { return m_Next; } wxLayoutLine *GetNextLine() const { return m_Next; }
/// Returns pointer to previous line. /// Returns pointer to previous line.
wxLayoutLine *GetPreviousLine(void) const { return m_Previous; } wxLayoutLine *GetPreviousLine() const { return m_Previous; }
/// Sets the link to the next line. /// Sets the link to the next line.
void SetNext(wxLayoutLine *next) void SetNext(wxLayoutLine *next)
{ m_Next = next; if(next) next->m_Previous = this; } { m_Next = next; if(next) next->m_Previous = this; }
/// Sets the link to the previous line. /// Sets the link to the previous line.
void SetPrevious(wxLayoutLine *previous) void SetPrevious(wxLayoutLine *previous)
{ m_Previous = previous; if(previous) previous->m_Next = this; } { m_Previous = previous; if(previous) previous->m_Next = this; }
//@} //@}
/// Returns the position of this line on the canvas. /// Returns the position of this line on the canvas.
wxPoint GetPosition(void) const { return m_Position; } wxPoint GetPosition() const { return m_Position; }
/// Returns the height of this line. /// Returns the height of this line.
CoordType GetHeight(void) const { return m_Height; } CoordType GetHeight() const { return m_Height; }
/// Returns the width of this line. /// Returns the width of this line.
CoordType GetWidth(void) const { return m_Width; } CoordType GetWidth() const { return m_Width; }
/// Recalculates the position of this line on the canvas. /// Recalculates the position of this line on the canvas.
wxPoint RecalculatePosition(wxLayoutList *llist); wxPoint RecalculatePosition(wxLayoutList *llist);
@@ -699,12 +744,13 @@ public:
CoordType to = -1); CoordType to = -1);
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
void Debug(void) const; void Debug() const;
#endif #endif
wxLayoutStyleInfo const & GetStyleInfo() const { return m_StyleInfo; } wxLayoutStyleInfo const & GetStyleInfo() const { return m_StyleInfo; }
/// Returns dirty state /// Returns dirty state
bool IsDirty(void) const { return m_Dirty; } bool IsDirty() const { return m_Dirty; }
/** Marks this line as diry. /** Marks this line as diry.
@param left xpos from where it is dirty or -1 for all @param left xpos from where it is dirty or -1 for all
*/ */
@@ -719,6 +765,7 @@ public:
m_Dirty = true; m_Dirty = true;
if(m_Next) m_Next->MarkDirty(); if(m_Next) m_Next->MarkDirty();
} }
/// Reset the dirty flag /// Reset the dirty flag
void MarkClean() { m_Dirty = false; m_updateLeft = -1; } void MarkClean() { m_Dirty = false; m_updateLeft = -1; }
@@ -732,39 +779,55 @@ private:
dirty. dirty.
@param height new height @param height new height
*/ */
void SetHeight(CoordType height, wxLayoutList *llist) void SetHeight( CoordType height, wxLayoutList * WXUNUSED(llist) )
{ m_Height = height; MarkDirty(); } {
m_Height = height; MarkDirty();
}
/** Updates the line numbers. */ /** Updates the line numbers. */
void ReNumber(void); void ReNumber();
//@} //@}
private: private:
/// The line number. /// The line number.
CoordType m_LineNumber; CoordType m_LineNumber;
/// The line length in cursor positions. /// The line length in cursor positions.
CoordType m_Length; CoordType m_Length;
/// The total height of the line. /// The total height of the line.
CoordType m_Height; CoordType m_Height;
/// The total width of the line on screen. /// The total width of the line on screen.
CoordType m_Width; CoordType m_Width;
/// The baseline for drawing objects /// The baseline for drawing objects
CoordType m_BaseLine; CoordType m_BaseLine;
/// The position on the canvas. /// The position on the canvas.
wxPoint m_Position; wxPoint m_Position;
/// The list of objects /// The list of objects
wxLayoutObjectList m_ObjectList; wxLayoutObjectList m_ObjectList;
/// Have we been changed since the last layout? /// Have we been changed since the last layout?
bool m_Dirty; bool m_Dirty;
/// The coordinate of the left boundary of the update rectangle (if m_Dirty) /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
CoordType m_updateLeft; CoordType m_updateLeft;
/// Pointer to previous line if it exists. /// Pointer to previous line if it exists.
wxLayoutLine *m_Previous; wxLayoutLine *m_Previous;
/// Pointer to next line if it exists. /// Pointer to next line if it exists.
wxLayoutLine *m_Next; wxLayoutLine *m_Next;
/// A StyleInfo structure, holding the current settings. /// A StyleInfo structure, holding the current settings.
wxLayoutStyleInfo m_StyleInfo; wxLayoutStyleInfo m_StyleInfo;
/// Just to suppress gcc compiler warnings. /// Just to suppress gcc compiler warnings.
friend class dummy; friend class dummy;
private: private:
wxLayoutLine(const wxLayoutLine &); wxLayoutLine(const wxLayoutLine &);
}; };
@@ -784,6 +847,7 @@ class wxLayoutList
public: public:
/// Constructor. /// Constructor.
wxLayoutList(); wxLayoutList();
/// Destructor. /// Destructor.
~wxLayoutList(); ~wxLayoutList();
@@ -800,17 +864,20 @@ public:
int underline=0, int underline=0,
wxColour *fg=NULL, wxColour *fg=NULL,
wxColour *bg=NULL); wxColour *bg=NULL);
/// Empty: clear the list but leave font settings. /// Empty: clear the list but leave font settings.
void Empty(void); void Empty();
/** Enable or disable auto-formatting. Normally, while editing this /** Enable or disable auto-formatting. Normally, while editing this
should be enabled which is the default. While should be enabled which is the default. While
inserting/deleting lots of text, it makes sense to temporarily inserting/deleting lots of text, it makes sense to temporarily
disable this. disable this.
@param enable TRUE to enable, FALSE to disable @param enable true to enable, false to disable
*/ */
void SetAutoFormatting(bool enable = TRUE)
void SetAutoFormatting(bool enable = true)
{ m_AutoFormat = enable; } { m_AutoFormat = enable; }
/**@name Cursor Management */ /**@name Cursor Management */
//@{ //@{
/** Set new cursor position. /** Set new cursor position.
@@ -818,16 +885,19 @@ public:
@return bool if it could be set @return bool if it could be set
*/ */
bool MoveCursorTo(wxPoint const &p); bool MoveCursorTo(wxPoint const &p);
/** Move cursor up or down. /** Move cursor up or down.
@param n @param n
@return bool if it could be moved @return bool if it could be moved
*/ */
bool MoveCursorVertically(int n); bool MoveCursorVertically(int n);
/** Move cursor left or right. /** Move cursor left or right.
@param n = number of positions to move @param n = number of positions to move
@return bool if it could be moved @return bool if it could be moved
*/ */
bool MoveCursorHorizontally(int n); bool MoveCursorHorizontally(int n);
/** Move cursor to the left or right counting in words /** Move cursor to the left or right counting in words
@param n = number of positions in words @param n = number of positions in words
@param untilNext: puts the cursor at the start of the next word if true, @param untilNext: puts the cursor at the start of the next word if true,
@@ -837,26 +907,27 @@ public:
bool MoveCursorWord(int n, bool untilNext = true); bool MoveCursorWord(int n, bool untilNext = true);
/// Move cursor to end of line. /// Move cursor to end of line.
void MoveCursorToEndOfLine(void) void MoveCursorToEndOfLine()
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x); MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
} }
/// Move cursor to the start of line. /// Move cursor to the start of line.
void MoveCursorToBeginOfLine(void) void MoveCursorToBeginOfLine()
{ MoveCursorHorizontally(-m_CursorPos.x); } { MoveCursorHorizontally(-m_CursorPos.x); }
/// get the number of lines in the list /// get the number of lines in the list
size_t GetNumLines() const { return m_numLines; } size_t GetNumLines() const { return m_numLines; }
/// Returns current cursor position. /// Returns current cursor position.
const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; } const wxPoint &GetCursorPos(wxDC & WXUNUSED(dc) ) const
{ return m_CursorPos; }
const wxPoint &GetCursorPos() const { return m_CursorPos; } const wxPoint &GetCursorPos() const { return m_CursorPos; }
wxLayoutLine * GetCursorLine(void) { return m_CursorLine; } wxLayoutLine * GetCursorLine() { return m_CursorLine; }
/// move cursor to the end of text /// move cursor to the end of text
void MoveCursorToEnd(void) void MoveCursorToEnd()
{ {
MoveCursorTo(wxPoint(0, GetNumLines() - 1)); MoveCursorTo(wxPoint(0, GetNumLines() - 1));
MoveCursorToEndOfLine(); MoveCursorToEndOfLine();
@@ -870,13 +941,15 @@ public:
//@{ //@{
/// Insert text at current cursor position. /// Insert text at current cursor position.
bool Insert(wxString const &text); bool Insert(wxString const &text);
/// Insert some other object at current cursor position. /// Insert some other object at current cursor position.
bool Insert(wxLayoutObject *obj); bool Insert(wxLayoutObject *obj);
/// Inserts objects at current cursor positions /// Inserts objects at current cursor positions
bool Insert(wxLayoutList *llist); bool Insert(wxLayoutList *llist);
/// Inserts a linebreak at current cursor position. /// Inserts a linebreak at current cursor position.
bool LineBreak(void); bool LineBreak();
/** Wraps the current line. Searches to the left of the cursor to /** Wraps the current line. Searches to the left of the cursor to
break the line. Does nothing if the cursor position is before break the line. Does nothing if the cursor position is before
the break position parameter. the break position parameter.
@@ -903,13 +976,14 @@ public:
int DeleteLines(int n); int DeleteLines(int n);
/// Delete to end of line. /// Delete to end of line.
void DeleteToEndOfLine(void) void DeleteToEndOfLine()
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
Delete(m_CursorLine->GetLength()-m_CursorPos.x); Delete(m_CursorLine->GetLength()-m_CursorPos.x);
} }
/// Delete to begin of line. /// Delete to begin of line.
void DeleteToBeginOfLine(void) void DeleteToBeginOfLine()
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
CoordType n = m_CursorPos.x; CoordType n = m_CursorPos.x;
@@ -923,7 +997,7 @@ public:
/** Delete the next word. /** Delete the next word.
*/ */
void DeleteWord(void) void DeleteWord()
{ {
wxASSERT(m_CursorLine); wxASSERT(m_CursorLine);
m_CursorLine->DeleteWord(m_CursorPos.x); m_CursorLine->DeleteWord(m_CursorPos.x);
@@ -945,31 +1019,40 @@ public:
int weight, int underline, int weight, int underline,
wxColour *fg, wxColour *fg,
wxColour *bg); wxColour *bg);
/// sets font parameters, colours by name /// sets font parameters, colours by name
void SetFont(int family=-1, int size = -1, int style=-1, void SetFont(int family=-1, int size = -1, int style=-1,
int weight=-1, int underline = -1, int weight=-1, int underline = -1,
wxChar const *fg = NULL, wxChar const *fg = NULL,
wxChar const *bg = NULL); wxChar const *bg = NULL);
/// changes to the next larger font size /// changes to the next larger font size
inline void SetFontLarger(void) inline void SetFontLarger()
{ SetFont(-1,(12*m_CurrentStyleInfo.size)/10); } { SetFont(-1,(12*m_CurrentStyleInfo.size)/10); }
/// changes to the next smaller font size /// changes to the next smaller font size
inline void SetFontSmaller(void) inline void SetFontSmaller()
{ SetFont(-1,(10*m_CurrentStyleInfo.size)/12); } { SetFont(-1,(10*m_CurrentStyleInfo.size)/12); }
/// set font family /// set font family
inline void SetFontFamily(int family) { SetFont(family); } inline void SetFontFamily(int family) { SetFont(family); }
/// set font size /// set font size
inline void SetFontSize(int size) { SetFont(-1,size); } inline void SetFontSize(int size) { SetFont(-1,size); }
/// set font style /// set font style
inline void SetFontStyle(int style) { SetFont(-1,-1,style); } inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
/// set font weight /// set font weight
inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); } inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
/// toggle underline flag /// toggle underline flag
inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); } inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
/// set font colours by name /// set font colours by name
inline void SetFontColour(wxChar const *fg, wxChar const *bg = NULL) inline void SetFontColour(wxChar const *fg, wxChar const *bg = NULL)
{ SetFont(-1,-1,-1,-1,-1,fg,bg); } { SetFont(-1,-1,-1,-1,-1,fg,bg); }
/// set font colours by colour /// set font colours by colour
inline void SetFontColour(wxColour *fg, wxColour *bg = NULL) inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
{ SetFont(-1,-1,-1,-1,-1,fg,bg); } { SetFont(-1,-1,-1,-1,-1,fg,bg); }
@@ -980,15 +1063,17 @@ public:
anywhere. anywhere.
@return the default settings of the list @return the default settings of the list
*/ */
wxLayoutStyleInfo &GetDefaultStyleInfo(void) { return m_DefaultStyleInfo ; } wxLayoutStyleInfo &GetDefaultStyleInfo() { return m_DefaultStyleInfo ; }
wxLayoutStyleInfo &GetStyleInfo(void) { return m_CurrentStyleInfo ; } wxLayoutStyleInfo &GetStyleInfo() { return m_CurrentStyleInfo ; }
const wxLayoutStyleInfo &GetStyleInfo(void) const { return m_CurrentStyleInfo ; } const wxLayoutStyleInfo &GetStyleInfo() const { return m_CurrentStyleInfo ; }
const wxLayoutStyleInfo &GetCursorStyleInfo(void) const { return m_CursorStyleInfo ; } const wxLayoutStyleInfo &GetCursorStyleInfo() const { return m_CursorStyleInfo ; }
/// is the current font underlined? /// is the current font underlined?
bool IsFontUnderlined() const { return GetCursorStyleInfo().underline != 0; } bool IsFontUnderlined() const { return GetCursorStyleInfo().underline != 0; }
/// is the current font bold? /// is the current font bold?
bool IsFontBold() const { return GetCursorStyleInfo().weight == wxBOLD; } bool IsFontBold() const { return GetCursorStyleInfo().weight == wxBOLD; }
/// is the current font italic? /// is the current font italic?
bool IsFontItalic() const { return GetCursorStyleInfo().style == wxITALIC; } bool IsFontItalic() const { return GetCursorStyleInfo().style == wxITALIC; }
@@ -1036,9 +1121,9 @@ public:
/** Ensure that the whole list will be recalculate on the next call /** Ensure that the whole list will be recalculate on the next call
to Layout() or Draw(). to Layout() or Draw().
@param redrawAll TRUE or FALSE to reset it @param redrawAll true or false to reset it
*/ */
void ForceTotalLayout(bool redrawAll = TRUE) void ForceTotalLayout(bool redrawAll = true)
{ m_ReLayoutAll = redrawAll; } { m_ReLayoutAll = redrawAll; }
/** Returns the screen coordinates relating to a given cursor /** Returns the screen coordinates relating to a given cursor
@@ -1063,11 +1148,11 @@ public:
@return a wxPoint holding the maximal x/y coordinates used for @return a wxPoint holding the maximal x/y coordinates used for
drawing drawing
*/ */
wxPoint GetSize(void) const; wxPoint GetSize() const;
/** Returns the cursor position on the screen. /** Returns the cursor position on the screen.
*/ */
wxPoint GetCursorScreenPos(void) const; wxPoint GetCursorScreenPos() const;
/** Draws the cursor. /** Draws the cursor.
@param active If true, draw a bold cursor to mark window as @param active If true, draw a bold cursor to mark window as
@@ -1096,11 +1181,13 @@ public:
@param y vertical coordinate to include in rectangle @param y vertical coordinate to include in rectangle
*/ */
void SetUpdateRect(CoordType x, CoordType y); void SetUpdateRect(CoordType x, CoordType y);
/** Called by the objects to update the update rectangle. /** Called by the objects to update the update rectangle.
@param p a point to include in it @param p a point to include in it
*/ */
void SetUpdateRect(const wxPoint &p) void SetUpdateRect(const wxPoint &p)
{ SetUpdateRect(p.x,p.y); } { SetUpdateRect(p.x,p.y); }
/// adds the cursor position to the update rectangle /// adds the cursor position to the update rectangle
void AddCursorPosToUpdateRect() void AddCursorPosToUpdateRect()
{ {
@@ -1110,10 +1197,12 @@ public:
//#else - the caret will take care of refreshing itself //#else - the caret will take care of refreshing itself
#endif // !WXLAYOUT_USE_CARET #endif // !WXLAYOUT_USE_CARET
} }
/// Invalidates the update rectangle. /// Invalidates the update rectangle.
void InvalidateUpdateRect(void) { m_UpdateRectValid = false; } void InvalidateUpdateRect() { m_UpdateRectValid = false; }
/// Returns the update rectangle. /// Returns the update rectangle.
const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; } const wxRect *GetUpdateRect() const { return &m_UpdateRect; }
//@} //@}
/// get the current cursor size /// get the current cursor size
@@ -1122,7 +1211,7 @@ public:
/**@name For exporting one object after another. */ /**@name For exporting one object after another. */
//@{ //@{
/** Returns a pointer to the first line in the list. */ /** Returns a pointer to the first line in the list. */
wxLayoutLine *GetFirstLine(void) wxLayoutLine *GetFirstLine()
{ {
wxASSERT(m_FirstLine); wxASSERT(m_FirstLine);
return m_FirstLine; return m_FirstLine;
@@ -1132,18 +1221,24 @@ public:
/// Begin selecting text /// Begin selecting text
void StartSelection(const wxPoint& cpos = wxPoint(-1,-1), void StartSelection(const wxPoint& cpos = wxPoint(-1,-1),
const wxPoint& spos = wxPoint(-1,-1)); const wxPoint& spos = wxPoint(-1,-1));
// Continue selecting text // Continue selecting text
void ContinueSelection(const wxPoint& cpos = wxPoint(-1,-1), void ContinueSelection(const wxPoint& cpos = wxPoint(-1,-1),
const wxPoint& spos = wxPoint(-1,-1)); const wxPoint& spos = wxPoint(-1,-1));
/// End selecting text. /// End selecting text.
void EndSelection(const wxPoint& cpos = wxPoint(-1,-1), void EndSelection(const wxPoint& cpos = wxPoint(-1,-1),
const wxPoint& spos = wxPoint(-1,-1)); const wxPoint& spos = wxPoint(-1,-1));
/// Discard the current selection /// Discard the current selection
void DiscardSelection(); void DiscardSelection();
/// Are we still selecting text? /// Are we still selecting text?
bool IsSelecting(void) const; bool IsSelecting() const;
/// Is the given point (text coords) selected? /// Is the given point (text coords) selected?
bool IsSelected(const wxPoint &cursor) const; bool IsSelected(const wxPoint &cursor) const;
/// Do we have a non null selection? /// Do we have a non null selection?
bool HasSelection() const bool HasSelection() const
{ return m_Selection.m_valid || m_Selection.m_selecting; } { return m_Selection.m_valid || m_Selection.m_selecting; }
@@ -1152,15 +1247,17 @@ public:
@param invalidate if true, the selection will be invalidated after this and can no longer be used. @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 @return Another layout list object holding the selection, must be freed by caller
*/ */
wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = TRUE); wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = true);
/// Delete selected bit /// Delete selected bit
void DeleteSelection(void); void DeleteSelection();
wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0), wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
const wxPoint &to = wxPoint(-1,-1)); const wxPoint &to = wxPoint(-1,-1));
/// starts highlighting of text for selections /// starts highlighting of text for selections
void StartHighlighting(wxDC &dc); void StartHighlighting(wxDC &dc);
/// ends highlighting of text for selections /// ends highlighting of text for selections
void EndHighlighting(wxDC &dc); void EndHighlighting(wxDC &dc);
@@ -1171,13 +1268,12 @@ public:
@param to set to last 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 @return 0 = not selected, 1 = fully selected, -1 = partially
selected selected
*/ */
int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to); int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
void ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc); void ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc);
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
void Debug(void); void Debug();
#endif #endif
// for wxLayoutLine usage only // for wxLayoutLine usage only
@@ -1195,34 +1291,43 @@ public:
private: private:
/// Clear the list. /// Clear the list.
void InternalClear(void); void InternalClear();
/// The list of lines. /// The list of lines.
wxLayoutLine *m_FirstLine; wxLayoutLine *m_FirstLine;
/// The number of lines in the list (store instead recalculating for speed) /// The number of lines in the list (store instead recalculating for speed)
size_t m_numLines; size_t m_numLines;
/// The update rectangle which needs to be refreshed: /// The update rectangle which needs to be refreshed:
wxRect m_UpdateRect; wxRect m_UpdateRect;
/// Is the update rectangle valid? /// Is the update rectangle valid?
bool m_UpdateRectValid; bool m_UpdateRectValid;
/// Shall we auto-format? /// Shall we auto-format?
bool m_AutoFormat; bool m_AutoFormat;
/// Shall we re-layout everything? /// Shall we re-layout everything?
bool m_ReLayoutAll; bool m_ReLayoutAll;
/**@name Cursor Management */ /**@name Cursor Management */
//@{ //@{
/// Where the text cursor (column,line) is. /// Where the text cursor (column,line) is.
wxPoint m_CursorPos; wxPoint m_CursorPos;
/// Where the cursor should be drawn. /// Where the cursor should be drawn.
wxPoint m_CursorScreenPos; wxPoint m_CursorScreenPos;
/// The line where the cursor is. /// The line where the cursor is.
wxLayoutLine *m_CursorLine; wxLayoutLine *m_CursorLine;
/// The size of the cursor. /// The size of the cursor.
wxPoint m_CursorSize; wxPoint m_CursorSize;
/// Has the cursor moved (is m_CursorScreenPos up to date)? /// Has the cursor moved (is m_CursorScreenPos up to date)?
bool m_movedCursor; bool m_movedCursor;
#ifdef WXLAYOUT_USE_CARET #ifdef WXLAYOUT_USE_CARET
/// the caret /// the caret
wxCaret *m_caret; wxCaret *m_caret;
@@ -1236,7 +1341,7 @@ private:
bool m_valid; bool m_valid;
bool m_selecting; bool m_selecting;
bool m_discarded; // may be TRUE only until the next redraw bool m_discarded; // may be true only until the next redraw
// returns true if we already have the screen coordinates of the // returns true if we already have the screen coordinates of the
// selection start and end // selection start and end
@@ -1253,10 +1358,13 @@ private:
//@{ //@{
/// this object manages the fonts for us /// this object manages the fonts for us
wxFontCache m_FontCache; wxFontCache m_FontCache;
/// the default setting: /// the default setting:
wxLayoutStyleInfo m_DefaultStyleInfo; wxLayoutStyleInfo m_DefaultStyleInfo;
/// the current setting: /// the current setting:
wxLayoutStyleInfo m_CurrentStyleInfo; wxLayoutStyleInfo m_CurrentStyleInfo;
/// the current setting: /// the current setting:
wxLayoutStyleInfo m_CursorStyleInfo; wxLayoutStyleInfo m_CursorStyleInfo;
//@} //@}
@@ -1279,6 +1387,7 @@ public:
// type safe wrappers // type safe wrappers
void SetLayoutData(const wxString& text) void SetLayoutData(const wxString& text)
{ SetData(text.length() + 1, text.c_str()); } { SetData(text.length() + 1, text.c_str()); }
const wxChar *GetLayoutData() const { return (const wxChar *)GetData(); } const wxChar *GetLayoutData() const { return (const wxChar *)GetData(); }
}; };
@@ -1301,6 +1410,7 @@ public:
wxLayoutPrintout(wxLayoutList *llist, wxLayoutPrintout(wxLayoutList *llist,
wxString const & title = wxString const & title =
_T("wxLayout Printout")); _T("wxLayout Printout"));
/// Destructor. /// Destructor.
~wxLayoutPrintout(); ~wxLayoutPrintout();
@@ -1335,17 +1445,23 @@ protected:
/* no longer used /* no longer used
virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno); virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
*/ */
private: private:
/// The list to print. /// The list to print.
wxLayoutList *m_llist; wxLayoutList *m_llist;
/// Title for PS file or window. /// Title for PS file or window.
wxString m_title; wxString m_title;
/// The real paper size. /// The real paper size.
int m_PageHeight, m_PageWidth; int m_PageHeight, m_PageWidth;
/// How much we actually print per page. /// How much we actually print per page.
int m_PrintoutHeight; int m_PrintoutHeight;
/// How many pages we need to print. /// How many pages we need to print.
int m_NumOfPages; int m_NumOfPages;
/// Top left corner where we start printing. /// Top left corner where we start printing.
wxPoint m_Offset; wxPoint m_Offset;
}; };

View File

@@ -45,6 +45,7 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str)
// VZ: I still don't like it... the string data may be shared... // VZ: I still don't like it... the string data may be shared...
wxChar * cptr = (wxChar *)str.c_str(); // const_cast wxChar * cptr = (wxChar *)str.c_str(); // const_cast
const wxChar * begin = cptr; const wxChar * begin = cptr;
wxUnusedVar(begin);
wxChar backup; wxChar backup;
for(;;) for(;;)
@@ -165,7 +166,7 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list)
m_si = list->GetDefaultStyleInfo(); m_si = list->GetDefaultStyleInfo();
m_line = list->GetFirstLine(); m_line = list->GetFirstLine();
m_iterator = m_line->GetFirstObject(); m_iterator = m_line->GetFirstObject();
m_FirstTime = TRUE; m_FirstTime = true;
} }
@@ -215,6 +216,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
else else
type = WXLO_TYPE_TEXT; type = WXLO_TYPE_TEXT;
} }
wxUnusedVar(type);
wxString *str = new wxString(); wxString *str = new wxString();
// text must be concatenated // text must be concatenated
@@ -250,7 +252,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
*str += wxLayoutExportCmdAsHTML( *str += wxLayoutExportCmdAsHTML(
*(wxLayoutObjectCmd const *)*status->m_iterator, *(wxLayoutObjectCmd const *)*status->m_iterator,
& status->m_si, status->m_FirstTime); & status->m_si, status->m_FirstTime);
status->m_FirstTime = FALSE; status->m_FirstTime = false;
break; break;
default: // ignore icons default: // ignore icons
; ;

View File

@@ -39,19 +39,19 @@
# include "strutil.h" # include "strutil.h"
#else #else
# ifdef __WXMSW__ # ifdef __WXMSW__
# include <wx/msw/private.h> # include "wx/msw/private.h"
# endif # endif
# include "wxlwindow.h" # include "wxlwindow.h"
# include "wxlparser.h" # include "wxlparser.h"
#endif #endif
#include <wx/clipbrd.h> #include "wx/clipbrd.h"
#include <wx/textctrl.h> #include "wx/textctrl.h"
#include <wx/dataobj.h> #include "wx/dataobj.h"
#ifdef WXLAYOUT_USE_CARET #ifdef WXLAYOUT_USE_CARET
# include <wx/caret.h> # include "wx/caret.h"
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
#include <ctype.h> #include <ctype.h>
@@ -130,7 +130,7 @@ END_EVENT_TABLE()
// function prototypes // 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); static bool IsDirectionKey(long keyCode);
// ============================================================================ // ============================================================================
@@ -184,14 +184,14 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
m_llist->SetCaret(caret); m_llist->SetCaret(caret);
#endif // WXLAYOUT_USE_CARET #endif // WXLAYOUT_USE_CARET
m_HaveFocus = FALSE; m_HaveFocus = false;
m_HandCursor = FALSE; m_HandCursor = false;
m_CursorVisibility = -1; m_CursorVisibility = -1;
SetCursor(wxCURSOR_IBEAM); SetCursor(wxCURSOR_IBEAM);
SetDirty(); SetDirty();
// at least under Windows, this should be the default behaviour // at least under Windows, this should be the default behaviour
m_AutoDeleteSelection = TRUE; m_AutoDeleteSelection = true;
} }
wxLayoutWindow::~wxLayoutWindow() wxLayoutWindow::~wxLayoutWindow()
@@ -217,7 +217,7 @@ wxLayoutWindow::Clear(int family,
//wxScrolledWindow::Clear(); //wxScrolledWindow::Clear();
ResizeScrollbars(true); ResizeScrollbars(true);
SetDirty(); SetDirty();
SetModified(FALSE); SetModified(false);
if ( m_Editable ) if ( m_Editable )
m_CursorVisibility = 1; m_CursorVisibility = 1;
@@ -243,9 +243,11 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
#ifndef __WXMSW__ #ifndef __WXMSW__
|| m_FocusFollowMode || m_FocusFollowMode
#endif #endif
) && (wxWindow::FindFocus() != this)
) )
&& (wxWindow::FindFocus() != this) )
{
SetFocus(); SetFocus();
}
wxPoint findPos; wxPoint findPos;
findPos.x = dc.DeviceToLogicalX(event.GetX()); findPos.x = dc.DeviceToLogicalX(event.GetX());
@@ -256,6 +258,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
if(findPos.x < 0) if(findPos.x < 0)
findPos.x = 0; findPos.x = 0;
if(findPos.y < 0) if(findPos.y < 0)
findPos.y = 0; findPos.y = 0;
@@ -276,6 +279,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X; xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X;
else else
xdelta = 0; xdelta = 0;
if(event.GetY() < WXLO_SCROLLMARGIN_Y) if(event.GetY() < WXLO_SCROLLMARGIN_Y)
ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY()); ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY());
else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y) else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y)
@@ -314,7 +318,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{ {
if(!m_HandCursor) if(!m_HandCursor)
SetCursor(wxCURSOR_HAND); SetCursor(wxCURSOR_HAND);
m_HandCursor = TRUE; m_HandCursor = true;
if(m_StatusBar && m_StatusFieldLabel != -1) if(m_StatusBar && m_StatusFieldLabel != -1)
{ {
const wxString &label = u->GetLabel(); const wxString &label = u->GetLabel();
@@ -330,7 +334,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
{ {
if(m_HandCursor) if(m_HandCursor)
SetCursor(wxCURSOR_IBEAM); SetCursor(wxCURSOR_IBEAM);
m_HandCursor = FALSE; m_HandCursor = false;
if( m_StatusBar && m_StatusFieldLabel != -1 && if( m_StatusBar && m_StatusFieldLabel != -1 &&
s_hasPutMessageInStatusBar ) s_hasPutMessageInStatusBar )
{ {
@@ -382,6 +386,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
if(m_CursorVisibility == -1) if(m_CursorVisibility == -1)
m_CursorVisibility = 1; m_CursorVisibility = 1;
#ifdef WXLAYOUT_USE_CARET #ifdef WXLAYOUT_USE_CARET
if ( m_CursorVisibility == 1 ) if ( m_CursorVisibility == 1 )
GetCaret()->Show(); GetCaret()->Show();
@@ -416,7 +421,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
break; break;
case WXLOWIN_MENU_MDOWN: case WXLOWIN_MENU_MDOWN:
Paste(TRUE); Paste(true);
break; break;
case WXLOWIN_MENU_DBLCLICK: case WXLOWIN_MENU_DBLCLICK:
@@ -464,7 +469,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
void void
wxLayoutWindow::OnChar(wxKeyEvent& event) wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
int keyCode = event.KeyCode(); int keyCode = event.GetKeyCode();
bool ctrlDown = event.ControlDown(); bool ctrlDown = event.ControlDown();
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
@@ -493,8 +498,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
&& !m_Selecting && !m_Selecting
&& m_llist->HasSelection() && m_llist->HasSelection()
&& ! IsDirectionKey(keyCode) && ! IsDirectionKey(keyCode)
&& ! (event.AltDown() || ctrlDown) && ! (event.AltDown() || ctrlDown) )
)
{ {
m_llist->DeleteSelection(); m_llist->DeleteSelection();
deletedSelection = true; deletedSelection = true;
@@ -506,7 +510,9 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
// just continue the old selection // just continue the old selection
if ( m_Selecting && event.ShiftDown() ) if ( m_Selecting && event.ShiftDown() )
{
m_llist->ContinueSelection(); m_llist->ContinueSelection();
}
else else
{ {
m_llist->DiscardSelection(); m_llist->DiscardSelection();
@@ -530,62 +536,78 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
*/ */
switch(keyCode) switch(keyCode)
{ {
case WXK_RIGHT: case WXK_RIGHT:
if ( ctrlDown ) if ( ctrlDown )
m_llist->MoveCursorWord(1); m_llist->MoveCursorWord(1);
else else
m_llist->MoveCursorHorizontally(1); m_llist->MoveCursorHorizontally(1);
break; break;
case WXK_LEFT: case WXK_LEFT:
if ( ctrlDown ) if ( ctrlDown )
m_llist->MoveCursorWord(-1); m_llist->MoveCursorWord(-1);
else else
m_llist->MoveCursorHorizontally(-1); m_llist->MoveCursorHorizontally(-1);
break; break;
case WXK_UP: case WXK_UP:
m_llist->MoveCursorVertically(-1); m_llist->MoveCursorVertically(-1);
break; break;
case WXK_DOWN: case WXK_DOWN:
m_llist->MoveCursorVertically(1); m_llist->MoveCursorVertically(1);
break; break;
case WXK_PRIOR: case WXK_PRIOR:
m_llist->MoveCursorVertically(-Y_SCROLL_PAGE); m_llist->MoveCursorVertically(-Y_SCROLL_PAGE);
break; break;
case WXK_NEXT: case WXK_NEXT:
m_llist->MoveCursorVertically(Y_SCROLL_PAGE); m_llist->MoveCursorVertically(Y_SCROLL_PAGE);
break; break;
case WXK_HOME: case WXK_HOME:
if ( ctrlDown ) if ( ctrlDown )
m_llist->MoveCursorTo(wxPoint(0, 0)); m_llist->MoveCursorTo(wxPoint(0, 0));
else else
m_llist->MoveCursorToBeginOfLine(); m_llist->MoveCursorToBeginOfLine();
break; break;
case WXK_END: case WXK_END:
if ( ctrlDown ) if ( ctrlDown )
m_llist->MoveCursorToEnd(); m_llist->MoveCursorToEnd();
else else
m_llist->MoveCursorToEndOfLine(); m_llist->MoveCursorToEndOfLine();
break; break;
default: default:
if(ctrlDown && ! IsEditable()) if(ctrlDown && ! IsEditable())
{
switch(keyCode) switch(keyCode)
{ {
case 'c': case 'c':
// this should work even in read-only mode // this should work even in read-only mode
Copy(TRUE, TRUE); Copy(true, true);
break; break;
case 's': // search case 's': // search
Find(wxEmptyString); Find(wxEmptyString);
break; break;
case 't': // search again case 't': // search again
FindAgain(); FindAgain();
break; break;
default: default:
// we don't handle it, maybe an accelerator? // we don't handle it, maybe an accelerator?
event.Skip(); event.Skip();
; ;
} }
}
else if( IsEditable() ) else if( IsEditable() )
{ {
/* First, handle control keys */ /* First, handle control keys */
@@ -593,11 +615,14 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
if(keyCode >= 'A' && keyCode <= 'Z') if(keyCode >= 'A' && keyCode <= 'Z')
keyCode = tolower(keyCode); keyCode = tolower(keyCode);
switch(keyCode) switch(keyCode)
{ {
case WXK_INSERT: case WXK_INSERT:
Copy(); Copy();
break; break;
case WXK_DELETE : case WXK_DELETE :
if(! deletedSelection) if(! deletedSelection)
{ {
@@ -605,6 +630,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
SetDirty(); SetDirty();
} }
break; break;
case 'd': case 'd':
if(! deletedSelection) // already done if(! deletedSelection) // already done
{ {
@@ -612,10 +638,12 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
SetDirty(); SetDirty();
} }
break; break;
case 'y': case 'y':
m_llist->DeleteLines(1); m_llist->DeleteLines(1);
SetDirty(); SetDirty();
break; break;
case 'h': // like backspace case 'h': // like backspace
if(m_llist->MoveCursorHorizontally(-1)) if(m_llist->MoveCursorHorizontally(-1))
{ {
@@ -623,45 +651,57 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
SetDirty(); SetDirty();
} }
break; break;
case 's': // search case 's': // search
Find(wxEmptyString); Find(wxEmptyString);
break; break;
case 't': // search again case 't': // search again
FindAgain(); FindAgain();
break; break;
case 'u': case 'u':
m_llist->DeleteToBeginOfLine(); m_llist->DeleteToBeginOfLine();
SetDirty(); SetDirty();
break; break;
case 'k': case 'k':
m_llist->DeleteToEndOfLine(); m_llist->DeleteToEndOfLine();
SetDirty(); SetDirty();
break; break;
case 'c': case 'c':
Copy(TRUE, TRUE); Copy(true, true);
break; break;
case 'v': case 'v':
Paste( TRUE ); Paste(true);
break; break;
case 'x': case 'x':
Cut(); Cut();
break; break;
case 'w': case 'w':
if(m_WrapMargin > 0) if(m_WrapMargin > 0)
m_llist->WrapLine(m_WrapMargin); m_llist->WrapLine(m_WrapMargin);
break; break;
case 'q': case 'q':
if(m_WrapMargin > 0) if(m_WrapMargin > 0)
m_llist->WrapAll(m_WrapMargin); m_llist->WrapAll(m_WrapMargin);
break; break;
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
case WXK_F1: case WXK_F1:
m_llist->SetFont(-1,-1,-1,-1,true); // underlined m_llist->SetFont(-1,-1,-1,-1,true); // underlined
break; break;
case 'l': case 'l':
Refresh(TRUE); Refresh(true);
break; break;
#endif #endif
default: default:
// we don't handle it, maybe an accelerator? // we don't handle it, maybe an accelerator?
event.Skip(); event.Skip();
@@ -677,6 +717,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
m_llist->DeleteWord(); m_llist->DeleteWord();
SetDirty(); SetDirty();
break; break;
default: default:
// we don't handle it, maybe an accelerator? // we don't handle it, maybe an accelerator?
event.Skip(); event.Skip();
@@ -691,29 +732,38 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
if(event.ShiftDown()) if(event.ShiftDown())
Paste(); Paste();
break; break;
case WXK_DELETE : case WXK_DELETE :
if(event.ShiftDown()) if(event.ShiftDown())
{
Cut(); Cut();
else }
if(! deletedSelection) else if(! deletedSelection)
{ {
m_llist->Delete(1); m_llist->Delete(1);
SetDirty(); SetDirty();
} }
break; break;
case WXK_BACK: // backspace case WXK_BACK: // backspace
if(! deletedSelection) if(! deletedSelection)
{
if(m_llist->MoveCursorHorizontally(-1)) if(m_llist->MoveCursorHorizontally(-1))
{ {
m_llist->Delete(1); m_llist->Delete(1);
SetDirty(); SetDirty();
} }
}
break; break;
case WXK_RETURN: case WXK_RETURN:
if (m_DoWordWrap && if (m_DoWordWrap &&
m_WrapMargin > 0 m_WrapMargin > 0
&& m_llist->GetCursorPos().x > m_WrapMargin ) && m_llist->GetCursorPos().x > m_WrapMargin )
{
m_llist->WrapLine(m_WrapMargin); m_llist->WrapLine(m_WrapMargin);
}
m_llist->LineBreak(); m_llist->LineBreak();
SetDirty(); SetDirty();
break; break;
@@ -732,10 +782,8 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
break; break;
default: default:
if((!(event.ControlDown() || event.AltDown() if ( ( !(event.ControlDown() || event.AltDown()) )
)) && (keyCode < 256 && keyCode >= 32) )
&& (keyCode < 256 && keyCode >= 32)
)
{ {
if ( m_DoWordWrap if ( m_DoWordWrap
&& m_WrapMargin > 0 && m_WrapMargin > 0
@@ -749,15 +797,20 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
SetDirty(); SetDirty();
} }
else else
{
// we don't handle it, maybe an accelerator? // we don't handle it, maybe an accelerator?
event.Skip(); event.Skip();
}
break; break;
} }
} }
}// if(IsEditable()) }// if(IsEditable())
else else
{
// we don't handle it, maybe an accelerator? // we don't handle it, maybe an accelerator?
event.Skip(); event.Skip();
}
}// first switch() }// first switch()
if ( m_Selecting ) if ( m_Selecting )
@@ -765,6 +818,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
// continue selection to the current (new) cursor position // continue selection to the current (new) cursor position
m_llist->ContinueSelection(); m_llist->ContinueSelection();
} }
ScrollToCursor(); ScrollToCursor();
// refresh the screen // refresh the screen
RequestUpdate(m_llist->GetUpdateRect()); RequestUpdate(m_llist->GetUpdateRect());
@@ -773,7 +827,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
void void
wxLayoutWindow::OnKeyUp(wxKeyEvent& event) wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
{ {
if ( event.KeyCode() == WXK_SHIFT && m_Selecting ) if ( event.GetKeyCode() == WXK_SHIFT && m_Selecting )
{ {
m_llist->EndSelection(); m_llist->EndSelection();
m_Selecting = false; m_Selecting = false;
@@ -784,7 +838,7 @@ wxLayoutWindow::OnKeyUp(wxKeyEvent& event)
void void
wxLayoutWindow::ScrollToCursor(void) wxLayoutWindow::ScrollToCursor()
{ {
//is always needed to make sure we know where the cursor is //is always needed to make sure we know where the cursor is
//if(IsDirty()) //if(IsDirty())
@@ -814,6 +868,7 @@ wxLayoutWindow::ScrollToCursor(void)
wxPoint cs(m_llist->GetCursorSize()); wxPoint cs(m_llist->GetCursorSize());
int nx = -1, int nx = -1,
ny = -1; ny = -1;
if ( cc.x < x0 || cc.x >= x0 + x1 - cs.x ) if ( cc.x < x0 || cc.x >= x0 + x1 - cs.x )
{ {
nx = cc.x - x1/2; nx = cc.x - x1/2;
@@ -861,7 +916,7 @@ wxLayoutWindow::RequestUpdate(const wxRect *
// shouldn't specify the update rectangle if it doesn't include all the // shouldn't specify the update rectangle if it doesn't include all the
// changed locations - otherwise, they won't be repainted at all because // changed locations - otherwise, they won't be repainted at all because
// the system clips the display to the update rect // the system clips the display to the update rect
Refresh(FALSE); //, updateRect); Refresh(false); //, updateRect);
#endif #endif
} }
@@ -930,8 +985,13 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
w = m_BGbitmap->GetWidth(), w = m_BGbitmap->GetWidth(),
h = m_BGbitmap->GetHeight(); h = m_BGbitmap->GetHeight();
for(y = 0; y < y1; y+=h) for(y = 0; y < y1; y+=h)
{
for(x = 0; x < x1; x+=w) for(x = 0; x < x1; x+=w)
{
m_memDC->DrawBitmap(*m_BGbitmap, x, y); m_memDC->DrawBitmap(*m_BGbitmap, x, y);
}
}
m_memDC->SetBackgroundMode(wxTRANSPARENT); m_memDC->SetBackgroundMode(wxTRANSPARENT);
} }
@@ -975,8 +1035,9 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
{ {
WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld", WXLO_DEBUG(("UpdateRegion: %ld,%ld, %ld,%ld",
ri.GetX(),ri.GetY(),ri.GetW(),ri.GetH())); ri.GetX(),ri.GetY(),ri.GetW(),ri.GetH()));
dc.Blit(x0+ri.GetX(),y0+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); m_memDC,ri.GetX(),ri.GetY(),wxCOPY,false);
ri++; ri++;
} }
else else
@@ -988,8 +1049,9 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
// if(updateRect->height < y1) // if(updateRect->height < y1)
// y1 = updateRect->height; // y1 = updateRect->height;
// y1 += WXLO_YOFFSET; //FIXME might not be needed // y1 += WXLO_YOFFSET; //FIXME might not be needed
dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE); dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,false);
} }
WXLO_TIMER_STOP(BlitTimer); WXLO_TIMER_STOP(BlitTimer);
@@ -1051,6 +1113,7 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
m_llist->Layout(dc, 0); m_llist->Layout(dc, 0);
return; return;
} }
WXLO_TIMER_START(LayoutTimer); WXLO_TIMER_START(LayoutTimer);
m_llist->Layout(dc, -1); m_llist->Layout(dc, -1);
WXLO_TIMER_STOP(LayoutTimer); WXLO_TIMER_STOP(LayoutTimer);
@@ -1065,6 +1128,7 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
// in the absence of scrollbars we should compare with the client size // in the absence of scrollbars we should compare with the client size
if ( !m_hasHScrollbar ) if ( !m_hasHScrollbar )
m_maxx = size.x;// - WXLO_ROFFSET; m_maxx = size.x;// - WXLO_ROFFSET;
if ( !m_hasVScrollbar ) if ( !m_hasVScrollbar )
m_maxy = size.y;// - WXLO_BOFFSET; m_maxy = size.y;// - WXLO_BOFFSET;
@@ -1084,25 +1148,28 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
max.y += WXLO_BOFFSET; max.y += WXLO_BOFFSET;
} }
bool done = FALSE; bool done = false;
if(max.x < X_SCROLL_PAGE && m_hasHScrollbar) if(max.x < X_SCROLL_PAGE && m_hasHScrollbar)
{ {
SetScrollbars(0,-1,0,-1,0,-1,true); SetScrollbars(0,-1,0,-1,0,-1,true);
m_hasHScrollbar = FALSE; m_hasHScrollbar = false;
done = TRUE; done = true;
} }
if(max.y < Y_SCROLL_PAGE && m_hasVScrollbar) if(max.y < Y_SCROLL_PAGE && m_hasVScrollbar)
{ {
SetScrollbars(-1,0,-1,0,-1,0,true); SetScrollbars(-1,0,-1,0,-1,0,true);
m_hasVScrollbar = FALSE; m_hasVScrollbar = false;
done = TRUE; done = true;
} }
if (! done && if (! done &&
// (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE) // (max.x > X_SCROLL_PAGE || max.y > Y_SCROLL_PAGE)
(max.x > size.x - X_SCROLL_PAGE|| max.y > size.y - Y_SCROLL_PAGE) (max.x > size.x - X_SCROLL_PAGE|| max.y > size.y - Y_SCROLL_PAGE) )
)
{ {
GetViewStart(&m_ViewStartX, &m_ViewStartY); GetViewStart(&m_ViewStartX, &m_ViewStartY);
SetScrollbars(X_SCROLL_PAGE, SetScrollbars(X_SCROLL_PAGE,
Y_SCROLL_PAGE, Y_SCROLL_PAGE,
max.x / X_SCROLL_PAGE + 2, max.x / X_SCROLL_PAGE + 2,
@@ -1110,6 +1177,7 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
m_ViewStartX, m_ViewStartX,
m_ViewStartY, m_ViewStartY,
true); true);
m_hasHScrollbar = m_hasHScrollbar =
m_hasVScrollbar = true; m_hasVScrollbar = true;
// ScrollToCursor(); // ScrollToCursor();
@@ -1150,6 +1218,7 @@ wxLayoutWindow::Paste(bool usePrivate, bool primary)
} }
} }
} }
wxTextDataObject data; wxTextDataObject data;
if (wxTheClipboard->IsSupported( data.GetFormat() ) if (wxTheClipboard->IsSupported( data.GetFormat() )
&& wxTheClipboard->GetData(data) ) && wxTheClipboard->GetData(data) )
@@ -1197,7 +1266,7 @@ wxLayoutWindow::Copy(bool invalidate, bool privateFormat, bool primary)
wxLayoutDataObject *wldo = new wxLayoutDataObject; wxLayoutDataObject *wldo = new wxLayoutDataObject;
wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate); wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate);
if(! llist) if(! llist)
return FALSE; return false;
// Export selection as text: // Export selection as text:
wxString text; wxString text;
wxLayoutExportObject *exp; wxLayoutExportObject *exp;
@@ -1206,8 +1275,10 @@ wxLayoutWindow::Copy(bool invalidate, bool privateFormat, bool primary)
{ {
if(exp->type == WXLO_EXPORT_TEXT) if(exp->type == WXLO_EXPORT_TEXT)
text << *(exp->content.text); text << *(exp->content.text);
delete exp; delete exp;
} }
delete llist; delete llist;
// The exporter always appends a newline, so we chop it off if it // The exporter always appends a newline, so we chop it off if it
@@ -1237,18 +1308,20 @@ if(! primary) // always copy as text-only to primary selection
if (wxTheClipboard->Open()) if (wxTheClipboard->Open())
{ {
wxTextDataObject *data = new wxTextDataObject( text ); wxTextDataObject *data = new wxTextDataObject( text );
bool rc; bool rc = wxTheClipboard->SetData( data );
rc = wxTheClipboard->SetData( data );
if(privateFormat) if(privateFormat)
rc |= wxTheClipboard->SetData( wldo ); rc |= wxTheClipboard->SetData( wldo );
wxTheClipboard->Close(); wxTheClipboard->Close();
return rc; return rc;
} }
else else
{
delete wldo; delete wldo;
}
return FALSE; return false;
} }
bool bool
@@ -1258,10 +1331,12 @@ wxLayoutWindow::Cut(bool privateFormat, bool usePrimary)
{ {
m_llist->DeleteSelection(); m_llist->DeleteSelection();
SetDirty(); SetDirty();
return TRUE; return true;
} }
else else
return FALSE; {
return false;
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1269,25 +1344,15 @@ wxLayoutWindow::Cut(bool privateFormat, bool usePrimary)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool bool
wxLayoutWindow::Find(const wxString & wxLayoutWindow::Find(
#ifdef M_BASEDIR #ifdef M_BASEDIR
needle const wxString &needle,
wxPoint * fromWhere,
const wxString &configPath
#else #else
WXUNUSED(needle) const wxString & WXUNUSED(needle),
#endif wxPoint * WXUNUSED(fromWhere),
, const wxString & WXUNUSED(configPath)
wxPoint *
#ifdef M_BASEDIR
fromWhere
#else
WXUNUSED(fromWhere)
#endif
,
const wxString &
#ifdef M_BASEDIR
configPath
#else
WXUNUSED(configPath)
#endif #endif
) )
{ {
@@ -1302,15 +1367,20 @@ wxLayoutWindow::Find(const wxString &
this, this,
configPath, "") configPath, "")
|| strutil_isempty(m_FindString)) || strutil_isempty(m_FindString))
{
return true; return true;
} }
}
else else
{
m_FindString = needle; m_FindString = needle;
}
if(fromWhere == NULL) if(fromWhere == NULL)
found = m_llist->FindText(m_FindString, m_llist->GetCursorPos()); found = m_llist->FindText(m_FindString, m_llist->GetCursorPos());
else else
found = m_llist->FindText(m_FindString, *fromWhere); found = m_llist->FindText(m_FindString, *fromWhere);
if(found.x != -1) if(found.x != -1)
{ {
if(fromWhere) if(fromWhere)
@@ -1318,18 +1388,21 @@ wxLayoutWindow::Find(const wxString &
*fromWhere = found; *fromWhere = found;
fromWhere->x ++; fromWhere->x ++;
} }
m_llist->MoveCursorTo(found); m_llist->MoveCursorTo(found);
ScrollToCursor(); ScrollToCursor();
RequestUpdate(); RequestUpdate();
return true; return true;
} }
#endif #endif
return false; return false;
} }
bool bool
wxLayoutWindow::FindAgain(void) wxLayoutWindow::FindAgain()
{ {
bool rc = Find(m_FindString); bool rc = Find(m_FindString);
return rc; return rc;
@@ -1344,16 +1417,16 @@ wxLayoutWindow::MakeFormatMenu()
{ {
wxMenu *m = new wxMenu(_("Layout Menu")); wxMenu *m = new wxMenu(_("Layout Menu"));
m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."), false); m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."));
m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."), false); m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."));
m->AppendSeparator(); m->AppendSeparator();
m->Append(WXLOWIN_MENU_UNDERLINE, _("&Underline"),_("Underline mode."), true); m->Append(WXLOWIN_MENU_UNDERLINE, _("&Underline"),_("Underline mode."), wxITEM_CHECK);
m->Append(WXLOWIN_MENU_BOLD, _("&Bold"),_("Bold mode."), true); m->Append(WXLOWIN_MENU_BOLD, _("&Bold"),_("Bold mode."), wxITEM_CHECK);
m->Append(WXLOWIN_MENU_ITALICS, _("&Italics"),_("Italics mode."), true); m->Append(WXLOWIN_MENU_ITALICS, _("&Italics"),_("Italics mode."), wxITEM_CHECK);
m->AppendSeparator(); m->AppendSeparator();
m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."), false); m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."));
m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."), false); m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."));
m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."), false); m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."));
return m; return m;
} }
@@ -1379,18 +1452,25 @@ void wxLayoutWindow::OnMenu(wxCommandEvent& event)
{ {
case WXLOWIN_MENU_LARGER: case WXLOWIN_MENU_LARGER:
m_llist->SetFontLarger(); RequestUpdate(); break; m_llist->SetFontLarger(); RequestUpdate(); break;
case WXLOWIN_MENU_SMALLER: case WXLOWIN_MENU_SMALLER:
m_llist->SetFontSmaller(); RequestUpdate(); break; m_llist->SetFontSmaller(); RequestUpdate(); break;
case WXLOWIN_MENU_UNDERLINE: case WXLOWIN_MENU_UNDERLINE:
m_llist->ToggleFontUnderline(); RequestUpdate(); break; m_llist->ToggleFontUnderline(); RequestUpdate(); break;
case WXLOWIN_MENU_BOLD: case WXLOWIN_MENU_BOLD:
m_llist->ToggleFontWeight(); RequestUpdate(); break; m_llist->ToggleFontWeight(); RequestUpdate(); break;
case WXLOWIN_MENU_ITALICS: case WXLOWIN_MENU_ITALICS:
m_llist->ToggleFontItalics(); RequestUpdate(); break; m_llist->ToggleFontItalics(); RequestUpdate(); break;
case WXLOWIN_MENU_ROMAN: case WXLOWIN_MENU_ROMAN:
m_llist->SetFontFamily(wxROMAN); RequestUpdate(); break; m_llist->SetFontFamily(wxROMAN); RequestUpdate(); break;
case WXLOWIN_MENU_TYPEWRITER: case WXLOWIN_MENU_TYPEWRITER:
m_llist->SetFontFamily(wxFIXED); RequestUpdate(); break; m_llist->SetFontFamily(wxFIXED); RequestUpdate(); break;
case WXLOWIN_MENU_SANSSERIF: case WXLOWIN_MENU_SANSSERIF:
m_llist->SetFontFamily(wxSWISS); RequestUpdate(); break; m_llist->SetFontFamily(wxSWISS); RequestUpdate(); break;
} }
@@ -1438,3 +1518,4 @@ static bool IsDirectionKey(long keyCode)
return false; return false;
} }
} }

View File

@@ -13,7 +13,7 @@
#endif #endif
#ifndef USE_PCH #ifndef USE_PCH
# include <wx/wx.h> # include "wx/wx.h"
#endif #endif
#include "wxllist.h" #include "wxllist.h"
@@ -69,7 +69,7 @@ public:
wxColour *bg = NULL); wxColour *bg = NULL);
/// override base class virtual to also refresh the scrollbar position /// override base class virtual to also refresh the scrollbar position
virtual void Refresh(bool eraseBackground = TRUE, virtual void Refresh(bool eraseBackground = true,
const wxRect *rect = (const wxRect *)NULL); const wxRect *rect = (const wxRect *)NULL);
/** Sets a background image, only used on screen, not on printouts. /** Sets a background image, only used on screen, not on printouts.
@@ -80,36 +80,47 @@ public:
if(m_BGbitmap) delete m_BGbitmap; if(m_BGbitmap) delete m_BGbitmap;
m_BGbitmap = bitmap; m_BGbitmap = bitmap;
} }
/// Enable or disable editing, i.e. processing of keystrokes. /// Enable or disable editing, i.e. processing of keystrokes.
void SetEditable(bool toggle) void SetEditable(bool toggle)
{ m_Editable = toggle; SetCursorVisibility(toggle); } {
m_Editable = toggle;
SetCursorVisibility(toggle);
}
/// Query whether list can be edited by user. /// Query whether list can be edited by user.
bool IsEditable(void) const { return m_Editable; } bool IsEditable() const { return m_Editable; }
/** Sets cursor visibility, visible=1, invisible=0, /** Sets cursor visibility, visible=1, invisible=0,
visible-on-demand=-1, to hide it until moved. visible-on-demand=-1, to hide it until moved.
@param visibility -1,0 or 1 @param visibility -1,0 or 1
@return the old visibility @return the old visibility
*/ */
inline int SetCursorVisibility(int visibility = -1) inline int SetCursorVisibility(int visibility = -1)
{ int v =m_CursorVisibility; {
m_CursorVisibility = visibility; return v;} int v =m_CursorVisibility;
m_CursorVisibility = visibility; return v;
}
/// Pastes text from clipboard. /// Pastes text from clipboard.
void Paste(bool privateFormat = FALSE, bool usePrimarySelection = FALSE); void Paste(bool privateFormat = false, bool usePrimarySelection = false);
/** Copies selection to clipboard. /** Copies selection to clipboard.
@param invalidate used internally, see wxllist.h for details @param invalidate used internally, see wxllist.h for details
*/ */
bool Copy(bool invalidate = true, bool privateFormat = FALSE, bool primary = FALSE); bool Copy(bool invalidate = true, bool privateFormat = false, bool primary = false);
/// Copies selection to clipboard and deletes it. /// Copies selection to clipboard and deletes it.
bool Cut(bool privateFormat = FALSE, bool usePrimary = FALSE); bool Cut(bool privateFormat = false, bool usePrimary = false);
//@} //@}
/// find string in buffer /// find string in buffer
bool Find(const wxString &needle, bool Find(const wxString &needle,
wxPoint * fromWhere = NULL, wxPoint * fromWhere = NULL,
const wxString &configPath = _T("MsgViewFindString")); const wxString &configPath = _T("MsgViewFindString"));
/// find the same string again /// find the same string again
bool FindAgain(void); bool FindAgain();
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; } void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
@@ -135,10 +146,10 @@ public:
/// if the flag is true, we send events when user clicks on embedded objects /// if the flag is true, we send events when user clicks on embedded objects
inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; } inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
/* Returns a pointer to the wxLayoutList object. /** Returns a pointer to the wxLayoutList object.
@return the list @return the list
*/ */
wxLayoutList * GetLayoutList(void) { return m_llist; } wxLayoutList * GetLayoutList() { return m_llist; }
/**@name Callbacks */ /**@name Callbacks */
//@{ //@{
@@ -161,7 +172,8 @@ public:
//@} //@}
/// Creates a wxMenu for use as a format popup. /// Creates a wxMenu for use as a format popup.
static wxMenu * MakeFormatMenu(void); static wxMenu * MakeFormatMenu();
/// Redraws the window, used by RequestUpdate() or OnPaint(). /// Redraws the window, used by RequestUpdate() or OnPaint().
void InternalPaint(const wxRect *updateRect); void InternalPaint(const wxRect *updateRect);
@@ -178,65 +190,85 @@ public:
m_StatusBar = bar; m_StatusFieldLabel = labelfield; m_StatusBar = bar; m_StatusFieldLabel = labelfield;
m_StatusFieldCursor = cursorfield; m_StatusFieldCursor = cursorfield;
} }
#ifndef __WXMSW__ #ifndef __WXMSW__
/// Enable or disable focus follow mode under non-MSW /// Enable or disable focus follow mode under non-MSW
void SetFocusFollowMode(bool enable = TRUE) void SetFocusFollowMode(bool enable = true)
{ m_FocusFollowMode = enable; } {
m_FocusFollowMode = enable;
}
#endif #endif
/** @name Modified flag handling, will not get reset by list unless /** @name Modified flag handling, will not get reset by list unless
in Clear() */ in Clear() */
//@{ //@{
/// Set dirty flag. /// Set dirty flag.
void SetModified(bool modified = TRUE) { m_Modified = modified; } void SetModified(bool modified = true) { m_Modified = modified; }
/// Query whether window needs redrawing. /// Query whether window needs redrawing.
bool IsModified(void) const { return m_Modified; } bool IsModified() const { return m_Modified; }
//@} //@}
/**@name Dirty flag handling for optimisations. /**
@name Dirty flag handling for optimisations.
Normally one should only need to call SetDirty(), e.g. when Normally one should only need to call SetDirty(), e.g. when
manipulating the wxLayoutList directly, so the window will update manipulating the wxLayoutList directly, so the window will update
itself. ResetDirty() and IsDirty() should only be used itself. ResetDirty() and IsDirty() should only be used
internally. */ internally. */
//@{ //@{
/// Set dirty flag. /// Set dirty flag.
void SetDirty(void) { m_Dirty = true; m_Modified = true; } void SetDirty() { m_Dirty = true; m_Modified = true; }
/// Query whether window needs redrawing. /// Query whether window needs redrawing.
bool IsDirty(void) const { return m_Dirty; } bool IsDirty() const { return m_Dirty; }
/// Reset dirty flag. /// Reset dirty flag.
void ResetDirty(void) { m_Dirty = false; } void ResetDirty() { m_Dirty = false; }
//@} //@}
protected: protected:
/// generic function for mouse events processing /// generic function for mouse events processing
void OnMouse(int eventId, wxMouseEvent& event); void OnMouse(int eventId, wxMouseEvent& event);
/// as the name says /// as the name says
void ScrollToCursor(void); void ScrollToCursor();
/// for sending events /// for sending events
wxWindow *m_Parent; wxWindow *m_Parent;
/// Shall we send events? /// Shall we send events?
bool m_doSendEvents; bool m_doSendEvents;
/// Where does the current view start? /// Where does the current view start?
int m_ViewStartX; int m_ViewStartY; int m_ViewStartX; int m_ViewStartY;
/// Do we currently have the focus? /// Do we currently have the focus?
bool m_HaveFocus; bool m_HaveFocus;
/// do we handle clicks of the right mouse button? /// do we handle clicks of the right mouse button?
bool m_DoPopupMenu; bool m_DoPopupMenu;
/// Should InternalPaint() scroll to cursor (VZ: seems unused any more) /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
bool m_ScrollToCursor; bool m_ScrollToCursor;
/// Do we currently have a non-standard cursor? /// Do we currently have a non-standard cursor?
bool m_HandCursor; bool m_HandCursor;
/// the menu /// the menu
wxMenu * m_PopupMenu; wxMenu * m_PopupMenu;
/// for derived classes, set when mouse is clicked /// for derived classes, set when mouse is clicked
wxPoint m_ClickPosition; wxPoint m_ClickPosition;
/// for scrollbar calculations: /// for scrollbar calculations:
int m_maxx; int m_maxx;
int m_maxy; int m_maxy;
int m_lineHeight; int m_lineHeight;
/// do we want automatic word wrap? /// do we want automatic word wrap?
bool m_DoWordWrap; bool m_DoWordWrap;
/// wrap margin /// wrap margin
CoordType m_WrapMargin; CoordType m_WrapMargin;
@@ -249,7 +281,7 @@ protected:
*/ */
int m_CursorVisibility; int m_CursorVisibility;
bool SetAutoDeleteSelection(bool enable = TRUE) bool SetAutoDeleteSelection(bool enable = true)
{ {
bool old = m_AutoDeleteSelection; bool old = m_AutoDeleteSelection;
m_AutoDeleteSelection = enable; m_AutoDeleteSelection = enable;
@@ -258,29 +290,40 @@ protected:
private: private:
/// The layout list to be displayed. /// The layout list to be displayed.
wxLayoutList *m_llist; wxLayoutList *m_llist;
/// Can user edit the window? /// Can user edit the window?
bool m_Editable; bool m_Editable;
/// Are we currently building a selection with the keyboard? /// Are we currently building a selection with the keyboard?
bool m_Selecting; bool m_Selecting;
/// Has list changed since last redraw, e.g. in size? /// Has list changed since last redraw, e.g. in size?
bool m_Dirty; bool m_Dirty;
/// Has the list ever been modified? /// Has the list ever been modified?
bool m_Modified; bool m_Modified;
wxMemoryDC *m_memDC; wxMemoryDC *m_memDC;
wxBitmap *m_bitmap; wxBitmap *m_bitmap;
wxPoint m_bitmapSize; wxPoint m_bitmapSize;
/// A frame's statusbar to update /// A frame's statusbar to update
class wxStatusBar *m_StatusBar; class wxStatusBar *m_StatusBar;
/// statusbar field for labels /// statusbar field for labels
int m_StatusFieldLabel; int m_StatusFieldLabel;
/// statusbar field for cursor positions /// statusbar field for cursor positions
int m_StatusFieldCursor; int m_StatusFieldCursor;
/// a pointer to a bitmap for the background /// a pointer to a bitmap for the background
wxBitmap *m_BGbitmap; wxBitmap *m_BGbitmap;
/**@name Some configuration options */ /**@name Some configuration options */
//@{ //@{
/// Do we want to auto-replace the selection with new text? /// Do we want to auto-replace the selection with new text?
bool m_AutoDeleteSelection; bool m_AutoDeleteSelection;
#ifndef __WXMSW__ #ifndef __WXMSW__
/// Do we want the focus to follow the mouse? /// Do we want the focus to follow the mouse?
bool m_FocusFollowMode; bool m_FocusFollowMode;
@@ -288,6 +331,7 @@ private:
/// For finding text and finding it again: /// For finding text and finding it again:
wxString m_FindString; wxString m_FindString;
//@} //@}
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };