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
,
40 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
41 ID_TEST
, ID_LONG_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, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
66 SetStatusText( "wxLayout by Karsten Ballüder." );
68 wxMenuBar
*menu_bar
= new wxMenuBar();
70 wxMenu
*file_menu
= new wxMenu
;
71 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
72 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
73 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
74 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
76 file_menu
->AppendSeparator();
77 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
78 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
79 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
80 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
82 file_menu
->AppendSeparator();
83 file_menu
->Append( ID_TEXT
, "Export Text");
84 file_menu
->Append( ID_HTML
, "Export HTML");
85 file_menu
->Append( ID_QUIT
, "Exit");
86 menu_bar
->Append(file_menu
, "File" );
88 wxMenu
*edit_menu
= new wxMenu
;
89 edit_menu
->Append( ID_CLEAR
, "Clear");
90 edit_menu
->Append( ID_ADD_SAMPLE
, "Example");
91 edit_menu
->Append( ID_LONG_TEST
, "Add many lines");
92 edit_menu
->AppendSeparator();
93 edit_menu
->Append(ID_WRAP
, "Wrap mode", "Activate wrapping at pixel 200.");
94 edit_menu
->Append(ID_NOWRAP
, "No-wrap mode", "Deactivate wrapping.");
95 edit_menu
->AppendSeparator();
96 edit_menu
->Append(ID_COPY
, "Copy", "Copy text to clipboard.");
97 edit_menu
->Append(ID_CUT
, "Cut", "Cut text to clipboard.");
98 edit_menu
->Append(ID_PASTE
,"Paste", "Paste text from clipboard.");
99 menu_bar
->Append(edit_menu
, "Edit" );
102 menu_bar
->Show( TRUE
);
105 SetMenuBar( menu_bar
);
107 m_lwin
= new wxLayoutWindow(this);
108 m_lwin
->SetMouseTracking(true);
109 m_lwin
->SetEditable(true);
110 m_lwin
->SetWrapMargin(40);
111 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
116 MyFrame::AddSampleText(wxLayoutList
*llist
)
118 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
122 llist
->SetFont(wxROMAN
);
123 llist
->Insert("The quick brown fox jumps over the lazy dog.");
125 llist
->Insert("Hello ");
126 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
127 llist
->SetFontWeight(wxBOLD
);
128 llist
->Insert("World! ");
129 llist
->SetFontWeight(wxNORMAL
);
130 llist
->Insert("The quick brown fox jumps...");
133 llist
->Insert("over the lazy dog.");
134 llist
->SetFont(-1,-1,-1,-1,true);
135 llist
->Insert("underlined");
136 llist
->SetFont(-1,-1,-1,-1,false);
137 llist
->SetFont(wxROMAN
);
138 llist
->Insert("This is ");
139 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
140 llist
->Insert("and ");
141 llist
->SetFont(-1,-1,wxITALIC
);
142 llist
->Insert("italics ");
143 llist
->SetFont(-1,-1,wxNORMAL
);
146 llist
->Insert("and ");
147 llist
->SetFont(-1,-1,wxSLANT
);
148 llist
->Insert("slanted");
149 llist
->SetFont(-1,-1,wxNORMAL
);
150 llist
->Insert(" text.");
152 llist
->Insert("and ");
153 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
154 llist
->Insert("blue");
155 llist
->SetFont(-1,-1,-1,-1,-1,"black");
156 llist
->Insert(" and ");
157 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
158 llist
->Insert("green on black");
159 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
160 llist
->Insert(" text.");
163 llist
->SetFont(-1,-1,wxSLANT
);
164 llist
->Insert("Slanted");
165 llist
->SetFont(-1,-1,wxNORMAL
);
166 llist
->Insert(" and normal text and ");
167 llist
->SetFont(-1,-1,wxSLANT
);
168 llist
->Insert("slanted");
169 llist
->SetFont(-1,-1,wxNORMAL
);
170 llist
->Insert(" again.");
173 // add some more text for testing:
174 llist
->Insert("And here the source for the test program:");
176 llist
->SetFont(wxTELETYPE
,16);
178 FILE *in
= fopen("wxLayout.cpp","r");
183 fgets(buffer
,1024,in
);
186 llist
->Insert(buffer
);
190 llist
->MoveCursorTo(wxPoint(0,0));
198 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
202 void MyFrame::OnCommand( wxCommandEvent
&event
)
204 switch (event
.GetId())
212 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
213 if (! printer
.Print(this, &printout
, TRUE
))
215 _("There was a problem with printing the message:\n"
216 "perhaps your current printer is not set up correctly?"),
217 _("Printing"), wxOK
);
222 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
225 AddSampleText(m_lwin
->GetLayoutList());
231 cerr
<< "Received click event." << endl
;
235 m_lwin
->Refresh(FALSE
);
239 m_lwin
->Refresh(FALSE
);
243 m_lwin
->Refresh(FALSE
);
247 wxLayoutExportObject
*export
;
248 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
250 while((export
= wxLayoutExport( &status
,
251 WXLO_EXPORT_AS_HTML
)) != NULL
)
253 if(export
->type
== WXLO_EXPORT_HTML
)
254 cout
<< *(export
->content
.text
);
256 cout
<< "<!--UNKNOWN OBJECT>";
263 wxLayoutExportObject
*export
;
264 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
266 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
268 if(export
->type
== WXLO_EXPORT_TEXT
)
269 cout
<< *(export
->content
.text
);
271 cout
<< "<!--UNKNOWN OBJECT>";
279 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
280 for(int i
= 1; i
< 5000; i
++)
282 line
.Printf("This is line number %d.", i
);
286 llist
->MoveCursorTo(wxPoint(0,0));
294 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
297 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
299 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
302 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
303 if (! printer
.Print(this, &printout
, TRUE
))
305 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
309 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
311 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
314 wxPostScriptPrinter printer
;
315 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
316 printer
.Print(this, &printout
, TRUE
);
320 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
323 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
325 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
327 wxPrintData printData
;
329 // Pass two printout objects: for preview, and possible printing.
330 wxPrintPreview
*preview
= new wxPrintPreview(new
332 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
336 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
340 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
341 frame
->Centre(wxBOTH
);
346 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
348 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
350 wxPrintData printData
;
352 // Pass two printout objects: for preview, and possible printing.
353 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
354 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
355 frame
->Centre(wxBOTH
);
360 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
363 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
365 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
367 wxPrintDialog
printerDialog(this, & m_PrintData
);
368 printerDialog
.ShowModal();
371 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
374 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
376 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
378 wxPageSetupData data
;
381 wxPageSetupDialog
pageSetupDialog(this, & data
);
383 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
385 pageSetupDialog
.ShowModal();
387 data
= pageSetupDialog
.GetPageSetupData();
390 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
392 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
397 wxPrintDialog
printerDialog(this, & data
);
399 wxGenericPrintDialog
printerDialog(this, & data
);
401 printerDialog
.ShowModal();
404 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
406 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
408 wxPageSetupData data
;
410 wxPageSetupDialog
pageSetupDialog(this, & data
);
412 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
414 pageSetupDialog
.ShowModal();
418 //-----------------------------------------------------------------------------
420 //-----------------------------------------------------------------------------
427 bool MyApp::OnInit(void)
429 wxFrame
*frame
= new MyFrame();
431 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");