]>
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
)
82 llist
.Insert("The quick brown fox jumps over the lazy dog.");
84 llist
.Insert("Hello ");
85 llist
.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm
,-1,-1)));
87 llist
.SetFontWeight(wxBOLD
);
88 llist
.Insert("World! ");
89 llist
.SetFontWeight(wxNORMAL
);
90 llist
.Insert("The quick brown fox jumps...");
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
);
106 llist
.Insert("and ");
107 llist
.SetFont(-1,-1,wxSLANT
);
108 llist
.Insert("slanted");
109 llist
.SetFont(-1,-1,wxNORMAL
);
110 llist
.Insert(" text.");
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.");
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.");
134 // add some more text for testing:
135 llist
.Insert("And here the source for the test program:");
137 llist
.SetFont(wxTELETYPE
,16);
139 FILE *in
= fopen("wxLayout.cpp","r");
144 fgets(buffer
,1024,in
);
147 llist
.Insert(buffer
);
153 m_lwin
->UpdateScrollbars();
155 llist
.SetCursor(wxPoint(0,0));
162 m_lwin
->UpdateScrollbars();
165 /* test the editing */
166 void MyFrame::Edit(void)
168 wxLayoutList
& llist
= m_lwin
->GetLayoutList();
169 m_lwin
->SetEventId(ID_CLICK
);
173 llist
.MoveCursor(0,2);
181 void MyFrame::OnCommand( wxCommandEvent
&event
)
183 cerr
<< "id:" << event
.GetId() << endl
;
184 switch (event
.GetId())
195 AddSampleText(llist
);
196 wxPostScriptDC
dc("layout.ps",true,this);
197 if (dc
.Ok() && dc
.StartDoc((char *)_("Printing message...")))
199 //dc.SetUserScale(1.0, 1.0);
200 llist
.Draw(dc
); //,false,wxPoint(0,0),true);
209 AddSampleText(m_lwin
->GetLayoutList());
214 case ID_WXLAYOUT_DEBUG
:
215 m_lwin
->GetLayoutList().Debug();
218 cerr
<< "Received click event." << endl
;
222 wxLayoutExportObject
*export
;
223 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
225 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
226 i
,WXLO_EXPORT_AS_HTML
)) != NULL
)
228 if(export
->type
== WXLO_EXPORT_HTML
)
229 cout
<< *(export
->content
.text
);
231 cout
<< "<!--UNKNOWN OBJECT>";
238 wxLayoutExportObject
*export
;
239 wxLayoutList::iterator i
= m_lwin
->GetLayoutList().begin();
241 while((export
= wxLayoutExport(m_lwin
->GetLayoutList(),
242 i
,WXLO_EXPORT_AS_TEXT
)) != NULL
)
244 if(export
->type
== WXLO_EXPORT_TEXT
)
245 cout
<< *(export
->content
.text
);
247 cout
<< "<!--UNKNOWN OBJECT>";
256 //-----------------------------------------------------------------------------
258 //-----------------------------------------------------------------------------
265 bool MyApp::OnInit(void)
267 wxFrame
*frame
= new MyFrame();
269 wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");