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" );
93 menu_bar
->Show( TRUE
);
95 SetMenuBar( menu_bar
);
97 m_lwin
= new wxLayoutWindow(this);
98 m_lwin
->SetMouseTracking(true);
99 m_lwin
->GetLayoutList().SetEditable(true);
100 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
105 MyFrame::AddSampleText(wxLayoutList
&llist
)
107 llist
.SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
111 llist
.SetFont(wxROMAN
);
112 llist
.Insert("The quick brown fox jumps over the lazy dog.");
114 llist
.Insert("Hello ");
115 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
117 llist
.SetFontWeight(wxBOLD
);
118 llist
.Insert("World! ");
119 llist
.SetFontWeight(wxNORMAL
);
120 llist
.Insert("The quick brown fox jumps...");
123 llist
.Insert("over the lazy dog.");
124 llist
.SetFont(-1,-1,-1,-1,true);
125 llist
.Insert("underlined");
126 llist
.SetFont(-1,-1,-1,-1,false);
127 llist
.SetFont(wxROMAN
);
128 llist
.Insert("This is ");
129 llist
.SetFont(-1,-1,-1,wxBOLD
); llist
.Insert("BOLD "); llist
.SetFont(-1,-1,-1,wxNORMAL
);
130 llist
.Insert("and ");
131 llist
.SetFont(-1,-1,wxITALIC
);
132 llist
.Insert("italics ");
133 llist
.SetFont(-1,-1,wxNORMAL
);
136 llist
.Insert("and ");
137 llist
.SetFont(-1,-1,wxSLANT
);
138 llist
.Insert("slanted");
139 llist
.SetFont(-1,-1,wxNORMAL
);
140 llist
.Insert(" text.");
143 llist
.Insert("and ");
144 llist
.SetFont(-1,-1,-1,-1,-1,"blue");
145 llist
.Insert("blue");
146 llist
.SetFont(-1,-1,-1,-1,-1,"black");
147 llist
.Insert(" and ");
148 llist
.SetFont(-1,-1,-1,-1,-1,"green","black");
149 llist
.Insert("green on black");
150 llist
.SetFont(-1,-1,-1,-1,-1,"black","white");
151 llist
.Insert(" text.");
154 llist
.SetFont(-1,-1,wxSLANT
);
155 llist
.Insert("Slanted");
156 llist
.SetFont(-1,-1,wxNORMAL
);
157 llist
.Insert(" and normal text and ");
158 llist
.SetFont(-1,-1,wxSLANT
);
159 llist
.Insert("slanted");
160 llist
.SetFont(-1,-1,wxNORMAL
);
161 llist
.Insert(" again.");
164 // add some more text for testing:
165 llist
.Insert("And here the source for the test program:");
167 llist
.SetFont(wxTELETYPE
,16);
169 FILE *in
= fopen("wxLayout.cpp","r");
174 fgets(buffer
,1024,in
);
177 llist
.Insert(buffer
);
183 m_lwin
->UpdateScrollbars();
185 llist
.SetCursor(wxPoint(0,0));
191 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
192 m_lwin
->UpdateScrollbars();
195 /* test the editing */
196 void MyFrame::Edit(void)
198 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
199 //m_lwin->SetEventId(ID_CLICK);
203 llist
.MoveCursor(0,2);
211 void MyFrame::OnCommand( wxCommandEvent
&event
)
213 cerr
<< "id:" << event
.GetId() << endl
;
214 switch (event
.GetId())
225 AddSampleText(llist
);
226 wxPostScriptDC
dc("layout.ps",true,this);
227 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
229 //dc.SetUserScale(1.0, 1.0);
230 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
239 AddSampleText(m_lwin
->GetLayoutList());
244 case ID_WXLAYOUT_DEBUG
:
245 m_lwin
->GetLayoutList().Debug();
248 cerr
<< "Received click event." << endl
;
252 wxLayoutExportObject
*export
;
253 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
255 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
256 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
258 if(export
->type
== WXLO_EXPORT_HTML
)
259 cout
<< *(export
->content
.text
);
261 cout
<< "<!--UNKNOWN OBJECT>";
268 wxLayoutExportObject
*export
;
269 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
271 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
272 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
274 if(export
->type
== WXLO_EXPORT_TEXT
)
275 cout
<< *(export
->content
.text
);
277 cout
<< "<!--UNKNOWN OBJECT>";
285 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
288 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
290 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
293 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
294 if (! printer
.Print(this, &printout
, TRUE
))
296 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
300 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
302 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
304 wxPostScriptPrinter printer
;
305 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
306 printer
.Print(this, &printout
, TRUE
);
309 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
312 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
314 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
316 wxPrintData printData
;
317 printData
.SetOrientation(orientation
);
319 // Pass two printout objects: for preview, and possible printing.
320 wxPrintPreview
*preview
= new wxPrintPreview(new
322 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
326 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
330 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
331 frame
->Centre(wxBOTH
);
336 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
338 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
340 wxPrintData printData
;
341 printData
.SetOrientation(orientation
);
343 // Pass two printout objects: for preview, and possible printing.
344 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
345 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
346 frame
->Centre(wxBOTH
);
351 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
354 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
356 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
359 data
.SetOrientation(orientation
);
362 wxPrintDialog
printerDialog(this, & data
);
364 wxGenericPrintDialog
printerDialog(this, & data
);
366 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
367 printerDialog
.ShowModal();
369 orientation
= printerDialog
.GetPrintData().GetOrientation();
372 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
375 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
377 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
379 wxPageSetupData data
;
380 data
.SetOrientation(orientation
);
383 wxPageSetupDialog
pageSetupDialog(this, & data
);
385 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
387 pageSetupDialog
.ShowModal();
389 data
= pageSetupDialog
.GetPageSetupData();
390 orientation
= data
.GetOrientation();
393 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
395 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
398 data
.SetOrientation(orientation
);
400 wxGenericPrintDialog
printerDialog(this, & data
);
401 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
402 printerDialog
.ShowModal();
404 orientation
= printerDialog
.GetPrintData().GetOrientation();
407 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
409 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
411 wxPageSetupData data
;
412 data
.SetOrientation(orientation
);
414 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
415 pageSetupDialog
.ShowModal();
417 orientation
= pageSetupDialog
.GetPageSetupData().GetOrientation();
421 //-----------------------------------------------------------------------------
423 //-----------------------------------------------------------------------------
430 bool MyApp::OnInit(void)
432 wxFrame
*frame
= new MyFrame();
434 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");