add skeleton for variant type support
[pywinlite.git] / olepicture.py
blob30ce001157df581dcda7cc83bde76cc17cf0a5fa
1 #Copyright (c) 2009 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
10 #conditions:
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 # ole pictures
26 from ctypes import POINTER, windll, byref
28 from windef import LONG, GUID, HRESULT, OLE_HANDLE, SHORT, HDC, LPCRECT, BOOL, LPVOID, REFIID, DWORD
29 from winliteutils import get_symbols
30 from winlitecom import IUnknown
31 from storage import IStream, file_stream, STGM_SHARE_DENY_WRITE, STGM_READ
33 OLE_XPOS_HIMETRIC = LONG
34 OLE_YPOS_HIMETRIC = LONG
35 OLE_XSIZE_HIMETRIC = LONG
36 OLE_YSIZE_HIMETRIC = LONG
38 class IPicture(IUnknown):
39 iid = GUID("7bf80980-bf32-101a-8bbb-00aa00300cab")
41 com_methods = [('get_Handle', HRESULT, POINTER(OLE_HANDLE)),
42 ('get_hPal', HRESULT, POINTER(OLE_HANDLE)),
43 ('get_Type', HRESULT, POINTER(SHORT)),
44 ('get_Width', HRESULT, POINTER(OLE_XSIZE_HIMETRIC)),
45 ('get_Height', HRESULT, POINTER(OLE_YSIZE_HIMETRIC)),
46 ('Render', HRESULT, HDC, LONG, LONG, LONG, LONG, OLE_XPOS_HIMETRIC, OLE_YPOS_HIMETRIC, OLE_XSIZE_HIMETRIC, OLE_YSIZE_HIMETRIC, LPCRECT),
47 ('set_hPal', HRESULT, POINTER(OLE_HANDLE)),
48 ('get_CurDC', HRESULT, HDC),
49 ('SelectPicture', HRESULT, HDC, POINTER(HDC), POINTER(OLE_HANDLE)),
50 ('get_KeepOriginalFormat', HRESULT, POINTER(BOOL)),
51 ('put_KeepOriginalFormat', HRESULT, BOOL),
52 ('PictureChanged', HRESULT),
53 ('SaveAsFile', HRESULT, IStream, BOOL, LONG),
54 ('get_Attributes', HRESULT, POINTER(DWORD)),
57 def _get_width(self):
58 result = OLE_XSIZE_HIMETRIC()
59 self.get_Width(byref(result))
60 return result.value
62 width = property(_get_width)
64 def _get_height(self):
65 result = OLE_YSIZE_HIMETRIC()
66 self.get_Height(byref(result))
67 return result.value
69 height = property(_get_height)
71 def _get_handle(self):
72 result = OLE_HANDLE()
73 self.get_Handle(byref(result))
74 return result.value
76 handle = property(_get_handle)
78 _oleaut32 = windll.oleaut32
80 get_symbols(globals(), _oleaut32, ['OleLoadPicture'])
82 OleLoadPicture.argtypes = [IStream, LONG, BOOL, REFIID, LPVOID]
83 OleLoadPicture.restype = HRESULT
85 def stream_picture(stream):
86 p = LPVOID()
87 OleLoadPicture(stream, 0, 1, byref(IPicture.iid), byref(p))
88 return IPicture(p.value)
90 def file_picture(filename):
91 stream = file_stream(filename, STGM_SHARE_DENY_WRITE|STGM_READ)
92 return stream_picture(stream)