2 * OLE Font encapsulation implementation
4 * This file contains an implementation of the IFont
5 * interface and the OleCreateFontIndirect API call.
7 * Copyright 1999 Francis Beaudet
17 /***********************************************************************
18 * Declaration of the implemetation class for the IFont interface
20 typedef struct OLEFontImpl OLEFontImpl;
25 * This class supports many interfaces. IUnknown, IFont,
26 * IDispatch and IDispFont. The first two are supported by
27 * the first vtablem the other two are supported by the second
30 ICOM_VTABLE(IFont)* lpvtbl1;
31 ICOM_VTABLE(IDispatch)* lpvtbl2;
34 * Reference count for that instance of the class.
39 * This structure contains the description of the class.
45 * Here, I define utility macros to help with the casting of the
47 * There is a version to accomodate the first vtable and a version to
48 * accomodate the second one.
50 #define _ICOM_THIS(class,name) class* this = (class*)name;
51 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((void*)name)-sizeof(void*));
53 /***********************************************************************
54 * Prototypes for the implementation functions for the IFont
57 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc);
58 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
59 static HRESULT WINAPI OLEFontImpl_QueryInterface(IFont* iface, REFIID riid, VOID** ppvoid);
60 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
61 static ULONG WINAPI OLEFontImpl_Release(IFont* iface);
62 static HRESULT WINAPI OLEFontImpl_get_Name(IFont* iface, BSTR* pname);
63 static HRESULT WINAPI OLEFontImpl_put_Name(IFont* iface, BSTR name);
64 static HRESULT WINAPI OLEFontImpl_get_Size(IFont* iface, CY* psize);
65 static HRESULT WINAPI OLEFontImpl_put_Size(IFont* iface, CY size);
66 static HRESULT WINAPI OLEFontImpl_get_Bold(IFont* iface, BOOL* pbold);
67 static HRESULT WINAPI OLEFontImpl_put_Bold(IFont* iface, BOOL bold);
68 static HRESULT WINAPI OLEFontImpl_get_Italic(IFont* iface, BOOL* pitalic);
69 static HRESULT WINAPI OLEFontImpl_put_Italic(IFont* iface, BOOL italic);
70 static HRESULT WINAPI OLEFontImpl_get_Underline(IFont* iface, BOOL* punderline);
71 static HRESULT WINAPI OLEFontImpl_put_Underline(IFont* iface, BOOL underline);
72 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(IFont* iface, BOOL* pstrikethrough);
73 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(IFont* iface, BOOL strikethrough);
74 static HRESULT WINAPI OLEFontImpl_get_Weight(IFont* iface, short* pweight);
75 static HRESULT WINAPI OLEFontImpl_put_Weight(IFont* iface, short weight);
76 static HRESULT WINAPI OLEFontImpl_get_Charset(IFont* iface, short* pcharset);
77 static HRESULT WINAPI OLEFontImpl_put_Charset(IFont* iface, short charset);
78 static HRESULT WINAPI OLEFontImpl_get_hFont(IFont* iface, HFONT* phfont);
79 static HRESULT WINAPI OLEFontImpl_put_hFont(IFont* iface, HFONT hfont);
80 static HRESULT WINAPI OLEFontImpl_Clone(IFont* iface, IFont** ppfont);
81 static HRESULT WINAPI OLEFontImpl_IsEqual(IFont* iface, IFont* pFontOther);
82 static HRESULT WINAPI OLEFontImpl_SetRatio(IFont* iface, long cyLogical, long cyHimetric);
83 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(IFont* iface, TEXTMETRICOLE* ptm);
84 static HRESULT WINAPI OLEFontImpl_AddRefHfont(IFont* iface, HFONT hfont);
85 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(IFont* iface, HFONT hfont);
86 static HRESULT WINAPI OLEFontImpl_SetHdc(IFont* iface, HDC hdc);
88 /***********************************************************************
89 * Prototypes for the implementation functions for the IDispatch
92 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(IDispatch* iface,
95 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(IDispatch* iface);
96 static ULONG WINAPI OLEFontImpl_IDispatch_Release(IDispatch* iface);
97 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(IDispatch* iface,
98 unsigned int* pctinfo);
99 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(IDispatch* iface,
102 ITypeInfo** ppTInfo);
103 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(IDispatch* iface,
109 static HRESULT WINAPI OLEFontImpl_Invoke(IDispatch* iface,
114 DISPPARAMS* pDispParams,
116 EXCEPINFO* pExepInfo,
120 * Virtual function tables for the OLEFontImpl class.
122 static ICOM_VTABLE(IFont) OLEFontImpl_VTable =
124 OLEFontImpl_QueryInterface,
127 OLEFontImpl_get_Name,
128 OLEFontImpl_put_Name,
129 OLEFontImpl_get_Size,
130 OLEFontImpl_put_Size,
131 OLEFontImpl_get_Bold,
132 OLEFontImpl_put_Bold,
133 OLEFontImpl_get_Italic,
134 OLEFontImpl_put_Italic,
135 OLEFontImpl_get_Underline,
136 OLEFontImpl_put_Underline,
137 OLEFontImpl_get_Strikethrough,
138 OLEFontImpl_put_Strikethrough,
139 OLEFontImpl_get_Weight,
140 OLEFontImpl_put_Weight,
141 OLEFontImpl_get_Charset,
142 OLEFontImpl_put_Charset,
143 OLEFontImpl_get_hFont,
144 OLEFontImpl_put_hFont,
147 OLEFontImpl_SetRatio,
148 OLEFontImpl_QueryTextMetrics,
149 OLEFontImpl_AddRefHfont,
150 OLEFontImpl_ReleaseHfont,
154 static ICOM_VTABLE(IDispatch) OLEFontImpl_IDispatch_VTable =
156 OLEFontImpl_IDispatch_QueryInterface,
157 OLEFontImpl_IDispatch_AddRef,
158 OLEFontImpl_IDispatch_Release,
159 OLEFontImpl_GetTypeInfoCount,
160 OLEFontImpl_GetTypeInfo,
161 OLEFontImpl_GetIDsOfNames,
166 /******************************************************************************
167 * OleCreateFontIndirect [OLEAUT32.420]
169 WINOLECTLAPI OleCreateFontIndirect(
170 LPFONTDESC lpFontDesc,
174 OLEFontImpl* newFont = 0;
186 * Try to construct a new instance of the class.
188 newFont = OLEFontImpl_Construct(lpFontDesc);
191 return E_OUTOFMEMORY;
194 * Make sure it supports the interface required by the caller.
196 hr = IFont_QueryInterface((IFont*)newFont, riid, ppvObj);
199 * Release the reference obtained in the constructor. If
200 * the QueryInterface was unsuccessful, it will free the class.
202 IFont_Release((IFont*)newFont);
208 /***********************************************************************
209 * Implementation of the OLEFontImpl class.
212 /************************************************************************
213 * OLEFontImpl_Construct
215 * This method will construct a new instance of the OLEFontImpl
218 * The caller of this method must release the object when it's
221 static OLEFontImpl* OLEFontImpl_Construct(LPFONTDESC fontDesc)
223 OLEFontImpl* newObject = 0;
226 * Allocate space for the object.
228 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
234 * Initialize the virtual function table.
236 newObject->lpvtbl1 = &OLEFontImpl_VTable;
237 newObject->lpvtbl2 = &OLEFontImpl_IDispatch_VTable;
240 * Start with one reference count. The caller of this function
241 * must release the interface pointer when it is done.
246 * Copy the description of the font in the object.
248 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
250 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
251 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
253 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
254 lstrcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
255 newObject->description.cySize = fontDesc->cySize;
256 newObject->description.sWeight = fontDesc->sWeight;
257 newObject->description.sCharset = fontDesc->sCharset;
258 newObject->description.fItalic = fontDesc->fItalic;
259 newObject->description.fUnderline = fontDesc->fUnderline;
260 newObject->description.fStrikeThrough = fontDesc->fStrikeThrough;
265 /************************************************************************
266 * OLEFontImpl_Construct
268 * This method is called by the Release method when the reference
269 * count goes doen to 0. it will free all resources used by
272 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
274 if (fontDesc->description.lpstrName!=0)
275 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
277 HeapFree(GetProcessHeap(), 0, fontDesc);
281 /************************************************************************
282 * OLEFontImpl_QueryInterface (IUnknown)
284 * See Windows documentation for more details on IUnknown methods.
286 HRESULT WINAPI OLEFontImpl_QueryInterface(
291 _ICOM_THIS(OLEFontImpl, iface);
294 * Perform a sanity check on the parameters.
296 if ( (this==0) || (ppvObject==0) )
300 * Initialize the return parameter.
305 * Compare the riid with the interface IDs implemented by this object.
307 if (memcmp(&IID_IUnknown, riid, sizeof(IID_IUnknown)) == 0)
309 *ppvObject = (IFont*)this;
311 else if (memcmp(&IID_IFont, riid, sizeof(IID_IFont)) == 0)
313 *ppvObject = (IFont*)this;
315 else if (memcmp(&IID_IDispatch, riid, sizeof(IID_IDispatch)) == 0)
317 *ppvObject = (IDispatch*)&(this->lpvtbl2);
319 else if (memcmp(&IID_IFontDisp, riid, sizeof(IID_IFontDisp)) == 0)
321 *ppvObject = (IDispatch*)&(this->lpvtbl2);
325 * Check that we obtained an interface.
328 return E_NOINTERFACE;
331 * Query Interface always increases the reference count by one when it is
334 OLEFontImpl_AddRef((IFont*)this);
339 /************************************************************************
340 * OLEFontImpl_AddRef (IUnknown)
342 * See Windows documentation for more details on IUnknown methods.
344 ULONG WINAPI OLEFontImpl_AddRef(
347 _ICOM_THIS(OLEFontImpl, iface);
354 /************************************************************************
355 * OLEFontImpl_Release (IUnknown)
357 * See Windows documentation for more details on IUnknown methods.
359 ULONG WINAPI OLEFontImpl_Release(
362 _ICOM_THIS(OLEFontImpl, iface);
365 * Decrease the reference count on this object.
370 * If the reference count goes down to 0, perform suicide.
374 OLEFontImpl_Destroy(this);
382 /************************************************************************
383 * OLEFontImpl_get_Name (IFont)
385 * See Windows documentation for more details on IFont methods.
387 static HRESULT WINAPI OLEFontImpl_get_Name(
391 _ICOM_THIS(OLEFontImpl, iface);
399 if (this->description.lpstrName!=0)
400 *pname = SysAllocString(this->description.lpstrName);
407 /************************************************************************
408 * OLEFontImpl_put_Name (IFont)
410 * See Windows documentation for more details on IFont methods.
412 static HRESULT WINAPI OLEFontImpl_put_Name(
416 _ICOM_THIS(OLEFontImpl, iface);
418 if (this->description.lpstrName==0)
420 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
422 (lstrlenW(name)+1) * sizeof(WCHAR));
426 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
428 this->description.lpstrName,
429 (lstrlenW(name)+1) * sizeof(WCHAR));
432 if (this->description.lpstrName==0)
433 return E_OUTOFMEMORY;
435 lstrcpyW(this->description.lpstrName, name);
440 /************************************************************************
441 * OLEFontImpl_get_Size (IFont)
443 * See Windows documentation for more details on IFont methods.
445 static HRESULT WINAPI OLEFontImpl_get_Size(
449 _ICOM_THIS(OLEFontImpl, iface);
457 *psize = this->description.cySize;
462 /************************************************************************
463 * OLEFontImpl_put_Size (IFont)
465 * See Windows documentation for more details on IFont methods.
467 static HRESULT WINAPI OLEFontImpl_put_Size(
471 _ICOM_THIS(OLEFontImpl, iface);
473 this->description.cySize = size;
478 /************************************************************************
479 * OLEFontImpl_get_Bold (IFont)
481 * See Windows documentation for more details on IFont methods.
483 static HRESULT WINAPI OLEFontImpl_get_Bold(
487 FIXME(ole,"():Stub\n");
491 /************************************************************************
492 * OLEFontImpl_put_Bold (IFont)
494 * See Windows documentation for more details on IFont methods.
496 static HRESULT WINAPI OLEFontImpl_put_Bold(
500 FIXME(ole,"():Stub\n");
504 /************************************************************************
505 * OLEFontImpl_get_Italic (IFont)
507 * See Windows documentation for more details on IFont methods.
509 static HRESULT WINAPI OLEFontImpl_get_Italic(
513 _ICOM_THIS(OLEFontImpl, iface);
521 *pitalic = this->description.fItalic;
526 /************************************************************************
527 * OLEFontImpl_put_Italic (IFont)
529 * See Windows documentation for more details on IFont methods.
531 static HRESULT WINAPI OLEFontImpl_put_Italic(
535 _ICOM_THIS(OLEFontImpl, iface);
537 this->description.fItalic = italic;
542 /************************************************************************
543 * OLEFontImpl_get_Underline (IFont)
545 * See Windows documentation for more details on IFont methods.
547 static HRESULT WINAPI OLEFontImpl_get_Underline(
551 _ICOM_THIS(OLEFontImpl, iface);
559 *punderline = this->description.fUnderline;
564 /************************************************************************
565 * OLEFontImpl_put_Underline (IFont)
567 * See Windows documentation for more details on IFont methods.
569 static HRESULT WINAPI OLEFontImpl_put_Underline(
573 _ICOM_THIS(OLEFontImpl, iface);
575 this->description.fUnderline = underline;
580 /************************************************************************
581 * OLEFontImpl_get_Strikethrough (IFont)
583 * See Windows documentation for more details on IFont methods.
585 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
587 BOOL* pstrikethrough)
589 _ICOM_THIS(OLEFontImpl, iface);
594 if (pstrikethrough==0)
597 *pstrikethrough = this->description.fStrikeThrough;
602 /************************************************************************
603 * OLEFontImpl_put_Strikethrough (IFont)
605 * See Windows documentation for more details on IFont methods.
607 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
611 _ICOM_THIS(OLEFontImpl, iface);
613 this->description.fStrikeThrough = strikethrough;
618 /************************************************************************
619 * OLEFontImpl_get_Weight (IFont)
621 * See Windows documentation for more details on IFont methods.
623 static HRESULT WINAPI OLEFontImpl_get_Weight(
627 _ICOM_THIS(OLEFontImpl, iface);
635 *pweight = this->description.sWeight;
640 /************************************************************************
641 * OLEFontImpl_put_Weight (IFont)
643 * See Windows documentation for more details on IFont methods.
645 static HRESULT WINAPI OLEFontImpl_put_Weight(
649 _ICOM_THIS(OLEFontImpl, iface);
651 this->description.sWeight = weight;
656 /************************************************************************
657 * OLEFontImpl_get_Charset (IFont)
659 * See Windows documentation for more details on IFont methods.
661 static HRESULT WINAPI OLEFontImpl_get_Charset(
665 _ICOM_THIS(OLEFontImpl, iface);
673 *pcharset = this->description.sCharset;
678 /************************************************************************
679 * OLEFontImpl_put_Charset (IFont)
681 * See Windows documentation for more details on IFont methods.
683 static HRESULT WINAPI OLEFontImpl_put_Charset(
687 _ICOM_THIS(OLEFontImpl, iface);
689 this->description.sCharset = charset;
694 /************************************************************************
695 * OLEFontImpl_get_hFont (IFont)
697 * See Windows documentation for more details on IFont methods.
699 static HRESULT WINAPI OLEFontImpl_get_hFont(
703 FIXME(ole,"():Stub\n");
707 /************************************************************************
708 * OLEFontImpl_put_hFont (IFont)
710 * See Windows documentation for more details on IFont methods.
712 static HRESULT WINAPI OLEFontImpl_put_hFont(
716 FIXME(ole,"():Stub\n");
720 /************************************************************************
721 * OLEFontImpl_Clone (IFont)
723 * See Windows documentation for more details on IFont methods.
725 static HRESULT WINAPI OLEFontImpl_Clone(
729 FIXME(ole,"():Stub\n");
733 /************************************************************************
734 * OLEFontImpl_IsEqual (IFont)
736 * See Windows documentation for more details on IFont methods.
738 static HRESULT WINAPI OLEFontImpl_IsEqual(
742 FIXME(ole,"():Stub\n");
746 /************************************************************************
747 * OLEFontImpl_SetRatio (IFont)
749 * See Windows documentation for more details on IFont methods.
751 static HRESULT WINAPI OLEFontImpl_SetRatio(
756 FIXME(ole,"():Stub\n");
760 /************************************************************************
761 * OLEFontImpl_QueryTextMetrics (IFont)
763 * See Windows documentation for more details on IFont methods.
765 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
769 FIXME(ole,"():Stub\n");
773 /************************************************************************
774 * OLEFontImpl_AddRefHfont (IFont)
776 * See Windows documentation for more details on IFont methods.
778 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
782 FIXME(ole,"():Stub\n");
786 /************************************************************************
787 * OLEFontImpl_ReleaseHfont (IFont)
789 * See Windows documentation for more details on IFont methods.
791 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
795 FIXME(ole,"():Stub\n");
799 /************************************************************************
800 * OLEFontImpl_SetHdc (IFont)
802 * See Windows documentation for more details on IFont methods.
804 static HRESULT WINAPI OLEFontImpl_SetHdc(
808 FIXME(ole,"():Stub\n");
812 /************************************************************************
813 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
815 * See Windows documentation for more details on IUnknown methods.
817 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
822 _ICOM_THIS_From_IDispatch(IFont, iface);
824 return IFont_QueryInterface(this, riid, ppvoid);
827 /************************************************************************
828 * OLEFontImpl_IDispatch_Release (IUnknown)
830 * See Windows documentation for more details on IUnknown methods.
832 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
835 _ICOM_THIS_From_IDispatch(IFont, iface);
837 return IFont_Release(this);
840 /************************************************************************
841 * OLEFontImpl_IDispatch_AddRef (IUnknown)
843 * See Windows documentation for more details on IUnknown methods.
845 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
848 _ICOM_THIS_From_IDispatch(IFont, iface);
850 return IFont_AddRef(this);
853 /************************************************************************
854 * OLEFontImpl_GetTypeInfoCount (IDispatch)
856 * See Windows documentation for more details on IDispatch methods.
858 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
860 unsigned int* pctinfo)
862 FIXME(ole,"():Stub\n");
867 /************************************************************************
868 * OLEFontImpl_GetTypeInfo (IDispatch)
870 * See Windows documentation for more details on IDispatch methods.
872 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
878 FIXME(ole,"():Stub\n");
883 /************************************************************************
884 * OLEFontImpl_GetIDsOfNames (IDispatch)
886 * See Windows documentation for more details on IDispatch methods.
888 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
896 FIXME(ole,"():Stub\n");
901 /************************************************************************
902 * OLEFontImpl_Invoke (IDispatch)
904 * See Windows documentation for more details on IDispatch methods.
906 static HRESULT WINAPI OLEFontImpl_Invoke(
912 DISPPARAMS* pDispParams,
914 EXCEPINFO* pExepInfo,
917 FIXME(ole,"():Stub\n");