ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

loadopts.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006 Jacek Caban for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 
00021 #include <stdarg.h>
00022 #include <stdio.h>
00023 
00024 #define COBJMACROS
00025 
00026 #include "windef.h"
00027 #include "winbase.h"
00028 #include "winuser.h"
00029 #include "ole2.h"
00030 #include "optary.h"
00031 
00032 #include "wine/debug.h"
00033 
00034 #include "mshtml_private.h"
00035 
00036 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
00037 
00038 typedef struct load_opt {
00039     DWORD option;
00040     PVOID buffer;
00041     DWORD size;
00042 
00043     struct load_opt *next;
00044 } load_opt;
00045 
00046 typedef struct {
00047     const IHtmlLoadOptionsVtbl *lpHtmlLoadOptionsVtbl;
00048 
00049     LONG ref;
00050 
00051     load_opt *opts;
00052 } HTMLLoadOptions;
00053 
00054 #define LOADOPTS(x)  ((IHtmlLoadOptions*) &(x)->lpHtmlLoadOptionsVtbl)
00055 
00056 #define LOADOPTS_THIS(iface) DEFINE_THIS(HTMLLoadOptions, HtmlLoadOptions, iface)
00057 
00058 static HRESULT WINAPI HtmlLoadOptions_QueryInterface(IHtmlLoadOptions *iface,
00059         REFIID riid, void **ppv)
00060 {
00061     HTMLLoadOptions *This = LOADOPTS_THIS(iface);
00062 
00063     *ppv = NULL;
00064 
00065     if(IsEqualGUID(&IID_IUnknown, riid)) {
00066         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
00067         *ppv = LOADOPTS(This);
00068     }else if(IsEqualGUID(&IID_IOptionArray, riid)) {
00069         TRACE("(%p)->(IID_IOptionArray %p)\n", This, ppv);
00070         *ppv = LOADOPTS(This);
00071     }else if(IsEqualGUID(&IID_IHtmlLoadOptions, riid)) {
00072         TRACE("(%p)->(IID_IHtmlLoadOptions %p)\n", This, ppv);
00073         *ppv = LOADOPTS(This);
00074     }
00075 
00076     if(*ppv) {
00077         IHtmlLoadOptions_AddRef(LOADOPTS(This));
00078         return S_OK;
00079     }
00080 
00081     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
00082     return E_NOINTERFACE;
00083 }
00084 
00085 static ULONG WINAPI HtmlLoadOptions_AddRef(IHtmlLoadOptions *iface)
00086 {
00087     HTMLLoadOptions *This = LOADOPTS_THIS(iface);
00088     LONG ref = InterlockedIncrement(&This->ref);
00089 
00090     TRACE("(%p) ref=%d\n", This, ref);
00091 
00092     return ref;
00093 }
00094 
00095 static ULONG WINAPI HtmlLoadOptions_Release(IHtmlLoadOptions *iface)
00096 {
00097     HTMLLoadOptions *This = LOADOPTS_THIS(iface);
00098     LONG ref = InterlockedDecrement(&This->ref);
00099 
00100     TRACE("(%p) ref=%d\n", This, ref);
00101 
00102     if(!ref) {
00103         load_opt *iter = This->opts, *last;
00104 
00105         while(iter) {
00106             last = iter;
00107             iter = iter->next;
00108 
00109             heap_free(last->buffer);
00110             heap_free(last);
00111         }
00112 
00113         heap_free(This);
00114     }
00115 
00116     return ref;
00117 }
00118 
00119 static HRESULT WINAPI HtmlLoadOptions_QueryOption(IHtmlLoadOptions *iface, DWORD dwOption,
00120         LPVOID pBuffer, ULONG *pcbBuf)
00121 {
00122     HTMLLoadOptions *This = LOADOPTS_THIS(iface);
00123     load_opt *iter;
00124 
00125     TRACE("(%p)->(%d %p %p)\n", This, dwOption, pBuffer, pcbBuf);
00126 
00127     for(iter = This->opts; iter; iter = iter->next) {
00128         if(iter->option == dwOption)
00129             break;
00130     }
00131 
00132     if(!iter) {
00133         *pcbBuf = 0;
00134         return S_OK;
00135     }
00136 
00137     if(*pcbBuf < iter->size) {
00138         *pcbBuf = iter->size;
00139         return E_FAIL;
00140     }
00141 
00142     memcpy(pBuffer, iter->buffer, iter->size);
00143     *pcbBuf = iter->size;
00144 
00145     return S_OK;
00146 }
00147 
00148 static HRESULT WINAPI HtmlLoadOptions_SetOption(IHtmlLoadOptions *iface, DWORD dwOption,
00149         LPVOID pBuffer, ULONG cbBuf)
00150 {
00151     HTMLLoadOptions *This = LOADOPTS_THIS(iface);
00152     load_opt *iter = NULL;
00153 
00154     TRACE("(%p)->(%d %p %d)\n", This, dwOption, pBuffer, cbBuf);
00155 
00156     for(iter = This->opts; iter; iter = iter->next) {
00157         if(iter->option == dwOption)
00158             break;
00159     }
00160 
00161     if(!iter) {
00162         iter = heap_alloc(sizeof(load_opt));
00163         iter->next = This->opts;
00164         This->opts = iter;
00165 
00166         iter->option = dwOption;
00167     }else {
00168         heap_free(iter->buffer);
00169     }
00170 
00171     if(!cbBuf) {
00172         iter->buffer = NULL;
00173         iter->size = 0;
00174 
00175         return S_OK;
00176     }
00177 
00178     iter->size = cbBuf;
00179     iter->buffer = heap_alloc(cbBuf);
00180     memcpy(iter->buffer, pBuffer, iter->size);
00181 
00182     return S_OK;
00183 }
00184 
00185 #undef LOADOPTS_THIS
00186 
00187 static const IHtmlLoadOptionsVtbl HtmlLoadOptionsVtbl = {
00188     HtmlLoadOptions_QueryInterface,
00189     HtmlLoadOptions_AddRef,
00190     HtmlLoadOptions_Release,
00191     HtmlLoadOptions_QueryOption,
00192     HtmlLoadOptions_SetOption
00193 };
00194 
00195 HRESULT HTMLLoadOptions_Create(IUnknown *pUnkOuter, REFIID riid, void** ppv)
00196 {
00197     HTMLLoadOptions *ret;
00198     HRESULT hres;
00199 
00200     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
00201 
00202     ret = heap_alloc(sizeof(HTMLLoadOptions));
00203 
00204     ret->lpHtmlLoadOptionsVtbl = &HtmlLoadOptionsVtbl;
00205     ret->ref = 1;
00206     ret->opts = NULL;
00207 
00208     hres = IHtmlLoadOptions_QueryInterface(LOADOPTS(ret), riid, ppv);
00209     IHtmlLoadOptions_Release(LOADOPTS(ret));
00210 
00211     return hres;
00212 }

Generated on Fri May 25 2012 04:23:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.