diff options
author | fvogel <fvogelnew1@free.fr> | 2020-11-08 13:46:37 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2020-11-08 13:46:37 (GMT) |
commit | 14635cf721890ec922b5b34f333ac5ac93346c9c (patch) | |
tree | bba45650776ea6e5c3ba381bce5ecfebb20288f5 /win | |
parent | b0a82cca7d1314476ae7fe568baa8e06358554a5 (diff) | |
download | tk-14635cf721890ec922b5b34f333ac5ac93346c9c.zip tk-14635cf721890ec922b5b34f333ac5ac93346c9c.tar.gz tk-14635cf721890ec922b5b34f333ac5ac93346c9c.tar.bz2 |
Remove duplicate code.
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinIco.c | 64 | ||||
-rw-r--r-- | win/tkWinIco.h | 4 | ||||
-rw-r--r-- | win/tkWinSysTray.c | 21 | ||||
-rw-r--r-- | win/tkWinWm.c | 40 |
4 files changed, 58 insertions, 71 deletions
diff --git a/win/tkWinIco.c b/win/tkWinIco.c index f23d619..039a680 100644 --- a/win/tkWinIco.c +++ b/win/tkWinIco.c @@ -13,7 +13,6 @@ #include "tkWinIco.h" - /* *---------------------------------------------------------------------- * @@ -54,7 +53,7 @@ DIBNumColors( return 0; } } - + /* *---------------------------------------------------------------------- * @@ -74,7 +73,7 @@ PaletteSize( { return (WORD) (DIBNumColors(lpbi) * sizeof(RGBQUAD)); } - + /* *---------------------------------------------------------------------- * @@ -98,7 +97,7 @@ FindDIBBits( { return lpbi + *((LPDWORD) lpbi) + PaletteSize(lpbi); } - + /* *---------------------------------------------------------------------- * @@ -120,8 +119,7 @@ BytesPerLine( { return WIDTHBYTES(lpBMIH->biWidth * lpBMIH->biPlanes * lpBMIH->biBitCount); } - - + /* *---------------------------------------------------------------------- * @@ -189,7 +187,61 @@ AdjustIconImagePointers( lpImage->Height*BytesPerLine((LPBITMAPINFOHEADER) lpImage->lpbi); return TRUE; } + +/* + *---------------------------------------------------------------------- + * + * ReadICOHeader -- + * + * Reads the header from an ICO file, as specfied by channel. + * + * Results: + * UINT - Number of images in file, -1 for failure. If this succeeds, + * there is a decent chance this is a valid icon file. + * + *---------------------------------------------------------------------- + */ + +static int +ReadICOHeader( + Tcl_Channel channel) +{ + union { + WORD word; + char bytes[sizeof(WORD)]; + } input; + /* + * Read the 'reserved' WORD, which should be a zero word. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + if (input.word != 0) { + return -1; + } + + /* + * Read the type WORD, which should be of type 1. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + if (input.word != 1) { + return -1; + } + + /* + * Get and return the count of images. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + return (int) input.word; +} /* * Local Variables: diff --git a/win/tkWinIco.h b/win/tkWinIco.h index 3f4bfb6..a76067d 100644 --- a/win/tkWinIco.h +++ b/win/tkWinIco.h @@ -74,25 +74,21 @@ typedef struct { ICONDIRENTRY idEntries[1]; /* The entries for each image */ } ICONDIR, *LPICONDIR; - /* * Used in BytesPerLine */ #define WIDTHBYTES(bits) ((((bits) + 31)>>5)<<2) - /* * The following are implemented in tkWinIco.c and also used in tkWinWm.c and tkWinSysTray.c. */ - DWORD BytesPerLine(LPBITMAPINFOHEADER lpBMIH); LPSTR FindDIBBits(LPSTR lpbi); WORD PaletteSize(LPSTR lpbi); WORD DIBNumColors(LPSTR lpbi); int ReadICOHeader(Tcl_Channel channel); - /* * Local Variables: diff --git a/win/tkWinSysTray.c b/win/tkWinSysTray.c index 63e50aa..5906e72 100644 --- a/win/tkWinSysTray.c +++ b/win/tkWinSysTray.c @@ -300,27 +300,6 @@ DrawANDMask(HDC hDC, RECT Rect, LPLPICONIMAGE lpIcon) { /* *---------------------------------------------------------------------- * - * FindDIBBits -- - * - * Locate the image bits in a CF_DIB format DIB. - * - * Results: - * Icon is rendered. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static LPSTR -FindDIBBits(LPSTR lpbi) { - return (lpbi + * (LPDWORD) lpbi + PaletteSize(lpbi)); -} - -/* - *---------------------------------------------------------------------- - * * NotifyA -- * * Display icon in system tray on older ANSI-encoded systems. diff --git a/win/tkWinWm.c b/win/tkWinWm.c index 911291d..739f5f4 100644 --- a/win/tkWinWm.c +++ b/win/tkWinWm.c @@ -500,47 +500,7 @@ static void WmUpdateGeom(WmInfo *wmPtr, TkWindow *winPtr); #define WIDTHBYTES(bits) ((((bits) + 31)>>5)<<2) -/* - *---------------------------------------------------------------------- - * - * DIBNumColors -- - * - * Calculates the number of entries in the color table, given by LPSTR - * lpbi - pointer to the CF_DIB memory block. Used by titlebar icon code. - * - * Results: - * WORD - Number of entries in the color table. - * - *---------------------------------------------------------------------- - */ - -static WORD -DIBNumColors( - LPSTR lpbi) -{ - WORD wBitCount; - DWORD dwClrUsed; - - dwClrUsed = ((LPBITMAPINFOHEADER) lpbi)->biClrUsed; - - if (dwClrUsed) { - return (WORD) dwClrUsed; - } - - wBitCount = ((LPBITMAPINFOHEADER) lpbi)->biBitCount; - switch (wBitCount) { - case 1: - return 2; - case 4: - return 16; - case 8: - return 256; - default: - return 0; - } -} - /* *---------------------------------------------------------------------- * |