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())
230 m_lwin
->GetLayoutList().SetWrapMargin(
231 event
.GetId() == ID_NOWRAP
? -1 : 40);
236 AddSampleText(llist
);
237 wxPostScriptDC
dc("layout.ps",true,this);
238 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
240 //dc.SetUserScale(1.0, 1.0);
241 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
250 AddSampleText(m_lwin
->GetLayoutList());
255 case ID_WXLAYOUT_DEBUG
:
256 m_lwin
->GetLayoutList().Debug();
259 cerr
<< "Received click event." << endl
;
263 wxLayoutExportObject
*export
;
264 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
266 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
267 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
269 if(export
->type
== WXLO_EXPORT_HTML
)
270 cout
<< *(export
->content
.text
);
272 cout
<< "<!--UNKNOWN OBJECT>";
279 wxLayoutExportObject
*export
;
280 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
282 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
283 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
285 if(export
->type
== WXLO_EXPORT_TEXT
)
286 cout
<< *(export
->content
.text
);
288 cout
<< "<!--UNKNOWN OBJECT>";
296 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
299 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
301 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
304 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
305 if (! printer
.Print(this, &printout
, TRUE
))
307 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
311 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
313 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
315 wxPostScriptPrinter printer
;
316 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
317 printer
.Print(this, &printout
, TRUE
);
320 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
323 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
325 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
327 wxPrintData printData
;
328 printData
.SetOrientation(orientation
);
330 // Pass two printout objects: for preview, and possible printing.
331 wxPrintPreview
*preview
= new wxPrintPreview(new
333 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
337 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
341 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
342 frame
->Centre(wxBOTH
);
347 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
349 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
351 wxPrintData printData
;
352 printData
.SetOrientation(orientation
);
354 // Pass two printout objects: for preview, and possible printing.
355 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
356 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
357 frame
->Centre(wxBOTH
);
362 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
365 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
367 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
370 data
.SetOrientation(orientation
);
373 wxPrintDialog
printerDialog(this, & data
);
375 wxGenericPrintDialog
printerDialog(this, & data
);
377 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
378 printerDialog
.ShowModal();
380 orientation
= printerDialog
.GetPrintData().GetOrientation();
383 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
386 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
388 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
390 wxPageSetupData data
;
391 data
.SetOrientation(orientation
);
394 wxPageSetupDialog
pageSetupDialog(this, & data
);
396 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
398 pageSetupDialog
.ShowModal();
400 data
= pageSetupDialog
.GetPageSetupData();
401 orientation
= data
.GetOrientation();
404 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
406 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
409 data
.SetOrientation(orientation
);
411 wxGenericPrintDialog
printerDialog(this, & data
);
412 printerDialog
.GetPrintData().SetSetupDialog(TRUE
);
413 printerDialog
.ShowModal();
415 orientation
= printerDialog
.GetPrintData().GetOrientation();
418 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
420 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
422 wxPageSetupData data
;
423 data
.SetOrientation(orientation
);
425 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
426 pageSetupDialog
.ShowModal();
428 orientation
= pageSetupDialog
.GetPageSetupData().GetOrientation();
432 //-----------------------------------------------------------------------------
434 //-----------------------------------------------------------------------------
441 bool MyApp::OnInit(void)
443 wxFrame
*frame
= new MyFrame();
445 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");