New, rewritten, wxLayout. Almost complete.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1873 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f5ee2e5f8f
commit
43e916c33e
25
user/wxLayout/TODO
Normal file
25
user/wxLayout/TODO
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
BUGS
|
||||
=====================================================================
|
||||
|
||||
- Delete():
|
||||
1 - occasionally delete deletes too much, maybe when at begin of
|
||||
line?
|
||||
2 - when in an empty line, Delete() doesn't always merge lines
|
||||
3 - line numbers aren't updated properly, may be related to 2.
|
||||
4 - deleting lines leaves later parts of the list unaffected
|
||||
--> just redrawing at least the next two lines doesn't seem
|
||||
enough, strange, don't positions change?
|
||||
- dmalloc shows duplicate deletion after merging two lines and
|
||||
deleting the second half
|
||||
|
||||
TODO
|
||||
=====================================================================
|
||||
|
||||
- Add word wrap to wxlwindow/wxllist.
|
||||
- Cursor to mouseclick
|
||||
- Focus feedback for cursor
|
||||
- Selections
|
||||
|
||||
- More optimisations
|
||||
|
@ -311,5 +311,5 @@ protected: \
|
||||
/// define the most commonly used list type once:
|
||||
KBLIST_DEFINE(kbStringList, String);
|
||||
#endif
|
||||
|
||||
//@}
|
||||
#endif // KBLIST_H
|
||||
|
@ -30,34 +30,34 @@ IMPLEMENT_APP(MyApp)
|
||||
// MyFrame
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
enum ids{ ID_EDIT = 1, ID_ADD_SAMPLE, ID_CLEAR, ID_PRINT,
|
||||
enum ids{ ID_ADD_SAMPLE = 1, ID_CLEAR, ID_PRINT,
|
||||
ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
|
||||
ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
|
||||
ID_DPRINT, ID_WRAP, ID_NOWRAP,
|
||||
ID_WRAP, ID_NOWRAP,
|
||||
ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT, ID_TEST };
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
||||
EVT_MENU(ID_PRINT, MyFrame::OnPrint)
|
||||
EVT_MENU(ID_PREVIEW, MyFrame::OnPrintPreview)
|
||||
EVT_MENU(ID_PRINT_SETUP, MyFrame::OnPrintSetup)
|
||||
EVT_MENU(ID_PAGE_SETUP, MyFrame::OnPageSetup)
|
||||
EVT_MENU(ID_PRINT_PS, MyFrame::OnPrintPS)
|
||||
EVT_MENU(ID_PREVIEW_PS, MyFrame::OnPrintPreviewPS)
|
||||
EVT_MENU(ID_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS)
|
||||
EVT_MENU(ID_PAGE_SETUP_PS, MyFrame::OnPageSetupPS)
|
||||
EVT_MENU (-1, MyFrame::OnCommand)
|
||||
EVT_COMMAND (-1,-1, MyFrame::OnCommand)
|
||||
EVT_CHAR ( wxLayoutWindow::OnChar )
|
||||
EVT_MENU(ID_PRINT, MyFrame::OnPrint)
|
||||
EVT_MENU(ID_PREVIEW, MyFrame::OnPrintPreview)
|
||||
EVT_MENU(ID_PRINT_SETUP, MyFrame::OnPrintSetup)
|
||||
EVT_MENU(ID_PAGE_SETUP, MyFrame::OnPageSetup)
|
||||
EVT_MENU(ID_PRINT_PS, MyFrame::OnPrintPS)
|
||||
EVT_MENU(ID_PREVIEW_PS, MyFrame::OnPrintPreviewPS)
|
||||
EVT_MENU(ID_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS)
|
||||
EVT_MENU(ID_PAGE_SETUP_PS, MyFrame::OnPageSetupPS)
|
||||
EVT_MENU (-1, MyFrame::OnCommand)
|
||||
EVT_COMMAND (-1,-1, MyFrame::OnCommand)
|
||||
EVT_CHAR ( wxLayoutWindow::OnChar )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
int orientation = wxPORTRAIT;
|
||||
int orientation = wxPORTRAIT;
|
||||
|
||||
MyFrame::MyFrame(void) :
|
||||
wxFrame( (wxFrame *) NULL, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
|
||||
wxFrame( (wxFrame *) NULL, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
|
||||
{
|
||||
CreateStatusBar( 1 );
|
||||
|
||||
@ -66,29 +66,25 @@ MyFrame::MyFrame(void) :
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
file_menu->Append( ID_CLEAR, "Clear");
|
||||
file_menu->Append( ID_ADD_SAMPLE, "Example");
|
||||
// file_menu->Append( ID_EDIT, "Edit");
|
||||
// file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
|
||||
|
||||
file_menu->Append(ID_PRINT, "&Print...", "Print");
|
||||
file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
|
||||
file_menu->Append(ID_PAGE_SETUP, "Page Set&up...", "Page setup");
|
||||
file_menu->Append(ID_PREVIEW, "Print Pre&view", "Preview");
|
||||
file_menu->Append(ID_PRINT, "&Print...", "Print");
|
||||
file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties");
|
||||
file_menu->Append(ID_PAGE_SETUP, "Page Set&up...", "Page setup");
|
||||
file_menu->Append(ID_PREVIEW, "Print Pre&view", "Preview");
|
||||
#ifdef __WXMSW__
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(ID_PRINT_PS, "Print PostScript...", "Print (PostScript)");
|
||||
file_menu->Append(ID_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)");
|
||||
file_menu->Append(ID_PAGE_SETUP_PS, "Page Setup PostScript...", "Page setup (PostScript)");
|
||||
file_menu->Append(ID_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(ID_PRINT_PS, "Print PostScript...", "Print (PostScript)");
|
||||
file_menu->Append(ID_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)");
|
||||
file_menu->Append(ID_PAGE_SETUP_PS, "Page Setup PostScript...", "Page setup (PostScript)");
|
||||
file_menu->Append(ID_PREVIEW_PS, "Print Preview PostScript", "Preview (PostScript)");
|
||||
#endif
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(ID_WRAP, "Wrap mode", "Activate wrapping at pixel 200.");
|
||||
file_menu->Append(ID_NOWRAP, "No-wrap mode", "Deactivate wrapping.");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(ID_WRAP, "Wrap mode", "Activate wrapping at pixel 200.");
|
||||
file_menu->Append(ID_NOWRAP, "No-wrap mode", "Deactivate wrapping.");
|
||||
|
||||
file_menu->AppendSeparator();
|
||||
// file_menu->Append( ID_DPRINT, "Direct Print");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append( ID_TEXT, "Export Text");
|
||||
file_menu->Append( ID_HTML, "Export HTML");
|
||||
// file_menu->Append( ID_TEST, "Test");
|
||||
file_menu->Append( ID_QUIT, "Exit");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar();
|
||||
@ -102,75 +98,74 @@ MyFrame::MyFrame(void) :
|
||||
|
||||
m_lwin = new wxLayoutWindow(this);
|
||||
m_lwin->SetMouseTracking(true);
|
||||
m_lwin->GetLayoutList().SetEditable(true);
|
||||
m_lwin->SetEditable(true);
|
||||
m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
|
||||
m_lwin->SetFocus();
|
||||
};
|
||||
|
||||
void
|
||||
MyFrame::AddSampleText(wxLayoutList &llist)
|
||||
MyFrame::AddSampleText(wxLayoutList *llist)
|
||||
{
|
||||
llist.SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false);
|
||||
llist.Insert("--");
|
||||
llist.LineBreak();
|
||||
llist->SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false);
|
||||
llist->Insert("--");
|
||||
llist->LineBreak();
|
||||
|
||||
llist.SetFont(wxROMAN);
|
||||
llist.Insert("The quick brown fox jumps over the lazy dog.");
|
||||
llist.LineBreak();
|
||||
llist.Insert("Hello ");
|
||||
llist.Insert(new wxLayoutObjectIcon(new wxICON(Micon)));
|
||||
llist.LineBreak();
|
||||
llist.SetFontWeight(wxBOLD);
|
||||
llist.Insert("World! ");
|
||||
llist.SetFontWeight(wxNORMAL);
|
||||
llist.Insert("The quick brown fox jumps...");
|
||||
llist.LineBreak();
|
||||
llist->SetFont(wxROMAN);
|
||||
llist->Insert("The quick brown fox jumps over the lazy dog.");
|
||||
llist->LineBreak();
|
||||
llist->Insert("Hello ");
|
||||
llist->Insert(new wxLayoutObjectIcon(new wxICON(Micon)));
|
||||
llist->SetFontWeight(wxBOLD);
|
||||
llist->Insert("World! ");
|
||||
llist->SetFontWeight(wxNORMAL);
|
||||
llist->Insert("The quick brown fox jumps...");
|
||||
llist->LineBreak();
|
||||
|
||||
llist.Insert("over the lazy dog.");
|
||||
llist.SetFont(-1,-1,-1,-1,true);
|
||||
llist.Insert("underlined");
|
||||
llist.SetFont(-1,-1,-1,-1,false);
|
||||
llist.SetFont(wxROMAN);
|
||||
llist.Insert("This is ");
|
||||
llist.SetFont(-1,-1,-1,wxBOLD); llist.Insert("BOLD "); llist.SetFont(-1,-1,-1,wxNORMAL);
|
||||
llist.Insert("and ");
|
||||
llist.SetFont(-1,-1,wxITALIC);
|
||||
llist.Insert("italics ");
|
||||
llist.SetFont(-1,-1,wxNORMAL);
|
||||
llist.LineBreak();
|
||||
llist->Insert("over the lazy dog.");
|
||||
llist->SetFont(-1,-1,-1,-1,true);
|
||||
llist->Insert("underlined");
|
||||
llist->SetFont(-1,-1,-1,-1,false);
|
||||
llist->SetFont(wxROMAN);
|
||||
llist->Insert("This is ");
|
||||
llist->SetFont(-1,-1,-1,wxBOLD); llist->Insert("BOLD "); llist->SetFont(-1,-1,-1,wxNORMAL);
|
||||
llist->Insert("and ");
|
||||
llist->SetFont(-1,-1,wxITALIC);
|
||||
llist->Insert("italics ");
|
||||
llist->SetFont(-1,-1,wxNORMAL);
|
||||
llist->LineBreak();
|
||||
|
||||
llist.Insert("and ");
|
||||
llist.SetFont(-1,-1,wxSLANT);
|
||||
llist.Insert("slanted");
|
||||
llist.SetFont(-1,-1,wxNORMAL);
|
||||
llist.Insert(" text.");
|
||||
llist.LineBreak();
|
||||
llist->Insert("and ");
|
||||
llist->SetFont(-1,-1,wxSLANT);
|
||||
llist->Insert("slanted");
|
||||
llist->SetFont(-1,-1,wxNORMAL);
|
||||
llist->Insert(" text.");
|
||||
llist->LineBreak();
|
||||
|
||||
llist.Insert("and ");
|
||||
llist.SetFont(-1,-1,-1,-1,-1,"blue");
|
||||
llist.Insert("blue");
|
||||
llist.SetFont(-1,-1,-1,-1,-1,"black");
|
||||
llist.Insert(" and ");
|
||||
llist.SetFont(-1,-1,-1,-1,-1,"green","black");
|
||||
llist.Insert("green on black");
|
||||
llist.SetFont(-1,-1,-1,-1,-1,"black","white");
|
||||
llist.Insert(" text.");
|
||||
llist.LineBreak();
|
||||
llist->Insert("and ");
|
||||
llist->SetFont(-1,-1,-1,-1,-1,"blue");
|
||||
llist->Insert("blue");
|
||||
llist->SetFont(-1,-1,-1,-1,-1,"black");
|
||||
llist->Insert(" and ");
|
||||
llist->SetFont(-1,-1,-1,-1,-1,"green","black");
|
||||
llist->Insert("green on black");
|
||||
llist->SetFont(-1,-1,-1,-1,-1,"black","white");
|
||||
llist->Insert(" text.");
|
||||
llist->LineBreak();
|
||||
|
||||
llist.SetFont(-1,-1,wxSLANT);
|
||||
llist.Insert("Slanted");
|
||||
llist.SetFont(-1,-1,wxNORMAL);
|
||||
llist.Insert(" and normal text and ");
|
||||
llist.SetFont(-1,-1,wxSLANT);
|
||||
llist.Insert("slanted");
|
||||
llist.SetFont(-1,-1,wxNORMAL);
|
||||
llist.Insert(" again.");
|
||||
llist.LineBreak();
|
||||
llist->SetFont(-1,-1,wxSLANT);
|
||||
llist->Insert("Slanted");
|
||||
llist->SetFont(-1,-1,wxNORMAL);
|
||||
llist->Insert(" and normal text and ");
|
||||
llist->SetFont(-1,-1,wxSLANT);
|
||||
llist->Insert("slanted");
|
||||
llist->SetFont(-1,-1,wxNORMAL);
|
||||
llist->Insert(" again.");
|
||||
llist->LineBreak();
|
||||
|
||||
// add some more text for testing:
|
||||
llist.Insert("And here the source for the test program:");
|
||||
llist.LineBreak();
|
||||
llist.SetFont(wxTELETYPE,16);
|
||||
llist->Insert("And here the source for the test program:");
|
||||
llist->LineBreak();
|
||||
llist->SetFont(wxTELETYPE,16);
|
||||
char buffer[1024];
|
||||
FILE *in = fopen("wxLayout.cpp","r");
|
||||
if(in)
|
||||
@ -180,79 +175,44 @@ MyFrame::AddSampleText(wxLayoutList &llist)
|
||||
fgets(buffer,1024,in);
|
||||
if(feof(in))
|
||||
break;
|
||||
llist.Insert(buffer);
|
||||
llist.LineBreak();
|
||||
llist->Insert(buffer);
|
||||
llist->LineBreak();
|
||||
}
|
||||
}
|
||||
|
||||
llist->MoveCursorTo(wxPoint(0,0));
|
||||
m_lwin->SetDirty();
|
||||
m_lwin->Refresh();
|
||||
m_lwin->UpdateScrollbars();
|
||||
llist.SetEditable();
|
||||
llist.SetCursor(wxPoint(0,0));
|
||||
}
|
||||
|
||||
void
|
||||
MyFrame::Clear(void)
|
||||
{
|
||||
m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
|
||||
m_lwin->UpdateScrollbars();
|
||||
}
|
||||
|
||||
/* test the editing */
|
||||
void MyFrame::Edit(void)
|
||||
{
|
||||
wxLayoutList & llist = m_lwin->GetLayoutList();
|
||||
//m_lwin->SetEventId(ID_CLICK);
|
||||
|
||||
llist.MoveCursor(0);
|
||||
llist.MoveCursor(5);
|
||||
llist.MoveCursor(0,2);
|
||||
llist.Delete(2);
|
||||
llist.MoveCursor(2);
|
||||
llist.Insert("not");
|
||||
llist.LineBreak();
|
||||
m_lwin->Refresh();
|
||||
}
|
||||
|
||||
void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
{
|
||||
cerr << "id:" << event.GetId() << endl;
|
||||
switch (event.GetId())
|
||||
{
|
||||
case ID_QUIT:
|
||||
Close( TRUE );
|
||||
break;
|
||||
case ID_PRINT:
|
||||
{
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
_("There was a problem with printing the message:\n"
|
||||
"perhaps your current printer is not set up correctly?"),
|
||||
_("Printing"), wxOK);
|
||||
}
|
||||
break;
|
||||
case ID_NOWRAP:
|
||||
case ID_WRAP:
|
||||
m_lwin->GetLayoutList().SetWrapMargin(
|
||||
event.GetId() == ID_NOWRAP ? -1 : 40);
|
||||
break;
|
||||
case ID_DPRINT:
|
||||
{
|
||||
wxLayoutList llist;
|
||||
AddSampleText(llist);
|
||||
wxPostScriptDC dc("layout.ps",true,this);
|
||||
if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
|
||||
{
|
||||
//dc.SetUserScale(1.0, 1.0);
|
||||
llist.Draw(dc); //,false,wxPoint(0,0),true);
|
||||
dc.EndDoc();
|
||||
}
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout"));
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
_("There was a problem with printing the message:\n"
|
||||
"perhaps your current printer is not set up correctly?"),
|
||||
_("Printing"), wxOK);
|
||||
}
|
||||
break;
|
||||
case ID_EDIT:
|
||||
Edit();
|
||||
case ID_NOWRAP:
|
||||
case ID_WRAP:
|
||||
//// m_lwin->GetLayoutList()->SetWrapMargin(
|
||||
//// event.GetId() == ID_NOWRAP ? -1 : 40);
|
||||
break;
|
||||
case ID_ADD_SAMPLE:
|
||||
AddSampleText(m_lwin->GetLayoutList());
|
||||
@ -260,19 +220,15 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
case ID_CLEAR:
|
||||
Clear();
|
||||
break;
|
||||
case ID_WXLAYOUT_DEBUG:
|
||||
m_lwin->GetLayoutList().Debug();
|
||||
break;
|
||||
case ID_CLICK:
|
||||
cerr << "Received click event." << endl;
|
||||
break;
|
||||
case ID_HTML:
|
||||
{
|
||||
wxLayoutExportObject *export;
|
||||
wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
|
||||
wxLayoutExportStatus status(m_lwin->GetLayoutList());
|
||||
|
||||
while((export = wxLayoutExport(m_lwin->GetLayoutList(),
|
||||
i,WXLO_EXPORT_AS_HTML)) != NULL)
|
||||
while((export = wxLayoutExport( &status, WXLO_EXPORT_AS_HTML)) != NULL)
|
||||
{
|
||||
if(export->type == WXLO_EXPORT_HTML)
|
||||
cout << *(export->content.text);
|
||||
@ -285,10 +241,9 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
case ID_TEXT:
|
||||
{
|
||||
wxLayoutExportObject *export;
|
||||
wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
|
||||
wxLayoutExportStatus status(m_lwin->GetLayoutList());
|
||||
|
||||
while((export = wxLayoutExport(m_lwin->GetLayoutList(),
|
||||
i,WXLO_EXPORT_AS_TEXT)) != NULL)
|
||||
while((export = wxLayoutExport( &status, WXLO_EXPORT_AS_TEXT)) != NULL)
|
||||
{
|
||||
if(export->type == WXLO_EXPORT_TEXT)
|
||||
cout << *(export->content.text);
|
||||
@ -304,136 +259,136 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
#else
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
#endif
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"Printout from wxLayout");
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
"There was a problem printing.\nPerhaps your current printer is not set correctly?",
|
||||
"Printing", wxOK);
|
||||
wxPrinter printer;
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"Printout from wxLayout");
|
||||
if (! printer.Print(this, &printout, TRUE))
|
||||
wxMessageBox(
|
||||
"There was a problem printing.\nPerhaps your current printer is not set correctly?",
|
||||
"Printing", wxOK);
|
||||
}
|
||||
|
||||
void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
|
||||
wxPostScriptPrinter printer;
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
|
||||
printer.Print(this, &printout, TRUE);
|
||||
wxPostScriptPrinter printer;
|
||||
wxLayoutPrintout printout( m_lwin->GetLayoutList(),"My printout");
|
||||
printer.Print(this, &printout, TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
#else
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
#endif
|
||||
wxPrintData printData;
|
||||
printData.SetOrientation(orientation);
|
||||
wxPrintData printData;
|
||||
printData.SetOrientation(orientation);
|
||||
|
||||
// Pass two printout objects: for preview, and possible printing.
|
||||
wxPrintPreview *preview = new wxPrintPreview(new
|
||||
wxLayoutPrintout(
|
||||
m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
|
||||
if (!preview->Ok())
|
||||
{
|
||||
delete preview;
|
||||
wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK);
|
||||
return;
|
||||
}
|
||||
// Pass two printout objects: for preview, and possible printing.
|
||||
wxPrintPreview *preview = new wxPrintPreview(new
|
||||
wxLayoutPrintout(
|
||||
m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
|
||||
if (!preview->Ok())
|
||||
{
|
||||
delete preview;
|
||||
wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK);
|
||||
return;
|
||||
}
|
||||
|
||||
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
|
||||
frame->Centre(wxBOTH);
|
||||
frame->Initialize();
|
||||
frame->Show(TRUE);
|
||||
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
|
||||
frame->Centre(wxBOTH);
|
||||
frame->Initialize();
|
||||
frame->Show(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
|
||||
wxPrintData printData;
|
||||
printData.SetOrientation(orientation);
|
||||
wxPrintData printData;
|
||||
printData.SetOrientation(orientation);
|
||||
|
||||
// Pass two printout objects: for preview, and possible printing.
|
||||
wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
|
||||
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
|
||||
frame->Centre(wxBOTH);
|
||||
frame->Initialize();
|
||||
frame->Show(TRUE);
|
||||
// Pass two printout objects: for preview, and possible printing.
|
||||
wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData);
|
||||
wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
|
||||
frame->Centre(wxBOTH);
|
||||
frame->Initialize();
|
||||
frame->Show(TRUE);
|
||||
}
|
||||
|
||||
void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
#else
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
#endif
|
||||
wxPrintData data;
|
||||
data.SetOrientation(orientation);
|
||||
wxPrintData data;
|
||||
data.SetOrientation(orientation);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
wxPrintDialog printerDialog(this, & data);
|
||||
wxPrintDialog printerDialog(this, & data);
|
||||
#else
|
||||
wxGenericPrintDialog printerDialog(this, & data);
|
||||
wxGenericPrintDialog printerDialog(this, & data);
|
||||
#endif
|
||||
printerDialog.GetPrintData().SetSetupDialog(TRUE);
|
||||
printerDialog.ShowModal();
|
||||
printerDialog.GetPrintData().SetSetupDialog(TRUE);
|
||||
printerDialog.ShowModal();
|
||||
|
||||
orientation = printerDialog.GetPrintData().GetOrientation();
|
||||
orientation = printerDialog.GetPrintData().GetOrientation();
|
||||
}
|
||||
|
||||
void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
|
||||
#else
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
#endif
|
||||
wxPageSetupData data;
|
||||
data.SetOrientation(orientation);
|
||||
wxPageSetupData data;
|
||||
data.SetOrientation(orientation);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
wxPageSetupDialog pageSetupDialog(this, & data);
|
||||
wxPageSetupDialog pageSetupDialog(this, & data);
|
||||
#else
|
||||
wxGenericPageSetupDialog pageSetupDialog(this, & data);
|
||||
wxGenericPageSetupDialog pageSetupDialog(this, & data);
|
||||
#endif
|
||||
pageSetupDialog.ShowModal();
|
||||
pageSetupDialog.ShowModal();
|
||||
|
||||
data = pageSetupDialog.GetPageSetupData();
|
||||
orientation = data.GetOrientation();
|
||||
data = pageSetupDialog.GetPageSetupData();
|
||||
orientation = data.GetOrientation();
|
||||
}
|
||||
|
||||
void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
|
||||
wxPrintData data;
|
||||
data.SetOrientation(orientation);
|
||||
wxPrintData data;
|
||||
data.SetOrientation(orientation);
|
||||
|
||||
wxGenericPrintDialog printerDialog(this, & data);
|
||||
printerDialog.GetPrintData().SetSetupDialog(TRUE);
|
||||
printerDialog.ShowModal();
|
||||
wxGenericPrintDialog printerDialog(this, & data);
|
||||
printerDialog.GetPrintData().SetSetupDialog(TRUE);
|
||||
printerDialog.ShowModal();
|
||||
|
||||
orientation = printerDialog.GetPrintData().GetOrientation();
|
||||
orientation = printerDialog.GetPrintData().GetOrientation();
|
||||
}
|
||||
|
||||
void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
|
||||
|
||||
wxPageSetupData data;
|
||||
data.SetOrientation(orientation);
|
||||
wxPageSetupData data;
|
||||
data.SetOrientation(orientation);
|
||||
|
||||
wxGenericPageSetupDialog pageSetupDialog(this, & data);
|
||||
pageSetupDialog.ShowModal();
|
||||
wxGenericPageSetupDialog pageSetupDialog(this, & data);
|
||||
pageSetupDialog.ShowModal();
|
||||
|
||||
orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
|
||||
orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,8 +31,7 @@ class MyFrame: public wxFrame
|
||||
public:
|
||||
|
||||
MyFrame(void);
|
||||
void Edit(void);
|
||||
void AddSampleText(wxLayoutList &llist);
|
||||
void AddSampleText(wxLayoutList *llist);
|
||||
void Clear(void);
|
||||
void OnCommand( wxCommandEvent &event );
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,7 @@ inline static bool IsEndOfLine(const char *p, int mode)
|
||||
(((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
|
||||
}
|
||||
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str, int withflag)
|
||||
void wxLayoutImportText(wxLayoutList &list, wxString const &str, int withflag)
|
||||
{
|
||||
char * cptr = (char *)str.c_str(); // string gets changed only temporarily
|
||||
const char * begin = cptr;
|
||||
@ -63,32 +63,29 @@ void wxLayoutImportText(wxLayoutList &list, String const &str, int withflag)
|
||||
}
|
||||
|
||||
static
|
||||
String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
wxLayoutStyleInfo **lastStylePtr)
|
||||
wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
wxLayoutStyleInfo *styleInfo)
|
||||
{
|
||||
static char buffer[20];
|
||||
String html;
|
||||
wxString html;
|
||||
|
||||
wxLayoutStyleInfo *si = cmd.GetStyle();
|
||||
wxLayoutStyleInfo *last_si = NULL;
|
||||
wxLayoutStyleInfo si;
|
||||
cmd.GetStyle(&si);
|
||||
|
||||
int size, sizecount;
|
||||
|
||||
if(lastStylePtr != NULL)
|
||||
last_si = *lastStylePtr;
|
||||
|
||||
html += "<font ";
|
||||
|
||||
html +="color=";
|
||||
sprintf(buffer,"\"#%02X%02X%02X\"", si->fg_red,si->fg_green,si->fg_blue);
|
||||
sprintf(buffer,"\"#%02X%02X%02X\"", si.fg_red,si.fg_green,si.fg_blue);
|
||||
html += buffer;
|
||||
|
||||
|
||||
html += " bgcolor=";
|
||||
sprintf(buffer,"\"#%02X%02X%02X\"", si->bg_red,si->bg_green,si->bg_blue);
|
||||
sprintf(buffer,"\"#%02X%02X%02X\"", si.bg_red,si.bg_green,si.bg_blue);
|
||||
html += buffer;
|
||||
|
||||
switch(si->family)
|
||||
switch(si.family)
|
||||
{
|
||||
case wxSWISS:
|
||||
case wxMODERN:
|
||||
@ -102,12 +99,12 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
}
|
||||
|
||||
size = BASE_SIZE; sizecount = 0;
|
||||
while(size < si->size && sizecount < 5)
|
||||
while(size < si.size && sizecount < 5)
|
||||
{
|
||||
sizecount ++;
|
||||
size = (size*12)/10;
|
||||
}
|
||||
while(size > si->size && sizecount > -5)
|
||||
while(size > si.size && sizecount > -5)
|
||||
{
|
||||
sizecount --;
|
||||
size = (size*10)/12;
|
||||
@ -118,97 +115,124 @@ String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
|
||||
html +=">";
|
||||
|
||||
if(last_si != NULL)
|
||||
if(styleInfo != NULL)
|
||||
html ="</font>"+html; // terminate any previous font command
|
||||
|
||||
if((si->weight == wxBOLD) && ( (!last_si) || (last_si->weight != wxBOLD)))
|
||||
if((si.weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
|
||||
html += "<b>";
|
||||
else
|
||||
if(si->weight != wxBOLD && ( last_si && (last_si->weight == wxBOLD)))
|
||||
if(si.weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD)))
|
||||
html += "</b>";
|
||||
|
||||
if(si->style == wxSLANT)
|
||||
si->style = wxITALIC; // the same for html
|
||||
if(si.style == wxSLANT)
|
||||
si.style = wxITALIC; // the same for html
|
||||
|
||||
if((si->style == wxITALIC) && ( (!last_si) || (last_si->style != wxITALIC)))
|
||||
if((si.style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC)))
|
||||
html += "<i>";
|
||||
else
|
||||
if(si->style != wxITALIC && ( last_si && (last_si->style == wxITALIC)))
|
||||
if(si.style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC)))
|
||||
html += "</i>";
|
||||
|
||||
if(si->underline && ( (!last_si) || ! last_si->underline))
|
||||
if(si.underline && ( (!styleInfo) || ! styleInfo->underline))
|
||||
html += "<u>";
|
||||
else if(si->underline == false && ( last_si && last_si->underline))
|
||||
else if(si.underline == false && ( styleInfo && styleInfo->underline))
|
||||
html += "</u>";
|
||||
|
||||
|
||||
*styleInfo = si; // update last style info
|
||||
|
||||
if(last_si)
|
||||
delete last_si;
|
||||
*lastStylePtr = si;
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define WXLO_IS_TEXT(type) \
|
||||
( (type == WXLO_TYPE_TEXT || type == WXLO_TYPE_LINEBREAK) \
|
||||
( type == WXLO_TYPE_TEXT \
|
||||
|| (type == WXLO_TYPE_CMD \
|
||||
&& (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML))
|
||||
|
||||
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
int mode)
|
||||
{
|
||||
if(from == list.end())
|
||||
return NULL;
|
||||
|
||||
wxLayoutObjectType type = (*from)->GetType();
|
||||
wxLayoutExportObject * export = new wxLayoutExportObject();
|
||||
wxASSERT(status);
|
||||
wxLayoutExportObject * export;
|
||||
|
||||
static wxLayoutStyleInfo *s_si = NULL;
|
||||
if(status->m_iterator == NULLIT) // end of line
|
||||
{
|
||||
if(!status->m_line || status->m_line->GetNextLine() == NULL) // reached end of list
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
status->m_line = status->m_line->GetNextLine();
|
||||
status->m_iterator = status->m_line->GetFirstObject();
|
||||
export = new wxLayoutExportObject();;
|
||||
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
||||
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
|
||||
export->content.text = new wxString("\r\n");
|
||||
else
|
||||
export->content.text = new wxString("\n");
|
||||
return export;
|
||||
}
|
||||
}
|
||||
|
||||
export = new wxLayoutExportObject();
|
||||
wxLayoutObjectType type = (** status->m_iterator).GetType();
|
||||
if( (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
|
||||
{
|
||||
export->type = WXLO_EXPORT_OBJECT;
|
||||
export->content.object = *from;
|
||||
from++;
|
||||
export->content.object = *status->m_iterator;
|
||||
status->m_iterator++;
|
||||
return export;
|
||||
}
|
||||
|
||||
String *str = new String();
|
||||
|
||||
// else: must be text
|
||||
wxString *str = new wxString();
|
||||
// text must be concatenated
|
||||
while(from != list.end() && WXLO_IS_TEXT(type))
|
||||
do
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case WXLO_TYPE_TEXT:
|
||||
*str += ((wxLayoutObjectText *)*from)->GetText();
|
||||
break;
|
||||
case WXLO_TYPE_LINEBREAK:
|
||||
if((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
||||
*str += "<br>";
|
||||
if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
|
||||
*str += "\r\n";
|
||||
else
|
||||
*str += '\n';
|
||||
*str += ((wxLayoutObjectText *)*status->m_iterator)->GetText();
|
||||
break;
|
||||
case WXLO_TYPE_CMD:
|
||||
wxASSERT_MSG( (mode&WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML,
|
||||
"reached cmd object in text mode" );
|
||||
|
||||
*str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
|
||||
*)*from, &s_si);
|
||||
*)*status->m_iterator, & status->m_si);
|
||||
break;
|
||||
default: // ignore icons
|
||||
;
|
||||
}
|
||||
from++;
|
||||
if(from != list.end())
|
||||
type = (*from)->GetType();
|
||||
status->m_iterator++;
|
||||
if(status->m_iterator == NULLIT) // end of line!
|
||||
{
|
||||
if((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
||||
*str += "<br>";
|
||||
if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
|
||||
*str += "\r\n";
|
||||
else
|
||||
*str += '\n';
|
||||
status->m_line = status->m_line->GetNextLine();
|
||||
if(status->m_line)
|
||||
status->m_iterator = status->m_line->GetFirstObject();
|
||||
else
|
||||
status->m_iterator = NULLIT;
|
||||
}
|
||||
if(status->m_iterator != NULLIT)
|
||||
type = (** status->m_iterator).GetType();
|
||||
else
|
||||
break;
|
||||
}
|
||||
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
while(WXLO_IS_TEXT(type));
|
||||
|
||||
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
||||
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
export->content.text = str;
|
||||
return export;
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,8 @@ struct wxLayoutExportObject
|
||||
wxLayoutExportType type;
|
||||
union
|
||||
{
|
||||
String *text;
|
||||
wxLayoutObjectBase *object;
|
||||
wxString *text;
|
||||
wxLayoutObject *object;
|
||||
}content;
|
||||
~wxLayoutExportObject()
|
||||
{
|
||||
@ -51,22 +51,37 @@ struct wxLayoutExportObject
|
||||
}
|
||||
};
|
||||
|
||||
struct wxLayoutExportStatus
|
||||
{
|
||||
wxLayoutExportStatus(wxLayoutList *list)
|
||||
{
|
||||
list->GetDefaults()->GetStyle(&m_si);
|
||||
m_line = list->GetFirstLine();
|
||||
m_iterator = m_line->GetFirstObject();
|
||||
}
|
||||
|
||||
wxLayoutLine * m_line;
|
||||
wxLOiterator m_iterator;
|
||||
wxLayoutStyleInfo m_si;
|
||||
};
|
||||
|
||||
|
||||
#ifdef OS_WIN
|
||||
/// import text into a wxLayoutList (including linefeeds):
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str,
|
||||
void wxLayoutImportText(wxLayoutList &list, wxString const &str,
|
||||
int withflag = WXLO_EXPORT_WITH_CRLF);
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
int mode = WXLO_EXPORT_AS_TEXT|WXLO_EXPORT_WITH_CRLF);
|
||||
#else
|
||||
/// import text into a wxLayoutList (including linefeeds):
|
||||
void wxLayoutImportText(wxLayoutList &list, String const &str,
|
||||
void wxLayoutImportText(wxLayoutList &list, wxString const &str,
|
||||
int withflag = WXLO_EXPORT_WITH_LF_ONLY);
|
||||
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
|
||||
wxLayoutList::iterator &from,
|
||||
int mode = WXLO_EXPORT_AS_TEXT|WXLO_EXPORT_WITH_LF_ONLY);
|
||||
/// export text in a given format FIXME-MT: not thread safe, uses static variable
|
||||
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
int mode = WXLO_EXPORT_AS_TEXT|WXLO_EXPORT_WITH_LF_ONLY
|
||||
);
|
||||
#endif
|
||||
|
||||
#endif //WXLPARSER_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*-*- c++ -*-********************************************************
|
||||
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
|
||||
* *
|
||||
* (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* *
|
||||
* $Id$
|
||||
*******************************************************************/
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
//#include "Mpch.h"
|
||||
|
||||
#ifdef M_PREFIX
|
||||
#ifdef M_BASEDIR
|
||||
# ifndef USE_PCH
|
||||
# include "Mcommon.h"
|
||||
# include "gui/wxMenuDefs.h"
|
||||
@ -22,62 +22,65 @@
|
||||
#else
|
||||
# ifdef __WXMSW__
|
||||
# include <windows.h>
|
||||
|
||||
# undef FindWindow
|
||||
# undef GetCharWidth
|
||||
# undef StartDoc
|
||||
# endif
|
||||
|
||||
# include "wxlwindow.h"
|
||||
# define TRACEMESSAGE(x)
|
||||
#endif
|
||||
# define WXL_VAR(x) { wxString s; s << #x " = " << x; wxLogDebug(s); }
|
||||
|
||||
BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
|
||||
EVT_PAINT (wxLayoutWindow::OnPaint)
|
||||
EVT_CHAR (wxLayoutWindow::OnChar)
|
||||
|
||||
EVT_LEFT_DOWN(wxLayoutWindow::OnLeftMouseClick)
|
||||
EVT_RIGHT_DOWN(wxLayoutWindow::OnRightMouseClick)
|
||||
EVT_LEFT_DCLICK(wxLayoutWindow::OnMouseDblClick)
|
||||
EVT_MENU(WXLOWIN_MENU_LARGER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_SMALLER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_UNDERLINE, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_BOLD, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_ITALICS, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_ROMAN, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_TYPEWRITER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_SANSSERIF, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU_RANGE(WXLOWIN_MENU_FIRST, WXLOWIN_MENU_LAST, wxLayoutWindow::OnMenu)
|
||||
EVT_SET_FOCUS(wxLayoutWindow::OnSetFocus)
|
||||
EVT_KILL_FOCUS(wxLayoutWindow::OnKillFocus)
|
||||
END_EVENT_TABLE()
|
||||
/*
|
||||
|
||||
EVT_MENU(WXLOWIN_MENU_LARGER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_SMALLER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_UNDERLINE_ON, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_UNDERLINE_OFF, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_BOLD_ON, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_BOLD_OFF, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_ITALICS_ON, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_ITALICS_OFF, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_ROMAN, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_TYPEWRITER, wxLayoutWindow::OnMenu)
|
||||
EVT_MENU(WXLOWIN_MENU_SANSSERIF, wxLayoutWindow::OnMenu)
|
||||
*/
|
||||
|
||||
wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
|
||||
: wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
|
||||
wxHSCROLL | wxVSCROLL | wxBORDER)
|
||||
|
||||
{
|
||||
m_Editable = false;
|
||||
m_doSendEvents = false;
|
||||
m_ViewStartX = 0; m_ViewStartY = 0;
|
||||
m_DoPopupMenu = true;
|
||||
m_PopupMenu = NULL;
|
||||
m_PopupMenu = MakeFormatMenu();
|
||||
m_memDC = new wxMemoryDC;
|
||||
m_bitmap = new wxBitmap(4,4);
|
||||
m_bitmapSize = wxPoint(4,4);
|
||||
|
||||
CoordType
|
||||
max_x, max_y, lineHeight;
|
||||
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
||||
SetScrollbars(10, lineHeight, max_x/10+1, max_y/lineHeight+1);
|
||||
m_llist = new wxLayoutList();
|
||||
wxPoint max = m_llist->GetSize();
|
||||
SetScrollbars(10, 20 /*lineHeight*/, max.x/10+1, max.y/20+1);
|
||||
EnableScrolling(true,true);
|
||||
m_maxx = max_x; m_maxy = max_y; m_lineHeight = lineHeight;
|
||||
m_maxx = max.x; m_maxy = max.y;
|
||||
SetDirty();
|
||||
}
|
||||
|
||||
wxLayoutWindow::~wxLayoutWindow()
|
||||
{
|
||||
delete m_memDC; // deletes bitmap automatically (?)
|
||||
delete m_bitmap;
|
||||
if(m_PopupMenu) delete m_PopupMenu;
|
||||
delete m_llist;
|
||||
delete m_PopupMenu;
|
||||
}
|
||||
|
||||
#ifdef __WXMSW__
|
||||
@ -89,19 +92,6 @@ wxLayoutWindow::MSWGetDlgCode()
|
||||
}
|
||||
#endif //MSW
|
||||
|
||||
void
|
||||
wxLayoutWindow::Update(void)
|
||||
{
|
||||
if(IsDirty())
|
||||
{
|
||||
UpdateScrollbars();
|
||||
DoPaint();
|
||||
}
|
||||
else
|
||||
DoPaint(true); // only the cursor
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
||||
{
|
||||
@ -116,21 +106,29 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
||||
findPos.x = dc.DeviceToLogicalX(event.GetX());
|
||||
findPos.y = dc.DeviceToLogicalY(event.GetY());
|
||||
|
||||
TRACEMESSAGE(("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
|
||||
event.GetX(), event.GetY(), findPos.x, findPos.y));
|
||||
#ifdef WXLAYOUT_DEBUG
|
||||
wxLogDebug("wxLayoutWindow::OnMouse: (%d, %d) -> (%d, %d)",
|
||||
event.GetX(), event.GetY(), findPos.x, findPos.y);
|
||||
#endif
|
||||
|
||||
m_ClickPosition = findPos;
|
||||
wxLayoutObjectBase *obj = m_llist.Find(findPos);
|
||||
wxLayoutObject *obj = m_llist->FindObject(findPos);
|
||||
|
||||
#ifdef WXLAYOUT_DEBUG
|
||||
if(obj)
|
||||
wxLogDebug("wxLayoutWindow::OnMouse: Found object of type %d.",
|
||||
obj->GetType());
|
||||
else
|
||||
wxLogDebug("wxLayoutWindow::OnMouse: Found no object.");
|
||||
#endif
|
||||
|
||||
// only do the menu if activated, editable and not on a clickable object
|
||||
if(eventId == WXLOWIN_MENU_RCLICK
|
||||
&& m_DoPopupMenu
|
||||
&& m_llist.IsEditable()
|
||||
&& obj && obj->GetUserData() == NULL)
|
||||
&& IsEditable()
|
||||
&& (! obj || (obj && obj->GetUserData() == NULL))
|
||||
)
|
||||
{
|
||||
// when does this menu get freed?
|
||||
// how do we handle toggling? FIXME
|
||||
PopupMenu(MakeFormatMenu(), event.GetX(), event.GetY());
|
||||
PopupMenu(m_PopupMenu, event.GetX(), event.GetY());
|
||||
return;
|
||||
}
|
||||
// find the object at this position
|
||||
@ -143,83 +141,13 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteToEndOfLine(void)
|
||||
{
|
||||
int help = m_llist.GetLineLength(
|
||||
m_llist.GetCurrentObject())
|
||||
- m_llist.GetCursor().x;
|
||||
m_llist.Delete(help>1 ? help-1 : 1);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::GotoEndOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
p.x = m_llist.GetLineLength(m_llist.GetCurrentObject());
|
||||
if(p.x > 0) p.x --; // do not count the linebreak
|
||||
m_llist.SetCursor(p);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::GotoBeginOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
p.x = 0;
|
||||
m_llist.SetCursor(p);
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteLine(void)
|
||||
{
|
||||
GotoBeginOfLine();
|
||||
DeleteToEndOfLine();
|
||||
m_llist.Delete(1); // newline
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DeleteToBeginOfLine(void)
|
||||
{
|
||||
wxPoint p = m_llist.GetCursor();
|
||||
int count = p.x;
|
||||
if(count > 0)
|
||||
{
|
||||
p.x = 0;
|
||||
m_llist.SetCursor(p);
|
||||
m_llist.Delete(count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wxLayoutWindow::ScrollToCursor(void)
|
||||
{
|
||||
/** Scroll so that cursor is visible! */
|
||||
int x0,y0,x1,y1,ux,uy;
|
||||
ViewStart(&x0,&y0);
|
||||
GetScrollPixelsPerUnit(&ux,&uy);
|
||||
x0*=ux; y0*=uy;
|
||||
GetClientSize(&x1,&y1);
|
||||
|
||||
wxPoint cc = m_llist.GetCursorCoords();
|
||||
|
||||
if(cc.x < x0 || cc.y < y0
|
||||
|| cc.x >= x0+(9*x1)/10 || cc.y >= y0+(9*y1/10)) // (9*x)/10 == 90%
|
||||
{
|
||||
int nx, ny;
|
||||
nx = cc.x - (8*x1)/10; if(nx < 0) nx = 0;
|
||||
ny = cc.y - (8*y1)/10; if(ny < 0) ny = 0;
|
||||
Scroll(nx/ux,ny/uy);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* some simple keyboard handling
|
||||
* Some simple keyboard handling.
|
||||
*/
|
||||
void
|
||||
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||
{
|
||||
if(! m_llist.IsEditable()) // do nothing
|
||||
if(!IsEditable()) // do nothing
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
@ -228,96 +156,96 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||
long keyCode = event.KeyCode();
|
||||
|
||||
/* First, handle control keys */
|
||||
if(event.ControlDown())
|
||||
if(event.ControlDown() && ! event.AltDown())
|
||||
{
|
||||
switch(event.KeyCode())
|
||||
{
|
||||
case WXK_DELETE :
|
||||
case 'k':
|
||||
DeleteToEndOfLine(); break;
|
||||
case 'd':
|
||||
m_llist.Delete(1); break;
|
||||
m_llist->Delete(1);
|
||||
break;
|
||||
case 'y':
|
||||
DeleteLine(); break;
|
||||
m_llist->DeleteLines(1);
|
||||
break;
|
||||
case 'h': // like backspace
|
||||
if(m_llist.MoveCursor(-1))
|
||||
m_llist.Delete(1);
|
||||
if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1);
|
||||
break;
|
||||
case 'u':
|
||||
DeleteToBeginOfLine(); break;
|
||||
m_llist->DeleteToBeginOfLine();
|
||||
break;
|
||||
case 'k':
|
||||
m_llist->DeleteToEndOfLine();
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
else // no control keys
|
||||
// ALT only:
|
||||
else if( event.AltDown() && ! event.ControlDown() )
|
||||
{
|
||||
switch(event.KeyCode())
|
||||
{
|
||||
case WXK_DELETE:
|
||||
case 'd':
|
||||
m_llist->DeleteWord();
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
// no control keys:
|
||||
else if ( ! event.AltDown() && ! event.ControlDown())
|
||||
{
|
||||
switch(event.KeyCode())
|
||||
{
|
||||
case WXK_RIGHT:
|
||||
m_llist.MoveCursor(1);
|
||||
m_llist->MoveCursorHorizontally(1);
|
||||
break;
|
||||
case WXK_LEFT:
|
||||
m_llist.MoveCursor(-1);
|
||||
m_llist->MoveCursorHorizontally(-1);
|
||||
break;
|
||||
case WXK_UP:
|
||||
m_llist.MoveCursor(0,-1);
|
||||
m_llist->MoveCursorVertically(-1);
|
||||
break;
|
||||
case WXK_DOWN:
|
||||
m_llist.MoveCursor(0,1);
|
||||
m_llist->MoveCursorVertically(1);
|
||||
break;
|
||||
case WXK_PRIOR:
|
||||
m_llist.MoveCursor(0,-20);
|
||||
m_llist->MoveCursorVertically(-20);
|
||||
break;
|
||||
case WXK_NEXT:
|
||||
m_llist.MoveCursor(0,20);
|
||||
m_llist->MoveCursorVertically(20);
|
||||
break;
|
||||
case WXK_HOME:
|
||||
GotoBeginOfLine();
|
||||
m_llist->MoveCursorToBeginOfLine();
|
||||
break;
|
||||
case WXK_END:
|
||||
GotoEndOfLine();
|
||||
m_llist->MoveCursorToEndOfLine();
|
||||
break;
|
||||
case WXK_DELETE :
|
||||
if(event.ControlDown()) // delete to end of line
|
||||
DeleteToEndOfLine();
|
||||
else
|
||||
m_llist.Delete(1);
|
||||
m_llist->Delete(1);
|
||||
break;
|
||||
case WXK_BACK: // backspace
|
||||
if(m_llist.MoveCursor(-1)) {
|
||||
m_llist.Delete(1);
|
||||
}
|
||||
if(m_llist->MoveCursorHorizontally(-1)) m_llist->Delete(1);
|
||||
break;
|
||||
case WXK_RETURN:
|
||||
m_llist.LineBreak();
|
||||
m_llist->LineBreak();
|
||||
break;
|
||||
|
||||
#ifdef WXLAYOUT_DEBUG
|
||||
case WXK_F1:
|
||||
m_llist.Debug();
|
||||
break;
|
||||
case WXK_F2:
|
||||
m_llist.WrapLine();
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
if((!(event.ControlDown() || event.AltDown() || event.MetaDown()))
|
||||
&& (keyCode < 256 && keyCode >= 32)
|
||||
)
|
||||
{
|
||||
String tmp;
|
||||
wxString tmp;
|
||||
tmp += keyCode;
|
||||
m_llist.Insert(tmp);
|
||||
m_llist.WrapLine();
|
||||
m_llist->Insert(tmp);
|
||||
//// m_llist->WrapLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollToCursor();
|
||||
Update();
|
||||
ScrollToCursor();
|
||||
SetDirty();
|
||||
DoPaint(true); // paint and scroll to cursor
|
||||
}
|
||||
|
||||
void
|
||||
@ -327,153 +255,160 @@ wxLayoutWindow::OnPaint( wxPaintEvent &WXUNUSED(event)) // or: OnDraw(wxDC& dc)
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::DoPaint(bool cursorOnly) // or: OnDraw(wxDC& dc)
|
||||
wxLayoutWindow::DoPaint(bool scrollToCursor)
|
||||
{
|
||||
wxPaintDC dc( this );
|
||||
PrepareDC( dc );
|
||||
|
||||
// wxGTK: wxMemoryDC broken? YES!!
|
||||
int x0,y0,x1,y1, dx, dy;
|
||||
|
||||
// Calculate where the top of the visible area is:
|
||||
ViewStart(&x0,&y0);
|
||||
GetClientSize(&x1,&y1); // this is the size of the visible window
|
||||
wxASSERT(x1 > 0);
|
||||
wxASSERT(y1 > 0);
|
||||
GetScrollPixelsPerUnit(&dx, &dy);
|
||||
x0 *= dx; y0 *= dy;
|
||||
//FIXME: trying an offset for small border:
|
||||
wxPoint offset(-x0+4,-y0+4);
|
||||
|
||||
//Blit() doesn't work on scrolled window!
|
||||
// So we have to draw the cursor on the memdc.
|
||||
//if(! cursorOnly)
|
||||
// Get the size of the visible window:
|
||||
GetClientSize(&x1,&y1);
|
||||
wxASSERT(x1 > 0);
|
||||
|
||||
wxASSERT(y1 > 0);
|
||||
|
||||
// Maybe we need to change the scrollbar sizes or positions,
|
||||
// so layout the list and check:
|
||||
if(IsDirty() || scrollToCursor)
|
||||
m_llist->Layout(dc);
|
||||
if(IsDirty())
|
||||
ResizeScrollbars();
|
||||
|
||||
/* Make sure that the scrollbars are at a position so that the
|
||||
cursor is visible if we are editing. */
|
||||
/** Scroll so that cursor is visible! */
|
||||
if(IsEditable() && scrollToCursor)
|
||||
{
|
||||
if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y)
|
||||
wxPoint cc = m_llist->GetCursorScreenPos();
|
||||
if(cc.x < x0 || cc.y < y0
|
||||
|| cc.x >= x0+(9*x1)/10 || cc.y >= y0+(9*y1/10)) // (9*x)/10 == 90%
|
||||
{
|
||||
wxASSERT(m_bitmapSize.x > 0);
|
||||
wxASSERT(m_bitmapSize.y > 0);
|
||||
|
||||
m_memDC->SelectObject(wxNullBitmap);
|
||||
delete m_bitmap;
|
||||
m_bitmapSize = wxPoint(x1,y1);
|
||||
m_bitmap = new wxBitmap(x1,y1);
|
||||
m_memDC->SelectObject(*m_bitmap);
|
||||
int nx, ny;
|
||||
nx = cc.x - x1/2; if(nx < 0) nx = 0;
|
||||
ny = cc.y - y1/2; if(ny < 0) ny = 0;
|
||||
Scroll(nx/dx,ny/dy); // new view start
|
||||
x0 = nx; y0 = ny;
|
||||
}
|
||||
m_memDC->SetDeviceOrigin(0,0);
|
||||
m_memDC->Clear();
|
||||
if(IsDirty() || m_llist.CursorMoved())
|
||||
m_llist.Layout(dc);
|
||||
|
||||
m_llist.EraseAndDraw(*m_memDC,
|
||||
wxLayoutObjectList::iterator(NULL),offset);
|
||||
m_llist.DrawCursor(*m_memDC,false,offset);
|
||||
dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
|
||||
}
|
||||
|
||||
/* Check whether the window has grown, if so, we need to reallocate
|
||||
the bitmap to be larger. */
|
||||
if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y)
|
||||
{
|
||||
wxASSERT(m_bitmapSize.x > 0);
|
||||
wxASSERT(m_bitmapSize.y > 0);
|
||||
|
||||
m_memDC->SelectObject(wxNullBitmap);
|
||||
delete m_bitmap;
|
||||
m_bitmapSize = wxPoint(x1,y1);
|
||||
m_bitmap = new wxBitmap(x1,y1);
|
||||
m_memDC->SelectObject(*m_bitmap);
|
||||
}
|
||||
// Device origins on the memDC are suspect, we translate manually
|
||||
// with the translate parameter of Draw().
|
||||
m_memDC->SetDeviceOrigin(0,0);
|
||||
m_memDC->Clear();
|
||||
|
||||
//FIXME obsolete? ResetDirty();
|
||||
UpdateScrollbars();
|
||||
// The +4 give the window a tiny border on the left and top, looks nice.
|
||||
wxPoint offset(-x0+4,-y0+4);
|
||||
m_llist->Draw(*m_memDC,offset);
|
||||
if(IsEditable())
|
||||
m_llist->DrawCursor(*m_memDC,m_HaveFocus,offset);
|
||||
// Now copy everything to the screen:
|
||||
dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE);
|
||||
|
||||
|
||||
ResetDirty();
|
||||
}
|
||||
|
||||
// change the range and position of scroll bars
|
||||
void
|
||||
wxLayoutWindow::UpdateScrollbars(bool exact)
|
||||
wxLayoutWindow::ResizeScrollbars(bool exact)
|
||||
{
|
||||
CoordType
|
||||
max_x, max_y, lineHeight;
|
||||
|
||||
m_llist.GetSize(&max_x, &max_y, &lineHeight);
|
||||
wxPoint max = m_llist->GetSize();
|
||||
|
||||
if(max_x > m_maxx || max_y > m_maxy || exact)
|
||||
if(max.x > m_maxx || max.y > m_maxy
|
||||
|| max.x < (7*m_maxx)/10 || max.y << (7*m_maxy)/10
|
||||
|| exact)
|
||||
{
|
||||
if(! exact) // add an extra 50% to the sizes to avoid future updates
|
||||
if(! exact) // add an extra 20% to the sizes to avoid future updates
|
||||
{
|
||||
max_x = (3*max_x)/2;
|
||||
max_y = (3*max_y)/2;
|
||||
max.x = (12*max.x)/10; // 12/20 = 120%
|
||||
max.y = (12*max.y)/10;
|
||||
}
|
||||
ViewStart(&m_ViewStartX, &m_ViewStartY);
|
||||
SetScrollbars(10, 20, max_x/10+1,max_y/20+1,m_ViewStartX,m_ViewStartY,true);
|
||||
m_maxx = max_x; m_maxy = max_y;
|
||||
SetScrollbars(10, 20, max.x/10+1,max.y/20+1,m_ViewStartX,m_ViewStartY,true);
|
||||
m_maxx = max.x; m_maxy = max.y;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::Print(wxDC &dc)
|
||||
{
|
||||
if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
|
||||
{
|
||||
//dc.SetUserScale(1.0, 1.0);
|
||||
m_llist.Draw(dc);
|
||||
dc.EndDoc();
|
||||
}
|
||||
}
|
||||
|
||||
wxMenu *
|
||||
wxLayoutWindow::MakeFormatMenu()
|
||||
{
|
||||
if(m_PopupMenu)
|
||||
return m_PopupMenu;
|
||||
|
||||
wxMenu *m = new wxMenu();
|
||||
wxMenu *m = new wxMenu(_("Layout Menu"));
|
||||
|
||||
m->Append(WXLOWIN_MENU_LARGER ,_("&Larger"),_("Switch to larger font."), false);
|
||||
m->Append(WXLOWIN_MENU_SMALLER ,_("&Smaller"),_("Switch to smaller font."), false);
|
||||
m->AppendSeparator();
|
||||
m->Append(WXLOWIN_MENU_UNDERLINE,_("&Underline"),_("Toggle underline mode."), true);
|
||||
m->Append(WXLOWIN_MENU_BOLD ,_("&Bold"),_("Toggle bold mode."), true);
|
||||
m->Append(WXLOWIN_MENU_ITALICS ,_("&Italics"),_("Toggle italics mode."), true);
|
||||
m->Append(WXLOWIN_MENU_UNDERLINE_ON, _("&Underline on"),_("Activate underline mode."), false);
|
||||
m->Append(WXLOWIN_MENU_UNDERLINE_OFF,_("&Underline off"),_("Deactivate underline mode."), false);
|
||||
m->Append(WXLOWIN_MENU_BOLD_ON ,_("&Bold on"),_("Activate bold mode."), false);
|
||||
m->Append(WXLOWIN_MENU_BOLD_OFF ,_("&Bold off"),_("Deactivate bold mode."), false);
|
||||
m->Append(WXLOWIN_MENU_ITALICS_ON ,_("&Italics on"),_("Activate italics mode."), false);
|
||||
m->Append(WXLOWIN_MENU_ITALICS_OFF ,_("&Italics off"),_("Deactivate italics mode."), false);
|
||||
m->AppendSeparator();
|
||||
m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Toggle underline mode."), false);
|
||||
m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Toggle bold mode."), false);
|
||||
m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Toggle italics mode."), false);
|
||||
|
||||
return m_PopupMenu = m;
|
||||
m->Append(WXLOWIN_MENU_ROMAN ,_("&Roman"),_("Switch to roman font."), false);
|
||||
m->Append(WXLOWIN_MENU_TYPEWRITER,_("&Typewriter"),_("Switch to typewriter font."), false);
|
||||
m->Append(WXLOWIN_MENU_SANSSERIF ,_("&Sans Serif"),_("Switch to sans serif font."), false);
|
||||
return m;
|
||||
}
|
||||
|
||||
void wxLayoutWindow::OnMenu(wxCommandEvent& event)
|
||||
{
|
||||
if(! m_llist.IsEditable())
|
||||
return;
|
||||
|
||||
switch (event.GetId())
|
||||
{
|
||||
case WXLOWIN_MENU_LARGER:
|
||||
m_llist.SetFontLarger();
|
||||
break;
|
||||
m_llist->SetFontLarger(); break;
|
||||
case WXLOWIN_MENU_SMALLER:
|
||||
m_llist.SetFontSmaller();
|
||||
break;
|
||||
case WXLOWIN_MENU_UNDERLINE:
|
||||
m_llist.SetFontUnderline(
|
||||
m_PopupMenu->IsChecked(WXLOWIN_MENU_UNDERLINE) ? false : true
|
||||
);
|
||||
break;
|
||||
case WXLOWIN_MENU_BOLD:
|
||||
m_llist.SetFontWeight(
|
||||
m_PopupMenu->IsChecked(WXLOWIN_MENU_BOLD) ? wxNORMAL : wxBOLD
|
||||
);
|
||||
case WXLOWIN_MENU_ITALICS:
|
||||
m_llist.SetFontStyle(
|
||||
m_PopupMenu->IsChecked(WXLOWIN_MENU_ITALICS) ? wxNORMAL : wxITALIC
|
||||
);
|
||||
break;
|
||||
m_llist->SetFontSmaller(); break;
|
||||
case WXLOWIN_MENU_UNDERLINE_ON:
|
||||
m_llist->SetFontUnderline(true); break;
|
||||
case WXLOWIN_MENU_UNDERLINE_OFF:
|
||||
m_llist->SetFontUnderline(false); break;
|
||||
case WXLOWIN_MENU_BOLD_ON:
|
||||
m_llist->SetFontWeight(wxBOLD); break;
|
||||
case WXLOWIN_MENU_BOLD_OFF:
|
||||
m_llist->SetFontWeight(wxNORMAL); break;
|
||||
case WXLOWIN_MENU_ITALICS_ON:
|
||||
m_llist->SetFontStyle(wxITALIC); break;
|
||||
case WXLOWIN_MENU_ITALICS_OFF:
|
||||
m_llist->SetFontStyle(wxNORMAL); break;
|
||||
case WXLOWIN_MENU_ROMAN:
|
||||
m_llist.SetFontFamily(wxROMAN); break;
|
||||
m_llist->SetFontFamily(wxROMAN); break;
|
||||
case WXLOWIN_MENU_TYPEWRITER:
|
||||
m_llist.SetFontFamily(wxFIXED); break;
|
||||
m_llist->SetFontFamily(wxFIXED); break;
|
||||
case WXLOWIN_MENU_SANSSERIF:
|
||||
m_llist.SetFontFamily(wxSWISS); break;
|
||||
m_llist->SetFontFamily(wxSWISS); break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnSetFocus(wxFocusEvent &ev)
|
||||
{
|
||||
m_llist.SetBoldCursor(true);
|
||||
DoPaint(true);
|
||||
m_HaveFocus = true;
|
||||
DoPaint(); // to repaint the cursor
|
||||
}
|
||||
|
||||
void
|
||||
wxLayoutWindow::OnKillFocus(wxFocusEvent &ev)
|
||||
{
|
||||
m_llist.SetBoldCursor(false);
|
||||
Update();
|
||||
m_HaveFocus = true;
|
||||
DoPaint(); // to repaint the cursor
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*-*- c++ -*-********************************************************
|
||||
* wxLwindow.h : a scrolled Window for displaying/entering rich text*
|
||||
* *
|
||||
* (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* (C) 1998,1999 by Karsten Ballüder (Ballueder@usa.net) *
|
||||
* *
|
||||
* $Id$
|
||||
*******************************************************************/
|
||||
@ -18,22 +18,32 @@
|
||||
|
||||
#include "wxllist.h"
|
||||
|
||||
#ifndef WXLOWIN_MENU_FIRST
|
||||
# define WXLOWIN_MENU_FIRST 12000
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
WXLOWIN_MENU_LARGER = 12000,
|
||||
WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
|
||||
WXLOWIN_MENU_SMALLER,
|
||||
WXLOWIN_MENU_UNDERLINE,
|
||||
WXLOWIN_MENU_BOLD,
|
||||
WXLOWIN_MENU_ITALICS,
|
||||
WXLOWIN_MENU_UNDERLINE_ON,
|
||||
WXLOWIN_MENU_UNDERLINE_OFF,
|
||||
WXLOWIN_MENU_BOLD_ON,
|
||||
WXLOWIN_MENU_BOLD_OFF,
|
||||
WXLOWIN_MENU_ITALICS_ON,
|
||||
WXLOWIN_MENU_ITALICS_OFF,
|
||||
WXLOWIN_MENU_ROMAN,
|
||||
WXLOWIN_MENU_TYPEWRITER,
|
||||
WXLOWIN_MENU_SANSSERIF,
|
||||
WXLOWIN_MENU_RCLICK,
|
||||
WXLOWIN_MENU_LCLICK,
|
||||
WXLOWIN_MENU_DBLCLICK
|
||||
|
||||
WXLOWIN_MENU_DBLCLICK,
|
||||
WXLOWIN_MENU_LAST = WXLOWIN_MENU_DBLCLICK
|
||||
};
|
||||
|
||||
/**
|
||||
This class is a rich text editing widget.
|
||||
*/
|
||||
class wxLayoutWindow : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
@ -44,90 +54,90 @@ public:
|
||||
|
||||
/// Destructor.
|
||||
virtual ~wxLayoutWindow();
|
||||
|
||||
/* Returns a reference to the wxLayoutList object.
|
||||
@return the list
|
||||
*/
|
||||
wxLayoutList & GetLayoutList(void) { return m_llist; }
|
||||
|
||||
// clears the window and sets default parameters:
|
||||
void Clear(int family = wxROMAN, int size=12, int style=wxNORMAL, int weight=wxNORMAL,
|
||||
int underline=0, char const *fg="black", char const
|
||||
*bg="white")
|
||||
/**@name Editing functionality */
|
||||
//@{
|
||||
/// Clears the window and sets default parameters.
|
||||
void Clear(int family = wxROMAN,
|
||||
int size=12,
|
||||
int style=wxNORMAL,
|
||||
int weight=wxNORMAL,
|
||||
int underline=0,
|
||||
char const *fg="black",
|
||||
char const *bg="white")
|
||||
{
|
||||
GetLayoutList().Clear(family,size,style,weight,underline,fg,bg);
|
||||
SetBackgroundColour( *GetLayoutList().GetDefaults()->GetBGColour());
|
||||
Update();
|
||||
m_bDirty = FALSE;
|
||||
GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
|
||||
SetBackgroundColour(*GetLayoutList()->GetDefaults()->GetBGColour());
|
||||
SetDirty();
|
||||
DoPaint();
|
||||
}
|
||||
|
||||
// callbacks
|
||||
// NB: these functions are used as event handlers and must not be virtual
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void OnLeftMouseClick(wxMouseEvent& event)
|
||||
{ OnMouse(WXLOWIN_MENU_LCLICK, event); }
|
||||
void OnRightMouseClick(wxMouseEvent& event)
|
||||
{ OnMouse(WXLOWIN_MENU_RCLICK, event); }
|
||||
void OnMouseDblClick(wxMouseEvent& event)
|
||||
{ OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
|
||||
|
||||
void OnChar(wxKeyEvent& event);
|
||||
void OnMenu(wxCommandEvent& event);
|
||||
/// Enable or disable editing, i.e. processing of keystrokes.
|
||||
void SetEditable(bool toggle) { m_Editable = toggle; }
|
||||
/// Query whether list can be edited by user.
|
||||
bool IsEditable(void) const { return m_Editable; }
|
||||
|
||||
//@}
|
||||
|
||||
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
|
||||
/// gets called by either Update() or OnPaint()
|
||||
void DoPaint(bool cursoronly = false);
|
||||
|
||||
/** Redraws the window.
|
||||
@param scrollToCursor if true, scroll the window so that the
|
||||
cursor becomes visible
|
||||
*/
|
||||
void DoPaint(bool scrollToCursor = false);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
virtual long MSWGetDlgCode();
|
||||
#endif //MSW
|
||||
|
||||
/// if exact == false, assume 50% extra size for the future
|
||||
void UpdateScrollbars(bool exact = false); // don't change this to true!
|
||||
void Print(wxDC &dc);
|
||||
wxMenu * MakeFormatMenu(void);
|
||||
void ResizeScrollbars(bool exact = false); // don't change this to true!
|
||||
|
||||
/// if the flag is true, we send events when user clicks on embedded objects
|
||||
inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
|
||||
|
||||
// dirty flag access
|
||||
bool IsDirty() const { return m_llist.IsDirty(); }
|
||||
void ResetDirty() { m_llist.ResetDirty(); }
|
||||
/* Returns a pointer to the wxLayoutList object.
|
||||
@return the list
|
||||
*/
|
||||
wxLayoutList * GetLayoutList(void) { return m_llist; }
|
||||
|
||||
/**@name Callbacks */
|
||||
//@{
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void OnChar(wxKeyEvent& event);
|
||||
void OnMenu(wxCommandEvent& event);
|
||||
void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); }
|
||||
void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
|
||||
void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
|
||||
void OnSetFocus(wxFocusEvent &ev);
|
||||
void OnKillFocus(wxFocusEvent &ev);
|
||||
//@}
|
||||
|
||||
/// Creates a wxMenu for use as a format popup.
|
||||
static wxMenu * MakeFormatMenu(void);
|
||||
/// Set dirty flag.
|
||||
void SetDirty(void) { m_Dirty = true; }
|
||||
protected:
|
||||
/// Deletes from cursor to end of line.
|
||||
void DeleteToEndOfLine(void);
|
||||
/// Deletes everything left of cursor.
|
||||
void DeleteToBeginOfLine(void);
|
||||
/// Goto end of line.
|
||||
void GotoEndOfLine(void);
|
||||
/// Goto begin of line.
|
||||
void GotoBeginOfLine(void);
|
||||
/// Delete Line
|
||||
void DeleteLine(void);
|
||||
/**@name Dirty flag handling for optimisations. */
|
||||
//@{
|
||||
/// Query whether window needs redrawing.
|
||||
bool IsDirty(void) const { return m_Dirty; }
|
||||
/// Reset dirty flag.
|
||||
void ResetDirty(void) { m_Dirty = false; }
|
||||
//@}
|
||||
protected:
|
||||
/// generic function for mouse events processing
|
||||
void OnMouse(int eventId, wxMouseEvent& event);
|
||||
/// scroll to cursor
|
||||
void ScrollToCursor(void);
|
||||
|
||||
/// repaint if needed
|
||||
void Update(void);
|
||||
|
||||
/// for sending events
|
||||
wxWindow *m_Parent;
|
||||
/// Shall we send events?
|
||||
bool m_doSendEvents;
|
||||
|
||||
/// the layout list to be displayed
|
||||
wxLayoutList m_llist;
|
||||
|
||||
/// Where does the current view start?
|
||||
int m_ViewStartX; int m_ViewStartY;
|
||||
|
||||
/// do we have unsaved data?
|
||||
bool m_bDirty;
|
||||
|
||||
/// Do we currently have the focus?
|
||||
bool m_HaveFocus;
|
||||
/// do we handle clicks of the right mouse button?
|
||||
bool m_DoPopupMenu;
|
||||
/// the menu
|
||||
@ -139,6 +149,13 @@ protected:
|
||||
int m_maxy;
|
||||
int m_lineHeight;
|
||||
private:
|
||||
/// The layout list to be displayed.
|
||||
wxLayoutList *m_llist;
|
||||
|
||||
/// Can user edit the window?
|
||||
bool m_Editable;
|
||||
/// Is list dirty?
|
||||
bool m_Dirty;
|
||||
wxMemoryDC *m_memDC;
|
||||
wxBitmap *m_bitmap;
|
||||
wxPoint m_bitmapSize;
|
||||
|
Loading…
Reference in New Issue
Block a user