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 ");
175 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
177 llist
->Insert(new wxLayoutObjectIcon(new wxBitmap (wxICON(Micon
))));
179 llist
->SetFontWeight(wxBOLD
);
180 llist
->Insert("World! ");
181 llist
->SetFontWeight(wxNORMAL
);
182 llist
->Insert("The quick brown fox jumps...");
184 llist
->Insert("over the lazy dog.");
185 llist
->SetFont(-1,-1,-1,-1,true);
186 llist
->Insert("underlined");
187 llist
->SetFont(-1,-1,-1,-1,false);
188 llist
->SetFont(wxROMAN
);
189 llist
->Insert("This is ");
190 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
191 llist
->Insert("and ");
192 llist
->SetFont(-1,-1,wxITALIC
);
193 llist
->Insert("italics ");
194 llist
->SetFont(-1,-1,wxNORMAL
);
196 llist
->Insert("and ");
197 llist
->SetFont(-1,-1,wxSLANT
);
198 llist
->Insert("slanted");
199 llist
->SetFont(-1,-1,wxNORMAL
);
200 llist
->Insert(" text.");
202 llist
->Insert("and ");
203 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
204 llist
->Insert("blue");
205 llist
->SetFont(-1,-1,-1,-1,-1,"black");
206 llist
->Insert(" and ");
207 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
208 llist
->Insert("green on black");
209 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
210 llist
->Insert(" text.");
213 llist
->SetFont(-1,-1,wxSLANT
);
214 llist
->Insert("Slanted");
215 llist
->SetFont(-1,-1,wxNORMAL
);
216 llist
->Insert(" and normal text and ");
217 llist
->SetFont(-1,-1,wxSLANT
);
218 llist
->Insert("slanted");
219 llist
->SetFont(-1,-1,wxNORMAL
);
220 llist
->Insert(" again.");
223 // add some more text for testing:
224 llist
->Insert("And here the source for the test program:");
226 llist
->SetFont(wxTELETYPE
,16);
227 llist
->Insert("And here the source for the test program:");
229 llist
->Insert("And here the source for the test program:");
231 llist
->Insert("And here the source for the test program:");
234 FILE *in
= fopen("wxLayout.cpp","r");
239 fgets(buffer
,1024,in
);
242 wxLayoutImportText(llist
, buffer
);
246 llist
->MoveCursorTo(wxPoint(0,0));
254 wxColour
colBg(0, 0, 0);
256 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false, wxRED
, &colBg
);
260 void MyFrame::OnCommand( wxCommandEvent
&event
)
262 switch (event
.GetId())
270 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
271 if (! printer
.Print(this, &printout
, TRUE
))
273 _("There was a problem with printing the message:\n"
274 "perhaps your current printer is not set up correctly?"),
275 _("Printing"), wxOK
);
280 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
283 AddSampleText(m_lwin
->GetLayoutList());
289 cerr
<< "Received click event." << endl
;
293 m_lwin
->Refresh(FALSE
);
296 case ID_PASTE_PRIMARY
:
297 // text only from primary:
298 m_lwin
->Paste(FALSE
, TRUE
);
299 m_lwin
->Refresh(FALSE
);
301 case ID_COPY_PRIMARY
:
302 // copy text-only to primary selection:
303 m_lwin
->Copy(FALSE
,FALSE
,TRUE
);
304 m_lwin
->Refresh(FALSE
);
308 m_lwin
->Copy(TRUE
,TRUE
,FALSE
);
309 m_lwin
->Refresh(FALSE
);
313 m_lwin
->Refresh(FALSE
);
317 m_lwin
->Find("void");
318 m_lwin
->Refresh(FALSE
);
323 wxLayoutExportObject
*export0
;
324 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
326 cout
<< "<HTML>" << endl
;
327 while((export0
= wxLayoutExport( &status
,
328 WXLO_EXPORT_AS_HTML
)) != NULL
)
330 if(export0
->type
== WXLO_EXPORT_HTML
)
331 cout
<< *(export0
->content
.text
);
333 ; // ignore itcout << "<!--UNKNOWN OBJECT>";
340 wxLayoutExportObject
*export0
;
341 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
343 while((export0
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
345 if(export0
->type
== WXLO_EXPORT_TEXT
)
346 cout
<< *(export0
->content
.text
);
348 cout
<< "<!--UNKNOWN OBJECT>";
356 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
357 for(int i
= 1; i
< 300; i
++)
359 line
.Printf("This is line number %d.", i
);
363 llist
->MoveCursorTo(wxPoint(0,0));
369 case ID_LINEBREAKS_TEST
:
370 wxLayoutImportText(m_lwin
->GetLayoutList(),
372 "with embedded line\n"
379 // VZ: this doesn't work, of course, but I think it should -
380 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
381 // (instead of doing it manually like M does now)
382 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
386 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
389 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
391 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
394 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
395 if (! printer
.Print(this, &printout
, TRUE
))
397 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
401 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
403 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
406 wxPostScriptPrinter printer
;
407 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
408 printer
.Print(this, &printout
, TRUE
);
412 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
415 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
417 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
419 wxPrintData printData
;
421 // Pass two printout objects: for preview, and possible printing.
422 wxPrintPreview
*preview
= new wxPrintPreview(new
424 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
428 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
432 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
433 frame
->Centre(wxBOTH
);
438 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
440 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
442 wxPrintData printData
;
444 // Pass two printout objects: for preview, and possible printing.
445 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
446 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
447 frame
->Centre(wxBOTH
);
452 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
455 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
457 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
459 wxPrintDialog
printerDialog(this, & m_PrintData
);
460 printerDialog
.ShowModal();
463 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
466 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
468 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
470 wxPageSetupData data
;
473 wxPageSetupDialog
pageSetupDialog(this, & data
);
475 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
477 pageSetupDialog
.ShowModal();
479 data
= pageSetupDialog
.GetPageSetupData();
482 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
484 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
489 wxPrintDialog
printerDialog(this, & data
);
491 wxGenericPrintDialog
printerDialog(this, & data
);
493 printerDialog
.ShowModal();
496 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
498 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
500 wxPageSetupData data
;
502 wxPageSetupDialog
pageSetupDialog(this, & data
);
504 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
506 pageSetupDialog
.ShowModal();
510 //-----------------------------------------------------------------------------
512 //-----------------------------------------------------------------------------
519 bool MyApp::OnInit(void)
521 wxFrame
*frame
= new MyFrame();
522 wxInitAllImageHandlers();
524 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");