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>
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
39 ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
40 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
41 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
42 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
,
45 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
46 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
50 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
52 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
53 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
54 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
55 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
56 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
57 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
58 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
59 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
60 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
61 EVT_MENU (-1, MyFrame::OnCommand
)
62 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
63 EVT_CHAR ( wxLayoutWindow::OnChar
)
67 MyFrame::MyFrame(void) :
68 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
69 wxPoint(880,100), wxSize(256,256) )
73 SetStatusText( "wxLayout by Karsten Ballüder." );
75 wxMenuBar
*menu_bar
= new wxMenuBar();
77 wxMenu
*file_menu
= new wxMenu
;
78 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
79 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
80 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
81 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
83 file_menu
->AppendSeparator();
84 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
85 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
86 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
87 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
89 file_menu
->AppendSeparator();
90 file_menu
->Append( ID_TEXT
, "Export &Text");
91 file_menu
->Append( ID_HTML
, "Export &HTML");
92 file_menu
->Append( ID_QUIT
, "E&xit");
93 menu_bar
->Append(file_menu
, "&File" );
95 wxMenu
*edit_menu
= new wxMenu
;
96 edit_menu
->Append( ID_CLEAR
, "C&lear");
97 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
98 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
99 edit_menu
->AppendSeparator();
100 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
101 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
102 edit_menu
->AppendSeparator();
103 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
104 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
105 edit_menu
->AppendSeparator();
106 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
107 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_PASTE_PRIMARY
,"&Paste primary", "Paste text from primary selection.");
112 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
113 menu_bar
->Append(edit_menu
, "&Edit" );
116 menu_bar
->Show( TRUE
);
119 SetMenuBar( menu_bar
);
121 m_lwin
= new wxLayoutWindow(this);
122 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
123 m_lwin
->SetMouseTracking(true);
124 m_lwin
->SetEditable(true);
125 m_lwin
->SetWrapMargin(40);
128 // JACS: under MSW, the window doesn't show the caret initially,
129 // and the following line I added doesn't help either.
130 // going to another window and then back again fixes it.
131 // m_lwin->OnSetFocus(wxFocusEvent());
136 // create and set the background bitmap (this will result in a lattice)
137 static const int sizeBmp
= 10;
138 wxBitmap
*bitmap
= new wxBitmap(sizeBmp
, sizeBmp
);
140 dcMem
.SelectObject( *bitmap
);
141 dcMem
.SetBackground( *wxWHITE_BRUSH
);
144 dcMem
.SetPen( *wxGREEN_PEN
);
145 dcMem
.DrawLine(sizeBmp
/2, 0, sizeBmp
/2, sizeBmp
);
146 dcMem
.DrawLine(0, sizeBmp
/2, sizeBmp
, sizeBmp
/2);
148 dcMem
.SelectObject( wxNullBitmap
);
150 m_lwin
->SetBackgroundBitmap(bitmap
);
155 MyFrame::AddSampleText(wxLayoutList
*llist
)
157 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
158 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
159 llist
->Insert("blue");
160 llist
->SetFont(-1,-1,-1,-1,-1,"black");
161 llist
->Insert("The quick brown fox jumps over the lazy dog.");
164 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
168 llist
->SetFont(wxROMAN
);
169 llist
->Insert("The quick brown fox jumps over the lazy dog.");
171 llist
->Insert("Hello ");
172 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
173 llist
->SetFontWeight(wxBOLD
);
174 llist
->Insert("World! ");
175 llist
->SetFontWeight(wxNORMAL
);
176 llist
->Insert("The quick brown fox jumps...");
178 llist
->Insert("over the lazy dog.");
179 llist
->SetFont(-1,-1,-1,-1,true);
180 llist
->Insert("underlined");
181 llist
->SetFont(-1,-1,-1,-1,false);
182 llist
->SetFont(wxROMAN
);
183 llist
->Insert("This is ");
184 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
185 llist
->Insert("and ");
186 llist
->SetFont(-1,-1,wxITALIC
);
187 llist
->Insert("italics ");
188 llist
->SetFont(-1,-1,wxNORMAL
);
190 llist
->Insert("and ");
191 llist
->SetFont(-1,-1,wxSLANT
);
192 llist
->Insert("slanted");
193 llist
->SetFont(-1,-1,wxNORMAL
);
194 llist
->Insert(" text.");
196 llist
->Insert("and ");
197 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
198 llist
->Insert("blue");
199 llist
->SetFont(-1,-1,-1,-1,-1,"black");
200 llist
->Insert(" and ");
201 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
202 llist
->Insert("green on black");
203 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
204 llist
->Insert(" text.");
207 llist
->SetFont(-1,-1,wxSLANT
);
208 llist
->Insert("Slanted");
209 llist
->SetFont(-1,-1,wxNORMAL
);
210 llist
->Insert(" and normal text and ");
211 llist
->SetFont(-1,-1,wxSLANT
);
212 llist
->Insert("slanted");
213 llist
->SetFont(-1,-1,wxNORMAL
);
214 llist
->Insert(" again.");
217 // add some more text for testing:
218 llist
->Insert("And here the source for the test program:");
220 llist
->SetFont(wxTELETYPE
,16);
221 llist
->Insert("And here the source for the test program:");
223 llist
->Insert("And here the source for the test program:");
225 llist
->Insert("And here the source for the test program:");
228 FILE *in
= fopen("wxLayout.cpp","r");
233 fgets(buffer
,1024,in
);
236 wxLayoutImportText(llist
, buffer
);
240 llist
->MoveCursorTo(wxPoint(0,0));
248 wxColour
colBg(0, 0, 0);
250 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false, wxRED
, &colBg
);
254 void MyFrame::OnCommand( wxCommandEvent
&event
)
256 switch (event
.GetId())
264 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
265 if (! printer
.Print(this, &printout
, TRUE
))
267 _("There was a problem with printing the message:\n"
268 "perhaps your current printer is not set up correctly?"),
269 _("Printing"), wxOK
);
274 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
277 AddSampleText(m_lwin
->GetLayoutList());
283 cerr
<< "Received click event." << endl
;
287 m_lwin
->Refresh(FALSE
);
290 case ID_PASTE_PRIMARY
:
292 m_lwin
->Refresh(FALSE
);
297 m_lwin
->Refresh(FALSE
);
301 m_lwin
->Refresh(FALSE
);
305 m_lwin
->Find("void");
306 m_lwin
->Refresh(FALSE
);
311 wxLayoutExportObject
*export
;
312 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
314 while((export
= wxLayoutExport( &status
,
315 WXLO_EXPORT_AS_HTML
)) != NULL
)
317 if(export
->type
== WXLO_EXPORT_HTML
)
318 cout
<< *(export
->content
.text
);
320 cout
<< "<!--UNKNOWN OBJECT>";
327 wxLayoutExportObject
*export
;
328 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
330 while((export
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
332 if(export
->type
== WXLO_EXPORT_TEXT
)
333 cout
<< *(export
->content
.text
);
335 cout
<< "<!--UNKNOWN OBJECT>";
343 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
344 for(int i
= 1; i
< 300; i
++)
346 line
.Printf("This is line number %d.", i
);
350 llist
->MoveCursorTo(wxPoint(0,0));
356 case ID_LINEBREAKS_TEST
:
357 wxLayoutImportText(m_lwin
->GetLayoutList(),
359 "with embedded line\n"
366 // VZ: this doesn't work, of course, but I think it should -
367 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
368 // (instead of doing it manually like M does now)
369 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
373 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
376 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
378 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
381 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
382 if (! printer
.Print(this, &printout
, TRUE
))
384 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
388 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
390 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
393 wxPostScriptPrinter printer
;
394 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
395 printer
.Print(this, &printout
, TRUE
);
399 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
402 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
404 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
406 wxPrintData printData
;
408 // Pass two printout objects: for preview, and possible printing.
409 wxPrintPreview
*preview
= new wxPrintPreview(new
411 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
415 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
419 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
420 frame
->Centre(wxBOTH
);
425 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
427 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
429 wxPrintData printData
;
431 // Pass two printout objects: for preview, and possible printing.
432 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
433 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
434 frame
->Centre(wxBOTH
);
439 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
442 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
444 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
446 wxPrintDialog
printerDialog(this, & m_PrintData
);
447 printerDialog
.ShowModal();
450 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
453 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
455 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
457 wxPageSetupData data
;
460 wxPageSetupDialog
pageSetupDialog(this, & data
);
462 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
464 pageSetupDialog
.ShowModal();
466 data
= pageSetupDialog
.GetPageSetupData();
469 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
471 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
476 wxPrintDialog
printerDialog(this, & data
);
478 wxGenericPrintDialog
printerDialog(this, & data
);
480 printerDialog
.ShowModal();
483 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
485 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
487 wxPageSetupData data
;
489 wxPageSetupDialog
pageSetupDialog(this, & data
);
491 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
493 pageSetupDialog
.ShowModal();
497 //-----------------------------------------------------------------------------
499 //-----------------------------------------------------------------------------
506 bool MyApp::OnInit(void)
508 wxFrame
*frame
= new MyFrame();
510 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");