]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxLayout.cpp
Added wxFrame::OnCreateStatusBar and ToolBar
[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, ID_TEST };
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_TEST, "Test");
62 file_menu->Append( ID_QUIT, "Exit");
63
64 wxMenuBar *menu_bar = new wxMenuBar();
65 menu_bar->Append(file_menu, "File" );
66 menu_bar->Show( TRUE );
67
68 SetMenuBar( menu_bar );
69
70 m_lwin = new wxLayoutWindow(this);
71 m_lwin->SetEventId(ID_CLICK);
72 m_lwin->GetLayoutList().SetEditable(true);
73 m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
74 m_lwin->SetFocus();
75 };
76
77 void
78 MyFrame::AddSampleText(wxLayoutList &llist)
79 {
80 llist.Insert("--");
81 llist.LineBreak();
82
83 llist.Insert("The quick brown fox jumps over the lazy dog.");
84 llist.LineBreak();
85 llist.Insert("Hello ");
86 llist.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm,-1,-1)));
87 llist.LineBreak();
88 llist.SetFontWeight(wxBOLD);
89 llist.Insert("World! ");
90 llist.SetFontWeight(wxNORMAL);
91 llist.Insert("The quick brown fox jumps...");
92 llist.LineBreak();
93
94 llist.Insert("over the lazy dog.");
95 llist.SetFont(-1,-1,-1,-1,true);
96 llist.Insert("underlined");
97 llist.SetFont(-1,-1,-1,-1,false);
98 llist.SetFont(wxROMAN);
99 llist.Insert("This is ");
100 llist.SetFont(-1,-1,-1,wxBOLD); llist.Insert("BOLD "); llist.SetFont(-1,-1,-1,wxNORMAL);
101 llist.Insert("and ");
102 llist.SetFont(-1,-1,wxITALIC);
103 llist.Insert("italics ");
104 llist.SetFont(-1,-1,wxNORMAL);
105 llist.LineBreak();
106
107 llist.Insert("and ");
108 llist.SetFont(-1,-1,wxSLANT);
109 llist.Insert("slanted");
110 llist.SetFont(-1,-1,wxNORMAL);
111 llist.Insert(" text.");
112 llist.LineBreak();
113
114 llist.Insert("and ");
115 llist.SetFont(-1,-1,-1,-1,-1,"blue");
116 llist.Insert("blue");
117 llist.SetFont(-1,-1,-1,-1,-1,"black");
118 llist.Insert(" and ");
119 llist.SetFont(-1,-1,-1,-1,-1,"green","black");
120 llist.Insert("green on black");
121 llist.SetFont(-1,-1,-1,-1,-1,"black","white");
122 llist.Insert(" text.");
123 llist.LineBreak();
124
125 llist.SetFont(-1,-1,wxSLANT);
126 llist.Insert("Slanted");
127 llist.SetFont(-1,-1,wxNORMAL);
128 llist.Insert(" and normal text and ");
129 llist.SetFont(-1,-1,wxSLANT);
130 llist.Insert("slanted");
131 llist.SetFont(-1,-1,wxNORMAL);
132 llist.Insert(" again.");
133 llist.LineBreak();
134
135 // add some more text for testing:
136 llist.Insert("And here the source for the test program:");
137 llist.LineBreak();
138 llist.SetFont(wxTELETYPE,16);
139 char buffer[1024];
140 FILE *in = fopen("wxLayout.cpp","r");
141 if(in)
142 {
143 for(;;)
144 {
145 fgets(buffer,1024,in);
146 if(feof(in))
147 break;
148 llist.Insert(buffer);
149 llist.LineBreak();
150 }
151 }
152
153 m_lwin->Refresh();
154 m_lwin->UpdateScrollbars();
155 llist.SetEditable();
156 llist.SetCursor(wxPoint(0,0));
157 }
158
159 void
160 MyFrame::Clear(void)
161 {
162 m_lwin->Erase();
163 m_lwin->UpdateScrollbars();
164 }
165
166 /* test the editing */
167 void MyFrame::Edit(void)
168 {
169 wxLayoutList & llist = m_lwin->GetLayoutList();
170 m_lwin->SetEventId(ID_CLICK);
171
172 llist.MoveCursor(0);
173 llist.MoveCursor(5);
174 llist.MoveCursor(0,2);
175 llist.Delete(2);
176 llist.MoveCursor(2);
177 llist.Insert("not");
178 llist.LineBreak();
179 m_lwin->Refresh();
180 }
181
182 void MyFrame::OnCommand( wxCommandEvent &event )
183 {
184 cerr << "id:" << event.GetId() << endl;
185 switch (event.GetId())
186 {
187 case ID_QUIT:
188 Close( TRUE );
189 break;
190 case ID_PRINT:
191 m_lwin->Print();
192 break;
193 case ID_DPRINT:
194 {
195 wxLayoutList llist;
196 AddSampleText(llist);
197 wxPostScriptDC dc("layout.ps",true,this);
198 if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
199 {
200 //dc.SetUserScale(1.0, 1.0);
201 llist.Draw(dc); //,false,wxPoint(0,0),true);
202 dc.EndDoc();
203 }
204 }
205 break;
206 case ID_EDIT:
207 Edit();
208 break;
209 case ID_ADD_SAMPLE:
210 AddSampleText(m_lwin->GetLayoutList());
211 break;
212 case ID_CLEAR:
213 Clear();
214 break;
215 case ID_WXLAYOUT_DEBUG:
216 m_lwin->GetLayoutList().Debug();
217 break;
218 case ID_CLICK:
219 cerr << "Received click event." << endl;
220 break;
221 case ID_TEST:
222 {
223 Clear();
224 m_lwin->GetLayoutList().LineBreak();
225 m_lwin->GetLayoutList().Insert("abc");
226 m_lwin->GetLayoutList().LineBreak();
227 m_lwin->GetLayoutList().Insert("def");
228 break;
229 }
230 case ID_HTML:
231 {
232 wxLayoutExportObject *export;
233 wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
234
235 while((export = wxLayoutExport(m_lwin->GetLayoutList(),
236 i,WXLO_EXPORT_AS_HTML)) != NULL)
237 {
238 if(export->type == WXLO_EXPORT_HTML)
239 cout << *(export->content.text);
240 else
241 cout << "<!--UNKNOWN OBJECT>";
242 delete export;
243 }
244 }
245 break;
246 case ID_TEXT:
247 {
248 wxLayoutExportObject *export;
249 wxLayoutList::iterator i = m_lwin->GetLayoutList().begin();
250
251 while((export = wxLayoutExport(m_lwin->GetLayoutList(),
252 i,WXLO_EXPORT_AS_TEXT)) != NULL)
253 {
254 if(export->type == WXLO_EXPORT_TEXT)
255 cout << *(export->content.text);
256 else
257 cout << "<!--UNKNOWN OBJECT>";
258 delete export;
259 }
260 }
261 break;
262 }
263 };
264
265
266 //-----------------------------------------------------------------------------
267 // MyApp
268 //-----------------------------------------------------------------------------
269
270 MyApp::MyApp(void) :
271 wxApp( )
272 {
273 };
274
275 bool MyApp::OnInit(void)
276 {
277 wxFrame *frame = new MyFrame();
278 frame->Show( TRUE );
279 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
280 return TRUE;
281 };
282
283
284
285
286