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