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
)
120 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
121 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
122 llist
->Insert("blue");
123 llist
->SetFont(-1,-1,-1,-1,-1,"black");
124 llist
->Insert("The quick brown fox jumps over the lazy dog.");
128 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
132 llist
->SetFont(wxROMAN
);
133 llist
->Insert("The quick brown fox jumps over the lazy dog.");
135 llist
->Insert("Hello ");
136 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
137 llist
->SetFontWeight(wxBOLD
);
138 llist
->Insert("World! ");
139 llist
->SetFontWeight(wxNORMAL
);
140 llist
->Insert("The quick brown fox jumps...");
142 llist
->Insert("over the lazy dog.");
143 llist
->SetFont(-1,-1,-1,-1,true);
144 llist
->Insert("underlined");
145 llist
->SetFont(-1,-1,-1,-1,false);
146 llist
->SetFont(wxROMAN
);
147 llist
->Insert("This is ");
148 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
149 llist
->Insert("and ");
150 llist
->SetFont(-1,-1,wxITALIC
);
151 llist
->Insert("italics ");
152 llist
->SetFont(-1,-1,wxNORMAL
);
156 llist
->Insert("and ");
157 llist
->SetFont(-1,-1,wxSLANT
);
158 llist
->Insert("slanted");
159 llist
->SetFont(-1,-1,wxNORMAL
);
160 llist
->Insert(" text.");
162 llist
->Insert("and ");
163 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
164 llist
->Insert("blue");
165 llist
->SetFont(-1,-1,-1,-1,-1,"black");
166 llist
->Insert(" and ");
167 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
168 llist
->Insert("green on black");
169 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
170 llist
->Insert(" text.");
173 llist
->SetFont(-1,-1,wxSLANT
);
174 llist
->Insert("Slanted");
175 llist
->SetFont(-1,-1,wxNORMAL
);
176 llist
->Insert(" and normal text and ");
177 llist
->SetFont(-1,-1,wxSLANT
);
178 llist
->Insert("slanted");
179 llist
->SetFont(-1,-1,wxNORMAL
);
180 llist
->Insert(" again.");
183 // add some more text for testing:
184 llist
->Insert("And here the source for the test program:");
186 llist
->SetFont(wxTELETYPE
,16);
188 FILE *in
= fopen("wxLayout.cpp","r");
193 fgets(buffer
,1024,in
);
196 llist
->Insert(buffer
);
201 llist
->MoveCursorTo(wxPoint(0,0));
209 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
213 void MyFrame::OnCommand( wxCommandEvent
&event
)
215 switch (event
.GetId())
223 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
224 if (! printer
.Print(this, &printout
, TRUE
))
226 _("There was a problem with printing the message:\n"
227 "perhaps your current printer is not set up correctly?"),
228 _("Printing"), wxOK
);
233 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
236 AddSampleText(m_lwin
->GetLayoutList());
242 cerr
<< "Received click event." << endl
;
246 m_lwin
->Refresh(FALSE
);
250 m_lwin
->Refresh(FALSE
);
254 m_lwin
->Refresh(FALSE
);
257 m_lwin
->Find("void");
258 m_lwin
->Refresh(FALSE
);
262 wxLayoutExportObject
*export
;
263 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
265 while((export
= wxLayoutExport( &status
,
266 WXLO_EXPORT_AS_HTML
)) != NULL
)
268 if(export
->type
== WXLO_EXPORT_HTML
)
269 cout
<< *(export
->content
.text
);
271 cout
<< "<!--UNKNOWN OBJECT>";
278 wxLayoutExportObject
*export
;
279 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
281 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
283 if(export
->type
== WXLO_EXPORT_TEXT
)
284 cout
<< *(export
->content
.text
);
286 cout
<< "<!--UNKNOWN OBJECT>";
294 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
295 for(int i
= 1; i
< 5000; i
++)
297 line
.Printf("This is line number %d.", i
);
301 llist
->MoveCursorTo(wxPoint(0,0));
309 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
312 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
314 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
317 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
318 if (! printer
.Print(this, &printout
, TRUE
))
320 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
324 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
326 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
329 wxPostScriptPrinter printer
;
330 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
331 printer
.Print(this, &printout
, TRUE
);
335 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
338 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
340 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
342 wxPrintData printData
;
344 // Pass two printout objects: for preview, and possible printing.
345 wxPrintPreview
*preview
= new wxPrintPreview(new
347 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
351 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
355 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
356 frame
->Centre(wxBOTH
);
361 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
363 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
365 wxPrintData printData
;
367 // Pass two printout objects: for preview, and possible printing.
368 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
369 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
370 frame
->Centre(wxBOTH
);
375 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
378 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
380 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
382 wxPrintDialog
printerDialog(this, & m_PrintData
);
383 printerDialog
.ShowModal();
386 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
389 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
391 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
393 wxPageSetupData data
;
396 wxPageSetupDialog
pageSetupDialog(this, & data
);
398 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
400 pageSetupDialog
.ShowModal();
402 data
= pageSetupDialog
.GetPageSetupData();
405 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
407 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
412 wxPrintDialog
printerDialog(this, & data
);
414 wxGenericPrintDialog
printerDialog(this, & data
);
416 printerDialog
.ShowModal();
419 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
421 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
423 wxPageSetupData data
;
425 wxPageSetupDialog
pageSetupDialog(this, & data
);
427 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
429 pageSetupDialog
.ShowModal();
433 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
442 bool MyApp::OnInit(void)
444 wxFrame
*frame
= new MyFrame();
446 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");