]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxLayout.cpp
4 * Author: Karsten Ballüder
6 * Copyright: (C) 1998, Karsten Ballüder <Ballueder@usa.net>
11 #pragma implementation "wxLayout.h"
15 #include "wx/textfile.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
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
};
37 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
39 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
40 EVT_MENU (-1, MyFrame::OnCommand
)
41 EVT_COMMAND (-1,-1, MyFrame::OnCommand
)
42 EVT_CHAR ( wxLayoutWindow::OnChar
)
45 MyFrame::MyFrame(void) :
46 wxFrame( NULL
, -1, "wxLayout", wxPoint(20,20), wxSize(600,360) )
50 SetStatusText( "wxLayout by Karsten Ballüder." );
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");
64 wxMenuBar
*menu_bar
= new wxMenuBar();
65 menu_bar
->Append(file_menu
, "File" );
66 menu_bar
->Show( TRUE
);
68 SetMenuBar( menu_bar
);
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);
78 MyFrame::AddSampleText(wxLayoutList
&llist
)
83 llist
.Insert("The quick brown fox jumps over the lazy dog.");
85 llist
.Insert("Hello ");
86 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
88 llist
.SetFontWeight(wxBOLD
);
89 llist
.Insert("World! ");
90 llist
.SetFontWeight(wxNORMAL
);
91 llist
.Insert("The quick brown fox jumps...");
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
);
107 llist
.Insert("and ");
108 llist
.SetFont(-1,-1,wxSLANT
);
109 llist
.Insert("slanted");
110 llist
.SetFont(-1,-1,wxNORMAL
);
111 llist
.Insert(" text.");
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.");
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.");
135 // add some more text for testing:
136 llist
.Insert("And here the source for the test program:");
138 llist
.SetFont(wxTELETYPE
,16);
140 FILE *in
= fopen("wxLayout.cpp","r");
145 fgets(buffer
,1024,in
);
148 llist
.Insert(buffer
);
154 m_lwin
->UpdateScrollbars();
156 llist
.SetCursor(wxPoint(0,0));
163 m_lwin
->UpdateScrollbars();
166 /* test the editing */
167 void MyFrame::Edit(void)
169 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
170 m_lwin
->SetEventId(ID_CLICK
);
174 llist
.MoveCursor(0,2);
182 void MyFrame::OnCommand( wxCommandEvent
&event
)
184 cerr
<< "id:" << event
.GetId() << endl
;
185 switch (event
.GetId())
196 AddSampleText(llist
);
197 wxPostScriptDC
dc("layout.ps",true,this);
198 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
200 //dc.SetUserScale(1.0, 1.0);
201 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
210 AddSampleText(m_lwin
->GetLayoutList());
215 case ID_WXLAYOUT_DEBUG
:
216 m_lwin
->GetLayoutList().Debug();
219 cerr
<< "Received click event." << endl
;
224 m_lwin
->GetLayoutList().LineBreak();
225 m_lwin
->GetLayoutList().Insert("abc");
226 m_lwin
->GetLayoutList().LineBreak();
227 m_lwin
->GetLayoutList().Insert("def");
232 wxLayoutExportObject
*export
;
233 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
235 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
236 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
238 if(export
->type
== WXLO_EXPORT_HTML
)
239 cout
<< *(export
->content
.text
);
241 cout
<< "<!--UNKNOWN OBJECT>";
248 wxLayoutExportObject
*export
;
249 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
251 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
252 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
254 if(export
->type
== WXLO_EXPORT_TEXT
)
255 cout
<< *(export
->content
.text
);
257 cout
<< "<!--UNKNOWN OBJECT>";
266 //-----------------------------------------------------------------------------
268 //-----------------------------------------------------------------------------
275 bool MyApp::OnInit(void)
277 wxFrame
*frame
= new MyFrame();
279 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");