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
,
36 ID_DPRINT
, ID_WRAP
, ID_NOWRAP
,
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();
84 file_menu
->Append(ID_WRAP
, "Wrap mode", "Activate wrapping at pixel 200.");
85 file_menu
->Append(ID_NOWRAP
, "No-wrap mode", "Deactivate wrapping.");
87 file_menu
->AppendSeparator();
88 // file_menu->Append( ID_DPRINT, "Direct Print");
89 file_menu
->Append( ID_TEXT
, "Export Text");
90 file_menu
->Append( ID_HTML
, "Export HTML");
91 // file_menu->Append( ID_TEST, "Test");
92 file_menu
->Append( ID_QUIT
, "Exit");
94 wxMenuBar
*menu_bar
= new wxMenuBar();
95 menu_bar
->Append(file_menu
, "File" );
98 menu_bar
->Show( TRUE
);
101 SetMenuBar( menu_bar
);
103 m_lwin
= new wxLayoutWindow(this);
104 m_lwin
->SetMouseTracking(true);
105 m_lwin
->GetLayoutList().SetEditable(true);
106 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
111 MyFrame::AddSampleText(wxLayoutList
&llist
)
113 llist
.SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
117 llist
.SetFont(wxROMAN
);
118 llist
.Insert("The quick brown fox jumps over the lazy dog.");
120 llist
.Insert("Hello ");
121 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.");
149 llist
.Insert("and ");
150 llist
.SetFont(-1,-1,-1,-1,-1,"blue");
151 llist
.Insert("blue");
152 llist
.SetFont(-1,-1,-1,-1,-1,"black");
153 llist
.Insert(" and ");
154 llist
.SetFont(-1,-1,-1,-1,-1,"green","black");
155 llist
.Insert("green on black");
156 llist
.SetFont(-1,-1,-1,-1,-1,"black","white");
157 llist
.Insert(" text.");
160 llist
.SetFont(-1,-1,wxSLANT
);
161 llist
.Insert("Slanted");
162 llist
.SetFont(-1,-1,wxNORMAL
);
163 llist
.Insert(" and normal text and ");
164 llist
.SetFont(-1,-1,wxSLANT
);
165 llist
.Insert("slanted");
166 llist
.SetFont(-1,-1,wxNORMAL
);
167 llist
.Insert(" again.");
170 // add some more text for testing:
171 llist
.Insert("And here the source for the test program:");
173 llist
.SetFont(wxTELETYPE
,16);
175 FILE *in
= fopen("wxLayout.cpp","r");
180 fgets(buffer
,1024,in
);
183 llist
.Insert(buffer
);
189 m_lwin
->UpdateScrollbars();
191 llist
.SetCursor(wxPoint(0,0));
197 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
198 m_lwin
->UpdateScrollbars();
201 /* test the editing */
202 void MyFrame::Edit(void)
204 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
205 //m_lwin->SetEventId(ID_CLICK);
209 llist
.MoveCursor(0,2);
217 void MyFrame::OnCommand( wxCommandEvent
&event
)
219 cerr
<< "id:" << event
.GetId() << endl
;
220 switch (event
.GetId())
228 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
229 if (! printer
.Print(this, &printout
, TRUE
))
231 _("There was a problem with printing the message:\n"
232 "perhaps your current printer is not set up correctly?"),
233 _("Printing"), wxOK
);
238 m_lwin
->GetLayoutList().SetWrapMargin(
239 event
.GetId() == ID_NOWRAP
? -1 : 40);
244 AddSampleText(llist
);
245 wxPostScriptDC
dc("layout.ps",true,this);
246 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
248 //dc.SetUserScale(1.0, 1.0);
249 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
258 AddSampleText(m_lwin
->GetLayoutList());
263 case ID_WXLAYOUT_DEBUG
:
264 m_lwin
->GetLayoutList().Debug();
267 cerr
<< "Received click event." << endl
;
271 wxLayoutExportObject
*export
;
272 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
274 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
275 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
277 if(export
->type
== WXLO_EXPORT_HTML
)
278 cout
<< *(export
->content
.text
);
280 cout
<< "<!--UNKNOWN OBJECT>";
287 wxLayoutExportObject
*export
;
288 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
290 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
291 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
293 if(export
->type
== WXLO_EXPORT_TEXT
)
294 cout
<< *(export
->content
.text
);
296 cout
<< "<!--UNKNOWN OBJECT>";
304 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
307 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
309 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
312 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
313 if (! printer
.Print(this, &printout
, TRUE
))
315 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
319 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
321 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
323 wxPostScriptPrinter printer
;
324 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
325 printer
.Print(this, &printout
, TRUE
);
328 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
331 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
333 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
335 wxPrintData printData
;
336 printData
.SetOrientation(orientation
);
338 // Pass two printout objects: for preview, and possible printing.
339 wxPrintPreview
*preview
= new wxPrintPreview(new
341 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
345 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
349 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
350 frame
->Centre(wxBOTH
);
355 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
357 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
359 wxPrintData printData
;
360 printData
.SetOrientation(orientation
);
362 // Pass two printout objects: for preview, and possible printing.
363 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
364 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
365 frame
->Centre(wxBOTH
);
370 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
373 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
375 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
378 data
.SetOrientation(orientation
);
381 wxPrintDialog
printerDialog(this, & data
);
383 wxGenericPrintDialog
printerDialog(this, & data
);
385 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
386 printerDialog
.ShowModal();
388 orientation
= printerDialog
.GetPrintData().GetOrientation();
391 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
394 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
396 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
398 wxPageSetupData data
;
399 data
.SetOrientation(orientation
);
402 wxPageSetupDialog
pageSetupDialog(this, & data
);
404 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
406 pageSetupDialog
.ShowModal();
408 data
= pageSetupDialog
.GetPageSetupData();
409 orientation
= data
.GetOrientation();
412 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
414 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
417 data
.SetOrientation(orientation
);
419 wxGenericPrintDialog
printerDialog(this, & data
);
420 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
421 printerDialog
.ShowModal();
423 orientation
= printerDialog
.GetPrintData().GetOrientation();
426 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
428 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
430 wxPageSetupData data
;
431 data
.SetOrientation(orientation
);
433 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
434 pageSetupDialog
.ShowModal();
436 orientation
= pageSetupDialog
.GetPageSetupData().GetOrientation();
440 //-----------------------------------------------------------------------------
442 //-----------------------------------------------------------------------------
449 bool MyApp::OnInit(void)
451 wxFrame
*frame
= new MyFrame();
453 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");