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
18 /***********************************************************************
19 * Declaration of the implemetation class for the IFont interface
21 typedef struct OLEFontImpl OLEFontImpl
;
26 * This class supports many interfaces. IUnknown, IFont,
27 * IDispatch and IDispFont. The first two are supported by
28 * the first vtablem the other two are supported by the second
31 ICOM_VTABLE(IFont
)* lpvtbl1
;
32 ICOM_VTABLE(IDispatch
)* lpvtbl2
;
35 * Reference count for that instance of the class.
40 * This structure contains the description of the class.
46 * Here, I define utility macros to help with the casting of the
48 * There is a version to accomodate the first vtable and a version to
49 * accomodate the second one.
51 #define _ICOM_THIS(class,name) class* this = (class*)name;
52 #define _ICOM_THIS_From_IDispatch(class, name) class* this = (class*)(((void*)name)-sizeof(void*));
54 /***********************************************************************
55 * Prototypes for the implementation functions for the IFont
58 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
);
59 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
);
60 static HRESULT WINAPI
OLEFontImpl_QueryInterface(IFont
* iface
, REFIID riid
, VOID
** ppvoid
);
61 static ULONG WINAPI
OLEFontImpl_AddRef(IFont
* iface
);
62 static ULONG WINAPI
OLEFontImpl_Release(IFont
* iface
);
63 static HRESULT WINAPI
OLEFontImpl_get_Name(IFont
* iface
, BSTR
* pname
);
64 static HRESULT WINAPI
OLEFontImpl_put_Name(IFont
* iface
, BSTR name
);
65 static HRESULT WINAPI
OLEFontImpl_get_Size(IFont
* iface
, CY
* psize
);
66 static HRESULT WINAPI
OLEFontImpl_put_Size(IFont
* iface
, CY size
);
67 static HRESULT WINAPI
OLEFontImpl_get_Bold(IFont
* iface
, BOOL
* pbold
);
68 static HRESULT WINAPI
OLEFontImpl_put_Bold(IFont
* iface
, BOOL bold
);
69 static HRESULT WINAPI
OLEFontImpl_get_Italic(IFont
* iface
, BOOL
* pitalic
);
70 static HRESULT WINAPI
OLEFontImpl_put_Italic(IFont
* iface
, BOOL italic
);
71 static HRESULT WINAPI
OLEFontImpl_get_Underline(IFont
* iface
, BOOL
* punderline
);
72 static HRESULT WINAPI
OLEFontImpl_put_Underline(IFont
* iface
, BOOL underline
);
73 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(IFont
* iface
, BOOL
* pstrikethrough
);
74 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(IFont
* iface
, BOOL strikethrough
);
75 static HRESULT WINAPI
OLEFontImpl_get_Weight(IFont
* iface
, short* pweight
);
76 static HRESULT WINAPI
OLEFontImpl_put_Weight(IFont
* iface
, short weight
);
77 static HRESULT WINAPI
OLEFontImpl_get_Charset(IFont
* iface
, short* pcharset
);
78 static HRESULT WINAPI
OLEFontImpl_put_Charset(IFont
* iface
, short charset
);
79 static HRESULT WINAPI
OLEFontImpl_get_hFont(IFont
* iface
, HFONT
* phfont
);
80 static HRESULT WINAPI
OLEFontImpl_put_hFont(IFont
* iface
, HFONT hfont
);
81 static HRESULT WINAPI
OLEFontImpl_Clone(IFont
* iface
, IFont
** ppfont
);
82 static HRESULT WINAPI
OLEFontImpl_IsEqual(IFont
* iface
, IFont
* pFontOther
);
83 static HRESULT WINAPI
OLEFontImpl_SetRatio(IFont
* iface
, long cyLogical
, long cyHimetric
);
84 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(IFont
* iface
, TEXTMETRICOLE
* ptm
);
85 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(IFont
* iface
, HFONT hfont
);
86 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(IFont
* iface
, HFONT hfont
);
87 static HRESULT WINAPI
OLEFontImpl_SetHdc(IFont
* iface
, HDC hdc
);
89 /***********************************************************************
90 * Prototypes for the implementation functions for the IDispatch
93 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(IDispatch
* iface
,
96 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(IDispatch
* iface
);
97 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(IDispatch
* iface
);
98 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(IDispatch
* iface
,
99 unsigned int* pctinfo
);
100 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(IDispatch
* iface
,
103 ITypeInfo
** ppTInfo
);
104 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(IDispatch
* iface
,
110 static HRESULT WINAPI
OLEFontImpl_Invoke(IDispatch
* iface
,
115 DISPPARAMS
* pDispParams
,
117 EXCEPINFO
* pExepInfo
,
121 * Virtual function tables for the OLEFontImpl class.
123 static ICOM_VTABLE(IFont
) OLEFontImpl_VTable
=
125 OLEFontImpl_QueryInterface
,
128 OLEFontImpl_get_Name
,
129 OLEFontImpl_put_Name
,
130 OLEFontImpl_get_Size
,
131 OLEFontImpl_put_Size
,
132 OLEFontImpl_get_Bold
,
133 OLEFontImpl_put_Bold
,
134 OLEFontImpl_get_Italic
,
135 OLEFontImpl_put_Italic
,
136 OLEFontImpl_get_Underline
,
137 OLEFontImpl_put_Underline
,
138 OLEFontImpl_get_Strikethrough
,
139 OLEFontImpl_put_Strikethrough
,
140 OLEFontImpl_get_Weight
,
141 OLEFontImpl_put_Weight
,
142 OLEFontImpl_get_Charset
,
143 OLEFontImpl_put_Charset
,
144 OLEFontImpl_get_hFont
,
145 OLEFontImpl_put_hFont
,
148 OLEFontImpl_SetRatio
,
149 OLEFontImpl_QueryTextMetrics
,
150 OLEFontImpl_AddRefHfont
,
151 OLEFontImpl_ReleaseHfont
,
155 static ICOM_VTABLE(IDispatch
) OLEFontImpl_IDispatch_VTable
=
157 OLEFontImpl_IDispatch_QueryInterface
,
158 OLEFontImpl_IDispatch_AddRef
,
159 OLEFontImpl_IDispatch_Release
,
160 OLEFontImpl_GetTypeInfoCount
,
161 OLEFontImpl_GetTypeInfo
,
162 OLEFontImpl_GetIDsOfNames
,
167 /******************************************************************************
168 * OleCreateFontIndirect [OLEAUT32.420]
170 WINOLECTLAPI
OleCreateFontIndirect(
171 LPFONTDESC lpFontDesc
,
175 OLEFontImpl
* newFont
= 0;
187 * Try to construct a new instance of the class.
189 newFont
= OLEFontImpl_Construct(lpFontDesc
);
192 return E_OUTOFMEMORY
;
195 * Make sure it supports the interface required by the caller.
197 hr
= IFont_QueryInterface((IFont
*)newFont
, riid
, ppvObj
);
200 * Release the reference obtained in the constructor. If
201 * the QueryInterface was unsuccessful, it will free the class.
203 IFont_Release((IFont
*)newFont
);
209 /***********************************************************************
210 * Implementation of the OLEFontImpl class.
213 /************************************************************************
214 * OLEFontImpl_Construct
216 * This method will construct a new instance of the OLEFontImpl
219 * The caller of this method must release the object when it's
222 static OLEFontImpl
* OLEFontImpl_Construct(LPFONTDESC fontDesc
)
224 OLEFontImpl
* newObject
= 0;
227 * Allocate space for the object.
229 newObject
= HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl
));
235 * Initialize the virtual function table.
237 newObject
->lpvtbl1
= &OLEFontImpl_VTable
;
238 newObject
->lpvtbl2
= &OLEFontImpl_IDispatch_VTable
;
241 * Start with one reference count. The caller of this function
242 * must release the interface pointer when it is done.
247 * Copy the description of the font in the object.
249 assert(fontDesc
->cbSizeofstruct
>= sizeof(FONTDESC
));
251 newObject
->description
.cbSizeofstruct
= sizeof(FONTDESC
);
252 newObject
->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
254 (lstrlenW(fontDesc
->lpstrName
)+1) * sizeof(WCHAR
));
255 lstrcpyW(newObject
->description
.lpstrName
, fontDesc
->lpstrName
);
256 newObject
->description
.cySize
= fontDesc
->cySize
;
257 newObject
->description
.sWeight
= fontDesc
->sWeight
;
258 newObject
->description
.sCharset
= fontDesc
->sCharset
;
259 newObject
->description
.fItalic
= fontDesc
->fItalic
;
260 newObject
->description
.fUnderline
= fontDesc
->fUnderline
;
261 newObject
->description
.fStrikeThrough
= fontDesc
->fStrikeThrough
;
266 /************************************************************************
267 * OLEFontImpl_Construct
269 * This method is called by the Release method when the reference
270 * count goes doen to 0. it will free all resources used by
273 static void OLEFontImpl_Destroy(OLEFontImpl
* fontDesc
)
275 if (fontDesc
->description
.lpstrName
!=0)
276 HeapFree(GetProcessHeap(), 0, fontDesc
->description
.lpstrName
);
278 HeapFree(GetProcessHeap(), 0, fontDesc
);
282 /************************************************************************
283 * OLEFontImpl_QueryInterface (IUnknown)
285 * See Windows documentation for more details on IUnknown methods.
287 HRESULT WINAPI
OLEFontImpl_QueryInterface(
292 _ICOM_THIS(OLEFontImpl
, iface
);
295 * Perform a sanity check on the parameters.
297 if ( (this==0) || (ppvObject
==0) )
301 * Initialize the return parameter.
306 * Compare the riid with the interface IDs implemented by this object.
308 if (memcmp(&IID_IUnknown
, riid
, sizeof(IID_IUnknown
)) == 0)
310 *ppvObject
= (IFont
*)this;
312 else if (memcmp(&IID_IFont
, riid
, sizeof(IID_IFont
)) == 0)
314 *ppvObject
= (IFont
*)this;
316 else if (memcmp(&IID_IDispatch
, riid
, sizeof(IID_IDispatch
)) == 0)
318 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
320 else if (memcmp(&IID_IFontDisp
, riid
, sizeof(IID_IFontDisp
)) == 0)
322 *ppvObject
= (IDispatch
*)&(this->lpvtbl2
);
326 * Check that we obtained an interface.
329 return E_NOINTERFACE
;
332 * Query Interface always increases the reference count by one when it is
335 OLEFontImpl_AddRef((IFont
*)this);
340 /************************************************************************
341 * OLEFontImpl_AddRef (IUnknown)
343 * See Windows documentation for more details on IUnknown methods.
345 ULONG WINAPI
OLEFontImpl_AddRef(
348 _ICOM_THIS(OLEFontImpl
, iface
);
355 /************************************************************************
356 * OLEFontImpl_Release (IUnknown)
358 * See Windows documentation for more details on IUnknown methods.
360 ULONG WINAPI
OLEFontImpl_Release(
363 _ICOM_THIS(OLEFontImpl
, iface
);
366 * Decrease the reference count on this object.
371 * If the reference count goes down to 0, perform suicide.
375 OLEFontImpl_Destroy(this);
383 /************************************************************************
384 * OLEFontImpl_get_Name (IFont)
386 * See Windows documentation for more details on IFont methods.
388 static HRESULT WINAPI
OLEFontImpl_get_Name(
392 _ICOM_THIS(OLEFontImpl
, iface
);
400 if (this->description
.lpstrName
!=0)
401 *pname
= SysAllocString(this->description
.lpstrName
);
408 /************************************************************************
409 * OLEFontImpl_put_Name (IFont)
411 * See Windows documentation for more details on IFont methods.
413 static HRESULT WINAPI
OLEFontImpl_put_Name(
417 _ICOM_THIS(OLEFontImpl
, iface
);
419 if (this->description
.lpstrName
==0)
421 this->description
.lpstrName
= HeapAlloc(GetProcessHeap(),
423 (lstrlenW(name
)+1) * sizeof(WCHAR
));
427 this->description
.lpstrName
= HeapReAlloc(GetProcessHeap(),
429 this->description
.lpstrName
,
430 (lstrlenW(name
)+1) * sizeof(WCHAR
));
433 if (this->description
.lpstrName
==0)
434 return E_OUTOFMEMORY
;
436 lstrcpyW(this->description
.lpstrName
, name
);
441 /************************************************************************
442 * OLEFontImpl_get_Size (IFont)
444 * See Windows documentation for more details on IFont methods.
446 static HRESULT WINAPI
OLEFontImpl_get_Size(
450 _ICOM_THIS(OLEFontImpl
, iface
);
458 *psize
= this->description
.cySize
;
463 /************************************************************************
464 * OLEFontImpl_put_Size (IFont)
466 * See Windows documentation for more details on IFont methods.
468 static HRESULT WINAPI
OLEFontImpl_put_Size(
472 _ICOM_THIS(OLEFontImpl
, iface
);
474 this->description
.cySize
= size
;
479 /************************************************************************
480 * OLEFontImpl_get_Bold (IFont)
482 * See Windows documentation for more details on IFont methods.
484 static HRESULT WINAPI
OLEFontImpl_get_Bold(
488 FIXME(ole
,"():Stub\n");
492 /************************************************************************
493 * OLEFontImpl_put_Bold (IFont)
495 * See Windows documentation for more details on IFont methods.
497 static HRESULT WINAPI
OLEFontImpl_put_Bold(
501 FIXME(ole
,"():Stub\n");
505 /************************************************************************
506 * OLEFontImpl_get_Italic (IFont)
508 * See Windows documentation for more details on IFont methods.
510 static HRESULT WINAPI
OLEFontImpl_get_Italic(
514 _ICOM_THIS(OLEFontImpl
, iface
);
522 *pitalic
= this->description
.fItalic
;
527 /************************************************************************
528 * OLEFontImpl_put_Italic (IFont)
530 * See Windows documentation for more details on IFont methods.
532 static HRESULT WINAPI
OLEFontImpl_put_Italic(
536 _ICOM_THIS(OLEFontImpl
, iface
);
538 this->description
.fItalic
= italic
;
543 /************************************************************************
544 * OLEFontImpl_get_Underline (IFont)
546 * See Windows documentation for more details on IFont methods.
548 static HRESULT WINAPI
OLEFontImpl_get_Underline(
552 _ICOM_THIS(OLEFontImpl
, iface
);
560 *punderline
= this->description
.fUnderline
;
565 /************************************************************************
566 * OLEFontImpl_put_Underline (IFont)
568 * See Windows documentation for more details on IFont methods.
570 static HRESULT WINAPI
OLEFontImpl_put_Underline(
574 _ICOM_THIS(OLEFontImpl
, iface
);
576 this->description
.fUnderline
= underline
;
581 /************************************************************************
582 * OLEFontImpl_get_Strikethrough (IFont)
584 * See Windows documentation for more details on IFont methods.
586 static HRESULT WINAPI
OLEFontImpl_get_Strikethrough(
588 BOOL
* pstrikethrough
)
590 _ICOM_THIS(OLEFontImpl
, iface
);
595 if (pstrikethrough
==0)
598 *pstrikethrough
= this->description
.fStrikeThrough
;
603 /************************************************************************
604 * OLEFontImpl_put_Strikethrough (IFont)
606 * See Windows documentation for more details on IFont methods.
608 static HRESULT WINAPI
OLEFontImpl_put_Strikethrough(
612 _ICOM_THIS(OLEFontImpl
, iface
);
614 this->description
.fStrikeThrough
= strikethrough
;
619 /************************************************************************
620 * OLEFontImpl_get_Weight (IFont)
622 * See Windows documentation for more details on IFont methods.
624 static HRESULT WINAPI
OLEFontImpl_get_Weight(
628 _ICOM_THIS(OLEFontImpl
, iface
);
636 *pweight
= this->description
.sWeight
;
641 /************************************************************************
642 * OLEFontImpl_put_Weight (IFont)
644 * See Windows documentation for more details on IFont methods.
646 static HRESULT WINAPI
OLEFontImpl_put_Weight(
650 _ICOM_THIS(OLEFontImpl
, iface
);
652 this->description
.sWeight
= weight
;
657 /************************************************************************
658 * OLEFontImpl_get_Charset (IFont)
660 * See Windows documentation for more details on IFont methods.
662 static HRESULT WINAPI
OLEFontImpl_get_Charset(
666 _ICOM_THIS(OLEFontImpl
, iface
);
674 *pcharset
= this->description
.sCharset
;
679 /************************************************************************
680 * OLEFontImpl_put_Charset (IFont)
682 * See Windows documentation for more details on IFont methods.
684 static HRESULT WINAPI
OLEFontImpl_put_Charset(
688 _ICOM_THIS(OLEFontImpl
, iface
);
690 this->description
.sCharset
= charset
;
695 /************************************************************************
696 * OLEFontImpl_get_hFont (IFont)
698 * See Windows documentation for more details on IFont methods.
700 static HRESULT WINAPI
OLEFontImpl_get_hFont(
704 FIXME(ole
,"():Stub\n");
708 /************************************************************************
709 * OLEFontImpl_put_hFont (IFont)
711 * See Windows documentation for more details on IFont methods.
713 static HRESULT WINAPI
OLEFontImpl_put_hFont(
717 FIXME(ole
,"():Stub\n");
721 /************************************************************************
722 * OLEFontImpl_Clone (IFont)
724 * See Windows documentation for more details on IFont methods.
726 static HRESULT WINAPI
OLEFontImpl_Clone(
730 FIXME(ole
,"():Stub\n");
734 /************************************************************************
735 * OLEFontImpl_IsEqual (IFont)
737 * See Windows documentation for more details on IFont methods.
739 static HRESULT WINAPI
OLEFontImpl_IsEqual(
743 FIXME(ole
,"():Stub\n");
747 /************************************************************************
748 * OLEFontImpl_SetRatio (IFont)
750 * See Windows documentation for more details on IFont methods.
752 static HRESULT WINAPI
OLEFontImpl_SetRatio(
757 FIXME(ole
,"():Stub\n");
761 /************************************************************************
762 * OLEFontImpl_QueryTextMetrics (IFont)
764 * See Windows documentation for more details on IFont methods.
766 static HRESULT WINAPI
OLEFontImpl_QueryTextMetrics(
770 FIXME(ole
,"():Stub\n");
774 /************************************************************************
775 * OLEFontImpl_AddRefHfont (IFont)
777 * See Windows documentation for more details on IFont methods.
779 static HRESULT WINAPI
OLEFontImpl_AddRefHfont(
783 FIXME(ole
,"():Stub\n");
787 /************************************************************************
788 * OLEFontImpl_ReleaseHfont (IFont)
790 * See Windows documentation for more details on IFont methods.
792 static HRESULT WINAPI
OLEFontImpl_ReleaseHfont(
796 FIXME(ole
,"():Stub\n");
800 /************************************************************************
801 * OLEFontImpl_SetHdc (IFont)
803 * See Windows documentation for more details on IFont methods.
805 static HRESULT WINAPI
OLEFontImpl_SetHdc(
809 FIXME(ole
,"():Stub\n");
813 /************************************************************************
814 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
816 * See Windows documentation for more details on IUnknown methods.
818 static HRESULT WINAPI
OLEFontImpl_IDispatch_QueryInterface(
823 _ICOM_THIS_From_IDispatch(IFont
, iface
);
825 return IFont_QueryInterface(this, riid
, ppvoid
);
828 /************************************************************************
829 * OLEFontImpl_IDispatch_Release (IUnknown)
831 * See Windows documentation for more details on IUnknown methods.
833 static ULONG WINAPI
OLEFontImpl_IDispatch_Release(
836 _ICOM_THIS_From_IDispatch(IFont
, iface
);
838 return IFont_Release(this);
841 /************************************************************************
842 * OLEFontImpl_IDispatch_AddRef (IUnknown)
844 * See Windows documentation for more details on IUnknown methods.
846 static ULONG WINAPI
OLEFontImpl_IDispatch_AddRef(
849 _ICOM_THIS_From_IDispatch(IFont
, iface
);
851 return IFont_AddRef(this);
854 /************************************************************************
855 * OLEFontImpl_GetTypeInfoCount (IDispatch)
857 * See Windows documentation for more details on IDispatch methods.
859 static HRESULT WINAPI
OLEFontImpl_GetTypeInfoCount(
861 unsigned int* pctinfo
)
863 FIXME(ole
,"():Stub\n");
868 /************************************************************************
869 * OLEFontImpl_GetTypeInfo (IDispatch)
871 * See Windows documentation for more details on IDispatch methods.
873 static HRESULT WINAPI
OLEFontImpl_GetTypeInfo(
879 FIXME(ole
,"():Stub\n");
884 /************************************************************************
885 * OLEFontImpl_GetIDsOfNames (IDispatch)
887 * See Windows documentation for more details on IDispatch methods.
889 static HRESULT WINAPI
OLEFontImpl_GetIDsOfNames(
897 FIXME(ole
,"():Stub\n");
902 /************************************************************************
903 * OLEFontImpl_Invoke (IDispatch)
905 * See Windows documentation for more details on IDispatch methods.
907 static HRESULT WINAPI
OLEFontImpl_Invoke(
913 DISPPARAMS
* pDispParams
,
915 EXCEPINFO
* pExepInfo
,
918 FIXME(ole
,"():Stub\n");