4 * Author: Karsten Ballüder
6 * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
11 #pragma implementation "wxLayout.h"
14 #include "wx/wxprec.h"
20 #include "wx/textfile.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 enum ids
{ ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
37 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
38 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
39 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
, ID_FIND
,
40 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
41 ID_TEST
, ID_LONG_TEST
};
44 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
46 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
47 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
48 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
49 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
50 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
51 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
52 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
53 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
54 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
55 EVT_MENU (-1, MyFrame::OnCommand
)
56 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
57 EVT_CHAR ( wxLayoutWindow::OnChar
)
61 MyFrame::MyFrame(void) :
62 wxFrame( (wxFrame
*) NULL
, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) )
66 SetStatusText( "wxLayout by Karsten Ballüder." );
68 wxMenuBar
*menu_bar
= new wxMenuBar();
70 wxMenu
*file_menu
= new wxMenu
;
71 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
72 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
73 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
74 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
76 file_menu
->AppendSeparator();
77 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
78 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
79 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
80 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
82 file_menu
->AppendSeparator();
83 file_menu
->Append( ID_TEXT
, "Export Text");
84 file_menu
->Append( ID_HTML
, "Export HTML");
85 file_menu
->Append( ID_QUIT
, "Exit");
86 menu_bar
->Append(file_menu
, "File" );
88 wxMenu
*edit_menu
= new wxMenu
;
89 edit_menu
->Append( ID_CLEAR
, "Clear");
90 edit_menu
->Append( ID_ADD_SAMPLE
, "Example");
91 edit_menu
->Append( ID_LONG_TEST
, "Add many lines");
92 edit_menu
->AppendSeparator();
93 edit_menu
->Append(ID_WRAP
, "Wrap mode", "Activate wrapping at pixel 200.");
94 edit_menu
->Append(ID_NOWRAP
, "No-wrap mode", "Deactivate wrapping.");
95 edit_menu
->AppendSeparator();
96 edit_menu
->Append(ID_COPY
, "Copy", "Copy text to clipboard.");
97 edit_menu
->Append(ID_CUT
, "Cut", "Cut text to clipboard.");
98 edit_menu
->Append(ID_PASTE
,"Paste", "Paste text from clipboard.");
99 edit_menu
->Append(ID_FIND
, "Find", "Find text.");
100 menu_bar
->Append(edit_menu
, "Edit" );
103 menu_bar
->Show( TRUE
);
106 SetMenuBar( menu_bar
);
108 m_lwin
= new wxLayoutWindow(this);
109 m_lwin
->SetMouseTracking(true);
110 m_lwin
->SetEditable(true);
111 m_lwin
->SetWrapMargin(40);
112 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
117 MyFrame::AddSampleText(wxLayoutList
*llist
)
119 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
120 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
121 llist
->Insert("blue");
122 llist
->SetFont(-1,-1,-1,-1,-1,"black");
123 llist
->Insert("The quick brown fox jumps over the lazy dog.");
126 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
130 llist
->SetFont(wxROMAN
);
131 llist
->Insert("The quick brown fox jumps over the lazy dog.");
133 llist
->Insert("Hello ");
134 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
135 llist
->SetFontWeight(wxBOLD
);
136 llist
->Insert("World! ");
137 llist
->SetFontWeight(wxNORMAL
);
138 llist
->Insert("The quick brown fox jumps...");
140 llist
->Insert("over the lazy dog.");
141 llist
->SetFont(-1,-1,-1,-1,true);
142 llist
->Insert("underlined");
143 llist
->SetFont(-1,-1,-1,-1,false);
144 llist
->SetFont(wxROMAN
);
145 llist
->Insert("This is ");
146 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
147 llist
->Insert("and ");
148 llist
->SetFont(-1,-1,wxITALIC
);
149 llist
->Insert("italics ");
150 llist
->SetFont(-1,-1,wxNORMAL
);
153 llist
->Insert("and ");
154 llist
->SetFont(-1,-1,wxSLANT
);
155 llist
->Insert("slanted");
156 llist
->SetFont(-1,-1,wxNORMAL
);
157 llist
->Insert(" text.");
159 llist
->Insert("and ");
160 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
161 llist
->Insert("blue");
162 llist
->SetFont(-1,-1,-1,-1,-1,"black");
163 llist
->Insert(" and ");
164 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
165 llist
->Insert("green on black");
166 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
167 llist
->Insert(" text.");
170 llist
->SetFont(-1,-1,wxSLANT
);
171 llist
->Insert("Slanted");
172 llist
->SetFont(-1,-1,wxNORMAL
);
173 llist
->Insert(" and normal text and ");
174 llist
->SetFont(-1,-1,wxSLANT
);
175 llist
->Insert("slanted");
176 llist
->SetFont(-1,-1,wxNORMAL
);
177 llist
->Insert(" again.");
180 // add some more text for testing:
181 llist
->Insert("And here the source for the test program:");
183 llist
->SetFont(wxTELETYPE
,16);
185 FILE *in
= fopen("wxLayout.cpp","r");
190 fgets(buffer
,1024,in
);
193 llist
->Insert(buffer
);
197 llist
->MoveCursorTo(wxPoint(0,0));
205 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
209 void MyFrame::OnCommand( wxCommandEvent
&event
)
211 switch (event
.GetId())
219 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
220 if (! printer
.Print(this, &printout
, TRUE
))
222 _("There was a problem with printing the message:\n"
223 "perhaps your current printer is not set up correctly?"),
224 _("Printing"), wxOK
);
229 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
232 AddSampleText(m_lwin
->GetLayoutList());
238 cerr
<< "Received click event." << endl
;
242 m_lwin
->Refresh(FALSE
);
246 m_lwin
->Refresh(FALSE
);
250 m_lwin
->Refresh(FALSE
);
253 m_lwin
->Find("void");
254 m_lwin
->Refresh(FALSE
);
258 wxLayoutExportObject
*export
;
259 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
261 while((export
= wxLayoutExport( &status
,
262 WXLO_EXPORT_AS_HTML
)) != NULL
)
264 if(export
->type
== WXLO_EXPORT_HTML
)
265 cout
<< *(export
->content
.text
);
267 cout
<< "<!--UNKNOWN OBJECT>";
274 wxLayoutExportObject
*export
;
275 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
277 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
279 if(export
->type
== WXLO_EXPORT_TEXT
)
280 cout
<< *(export
->content
.text
);
282 cout
<< "<!--UNKNOWN OBJECT>";
290 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
291 for(int i
= 1; i
< 5000; i
++)
293 line
.Printf("This is line number %d.", i
);
297 llist
->MoveCursorTo(wxPoint(0,0));
305 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
308 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
310 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
313 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
314 if (! printer
.Print(this, &printout
, TRUE
))
316 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
320 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
322 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
325 wxPostScriptPrinter printer
;
326 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
327 printer
.Print(this, &printout
, TRUE
);
331 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
334 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
336 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
338 wxPrintData printData
;
340 // Pass two printout objects: for preview, and possible printing.
341 wxPrintPreview
*preview
= new wxPrintPreview(new
343 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
347 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
351 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
352 frame
->Centre(wxBOTH
);
357 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
359 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
361 wxPrintData printData
;
363 // Pass two printout objects: for preview, and possible printing.
364 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
365 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
366 frame
->Centre(wxBOTH
);
371 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
374 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
376 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
378 wxPrintDialog
printerDialog(this, & m_PrintData
);
379 printerDialog
.ShowModal();
382 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
385 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
387 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
389 wxPageSetupData data
;
392 wxPageSetupDialog
pageSetupDialog(this, & data
);
394 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
396 pageSetupDialog
.ShowModal();
398 data
= pageSetupDialog
.GetPageSetupData();
401 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
403 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
408 wxPrintDialog
printerDialog(this, & data
);
410 wxGenericPrintDialog
printerDialog(this, & data
);
412 printerDialog
.ShowModal();
415 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
417 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
419 wxPageSetupData data
;
421 wxPageSetupDialog
pageSetupDialog(this, & data
);
423 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
425 pageSetupDialog
.ShowModal();
429 //-----------------------------------------------------------------------------
431 //-----------------------------------------------------------------------------
438 bool MyApp::OnInit(void)
440 wxFrame
*frame
= new MyFrame();
442 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");