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
,
42 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
43 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
};
46 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
48 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
49 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
50 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
51 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
52 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
53 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
54 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
55 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
56 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
57 EVT_MENU (-1, MyFrame::OnCommand
)
58 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
59 EVT_CHAR ( wxLayoutWindow::OnChar
)
63 MyFrame::MyFrame(void) :
64 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
65 wxPoint(880,100), wxSize(256,256) )
69 SetStatusText( "wxLayout by Karsten Ballüder." );
71 wxMenuBar
*menu_bar
= new wxMenuBar();
73 wxMenu
*file_menu
= new wxMenu
;
74 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
75 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
76 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
77 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
79 file_menu
->AppendSeparator();
80 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
81 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
82 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
83 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
85 file_menu
->AppendSeparator();
86 file_menu
->Append( ID_TEXT
, "Export &Text");
87 file_menu
->Append( ID_HTML
, "Export &HTML");
88 file_menu
->Append( ID_QUIT
, "E&xit");
89 menu_bar
->Append(file_menu
, "&File" );
91 wxMenu
*edit_menu
= new wxMenu
;
92 edit_menu
->Append( ID_CLEAR
, "C&lear");
93 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
94 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
95 edit_menu
->AppendSeparator();
96 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
97 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
98 edit_menu
->AppendSeparator();
99 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
100 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
101 edit_menu
->AppendSeparator();
102 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
103 edit_menu
->Append(ID_CUT
, "Cu&t", "Cut text to clipboard.");
105 edit_menu
->Append(ID_PASTE
,"&Paste", "Paste text from clipboard.");
107 edit_menu
->Append(ID_PASTE_PRIMARY
,"&Paste primary", "Paste text from primary selection.");
108 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
109 menu_bar
->Append(edit_menu
, "&Edit" );
112 menu_bar
->Show( TRUE
);
115 SetMenuBar( menu_bar
);
117 m_lwin
= new wxLayoutWindow(this);
118 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
119 m_lwin
->SetMouseTracking(true);
120 m_lwin
->SetEditable(true);
121 m_lwin
->SetWrapMargin(40);
122 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
125 // create and set the background bitmap (this will result in a lattice)
126 static const int sizeBmp
= 10;
127 wxBitmap
*bitmap
= new wxBitmap(sizeBmp
, sizeBmp
);
129 dcMem
.SelectObject( *bitmap
);
130 dcMem
.SetBackground( *wxWHITE_BRUSH
);
133 dcMem
.SetPen( *wxGREEN_PEN
);
134 dcMem
.DrawLine(sizeBmp
/2, 0, sizeBmp
/2, sizeBmp
);
135 dcMem
.DrawLine(0, sizeBmp
/2, sizeBmp
, sizeBmp
/2);
137 dcMem
.SelectObject( wxNullBitmap
);
139 m_lwin
->SetBackgroundBitmap(bitmap
);
143 MyFrame::AddSampleText(wxLayoutList
*llist
)
145 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
146 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
147 llist
->Insert("blue");
148 llist
->SetFont(-1,-1,-1,-1,-1,"black");
149 llist
->Insert("The quick brown fox jumps over the lazy dog.");
152 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
156 llist
->SetFont(wxROMAN
);
157 llist
->Insert("The quick brown fox jumps over the lazy dog.");
159 llist
->Insert("Hello ");
160 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
161 llist
->SetFontWeight(wxBOLD
);
162 llist
->Insert("World! ");
163 llist
->SetFontWeight(wxNORMAL
);
164 llist
->Insert("The quick brown fox jumps...");
166 llist
->Insert("over the lazy dog.");
167 llist
->SetFont(-1,-1,-1,-1,true);
168 llist
->Insert("underlined");
169 llist
->SetFont(-1,-1,-1,-1,false);
170 llist
->SetFont(wxROMAN
);
171 llist
->Insert("This is ");
172 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
173 llist
->Insert("and ");
174 llist
->SetFont(-1,-1,wxITALIC
);
175 llist
->Insert("italics ");
176 llist
->SetFont(-1,-1,wxNORMAL
);
178 llist
->Insert("and ");
179 llist
->SetFont(-1,-1,wxSLANT
);
180 llist
->Insert("slanted");
181 llist
->SetFont(-1,-1,wxNORMAL
);
182 llist
->Insert(" text.");
184 llist
->Insert("and ");
185 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
186 llist
->Insert("blue");
187 llist
->SetFont(-1,-1,-1,-1,-1,"black");
188 llist
->Insert(" and ");
189 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
190 llist
->Insert("green on black");
191 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
192 llist
->Insert(" text.");
195 llist
->SetFont(-1,-1,wxSLANT
);
196 llist
->Insert("Slanted");
197 llist
->SetFont(-1,-1,wxNORMAL
);
198 llist
->Insert(" and normal text and ");
199 llist
->SetFont(-1,-1,wxSLANT
);
200 llist
->Insert("slanted");
201 llist
->SetFont(-1,-1,wxNORMAL
);
202 llist
->Insert(" again.");
205 // add some more text for testing:
206 llist
->Insert("And here the source for the test program:");
208 llist
->SetFont(wxTELETYPE
,16);
209 llist
->Insert("And here the source for the test program:");
211 llist
->Insert("And here the source for the test program:");
213 llist
->Insert("And here the source for the test program:");
216 FILE *in
= fopen("wxLayout.cpp","r");
221 fgets(buffer
,1024,in
);
224 wxLayoutImportText(llist
, buffer
);
228 llist
->MoveCursorTo(wxPoint(0,0));
236 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
240 void MyFrame::OnCommand( wxCommandEvent
&event
)
242 switch (event
.GetId())
250 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
251 if (! printer
.Print(this, &printout
, TRUE
))
253 _("There was a problem with printing the message:\n"
254 "perhaps your current printer is not set up correctly?"),
255 _("Printing"), wxOK
);
260 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
263 AddSampleText(m_lwin
->GetLayoutList());
269 cerr
<< "Received click event." << endl
;
273 m_lwin
->Refresh(FALSE
);
276 case ID_PASTE_PRIMARY
:
278 m_lwin
->Refresh(FALSE
);
283 m_lwin
->Refresh(FALSE
);
287 m_lwin
->Refresh(FALSE
);
290 m_lwin
->Find("void");
291 m_lwin
->Refresh(FALSE
);
295 wxLayoutExportObject
*export
;
296 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
298 while((export
= wxLayoutExport( &status
,
299 WXLO_EXPORT_AS_HTML
)) != NULL
)
301 if(export
->type
== WXLO_EXPORT_HTML
)
302 cout
<< *(export
->content
.text
);
304 cout
<< "<!--UNKNOWN OBJECT>";
311 wxLayoutExportObject
*export
;
312 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
314 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
316 if(export
->type
== WXLO_EXPORT_TEXT
)
317 cout
<< *(export
->content
.text
);
319 cout
<< "<!--UNKNOWN OBJECT>";
327 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
328 for(int i
= 1; i
< 5000; i
++)
330 line
.Printf("This is line number %d.", i
);
334 llist
->MoveCursorTo(wxPoint(0,0));
340 case ID_LINEBREAKS_TEST
:
341 wxLayoutImportText(m_lwin
->GetLayoutList(),
343 "with embedded line\n"
350 // VZ: this doesn't work, of course, but I think it should -
351 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
352 // (instead of doing it manually like M does now)
353 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
357 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
360 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
362 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
365 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
366 if (! printer
.Print(this, &printout
, TRUE
))
368 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
372 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
374 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
377 wxPostScriptPrinter printer
;
378 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
379 printer
.Print(this, &printout
, TRUE
);
383 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
386 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
388 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
390 wxPrintData printData
;
392 // Pass two printout objects: for preview, and possible printing.
393 wxPrintPreview
*preview
= new wxPrintPreview(new
395 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
399 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
403 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
404 frame
->Centre(wxBOTH
);
409 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
411 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
413 wxPrintData printData
;
415 // Pass two printout objects: for preview, and possible printing.
416 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
417 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
418 frame
->Centre(wxBOTH
);
423 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
426 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
428 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
430 wxPrintDialog
printerDialog(this, & m_PrintData
);
431 printerDialog
.ShowModal();
434 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
437 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
439 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
441 wxPageSetupData data
;
444 wxPageSetupDialog
pageSetupDialog(this, & data
);
446 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
448 pageSetupDialog
.ShowModal();
450 data
= pageSetupDialog
.GetPageSetupData();
453 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
455 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
460 wxPrintDialog
printerDialog(this, & data
);
462 wxGenericPrintDialog
printerDialog(this, & data
);
464 printerDialog
.ShowModal();
467 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
469 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
471 wxPageSetupData data
;
473 wxPageSetupDialog
pageSetupDialog(this, & data
);
475 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
477 pageSetupDialog
.ShowModal();
481 //-----------------------------------------------------------------------------
483 //-----------------------------------------------------------------------------
490 bool MyApp::OnInit(void)
492 wxFrame
*frame
= new MyFrame();
494 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");