]>
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);
72 m_lwin
->Clear(wxROMAN
,16,wxNORMAL
,wxNORMAL
, false);
77 MyFrame::AddSampleText(wxLayoutList
&llist
)
80 llist
.Insert("The quick brown fox jumps over the lazy dog.");
82 llist
.Insert("Hello ");
83 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
85 llist
.SetFontWeight(wxBOLD
);
86 llist
.Insert("World! ");
87 llist
.SetFontWeight(wxNORMAL
);
88 llist
.Insert("The quick brown fox jumps...");
91 llist
.Insert("over the lazy dog.");
92 llist
.SetFont(-1,-1,-1,-1,true);
93 llist
.Insert("underlined");
94 llist
.SetFont(-1,-1,-1,-1,false);
95 llist
.SetFont(wxROMAN
);
96 llist
.Insert("This is ");
97 llist
.SetFont(-1,-1,-1,wxBOLD
); llist
.Insert("BOLD "); llist
.SetFont(-1,-1,-1,wxNORMAL
);
99 llist
.SetFont(-1,-1,wxITALIC
);
100 llist
.Insert("italics ");
101 llist
.SetFont(-1,-1,wxNORMAL
);
104 llist
.Insert("and ");
105 llist
.SetFont(-1,-1,wxSLANT
);
106 llist
.Insert("slanted");
107 llist
.SetFont(-1,-1,wxNORMAL
);
108 llist
.Insert(" text.");
111 llist
.Insert("and ");
112 llist
.SetFont(-1,-1,-1,-1,-1,"blue");
113 llist
.Insert("blue");
114 llist
.SetFont(-1,-1,-1,-1,-1,"black");
115 llist
.Insert(" and ");
116 llist
.SetFont(-1,-1,-1,-1,-1,"green","black");
117 llist
.Insert("green on black");
118 llist
.SetFont(-1,-1,-1,-1,-1,"black","white");
119 llist
.Insert(" text.");
122 llist
.SetFont(-1,-1,wxSLANT
);
123 llist
.Insert("Slanted");
124 llist
.SetFont(-1,-1,wxNORMAL
);
125 llist
.Insert(" and normal text and ");
126 llist
.SetFont(-1,-1,wxSLANT
);
127 llist
.Insert("slanted");
128 llist
.SetFont(-1,-1,wxNORMAL
);
129 llist
.Insert(" again.");
132 // add some more text for testing:
133 llist
.Insert("And here the source for the test program:");
135 llist
.SetFont(wxTELETYPE
,16);
137 FILE *in
= fopen("wxLayout.cpp","r");
142 fgets(buffer
,1024,in
);
145 llist
.Insert(buffer
);
151 m_lwin
->UpdateScrollbars();
158 m_lwin
->UpdateScrollbars();
161 /* test the editing */
162 void MyFrame::Edit(void)
164 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
165 m_lwin
->SetEventId(ID_CLICK
);
169 llist
.MoveCursor(0,2);
172 llist
.Insert("not all so ");
177 void MyFrame::OnCommand( wxCommandEvent
&event
)
179 cerr
<< "id:" << event
.GetId() << endl
;
180 switch (event
.GetId())
191 AddSampleText(llist
);
192 wxPostScriptDC
dc("layout.ps",true,this);
193 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
195 //dc.SetUserScale(1.0, 1.0);
196 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
205 AddSampleText(m_lwin
->GetLayoutList());
210 case ID_WXLAYOUT_DEBUG
:
211 m_lwin
->GetLayoutList().Debug();
214 cerr
<< "Received click event." << endl
;
218 wxLayoutExportObject
*export
;
219 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
221 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
222 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
224 if(export
->type
== WXLO_EXPORT_HTML
)
225 cout
<< *(export
->content
.text
);
227 cout
<< "<!--UNKNOWN OBJECT>";
234 wxLayoutExportObject
*export
;
235 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
237 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
238 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
240 if(export
->type
== WXLO_EXPORT_TEXT
)
241 cout
<< *(export
->content
.text
);
243 cout
<< "<!--UNKNOWN OBJECT>";
252 //-----------------------------------------------------------------------------
254 //-----------------------------------------------------------------------------
261 bool MyApp::OnInit(void)
263 wxFrame
*frame
= new MyFrame();
265 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");