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>
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
44 ID_ADD_SAMPLE
= 1, ID_CLEAR
, ID_PRINT
,
45 ID_PRINT_SETUP
, ID_PAGE_SETUP
, ID_PREVIEW
, ID_PRINT_PS
,
46 ID_PRINT_SETUP_PS
, ID_PAGE_SETUP_PS
,ID_PREVIEW_PS
,
47 ID_WRAP
, ID_NOWRAP
, ID_PASTE
, ID_COPY
, ID_CUT
,
48 ID_COPY_PRIMARY
, ID_PASTE_PRIMARY
,
50 ID_WXLAYOUT_DEBUG
, ID_QUIT
, ID_CLICK
, ID_HTML
, ID_TEXT
,
51 ID_TEST
, ID_LINEBREAKS_TEST
, ID_LONG_TEST
, ID_URL_TEST
55 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
57 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
58 EVT_MENU(ID_PRINT
, MyFrame::OnPrint
)
59 EVT_MENU(ID_PREVIEW
, MyFrame::OnPrintPreview
)
60 EVT_MENU(ID_PRINT_SETUP
, MyFrame::OnPrintSetup
)
61 EVT_MENU(ID_PAGE_SETUP
, MyFrame::OnPageSetup
)
62 EVT_MENU(ID_PRINT_PS
, MyFrame::OnPrintPS
)
63 EVT_MENU(ID_PREVIEW_PS
, MyFrame::OnPrintPreviewPS
)
64 EVT_MENU(ID_PRINT_SETUP_PS
, MyFrame::OnPrintSetupPS
)
65 EVT_MENU(ID_PAGE_SETUP_PS
, MyFrame::OnPageSetupPS
)
66 EVT_MENU (-1, MyFrame::OnCommand
)
67 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
68 EVT_CHAR ( wxLayoutWindow::OnChar
)
72 MyFrame::MyFrame(void) :
73 wxFrame( (wxFrame
*) NULL
, -1, "wxLayout",
74 wxPoint(880,100), wxSize(256,256) )
78 SetStatusText( "wxLayout by Karsten Ballüder." );
80 wxMenuBar
*menu_bar
= new wxMenuBar();
82 wxMenu
*file_menu
= new wxMenu
;
83 file_menu
->Append(ID_PRINT
, "&Print...", "Print");
84 file_menu
->Append(ID_PRINT_SETUP
, "Print &Setup...","Setup printer properties");
85 file_menu
->Append(ID_PAGE_SETUP
, "Page Set&up...", "Page setup");
86 file_menu
->Append(ID_PREVIEW
, "Print Pre&view", "Preview");
88 file_menu
->AppendSeparator();
89 file_menu
->Append(ID_PRINT_PS
, "Print PostScript...", "Print (PostScript)");
90 file_menu
->Append(ID_PRINT_SETUP_PS
, "Print Setup PostScript...", "Setup printer properties (PostScript)");
91 file_menu
->Append(ID_PAGE_SETUP_PS
, "Page Setup PostScript...", "Page setup (PostScript)");
92 file_menu
->Append(ID_PREVIEW_PS
, "Print Preview PostScript", "Preview (PostScript)");
94 file_menu
->AppendSeparator();
95 file_menu
->Append( ID_TEXT
, "Export &Text");
96 file_menu
->Append( ID_HTML
, "Export &HTML");
97 file_menu
->Append( ID_QUIT
, "E&xit");
98 menu_bar
->Append(file_menu
, "&File" );
100 wxMenu
*edit_menu
= new wxMenu
;
101 edit_menu
->Append( ID_CLEAR
, "C&lear");
102 edit_menu
->Append( ID_ADD_SAMPLE
, "&Example");
103 edit_menu
->Append( ID_LONG_TEST
, "Add &many lines");
104 edit_menu
->AppendSeparator();
105 edit_menu
->Append( ID_LINEBREAKS_TEST
, "Add &several lines");
106 edit_menu
->Append( ID_URL_TEST
, "Insert an &URL");
107 edit_menu
->AppendSeparator();
108 edit_menu
->Append(ID_WRAP
, "&Wrap mode", "Activate wrapping at pixel 200.");
109 edit_menu
->Append(ID_NOWRAP
, "&No-wrap mode", "Deactivate wrapping.");
110 edit_menu
->AppendSeparator();
111 edit_menu
->Append(ID_COPY
, "&Copy", "Copy text to clipboard.");
112 edit_menu
->Append(ID_CUT
, "Cu&t", "Cut text to clipboard.");
113 edit_menu
->Append(ID_PASTE
,"&Paste", "Paste text from clipboard.");
115 edit_menu
->Append(ID_COPY_PRIMARY
, "C&opy primary", "Copy text to primary selecton.");
116 edit_menu
->Append(ID_PASTE_PRIMARY
,"&Paste primary", "Paste text from primary selection.");
118 edit_menu
->Append(ID_FIND
, "&Find", "Find text.");
119 menu_bar
->Append(edit_menu
, "&Edit" );
122 menu_bar
->Show( TRUE
);
125 SetMenuBar( menu_bar
);
127 m_lwin
= new wxLayoutWindow(this);
128 m_lwin
->SetStatusBar(GetStatusBar(), 0, 1);
129 m_lwin
->SetMouseTracking(true);
130 m_lwin
->SetEditable(true);
131 m_lwin
->SetWrapMargin(40);
134 // JACS: under MSW, the window doesn't show the caret initially,
135 // and the following line I added doesn't help either.
136 // going to another window and then back again fixes it.
137 // m_lwin->OnSetFocus(wxFocusEvent());
142 // create and set the background bitmap (this will result in a lattice)
143 static const int sizeBmp
= 10;
144 wxBitmap
*bitmap
= new wxBitmap(sizeBmp
, sizeBmp
);
146 dcMem
.SelectObject( *bitmap
);
147 dcMem
.SetBackground( *wxWHITE_BRUSH
);
150 dcMem
.SetPen( *wxGREEN_PEN
);
151 dcMem
.DrawLine(sizeBmp
/2, 0, sizeBmp
/2, sizeBmp
);
152 dcMem
.DrawLine(0, sizeBmp
/2, sizeBmp
, sizeBmp
/2);
154 dcMem
.SelectObject( wxNullBitmap
);
156 m_lwin
->SetBackgroundBitmap(bitmap
);
161 MyFrame::AddSampleText(wxLayoutList
*llist
)
163 llist
->Clear(wxSWISS
,16,wxNORMAL
,wxNORMAL
, false);
164 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
165 llist
->Insert("blue");
166 llist
->SetFont(-1,-1,-1,-1,-1,"black");
167 llist
->Insert("The quick brown fox jumps over the lazy dog.");
170 llist
->SetFont(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
174 llist
->SetFont(wxROMAN
);
175 llist
->Insert("The quick brown fox jumps over the lazy dog.");
177 llist
->Insert("Hello ");
179 llist
->Insert(new wxLayoutObjectIcon(new wxICON(Micon
)));
181 llist
->Insert(new wxLayoutObjectIcon(new wxBitmap (wxICON(Micon
))));
183 llist
->SetFontWeight(wxBOLD
);
184 llist
->Insert("World! ");
185 llist
->SetFontWeight(wxNORMAL
);
186 llist
->Insert("The quick brown fox jumps...");
188 llist
->Insert("over the lazy dog.");
189 llist
->SetFont(-1,-1,-1,-1,true);
190 llist
->Insert("underlined");
191 llist
->SetFont(-1,-1,-1,-1,false);
192 llist
->SetFont(wxROMAN
);
193 llist
->Insert("This is ");
194 llist
->SetFont(-1,-1,-1,wxBOLD
); llist
->Insert("BOLD "); llist
->SetFont(-1,-1,-1,wxNORMAL
);
195 llist
->Insert("and ");
196 llist
->SetFont(-1,-1,wxITALIC
);
197 llist
->Insert("italics ");
198 llist
->SetFont(-1,-1,wxNORMAL
);
200 llist
->Insert("and ");
201 llist
->SetFont(-1,-1,wxSLANT
);
202 llist
->Insert("slanted");
203 llist
->SetFont(-1,-1,wxNORMAL
);
204 llist
->Insert(" text.");
206 llist
->Insert("and ");
207 llist
->SetFont(-1,-1,-1,-1,-1,"blue");
208 llist
->Insert("blue");
209 llist
->SetFont(-1,-1,-1,-1,-1,"black");
210 llist
->Insert(" and ");
211 llist
->SetFont(-1,-1,-1,-1,-1,"green","black");
212 llist
->Insert("green on black");
213 llist
->SetFont(-1,-1,-1,-1,-1,"black","white");
214 llist
->Insert(" text.");
217 llist
->SetFont(-1,-1,wxSLANT
);
218 llist
->Insert("Slanted");
219 llist
->SetFont(-1,-1,wxNORMAL
);
220 llist
->Insert(" and normal text and ");
221 llist
->SetFont(-1,-1,wxSLANT
);
222 llist
->Insert("slanted");
223 llist
->SetFont(-1,-1,wxNORMAL
);
224 llist
->Insert(" again.");
227 // add some more text for testing:
228 llist
->Insert("And here the source for the test program:");
230 llist
->SetFont(wxTELETYPE
,16);
231 llist
->Insert("And here the source for the test program:");
233 llist
->Insert("And here the source for the test program:");
235 llist
->Insert("And here the source for the test program:");
238 FILE *in
= fopen("wxLayout.cpp","r");
243 fgets(buffer
,1024,in
);
246 wxLayoutImportText(llist
, buffer
);
250 llist
->MoveCursorTo(wxPoint(0,0));
258 wxColour
colBg(0, 0, 0);
260 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false, wxRED
, &colBg
);
264 void MyFrame::OnCommand( wxCommandEvent
&event
)
266 switch (event
.GetId())
274 wxLayoutPrintout
printout(m_lwin
->GetLayoutList(),_("M: Printout"));
275 if (! printer
.Print(this, &printout
, TRUE
))
277 // Had to remove the split up strings that used to be below, and
278 // put them into one long strong. Otherwise MSVC would give an
279 // error "C2308: concatenating mismatched wide strings" when
280 // building a Unicode version.
283 _("There was a problem with printing the message:\nperhaps your current printer is not set up correctly?"),
292 m_lwin
->SetWrapMargin(event
.GetId() == ID_NOWRAP
? 0 : 40);
295 AddSampleText(m_lwin
->GetLayoutList());
301 cerr
<< "Received click event." << endl
;
305 m_lwin
->Refresh(FALSE
);
308 case ID_PASTE_PRIMARY
:
309 // text only from primary:
310 m_lwin
->Paste(FALSE
, TRUE
);
311 m_lwin
->Refresh(FALSE
);
313 case ID_COPY_PRIMARY
:
314 // copy text-only to primary selection:
315 m_lwin
->Copy(FALSE
,FALSE
,TRUE
);
316 m_lwin
->Refresh(FALSE
);
320 m_lwin
->Copy(TRUE
,TRUE
,FALSE
);
321 m_lwin
->Refresh(FALSE
);
325 m_lwin
->Refresh(FALSE
);
329 m_lwin
->Find("void");
330 m_lwin
->Refresh(FALSE
);
335 wxLayoutExportObject
*export0
;
336 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
338 cout
<< "<HTML>" << endl
;
339 while((export0
= wxLayoutExport( &status
,
340 WXLO_EXPORT_AS_HTML
)) != NULL
)
342 if(export0
->type
== WXLO_EXPORT_HTML
)
343 cout
<< *(export0
->content
.text
);
345 ; // ignore itcout << "<!--UNKNOWN OBJECT>";
354 wxLayoutExportObject
*export0
;
355 wxLayoutExportStatus
status(m_lwin
->GetLayoutList());
357 while((export0
= wxLayoutExport( &status
, WXLO_EXPORT_AS_TEXT
)) != NULL
)
359 if(export0
->type
== WXLO_EXPORT_TEXT
)
360 cout
<< *(export0
->content
.text
);
362 cout
<< "<!--UNKNOWN OBJECT>";
374 wxLayoutList
*llist
= m_lwin
->GetLayoutList();
375 for(int i
= 1; i
< 300; i
++)
377 line
.Printf(wxT("This is line number %d."), i
);
382 llist
->MoveCursorTo(wxPoint(0,0));
388 case ID_LINEBREAKS_TEST
:
391 m_lwin
->GetLayoutList(),
392 wxT("This is a text\nwith embedded line\nbreaks.\n")
400 // VZ: this doesn't work, of course, but I think it should -
401 // wxLayoutWindow should have a flag m_highlightUrls and do it itself
402 // (instead of doing it manually like M does now)
403 m_lwin
->GetLayoutList()->Insert("http://www.wxwindows.org/");
407 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
410 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
412 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
415 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"Printout from wxLayout");
416 if (! printer
.Print(this, &printout
, TRUE
))
418 "There was a problem printing.\nPerhaps your current printer is not set correctly?",
422 void MyFrame::OnPrintPS(wxCommandEvent
& WXUNUSED(event
))
424 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
427 wxPostScriptPrinter printer
;
428 wxLayoutPrintout
printout( m_lwin
->GetLayoutList(),"My printout");
429 printer
.Print(this, &printout
, TRUE
);
433 void MyFrame::OnPrintPreview(wxCommandEvent
& WXUNUSED(event
))
436 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
438 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
440 wxPrintData printData
;
442 // Pass two printout objects: for preview, and possible printing.
443 wxPrintPreview
*preview
= new wxPrintPreview(new
445 m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
449 wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK
);
453 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
454 frame
->Centre(wxBOTH
);
459 void MyFrame::OnPrintPreviewPS(wxCommandEvent
& WXUNUSED(event
))
461 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
463 wxPrintData printData
;
465 // Pass two printout objects: for preview, and possible printing.
466 wxPrintPreview
*preview
= new wxPrintPreview(new wxLayoutPrintout( m_lwin
->GetLayoutList()), new wxLayoutPrintout( m_lwin
->GetLayoutList()), & printData
);
467 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
468 frame
->Centre(wxBOTH
);
473 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
476 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
478 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
480 wxPrintDialog
printerDialog(this, & m_PrintData
);
481 printerDialog
.ShowModal();
484 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
487 wxGetApp().SetPrintMode(wxPRINT_WINDOWS
);
489 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
491 wxPageSetupData data
;
493 #if defined(__WXMSW__) || defined(__WXMAC__)
494 wxPageSetupDialog
pageSetupDialog(this, & data
);
496 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
498 pageSetupDialog
.ShowModal();
500 data
= pageSetupDialog
.GetPageSetupData();
503 void MyFrame::OnPrintSetupPS(wxCommandEvent
& WXUNUSED(event
))
505 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
509 #if defined(__WXMSW__) || defined(__WXMAC__)
510 wxPrintDialog
printerDialog(this, & data
);
512 wxGenericPrintDialog
printerDialog(this, & data
);
514 printerDialog
.ShowModal();
517 void MyFrame::OnPageSetupPS(wxCommandEvent
& WXUNUSED(event
))
519 wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT
);
521 wxPageSetupData data
;
522 #if defined(__WXMSW__) || defined(__WXMAC__)
523 wxPageSetupDialog
pageSetupDialog(this, & data
);
525 wxGenericPageSetupDialog
pageSetupDialog(this, & data
);
527 pageSetupDialog
.ShowModal();
531 //-----------------------------------------------------------------------------
533 //-----------------------------------------------------------------------------
540 bool MyApp::OnInit(void)
542 wxFrame
*frame
= new MyFrame();
543 wxInitAllImageHandlers();
545 // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");