]> git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/src/npframe.cpp
added demo for bitmaps of different size
[wxWidgets.git] / utils / nplugin / src / npframe.cpp
1 /*
2 * File: NPFrame.cc
3 * Purpose: wxPluginFrame implementation
4 * Author: Julian Smart
5 * Created: 1997
6 * Updated:
7 * Copyright: (c) Julian Smart
8 */
9
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/frame.h"
19 #endif
20
21 #include "wx/dcprint.h"
22
23 #include "NPFrame.h"
24 #include "NPApp.h"
25
26 #include <windows.h>
27
28 extern wxList wxModelessWindows;
29 extern char wxFrameClassName[];
30
31 IMPLEMENT_DYNAMIC_CLASS(wxPluginFrame, wxFrame)
32
33 wxPluginFrame::wxPluginFrame(void)
34 {
35 m_npWindow = NULL;
36 m_npInstance = NULL;
37 m_nAttributes = 0;
38 m_names = NULL;
39 m_values = NULL;
40 }
41
42 bool wxPluginFrame::Create(const wxPluginData& data)
43 {
44 SetName("pluginFrame");
45
46 m_npWindow = NULL;
47 m_npInstance = NULL;
48 m_nAttributes = 0;
49 m_names = NULL;
50 m_values = NULL;
51 m_npWindow = data.m_window;
52 m_npInstance = data.m_instance;
53
54 SetAttributeValues(data.m_argc, data.m_argn, data.m_argv);
55 SetNPWindow(data.m_window);
56
57 wxModelessWindows.Append(this);
58
59 if (wxTheApp->IsKindOf(CLASSINFO(wxPluginApp)))
60 {
61 ((wxPluginApp *)wxTheApp)->AddFrame(this);
62 }
63 return TRUE;
64 }
65
66 wxPluginFrame::~wxPluginFrame(void)
67 {
68 if (wxTheApp->IsKindOf(CLASSINFO(wxPluginApp)))
69 {
70 ((wxPluginApp *)wxTheApp)->RemoveFrame(this);
71 }
72
73 if ( GetHWND() )
74 UnsubclassWin();
75 m_hWnd = 0;
76
77 if ( m_names )
78 delete[] m_names;
79 if ( m_values )
80 delete[] m_values;
81 }
82
83 // Get size *available for subwindows* i.e. excluding menu bar etc.
84 // For XView, this is the same as GetSize
85 void wxPluginFrame::GetClientSize(int *x, int *y) const
86 {
87 if ( !m_hWnd )
88 {
89 *x = 0; *y = 0;
90 return;
91 }
92 wxFrame::GetClientSize(x, y);
93 }
94
95 // Set the client size (i.e. leave the calculation of borders etc.
96 // to wxWindows)
97 void wxPluginFrame::SetClientSize(const int width, const int height)
98 {
99 if ( !m_hWnd )
100 return ;
101
102 wxFrame::SetClientSize(width, height);
103 }
104
105 void wxPluginFrame::GetSize(int *width, int *height) const
106 {
107 if ( !m_hWnd )
108 {
109 *width = 0; *height = 0;
110 return;
111 }
112 wxFrame::GetSize(width, height);
113 }
114
115 void wxPluginFrame::GetPosition(int *x, int *y) const
116 {
117 if ( !m_hWnd )
118 {
119 *x = 0; *y = 0;
120 return;
121 }
122 wxFrame::GetPosition(x, y);
123 }
124
125 void wxPluginFrame::SetAttributeValues(const int n, const char *argn[], const char *argv[])
126 {
127 if ( m_names )
128 delete[] m_names;
129 if ( m_values )
130 delete[] m_values;
131
132 m_nAttributes = n;
133
134 m_names = new wxString[n];
135 m_values = new wxString[n];
136 int i;
137 for ( i = 0; i < n ; i ++)
138 {
139 m_names[i] = argn[i];
140 m_values[i] = argv[i];
141 }
142 }
143
144 void wxPluginFrame::SetAttributeValues(const int n, const wxString* argn, const wxString* argv)
145 {
146 if ( m_names )
147 delete[] m_names;
148 if ( m_values )
149 delete[] m_values;
150
151 m_nAttributes = n;
152
153 m_names = new wxString[n];
154 m_values = new wxString[n];
155 int i;
156 for ( i = 0; i < n ; i ++)
157 {
158 m_names[i] = argn[i];
159 m_values[i] = argv[i];
160 }
161 }
162
163 void wxPluginFrame::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags)
164 {
165 // Can't allow app to set the size.
166 return;
167 }
168
169 // Sets and subclasses the platform-specific window handle
170 bool wxPluginFrame::SetNPWindow(NPWindow *window)
171 {
172 if ( !window || !window->window)
173 {
174 if ( m_hWnd )
175 {
176 wxMessageBox("Unsubclassing window prematurely");
177 UnsubclassWin();
178 m_hWnd = 0;
179 }
180 m_npWindow = NULL;
181 }
182 else
183 {
184 if ( m_hWnd )
185 {
186 if ( m_hWnd == (WXHWND) window->window )
187 {
188 // Does this mean a resize?
189 return TRUE;
190 }
191 }
192
193 m_npWindow = window;
194 m_hWnd = (WXHWND) window->window;
195 SubclassWin(m_hWnd);
196 m_windowId = ::GetWindowLong((HWND) m_hWnd, GWL_ID);
197 }
198 return TRUE;
199 }
200
201 NPError wxPluginFrame::OnNPNewStream(NPMIMEType type, NPStream *stream, bool seekable, uint16* stype)
202 {
203 *stype = NP_ASFILE;
204 return NPERR_NO_ERROR;
205 }
206
207 void wxPluginFrame::OnNPNewFile(NPStream *stream, const wxString& fname)
208 {
209 }
210
211 void wxPluginFrame::OnNPPrint(NPPrint* printInfo)
212 {
213 if (printInfo->mode == NP_FULL)
214 {
215 //
216 // *Developers*: If your plugin would like to take over
217 // printing completely when it is in full-screen mode,
218 // set printInfo->pluginPrinted to TRUE and print your
219 // plugin as you see fit. If your plugin wants Netscape
220 // to handle printing in this case, set printInfo->pluginPrinted
221 // to FALSE (the default) and do nothing. If you do want
222 // to handle printing yourself, printOne is true if the
223 // print button (as opposed to the print menu) was clicked.
224 // On the Macintosh, platformPrint is a THPrint; on Windows,
225 // platformPrint is a structure (defined in npapi.h) containing
226 // the printer name, port, etc.
227 //
228 void* platformPrint = printInfo->print.fullPrint.platformPrint;
229 NPBool printOne = printInfo->print.fullPrint.printOne;
230
231 printInfo->print.fullPrint.pluginPrinted = FALSE; // Do the default
232
233 }
234 else // If not fullscreen, we must be embedded
235 {
236 //
237 // *Developers*: If your plugin is embedded, or is full-screen
238 // but you returned false in pluginPrinted above, NPP_Print
239 // will be called with mode == NP_EMBED. The NPWindow
240 // in the printInfo gives the location and dimensions of
241 // the embedded plugin on the printed page. On the Macintosh,
242 // platformPrint is the printer port; on Windows, platformPrint
243 // is the handle to the printing device context.
244 //
245 NPWindow* printWindow = &(printInfo->print.embedPrint.window);
246 void* platformPrint = printInfo->print.embedPrint.platformPrint;
247
248 HDC hDC = (HDC) platformPrint;
249 wxRect rect;
250 rect.x = printWindow->x;
251 rect.y = printWindow->y;
252 rect.width = printWindow->width;
253 rect.height = printWindow->height;
254
255 int saveIt = ::SaveDC(hDC);
256
257 wxPrinterDC *printerDC = new wxPrinterDC((WXHDC) hDC);
258
259 OnPrint(*printerDC, rect);
260
261 printerDC->SetHDC(0);
262 delete printerDC;
263
264 ::RestoreDC(hDC, saveIt);
265 }
266 }
267
268 void wxPluginFrame::OnPrint(wxPrinterDC& dc, wxRect& rect)
269 {
270 // We must do some transformations here
271 RECT winRect;
272 /*
273 winRect.left = rect.x;
274 winRect.top = rect.y;
275 winRect.right = rect.x + rect.right;
276 winRect.bottom = rect.y + rect.height;
277 */
278 POINT winPoint[2];
279 winPoint[0].x = rect.x;
280 winPoint[0].y = rect.y;
281 winPoint[1].x = rect.x + rect.width;
282 winPoint[1].y = rect.y + rect.height;
283
284 if (!LPtoDP((HDC) dc.GetHDC(), winPoint, 2))
285 wxMessageBox("LPtoDP failed.");
286
287 OnDraw(dc);
288 }
289
290 void wxPluginFrame::OnDraw(wxDC& dc)
291 {
292 }
293