1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
#include "nsWidgetSupport.h"
41
#include "nsIAppShell.h"
42
#include "nsIButton.h"
43
#include "nsIEventListener.h"
44
#include "nsITextWidget.h"
46
#include "nsILookAndFeel.h"
47
#include "nsIMouseListener.h"
48
#include "nsIToolkit.h"
49
#include "nsIWidget.h"
50
#include "nsICheckButton.h"
53
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
56
#define WIDGET_SUPPORT_EXPORT(returnType) PR_PUBLIC_API(returnType)
58
#define WIDGET_SUPPORT_EXPORT(returnType) returnType
61
WIDGET_SUPPORT_EXPORT(nsresult)
62
NS_CreateButton(nsISupports* aParent,
65
EVENT_CALLBACK aHandleEventFunction,
68
nsIWidget* parent = nsnull;
69
if (aParent != nsnull)
70
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
73
if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
74
widget->Create(parent, aRect, aHandleEventFunction, NULL);
75
widget->Show(PR_TRUE);
77
widget->SetFont(*aFont);
78
NS_IF_RELEASE(widget);
81
if (aParent != nsnull)
82
NS_IF_RELEASE(parent);
86
WIDGET_SUPPORT_EXPORT(nsresult)
87
NS_CreateCheckButton(nsISupports* aParent,
88
nsICheckButton* aCheckButton,
90
EVENT_CALLBACK aHandleEventFunction,
93
nsIWidget* parent = nsnull;
94
if (aParent != nsnull)
95
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
98
if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
99
widget->Create(parent, aRect, aHandleEventFunction, NULL);
100
widget->Show(PR_TRUE);
102
widget->SetFont(*aFont);
103
NS_IF_RELEASE(widget);
105
if (aParent != nsnull)
106
NS_IF_RELEASE(parent);
113
WIDGET_SUPPORT_EXPORT(nsresult)
114
NS_CreateLabel( nsISupports* aParent,
117
EVENT_CALLBACK aHandleEventFunction,
120
nsIWidget* parent = nsnull;
121
if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent))
124
if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
125
widget->Create(parent, aRect, aHandleEventFunction, NULL);
126
widget->Show(PR_TRUE);
128
widget->SetFont(*aFont);
129
NS_IF_RELEASE(widget);
131
NS_IF_RELEASE(parent);
137
WIDGET_SUPPORT_EXPORT(nsresult)
138
NS_CreateTextWidget(nsISupports* aParent,
139
nsITextWidget* aWidget,
141
EVENT_CALLBACK aHandleEventFunction,
144
nsIWidget* parent = nsnull;
145
if (aParent != nsnull)
146
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
148
nsIWidget* widget = nsnull;
149
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
150
widget->Create(parent, aRect, aHandleEventFunction, NULL);
151
widget->Show(PR_TRUE);
153
widget->SetFont(*aFont);
154
NS_IF_RELEASE(widget);
158
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
162
NS_IF_RELEASE(parent);
169
WIDGET_SUPPORT_EXPORT(nsresult)
170
NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
173
nsIWidget* widget = nsnull;
174
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
176
NS_IF_RELEASE(widget);
182
WIDGET_SUPPORT_EXPORT(nsresult)
183
NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY)
186
nsIWidget* widget = nsnull;
187
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
189
NS_IF_RELEASE(widget);
194
WIDGET_SUPPORT_EXPORT(nsresult)
195
NS_EnableWidget(nsISupports* aWidget, PRBool aEnable)
198
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
200
widget->Enable(aEnable);
207
WIDGET_SUPPORT_EXPORT(nsresult)
208
NS_SetFocusToWidget(nsISupports* aWidget)
211
nsIWidget* widget = nsnull;
212
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
214
NS_IF_RELEASE(widget);
219
WIDGET_SUPPORT_EXPORT(nsresult)
220
NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData)
222
void* result = nsnull;
224
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
226
result = widget->GetNativeData(NS_NATIVE_WIDGET);
229
*aNativeData = result;