wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / oleaut32 / olefont.c
blobf86ef20fa82bc5615cdab1a78acd1c340ebf6597
1 /*
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
8 * Copyright 2006 (Google) Benjamin Arai
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #define COBJMACROS
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
32 #include "winerror.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "wine/list.h"
38 #include "wine/unicode.h"
39 #include "objbase.h"
40 #include "oleauto.h" /* for SysAllocString(....) */
41 #include "ole2.h"
42 #include "olectl.h"
43 #include "wine/debug.h"
44 #include "connpt.h" /* for CreateConnectionPoint */
45 #include "oaidl.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 /***********************************************************************
50 * Declaration of constants used when serializing the font object.
52 #define FONTPERSIST_ITALIC 0x02
53 #define FONTPERSIST_UNDERLINE 0x04
54 #define FONTPERSIST_STRIKETHROUGH 0x08
56 static HDC olefont_hdc;
58 /***********************************************************************
59 * List of the HFONTs it has given out, with each one having a separate
60 * ref count.
62 typedef struct _HFONTItem
64 struct list entry;
66 /* Reference count of any IFont objects that own this hfont */
67 LONG int_refs;
69 /* Total reference count of any refs held by the application obtained by AddRefHfont plus any internal refs */
70 LONG total_refs;
72 /* The font associated with this object. */
73 HFONT gdiFont;
75 } HFONTItem, *PHFONTItem;
77 static struct list OLEFontImpl_hFontList = LIST_INIT(OLEFontImpl_hFontList);
79 /* Counts how many fonts contain at least one lock */
80 static LONG ifont_cnt = 0;
82 /***********************************************************************
83 * Critical section for OLEFontImpl_hFontList
85 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST;
86 static CRITICAL_SECTION_DEBUG OLEFontImpl_csHFONTLIST_debug =
88 0, 0, &OLEFontImpl_csHFONTLIST,
89 { &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList,
90 &OLEFontImpl_csHFONTLIST_debug.ProcessLocksList },
91 0, 0, { (DWORD_PTR)(__FILE__ ": OLEFontImpl_csHFONTLIST") }
93 static CRITICAL_SECTION OLEFontImpl_csHFONTLIST = { &OLEFontImpl_csHFONTLIST_debug, -1, 0, 0, 0, 0 };
95 static HDC get_dc(void)
97 HDC hdc;
98 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
99 if(!olefont_hdc)
100 olefont_hdc = CreateCompatibleDC(NULL);
101 hdc = olefont_hdc;
102 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
103 return hdc;
106 static void delete_dc(void)
108 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
109 if(olefont_hdc)
111 DeleteDC(olefont_hdc);
112 olefont_hdc = NULL;
114 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
117 static void HFONTItem_Delete(PHFONTItem item)
119 DeleteObject(item->gdiFont);
120 list_remove(&item->entry);
121 HeapFree(GetProcessHeap(), 0, item);
124 /* Find hfont item entry in the list. Should be called while holding the crit sect */
125 static HFONTItem *find_hfontitem(HFONT hfont)
127 HFONTItem *item;
129 LIST_FOR_EACH_ENTRY(item, &OLEFontImpl_hFontList, HFONTItem, entry)
131 if (item->gdiFont == hfont)
132 return item;
134 return NULL;
137 /* Add an item to the list with one internal reference */
138 static HRESULT add_hfontitem(HFONT hfont)
140 HFONTItem *new_item = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_item));
142 if(!new_item) return E_OUTOFMEMORY;
144 new_item->int_refs = 1;
145 new_item->total_refs = 1;
146 new_item->gdiFont = hfont;
147 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
148 list_add_tail(&OLEFontImpl_hFontList,&new_item->entry);
149 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
150 return S_OK;
153 static HRESULT inc_int_ref(HFONT hfont)
155 HFONTItem *item;
156 HRESULT hr = S_FALSE;
158 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
159 item = find_hfontitem(hfont);
161 if(item)
163 item->int_refs++;
164 item->total_refs++;
165 hr = S_OK;
167 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
169 return hr;
172 /* decrements the internal ref of a hfont item. If both refs are zero it'll
173 remove the item from the list and delete the hfont */
174 static HRESULT dec_int_ref(HFONT hfont)
176 HFONTItem *item;
177 HRESULT hr = S_FALSE;
179 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
180 item = find_hfontitem(hfont);
182 if(item)
184 item->int_refs--;
185 item->total_refs--;
186 if(item->int_refs == 0 && item->total_refs == 0)
187 HFONTItem_Delete(item);
188 hr = S_OK;
190 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
192 return hr;
195 static HRESULT inc_ext_ref(HFONT hfont)
197 HFONTItem *item;
198 HRESULT hr = S_FALSE;
200 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
202 item = find_hfontitem(hfont);
203 if(item)
205 item->total_refs++;
206 hr = S_OK;
208 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
210 return hr;
213 static HRESULT dec_ext_ref(HFONT hfont)
215 HFONTItem *item;
216 HRESULT hr = S_FALSE;
218 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
220 item = find_hfontitem(hfont);
221 if(item)
223 if(--item->total_refs >= 0) hr = S_OK;
225 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
227 return hr;
230 static WCHAR *strdupW(const WCHAR* str)
232 WCHAR *ret;
233 DWORD size = (strlenW(str) + 1) * sizeof(WCHAR);
235 ret = HeapAlloc(GetProcessHeap(), 0, size);
236 if(ret)
237 memcpy(ret, str, size);
238 return ret;
241 /***********************************************************************
242 * Declaration of the implementation class for the IFont interface
244 typedef struct OLEFontImpl OLEFontImpl;
246 struct OLEFontImpl
249 * This class supports many interfaces. IUnknown, IFont,
250 * IDispatch, IDispFont IPersistStream and IConnectionPointContainer.
251 * The first two are supported by the first vtable, the next two are
252 * supported by the second table and the last two have their own.
254 IFont IFont_iface;
255 IDispatch IDispatch_iface;
256 IPersistStream IPersistStream_iface;
257 IConnectionPointContainer IConnectionPointContainer_iface;
258 IPersistPropertyBag IPersistPropertyBag_iface;
259 IPersistStreamInit IPersistStreamInit_iface;
261 * Reference count for that instance of the class.
263 LONG ref;
266 * This structure contains the description of the class.
268 FONTDESC description;
271 * Contain the font associated with this object.
273 HFONT gdiFont;
274 BOOL dirty;
276 * Size ratio
278 LONG cyLogical;
279 LONG cyHimetric;
281 IConnectionPoint *pPropertyNotifyCP;
282 IConnectionPoint *pFontEventsCP;
286 * Here, I define utility macros to help with the casting of the
287 * "this" parameter.
288 * There is a version to accommodate all of the VTables implemented
289 * by this object.
292 static inline OLEFontImpl *impl_from_IFont(IFont *iface)
294 return CONTAINING_RECORD(iface, OLEFontImpl, IFont_iface);
297 static inline OLEFontImpl *impl_from_IDispatch( IDispatch *iface )
299 return CONTAINING_RECORD(iface, OLEFontImpl, IDispatch_iface);
302 static inline OLEFontImpl *impl_from_IPersistStream( IPersistStream *iface )
304 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStream_iface);
307 static inline OLEFontImpl *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
309 return CONTAINING_RECORD(iface, OLEFontImpl, IConnectionPointContainer_iface);
312 static inline OLEFontImpl *impl_from_IPersistPropertyBag( IPersistPropertyBag *iface )
314 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistPropertyBag_iface);
317 static inline OLEFontImpl *impl_from_IPersistStreamInit( IPersistStreamInit *iface )
319 return CONTAINING_RECORD(iface, OLEFontImpl, IPersistStreamInit_iface);
323 /***********************************************************************
324 * Prototypes for the implementation functions for the IFont
325 * interface
327 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc);
328 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc);
329 static ULONG WINAPI OLEFontImpl_AddRef(IFont* iface);
331 /******************************************************************************
332 * OleCreateFontIndirect [OLEAUT32.420]
334 HRESULT WINAPI OleCreateFontIndirect(
335 LPFONTDESC lpFontDesc,
336 REFIID riid,
337 LPVOID* ppvObj)
339 OLEFontImpl* newFont = 0;
340 HRESULT hr = S_OK;
342 TRACE("(%p, %s, %p)\n", lpFontDesc, debugstr_guid(riid), ppvObj);
344 * Sanity check
346 if (ppvObj==0)
347 return E_POINTER;
349 *ppvObj = 0;
351 if (!lpFontDesc) {
352 FONTDESC fd;
354 static WCHAR fname[] = { 'S','y','s','t','e','m',0 };
356 fd.cbSizeofstruct = sizeof(fd);
357 fd.lpstrName = fname;
358 fd.cySize.s.Lo = 80000;
359 fd.cySize.s.Hi = 0;
360 fd.sWeight = 0;
361 fd.sCharset = 0;
362 fd.fItalic = 0;
363 fd.fUnderline = 0;
364 fd.fStrikethrough = 0;
365 lpFontDesc = &fd;
369 * Try to construct a new instance of the class.
371 newFont = OLEFontImpl_Construct(lpFontDesc);
373 if (newFont == 0)
374 return E_OUTOFMEMORY;
377 * Make sure it supports the interface required by the caller.
379 hr = IFont_QueryInterface(&newFont->IFont_iface, riid, ppvObj);
382 * Release the reference obtained in the constructor. If
383 * the QueryInterface was unsuccessful, it will free the class.
385 IFont_Release(&newFont->IFont_iface);
387 return hr;
391 /***********************************************************************
392 * Implementation of the OLEFontImpl class.
395 /***********************************************************************
396 * OLEFont_SendNotify (internal)
398 * Sends notification messages of changed properties to any interested
399 * connections.
401 static void OLEFont_SendNotify(OLEFontImpl* this, DISPID dispID)
403 static const WCHAR wszName[] = {'N','a','m','e',0};
404 static const WCHAR wszSize[] = {'S','i','z','e',0};
405 static const WCHAR wszBold[] = {'B','o','l','d',0};
406 static const WCHAR wszItalic[] = {'I','t','a','l','i','c',0};
407 static const WCHAR wszUnder[] = {'U','n','d','e','r','l','i','n','e',0};
408 static const WCHAR wszStrike[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
409 static const WCHAR wszWeight[] = {'W','e','i','g','h','t',0};
410 static const WCHAR wszCharset[] = {'C','h','a','r','s','s','e','t',0};
411 static const LPCWSTR dispid_mapping[] =
413 wszName,
414 NULL,
415 wszSize,
416 wszBold,
417 wszItalic,
418 wszUnder,
419 wszStrike,
420 wszWeight,
421 wszCharset
424 IEnumConnections *pEnum;
425 CONNECTDATA CD;
426 HRESULT hres;
428 this->dirty = TRUE;
430 hres = IConnectionPoint_EnumConnections(this->pPropertyNotifyCP, &pEnum);
431 if (SUCCEEDED(hres))
433 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
434 IPropertyNotifySink *sink;
436 IUnknown_QueryInterface(CD.pUnk, &IID_IPropertyNotifySink, (LPVOID)&sink);
437 IPropertyNotifySink_OnChanged(sink, dispID);
438 IPropertyNotifySink_Release(sink);
439 IUnknown_Release(CD.pUnk);
441 IEnumConnections_Release(pEnum);
444 hres = IConnectionPoint_EnumConnections(this->pFontEventsCP, &pEnum);
445 if (SUCCEEDED(hres))
447 DISPPARAMS dispparams;
448 VARIANTARG vararg;
450 VariantInit(&vararg);
451 V_VT(&vararg) = VT_BSTR;
452 V_BSTR(&vararg) = SysAllocString(dispid_mapping[dispID]);
454 dispparams.cArgs = 1;
455 dispparams.cNamedArgs = 0;
456 dispparams.rgdispidNamedArgs = NULL;
457 dispparams.rgvarg = &vararg;
459 while(IEnumConnections_Next(pEnum, 1, &CD, NULL) == S_OK) {
460 IFontEventsDisp *disp;
462 IUnknown_QueryInterface(CD.pUnk, &IID_IFontEventsDisp, (LPVOID)&disp);
463 IDispatch_Invoke(disp, DISPID_FONT_CHANGED, &IID_NULL,
464 LOCALE_NEUTRAL, INVOKE_FUNC, &dispparams, NULL,
465 NULL, NULL);
467 IDispatch_Release(disp);
468 IUnknown_Release(CD.pUnk);
470 VariantClear(&vararg);
471 IEnumConnections_Release(pEnum);
475 /************************************************************************
476 * OLEFontImpl_QueryInterface (IUnknown)
478 * See Windows documentation for more details on IUnknown methods.
480 static HRESULT WINAPI OLEFontImpl_QueryInterface(
481 IFont* iface,
482 REFIID riid,
483 void** ppvObject)
485 OLEFontImpl *this = impl_from_IFont(iface);
486 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppvObject);
488 *ppvObject = 0;
491 * Compare the riid with the interface IDs implemented by this object.
493 if (IsEqualGUID(&IID_IUnknown, riid))
494 *ppvObject = this;
495 if (IsEqualGUID(&IID_IFont, riid))
496 *ppvObject = this;
497 if (IsEqualGUID(&IID_IDispatch, riid))
498 *ppvObject = &this->IDispatch_iface;
499 if (IsEqualGUID(&IID_IFontDisp, riid))
500 *ppvObject = &this->IDispatch_iface;
501 if (IsEqualIID(&IID_IPersist, riid) || IsEqualGUID(&IID_IPersistStream, riid))
502 *ppvObject = &this->IPersistStream_iface;
503 if (IsEqualGUID(&IID_IConnectionPointContainer, riid))
504 *ppvObject = &this->IConnectionPointContainer_iface;
505 if (IsEqualGUID(&IID_IPersistPropertyBag, riid))
506 *ppvObject = &this->IPersistPropertyBag_iface;
507 if (IsEqualGUID(&IID_IPersistStreamInit, riid))
508 *ppvObject = &this->IPersistStreamInit_iface;
511 * Check that we obtained an interface.
513 if ((*ppvObject)==0)
515 FIXME("() : asking for unsupported interface %s\n",debugstr_guid(riid));
516 return E_NOINTERFACE;
518 OLEFontImpl_AddRef(&this->IFont_iface);
519 return S_OK;
522 /************************************************************************
523 * OLEFontImpl_AddRef (IUnknown)
525 * See Windows documentation for more details on IUnknown methods.
527 static ULONG WINAPI OLEFontImpl_AddRef(
528 IFont* iface)
530 OLEFontImpl *this = impl_from_IFont(iface);
531 TRACE("(%p)->(ref=%d)\n", this, this->ref);
532 return InterlockedIncrement(&this->ref);
535 /************************************************************************
536 * OLEFontImpl_Release (IUnknown)
538 * See Windows documentation for more details on IUnknown methods.
540 static ULONG WINAPI OLEFontImpl_Release(
541 IFont* iface)
543 OLEFontImpl *this = impl_from_IFont(iface);
544 ULONG ret;
545 TRACE("(%p)->(ref=%d)\n", this, this->ref);
547 /* Decrease the reference count for current interface */
548 ret = InterlockedDecrement(&this->ref);
550 /* If the reference count goes down to 0, destroy. */
551 if (ret == 0)
553 ULONG fontlist_refs = InterlockedDecrement(&ifont_cnt);
555 /* Final IFont object so destroy font cache */
556 if (fontlist_refs == 0)
558 HFONTItem *item, *cursor2;
560 EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
561 LIST_FOR_EACH_ENTRY_SAFE(item, cursor2, &OLEFontImpl_hFontList, HFONTItem, entry)
562 HFONTItem_Delete(item);
563 LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
564 delete_dc();
566 else
568 dec_int_ref(this->gdiFont);
570 OLEFontImpl_Destroy(this);
573 return ret;
576 typedef struct
578 short orig_cs;
579 short avail_cs;
580 } enum_data;
582 static int CALLBACK font_enum_proc(const LOGFONTW *elf, const TEXTMETRICW *ntm, DWORD type, LPARAM lp)
584 enum_data *data = (enum_data*)lp;
586 if(elf->lfCharSet == data->orig_cs)
588 data->avail_cs = data->orig_cs;
589 return 0;
591 if(data->avail_cs == -1) data->avail_cs = elf->lfCharSet;
592 return 1;
595 static void realize_font(OLEFontImpl *This)
597 if (This->dirty)
599 LOGFONTW logFont;
600 INT fontHeight;
601 WCHAR text_face[LF_FACESIZE];
602 HDC hdc = get_dc();
603 HFONT old_font;
604 TEXTMETRICW tm;
606 text_face[0] = 0;
608 if(This->gdiFont)
610 old_font = SelectObject(hdc, This->gdiFont);
611 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
612 SelectObject(hdc, old_font);
613 dec_int_ref(This->gdiFont);
614 This->gdiFont = 0;
617 memset(&logFont, 0, sizeof(LOGFONTW));
619 lstrcpynW(logFont.lfFaceName, This->description.lpstrName, LF_FACESIZE);
620 logFont.lfCharSet = This->description.sCharset;
622 /* If the font name has been changed then enumerate all charsets
623 and pick one that'll result in the font specified being selected */
624 if(text_face[0] && lstrcmpiW(text_face, This->description.lpstrName))
626 enum_data data;
627 data.orig_cs = This->description.sCharset;
628 data.avail_cs = -1;
629 logFont.lfCharSet = DEFAULT_CHARSET;
630 EnumFontFamiliesExW(get_dc(), &logFont, font_enum_proc, (LPARAM)&data, 0);
631 if(data.avail_cs != -1) logFont.lfCharSet = data.avail_cs;
636 * The height of the font returned by the get_Size property is the
637 * height of the font in points multiplied by 10000... Using some
638 * simple conversions and the ratio given by the application, it can
639 * be converted to a height in pixels.
641 * Standard ratio is 72 / 2540, or 18 / 635 in lowest terms.
642 * Ratio is applied here relative to the standard.
645 fontHeight = MulDiv( This->description.cySize.s.Lo, This->cyLogical*635, This->cyHimetric*18 );
648 logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L) - 1 :
649 (-fontHeight/10000L);
650 logFont.lfItalic = This->description.fItalic;
651 logFont.lfUnderline = This->description.fUnderline;
652 logFont.lfStrikeOut = This->description.fStrikethrough;
653 logFont.lfWeight = This->description.sWeight;
654 logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
655 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
656 logFont.lfQuality = DEFAULT_QUALITY;
657 logFont.lfPitchAndFamily = DEFAULT_PITCH;
659 This->gdiFont = CreateFontIndirectW(&logFont);
660 This->dirty = FALSE;
662 add_hfontitem(This->gdiFont);
664 /* Fixup the name and charset properties so that they match the
665 selected font */
666 old_font = SelectObject(get_dc(), This->gdiFont);
667 GetTextFaceW(hdc, sizeof(text_face) / sizeof(text_face[0]), text_face);
668 if(lstrcmpiW(text_face, This->description.lpstrName))
670 HeapFree(GetProcessHeap(), 0, This->description.lpstrName);
671 This->description.lpstrName = strdupW(text_face);
673 GetTextMetricsW(hdc, &tm);
674 This->description.sCharset = tm.tmCharSet;
675 SelectObject(hdc, old_font);
679 /************************************************************************
680 * OLEFontImpl_get_Name (IFont)
682 * See Windows documentation for more details on IFont methods.
684 static HRESULT WINAPI OLEFontImpl_get_Name(
685 IFont* iface,
686 BSTR* pname)
688 OLEFontImpl *this = impl_from_IFont(iface);
689 TRACE("(%p)->(%p)\n", this, pname);
691 * Sanity check.
693 if (pname==0)
694 return E_POINTER;
696 if(this->dirty) realize_font(this);
698 if (this->description.lpstrName!=0)
699 *pname = SysAllocString(this->description.lpstrName);
700 else
701 *pname = 0;
703 return S_OK;
706 /************************************************************************
707 * OLEFontImpl_put_Name (IFont)
709 * See Windows documentation for more details on IFont methods.
711 static HRESULT WINAPI OLEFontImpl_put_Name(
712 IFont* iface,
713 BSTR name)
715 OLEFontImpl *this = impl_from_IFont(iface);
716 TRACE("(%p)->(%p)\n", this, name);
718 if (!name)
719 return CTL_E_INVALIDPROPERTYVALUE;
721 if (this->description.lpstrName==0)
723 this->description.lpstrName = HeapAlloc(GetProcessHeap(),
725 (lstrlenW(name)+1) * sizeof(WCHAR));
727 else
729 this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
731 this->description.lpstrName,
732 (lstrlenW(name)+1) * sizeof(WCHAR));
735 if (this->description.lpstrName==0)
736 return E_OUTOFMEMORY;
738 strcpyW(this->description.lpstrName, name);
739 TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
740 OLEFont_SendNotify(this, DISPID_FONT_NAME);
741 return S_OK;
744 /************************************************************************
745 * OLEFontImpl_get_Size (IFont)
747 * See Windows documentation for more details on IFont methods.
749 static HRESULT WINAPI OLEFontImpl_get_Size(
750 IFont* iface,
751 CY* psize)
753 OLEFontImpl *this = impl_from_IFont(iface);
754 TRACE("(%p)->(%p)\n", this, psize);
757 * Sanity check
759 if (psize==0)
760 return E_POINTER;
762 if(this->dirty) realize_font(this);
764 psize->s.Hi = 0;
765 psize->s.Lo = this->description.cySize.s.Lo;
767 return S_OK;
770 /************************************************************************
771 * OLEFontImpl_put_Size (IFont)
773 * See Windows documentation for more details on IFont methods.
775 static HRESULT WINAPI OLEFontImpl_put_Size(
776 IFont* iface,
777 CY size)
779 OLEFontImpl *this = impl_from_IFont(iface);
780 TRACE("(%p)->(%d)\n", this, size.s.Lo);
781 this->description.cySize.s.Hi = 0;
782 this->description.cySize.s.Lo = size.s.Lo;
783 OLEFont_SendNotify(this, DISPID_FONT_SIZE);
785 return S_OK;
788 /************************************************************************
789 * OLEFontImpl_get_Bold (IFont)
791 * See Windows documentation for more details on IFont methods.
793 static HRESULT WINAPI OLEFontImpl_get_Bold(
794 IFont* iface,
795 BOOL* pbold)
797 OLEFontImpl *this = impl_from_IFont(iface);
798 TRACE("(%p)->(%p)\n", this, pbold);
800 * Sanity check
802 if (pbold==0)
803 return E_POINTER;
805 if(this->dirty) realize_font(this);
807 *pbold = this->description.sWeight > 550;
809 return S_OK;
812 /************************************************************************
813 * OLEFontImpl_put_Bold (IFont)
815 * See Windows documentation for more details on IFont methods.
817 static HRESULT WINAPI OLEFontImpl_put_Bold(
818 IFont* iface,
819 BOOL bold)
821 OLEFontImpl *this = impl_from_IFont(iface);
822 TRACE("(%p)->(%d)\n", this, bold);
823 this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
824 OLEFont_SendNotify(this, DISPID_FONT_BOLD);
826 return S_OK;
829 /************************************************************************
830 * OLEFontImpl_get_Italic (IFont)
832 * See Windows documentation for more details on IFont methods.
834 static HRESULT WINAPI OLEFontImpl_get_Italic(
835 IFont* iface,
836 BOOL* pitalic)
838 OLEFontImpl *this = impl_from_IFont(iface);
839 TRACE("(%p)->(%p)\n", this, pitalic);
841 * Sanity check
843 if (pitalic==0)
844 return E_POINTER;
846 if(this->dirty) realize_font(this);
848 *pitalic = this->description.fItalic;
850 return S_OK;
853 /************************************************************************
854 * OLEFontImpl_put_Italic (IFont)
856 * See Windows documentation for more details on IFont methods.
858 static HRESULT WINAPI OLEFontImpl_put_Italic(
859 IFont* iface,
860 BOOL italic)
862 OLEFontImpl *this = impl_from_IFont(iface);
863 TRACE("(%p)->(%d)\n", this, italic);
865 this->description.fItalic = italic;
867 OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
868 return S_OK;
871 /************************************************************************
872 * OLEFontImpl_get_Underline (IFont)
874 * See Windows documentation for more details on IFont methods.
876 static HRESULT WINAPI OLEFontImpl_get_Underline(
877 IFont* iface,
878 BOOL* punderline)
880 OLEFontImpl *this = impl_from_IFont(iface);
881 TRACE("(%p)->(%p)\n", this, punderline);
884 * Sanity check
886 if (punderline==0)
887 return E_POINTER;
889 if(this->dirty) realize_font(this);
891 *punderline = this->description.fUnderline;
893 return S_OK;
896 /************************************************************************
897 * OLEFontImpl_put_Underline (IFont)
899 * See Windows documentation for more details on IFont methods.
901 static HRESULT WINAPI OLEFontImpl_put_Underline(
902 IFont* iface,
903 BOOL underline)
905 OLEFontImpl *this = impl_from_IFont(iface);
906 TRACE("(%p)->(%d)\n", this, underline);
908 this->description.fUnderline = underline;
910 OLEFont_SendNotify(this, DISPID_FONT_UNDER);
911 return S_OK;
914 /************************************************************************
915 * OLEFontImpl_get_Strikethrough (IFont)
917 * See Windows documentation for more details on IFont methods.
919 static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
920 IFont* iface,
921 BOOL* pstrikethrough)
923 OLEFontImpl *this = impl_from_IFont(iface);
924 TRACE("(%p)->(%p)\n", this, pstrikethrough);
927 * Sanity check
929 if (pstrikethrough==0)
930 return E_POINTER;
932 if(this->dirty) realize_font(this);
934 *pstrikethrough = this->description.fStrikethrough;
936 return S_OK;
939 /************************************************************************
940 * OLEFontImpl_put_Strikethrough (IFont)
942 * See Windows documentation for more details on IFont methods.
944 static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
945 IFont* iface,
946 BOOL strikethrough)
948 OLEFontImpl *this = impl_from_IFont(iface);
949 TRACE("(%p)->(%d)\n", this, strikethrough);
951 this->description.fStrikethrough = strikethrough;
952 OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
954 return S_OK;
957 /************************************************************************
958 * OLEFontImpl_get_Weight (IFont)
960 * See Windows documentation for more details on IFont methods.
962 static HRESULT WINAPI OLEFontImpl_get_Weight(
963 IFont* iface,
964 short* pweight)
966 OLEFontImpl *this = impl_from_IFont(iface);
967 TRACE("(%p)->(%p)\n", this, pweight);
970 * Sanity check
972 if (pweight==0)
973 return E_POINTER;
975 if(this->dirty) realize_font(this);
977 *pweight = this->description.sWeight;
979 return S_OK;
982 /************************************************************************
983 * OLEFontImpl_put_Weight (IFont)
985 * See Windows documentation for more details on IFont methods.
987 static HRESULT WINAPI OLEFontImpl_put_Weight(
988 IFont* iface,
989 short weight)
991 OLEFontImpl *this = impl_from_IFont(iface);
992 TRACE("(%p)->(%d)\n", this, weight);
994 this->description.sWeight = weight;
996 OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
997 return S_OK;
1000 /************************************************************************
1001 * OLEFontImpl_get_Charset (IFont)
1003 * See Windows documentation for more details on IFont methods.
1005 static HRESULT WINAPI OLEFontImpl_get_Charset(
1006 IFont* iface,
1007 short* pcharset)
1009 OLEFontImpl *this = impl_from_IFont(iface);
1010 TRACE("(%p)->(%p)\n", this, pcharset);
1013 * Sanity check
1015 if (pcharset==0)
1016 return E_POINTER;
1018 if(this->dirty) realize_font(this);
1020 *pcharset = this->description.sCharset;
1022 return S_OK;
1025 /************************************************************************
1026 * OLEFontImpl_put_Charset (IFont)
1028 * See Windows documentation for more details on IFont methods.
1030 static HRESULT WINAPI OLEFontImpl_put_Charset(
1031 IFont* iface,
1032 short charset)
1034 OLEFontImpl *this = impl_from_IFont(iface);
1035 TRACE("(%p)->(%d)\n", this, charset);
1037 this->description.sCharset = charset;
1038 OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
1040 return S_OK;
1043 /************************************************************************
1044 * OLEFontImpl_get_hFont (IFont)
1046 * See Windows documentation for more details on IFont methods.
1048 static HRESULT WINAPI OLEFontImpl_get_hFont(
1049 IFont* iface,
1050 HFONT* phfont)
1052 OLEFontImpl *this = impl_from_IFont(iface);
1053 TRACE("(%p)->(%p)\n", this, phfont);
1054 if (phfont==NULL)
1055 return E_POINTER;
1057 if(this->dirty) realize_font(this);
1059 *phfont = this->gdiFont;
1060 TRACE("Returning %p\n", *phfont);
1061 return S_OK;
1064 /************************************************************************
1065 * OLEFontImpl_Clone (IFont)
1067 * See Windows documentation for more details on IFont methods.
1069 static HRESULT WINAPI OLEFontImpl_Clone(
1070 IFont* iface,
1071 IFont** ppfont)
1073 OLEFontImpl* newObject = 0;
1074 OLEFontImpl *this = impl_from_IFont(iface);
1076 TRACE("(%p)->(%p)\n", this, ppfont);
1078 if (ppfont == NULL)
1079 return E_POINTER;
1081 *ppfont = NULL;
1084 * Allocate space for the object.
1086 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
1088 if (newObject==NULL)
1089 return E_OUTOFMEMORY;
1091 *newObject = *this;
1093 /* We need to alloc new memory for the string, otherwise
1094 * we free memory twice.
1096 newObject->description.lpstrName = HeapAlloc(
1097 GetProcessHeap(),0,
1098 (1+strlenW(this->description.lpstrName))*2
1100 strcpyW(newObject->description.lpstrName, this->description.lpstrName);
1103 /* Increment internal ref in hfont item list */
1104 if(newObject->gdiFont) inc_int_ref(newObject->gdiFont);
1106 InterlockedIncrement(&ifont_cnt);
1108 /* create new connection points */
1109 newObject->pPropertyNotifyCP = NULL;
1110 newObject->pFontEventsCP = NULL;
1111 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
1112 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
1114 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
1116 OLEFontImpl_Destroy(newObject);
1117 return E_OUTOFMEMORY;
1120 /* The cloned object starts with a reference count of 1 */
1121 newObject->ref = 1;
1123 *ppfont = &newObject->IFont_iface;
1125 return S_OK;
1128 /************************************************************************
1129 * OLEFontImpl_IsEqual (IFont)
1131 * See Windows documentation for more details on IFont methods.
1133 static HRESULT WINAPI OLEFontImpl_IsEqual(
1134 IFont* iface,
1135 IFont* pFontOther)
1137 OLEFontImpl *left = impl_from_IFont(iface);
1138 OLEFontImpl *right = impl_from_IFont(pFontOther);
1139 INT ret;
1140 INT left_len,right_len;
1142 if(pFontOther == NULL)
1143 return E_POINTER;
1144 else if (left->description.cySize.s.Lo != right->description.cySize.s.Lo)
1145 return S_FALSE;
1146 else if (left->description.cySize.s.Hi != right->description.cySize.s.Hi)
1147 return S_FALSE;
1148 else if (left->description.sWeight != right->description.sWeight)
1149 return S_FALSE;
1150 else if (left->description.sCharset != right->description.sCharset)
1151 return S_FALSE;
1152 else if (left->description.fItalic != right->description.fItalic)
1153 return S_FALSE;
1154 else if (left->description.fUnderline != right->description.fUnderline)
1155 return S_FALSE;
1156 else if (left->description.fStrikethrough != right->description.fStrikethrough)
1157 return S_FALSE;
1159 /* Check from string */
1160 left_len = strlenW(left->description.lpstrName);
1161 right_len = strlenW(right->description.lpstrName);
1162 ret = CompareStringW(0,0,left->description.lpstrName, left_len,
1163 right->description.lpstrName, right_len);
1164 if (ret != CSTR_EQUAL)
1165 return S_FALSE;
1167 return S_OK;
1170 /************************************************************************
1171 * OLEFontImpl_SetRatio (IFont)
1173 * See Windows documentation for more details on IFont methods.
1175 static HRESULT WINAPI OLEFontImpl_SetRatio(
1176 IFont* iface,
1177 LONG cyLogical,
1178 LONG cyHimetric)
1180 OLEFontImpl *this = impl_from_IFont(iface);
1181 TRACE("(%p)->(%d, %d)\n", this, cyLogical, cyHimetric);
1183 this->cyLogical = cyLogical;
1184 this->cyHimetric = cyHimetric;
1186 return S_OK;
1189 /************************************************************************
1190 * OLEFontImpl_QueryTextMetrics (IFont)
1192 * See Windows documentation for more details on IFont methods.
1194 static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
1195 IFont* iface,
1196 TEXTMETRICOLE* ptm)
1198 HDC hdcRef;
1199 HFONT hOldFont, hNewFont;
1201 hdcRef = GetDC(0);
1202 OLEFontImpl_get_hFont(iface, &hNewFont);
1203 hOldFont = SelectObject(hdcRef, hNewFont);
1204 GetTextMetricsW(hdcRef, ptm);
1205 SelectObject(hdcRef, hOldFont);
1206 ReleaseDC(0, hdcRef);
1207 return S_OK;
1210 /************************************************************************
1211 * OLEFontImpl_AddRefHfont (IFont)
1213 * See Windows documentation for more details on IFont methods.
1215 static HRESULT WINAPI OLEFontImpl_AddRefHfont(
1216 IFont* iface,
1217 HFONT hfont)
1219 OLEFontImpl *this = impl_from_IFont(iface);
1221 TRACE("(%p)->(%p)\n", this, hfont);
1223 if (!hfont) return E_INVALIDARG;
1225 return inc_ext_ref(hfont);
1228 /************************************************************************
1229 * OLEFontImpl_ReleaseHfont (IFont)
1231 * See Windows documentation for more details on IFont methods.
1233 static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
1234 IFont* iface,
1235 HFONT hfont)
1237 OLEFontImpl *this = impl_from_IFont(iface);
1239 TRACE("(%p)->(%p)\n", this, hfont);
1241 if (!hfont) return E_INVALIDARG;
1243 return dec_ext_ref(hfont);
1246 /************************************************************************
1247 * OLEFontImpl_SetHdc (IFont)
1249 * See Windows documentation for more details on IFont methods.
1251 static HRESULT WINAPI OLEFontImpl_SetHdc(
1252 IFont* iface,
1253 HDC hdc)
1255 OLEFontImpl *this = impl_from_IFont(iface);
1256 FIXME("(%p)->(%p): Stub\n", this, hdc);
1257 return E_NOTIMPL;
1261 * Virtual function tables for the OLEFontImpl class.
1263 static const IFontVtbl OLEFontImpl_VTable =
1265 OLEFontImpl_QueryInterface,
1266 OLEFontImpl_AddRef,
1267 OLEFontImpl_Release,
1268 OLEFontImpl_get_Name,
1269 OLEFontImpl_put_Name,
1270 OLEFontImpl_get_Size,
1271 OLEFontImpl_put_Size,
1272 OLEFontImpl_get_Bold,
1273 OLEFontImpl_put_Bold,
1274 OLEFontImpl_get_Italic,
1275 OLEFontImpl_put_Italic,
1276 OLEFontImpl_get_Underline,
1277 OLEFontImpl_put_Underline,
1278 OLEFontImpl_get_Strikethrough,
1279 OLEFontImpl_put_Strikethrough,
1280 OLEFontImpl_get_Weight,
1281 OLEFontImpl_put_Weight,
1282 OLEFontImpl_get_Charset,
1283 OLEFontImpl_put_Charset,
1284 OLEFontImpl_get_hFont,
1285 OLEFontImpl_Clone,
1286 OLEFontImpl_IsEqual,
1287 OLEFontImpl_SetRatio,
1288 OLEFontImpl_QueryTextMetrics,
1289 OLEFontImpl_AddRefHfont,
1290 OLEFontImpl_ReleaseHfont,
1291 OLEFontImpl_SetHdc
1294 /************************************************************************
1295 * OLEFontImpl_IDispatch_QueryInterface (IUnknown)
1297 * See Windows documentation for more details on IUnknown methods.
1299 static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
1300 IDispatch* iface,
1301 REFIID riid,
1302 VOID** ppvoid)
1304 OLEFontImpl *this = impl_from_IDispatch(iface);
1306 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1309 /************************************************************************
1310 * OLEFontImpl_IDispatch_Release (IUnknown)
1312 * See Windows documentation for more details on IUnknown methods.
1314 static ULONG WINAPI OLEFontImpl_IDispatch_Release(
1315 IDispatch* iface)
1317 OLEFontImpl *this = impl_from_IDispatch(iface);
1319 return IFont_Release(&this->IFont_iface);
1322 /************************************************************************
1323 * OLEFontImpl_IDispatch_AddRef (IUnknown)
1325 * See Windows documentation for more details on IUnknown methods.
1327 static ULONG WINAPI OLEFontImpl_IDispatch_AddRef(
1328 IDispatch* iface)
1330 OLEFontImpl *this = impl_from_IDispatch(iface);
1332 return IFont_AddRef(&this->IFont_iface);
1335 /************************************************************************
1336 * OLEFontImpl_GetTypeInfoCount (IDispatch)
1338 * See Windows documentation for more details on IDispatch methods.
1340 static HRESULT WINAPI OLEFontImpl_GetTypeInfoCount(
1341 IDispatch* iface,
1342 unsigned int* pctinfo)
1344 OLEFontImpl *this = impl_from_IDispatch(iface);
1345 TRACE("(%p)->(%p)\n", this, pctinfo);
1346 *pctinfo = 1;
1348 return S_OK;
1351 /************************************************************************
1352 * OLEFontImpl_GetTypeInfo (IDispatch)
1354 * See Windows documentation for more details on IDispatch methods.
1356 static HRESULT WINAPI OLEFontImpl_GetTypeInfo(
1357 IDispatch* iface,
1358 UINT iTInfo,
1359 LCID lcid,
1360 ITypeInfo** ppTInfo)
1362 static const WCHAR stdole2tlb[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1363 ITypeLib *tl;
1364 HRESULT hres;
1366 OLEFontImpl *this = impl_from_IDispatch(iface);
1367 TRACE("(%p, iTInfo=%d, lcid=%04x, %p)\n", this, iTInfo, (int)lcid, ppTInfo);
1368 if (iTInfo != 0)
1369 return E_FAIL;
1370 hres = LoadTypeLib(stdole2tlb, &tl);
1371 if (FAILED(hres)) {
1372 ERR("Could not load the stdole2.tlb?\n");
1373 return hres;
1375 hres = ITypeLib_GetTypeInfoOfGuid(tl, &IID_IFontDisp, ppTInfo);
1376 ITypeLib_Release(tl);
1377 if (FAILED(hres)) {
1378 FIXME("Did not IDispatch typeinfo from typelib, hres %x\n",hres);
1380 return hres;
1383 /************************************************************************
1384 * OLEFontImpl_GetIDsOfNames (IDispatch)
1386 * See Windows documentation for more details on IDispatch methods.
1388 static HRESULT WINAPI OLEFontImpl_GetIDsOfNames(
1389 IDispatch* iface,
1390 REFIID riid,
1391 LPOLESTR* rgszNames,
1392 UINT cNames,
1393 LCID lcid,
1394 DISPID* rgDispId)
1396 ITypeInfo * pTInfo;
1397 HRESULT hres;
1399 OLEFontImpl *this = impl_from_IDispatch(iface);
1401 TRACE("(%p,%s,%p,cNames=%d,lcid=%04x,%p)\n", this, debugstr_guid(riid),
1402 rgszNames, cNames, (int)lcid, rgDispId);
1404 if (cNames == 0)
1406 return E_INVALIDARG;
1408 else
1410 /* retrieve type information */
1411 hres = OLEFontImpl_GetTypeInfo(iface, 0, lcid, &pTInfo);
1413 if (FAILED(hres))
1415 ERR("GetTypeInfo failed.\n");
1416 return hres;
1419 /* convert names to DISPIDs */
1420 hres = DispGetIDsOfNames (pTInfo, rgszNames, cNames, rgDispId);
1421 ITypeInfo_Release(pTInfo);
1423 return hres;
1427 /************************************************************************
1428 * OLEFontImpl_Invoke (IDispatch)
1430 * See Windows documentation for more details on IDispatch methods.
1432 * Note: Do not call _put_Xxx methods, since setting things here
1433 * should not call notify functions as I found out debugging the generic
1434 * MS VB5 installer.
1436 static HRESULT WINAPI OLEFontImpl_Invoke(
1437 IDispatch* iface,
1438 DISPID dispIdMember,
1439 REFIID riid,
1440 LCID lcid,
1441 WORD wFlags,
1442 DISPPARAMS* pDispParams,
1443 VARIANT* pVarResult,
1444 EXCEPINFO* pExepInfo,
1445 UINT* puArgErr)
1447 OLEFontImpl *this = impl_from_IDispatch(iface);
1448 HRESULT hr;
1450 TRACE("%p->(%d,%s,0x%x,0x%x,%p,%p,%p,%p)\n", this, dispIdMember,
1451 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExepInfo,
1452 puArgErr);
1454 /* validate parameters */
1456 if (!IsEqualIID(riid, &IID_NULL))
1458 ERR("riid was %s instead of IID_NULL\n", debugstr_guid(riid));
1459 return DISP_E_UNKNOWNINTERFACE;
1462 if (wFlags & DISPATCH_PROPERTYGET)
1464 if (!pVarResult)
1466 ERR("null pVarResult not allowed when DISPATCH_PROPERTYGET specified\n");
1467 return DISP_E_PARAMNOTOPTIONAL;
1470 else if (wFlags & DISPATCH_PROPERTYPUT)
1472 if (!pDispParams)
1474 ERR("null pDispParams not allowed when DISPATCH_PROPERTYPUT specified\n");
1475 return DISP_E_PARAMNOTOPTIONAL;
1477 if (pDispParams->cArgs != 1)
1479 ERR("param count for DISPATCH_PROPERTYPUT was %d instead of 1\n", pDispParams->cArgs);
1480 return DISP_E_BADPARAMCOUNT;
1483 else
1485 ERR("one of DISPATCH_PROPERTYGET or DISPATCH_PROPERTYPUT must be specified\n");
1486 return DISP_E_MEMBERNOTFOUND;
1489 switch (dispIdMember) {
1490 case DISPID_FONT_NAME:
1491 if (wFlags & DISPATCH_PROPERTYGET) {
1492 V_VT(pVarResult) = VT_BSTR;
1493 return IFont_get_Name(&this->IFont_iface, &V_BSTR(pVarResult));
1494 } else {
1495 VARIANTARG vararg;
1497 VariantInit(&vararg);
1498 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BSTR);
1499 if (FAILED(hr))
1500 return hr;
1502 hr = IFont_put_Name(&this->IFont_iface, V_BSTR(&vararg));
1504 VariantClear(&vararg);
1505 return hr;
1507 break;
1508 case DISPID_FONT_BOLD:
1509 if (wFlags & DISPATCH_PROPERTYGET) {
1510 BOOL value;
1511 hr = IFont_get_Bold(&this->IFont_iface, &value);
1512 V_VT(pVarResult) = VT_BOOL;
1513 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1514 return hr;
1515 } else {
1516 VARIANTARG vararg;
1518 VariantInit(&vararg);
1519 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1520 if (FAILED(hr))
1521 return hr;
1523 hr = IFont_put_Bold(&this->IFont_iface, V_BOOL(&vararg));
1525 VariantClear(&vararg);
1526 return hr;
1528 break;
1529 case DISPID_FONT_ITALIC:
1530 if (wFlags & DISPATCH_PROPERTYGET) {
1531 BOOL value;
1532 hr = IFont_get_Italic(&this->IFont_iface, &value);
1533 V_VT(pVarResult) = VT_BOOL;
1534 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1535 return hr;
1536 } else {
1537 VARIANTARG vararg;
1539 VariantInit(&vararg);
1540 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1541 if (FAILED(hr))
1542 return hr;
1544 hr = IFont_put_Italic(&this->IFont_iface, V_BOOL(&vararg));
1546 VariantClear(&vararg);
1547 return hr;
1549 break;
1550 case DISPID_FONT_UNDER:
1551 if (wFlags & DISPATCH_PROPERTYGET) {
1552 BOOL value;
1553 hr = IFont_get_Underline(&this->IFont_iface, &value);
1554 V_VT(pVarResult) = VT_BOOL;
1555 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1556 return hr;
1557 } else {
1558 VARIANTARG vararg;
1560 VariantInit(&vararg);
1561 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1562 if (FAILED(hr))
1563 return hr;
1565 hr = IFont_put_Underline(&this->IFont_iface, V_BOOL(&vararg));
1567 VariantClear(&vararg);
1568 return hr;
1570 break;
1571 case DISPID_FONT_STRIKE:
1572 if (wFlags & DISPATCH_PROPERTYGET) {
1573 BOOL value;
1574 hr = IFont_get_Strikethrough(&this->IFont_iface, &value);
1575 V_VT(pVarResult) = VT_BOOL;
1576 V_BOOL(pVarResult) = value ? VARIANT_TRUE : VARIANT_FALSE;
1577 return hr;
1578 } else {
1579 VARIANTARG vararg;
1581 VariantInit(&vararg);
1582 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_BOOL);
1583 if (FAILED(hr))
1584 return hr;
1586 hr = IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&vararg));
1588 VariantClear(&vararg);
1589 return hr;
1591 break;
1592 case DISPID_FONT_SIZE:
1593 if (wFlags & DISPATCH_PROPERTYGET) {
1594 V_VT(pVarResult) = VT_CY;
1595 return OLEFontImpl_get_Size(&this->IFont_iface, &V_CY(pVarResult));
1596 } else {
1597 VARIANTARG vararg;
1599 VariantInit(&vararg);
1600 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_CY);
1601 if (FAILED(hr))
1602 return hr;
1604 hr = IFont_put_Size(&this->IFont_iface, V_CY(&vararg));
1606 VariantClear(&vararg);
1607 return hr;
1609 break;
1610 case DISPID_FONT_WEIGHT:
1611 if (wFlags & DISPATCH_PROPERTYGET) {
1612 V_VT(pVarResult) = VT_I2;
1613 return OLEFontImpl_get_Weight(&this->IFont_iface, &V_I2(pVarResult));
1614 } else {
1615 VARIANTARG vararg;
1617 VariantInit(&vararg);
1618 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1619 if (FAILED(hr))
1620 return hr;
1622 hr = IFont_put_Weight(&this->IFont_iface, V_I2(&vararg));
1624 VariantClear(&vararg);
1625 return hr;
1627 break;
1628 case DISPID_FONT_CHARSET:
1629 if (wFlags & DISPATCH_PROPERTYGET) {
1630 V_VT(pVarResult) = VT_I2;
1631 return OLEFontImpl_get_Charset(&this->IFont_iface, &V_I2(pVarResult));
1632 } else {
1633 VARIANTARG vararg;
1635 VariantInit(&vararg);
1636 hr = VariantChangeTypeEx(&vararg, &pDispParams->rgvarg[0], lcid, 0, VT_I2);
1637 if (FAILED(hr))
1638 return hr;
1640 hr = IFont_put_Charset(&this->IFont_iface, V_I2(&vararg));
1642 VariantClear(&vararg);
1643 return hr;
1645 break;
1646 default:
1647 ERR("member not found for dispid 0x%x\n", dispIdMember);
1648 return DISP_E_MEMBERNOTFOUND;
1652 static const IDispatchVtbl OLEFontImpl_IDispatch_VTable =
1654 OLEFontImpl_IDispatch_QueryInterface,
1655 OLEFontImpl_IDispatch_AddRef,
1656 OLEFontImpl_IDispatch_Release,
1657 OLEFontImpl_GetTypeInfoCount,
1658 OLEFontImpl_GetTypeInfo,
1659 OLEFontImpl_GetIDsOfNames,
1660 OLEFontImpl_Invoke
1663 /************************************************************************
1664 * OLEFontImpl_IPersistStream_QueryInterface (IUnknown)
1666 * See Windows documentation for more details on IUnknown methods.
1668 static HRESULT WINAPI OLEFontImpl_IPersistStream_QueryInterface(
1669 IPersistStream* iface,
1670 REFIID riid,
1671 VOID** ppvoid)
1673 OLEFontImpl *this = impl_from_IPersistStream(iface);
1675 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
1678 /************************************************************************
1679 * OLEFontImpl_IPersistStream_Release (IUnknown)
1681 * See Windows documentation for more details on IUnknown methods.
1683 static ULONG WINAPI OLEFontImpl_IPersistStream_Release(
1684 IPersistStream* iface)
1686 OLEFontImpl *this = impl_from_IPersistStream(iface);
1688 return IFont_Release(&this->IFont_iface);
1691 /************************************************************************
1692 * OLEFontImpl_IPersistStream_AddRef (IUnknown)
1694 * See Windows documentation for more details on IUnknown methods.
1696 static ULONG WINAPI OLEFontImpl_IPersistStream_AddRef(
1697 IPersistStream* iface)
1699 OLEFontImpl *this = impl_from_IPersistStream(iface);
1701 return IFont_AddRef(&this->IFont_iface);
1704 /************************************************************************
1705 * OLEFontImpl_GetClassID (IPersistStream)
1707 * See Windows documentation for more details on IPersistStream methods.
1709 static HRESULT WINAPI OLEFontImpl_GetClassID(
1710 IPersistStream* iface,
1711 CLSID* pClassID)
1713 TRACE("(%p,%p)\n",iface,pClassID);
1714 if (pClassID==0)
1715 return E_POINTER;
1717 *pClassID = CLSID_StdFont;
1719 return S_OK;
1722 /************************************************************************
1723 * OLEFontImpl_IsDirty (IPersistStream)
1725 * See Windows documentation for more details on IPersistStream methods.
1727 static HRESULT WINAPI OLEFontImpl_IsDirty(
1728 IPersistStream* iface)
1730 TRACE("(%p)\n",iface);
1731 return S_OK;
1734 /************************************************************************
1735 * OLEFontImpl_Load (IPersistStream)
1737 * See Windows documentation for more details on IPersistStream methods.
1739 * This is the format of the standard font serialization as far as I
1740 * know
1742 * Offset Type Value Comment
1743 * 0x0000 Byte Unknown Probably a version number, contains 0x01
1744 * 0x0001 Short Charset Charset value from the FONTDESC structure
1745 * 0x0003 Byte Attributes Flags defined as follows:
1746 * 00000010 - Italic
1747 * 00000100 - Underline
1748 * 00001000 - Strikethrough
1749 * 0x0004 Short Weight Weight value from FONTDESC structure
1750 * 0x0006 DWORD size "Low" portion of the cySize member of the FONTDESC
1751 * structure/
1752 * 0x000A Byte name length Length of the font name string (no null character)
1753 * 0x000B String name Name of the font (ASCII, no nul character)
1755 static HRESULT WINAPI OLEFontImpl_Load(
1756 IPersistStream* iface,
1757 IStream* pLoadStream)
1759 char readBuffer[0x100];
1760 ULONG cbRead;
1761 BYTE bVersion;
1762 BYTE bAttributes;
1763 BYTE bStringSize;
1764 INT len;
1766 OLEFontImpl *this = impl_from_IPersistStream(iface);
1769 * Read the version byte
1771 IStream_Read(pLoadStream, &bVersion, 1, &cbRead);
1773 if ( (cbRead!=1) ||
1774 (bVersion!=0x01) )
1775 return E_FAIL;
1778 * Charset
1780 IStream_Read(pLoadStream, &this->description.sCharset, 2, &cbRead);
1782 if (cbRead!=2)
1783 return E_FAIL;
1786 * Attributes
1788 IStream_Read(pLoadStream, &bAttributes, 1, &cbRead);
1790 if (cbRead!=1)
1791 return E_FAIL;
1793 this->description.fItalic = (bAttributes & FONTPERSIST_ITALIC) != 0;
1794 this->description.fStrikethrough = (bAttributes & FONTPERSIST_STRIKETHROUGH) != 0;
1795 this->description.fUnderline = (bAttributes & FONTPERSIST_UNDERLINE) != 0;
1798 * Weight
1800 IStream_Read(pLoadStream, &this->description.sWeight, 2, &cbRead);
1802 if (cbRead!=2)
1803 return E_FAIL;
1806 * Size
1808 IStream_Read(pLoadStream, &this->description.cySize.s.Lo, 4, &cbRead);
1810 if (cbRead!=4)
1811 return E_FAIL;
1813 this->description.cySize.s.Hi = 0;
1816 * FontName
1818 IStream_Read(pLoadStream, &bStringSize, 1, &cbRead);
1820 if (cbRead!=1)
1821 return E_FAIL;
1823 IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead);
1825 if (cbRead!=bStringSize)
1826 return E_FAIL;
1828 HeapFree(GetProcessHeap(), 0, this->description.lpstrName);
1830 len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 );
1831 this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) );
1832 MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len );
1833 this->description.lpstrName[len] = 0;
1835 /* Ensure use of this font causes a new one to be created */
1836 dec_int_ref(this->gdiFont);
1837 this->gdiFont = 0;
1838 this->dirty = TRUE;
1840 return S_OK;
1843 /************************************************************************
1844 * OLEFontImpl_Save (IPersistStream)
1846 * See Windows documentation for more details on IPersistStream methods.
1848 static HRESULT WINAPI OLEFontImpl_Save(
1849 IPersistStream* iface,
1850 IStream* pOutStream,
1851 BOOL fClearDirty)
1853 char* writeBuffer = NULL;
1854 ULONG cbWritten;
1855 BYTE bVersion = 0x01;
1856 BYTE bAttributes;
1857 BYTE bStringSize;
1859 OLEFontImpl *this = impl_from_IPersistStream(iface);
1862 * Read the version byte
1864 IStream_Write(pOutStream, &bVersion, 1, &cbWritten);
1866 if (cbWritten!=1)
1867 return E_FAIL;
1870 * Charset
1872 IStream_Write(pOutStream, &this->description.sCharset, 2, &cbWritten);
1874 if (cbWritten!=2)
1875 return E_FAIL;
1878 * Attributes
1880 bAttributes = 0;
1882 if (this->description.fItalic)
1883 bAttributes |= FONTPERSIST_ITALIC;
1885 if (this->description.fStrikethrough)
1886 bAttributes |= FONTPERSIST_STRIKETHROUGH;
1888 if (this->description.fUnderline)
1889 bAttributes |= FONTPERSIST_UNDERLINE;
1891 IStream_Write(pOutStream, &bAttributes, 1, &cbWritten);
1893 if (cbWritten!=1)
1894 return E_FAIL;
1897 * Weight
1899 IStream_Write(pOutStream, &this->description.sWeight, 2, &cbWritten);
1901 if (cbWritten!=2)
1902 return E_FAIL;
1905 * Size
1907 IStream_Write(pOutStream, &this->description.cySize.s.Lo, 4, &cbWritten);
1909 if (cbWritten!=4)
1910 return E_FAIL;
1913 * FontName
1915 if (this->description.lpstrName!=0)
1916 bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1917 strlenW(this->description.lpstrName), NULL, 0, NULL, NULL );
1918 else
1919 bStringSize = 0;
1921 IStream_Write(pOutStream, &bStringSize, 1, &cbWritten);
1923 if (cbWritten!=1)
1924 return E_FAIL;
1926 if (bStringSize!=0)
1928 if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY;
1929 WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1930 strlenW(this->description.lpstrName),
1931 writeBuffer, bStringSize, NULL, NULL );
1933 IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten);
1934 HeapFree(GetProcessHeap(), 0, writeBuffer);
1936 if (cbWritten!=bStringSize)
1937 return E_FAIL;
1940 return S_OK;
1943 /************************************************************************
1944 * OLEFontImpl_GetSizeMax (IPersistStream)
1946 * See Windows documentation for more details on IPersistStream methods.
1948 static HRESULT WINAPI OLEFontImpl_GetSizeMax(
1949 IPersistStream* iface,
1950 ULARGE_INTEGER* pcbSize)
1952 OLEFontImpl *this = impl_from_IPersistStream(iface);
1954 if (pcbSize==NULL)
1955 return E_POINTER;
1957 pcbSize->u.HighPart = 0;
1958 pcbSize->u.LowPart = 0;
1960 pcbSize->u.LowPart += sizeof(BYTE); /* Version */
1961 pcbSize->u.LowPart += sizeof(WORD); /* Lang code */
1962 pcbSize->u.LowPart += sizeof(BYTE); /* Flags */
1963 pcbSize->u.LowPart += sizeof(WORD); /* Weight */
1964 pcbSize->u.LowPart += sizeof(DWORD); /* Size */
1965 pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */
1967 if (this->description.lpstrName!=0)
1968 pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName,
1969 strlenW(this->description.lpstrName),
1970 NULL, 0, NULL, NULL );
1972 return S_OK;
1975 static const IPersistStreamVtbl OLEFontImpl_IPersistStream_VTable =
1977 OLEFontImpl_IPersistStream_QueryInterface,
1978 OLEFontImpl_IPersistStream_AddRef,
1979 OLEFontImpl_IPersistStream_Release,
1980 OLEFontImpl_GetClassID,
1981 OLEFontImpl_IsDirty,
1982 OLEFontImpl_Load,
1983 OLEFontImpl_Save,
1984 OLEFontImpl_GetSizeMax
1987 /************************************************************************
1988 * OLEFontImpl_IConnectionPointContainer_QueryInterface (IUnknown)
1990 * See Windows documentation for more details on IUnknown methods.
1992 static HRESULT WINAPI OLEFontImpl_IConnectionPointContainer_QueryInterface(
1993 IConnectionPointContainer* iface,
1994 REFIID riid,
1995 VOID** ppvoid)
1997 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
1999 return IFont_QueryInterface(&this->IFont_iface, riid, ppvoid);
2002 /************************************************************************
2003 * OLEFontImpl_IConnectionPointContainer_Release (IUnknown)
2005 * See Windows documentation for more details on IUnknown methods.
2007 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_Release(
2008 IConnectionPointContainer* iface)
2010 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2012 return IFont_Release(&this->IFont_iface);
2015 /************************************************************************
2016 * OLEFontImpl_IConnectionPointContainer_AddRef (IUnknown)
2018 * See Windows documentation for more details on IUnknown methods.
2020 static ULONG WINAPI OLEFontImpl_IConnectionPointContainer_AddRef(
2021 IConnectionPointContainer* iface)
2023 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2025 return IFont_AddRef(&this->IFont_iface);
2028 /************************************************************************
2029 * OLEFontImpl_EnumConnectionPoints (IConnectionPointContainer)
2031 * See Windows documentation for more details on IConnectionPointContainer
2032 * methods.
2034 static HRESULT WINAPI OLEFontImpl_EnumConnectionPoints(
2035 IConnectionPointContainer* iface,
2036 IEnumConnectionPoints **ppEnum)
2038 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2040 FIXME("(%p)->(%p): stub\n", this, ppEnum);
2041 return E_NOTIMPL;
2044 /************************************************************************
2045 * OLEFontImpl_FindConnectionPoint (IConnectionPointContainer)
2047 * See Windows documentation for more details on IConnectionPointContainer
2048 * methods.
2050 static HRESULT WINAPI OLEFontImpl_FindConnectionPoint(
2051 IConnectionPointContainer* iface,
2052 REFIID riid,
2053 IConnectionPoint **ppCp)
2055 OLEFontImpl *this = impl_from_IConnectionPointContainer(iface);
2056 TRACE("(%p)->(%s, %p)\n", this, debugstr_guid(riid), ppCp);
2058 if(IsEqualIID(riid, &IID_IPropertyNotifySink)) {
2059 return IConnectionPoint_QueryInterface(this->pPropertyNotifyCP,
2060 &IID_IConnectionPoint,
2061 (LPVOID)ppCp);
2062 } else if(IsEqualIID(riid, &IID_IFontEventsDisp)) {
2063 return IConnectionPoint_QueryInterface(this->pFontEventsCP,
2064 &IID_IConnectionPoint,
2065 (LPVOID)ppCp);
2066 } else {
2067 FIXME("no connection point for %s\n", debugstr_guid(riid));
2068 return CONNECT_E_NOCONNECTION;
2072 static const IConnectionPointContainerVtbl
2073 OLEFontImpl_IConnectionPointContainer_VTable =
2075 OLEFontImpl_IConnectionPointContainer_QueryInterface,
2076 OLEFontImpl_IConnectionPointContainer_AddRef,
2077 OLEFontImpl_IConnectionPointContainer_Release,
2078 OLEFontImpl_EnumConnectionPoints,
2079 OLEFontImpl_FindConnectionPoint
2082 /************************************************************************
2083 * OLEFontImpl implementation of IPersistPropertyBag.
2085 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_QueryInterface(
2086 IPersistPropertyBag *iface, REFIID riid, LPVOID *ppvObj
2088 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2089 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2092 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_AddRef(
2093 IPersistPropertyBag *iface
2095 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2096 return IFont_AddRef(&this->IFont_iface);
2099 static ULONG WINAPI OLEFontImpl_IPersistPropertyBag_Release(
2100 IPersistPropertyBag *iface
2102 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2103 return IFont_Release(&this->IFont_iface);
2106 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_GetClassID(
2107 IPersistPropertyBag *iface, CLSID *classid
2109 FIXME("(%p,%p), stub!\n", iface, classid);
2110 return E_FAIL;
2113 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_InitNew(
2114 IPersistPropertyBag *iface
2116 FIXME("(%p), stub!\n", iface);
2117 return S_OK;
2120 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Load(
2121 IPersistPropertyBag *iface, IPropertyBag* pPropBag, IErrorLog* pErrorLog
2123 /* (from Visual Basic 6 property bag)
2124 Name = "MS Sans Serif"
2125 Size = 13.8
2126 Charset = 0
2127 Weight = 400
2128 Underline = 0 'False
2129 Italic = 0 'False
2130 Strikethrough = 0 'False
2132 static const WCHAR sAttrName[] = {'N','a','m','e',0};
2133 static const WCHAR sAttrSize[] = {'S','i','z','e',0};
2134 static const WCHAR sAttrCharset[] = {'C','h','a','r','s','e','t',0};
2135 static const WCHAR sAttrWeight[] = {'W','e','i','g','h','t',0};
2136 static const WCHAR sAttrUnderline[] = {'U','n','d','e','r','l','i','n','e',0};
2137 static const WCHAR sAttrItalic[] = {'I','t','a','l','i','c',0};
2138 static const WCHAR sAttrStrikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
2139 OLEFontImpl *this = impl_from_IPersistPropertyBag(iface);
2140 VARIANT value;
2141 HRESULT iRes;
2143 VariantInit(&value);
2145 iRes = IPropertyBag_Read(pPropBag, sAttrName, &value, pErrorLog);
2146 if (iRes == S_OK)
2148 iRes = VariantChangeType(&value, &value, 0, VT_BSTR);
2149 if (iRes == S_OK)
2150 iRes = IFont_put_Name(&this->IFont_iface, V_BSTR(&value));
2152 else if (iRes == E_INVALIDARG)
2153 iRes = S_OK;
2155 VariantClear(&value);
2157 if (iRes == S_OK) {
2158 iRes = IPropertyBag_Read(pPropBag, sAttrSize, &value, pErrorLog);
2159 if (iRes == S_OK)
2161 iRes = VariantChangeType(&value, &value, 0, VT_CY);
2162 if (iRes == S_OK)
2163 iRes = IFont_put_Size(&this->IFont_iface, V_CY(&value));
2165 else if (iRes == E_INVALIDARG)
2166 iRes = S_OK;
2168 VariantClear(&value);
2171 if (iRes == S_OK) {
2172 iRes = IPropertyBag_Read(pPropBag, sAttrCharset, &value, pErrorLog);
2173 if (iRes == S_OK)
2175 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2176 if (iRes == S_OK)
2177 iRes = IFont_put_Charset(&this->IFont_iface, V_I2(&value));
2179 else if (iRes == E_INVALIDARG)
2180 iRes = S_OK;
2182 VariantClear(&value);
2185 if (iRes == S_OK) {
2186 iRes = IPropertyBag_Read(pPropBag, sAttrWeight, &value, pErrorLog);
2187 if (iRes == S_OK)
2189 iRes = VariantChangeType(&value, &value, 0, VT_I2);
2190 if (iRes == S_OK)
2191 iRes = IFont_put_Weight(&this->IFont_iface, V_I2(&value));
2193 else if (iRes == E_INVALIDARG)
2194 iRes = S_OK;
2196 VariantClear(&value);
2199 if (iRes == S_OK) {
2200 iRes = IPropertyBag_Read(pPropBag, sAttrUnderline, &value, pErrorLog);
2201 if (iRes == S_OK)
2203 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2204 if (iRes == S_OK)
2205 iRes = IFont_put_Underline(&this->IFont_iface, V_BOOL(&value));
2207 else if (iRes == E_INVALIDARG)
2208 iRes = S_OK;
2210 VariantClear(&value);
2213 if (iRes == S_OK) {
2214 iRes = IPropertyBag_Read(pPropBag, sAttrItalic, &value, pErrorLog);
2215 if (iRes == S_OK)
2217 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2218 if (iRes == S_OK)
2219 iRes = IFont_put_Italic(&this->IFont_iface, V_BOOL(&value));
2221 else if (iRes == E_INVALIDARG)
2222 iRes = S_OK;
2224 VariantClear(&value);
2227 if (iRes == S_OK) {
2228 iRes = IPropertyBag_Read(pPropBag, sAttrStrikethrough, &value, pErrorLog);
2229 if (iRes == S_OK)
2231 iRes = VariantChangeType(&value, &value, 0, VT_BOOL);
2232 if (iRes == S_OK)
2233 IFont_put_Strikethrough(&this->IFont_iface, V_BOOL(&value));
2235 else if (iRes == E_INVALIDARG)
2236 iRes = S_OK;
2238 VariantClear(&value);
2241 if (FAILED(iRes))
2242 WARN("-- 0x%08x\n", iRes);
2243 return iRes;
2246 static HRESULT WINAPI OLEFontImpl_IPersistPropertyBag_Save(
2247 IPersistPropertyBag *iface, IPropertyBag* pPropBag, BOOL fClearDirty,
2248 BOOL fSaveAllProperties
2250 FIXME("(%p,%p,%d,%d), stub!\n", iface, pPropBag, fClearDirty, fSaveAllProperties);
2251 return E_FAIL;
2254 static const IPersistPropertyBagVtbl OLEFontImpl_IPersistPropertyBag_VTable =
2256 OLEFontImpl_IPersistPropertyBag_QueryInterface,
2257 OLEFontImpl_IPersistPropertyBag_AddRef,
2258 OLEFontImpl_IPersistPropertyBag_Release,
2260 OLEFontImpl_IPersistPropertyBag_GetClassID,
2261 OLEFontImpl_IPersistPropertyBag_InitNew,
2262 OLEFontImpl_IPersistPropertyBag_Load,
2263 OLEFontImpl_IPersistPropertyBag_Save
2266 /************************************************************************
2267 * OLEFontImpl implementation of IPersistStreamInit.
2269 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_QueryInterface(
2270 IPersistStreamInit *iface, REFIID riid, LPVOID *ppvObj
2272 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2273 return IFont_QueryInterface(&this->IFont_iface,riid,ppvObj);
2276 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_AddRef(
2277 IPersistStreamInit *iface
2279 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2280 return IFont_AddRef(&this->IFont_iface);
2283 static ULONG WINAPI OLEFontImpl_IPersistStreamInit_Release(
2284 IPersistStreamInit *iface
2286 OLEFontImpl *this = impl_from_IPersistStreamInit(iface);
2287 return IFont_Release(&this->IFont_iface);
2290 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetClassID(
2291 IPersistStreamInit *iface, CLSID *classid
2293 FIXME("(%p,%p), stub!\n", iface, classid);
2294 return E_FAIL;
2297 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_IsDirty(
2298 IPersistStreamInit *iface
2300 FIXME("(%p), stub!\n", iface);
2301 return E_FAIL;
2304 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Load(
2305 IPersistStreamInit *iface, LPSTREAM pStm
2307 FIXME("(%p,%p), stub!\n", iface, pStm);
2308 return E_FAIL;
2311 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_Save(
2312 IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty
2314 FIXME("(%p,%p,%d), stub!\n", iface, pStm, fClearDirty);
2315 return E_FAIL;
2318 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_GetSizeMax(
2319 IPersistStreamInit *iface, ULARGE_INTEGER *pcbSize
2321 FIXME("(%p,%p), stub!\n", iface, pcbSize);
2322 return E_FAIL;
2325 static HRESULT WINAPI OLEFontImpl_IPersistStreamInit_InitNew(
2326 IPersistStreamInit *iface
2328 FIXME("(%p), stub!\n", iface);
2329 return S_OK;
2332 static const IPersistStreamInitVtbl OLEFontImpl_IPersistStreamInit_VTable =
2334 OLEFontImpl_IPersistStreamInit_QueryInterface,
2335 OLEFontImpl_IPersistStreamInit_AddRef,
2336 OLEFontImpl_IPersistStreamInit_Release,
2338 OLEFontImpl_IPersistStreamInit_GetClassID,
2339 OLEFontImpl_IPersistStreamInit_IsDirty,
2340 OLEFontImpl_IPersistStreamInit_Load,
2341 OLEFontImpl_IPersistStreamInit_Save,
2342 OLEFontImpl_IPersistStreamInit_GetSizeMax,
2343 OLEFontImpl_IPersistStreamInit_InitNew
2346 /************************************************************************
2347 * OLEFontImpl_Construct
2349 * This method will construct a new instance of the OLEFontImpl
2350 * class.
2352 * The caller of this method must release the object when it's
2353 * done with it.
2355 static OLEFontImpl* OLEFontImpl_Construct(const FONTDESC *fontDesc)
2357 OLEFontImpl* newObject = 0;
2360 * Allocate space for the object.
2362 newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
2364 if (newObject==0)
2365 return newObject;
2368 * Initialize the virtual function table.
2370 newObject->IFont_iface.lpVtbl = &OLEFontImpl_VTable;
2371 newObject->IDispatch_iface.lpVtbl = &OLEFontImpl_IDispatch_VTable;
2372 newObject->IPersistStream_iface.lpVtbl = &OLEFontImpl_IPersistStream_VTable;
2373 newObject->IConnectionPointContainer_iface.lpVtbl = &OLEFontImpl_IConnectionPointContainer_VTable;
2374 newObject->IPersistPropertyBag_iface.lpVtbl = &OLEFontImpl_IPersistPropertyBag_VTable;
2375 newObject->IPersistStreamInit_iface.lpVtbl = &OLEFontImpl_IPersistStreamInit_VTable;
2378 * Start with one reference count. The caller of this function
2379 * must release the interface pointer when it is done.
2381 newObject->ref = 1;
2384 * Copy the description of the font in the object.
2386 assert(fontDesc->cbSizeofstruct >= sizeof(FONTDESC));
2388 newObject->description.cbSizeofstruct = sizeof(FONTDESC);
2389 newObject->description.lpstrName = HeapAlloc(GetProcessHeap(),
2391 (lstrlenW(fontDesc->lpstrName)+1) * sizeof(WCHAR));
2392 strcpyW(newObject->description.lpstrName, fontDesc->lpstrName);
2393 newObject->description.cySize = fontDesc->cySize;
2394 newObject->description.sWeight = fontDesc->sWeight;
2395 newObject->description.sCharset = fontDesc->sCharset;
2396 newObject->description.fItalic = fontDesc->fItalic;
2397 newObject->description.fUnderline = fontDesc->fUnderline;
2398 newObject->description.fStrikethrough = fontDesc->fStrikethrough;
2401 * Initializing all the other members.
2403 newObject->gdiFont = 0;
2404 newObject->dirty = TRUE;
2405 newObject->cyLogical = 72L;
2406 newObject->cyHimetric = 2540L;
2407 newObject->pPropertyNotifyCP = NULL;
2408 newObject->pFontEventsCP = NULL;
2410 CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
2411 CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
2413 if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
2415 OLEFontImpl_Destroy(newObject);
2416 return NULL;
2419 InterlockedIncrement(&ifont_cnt);
2421 TRACE("returning %p\n", newObject);
2422 return newObject;
2425 /************************************************************************
2426 * OLEFontImpl_Destroy
2428 * This method is called by the Release method when the reference
2429 * count goes down to 0. It will free all resources used by
2430 * this object.
2432 static void OLEFontImpl_Destroy(OLEFontImpl* fontDesc)
2434 TRACE("(%p)\n", fontDesc);
2436 HeapFree(GetProcessHeap(), 0, fontDesc->description.lpstrName);
2438 if (fontDesc->pPropertyNotifyCP)
2439 IConnectionPoint_Release(fontDesc->pPropertyNotifyCP);
2440 if (fontDesc->pFontEventsCP)
2441 IConnectionPoint_Release(fontDesc->pFontEventsCP);
2443 HeapFree(GetProcessHeap(), 0, fontDesc);
2446 /*******************************************************************************
2447 * StdFont ClassFactory
2449 typedef struct
2451 /* IUnknown fields */
2452 IClassFactory IClassFactory_iface;
2453 LONG ref;
2454 } IClassFactoryImpl;
2456 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
2458 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
2461 static HRESULT WINAPI
2462 SFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
2463 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2465 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
2466 return E_NOINTERFACE;
2469 static ULONG WINAPI
2470 SFCF_AddRef(LPCLASSFACTORY iface) {
2471 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2472 return InterlockedIncrement(&This->ref);
2475 static ULONG WINAPI SFCF_Release(LPCLASSFACTORY iface) {
2476 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2477 /* static class, won't be freed */
2478 return InterlockedDecrement(&This->ref);
2481 static HRESULT WINAPI SFCF_CreateInstance(
2482 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
2484 return OleCreateFontIndirect(NULL,riid,ppobj);
2488 static HRESULT WINAPI SFCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
2489 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
2490 FIXME("(%p)->(%d),stub!\n",This,dolock);
2491 return S_OK;
2494 static const IClassFactoryVtbl SFCF_Vtbl = {
2495 SFCF_QueryInterface,
2496 SFCF_AddRef,
2497 SFCF_Release,
2498 SFCF_CreateInstance,
2499 SFCF_LockServer
2501 static IClassFactoryImpl STDFONT_CF = {{&SFCF_Vtbl}, 1 };
2503 void _get_STDFONT_CF(LPVOID *ppv) { *ppv = &STDFONT_CF; }