~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/widget/src/support/nsWidgetSupport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
 
 
39
#include "nsWidgetSupport.h"
 
40
#include "nsRect.h"
 
41
#include "nsIAppShell.h"
 
42
#include "nsIButton.h"
 
43
#include "nsIEventListener.h"
 
44
#include "nsITextWidget.h"
 
45
#include "nsILabel.h"
 
46
#include "nsILookAndFeel.h"
 
47
#include "nsIMouseListener.h"
 
48
#include "nsIToolkit.h"
 
49
#include "nsIWidget.h"
 
50
#include "nsICheckButton.h"
 
51
 
 
52
 
 
53
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
 
54
 
 
55
#ifdef XP_MAC
 
56
        #define WIDGET_SUPPORT_EXPORT(returnType)       PR_PUBLIC_API(returnType)
 
57
#else
 
58
        #define WIDGET_SUPPORT_EXPORT(returnType)       returnType
 
59
#endif
 
60
 
 
61
WIDGET_SUPPORT_EXPORT(nsresult)
 
62
NS_CreateButton(nsISupports* aParent, 
 
63
                                                                nsIButton* aButton, 
 
64
                                                                const nsRect& aRect, 
 
65
                                                                EVENT_CALLBACK aHandleEventFunction,
 
66
                                                                const nsFont* aFont)
 
67
{
 
68
        nsIWidget* parent = nsnull;
 
69
        if (aParent != nsnull)
 
70
    aParent->QueryInterface(kIWidgetIID,(void**)&parent);
 
71
 
 
72
  nsIWidget*    widget;
 
73
        if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
74
          widget->Create(parent, aRect, aHandleEventFunction, NULL);
 
75
          widget->Show(PR_TRUE);
 
76
    if (aFont != nsnull)
 
77
                widget->SetFont(*aFont);
 
78
                NS_IF_RELEASE(widget);
 
79
        }
 
80
  
 
81
  if (aParent != nsnull)
 
82
    NS_IF_RELEASE(parent);
 
83
  return NS_OK;
 
84
}
 
85
 
 
86
WIDGET_SUPPORT_EXPORT(nsresult)
 
87
NS_CreateCheckButton(nsISupports* aParent, 
 
88
                                                                                          nsICheckButton* aCheckButton, 
 
89
                                                                                          const nsRect& aRect, 
 
90
                                                                                          EVENT_CALLBACK aHandleEventFunction,
 
91
                                                                                          const nsFont* aFont)
 
92
{
 
93
        nsIWidget* parent = nsnull;
 
94
        if (aParent != nsnull)
 
95
    aParent->QueryInterface(kIWidgetIID,(void**)&parent);
 
96
 
 
97
        nsIWidget*      widget;
 
98
        if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
99
          widget->Create(parent, aRect, aHandleEventFunction, NULL);
 
100
          widget->Show(PR_TRUE);
 
101
    if (aFont != nsnull)
 
102
                widget->SetFont(*aFont);
 
103
                NS_IF_RELEASE(widget);
 
104
        }
 
105
  if (aParent != nsnull)
 
106
    NS_IF_RELEASE(parent);
 
107
 return NS_OK;
 
108
}
 
109
 
 
110
 
 
111
 
 
112
 
 
113
WIDGET_SUPPORT_EXPORT(nsresult)
 
114
NS_CreateLabel( nsISupports* aParent, 
 
115
                                                                        nsILabel* aLabel, 
 
116
                                                                        const nsRect& aRect, 
 
117
                                                                        EVENT_CALLBACK aHandleEventFunction,
 
118
                                                                        const nsFont* aFont)
 
119
{
 
120
        nsIWidget* parent = nsnull;
 
121
        if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent))
 
122
        {
 
123
                nsIWidget*      widget;
 
124
                if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
125
                widget->Create(parent, aRect, aHandleEventFunction, NULL);
 
126
                widget->Show(PR_TRUE);
 
127
      if (aFont != nsnull)
 
128
                  widget->SetFont(*aFont);
 
129
                        NS_IF_RELEASE(widget);
 
130
                }
 
131
                NS_IF_RELEASE(parent);
 
132
        }
 
133
  return NS_OK;
 
134
}
 
135
 
 
136
 
 
137
WIDGET_SUPPORT_EXPORT(nsresult)
 
138
NS_CreateTextWidget(nsISupports* aParent, 
 
139
                                                                        nsITextWidget* aWidget, 
 
140
                                                                        const nsRect& aRect, 
 
141
                                                                        EVENT_CALLBACK aHandleEventFunction,
 
142
                                                                        const nsFont* aFont)
 
143
{
 
144
        nsIWidget* parent = nsnull;
 
145
        if (aParent != nsnull)
 
146
    aParent->QueryInterface(kIWidgetIID,(void**)&parent);
 
147
 
 
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);
 
152
    if (aFont != nsnull)
 
153
                widget->SetFont(*aFont);
 
154
    NS_IF_RELEASE(widget);
 
155
        }
 
156
  else
 
157
  {
 
158
    NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
 
159
  }
 
160
 
 
161
        if (aParent)
 
162
          NS_IF_RELEASE(parent);
 
163
 
 
164
  return NS_OK;
 
165
}
 
166
 
 
167
 
 
168
 
 
169
WIDGET_SUPPORT_EXPORT(nsresult)
 
170
NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
 
171
{
 
172
 
 
173
  nsIWidget*    widget = nsnull;
 
174
        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
175
          widget->Show(aShow);
 
176
          NS_IF_RELEASE(widget);
 
177
        }
 
178
 
 
179
  return NS_OK;
 
180
}
 
181
 
 
182
WIDGET_SUPPORT_EXPORT(nsresult)
 
183
NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY)
 
184
{
 
185
 
 
186
  nsIWidget*    widget = nsnull;
 
187
        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
188
          widget->Move(aX,aY);
 
189
          NS_IF_RELEASE(widget);
 
190
        }
 
191
  return NS_OK;
 
192
}
 
193
 
 
194
WIDGET_SUPPORT_EXPORT(nsresult)
 
195
NS_EnableWidget(nsISupports* aWidget, PRBool aEnable)
 
196
{
 
197
        nsIWidget*      widget;
 
198
        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
 
199
        {
 
200
                widget->Enable(aEnable);
 
201
                NS_RELEASE(widget);
 
202
        }
 
203
  return NS_OK;
 
204
}
 
205
 
 
206
 
 
207
WIDGET_SUPPORT_EXPORT(nsresult)
 
208
NS_SetFocusToWidget(nsISupports* aWidget)
 
209
{
 
210
 
 
211
  nsIWidget*    widget = nsnull;
 
212
        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
 
213
          widget->SetFocus();
 
214
          NS_IF_RELEASE(widget);
 
215
        }
 
216
  return NS_OK;
 
217
}
 
218
 
 
219
WIDGET_SUPPORT_EXPORT(nsresult)
 
220
NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData)
 
221
{
 
222
        void*                   result = nsnull;
 
223
        nsIWidget*      widget;
 
224
        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
 
225
        {
 
226
                result = widget->GetNativeData(NS_NATIVE_WIDGET);
 
227
                NS_RELEASE(widget);
 
228
        }
 
229
        *aNativeData = result;
 
230
  return NS_OK;
 
231
 
 
232
}