]>
git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/samples/simple/simple.cpp
3 * Purpose: Minimal wxWidgets plugin
7 * Copyright: (c) Julian Smart
10 /* static const char sccsid[] = "%W% %G%"; */
12 #include "wx/wxprec.h"
27 // Define a new application type
28 class MyApp
: public wxPluginApp
30 virtual bool OnInit(void);
31 virtual wxPluginFrame
* OnNewInstance(const wxPluginData
& data
);
34 // Define a new frame type
35 class MyFrame
: public wxPluginFrame
37 MyFrame(const wxPluginData
& data
);
40 // Let's paint directly onto the 'frame'; we don't need a subwindow
41 void OnPaint(wxPaintEvent
& event
);
42 void OnDraw(wxDC
& dc
);
43 void OnMouseEvent(wxMouseEvent
& event
);
45 // Called when the file has been downloaded
46 virtual void OnNPNewFile(NPStream
*stream
, const wxString
& fname
);
48 void CentreStrings(wxDC
& dc
);
53 wxStringList m_strings
;
58 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
59 EVT_SIZE(MyFrame::OnSize
)
60 EVT_PAINT(MyFrame::OnPaint
)
61 EVT_MOUSE_EVENTS(MyFrame::OnMouseEvent
)
66 // No app initialisation necessary, and for a plugin there is no
68 bool MyApp::OnInit(void)
73 // Called whenever a new plugin instance is called. We could check
74 // various things here in 'data' but we won't bother.
75 wxPluginFrame
* MyApp::OnNewInstance(const wxPluginData
& data
)
77 // Implicitly added to list of plugin frames
78 return new MyFrame(data
);
81 // My frame constructor
82 MyFrame::MyFrame(const wxPluginData
& data
):
89 void MyFrame::OnPaint(wxPaintEvent
& event
)
96 void MyFrame::OnDraw(wxDC
& dc
)
98 dc
.SetBrush(*wxCYAN_BRUSH
);
99 dc
.SetPen(*wxRED_PEN
);
102 GetClientSize(&w
, &h
);
104 dc
.DrawRectangle(0, 0, w
, h
);
106 wxFont
swissFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
107 dc
.SetFont(swissFont
);
108 dc
.SetBackgroundMode(wxTRANSPARENT
);
113 // Called when the file has been downloaded
114 void MyFrame::OnNPNewFile(NPStream
*stream
, const wxString
& fname
)
122 str
.getline(buf
, 200);
130 void MyFrame::CentreStrings(wxDC
& dc
)
134 GetClientSize(&cw
, &ch
);
136 wxNode
*node
= m_strings
.First();
139 char *s
= (char *)node
->Data();
141 dc
.GetTextExtent(s
, &w
, &h
);
143 int x
= wxMax(0, (cw
- w
)/2);
144 dc
.DrawText(s
, x
, y
);
152 // This implements a tiny doodling program. Drag the mouse using
154 void MyFrame::OnMouseEvent(wxMouseEvent
& event
)
157 event
.Position(&x
, &y
);
160 if (m_xpos
> -1 && m_ypos
> -1 && event
.Dragging() && event
.LeftIsDown())
162 dc
.SetPen(wxBLACK_PEN
);
163 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
164 dc
.DrawLine(m_xpos
, m_ypos
, x
, y
);