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 //-----------------------------------------------------------------------------
38 ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
39 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
40 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
41 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
,
44 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
45 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
49 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
51 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
52 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
53 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
54 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
55 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
56 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
57 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
58 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
59 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
60 EVT_MENU (-1, MyFrame::OnCommand
)
61 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
62 EVT_CHAR ( wxLayoutWindow::OnChar
)
66 MyFrame::MyFrame(void) :
67 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
68 wxPoint(880,100), wxSize(256,256) )
72 SetStatusText( "wxLayout by Karsten Ballüder." );
74 wxMenuBar
*menu_bar
= new wxMenuBar();
76 wxMenu
*file_menu
= new wxMenu
;
77 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
78 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
79 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
80 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
82 file_menu
->AppendSeparator();
83 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
84 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
85 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
86 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
88 file_menu
->AppendSeparator();
89 file_menu
->Append( ID_TEXT
, "Export &Text");
90 file_menu
->Append( ID_HTML
, "Export &HTML");
91 file_menu
->Append( ID_QUIT
, "E&xit");
92 menu_bar
->Append(file_menu
, "&File" );
94 wxMenu
*edit_menu
= new wxMenu
;
95 edit_menu
->Append( ID_CLEAR
, "C&lear");
96 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
97 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
98 edit_menu
->AppendSeparator();
99 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
100 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
101 edit_menu
->AppendSeparator();
102 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
103 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
104 edit_menu
->AppendSeparator();
105 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
106 edit_menu
->Append(ID_CUT
, "Cu&t", "Cut text to clipboard.");
108 edit_menu
->Append(ID_PASTE
,"&Paste", "Paste text from clipboard.");
110 edit_menu
->Append(ID_PASTE_PRIMARY
,"&Paste primary", "Paste text from primary selection.");
111 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
112 menu_bar
->Append(edit_menu
, "&Edit" );
115 menu_bar
->Show( TRUE
);
118 SetMenuBar( menu_bar
);
120 m_lwin
= new wxLayoutWindow(this);
121 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
122 m_lwin
->SetMouseTracking(true);
123 m_lwin
->SetEditable(true);
124 m_lwin
->SetWrapMargin(40);
128 // create and set the background bitmap (this will result in a lattice)
129 static const int sizeBmp
= 10;
130 wxBitmap
*bitmap
= new wxBitmap(sizeBmp
, sizeBmp
);
132 dcMem
.SelectObject( *bitmap
);
133 dcMem
.SetBackground( *wxWHITE_BRUSH
);
136 dcMem
.SetPen( *wxGREEN_PEN
);
137 dcMem
.DrawLine(sizeBmp
/2, 0, sizeBmp
/2, sizeBmp
);
138 dcMem
.DrawLine(0, sizeBmp
/2, sizeBmp
, sizeBmp
/2);
140 dcMem
.SelectObject( wxNullBitmap
);
142 m_lwin
->SetBackgroundBitmap(bitmap
);
146 MyFrame::AddSampleText(wxLayoutList
*llist
)
148 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
149 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
150 llist
->Insert("blue");
151 llist
->SetFont(-1,-1,-1,-1,-1,"black");
152 llist
->Insert("The quick brown fox jumps over the lazy dog.");
155 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
159 llist
->SetFont(wxROMAN
);
160 llist
->Insert("The quick brown fox jumps over the lazy dog.");
162 llist
->Insert("Hello ");
163 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
164 llist
->SetFontWeight(wxBOLD
);
165 llist
->Insert("World! ");
166 llist
->SetFontWeight(wxNORMAL
);
167 llist
->Insert("The quick brown fox jumps...");
169 llist
->Insert("over the lazy dog.");
170 llist
->SetFont(-1,-1,-1,-1,true);
171 llist
->Insert("underlined");
172 llist
->SetFont(-1,-1,-1,-1,false);
173 llist
->SetFont(wxROMAN
);
174 llist
->Insert("This is ");
175 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
176 llist
->Insert("and ");
177 llist
->SetFont(-1,-1,wxITALIC
);
178 llist
->Insert("italics ");
179 llist
->SetFont(-1,-1,wxNORMAL
);
181 llist
->Insert("and ");
182 llist
->SetFont(-1,-1,wxSLANT
);
183 llist
->Insert("slanted");
184 llist
->SetFont(-1,-1,wxNORMAL
);
185 llist
->Insert(" text.");
187 llist
->Insert("and ");
188 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
189 llist
->Insert("blue");
190 llist
->SetFont(-1,-1,-1,-1,-1,"black");
191 llist
->Insert(" and ");
192 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
193 llist
->Insert("green on black");
194 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
195 llist
->Insert(" text.");
198 llist
->SetFont(-1,-1,wxSLANT
);
199 llist
->Insert("Slanted");
200 llist
->SetFont(-1,-1,wxNORMAL
);
201 llist
->Insert(" and normal text and ");
202 llist
->SetFont(-1,-1,wxSLANT
);
203 llist
->Insert("slanted");
204 llist
->SetFont(-1,-1,wxNORMAL
);
205 llist
->Insert(" again.");
208 // add some more text for testing:
209 llist
->Insert("And here the source for the test program:");
211 llist
->SetFont(wxTELETYPE
,16);
212 llist
->Insert("And here the source for the test program:");
214 llist
->Insert("And here the source for the test program:");
216 llist
->Insert("And here the source for the test program:");
219 FILE *in
= fopen("wxLayout.cpp","r");
224 fgets(buffer
,1024,in
);
227 wxLayoutImportText(llist
, buffer
);
231 llist
->MoveCursorTo(wxPoint(0,0));
239 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
243 void MyFrame::OnCommand( wxCommandEvent
&event
)
245 switch (event
.GetId())
253 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
254 if (! printer
.Print(this, &printout
, TRUE
))
256 _("There was a problem with printing the message:\n"
257 "perhaps your current printer is not set up correctly?"),
258 _("Printing"), wxOK
);
263 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
266 AddSampleText(m_lwin
->GetLayoutList());
272 cerr
<< "Received click event." << endl
;
276 m_lwin
->Refresh(FALSE
);
279 case ID_PASTE_PRIMARY
:
281 m_lwin
->Refresh(FALSE
);
286 m_lwin
->Refresh(FALSE
);
290 m_lwin
->Refresh(FALSE
);
293 m_lwin
->Find("void");
294 m_lwin
->Refresh(FALSE
);
298 wxLayoutExportObject
*export
;
299 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
301 while((export
= wxLayoutExport( &status
,
302 WXLO_EXPORT_AS_HTML
)) != NULL
)
304 if(export
->type
== WXLO_EXPORT_HTML
)
305 cout
<< *(export
->content
.text
);
307 cout
<< "<!--UNKNOWN OBJECT>";
314 wxLayoutExportObject
*export
;
315 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
317 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
319 if(export
->type
== WXLO_EXPORT_TEXT
)
320 cout
<< *(export
->content
.text
);
322 cout
<< "<!--UNKNOWN OBJECT>";
330 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
331 for(int i
= 1; i
< 5000; i
++)
333 line
.Printf("This is line number %d.", i
);
337 llist
->MoveCursorTo(wxPoint(0,0));
343 case ID_LINEBREAKS_TEST
:
344 wxLayoutImportText(m_lwin
->GetLayoutList(),
346 "with embedded line\n"
353 // VZ: this doesn't work, of course, but I think it should -
354 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
355 // (instead of doing it manually like M does now)
356 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
360 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
363 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
365 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
368 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
369 if (! printer
.Print(this, &printout
, TRUE
))
371 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
375 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
377 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
380 wxPostScriptPrinter printer
;
381 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
382 printer
.Print(this, &printout
, TRUE
);
386 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
389 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
391 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
393 wxPrintData printData
;
395 // Pass two printout objects: for preview, and possible printing.
396 wxPrintPreview
*preview
= new wxPrintPreview(new
398 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
402 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
406 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
407 frame
->Centre(wxBOTH
);
412 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
414 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
416 wxPrintData printData
;
418 // Pass two printout objects: for preview, and possible printing.
419 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
420 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
421 frame
->Centre(wxBOTH
);
426 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
429 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
431 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
433 wxPrintDialog
printerDialog(this, & m_PrintData
);
434 printerDialog
.ShowModal();
437 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
440 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
442 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
444 wxPageSetupData data
;
447 wxPageSetupDialog
pageSetupDialog(this, & data
);
449 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
451 pageSetupDialog
.ShowModal();
453 data
= pageSetupDialog
.GetPageSetupData();
456 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
458 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
463 wxPrintDialog
printerDialog(this, & data
);
465 wxGenericPrintDialog
printerDialog(this, & data
);
467 printerDialog
.ShowModal();
470 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
472 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
474 wxPageSetupData data
;
476 wxPageSetupDialog
pageSetupDialog(this, & data
);
478 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
480 pageSetupDialog
.ShowModal();
484 //-----------------------------------------------------------------------------
486 //-----------------------------------------------------------------------------
493 bool MyApp::OnInit(void)
495 wxFrame
*frame
= new MyFrame();
497 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");