]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxLayout.cpp
wxMDIChildFrame inherits from wxFrame
[wxWidgets.git] / user / wxLayout / wxLayout.cpp
1 /*
2 * Program: wxLayout
3 *
4 * Author: Karsten Ballüder
5 *
6 * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
7 *
8 */
9
10 #ifdef __GNUG__
11 #pragma implementation "wxLayout.h"
12 #endif
13
14 #include "wxLayout.h"
15 #include "wx/textfile.h"
16
17
18 #include "Micon.xpm"
19
20 // for testing only:
21 #include <stdio.h>
22
23 //-----------------------------------------------------------------------------
24 // main program
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_APP(MyApp)
28
29 //-----------------------------------------------------------------------------
30 // MyFrame
31 //-----------------------------------------------------------------------------
32
33 enum ids{ ID_EDIT = 1, ID_ADD_SAMPLE, ID_CLEAR, ID_PRINT, ID_DPRINT,
34 ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT };
35
36
37 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
38
39 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
40 EVT_MENU (-1, MyFrame::OnCommand)
41 EVT_COMMAND (-1,-1, MyFrame::OnCommand)
42 EVT_CHAR ( wxLayoutWindow::OnChar )
43 END_EVENT_TABLE()
44
45 MyFrame::MyFrame(void) :
46 wxFrame( NULL, -1, "wxLayout", wxPoint(20,20), wxSize(600,360) )
47 {
48 CreateStatusBar( 1 );
49
50 SetStatusText( "wxLayout by Karsten Ballüder." );
51
52 wxMenu *file_menu = new wxMenu( "Menu 1" );
53 file_menu->Append( ID_CLEAR, "Clear");
54 file_menu->Append( ID_ADD_SAMPLE, "Example");
55 file_menu->Append( ID_EDIT, "Edit");
56 file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
57 file_menu->Append( ID_PRINT, "Print");
58 file_menu->Append( ID_DPRINT, "Direct Print");
59 file_menu->Append( ID_TEXT, "Export Text");
60 file_menu->Append( ID_HTML, "Export HTML");
61 file_menu->Append( ID_QUIT, "Exit");
62
63 wxMenuBar *menu_bar = new wxMenuBar();
64 menu_bar->Append(file_menu, "File" );
65 menu_bar->Show( TRUE );
66
67 SetMenuBar( menu_bar );
68
69 m_lwin = new wxLayoutWindow(this);
70 m_lwin->SetEventId(ID_CLICK);
71 m_lwin->GetLayoutList().SetEditable(true);
72 m_lwin->SetFocus();
73 };
74
75 void
76 MyFrame::AddSampleText(wxLayoutList &llist)
77 {
78
79 llist.Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
80
81 llist.Insert("The quick brown fox jumps over the lazy dog.");
82 llist.LineBreak();
83 llist.Insert("Hello ");
84 llist.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm,-1,-1)));
85 llist.LineBreak();
86 llist.SetFontWeight(wxBOLD);
87 llist.Insert("World! ");
88 llist.SetFontWeight(wxNORMAL);
89 llist.Insert("The quick brown fox jumps...");
90 llist.LineBreak();
91
92 llist.Insert("over the lazy dog.");
93 llist.SetFont(-1,-1,-1,-1,true);
94 llist.Insert("underlined");
95 llist.SetFont(-1,-1,-1,-1,false);
96 llist.SetFont(wxROMAN);
97 llist.Insert("This is ");
98 llist.SetFont(-1,-1,-1,wxBOLD); llist.Insert("BOLD "); llist.SetFont(-1,-1,-1,wxNORMAL);
99 llist.Insert("and ");
100 llist.SetFont(-1,-1,wxITALIC);
101 llist.Insert("italics ");
102 llist.SetFont(-1,-1,wxNORMAL);
103 llist.LineBreak();
104
105 llist.Insert("and ");
106 llist.SetFont(-1,-1,wxSLANT);
107 llist.Insert("slanted");
108 llist.SetFont(-1,-1,wxNORMAL);
109 llist.Insert(" text.");
110 llist.LineBreak();
111
112 llist.Insert("and ");
113 llist.SetFont(-1,-1,-1,-1,-1,"blue");
114 llist.Insert("blue");
115 llist.SetFont(-1,-1,-1,-1,-1,"black");
116 llist.Insert(" and ");
117 llist.SetFont(-1,-1,-1,-1,-1,"red","black");
118 llist.Insert("red on black");
119 llist.SetFont(-1,-1,-1,-1,-1,"black","white");
120 llist.Insert(" text.");
121 llist.LineBreak();
122
123 llist.SetFont(-1,-1,wxSLANT);
124 llist.Insert("Slanted");
125 llist.SetFont(-1,-1,wxNORMAL);
126 llist.Insert(" and normal text and ");
127 llist.SetFont(-1,-1,wxSLANT);
128 llist.Insert("slanted");
129 llist.SetFont(-1,-1,wxNORMAL);
130 llist.Insert(" again.");
131 llist.LineBreak();
132
133 // add some more text for testing:
134 llist.Insert("And here the source for the test program:");
135 llist.LineBreak();
136 llist.SetFont(wxTELETYPE,16);
137 char buffer[1024];
138 FILE *in = fopen("wxLayout.cpp","r");
139 if(in)
140 {
141 for(;;)
142 {
143 fgets(buffer,1024,in);
144 if(feof(in))
145 break;
146 llist.Insert(buffer);
147 llist.LineBreak();
148 }
149 }
150
151 m_lwin->Refresh();
152 m_lwin->UpdateScrollbars();
153 }
154
155 void
156 MyFrame::Clear(void)
157 {
158 m_lwin->Erase();
159 m_lwin->UpdateScrollbars();
160 }
161
162 /* test the editing */
163 void MyFrame::Edit(void)
164 {
165 wxLayoutList & llist = m_lwin->GetLayoutList();
166 m_lwin->SetEventId(ID_CLICK);
167
168 llist.MoveCursor(0);
169 llist.MoveCursor(5);
170 llist.MoveCursor(0,2);
171 llist.Delete(2);
172 llist.MoveCursor(2);
173 llist.Insert("not all so ");
174 llist.LineBreak();
175 m_lwin->Refresh();
176 }
177
178 void MyFrame::OnCommand( wxCommandEvent &event )
179 {
180 cerr << "id:" << event.GetId() << endl;
181 switch (event.GetId())
182 {
183 case ID_QUIT:
184 Close( TRUE );
185 break;
186 case ID_PRINT:
187 m_lwin->Print();
188 break;
189 case ID_DPRINT:
190 {
191 wxLayoutList llist;
192 AddSampleText(llist);
193 wxPostScriptDC dc("layout.ps",true,this);
194 if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
195 {
196 //dc.SetUserScale(1.0, 1.0);
197 llist.Draw(dc); //,false,wxPoint(0,0),true);
198 dc.EndDoc();
199 }
200 }
201 break;
202 case ID_EDIT:
203 Edit();
204 break;
205 case ID_ADD_SAMPLE:
206 AddSampleText(m_lwin->GetLayoutList());
207 break;
208 case ID_CLEAR:
209 Clear();
210 break;
211 case ID_WXLAYOUT_DEBUG:
212 m_lwin->GetLayoutList().Debug();
213 break;
214 case ID_CLICK:
215 cerr << "Received click event." << endl;
216 break;
217 case ID_HTML:
218 {
219 wxLayoutExportObject *export;
220 wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
221
222 while((export = wxLayoutExport(m_lwin->GetLayoutList(),
223 i,WXLO_EXPORT_AS_HTML)) != NULL)
224 {
225 if(export->type == WXLO_EXPORT_HTML)
226 cout << *(export->content.text);
227 else
228 cout << "<!--UNKNOWN OBJECT>";
229 delete export;
230 }
231 }
232 break;
233 case ID_TEXT:
234 {
235 wxLayoutExportObject *export;
236 wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
237
238 while((export = wxLayoutExport(m_lwin->GetLayoutList(),
239 i,WXLO_EXPORT_AS_TEXT)) != NULL)
240 {
241 if(export->type == WXLO_EXPORT_TEXT)
242 cout << *(export->content.text);
243 else
244 cout << "<!--UNKNOWN OBJECT>";
245 delete export;
246 }
247 }
248 break;
249 }
250 };
251
252
253 //-----------------------------------------------------------------------------
254 // MyApp
255 //-----------------------------------------------------------------------------
256
257 MyApp::MyApp(void) :
258 wxApp( )
259 {
260 };
261
262 bool MyApp::OnInit(void)
263 {
264 wxFrame *frame = new MyFrame();
265 frame->Show( TRUE );
266 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
267 return TRUE;
268 };
269
270
271
272
273