[pywin32-checkins] pywin32/win32/Lib win32gui_struct.py, 1.11.2.2, 1.11.2.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2009-01-14 13:02:37
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4460/win32/Lib Modified Files: Tag: py3k win32gui_struct.py Log Message: merge lots of changes from the trunk Index: win32gui_struct.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/win32gui_struct.py,v retrieving revision 1.11.2.2 retrieving revision 1.11.2.3 diff -C2 -d -r1.11.2.2 -r1.11.2.3 *** win32gui_struct.py 3 Jan 2009 04:51:00 -0000 1.11.2.2 --- win32gui_struct.py 14 Jan 2009 12:42:03 -0000 1.11.2.3 *************** *** 35,38 **** --- 35,61 ---- import pywintypes + # Encode a string suitable for passing in a win32gui related structure + # If win32gui is built with UNICODE defined (ie, py3k), then functions + # like InsertMenuItem are actually calling InsertMenuItemW etc, so all + # strings will need to be unicode. + if win32gui.UNICODE: + def _make_text_buffer(text): + # XXX - at this stage win32gui.UNICODE is only True in py3k, + # and in py3k is makes sense to reject bytes. + if not isinstance(text, str): + raise TypeError('MENUITEMINFO text must be unicode') + data = (text+'\0').encode("unicode-internal") + return array.array("b", data) + + else: + def _make_text_buffer(text): + if isinstance(text, str): + text = text.encode("mbcs") + return array.array("b", text+'\0') + + # make an 'empty' buffer, ready for filling with cch characters. + def _make_empty_text_buffer(cch): + return _make_text_buffer("\0" * cch) + # Generic WM_NOTIFY unpacking def UnpackWMNOTIFY(lparam): *************** *** 48,52 **** # structure to avoid the caller needing to explicitly check validity # (None is used if the mask excludes/should exclude the value) ! menuitem_fmt = '5i5PiP' def PackMENUITEMINFO(fType=None, fState=None, wID=None, hSubMenu=None, --- 71,75 ---- # structure to avoid the caller needing to explicitly check validity # (None is used if the mask excludes/should exclude the value) ! _menuiteminfo_fmt = '5i5PiP' def PackMENUITEMINFO(fType=None, fState=None, wID=None, hSubMenu=None, *************** *** 89,96 **** if text is not None: fMask |= win32con.MIIM_STRING ! if not isinstance(text, str): ! raise TypeError('MENUITEMINFO text must be unicode') ! encoded_text = (text+'\0').encode("utf-16-le") ! str_buf = array.array("b", encoded_text) cch = len(text) # We are taking address of strbuf - it must not die until windows --- 112,116 ---- if text is not None: fMask |= win32con.MIIM_STRING ! str_buf = _make_text_buffer(text) cch = len(text) # We are taking address of strbuf - it must not die until windows *************** *** 104,109 **** # 'P' format does not accept PyHANDLE's ! item = struct.pack( ! menuitem_fmt, ! struct.calcsize(menuitem_fmt), # cbSize fMask, fType, --- 124,129 ---- # 'P' format does not accept PyHANDLE's ! item = struct.pack( ! _menuiteminfo_fmt, ! struct.calcsize(_menuiteminfo_fmt), # cbSize fMask, fType, *************** *** 134,138 **** lptext, cch, ! hbmpItem) = struct.unpack(menuitem_fmt, s) assert cb==len(s) if fMask & win32con.MIIM_FTYPE==0: fType = None --- 154,158 ---- lptext, cch, ! hbmpItem) = struct.unpack(_menuiteminfo_fmt, s) assert cb==len(s) if fMask & win32con.MIIM_FTYPE==0: fType = None *************** *** 151,154 **** --- 171,175 ---- def EmptyMENUITEMINFO(mask = None, text_buf_size=512): + # text_buf_size is number of *characters* - not necessarily no of bytes. extra = [] if mask is None: *************** *** 160,172 **** if mask & win32con.MIIM_STRING: ! text_buffer = array.array("c", "\0" * text_buf_size) extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() else: ! text_addr = text_len = 0 buf = struct.pack( ! menuitem_fmt, ! struct.calcsize(menuitem_fmt), # cbSize mask, 0, #fType, --- 181,195 ---- if mask & win32con.MIIM_STRING: ! text_buffer = _make_empty_text_buffer(text_buf_size) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() else: ! text_addr = text_buf_size = 0 + # Now copy the string to a writable buffer, so that the result + # could be passed to a 'Get' function buf = struct.pack( ! _menuiteminfo_fmt, ! struct.calcsize(_menuiteminfo_fmt), # cbSize mask, 0, #fType, *************** *** 178,188 **** 0, #dwItemData, text_addr, ! text_len, 0, #hbmpItem ) ! return array.array("c", buf), extra # MENUINFO struct ! menuinfo_fmt = '7i' def PackMENUINFO(dwStyle = None, cyMax = None, --- 201,211 ---- 0, #dwItemData, text_addr, ! text_buf_size, 0, #hbmpItem ) ! return array.array("b", buf), extra # MENUINFO struct ! _menuinfo_fmt = 'iiiiPiP' def PackMENUINFO(dwStyle = None, cyMax = None, *************** *** 201,206 **** # Create the struct. item = struct.pack( ! menuinfo_fmt, ! struct.calcsize(menuinfo_fmt), # cbSize fMask, dwStyle, --- 224,229 ---- # Create the struct. item = struct.pack( ! _menuinfo_fmt, ! struct.calcsize(_menuinfo_fmt), # cbSize fMask, dwStyle, *************** *** 209,213 **** dwContextHelpID, dwMenuData) ! return array.array("c", item) def UnpackMENUINFO(s): --- 232,236 ---- dwContextHelpID, dwMenuData) ! return array.array("b", item) def UnpackMENUINFO(s): *************** *** 218,222 **** hbrBack, dwContextHelpID, ! dwMenuData) = struct.unpack(menuinfo_fmt, s) assert cb==len(s) if fMask & win32con.MIM_STYLE==0: dwStyle = None --- 241,245 ---- hbrBack, dwContextHelpID, ! dwMenuData) = struct.unpack(_menuinfo_fmt, s) assert cb==len(s) if fMask & win32con.MIM_STYLE==0: dwStyle = None *************** *** 234,239 **** buf = struct.pack( ! menuinfo_fmt, ! struct.calcsize(menuinfo_fmt), # cbSize mask, 0, #dwStyle --- 257,262 ---- buf = struct.pack( ! _menuinfo_fmt, ! struct.calcsize(_menuinfo_fmt), # cbSize mask, 0, #dwStyle *************** *** 243,247 **** 0, #dwMenuData, ) ! return array.array("c", buf) ########################################################################## --- 266,270 ---- 0, #dwMenuData, ) ! return array.array("b", buf) ########################################################################## *************** *** 289,297 **** text_addr = text_len = 0 else: ! if isinstance(text, str): ! text = text.encode("mbcs") ! text_buffer = array.array("c", text+"\0") extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() format = "iiiiiiiiii" buf = struct.pack(format, --- 312,319 ---- text_addr = text_len = 0 else: ! text_buffer = _make_text_buffer(text) ! text_len = len(text) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() format = "iiiiiiiiii" buf = struct.pack(format, *************** *** 301,305 **** image, selimage, citems, param) ! return array.array("c", buf), extra # Make a new buffer suitable for querying hitem's attributes. --- 323,327 ---- image, selimage, citems, param) ! return array.array("b", buf), extra # Make a new buffer suitable for querying hitem's attributes. *************** *** 311,327 **** commctrl.TVIF_CHILDREN | commctrl.TVIF_PARAM if mask & commctrl.TVIF_TEXT: ! text_buffer = array.array("c", "\0" * text_buf_size) extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() else: ! text_addr = text_len = 0 format = "iiiiiiiiii" buf = struct.pack(format, mask, hitem, 0, 0, ! text_addr, text_len, # text 0, 0, 0, 0) ! return array.array("c", buf), extra def UnpackTVITEM(buffer): --- 333,349 ---- commctrl.TVIF_CHILDREN | commctrl.TVIF_PARAM if mask & commctrl.TVIF_TEXT: ! text_buffer = _make_empty_text_buffer(text_buf_size) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() else: ! text_addr = text_buf_size = 0 format = "iiiiiiiiii" buf = struct.pack(format, mask, hitem, 0, 0, ! text_addr, text_buf_size, # text 0, 0, 0, 0) ! return array.array("b", buf), extra def UnpackTVITEM(buffer): *************** *** 390,398 **** else: mask |= commctrl.LVIF_TEXT ! if isinstance(text, str): ! text = text.encode("mbcs") ! text_buffer = array.array("c", text+"\0") extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() format = "iiiiiiiiii" buf = struct.pack(format, --- 412,419 ---- else: mask |= commctrl.LVIF_TEXT ! text_buffer = _make_text_buffer(text) ! text_len = len(text) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() format = "iiiiiiiiii" buf = struct.pack(format, *************** *** 401,405 **** text_addr, text_len, # text image, param, indent) ! return array.array("c", buf), extra def UnpackLVITEM(buffer): --- 422,426 ---- text_addr, text_len, # text image, param, indent) ! return array.array("b", buf), extra def UnpackLVITEM(buffer): *************** *** 446,461 **** commctrl.LVIF_PARAM | commctrl.LVIF_STATE if mask & commctrl.LVIF_TEXT: ! text_buffer = array.array("c", "\0" * text_buf_size) extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() else: ! text_addr = text_len = 0 format = "iiiiiiiiii" buf = struct.pack(format, mask, item, subitem, 0, 0, ! text_addr, text_len, # text 0, 0, 0) ! return array.array("c", buf), extra --- 467,482 ---- commctrl.LVIF_PARAM | commctrl.LVIF_STATE if mask & commctrl.LVIF_TEXT: ! text_buffer = _make_empty_text_buffer(text_buf_size) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() else: ! text_addr = text_buf_size = 0 format = "iiiiiiiiii" buf = struct.pack(format, mask, item, subitem, 0, 0, ! text_addr, text_buf_size, # text 0, 0, 0) ! return array.array("b", buf), extra *************** *** 473,481 **** text_addr = text_len = 0 else: ! if isinstance(text, str): ! text = text.encode("mbcs") ! text_buffer = array.array("c", text+"\0") extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() format = "iiiiiiii" buf = struct.pack(format, --- 494,501 ---- text_addr = text_len = 0 else: ! text_buffer = _make_text_buffer(text) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() ! text_len = len(text) format = "iiiiiiii" buf = struct.pack(format, *************** *** 483,487 **** text_addr, text_len, # text subItem, image, order) ! return array.array("c", buf), extra def UnpackLVCOLUMN(lparam): --- 503,507 ---- text_addr, text_len, # text subItem, image, order) ! return array.array("b", buf), extra def UnpackLVCOLUMN(lparam): *************** *** 510,524 **** commctrl.LVCF_SUBITEM | commctrl.LVCF_IMAGE | commctrl.LVCF_ORDER if mask & commctrl.LVCF_TEXT: ! text_buffer = array.array("c", "\0" * text_buf_size) extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() else: ! text_addr = text_len = 0 format = "iiiiiiii" buf = struct.pack(format, mask, 0, 0, ! text_addr, text_len, # text 0, 0, 0) ! return array.array("c", buf), extra # List view hit-test. --- 530,544 ---- commctrl.LVCF_SUBITEM | commctrl.LVCF_IMAGE | commctrl.LVCF_ORDER if mask & commctrl.LVCF_TEXT: ! text_buffer = _make_empty_text_buffer(text_buf_size) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() else: ! text_addr = text_buf_size = 0 format = "iiiiiiii" buf = struct.pack(format, mask, 0, 0, ! text_addr, text_buf_size, # text 0, 0, 0) ! return array.array("b", buf), extra # List view hit-test. *************** *** 528,532 **** pt[0], pt[1], 0, 0, 0) ! return array.array("c", buf), None def UnpackLVHITTEST(buf): --- 548,552 ---- pt[0], pt[1], 0, 0, 0) ! return array.array("b", buf), None def UnpackLVHITTEST(buf): *************** *** 550,558 **** text_addr = text_len = 0 else: ! if isinstance(text, str): ! text = text.encode("mbcs") ! text_buffer = array.array("c", text+"\0") extra.append(text_buffer) ! text_addr, text_len = text_buffer.buffer_info() format = "iiiiiiiiiii" --- 570,577 ---- text_addr = text_len = 0 else: ! text_buffer = _make_text_buffer(text) extra.append(text_buffer) ! text_addr, _ = text_buffer.buffer_info() ! text_len = len(text) format = "iiiiiiiiiii" *************** *** 560,564 **** mask, cxy, text_addr, hbm, text_len, fmt, param, image, order, 0, 0) ! return array.array("c", buf), extra # Device notification stuff --- 579,583 ---- mask, cxy, text_addr, hbm, text_len, fmt, param, image, order, 0, 0) ! return array.array("b", buf), extra # Device notification stuff |