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
,
40 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
, ID_TEST
};
43 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
45 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
46 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
47 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
48 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
49 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
50 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
51 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
52 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
53 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
54 EVT_MENU (-1, MyFrame::OnCommand
)
55 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
56 EVT_CHAR ( wxLayoutWindow::OnChar
)
60 MyFrame::MyFrame(void) :
61 wxFrame( (wxFrame
*) NULL
, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
65 SetStatusText( "wxLayout by Karsten Ballüder." );
67 wxMenuBar
*menu_bar
= new wxMenuBar();
69 wxMenu
*file_menu
= new wxMenu
;
70 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
71 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
72 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
73 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
75 file_menu
->AppendSeparator();
76 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
77 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
78 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
79 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
81 file_menu
->AppendSeparator();
82 file_menu
->Append( ID_TEXT
, "Export Text");
83 file_menu
->Append( ID_HTML
, "Export HTML");
84 file_menu
->Append( ID_QUIT
, "Exit");
85 menu_bar
->Append(file_menu
, "File" );
87 wxMenu
*edit_menu
= new wxMenu
;
88 edit_menu
->Append( ID_CLEAR
, "Clear");
89 edit_menu
->Append( ID_ADD_SAMPLE
, "Example");
90 edit_menu
->AppendSeparator();
91 edit_menu
->Append(ID_WRAP
, "Wrap mode", "Activate wrapping at pixel 200.");
92 edit_menu
->Append(ID_NOWRAP
, "No-wrap mode", "Deactivate wrapping.");
93 edit_menu
->AppendSeparator();
94 edit_menu
->Append(ID_PASTE
, "Paste", "Paste text from clipboard.");
95 menu_bar
->Append(edit_menu
, "Edit" );
98 menu_bar
->Show( TRUE
);
101 SetMenuBar( menu_bar
);
103 m_lwin
= new wxLayoutWindow(this);
104 m_lwin
->SetMouseTracking(true);
105 m_lwin
->SetEditable(true);
106 m_lwin
->SetWrapMargin(40);
107 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
112 MyFrame::AddSampleText(wxLayoutList
*llist
)
114 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
118 llist
->SetFont(wxROMAN
);
119 llist
->Insert("The quick brown fox jumps over the lazy dog.");
121 llist
->Insert("Hello ");
122 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
123 llist
->SetFontWeight(wxBOLD
);
124 llist
->Insert("World! ");
125 llist
->SetFontWeight(wxNORMAL
);
126 llist
->Insert("The quick brown fox jumps...");
129 llist
->Insert("over the lazy dog.");
130 llist
->SetFont(-1,-1,-1,-1,true);
131 llist
->Insert("underlined");
132 llist
->SetFont(-1,-1,-1,-1,false);
133 llist
->SetFont(wxROMAN
);
134 llist
->Insert("This is ");
135 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
136 llist
->Insert("and ");
137 llist
->SetFont(-1,-1,wxITALIC
);
138 llist
->Insert("italics ");
139 llist
->SetFont(-1,-1,wxNORMAL
);
142 llist
->Insert("and ");
143 llist
->SetFont(-1,-1,wxSLANT
);
144 llist
->Insert("slanted");
145 llist
->SetFont(-1,-1,wxNORMAL
);
146 llist
->Insert(" text.");
148 llist
->Insert("and ");
149 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
150 llist
->Insert("blue");
151 llist
->SetFont(-1,-1,-1,-1,-1,"black");
152 llist
->Insert(" and ");
153 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
154 llist
->Insert("green on black");
155 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
156 llist
->Insert(" text.");
159 llist
->SetFont(-1,-1,wxSLANT
);
160 llist
->Insert("Slanted");
161 llist
->SetFont(-1,-1,wxNORMAL
);
162 llist
->Insert(" and normal text and ");
163 llist
->SetFont(-1,-1,wxSLANT
);
164 llist
->Insert("slanted");
165 llist
->SetFont(-1,-1,wxNORMAL
);
166 llist
->Insert(" again.");
169 // add some more text for testing:
170 llist
->Insert("And here the source for the test program:");
172 llist
->SetFont(wxTELETYPE
,16);
174 FILE *in
= fopen("wxLayout.cpp","r");
179 fgets(buffer
,1024,in
);
182 llist
->Insert(buffer
);
186 llist
->MoveCursorTo(wxPoint(0,0));
194 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
198 void MyFrame::OnCommand( wxCommandEvent
&event
)
200 switch (event
.GetId())
208 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
209 if (! printer
.Print(this, &printout
, TRUE
))
211 _("There was a problem with printing the message:\n"
212 "perhaps your current printer is not set up correctly?"),
213 _("Printing"), wxOK
);
218 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
221 AddSampleText(m_lwin
->GetLayoutList());
227 cerr
<< "Received click event." << endl
;
234 wxLayoutExportObject
*export
;
235 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
237 while((export
= wxLayoutExport( &status
,
238 WXLO_EXPORT_AS_HTML
)) != NULL
)
240 if(export
->type
== WXLO_EXPORT_HTML
)
241 cout
<< *(export
->content
.text
);
243 cout
<< "<!--UNKNOWN OBJECT>";
250 wxLayoutExportObject
*export
;
251 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
253 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
255 if(export
->type
== WXLO_EXPORT_TEXT
)
256 cout
<< *(export
->content
.text
);
258 cout
<< "<!--UNKNOWN OBJECT>";
266 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
269 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
271 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
274 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
275 if (! printer
.Print(this, &printout
, TRUE
))
277 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
281 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
283 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
286 wxPostScriptPrinter printer
;
287 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
288 printer
.Print(this, &printout
, TRUE
);
292 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
295 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
297 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
299 wxPrintData printData
;
301 // Pass two printout objects: for preview, and possible printing.
302 wxPrintPreview
*preview
= new wxPrintPreview(new
304 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
308 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
312 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
313 frame
->Centre(wxBOTH
);
318 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
320 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
322 wxPrintData printData
;
324 // Pass two printout objects: for preview, and possible printing.
325 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
326 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
327 frame
->Centre(wxBOTH
);
332 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
335 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
337 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
339 wxPrintDialog
printerDialog(this, & m_PrintData
);
340 printerDialog
.ShowModal();
343 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
346 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
348 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
350 wxPageSetupData data
;
353 wxPageSetupDialog
pageSetupDialog(this, & data
);
355 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
357 pageSetupDialog
.ShowModal();
359 data
= pageSetupDialog
.GetPageSetupData();
362 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
364 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
369 wxPrintDialog
printerDialog(this, & data
);
371 wxGenericPrintDialog
printerDialog(this, & data
);
373 printerDialog
.ShowModal();
376 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
378 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
380 wxPageSetupData data
;
382 wxPageSetupDialog
pageSetupDialog(this, & data
);
384 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
386 pageSetupDialog
.ShowModal();
390 //-----------------------------------------------------------------------------
392 //-----------------------------------------------------------------------------
399 bool MyApp::OnInit(void)
401 wxFrame
*frame
= new MyFrame();
403 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");