4 * Author: Karsten Ballüder
6 * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
11 #pragma implementation "wxLayout.h"
14 #include "wx/wxprec.h"
20 #include "wx/textfile.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 enum ids
{ ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
37 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
38 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
39 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
, ID_FIND
,
40 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
41 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
};
44 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
46 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
47 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
48 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
49 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
50 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
51 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
52 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
53 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
54 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
55 EVT_MENU (-1, MyFrame::OnCommand
)
56 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
57 EVT_CHAR ( wxLayoutWindow::OnChar
)
61 MyFrame::MyFrame(void) :
62 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
63 wxPoint(880,100), wxSize(256,256) )
67 SetStatusText( "wxLayout by Karsten Ballüder." );
69 wxMenuBar
*menu_bar
= new wxMenuBar();
71 wxMenu
*file_menu
= new wxMenu
;
72 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
73 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
74 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
75 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
77 file_menu
->AppendSeparator();
78 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
79 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
80 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
81 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
83 file_menu
->AppendSeparator();
84 file_menu
->Append( ID_TEXT
, "Export &Text");
85 file_menu
->Append( ID_HTML
, "Export &HTML");
86 file_menu
->Append( ID_QUIT
, "E&xit");
87 menu_bar
->Append(file_menu
, "&File" );
89 wxMenu
*edit_menu
= new wxMenu
;
90 edit_menu
->Append( ID_CLEAR
, "C&lear");
91 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
92 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
93 edit_menu
->AppendSeparator();
94 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
95 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
96 edit_menu
->AppendSeparator();
97 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
98 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
99 edit_menu
->AppendSeparator();
100 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
101 edit_menu
->Append(ID_CUT
, "Cu&t", "Cut text to clipboard.");
102 edit_menu
->Append(ID_PASTE
,"&Paste", "Paste text from clipboard.");
103 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
104 menu_bar
->Append(edit_menu
, "&Edit" );
107 menu_bar
->Show( TRUE
);
110 SetMenuBar( menu_bar
);
112 m_lwin
= new wxLayoutWindow(this);
113 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
114 m_lwin
->SetMouseTracking(true);
115 m_lwin
->SetEditable(true);
116 m_lwin
->SetWrapMargin(40);
117 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
122 MyFrame::AddSampleText(wxLayoutList
*llist
)
124 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
125 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
126 llist
->Insert("blue");
127 llist
->SetFont(-1,-1,-1,-1,-1,"black");
128 llist
->Insert("The quick brown fox jumps over the lazy dog.");
131 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
135 llist
->SetFont(wxROMAN
);
136 llist
->Insert("The quick brown fox jumps over the lazy dog.");
138 llist
->Insert("Hello ");
139 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
140 llist
->SetFontWeight(wxBOLD
);
141 llist
->Insert("World! ");
142 llist
->SetFontWeight(wxNORMAL
);
143 llist
->Insert("The quick brown fox jumps...");
145 llist
->Insert("over the lazy dog.");
146 llist
->SetFont(-1,-1,-1,-1,true);
147 llist
->Insert("underlined");
148 llist
->SetFont(-1,-1,-1,-1,false);
149 llist
->SetFont(wxROMAN
);
150 llist
->Insert("This is ");
151 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
152 llist
->Insert("and ");
153 llist
->SetFont(-1,-1,wxITALIC
);
154 llist
->Insert("italics ");
155 llist
->SetFont(-1,-1,wxNORMAL
);
158 llist
->Insert("and ");
159 llist
->SetFont(-1,-1,wxSLANT
);
160 llist
->Insert("slanted");
161 llist
->SetFont(-1,-1,wxNORMAL
);
162 llist
->Insert(" text.");
164 llist
->Insert("and ");
165 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
166 llist
->Insert("blue");
167 llist
->SetFont(-1,-1,-1,-1,-1,"black");
168 llist
->Insert(" and ");
169 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
170 llist
->Insert("green on black");
171 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
172 llist
->Insert(" text.");
175 llist
->SetFont(-1,-1,wxSLANT
);
176 llist
->Insert("Slanted");
177 llist
->SetFont(-1,-1,wxNORMAL
);
178 llist
->Insert(" and normal text and ");
179 llist
->SetFont(-1,-1,wxSLANT
);
180 llist
->Insert("slanted");
181 llist
->SetFont(-1,-1,wxNORMAL
);
182 llist
->Insert(" again.");
185 // add some more text for testing:
186 llist
->Insert("And here the source for the test program:");
188 llist
->SetFont(wxTELETYPE
,16);
190 FILE *in
= fopen("wxLayout.cpp","r");
195 fgets(buffer
,1024,in
);
198 wxLayoutImportText(llist
, buffer
);
201 llist
->MoveCursorTo(wxPoint(0,0));
209 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
213 void MyFrame::OnCommand( wxCommandEvent
&event
)
215 switch (event
.GetId())
223 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
224 if (! printer
.Print(this, &printout
, TRUE
))
226 _("There was a problem with printing the message:\n"
227 "perhaps your current printer is not set up correctly?"),
228 _("Printing"), wxOK
);
233 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
236 AddSampleText(m_lwin
->GetLayoutList());
242 cerr
<< "Received click event." << endl
;
246 m_lwin
->Refresh(FALSE
);
250 m_lwin
->Refresh(FALSE
);
254 m_lwin
->Refresh(FALSE
);
257 m_lwin
->Find("void");
258 m_lwin
->Refresh(FALSE
);
262 wxLayoutExportObject
*export
;
263 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
265 while((export
= wxLayoutExport( &status
,
266 WXLO_EXPORT_AS_HTML
)) != NULL
)
268 if(export
->type
== WXLO_EXPORT_HTML
)
269 cout
<< *(export
->content
.text
);
271 cout
<< "<!--UNKNOWN OBJECT>";
278 wxLayoutExportObject
*export
;
279 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
281 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
283 if(export
->type
== WXLO_EXPORT_TEXT
)
284 cout
<< *(export
->content
.text
);
286 cout
<< "<!--UNKNOWN OBJECT>";
294 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
295 for(int i
= 1; i
< 5000; i
++)
297 line
.Printf("This is line number %d.", i
);
301 llist
->MoveCursorTo(wxPoint(0,0));
307 case ID_LINEBREAKS_TEST
:
308 wxLayoutImportText(m_lwin
->GetLayoutList(),
310 "with embedded line\n"
315 // VZ: this doesn't work, of course, but I think it should -
316 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
317 // (instead of doing it manually like M does now)
318 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
322 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
325 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
327 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
330 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
331 if (! printer
.Print(this, &printout
, TRUE
))
333 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
337 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
339 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
342 wxPostScriptPrinter printer
;
343 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
344 printer
.Print(this, &printout
, TRUE
);
348 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
351 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
353 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
355 wxPrintData printData
;
357 // Pass two printout objects: for preview, and possible printing.
358 wxPrintPreview
*preview
= new wxPrintPreview(new
360 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
364 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
368 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
369 frame
->Centre(wxBOTH
);
374 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
376 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
378 wxPrintData printData
;
380 // Pass two printout objects: for preview, and possible printing.
381 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
382 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
383 frame
->Centre(wxBOTH
);
388 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
391 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
393 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
395 wxPrintDialog
printerDialog(this, & m_PrintData
);
396 printerDialog
.ShowModal();
399 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
402 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
404 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
406 wxPageSetupData data
;
409 wxPageSetupDialog
pageSetupDialog(this, & data
);
411 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
413 pageSetupDialog
.ShowModal();
415 data
= pageSetupDialog
.GetPageSetupData();
418 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
420 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
425 wxPrintDialog
printerDialog(this, & data
);
427 wxGenericPrintDialog
printerDialog(this, & data
);
429 printerDialog
.ShowModal();
432 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
434 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
436 wxPageSetupData data
;
438 wxPageSetupDialog
pageSetupDialog(this, & data
);
440 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
442 pageSetupDialog
.ShowModal();
446 //-----------------------------------------------------------------------------
448 //-----------------------------------------------------------------------------
455 bool MyApp::OnInit(void)
457 wxFrame
*frame
= new MyFrame();
459 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");