]>
git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/samples/gui/gui.cpp
3 * Purpose: Minimal wxWidgets plugin
7 * Copyright: (c) Julian Smart
10 /* static const char sccsid[] = "%W% %G%"; */
12 #include "wx/wxprec.h"
29 // Define a new application type
30 class MyApp
: public wxPluginApp
32 virtual wxFrame
*OnInit(void);
33 virtual wxPluginFrame
* OnNewInstance(const wxPluginData
& data
);
36 // Define a new frame type
37 class MyFrame
: public wxPluginFrame
39 MyFrame(const wxPluginData
& data
);
42 // Let's paint directly onto the 'frame'; we don't need a subwindow
43 void OnPaint(wxPaintEvent
& event
);
44 void OnMouseEvent(wxMouseEvent
& event
);
45 void OnHello(wxCommandEvent
& event
);
47 // Called when the file has been downloaded
48 virtual void OnNPNewFile(NPStream
*stream
, const wxString
& fname
);
50 void CentreStrings(wxDC
& dc
);
55 wxStringList m_strings
;
60 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
61 EVT_SIZE(MyFrame::OnSize
)
62 EVT_PAINT(MyFrame::OnPaint
)
63 EVT_MOUSE_EVENTS(MyFrame::OnMouseEvent
)
64 EVT_BUTTON(ID_HELLO
, MyFrame::OnHello
)
69 // No app initialisation necessary, and for a plugin there is no
71 wxFrame
*MyApp::OnInit(void)
76 // Called whenever a new plugin instance is called. We could check
77 // various things here in 'data' but we won't bother.
78 wxPluginFrame
* MyApp::OnNewInstance(const wxPluginData
& data
)
80 // Implicitly added to list of plugin frames
81 return new MyFrame(data
);
84 // My frame constructor
85 MyFrame::MyFrame(const wxPluginData
& data
):
91 wxMenuBar
*menuBar
= new wxMenuBar
;
92 wxMenu
*menu
= new wxMenu
;
93 menu
->Append(1, "E&xit");
94 menuBar
->Append(menu
, "&File");
98 new wxTextCtrl(this, -1, "", wxPoint(10, 30), wxSize(200, 25), wxSUNKEN_BORDER
);
99 new wxButton(this, ID_HELLO
, "Hello", wxPoint(10, 70));
102 void MyFrame::OnPaint(wxPaintEvent
& event
)
106 dc
.SetBrush(*wxCYAN_BRUSH
);
107 dc
.SetPen(*wxRED_PEN
);
110 GetClientSize(&w
, &h
);
112 dc
.DrawRectangle(0, 0, w
, h
);
114 wxFont
swissFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
115 dc
.SetFont(swissFont
);
116 dc
.SetBackgroundMode(wxTRANSPARENT
);
121 // Called when the file has been downloaded
122 void MyFrame::OnNPNewFile(NPStream
*stream
, const wxString
& fname
)
130 str
.getline(buf
, 200);
138 void MyFrame::CentreStrings(wxDC
& dc
)
142 GetClientSize(&cw
, &ch
);
144 wxNode
*node
= m_strings
.First();
147 char *s
= (char *)node
->Data();
149 dc
.GetTextExtent(s
, &w
, &h
);
151 int x
= wxMax(0, (cw
- w
)/2);
152 dc
.DrawText(s
, x
, y
);
160 // This implements a tiny doodling program. Drag the mouse using
162 void MyFrame::OnMouseEvent(wxMouseEvent
& event
)
165 event
.Position(&x
, &y
);
168 if (m_xpos
> -1 && m_ypos
> -1 && event
.Dragging() && event
.LeftIsDown())
170 dc
.SetPen(wxBLACK_PEN
);
171 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
172 dc
.DrawLine(m_xpos
, m_ypos
, x
, y
);
178 void MyFrame::OnHello(wxCommandEvent
& event
)
180 wxMessageBox("Hello!");