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
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
123 llist
->SetFont(wxROMAN
);
124 llist
->Insert("The quick brown fox jumps over the lazy dog.");
126 llist
->Insert("Hello ");
127 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
128 llist
->SetFontWeight(wxBOLD
);
129 llist
->Insert("World! ");
130 llist
->SetFontWeight(wxNORMAL
);
131 llist
->Insert("The quick brown fox jumps...");
134 llist
->Insert("over the lazy dog.");
135 llist
->SetFont(-1,-1,-1,-1,true);
136 llist
->Insert("underlined");
137 llist
->SetFont(-1,-1,-1,-1,false);
138 llist
->SetFont(wxROMAN
);
139 llist
->Insert("This is ");
140 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
141 llist
->Insert("and ");
142 llist
->SetFont(-1,-1,wxITALIC
);
143 llist
->Insert("italics ");
144 llist
->SetFont(-1,-1,wxNORMAL
);
147 llist
->Insert("and ");
148 llist
->SetFont(-1,-1,wxSLANT
);
149 llist
->Insert("slanted");
150 llist
->SetFont(-1,-1,wxNORMAL
);
151 llist
->Insert(" text.");
153 llist
->Insert("and ");
154 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
155 llist
->Insert("blue");
156 llist
->SetFont(-1,-1,-1,-1,-1,"black");
157 llist
->Insert(" and ");
158 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
159 llist
->Insert("green on black");
160 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
161 llist
->Insert(" text.");
164 llist
->SetFont(-1,-1,wxSLANT
);
165 llist
->Insert("Slanted");
166 llist
->SetFont(-1,-1,wxNORMAL
);
167 llist
->Insert(" and normal text and ");
168 llist
->SetFont(-1,-1,wxSLANT
);
169 llist
->Insert("slanted");
170 llist
->SetFont(-1,-1,wxNORMAL
);
171 llist
->Insert(" again.");
174 // add some more text for testing:
175 llist
->Insert("And here the source for the test program:");
177 llist
->SetFont(wxTELETYPE
,16);
179 FILE *in
= fopen("wxLayout.cpp","r");
184 fgets(buffer
,1024,in
);
187 llist
->Insert(buffer
);
191 llist
->MoveCursorTo(wxPoint(0,0));
199 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
203 void MyFrame::OnCommand( wxCommandEvent
&event
)
205 switch (event
.GetId())
213 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
214 if (! printer
.Print(this, &printout
, TRUE
))
216 _("There was a problem with printing the message:\n"
217 "perhaps your current printer is not set up correctly?"),
218 _("Printing"), wxOK
);
223 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
226 AddSampleText(m_lwin
->GetLayoutList());
232 cerr
<< "Received click event." << endl
;
236 m_lwin
->Refresh(FALSE
);
240 m_lwin
->Refresh(FALSE
);
244 m_lwin
->Refresh(FALSE
);
247 m_lwin
->Find("void");
248 m_lwin
->Refresh(FALSE
);
252 wxLayoutExportObject
*export
;
253 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
255 while((export
= wxLayoutExport( &status
,
256 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 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
271 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
273 if(export
->type
== WXLO_EXPORT_TEXT
)
274 cout
<< *(export
->content
.text
);
276 cout
<< "<!--UNKNOWN OBJECT>";
284 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
285 for(int i
= 1; i
< 5000; i
++)
287 line
.Printf("This is line number %d.", i
);
291 llist
->MoveCursorTo(wxPoint(0,0));
299 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
302 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
304 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
307 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
308 if (! printer
.Print(this, &printout
, TRUE
))
310 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
314 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
316 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
319 wxPostScriptPrinter printer
;
320 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
321 printer
.Print(this, &printout
, TRUE
);
325 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
328 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
330 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
332 wxPrintData printData
;
334 // Pass two printout objects: for preview, and possible printing.
335 wxPrintPreview
*preview
= new wxPrintPreview(new
337 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
341 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
345 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
346 frame
->Centre(wxBOTH
);
351 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
353 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
355 wxPrintData printData
;
357 // Pass two printout objects: for preview, and possible printing.
358 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
359 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
360 frame
->Centre(wxBOTH
);
365 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
368 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
370 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
372 wxPrintDialog
printerDialog(this, & m_PrintData
);
373 printerDialog
.ShowModal();
376 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
379 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
381 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
383 wxPageSetupData data
;
386 wxPageSetupDialog
pageSetupDialog(this, & data
);
388 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
390 pageSetupDialog
.ShowModal();
392 data
= pageSetupDialog
.GetPageSetupData();
395 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
397 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
402 wxPrintDialog
printerDialog(this, & data
);
404 wxGenericPrintDialog
printerDialog(this, & data
);
406 printerDialog
.ShowModal();
409 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
411 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
413 wxPageSetupData data
;
415 wxPageSetupDialog
pageSetupDialog(this, & data
);
417 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
419 pageSetupDialog
.ShowModal();
423 //-----------------------------------------------------------------------------
425 //-----------------------------------------------------------------------------
432 bool MyApp::OnInit(void)
434 wxFrame
*frame
= new MyFrame();
436 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");