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
)
57 int orientation
= wxPORTRAIT
;
59 MyFrame::MyFrame(void) :
60 wxFrame( (wxFrame
*) NULL
, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
64 SetStatusText( "wxLayout by Karsten Ballüder." );
66 wxMenu
*file_menu
= new wxMenu
;
67 file_menu
->Append( ID_CLEAR
, "Clear");
68 file_menu
->Append( ID_ADD_SAMPLE
, "Example");
69 // file_menu->Append( ID_EDIT, "Edit");
70 // file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
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();
85 // file_menu->Append( ID_DPRINT, "Direct Print");
86 file_menu
->Append( ID_TEXT
, "Export Text");
87 file_menu
->Append( ID_HTML
, "Export HTML");
88 // file_menu->Append( ID_TEST, "Test");
89 file_menu
->Append( ID_QUIT
, "Exit");
91 wxMenuBar
*menu_bar
= new wxMenuBar();
92 menu_bar
->Append(file_menu
, "File" );
95 menu_bar
->Show( TRUE
);
98 SetMenuBar( menu_bar
);
100 m_lwin
= new wxLayoutWindow(this);
101 m_lwin
->SetMouseTracking(true);
102 m_lwin
->GetLayoutList().SetEditable(true);
103 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
108 MyFrame::AddSampleText(wxLayoutList
&llist
)
110 llist
.SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
114 llist
.SetFont(wxROMAN
);
115 llist
.Insert("The quick brown fox jumps over the lazy dog.");
117 llist
.Insert("Hello ");
118 llist
.Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
120 llist
.SetFontWeight(wxBOLD
);
121 llist
.Insert("World! ");
122 llist
.SetFontWeight(wxNORMAL
);
123 llist
.Insert("The quick brown fox jumps...");
126 llist
.Insert("over the lazy dog.");
127 llist
.SetFont(-1,-1,-1,-1,true);
128 llist
.Insert("underlined");
129 llist
.SetFont(-1,-1,-1,-1,false);
130 llist
.SetFont(wxROMAN
);
131 llist
.Insert("This is ");
132 llist
.SetFont(-1,-1,-1,wxBOLD
); llist
.Insert("BOLD "); llist
.SetFont(-1,-1,-1,wxNORMAL
);
133 llist
.Insert("and ");
134 llist
.SetFont(-1,-1,wxITALIC
);
135 llist
.Insert("italics ");
136 llist
.SetFont(-1,-1,wxNORMAL
);
139 llist
.Insert("and ");
140 llist
.SetFont(-1,-1,wxSLANT
);
141 llist
.Insert("slanted");
142 llist
.SetFont(-1,-1,wxNORMAL
);
143 llist
.Insert(" text.");
146 llist
.Insert("and ");
147 llist
.SetFont(-1,-1,-1,-1,-1,"blue");
148 llist
.Insert("blue");
149 llist
.SetFont(-1,-1,-1,-1,-1,"black");
150 llist
.Insert(" and ");
151 llist
.SetFont(-1,-1,-1,-1,-1,"green","black");
152 llist
.Insert("green on black");
153 llist
.SetFont(-1,-1,-1,-1,-1,"black","white");
154 llist
.Insert(" text.");
157 llist
.SetFont(-1,-1,wxSLANT
);
158 llist
.Insert("Slanted");
159 llist
.SetFont(-1,-1,wxNORMAL
);
160 llist
.Insert(" and normal text and ");
161 llist
.SetFont(-1,-1,wxSLANT
);
162 llist
.Insert("slanted");
163 llist
.SetFont(-1,-1,wxNORMAL
);
164 llist
.Insert(" again.");
167 // add some more text for testing:
168 llist
.Insert("And here the source for the test program:");
170 llist
.SetFont(wxTELETYPE
,16);
172 FILE *in
= fopen("wxLayout.cpp","r");
177 fgets(buffer
,1024,in
);
180 llist
.Insert(buffer
);
186 m_lwin
->UpdateScrollbars();
188 llist
.SetCursor(wxPoint(0,0));
194 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
195 m_lwin
->UpdateScrollbars();
198 /* test the editing */
199 void MyFrame::Edit(void)
201 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
202 //m_lwin->SetEventId(ID_CLICK);
206 llist
.MoveCursor(0,2);
214 void MyFrame::OnCommand( wxCommandEvent
&event
)
216 cerr
<< "id:" << event
.GetId() << endl
;
217 switch (event
.GetId())
228 AddSampleText(llist
);
229 wxPostScriptDC
dc("layout.ps",true,this);
230 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
232 //dc.SetUserScale(1.0, 1.0);
233 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
242 AddSampleText(m_lwin
->GetLayoutList());
247 case ID_WXLAYOUT_DEBUG
:
248 m_lwin
->GetLayoutList().Debug();
251 cerr
<< "Received click event." << endl
;
255 wxLayoutExportObject
*export
;
256 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
258 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
259 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
261 if(export
->type
== WXLO_EXPORT_HTML
)
262 cout
<< *(export
->content
.text
);
264 cout
<< "<!--UNKNOWN OBJECT>";
271 wxLayoutExportObject
*export
;
272 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
274 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
275 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
277 if(export
->type
== WXLO_EXPORT_TEXT
)
278 cout
<< *(export
->content
.text
);
280 cout
<< "<!--UNKNOWN OBJECT>";
288 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
291 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
293 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
296 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
297 if (! printer
.Print(this, &printout
, TRUE
))
299 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
303 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
305 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
307 wxPostScriptPrinter printer
;
308 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
309 printer
.Print(this, &printout
, TRUE
);
312 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
315 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
317 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
319 wxPrintData printData
;
320 printData
.SetOrientation(orientation
);
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
;
344 printData
.SetOrientation(orientation
);
346 // Pass two printout objects: for preview, and possible printing.
347 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
348 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
349 frame
->Centre(wxBOTH
);
354 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
357 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
359 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
362 data
.SetOrientation(orientation
);
365 wxPrintDialog
printerDialog(this, & data
);
367 wxGenericPrintDialog
printerDialog(this, & data
);
369 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
370 printerDialog
.ShowModal();
372 orientation
= printerDialog
.GetPrintData().GetOrientation();
375 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
378 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
380 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
382 wxPageSetupData data
;
383 data
.SetOrientation(orientation
);
386 wxPageSetupDialog
pageSetupDialog(this, & data
);
388 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
390 pageSetupDialog
.ShowModal();
392 data
= pageSetupDialog
.GetPageSetupData();
393 orientation
= data
.GetOrientation();
396 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
398 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
401 data
.SetOrientation(orientation
);
403 wxGenericPrintDialog
printerDialog(this, & data
);
404 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
405 printerDialog
.ShowModal();
407 orientation
= printerDialog
.GetPrintData().GetOrientation();
410 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
412 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
414 wxPageSetupData data
;
415 data
.SetOrientation(orientation
);
417 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
418 pageSetupDialog
.ShowModal();
420 orientation
= pageSetupDialog
.GetPageSetupData().GetOrientation();
424 //-----------------------------------------------------------------------------
426 //-----------------------------------------------------------------------------
433 bool MyApp::OnInit(void)
435 wxFrame
*frame
= new MyFrame();
437 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");