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