Back to index

lightning-sunbird  0.9+nobinonly
IHTMLLocationImpl.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Adam Lock <adamlock@eircom.net>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef IHTMLLOCATIONIMPL_H
00040 #define IHTMLLOCATIONIMPL_H
00041 
00042 #include "nsIDOMLocation.h"
00043 
00044 #define IHTMLLOCATION_GET_IMPL(prop) \
00045     if (!p) return E_INVALIDARG; \
00046     nsCOMPtr<nsIDOMLocation> location; \
00047     if (NS_FAILED(GetDOMLocation(getter_AddRefs(location))) || !location) \
00048         return E_UNEXPECTED; \
00049     nsAutoString value; \
00050     NS_ENSURE_SUCCESS(location->Get ## prop(value), E_UNEXPECTED); \
00051     *p = ::SysAllocString(value.get()); \
00052     return (*p) ? S_OK : E_OUTOFMEMORY;
00053 
00054 #define IHTMLLOCATION_PUT_IMPL(prop) \
00055     return E_NOTIMPL; // For now
00056 
00057 template<class T>
00058 class IHTMLLocationImpl :
00059     public IDispatchImpl<IHTMLLocation, &__uuidof(IHTMLLocation), &LIBID_MSHTML>
00060 {
00061 protected:
00062 // Methods to be implemented by the derived class
00063     virtual nsresult GetDOMLocation(nsIDOMLocation **aLocation) = 0;
00064 public:
00065     
00066 // IHTMLLocation
00067     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_href( 
00068         /* [in] */ BSTR v)
00069     {
00070         IHTMLLOCATION_PUT_IMPL(Href);
00071     }
00072     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_href( 
00073         /* [out][retval] */ BSTR *p)
00074     {
00075         IHTMLLOCATION_GET_IMPL(Href);
00076     }
00077     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_protocol( 
00078         /* [in] */ BSTR v)
00079     {
00080         IHTMLLOCATION_PUT_IMPL(Protocol);
00081     }
00082     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_protocol( 
00083         /* [out][retval] */ BSTR *p)
00084     {
00085         IHTMLLOCATION_GET_IMPL(Protocol);
00086     }
00087     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_host( 
00088         /* [in] */ BSTR v)
00089     {
00090         IHTMLLOCATION_PUT_IMPL(Host);
00091     }
00092     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_host( 
00093         /* [out][retval] */ BSTR *p)
00094     {
00095         IHTMLLOCATION_GET_IMPL(Host);
00096     }
00097     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_hostname( 
00098         /* [in] */ BSTR v)
00099     {
00100         IHTMLLOCATION_PUT_IMPL(Hostname);
00101     }
00102     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_hostname( 
00103         /* [out][retval] */ BSTR *p)
00104     {
00105         IHTMLLOCATION_GET_IMPL(Hostname);
00106     }
00107     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_port( 
00108         /* [in] */ BSTR v)
00109     {
00110         IHTMLLOCATION_PUT_IMPL(Port);
00111     }
00112     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_port( 
00113         /* [out][retval] */ BSTR *p)
00114     {
00115         IHTMLLOCATION_GET_IMPL(Port);
00116     }
00117     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_pathname( 
00118         /* [in] */ BSTR v)
00119     {
00120         IHTMLLOCATION_PUT_IMPL(Pathname);
00121     }
00122     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_pathname( 
00123         /* [out][retval] */ BSTR *p)
00124     {
00125         IHTMLLOCATION_GET_IMPL(Pathname);
00126     }
00127     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_search( 
00128         /* [in] */ BSTR v)
00129     {
00130         IHTMLLOCATION_PUT_IMPL(Search);
00131     }
00132     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_search( 
00133         /* [out][retval] */ BSTR *p)
00134     {
00135         IHTMLLOCATION_GET_IMPL(Search);
00136     }
00137     virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_hash( 
00138         /* [in] */ BSTR v)
00139     {
00140         IHTMLLOCATION_PUT_IMPL(Hash);
00141     }
00142     virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_hash( 
00143         /* [out][retval] */ BSTR *p)
00144     {
00145         IHTMLLOCATION_GET_IMPL(Hash);
00146     }
00147     virtual /* [id] */ HRESULT STDMETHODCALLTYPE reload( 
00148         /* [in][defaultvalue] */ VARIANT_BOOL flag)
00149     {
00150         nsCOMPtr<nsIDOMLocation> location;
00151         if (NS_FAILED(GetDOMLocation(getter_AddRefs(location))) || !location)
00152             return E_UNEXPECTED;
00153         return NS_SUCCEEDED(location->Reload(flag)) ? S_OK : E_FAIL;
00154     }
00155     virtual /* [id] */ HRESULT STDMETHODCALLTYPE replace( 
00156         /* [in] */ BSTR bstr)
00157     {
00158         nsCOMPtr<nsIDOMLocation> location;
00159         if (NS_FAILED(GetDOMLocation(getter_AddRefs(location))) || !location)
00160             return E_UNEXPECTED;
00161         nsAutoString value(bstr);
00162         return NS_SUCCEEDED(location->Replace(value)) ? S_OK : E_FAIL;
00163     }
00164     virtual /* [id] */ HRESULT STDMETHODCALLTYPE assign( 
00165         /* [in] */ BSTR bstr)
00166     {
00167         nsCOMPtr<nsIDOMLocation> location;
00168         if (NS_FAILED(GetDOMLocation(getter_AddRefs(location))) || !location)
00169             return E_UNEXPECTED;
00170         nsAutoString value(bstr);
00171         return NS_SUCCEEDED(location->Assign(value)) ? S_OK : E_FAIL;
00172     }
00173     virtual /* [id] */ HRESULT STDMETHODCALLTYPE toString( 
00174         /* [out][retval] */ BSTR *string)
00175     {
00176         if (!string) return E_INVALIDARG;
00177         nsCOMPtr<nsIDOMLocation> location;
00178         if (NS_FAILED(GetDOMLocation(getter_AddRefs(location))) || !location)
00179             return E_UNEXPECTED;
00180         nsAutoString value;
00181         NS_ENSURE_SUCCESS(location->ToString(value), E_UNEXPECTED);
00182         *string = ::SysAllocString(value.get());
00183         return (*string) ? S_OK : E_OUTOFMEMORY;
00184     }
00185 };
00186 
00187 #endif