]>
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%"; */
13 #pragma implementation
17 #include "wx/wxprec.h"
32 // Define a new application type
33 class MyApp
: public wxPluginApp
35 virtual bool OnInit(void);
36 virtual wxPluginFrame
* OnNewInstance(const wxPluginData
& data
);
39 // Define a new frame type
40 class MyFrame
: public wxPluginFrame
42 MyFrame(const wxPluginData
& data
);
45 // Let's paint directly onto the 'frame'; we don't need a subwindow
46 void OnPaint(wxPaintEvent
& event
);
47 void OnDraw(wxDC
& dc
);
48 void OnMouseEvent(wxMouseEvent
& event
);
50 // Called when the file has been downloaded
51 virtual void OnNPNewFile(NPStream
*stream
, const wxString
& fname
);
53 void CentreStrings(wxDC
& dc
);
58 wxStringList m_strings
;
63 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
64 EVT_SIZE(MyFrame::OnSize
)
65 EVT_PAINT(MyFrame::OnPaint
)
66 EVT_MOUSE_EVENTS(MyFrame::OnMouseEvent
)
71 // No app initialisation necessary, and for a plugin there is no
73 bool MyApp::OnInit(void)
78 // Called whenever a new plugin instance is called. We could check
79 // various things here in 'data' but we won't bother.
80 wxPluginFrame
* MyApp::OnNewInstance(const wxPluginData
& data
)
82 // Implicitly added to list of plugin frames
83 return new MyFrame(data
);
86 // My frame constructor
87 MyFrame::MyFrame(const wxPluginData
& data
):
94 void MyFrame::OnPaint(wxPaintEvent
& event
)
101 void MyFrame::OnDraw(wxDC
& dc
)
103 dc
.SetBrush(*wxCYAN_BRUSH
);
104 dc
.SetPen(*wxRED_PEN
);
107 GetClientSize(&w
, &h
);
109 dc
.DrawRectangle(0, 0, w
, h
);
111 wxFont
swissFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
112 dc
.SetFont(swissFont
);
113 dc
.SetBackgroundMode(wxTRANSPARENT
);
118 // Called when the file has been downloaded
119 void MyFrame::OnNPNewFile(NPStream
*stream
, const wxString
& fname
)
127 str
.getline(buf
, 200);
135 void MyFrame::CentreStrings(wxDC
& dc
)
139 GetClientSize(&cw
, &ch
);
141 wxNode
*node
= m_strings
.First();
144 char *s
= (char *)node
->Data();
146 dc
.GetTextExtent(s
, &w
, &h
);
148 int x
= wxMax(0, (cw
- w
)/2);
149 dc
.DrawText(s
, x
, y
);
157 // This implements a tiny doodling program. Drag the mouse using
159 void MyFrame::OnMouseEvent(wxMouseEvent
& event
)
162 event
.Position(&x
, &y
);
165 if (m_xpos
> -1 && m_ypos
> -1 && event
.Dragging() && event
.LeftIsDown())
167 dc
.SetPen(wxBLACK_PEN
);
168 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
169 dc
.DrawLine(m_xpos
, m_ypos
, x
, y
);