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
,
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_PASTE
,"Paste", "Paste text from clipboard.");
98 menu_bar
->Append(edit_menu
, "Edit" );
101 menu_bar
->Show( TRUE
);
104 SetMenuBar( menu_bar
);
106 m_lwin
= new wxLayoutWindow(this);
107 m_lwin
->SetMouseTracking(true);
108 m_lwin
->SetEditable(true);
109 m_lwin
->SetWrapMargin(40);
110 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
115 MyFrame::AddSampleText(wxLayoutList
*llist
)
117 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
121 llist
->SetFont(wxROMAN
);
122 llist
->Insert("The quick brown fox jumps over the lazy dog.");
124 llist
->Insert("Hello ");
125 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
126 llist
->SetFontWeight(wxBOLD
);
127 llist
->Insert("World! ");
128 llist
->SetFontWeight(wxNORMAL
);
129 llist
->Insert("The quick brown fox jumps...");
132 llist
->Insert("over the lazy dog.");
133 llist
->SetFont(-1,-1,-1,-1,true);
134 llist
->Insert("underlined");
135 llist
->SetFont(-1,-1,-1,-1,false);
136 llist
->SetFont(wxROMAN
);
137 llist
->Insert("This is ");
138 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
139 llist
->Insert("and ");
140 llist
->SetFont(-1,-1,wxITALIC
);
141 llist
->Insert("italics ");
142 llist
->SetFont(-1,-1,wxNORMAL
);
145 llist
->Insert("and ");
146 llist
->SetFont(-1,-1,wxSLANT
);
147 llist
->Insert("slanted");
148 llist
->SetFont(-1,-1,wxNORMAL
);
149 llist
->Insert(" text.");
151 llist
->Insert("and ");
152 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
153 llist
->Insert("blue");
154 llist
->SetFont(-1,-1,-1,-1,-1,"black");
155 llist
->Insert(" and ");
156 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
157 llist
->Insert("green on black");
158 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
159 llist
->Insert(" text.");
162 llist
->SetFont(-1,-1,wxSLANT
);
163 llist
->Insert("Slanted");
164 llist
->SetFont(-1,-1,wxNORMAL
);
165 llist
->Insert(" and normal text and ");
166 llist
->SetFont(-1,-1,wxSLANT
);
167 llist
->Insert("slanted");
168 llist
->SetFont(-1,-1,wxNORMAL
);
169 llist
->Insert(" again.");
172 // add some more text for testing:
173 llist
->Insert("And here the source for the test program:");
175 llist
->SetFont(wxTELETYPE
,16);
177 FILE *in
= fopen("wxLayout.cpp","r");
182 fgets(buffer
,1024,in
);
185 llist
->Insert(buffer
);
189 llist
->MoveCursorTo(wxPoint(0,0));
197 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
201 void MyFrame::OnCommand( wxCommandEvent
&event
)
203 switch (event
.GetId())
211 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
212 if (! printer
.Print(this, &printout
, TRUE
))
214 _("There was a problem with printing the message:\n"
215 "perhaps your current printer is not set up correctly?"),
216 _("Printing"), wxOK
);
221 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
224 AddSampleText(m_lwin
->GetLayoutList());
230 cerr
<< "Received click event." << endl
;
240 wxLayoutExportObject
*export
;
241 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
243 while((export
= wxLayoutExport( &status
,
244 WXLO_EXPORT_AS_HTML
)) != NULL
)
246 if(export
->type
== WXLO_EXPORT_HTML
)
247 cout
<< *(export
->content
.text
);
249 cout
<< "<!--UNKNOWN OBJECT>";
256 wxLayoutExportObject
*export
;
257 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
259 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
261 if(export
->type
== WXLO_EXPORT_TEXT
)
262 cout
<< *(export
->content
.text
);
264 cout
<< "<!--UNKNOWN OBJECT>";
272 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
273 for(int i
= 1; i
< 5000; i
++)
275 line
.Printf("This is line number %d.", i
);
279 llist
->MoveCursorTo(wxPoint(0,0));
287 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
290 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
292 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
295 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
296 if (! printer
.Print(this, &printout
, TRUE
))
298 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
302 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
304 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
307 wxPostScriptPrinter printer
;
308 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
309 printer
.Print(this, &printout
, TRUE
);
313 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
316 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
318 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
320 wxPrintData printData
;
322 // Pass two printout objects: for preview, and possible printing.
323 wxPrintPreview
*preview
= new wxPrintPreview(new
325 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
329 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
333 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
334 frame
->Centre(wxBOTH
);
339 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
341 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
343 wxPrintData printData
;
345 // Pass two printout objects: for preview, and possible printing.
346 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
347 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
348 frame
->Centre(wxBOTH
);
353 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
356 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
358 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
360 wxPrintDialog
printerDialog(this, & m_PrintData
);
361 printerDialog
.ShowModal();
364 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
367 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
369 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
371 wxPageSetupData data
;
374 wxPageSetupDialog
pageSetupDialog(this, & data
);
376 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
378 pageSetupDialog
.ShowModal();
380 data
= pageSetupDialog
.GetPageSetupData();
383 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
385 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
390 wxPrintDialog
printerDialog(this, & data
);
392 wxGenericPrintDialog
printerDialog(this, & data
);
394 printerDialog
.ShowModal();
397 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
399 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
401 wxPageSetupData data
;
403 wxPageSetupDialog
pageSetupDialog(this, & data
);
405 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
407 pageSetupDialog
.ShowModal();
411 //-----------------------------------------------------------------------------
413 //-----------------------------------------------------------------------------
420 bool MyApp::OnInit(void)
422 wxFrame
*frame
= new MyFrame();
424 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");