]>
git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/samples/gui/gui.cpp
3 * Purpose: Minimal wxWindows plugin
7 * Copyright: (c) Julian Smart
10 /* static const char sccsid[] = "%W% %G%"; */
13 #pragma implementation
17 #include "wx/wxprec.h"
34 // Define a new application type
35 class MyApp
: public wxPluginApp
37 virtual wxFrame
*OnInit(void);
38 virtual wxPluginFrame
* OnNewInstance(const wxPluginData
& data
);
41 // Define a new frame type
42 class MyFrame
: public wxPluginFrame
44 MyFrame(const wxPluginData
& data
);
47 // Let's paint directly onto the 'frame'; we don't need a subwindow
48 void OnPaint(wxPaintEvent
& event
);
49 void OnMouseEvent(wxMouseEvent
& event
);
50 void OnHello(wxCommandEvent
& event
);
52 // Called when the file has been downloaded
53 virtual void OnNPNewFile(NPStream
*stream
, const wxString
& fname
);
55 void CentreStrings(wxDC
& dc
);
60 wxStringList m_strings
;
65 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
66 EVT_SIZE(MyFrame::OnSize
)
67 EVT_PAINT(MyFrame::OnPaint
)
68 EVT_MOUSE_EVENTS(MyFrame::OnMouseEvent
)
69 EVT_BUTTON(ID_HELLO
, MyFrame::OnHello
)
74 // No app initialisation necessary, and for a plugin there is no
76 wxFrame
*MyApp::OnInit(void)
81 // Called whenever a new plugin instance is called. We could check
82 // various things here in 'data' but we won't bother.
83 wxPluginFrame
* MyApp::OnNewInstance(const wxPluginData
& data
)
85 // Implicitly added to list of plugin frames
86 return new MyFrame(data
);
89 // My frame constructor
90 MyFrame::MyFrame(const wxPluginData
& data
):
96 wxMenuBar
*menuBar
= new wxMenuBar
;
97 wxMenu
*menu
= new wxMenu
;
98 menu
->Append(1, "E&xit");
99 menuBar
->Append(menu
, "&File");
103 new wxTextCtrl(this, -1, "", wxPoint(10, 30), wxSize(200, 25), wxSUNKEN_BORDER
);
104 new wxButton(this, ID_HELLO
, "Hello", wxPoint(10, 70));
107 void MyFrame::OnPaint(wxPaintEvent
& event
)
111 dc
.SetBrush(*wxCYAN_BRUSH
);
112 dc
.SetPen(*wxRED_PEN
);
115 GetClientSize(&w
, &h
);
117 dc
.DrawRectangle(0, 0, w
, h
);
119 wxFont
swissFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
120 dc
.SetFont(swissFont
);
121 dc
.SetBackgroundMode(wxTRANSPARENT
);
126 // Called when the file has been downloaded
127 void MyFrame::OnNPNewFile(NPStream
*stream
, const wxString
& fname
)
135 str
.getline(buf
, 200);
143 void MyFrame::CentreStrings(wxDC
& dc
)
147 GetClientSize(&cw
, &ch
);
149 wxNode
*node
= m_strings
.First();
152 char *s
= (char *)node
->Data();
154 dc
.GetTextExtent(s
, &w
, &h
);
156 int x
= wxMax(0, (cw
- w
)/2);
157 dc
.DrawText(s
, x
, y
);
165 // This implements a tiny doodling program. Drag the mouse using
167 void MyFrame::OnMouseEvent(wxMouseEvent
& event
)
170 event
.Position(&x
, &y
);
173 if (m_xpos
> -1 && m_ypos
> -1 && event
.Dragging() && event
.LeftIsDown())
175 dc
.SetPen(wxBLACK_PEN
);
176 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
177 dc
.DrawLine(m_xpos
, m_ypos
, x
, y
);
183 void MyFrame::OnHello(wxCommandEvent
& event
)
185 wxMessageBox("Hello!");