]>
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
};
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_QUIT
, "Exit");
63 wxMenuBar
*menu_bar
= new wxMenuBar();
64 menu_bar
->Append(file_menu
, "File" );
65 menu_bar
->Show( TRUE
);
67 SetMenuBar( menu_bar
);
69 m_lwin
= new wxLayoutWindow(this);
70 m_lwin
->SetEventId(ID_CLICK
);
71 m_lwin
->GetLayoutList().SetEditable(true);
76 MyFrame::AddSampleText(wxLayoutList
&llist
)
79 llist
.Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
81 llist
.Insert("The quick brown fox jumps over the lazy dog.");
83 llist
.Insert("Hello ");
84 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
86 llist
.SetFontWeight(wxBOLD
);
87 llist
.Insert("World! ");
88 llist
.SetFontWeight(wxNORMAL
);
89 llist
.Insert("The quick brown fox jumps...");
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
);
100 llist
.SetFont(-1,-1,wxITALIC
);
101 llist
.Insert("italics ");
102 llist
.SetFont(-1,-1,wxNORMAL
);
105 llist
.Insert("and ");
106 llist
.SetFont(-1,-1,wxSLANT
);
107 llist
.Insert("slanted");
108 llist
.SetFont(-1,-1,wxNORMAL
);
109 llist
.Insert(" text.");
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.");
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.");
133 // add some more text for testing:
134 llist
.Insert("And here the source for the test program:");
136 llist
.SetFont(wxTELETYPE
,16);
138 FILE *in
= fopen("wxLayout.cpp","r");
143 fgets(buffer
,1024,in
);
146 llist
.Insert(buffer
);
152 m_lwin
->UpdateScrollbars();
159 m_lwin
->UpdateScrollbars();
162 /* test the editing */
163 void MyFrame::Edit(void)
165 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
166 m_lwin
->SetEventId(ID_CLICK
);
170 llist
.MoveCursor(0,2);
173 llist
.Insert("not all so ");
178 void MyFrame::OnCommand( wxCommandEvent
&event
)
180 cerr
<< "id:" << event
.GetId() << endl
;
181 switch (event
.GetId())
192 AddSampleText(llist
);
193 wxPostScriptDC
dc("layout.ps",true,this);
194 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
196 //dc.SetUserScale(1.0, 1.0);
197 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
206 AddSampleText(m_lwin
->GetLayoutList());
211 case ID_WXLAYOUT_DEBUG
:
212 m_lwin
->GetLayoutList().Debug();
215 cerr
<< "Received click event." << endl
;
219 wxLayoutExportObject
*export
;
220 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
222 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
223 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
225 if(export
->type
== WXLO_EXPORT_HTML
)
226 cout
<< *(export
->content
.text
);
228 cout
<< "<!--UNKNOWN OBJECT>";
235 wxLayoutExportObject
*export
;
236 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
238 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
239 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
241 if(export
->type
== WXLO_EXPORT_TEXT
)
242 cout
<< *(export
->content
.text
);
244 cout
<< "<!--UNKNOWN OBJECT>";
253 //-----------------------------------------------------------------------------
255 //-----------------------------------------------------------------------------
262 bool MyApp::OnInit(void)
264 wxFrame
*frame
= new MyFrame();
266 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");