4 * Author: Karsten Ballüder
6 * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
11 #pragma implementation "wxLayout.h"
15 #include "wx/textfile.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 enum ids
{ ID_EDIT
= 1, ID_ADD_SAMPLE
, ID_CLEAR
, ID_PRINT
,
34 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
35 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
37 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
, ID_TEST
};
40 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
42 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
43 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
44 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
45 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
46 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
47 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
48 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
49 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
50 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
51 EVT_MENU (-1, MyFrame::OnCommand
)
52 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
53 EVT_CHAR ( wxLayoutWindow::OnChar
)
61 int orientation
= wxPORTRAIT
;
68 MyFrame::MyFrame(void) :
69 wxFrame( (wxFrame
*) NULL
, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
73 SetStatusText( "wxLayout by Karsten Ballüder." );
75 wxMenu
*file_menu
= new wxMenu( "Menu 1" );
76 file_menu
->Append( ID_CLEAR
, "Clear");
77 file_menu
->Append( ID_ADD_SAMPLE
, "Example");
78 file_menu
->Append( ID_EDIT
, "Edit");
79 file_menu
->Append( ID_WXLAYOUT_DEBUG
, "Debug");
81 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
82 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
83 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
84 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
86 file_menu
->AppendSeparator();
87 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
88 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
89 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
90 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
92 file_menu
->AppendSeparator();
94 file_menu
->Append( ID_DPRINT
, "Direct Print");
95 file_menu
->Append( ID_TEXT
, "Export Text");
96 file_menu
->Append( ID_HTML
, "Export HTML");
97 file_menu
->Append( ID_TEST
, "Test");
98 file_menu
->Append( ID_QUIT
, "Exit");
100 wxMenuBar
*menu_bar
= new wxMenuBar();
101 menu_bar
->Append(file_menu
, "File" );
102 menu_bar
->Show( TRUE
);
104 SetMenuBar( menu_bar
);
106 m_lwin
= new wxLayoutWindow(this);
107 m_lwin
->SetEventId(ID_CLICK
);
108 m_lwin
->GetLayoutList().SetEditable(true);
109 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
114 MyFrame::AddSampleText(wxLayoutList
&llist
)
119 llist
.Insert("The quick brown fox jumps over the lazy dog.");
121 llist
.Insert("Hello ");
122 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
124 llist
.SetFontWeight(wxBOLD
);
125 llist
.Insert("World! ");
126 llist
.SetFontWeight(wxNORMAL
);
127 llist
.Insert("The quick brown fox jumps...");
130 llist
.Insert("over the lazy dog.");
131 llist
.SetFont(-1,-1,-1,-1,true);
132 llist
.Insert("underlined");
133 llist
.SetFont(-1,-1,-1,-1,false);
134 llist
.SetFont(wxROMAN
);
135 llist
.Insert("This is ");
136 llist
.SetFont(-1,-1,-1,wxBOLD
); llist
.Insert("BOLD "); llist
.SetFont(-1,-1,-1,wxNORMAL
);
137 llist
.Insert("and ");
138 llist
.SetFont(-1,-1,wxITALIC
);
139 llist
.Insert("italics ");
140 llist
.SetFont(-1,-1,wxNORMAL
);
143 llist
.Insert("and ");
144 llist
.SetFont(-1,-1,wxSLANT
);
145 llist
.Insert("slanted");
146 llist
.SetFont(-1,-1,wxNORMAL
);
147 llist
.Insert(" text.");
150 llist
.Insert("and ");
151 llist
.SetFont(-1,-1,-1,-1,-1,"blue");
152 llist
.Insert("blue");
153 llist
.SetFont(-1,-1,-1,-1,-1,"black");
154 llist
.Insert(" and ");
155 llist
.SetFont(-1,-1,-1,-1,-1,"green","black");
156 llist
.Insert("green on black");
157 llist
.SetFont(-1,-1,-1,-1,-1,"black","white");
158 llist
.Insert(" text.");
161 llist
.SetFont(-1,-1,wxSLANT
);
162 llist
.Insert("Slanted");
163 llist
.SetFont(-1,-1,wxNORMAL
);
164 llist
.Insert(" and normal text and ");
165 llist
.SetFont(-1,-1,wxSLANT
);
166 llist
.Insert("slanted");
167 llist
.SetFont(-1,-1,wxNORMAL
);
168 llist
.Insert(" again.");
171 // add some more text for testing:
172 llist
.Insert("And here the source for the test program:");
174 llist
.SetFont(wxTELETYPE
,16);
176 FILE *in
= fopen("wxLayout.cpp","r");
181 fgets(buffer
,1024,in
);
184 llist
.Insert(buffer
);
190 m_lwin
->UpdateScrollbars();
192 llist
.SetCursor(wxPoint(0,0));
198 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
199 m_lwin
->UpdateScrollbars();
202 /* test the editing */
203 void MyFrame::Edit(void)
205 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
206 m_lwin
->SetEventId(ID_CLICK
);
210 llist
.MoveCursor(0,2);
218 void MyFrame::OnCommand( wxCommandEvent
&event
)
220 cerr
<< "id:" << event
.GetId() << endl
;
221 switch (event
.GetId())
232 AddSampleText(llist
);
233 wxPostScriptDC
dc("layout.ps",true,this);
234 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
236 //dc.SetUserScale(1.0, 1.0);
237 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
246 AddSampleText(m_lwin
->GetLayoutList());
251 case ID_WXLAYOUT_DEBUG
:
252 m_lwin
->GetLayoutList().Debug();
255 cerr
<< "Received click event." << endl
;
260 m_lwin
->GetLayoutList().LineBreak();
261 m_lwin
->GetLayoutList().Insert("abc");
262 m_lwin
->GetLayoutList().LineBreak();
263 m_lwin
->GetLayoutList().Insert("def");
268 wxLayoutExportObject
*export
;
269 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
271 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
272 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
274 if(export
->type
== WXLO_EXPORT_HTML
)
275 cout
<< *(export
->content
.text
);
277 cout
<< "<!--UNKNOWN OBJECT>";
284 wxLayoutExportObject
*export
;
285 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
287 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
288 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
290 if(export
->type
== WXLO_EXPORT_TEXT
)
291 cout
<< *(export
->content
.text
);
293 cout
<< "<!--UNKNOWN OBJECT>";
301 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
304 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
306 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
309 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
310 if (!printer
.Print(this, &printout
, TRUE
))
311 wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK
);
314 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
316 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
318 wxPostScriptPrinter printer
;
319 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
320 printer
.Print(this, &printout
, TRUE
);
323 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
326 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
328 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
330 wxPrintData printData
;
331 printData
.SetOrientation(orientation
);
333 // Pass two printout objects: for preview, and possible printing.
334 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
338 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
342 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
343 frame
->Centre(wxBOTH
);
348 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
350 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
352 wxPrintData printData
;
353 printData
.SetOrientation(orientation
);
355 // Pass two printout objects: for preview, and possible printing.
356 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
357 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
358 frame
->Centre(wxBOTH
);
363 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
366 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
368 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
371 data
.SetOrientation(orientation
);
374 wxPrintDialog
printerDialog(this, & data
);
376 wxGenericPrintDialog
printerDialog(this, & data
);
378 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
379 printerDialog
.ShowModal();
381 orientation
= printerDialog
.GetPrintData().GetOrientation();
384 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
387 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
389 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
391 wxPageSetupData data
;
392 data
.SetOrientation(orientation
);
395 wxPageSetupDialog
pageSetupDialog(this, & data
);
397 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
399 pageSetupDialog
.ShowModal();
401 data
= pageSetupDialog
.GetPageSetupData();
402 orientation
= data
.GetOrientation();
405 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
407 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
410 data
.SetOrientation(orientation
);
412 wxGenericPrintDialog
printerDialog(this, & data
);
413 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
414 printerDialog
.ShowModal();
416 orientation
= printerDialog
.GetPrintData().GetOrientation();
419 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
421 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
423 wxPageSetupData data
;
424 data
.SetOrientation(orientation
);
426 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
427 pageSetupDialog
.ShowModal();
429 orientation
= pageSetupDialog
.GetPageSetupData().GetOrientation();
433 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
442 bool MyApp::OnInit(void)
444 wxFrame
*frame
= new MyFrame();
446 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");