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 of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 "nsWidgetSupport.h"
00040 #include "nsRect.h"
00041 #include "nsIButton.h"
00042 #include "nsILabel.h"
00043 #include "nsIWidget.h"
00044 #include "nsICheckButton.h"
00045 #include "nsITextWidget.h"
00046 
00047 
00048 static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
00049 
00050 #ifdef XP_MAC
00051        #define WIDGET_SUPPORT_EXPORT(returnType) PR_PUBLIC_API(returnType)
00052 #else
00053        #define WIDGET_SUPPORT_EXPORT(returnType) returnType
00054 #endif
00055 
00056 WIDGET_SUPPORT_EXPORT(nsresult)
00057 NS_CreateButton(nsISupports* aParent, 
00058                                                         nsIButton* aButton, 
00059                                                         const nsRect& aRect, 
00060                                                         EVENT_CALLBACK aHandleEventFunction,
00061                                                         const nsFont* aFont)
00062 {
00063        nsIWidget* parent = nsnull;
00064        if (aParent != nsnull)
00065     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00066 
00067   nsIWidget*  widget;
00068        if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
00069          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00070          widget->Show(PR_TRUE);
00071     if (aFont != nsnull)
00072               widget->SetFont(*aFont);
00073               NS_IF_RELEASE(widget);
00074        }
00075   
00076   if (aParent != nsnull)
00077     NS_IF_RELEASE(parent);
00078   return NS_OK;
00079 }
00080 
00081 WIDGET_SUPPORT_EXPORT(nsresult)
00082 NS_CreateCheckButton(nsISupports* aParent, 
00083                                                                                nsICheckButton* aCheckButton, 
00084                                                                                const nsRect& aRect, 
00085                                                                                EVENT_CALLBACK aHandleEventFunction,
00086                                                                                const nsFont* aFont)
00087 {
00088        nsIWidget* parent = nsnull;
00089        if (aParent != nsnull)
00090     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00091 
00092        nsIWidget*    widget;
00093        if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
00094          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00095          widget->Show(PR_TRUE);
00096     if (aFont != nsnull)
00097               widget->SetFont(*aFont);
00098               NS_IF_RELEASE(widget);
00099        }
00100   if (aParent != nsnull)
00101     NS_IF_RELEASE(parent);
00102  return NS_OK;
00103 }
00104 
00105 
00106 
00107 
00108 WIDGET_SUPPORT_EXPORT(nsresult)
00109 NS_CreateLabel( nsISupports* aParent, 
00110                                                                nsILabel* aLabel, 
00111                                                                const nsRect& aRect, 
00112                                                                EVENT_CALLBACK aHandleEventFunction,
00113                                                                const nsFont* aFont)
00114 {
00115        nsIWidget* parent = nsnull;
00116        if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent))
00117        {
00118               nsIWidget*    widget;
00119               if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
00120               widget->Create(parent, aRect, aHandleEventFunction, NULL);
00121               widget->Show(PR_TRUE);
00122       if (aFont != nsnull)
00123                 widget->SetFont(*aFont);
00124                      NS_IF_RELEASE(widget);
00125               }
00126               NS_IF_RELEASE(parent);
00127        }
00128   return NS_OK;
00129 }
00130 
00131 
00132 WIDGET_SUPPORT_EXPORT(nsresult)
00133 NS_CreateTextWidget(nsISupports* aParent, 
00134                                                                nsITextWidget* aWidget, 
00135                                                                const nsRect& aRect, 
00136                                                                EVENT_CALLBACK aHandleEventFunction,
00137                                                                const nsFont* aFont)
00138 {
00139        nsIWidget* parent = nsnull;
00140        if (aParent != nsnull)
00141     aParent->QueryInterface(kIWidgetIID,(void**)&parent);
00142 
00143   nsIWidget*  widget = nsnull;
00144        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00145          widget->Create(parent, aRect, aHandleEventFunction, NULL);
00146          widget->Show(PR_TRUE);
00147     if (aFont != nsnull)
00148               widget->SetFont(*aFont);
00149     NS_IF_RELEASE(widget);
00150        }
00151   else
00152   {
00153     NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
00154   }
00155 
00156        if (aParent)
00157          NS_IF_RELEASE(parent);
00158 
00159   return NS_OK;
00160 }
00161 
00162 
00163 
00164 WIDGET_SUPPORT_EXPORT(nsresult)
00165 NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
00166 {
00167 
00168   nsIWidget*  widget = nsnull;
00169        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00170          widget->Show(aShow);
00171          NS_IF_RELEASE(widget);
00172        }
00173 
00174   return NS_OK;
00175 }
00176 
00177 WIDGET_SUPPORT_EXPORT(nsresult)
00178 NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY)
00179 {
00180 
00181   nsIWidget*  widget = nsnull;
00182        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00183          widget->Move(aX,aY);
00184          NS_IF_RELEASE(widget);
00185        }
00186   return NS_OK;
00187 }
00188 
00189 WIDGET_SUPPORT_EXPORT(nsresult)
00190 NS_EnableWidget(nsISupports* aWidget, PRBool aEnable)
00191 {
00192        nsIWidget*    widget;
00193        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
00194        {
00195               widget->Enable(aEnable);
00196               NS_RELEASE(widget);
00197        }
00198   return NS_OK;
00199 }
00200 
00201 
00202 WIDGET_SUPPORT_EXPORT(nsresult)
00203 NS_SetFocusToWidget(nsISupports* aWidget)
00204 {
00205 
00206   nsIWidget*  widget = nsnull;
00207        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
00208          widget->SetFocus();
00209          NS_IF_RELEASE(widget);
00210        }
00211   return NS_OK;
00212 }
00213 
00214 WIDGET_SUPPORT_EXPORT(nsresult)
00215 NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData)
00216 {
00217        void*                result = nsnull;
00218        nsIWidget*    widget;
00219        if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
00220        {
00221               result = widget->GetNativeData(NS_NATIVE_WIDGET);
00222               NS_RELEASE(widget);
00223        }
00224        *aNativeData = result;
00225   return NS_OK;
00226 
00227 }