Back to index

lightning-sunbird  0.9+nobinonly
nsWidgetSupport.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 #include "widgetCore.h"
00040 #include "nsWidgetSupport.h"
00041 #include "nsRect.h"
00042 #include "nsIAppShell.h"
00043 #include "nsIButton.h"
00044 #include "nsIEventListener.h"
00045 #include "nsILabel.h"
00046 #include "nsILookAndFeel.h"
00047 #include "nsIMouseListener.h"
00048 #include "nsIToolkit.h"
00049 #include "nsIWidget.h"
00050 #include "nsICheckButton.h"
00051 #include "nsITextWidget.h"
00052 
00053 
00054 static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
00055 
00056 
00057 NS_WIDGET nsresult 
00058 NS_CreateButton(nsISupports* aParent, 
00059                                                         nsIButton* aButton, 
00060                                                         const nsRect& aRect, 
00061                                                         EVENT_CALLBACK aHandleEventFunction,
00062                                                         const nsFont* aFont)
00063 {
00064        nsIWidget* parent = nsnull;
00065        if (aParent != nsnull)
00066     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00067 
00068   nsIWidget*  widget;
00069        if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
00070          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00071          widget->Show(PR_TRUE);
00072     if (aFont != nsnull)
00073               widget->SetFont(*aFont);
00074               NS_IF_RELEASE(widget);
00075        }
00076   
00077   if (aParent != nsnull)
00078     NS_IF_RELEASE(parent);
00079   return NS_OK;
00080 }
00081 
00082 NS_WIDGET nsresult 
00083 NS_CreateCheckButton(nsISupports* aParent, 
00084                                                                                nsICheckButton* aCheckButton, 
00085                                                                                const nsRect& aRect, 
00086                                                                                EVENT_CALLBACK aHandleEventFunction,
00087                                                                                const nsFont* aFont)
00088 {
00089        nsIWidget* parent = nsnull;
00090        if (aParent != nsnull)
00091     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00092 
00093        nsIWidget*    widget;
00094        if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
00095          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00096          widget->Show(PR_TRUE);
00097     if (aFont != nsnull)
00098               widget->SetFont(*aFont);
00099               NS_IF_RELEASE(widget);
00100        }
00101   if (aParent != nsnull)
00102     NS_IF_RELEASE(parent);
00103  return NS_OK;
00104 }
00105 
00106 
00107 
00108 
00109 NS_WIDGET nsresult 
00110 NS_CreateLabel( nsISupports* aParent, 
00111                                                                nsILabel* aLabel, 
00112                                                                const nsRect& aRect, 
00113                                                                EVENT_CALLBACK aHandleEventFunction,
00114                                                                const nsFont* aFont)
00115 {
00116        nsIWidget* parent = nsnull;
00117        if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent))
00118        {
00119               nsIWidget*    widget;
00120               if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
00121               widget->Create(parent, aRect, aHandleEventFunction, NULL);
00122               widget->Show(PR_TRUE);
00123       if (aFont != nsnull)
00124                 widget->SetFont(*aFont);
00125                      NS_IF_RELEASE(widget);
00126               }
00127               NS_IF_RELEASE(parent);
00128        }
00129   return NS_OK;
00130 }
00131 
00132 
00133 
00134 NS_WIDGET nsresult 
00135 NS_CreateTextWidget(nsISupports* aParent, 
00136                                                                nsITextWidget* aWidget, 
00137                                                                const nsRect& aRect, 
00138                                                                EVENT_CALLBACK aHandleEventFunction,
00139                                                                const nsFont* aFont)
00140 {
00141        nsIWidget* parent = nsnull;
00142        if (aParent != nsnull)
00143     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00144 
00145   nsIWidget*  widget = nsnull;
00146        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00147          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00148          widget->Show(PR_TRUE);
00149     if (aFont != nsnull)
00150               widget->SetFont(*aFont);
00151     NS_IF_RELEASE(widget);
00152        }
00153   else
00154   {
00155     NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
00156   }
00157 
00158        if (aParent)
00159          NS_IF_RELEASE(parent);
00160 
00161   return NS_OK;
00162 }
00163 
00164 
00165 
00166 extern NS_WIDGET nsresult 
00167 NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
00168 {
00169 
00170   nsIWidget*  widget = nsnull;
00171        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00172          widget->Show(aShow);
00173          NS_IF_RELEASE(widget);
00174        }
00175 
00176   return NS_OK;
00177 }
00178 
00179 extern NS_WIDGET nsresult 
00180 NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY)
00181 {
00182 
00183   nsIWidget*  widget = nsnull;
00184        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00185          widget->Move(aX,aY);
00186          NS_IF_RELEASE(widget);
00187        }
00188   return NS_OK;
00189 }
00190 
00191 extern NS_WIDGET nsresult 
00192 NS_EnableWidget(nsISupports* aWidget, PRBool aEnable)
00193 {
00194        nsIWidget*    widget;
00195        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
00196        {
00197               widget->Enable(aEnable);
00198               NS_RELEASE(widget);
00199        }
00200   return NS_OK;
00201 }
00202 
00203 
00204 extern NS_WIDGET nsresult 
00205 NS_SetFocusToWidget(nsISupports* aWidget)
00206 {
00207 
00208   nsIWidget*  widget = nsnull;
00209        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00210          widget->SetFocus();
00211          NS_IF_RELEASE(widget);
00212        }
00213   return NS_OK;
00214 }
00215 
00216 
00217 extern NS_WIDGET nsresult 
00218 NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData)
00219 {
00220        void*                result = nsnull;
00221        nsIWidget*    widget;
00222        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
00223        {
00224               result = widget->GetNativeData(NS_NATIVE_WIDGET);
00225               NS_RELEASE(widget);
00226        }
00227        *aNativeData = result;
00228   return NS_OK;
00229 
00230 }