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>
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
40 ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
41 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
42 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
43 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
,
44 ID_COPY_PRIMARY
, ID_PASTE_PRIMARY
,
46 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
47 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
51 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
53 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
54 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
55 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
56 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
57 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
58 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
59 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
60 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
61 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
62 EVT_MENU (-1, MyFrame::OnCommand
)
63 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
64 EVT_CHAR ( wxLayoutWindow::OnChar
)
68 MyFrame::MyFrame(void) :
69 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
70 wxPoint(880,100), wxSize(256,256) )
74 SetStatusText( "wxLayout by Karsten Ballüder." );
76 wxMenuBar
*menu_bar
= new wxMenuBar();
78 wxMenu
*file_menu
= new wxMenu
;
79 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
80 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
81 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
82 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
84 file_menu
->AppendSeparator();
85 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
86 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
87 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
88 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
90 file_menu
->AppendSeparator();
91 file_menu
->Append( ID_TEXT
, "Export &Text");
92 file_menu
->Append( ID_HTML
, "Export &HTML");
93 file_menu
->Append( ID_QUIT
, "E&xit");
94 menu_bar
->Append(file_menu
, "&File" );
96 wxMenu
*edit_menu
= new wxMenu
;
97 edit_menu
->Append( ID_CLEAR
, "C&lear");
98 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
99 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
100 edit_menu
->AppendSeparator();
101 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
102 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
103 edit_menu
->AppendSeparator();
104 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
105 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
106 edit_menu
->AppendSeparator();
107 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
108 edit_menu
->Append(ID_CUT
, "Cu&t", "Cut text to clipboard.");
109 edit_menu
->Append(ID_PASTE
,"&Paste", "Paste text from clipboard.");
111 edit_menu
->Append(ID_COPY_PRIMARY
, "C&opy primary", "Copy text to primary selecton.");
112 edit_menu
->Append(ID_PASTE_PRIMARY
,"&Paste primary", "Paste text from primary selection.");
114 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
115 menu_bar
->Append(edit_menu
, "&Edit" );
118 menu_bar
->Show( TRUE
);
121 SetMenuBar( menu_bar
);
123 m_lwin
= new wxLayoutWindow(this);
124 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
125 m_lwin
->SetMouseTracking(true);
126 m_lwin
->SetEditable(true);
127 m_lwin
->SetWrapMargin(40);
130 // JACS: under MSW, the window doesn't show the caret initially,
131 // and the following line I added doesn't help either.
132 // going to another window and then back again fixes it.
133 // m_lwin->OnSetFocus(wxFocusEvent());
138 // create and set the background bitmap (this will result in a lattice)
139 static const int sizeBmp
= 10;
140 wxBitmap
*bitmap
= new wxBitmap(sizeBmp
, sizeBmp
);
142 dcMem
.SelectObject( *bitmap
);
143 dcMem
.SetBackground( *wxWHITE_BRUSH
);
146 dcMem
.SetPen( *wxGREEN_PEN
);
147 dcMem
.DrawLine(sizeBmp
/2, 0, sizeBmp
/2, sizeBmp
);
148 dcMem
.DrawLine(0, sizeBmp
/2, sizeBmp
, sizeBmp
/2);
150 dcMem
.SelectObject( wxNullBitmap
);
152 m_lwin
->SetBackgroundBitmap(bitmap
);
157 MyFrame::AddSampleText(wxLayoutList
*llist
)
159 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
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("The quick brown fox jumps over the lazy dog.");
166 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
170 llist
->SetFont(wxROMAN
);
171 llist
->Insert("The quick brown fox jumps over the lazy dog.");
173 llist
->Insert("Hello ");
174 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
175 llist
->SetFontWeight(wxBOLD
);
176 llist
->Insert("World! ");
177 llist
->SetFontWeight(wxNORMAL
);
178 llist
->Insert("The quick brown fox jumps...");
180 llist
->Insert("over the lazy dog.");
181 llist
->SetFont(-1,-1,-1,-1,true);
182 llist
->Insert("underlined");
183 llist
->SetFont(-1,-1,-1,-1,false);
184 llist
->SetFont(wxROMAN
);
185 llist
->Insert("This is ");
186 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
187 llist
->Insert("and ");
188 llist
->SetFont(-1,-1,wxITALIC
);
189 llist
->Insert("italics ");
190 llist
->SetFont(-1,-1,wxNORMAL
);
192 llist
->Insert("and ");
193 llist
->SetFont(-1,-1,wxSLANT
);
194 llist
->Insert("slanted");
195 llist
->SetFont(-1,-1,wxNORMAL
);
196 llist
->Insert(" text.");
198 llist
->Insert("and ");
199 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
200 llist
->Insert("blue");
201 llist
->SetFont(-1,-1,-1,-1,-1,"black");
202 llist
->Insert(" and ");
203 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
204 llist
->Insert("green on black");
205 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
206 llist
->Insert(" text.");
209 llist
->SetFont(-1,-1,wxSLANT
);
210 llist
->Insert("Slanted");
211 llist
->SetFont(-1,-1,wxNORMAL
);
212 llist
->Insert(" and normal text and ");
213 llist
->SetFont(-1,-1,wxSLANT
);
214 llist
->Insert("slanted");
215 llist
->SetFont(-1,-1,wxNORMAL
);
216 llist
->Insert(" again.");
219 // add some more text for testing:
220 llist
->Insert("And here the source for the test program:");
222 llist
->SetFont(wxTELETYPE
,16);
223 llist
->Insert("And here the source for the test program:");
225 llist
->Insert("And here the source for the test program:");
227 llist
->Insert("And here the source for the test program:");
230 FILE *in
= fopen("wxLayout.cpp","r");
235 fgets(buffer
,1024,in
);
238 wxLayoutImportText(llist
, buffer
);
242 llist
->MoveCursorTo(wxPoint(0,0));
250 wxColour
colBg(0, 0, 0);
252 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false, wxRED
, &colBg
);
256 void MyFrame::OnCommand( wxCommandEvent
&event
)
258 switch (event
.GetId())
266 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
267 if (! printer
.Print(this, &printout
, TRUE
))
269 _("There was a problem with printing the message:\n"
270 "perhaps your current printer is not set up correctly?"),
271 _("Printing"), wxOK
);
276 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
279 AddSampleText(m_lwin
->GetLayoutList());
285 cerr
<< "Received click event." << endl
;
289 m_lwin
->Refresh(FALSE
);
292 case ID_PASTE_PRIMARY
:
293 // text only from primary:
294 m_lwin
->Paste(FALSE
, TRUE
);
295 m_lwin
->Refresh(FALSE
);
297 case ID_COPY_PRIMARY
:
298 // copy text-only to primary selection:
299 m_lwin
->Copy(FALSE
,FALSE
,TRUE
);
300 m_lwin
->Refresh(FALSE
);
304 m_lwin
->Copy(TRUE
,TRUE
,FALSE
);
305 m_lwin
->Refresh(FALSE
);
309 m_lwin
->Refresh(FALSE
);
313 m_lwin
->Find("void");
314 m_lwin
->Refresh(FALSE
);
319 wxLayoutExportObject
*export0
;
320 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
322 cout
<< "<HTML>" << endl
;
323 while((export0
= wxLayoutExport( &status
,
324 WXLO_EXPORT_AS_HTML
)) != NULL
)
326 if(export0
->type
== WXLO_EXPORT_HTML
)
327 cout
<< *(export0
->content
.text
);
329 ; // ignore itcout << "<!--UNKNOWN OBJECT>";
336 wxLayoutExportObject
*export0
;
337 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
339 while((export0
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
341 if(export0
->type
== WXLO_EXPORT_TEXT
)
342 cout
<< *(export0
->content
.text
);
344 cout
<< "<!--UNKNOWN OBJECT>";
352 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
353 for(int i
= 1; i
< 300; i
++)
355 line
.Printf("This is line number %d.", i
);
359 llist
->MoveCursorTo(wxPoint(0,0));
365 case ID_LINEBREAKS_TEST
:
366 wxLayoutImportText(m_lwin
->GetLayoutList(),
368 "with embedded line\n"
375 // VZ: this doesn't work, of course, but I think it should -
376 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
377 // (instead of doing it manually like M does now)
378 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
382 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
385 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
387 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
390 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
391 if (! printer
.Print(this, &printout
, TRUE
))
393 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
397 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
399 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
402 wxPostScriptPrinter printer
;
403 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
404 printer
.Print(this, &printout
, TRUE
);
408 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
411 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
413 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
415 wxPrintData printData
;
417 // Pass two printout objects: for preview, and possible printing.
418 wxPrintPreview
*preview
= new wxPrintPreview(new
420 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
424 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
428 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
429 frame
->Centre(wxBOTH
);
434 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
436 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
438 wxPrintData printData
;
440 // Pass two printout objects: for preview, and possible printing.
441 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
442 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
443 frame
->Centre(wxBOTH
);
448 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
451 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
453 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
455 wxPrintDialog
printerDialog(this, & m_PrintData
);
456 printerDialog
.ShowModal();
459 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
462 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
464 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
466 wxPageSetupData data
;
469 wxPageSetupDialog
pageSetupDialog(this, & data
);
471 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
473 pageSetupDialog
.ShowModal();
475 data
= pageSetupDialog
.GetPageSetupData();
478 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
480 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
485 wxPrintDialog
printerDialog(this, & data
);
487 wxGenericPrintDialog
printerDialog(this, & data
);
489 printerDialog
.ShowModal();
492 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
494 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
496 wxPageSetupData data
;
498 wxPageSetupDialog
pageSetupDialog(this, & data
);
500 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
502 pageSetupDialog
.ShowModal();
506 //-----------------------------------------------------------------------------
508 //-----------------------------------------------------------------------------
515 bool MyApp::OnInit(void)
517 wxFrame
*frame
= new MyFrame();
518 wxInitAllImageHandlers();
520 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");