]>
git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/src/npframe.cpp
3 * Purpose: wxPluginFrame implementation
7 * Copyright: (c) Julian Smart
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/dcprint.h"
28 extern wxList wxModelessWindows
;
29 extern char wxFrameClassName
[];
31 IMPLEMENT_DYNAMIC_CLASS(wxPluginFrame
, wxFrame
)
33 wxPluginFrame::wxPluginFrame(void)
42 bool wxPluginFrame::Create(const wxPluginData
& data
)
44 SetName("pluginFrame");
51 m_npWindow
= data
.m_window
;
52 m_npInstance
= data
.m_instance
;
54 SetAttributeValues(data
.m_argc
, data
.m_argn
, data
.m_argv
);
55 SetNPWindow(data
.m_window
);
57 wxModelessWindows
.Append(this);
59 if (wxTheApp
->IsKindOf(CLASSINFO(wxPluginApp
)))
61 ((wxPluginApp
*)wxTheApp
)->AddFrame(this);
66 wxPluginFrame::~wxPluginFrame(void)
68 if (wxTheApp
->IsKindOf(CLASSINFO(wxPluginApp
)))
70 ((wxPluginApp
*)wxTheApp
)->RemoveFrame(this);
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
92 wxFrame::GetClientSize(x
, y
);
95 // Set the client size (i.e. leave the calculation of borders etc.
97 void wxPluginFrame::SetClientSize(const int width
, const int height
)
102 wxFrame::SetClientSize(width
, height
);
105 void wxPluginFrame::GetSize(int *width
, int *height
) const
109 *width
= 0; *height
= 0;
112 wxFrame::GetSize(width
, height
);
115 void wxPluginFrame::GetPosition(int *x
, int *y
) const
122 wxFrame::GetPosition(x
, y
);
125 void wxPluginFrame::SetAttributeValues(const int n
, const char *argn
[], const char *argv
[])
134 m_names
= new wxString
[n
];
135 m_values
= new wxString
[n
];
137 for ( i
= 0; i
< n
; i
++)
139 m_names
[i
] = argn
[i
];
140 m_values
[i
] = argv
[i
];
144 void wxPluginFrame::SetAttributeValues(const int n
, const wxString
* argn
, const wxString
* argv
)
153 m_names
= new wxString
[n
];
154 m_values
= new wxString
[n
];
156 for ( i
= 0; i
< n
; i
++)
158 m_names
[i
] = argn
[i
];
159 m_values
[i
] = argv
[i
];
163 void wxPluginFrame::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
165 // Can't allow app to set the size.
169 // Sets and subclasses the platform-specific window handle
170 bool wxPluginFrame::SetNPWindow(NPWindow
*window
)
172 if ( !window
|| !window
->window
)
176 wxMessageBox("Unsubclassing window prematurely");
186 if ( m_hWnd
== (WXHWND
) window
->window
)
188 // Does this mean a resize?
194 m_hWnd
= (WXHWND
) window
->window
;
196 m_windowId
= ::GetWindowLong((HWND
) m_hWnd
, GWL_ID
);
201 NPError
wxPluginFrame::OnNPNewStream(NPMIMEType type
, NPStream
*stream
, bool seekable
, uint16
* stype
)
204 return NPERR_NO_ERROR
;
207 void wxPluginFrame::OnNPNewFile(NPStream
*stream
, const wxString
& fname
)
211 void wxPluginFrame::OnNPPrint(NPPrint
* printInfo
)
213 if (printInfo
->mode
== NP_FULL
)
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.
228 void* platformPrint
= printInfo
->print
.fullPrint
.platformPrint
;
229 NPBool printOne
= printInfo
->print
.fullPrint
.printOne
;
231 printInfo
->print
.fullPrint
.pluginPrinted
= FALSE
; // Do the default
234 else // If not fullscreen, we must be embedded
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.
245 NPWindow
* printWindow
= &(printInfo
->print
.embedPrint
.window
);
246 void* platformPrint
= printInfo
->print
.embedPrint
.platformPrint
;
248 HDC hDC
= (HDC
) platformPrint
;
250 rect
.x
= printWindow
->x
;
251 rect
.y
= printWindow
->y
;
252 rect
.width
= printWindow
->width
;
253 rect
.height
= printWindow
->height
;
255 int saveIt
= ::SaveDC(hDC
);
257 wxPrinterDC
*printerDC
= new wxPrinterDC((WXHDC
) hDC
);
259 OnPrint(*printerDC
, rect
);
261 printerDC
->SetHDC(0);
264 ::RestoreDC(hDC
, saveIt
);
268 void wxPluginFrame::OnPrint(wxPrinterDC
& dc
, wxRect
& rect
)
270 // We must do some transformations here
273 winRect.left = rect.x;
274 winRect.top = rect.y;
275 winRect.right = rect.x + rect.right;
276 winRect.bottom = rect.y + rect.height;
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
;
284 if (!LPtoDP((HDC
) dc
.GetHDC(), winPoint
, 2))
285 wxMessageBox("LPtoDP failed.");
290 void wxPluginFrame::OnDraw(wxDC
& dc
)