move common icon handling code to winmultiwindowicons.c set small icon for

window too
This commit is contained in:
Alexander Gottwald 2004-05-19 20:52:14 +00:00
parent 8bb17116d8
commit 5435bdb071
11 changed files with 169 additions and 114 deletions

View file

@ -1,3 +1,28 @@
2004-05-19 Alexander Gottwald <ago@freedesktop.org>
* win.h, winmultiwindowicons.c (winXIconToHICON): Takes iconsize
as parameter
* winglobals.c, winmultiwindowicons.c: Rename g_hiconX to g_hIconX.
Added new variable g_hSmallIconX for 16x16 icon.
* winwindow.h, winmultiwindowicons.c (winInitGlobalIcons): Inits the
global g_hIconX handles.
* winwindow.h, winmultiwindowicons.c (winDestroyIcon): Free the icon
without messing with the global icon handle.
* winmultiwindowicons.c (winSelectIcons): Generate a custom icon from
window settigns or set them to globals.
* winmultiwindowshape.c, winmultiwindowwindow.c, winwin32rootless.c,
winwin32rootlesswindow.c, winwin32rootlesswndproc.c: Remove
declaration of g_hiconX;
* winmultiwindowwindow.c (winCreateWindowsWindow),
winwin32rootless.c (winMWExtWMCreateFrame): Use winSelectIcons
to get the window icons. Set the small icon too.
* winmultiwindowwindow.c (winDestroyWindowsWindow),
winmultiwindowicons.c (winUpdateIcon),
winprefs.c (ReloadEnumWindowsProc),
winwin32rootlesswindow.c (winMWExtWMUpdateIcon),
winwin32rootless.c (winMWExtWMDestroyFrame): Use winDestroyIcon
to free the icon without destroying the global icon.
2004-05-17 Alexander Gottwald <ago@freedesktop.org>
* windialogs.c (winExitDlgProc, winAboutDlgProc),

View file

@ -1181,7 +1181,7 @@ winSetShapeRootless (WindowPtr pWindow);
*/
HICON
winXIconToHICON (WindowPtr pWin);
winXIconToHICON (WindowPtr pWin, int iconSize);
#ifdef XWIN_MULTIWINDOW

View file

@ -53,7 +53,8 @@ HWND g_hDlgExit = NULL;
HWND g_hDlgAbout = NULL;
const char * g_pszQueryHost = NULL;
Bool g_fXdmcpEnabled = FALSE;
HICON g_hiconX = NULL;
HICON g_hIconX = NULL;
HICON g_hSmallIconX = NULL;
char * g_pszLogFile = "/tmp/XWin.log";
int g_iLogVerbose = 2;
Bool g_fLogInited = FALSE;

View file

@ -39,7 +39,8 @@
* External global variables
*/
extern HICON g_hiconX;
extern HICON g_hIconX;
extern HICON g_hSmallIconX;
/*
@ -263,13 +264,13 @@ winScaleXBitmapToWindows (int iconSize,
*/
HICON
winXIconToHICON (WindowPtr pWin)
winXIconToHICON (WindowPtr pWin, int iconSize)
{
unsigned char *mask, *image, *imageMask;
unsigned char *dst, *src;
PixmapPtr iconPtr;
PixmapPtr maskPtr;
int iconSize, planes, bpp, effBPP, stride, maskStride, i;
int planes, bpp, effBPP, stride, maskStride, i;
HDC hDC;
ICONINFO ii;
WinXWMHints hints;
@ -282,8 +283,6 @@ winXIconToHICON (WindowPtr pWin)
if (!iconPtr) return NULL;
iconSize = 32;
hDC = GetDC (GetDesktopWindow ());
planes = GetDeviceCaps (hDC, PLANES);
bpp = GetDeviceCaps (hDC, BITSPIXEL);
@ -370,7 +369,7 @@ winUpdateIcon (Window id)
hIcon = (HICON)winOverrideIcon ((unsigned long)pWin);
if (!hIcon)
hIcon = winXIconToHICON (pWin);
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
if (hIcon)
{
@ -383,9 +382,90 @@ winUpdateIcon (Window id)
(int) hIcon);
/* Delete the icon if its not the default */
if (hiconOld != g_hiconX &&
!winIconIsOverride((unsigned long)hiconOld))
DestroyIcon (hiconOld);
winDestroyIcon(hiconOld);
}
}
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON));
if (hIcon)
{
winWindowPriv(pWin);
if (pWinPriv->hWnd)
{
hiconOld = (HICON) SetClassLong (pWinPriv->hWnd,
GCL_HICONSM,
(int) hIcon);
winDestroyIcon (hiconOld);
}
}
}
void winInitGlobalIcons (void)
{
/* Load default X icon in case it's not ready yet */
if (!g_hIconX)
{
g_hIconX = (HICON)winOverrideDefaultIcon();
g_hSmallIconX = NULL;
}
if (!g_hIconX)
{
g_hIconX = (HICON)LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON),
0);
g_hSmallIconX = (HICON)LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTSIZE);
}
}
void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon)
{
HICON hIcon, hSmallIcon;
winInitGlobalIcons();
/* Try and get the icon from WM_HINTS */
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
hSmallIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON));
/* If we got the small, but not the large one swap them */
if (!hIcon && hSmallIcon)
{
hIcon = hSmallIcon;
hSmallIcon = NULL;
}
/* Use default X icon if no icon loaded from WM_HINTS */
if (!hIcon) {
hIcon = g_hIconX;
hSmallIcon = g_hSmallIconX;
}
if (pIcon)
*pIcon = hIcon;
else
winDestroyIcon(hIcon);
if (pSmallIcon)
*pSmallIcon = hSmallIcon;
else
winDestroyIcon(hSmallIcon);
}
void winDestroyIcon(HICON hIcon)
{
/* Delete the icon if its not the default */
if (hIcon &&
hIcon != g_hIconX &&
hIcon != g_hSmallIconX &&
!winIconIsOverride((unsigned long)hIcon))
DestroyIcon (hIcon);
}

View file

@ -35,13 +35,6 @@
#include "win.h"
/*
* External global variables
*/
extern HICON g_hiconX;
/*
* winSetShapeMultiWindow - See Porting Layer Definition - p. 42
*/

View file

@ -36,14 +36,13 @@
#include "winmultiwindowclass.h"
#include "winprefs.h"
/*
* External global variables
*/
extern HICON g_hiconX;
extern HWND g_hDlgDepthChange;
extern void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon);
/*
* Prototypes for local functions
@ -464,9 +463,10 @@ winCreateWindowsWindow (WindowPtr pWin)
int iWidth;
int iHeight;
HWND hWnd;
WNDCLASS wc;
WNDCLASSEX wc;
winWindowPriv(pWin);
HICON hIcon;
HICON hIcon;
HICON hIconSmall;
#define CLASS_NAME_LENGTH 512
char pszClass[CLASS_NAME_LENGTH], pszWindowID[12];
char *res_name, *res_class, *res_role;
@ -495,23 +495,7 @@ winCreateWindowsWindow (WindowPtr pWin)
iWidth = pWin->drawable.width;
iHeight = pWin->drawable.height;
/* Load default X icon in case it's not ready yet */
if (!g_hiconX)
g_hiconX = (HICON)winOverrideDefaultIcon();
if (!g_hiconX)
g_hiconX = (HICON)LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
0, 0,
LR_DEFAULTSIZE);
/* Try and get the icon from WM_HINTS */
hIcon = winXIconToHICON (pWin);
/* Use default X icon if no icon loaded from WM_HINTS */
if (!hIcon)
hIcon = g_hiconX;
winSelectIcons(pWin, &hIcon, &hIconSmall);
/* Set standard class name prefix so we can identify window easily */
strncpy (pszClass, WINDOW_CLASS_X, sizeof(pszClass));
@ -548,17 +532,19 @@ winCreateWindowsWindow (WindowPtr pWin)
#endif
/* Setup our window class */
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = winTopLevelWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
wc.hIcon = hIcon;
wc.hIconSm = hIconSmall;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = pszClass;
RegisterClass (&wc);
RegisterClassEx (&wc);
/* Create the window */
/* Make it OVERLAPPED in create call since WS_POPUP doesn't support */
@ -613,6 +599,7 @@ winDestroyWindowsWindow (WindowPtr pWin)
MSG msg;
winWindowPriv(pWin);
HICON hiconClass;
HICON hiconSmClass;
HMODULE hInstance;
int iReturn;
char pszClass[512];
@ -628,6 +615,7 @@ winDestroyWindowsWindow (WindowPtr pWin)
/* Store the info we need to destroy after this window is gone */
hInstance = (HINSTANCE) GetClassLong (pWinPriv->hWnd, GCL_HMODULE);
hiconClass = (HICON) GetClassLong (pWinPriv->hWnd, GCL_HICON);
hiconSmClass = (HICON) GetClassLong (pWinPriv->hWnd, GCL_HICONSM);
iReturn = GetClassName (pWinPriv->hWnd, pszClass, 512);
/* Destroy the Windows window */
@ -657,15 +645,8 @@ winDestroyWindowsWindow (WindowPtr pWin)
ErrorF ("winDestroyWindowsWindow - %d Deleting Icon: ", iReturn);
#endif
/* Only delete if it's not the default */
if ((hiconClass != g_hiconX) &&
!winIconIsOverride((unsigned long)hiconClass))
{
iReturn = DestroyIcon (hiconClass);
#if CYGMULTIWINDOW_DEBUG
ErrorF ("winDestroyWindowsWindow - %d\n", iReturn);
#endif
}
winDestroyIcon(hiconClass);
winDestroyIcon(hiconSmClass);
}
#if CYGMULTIWINDOW_DEBUG

View file

@ -57,7 +57,8 @@ extern void parse_file (FILE *fp);
extern WINPREFS pref;
/* The global X default icon */
extern HICON g_hiconX;
extern HICON g_hIconX;
extern HICON g_hSmallIconX;
/* Currently in use command ID, incremented each new menu item created */
static int g_cmdid = STARTMENUID;
@ -188,9 +189,15 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam)
SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (NULL, IDI_APPLICATION));
/* If it's generated on-the-fly, get rid of it, will regen */
if (!winIconIsOverride((unsigned long)hicon) && (hicon!=g_hiconX))
DestroyIcon (hicon);
winDestroyIcon (hicon);
hicon = (HICON)GetClassLong(hwnd, GCL_HICONSM);
/* Unselect any icon in the class structure */
SetClassLong (hwnd, GCL_HICONSM, 0);
/* If it's generated on-the-fly, get rid of it, will regen */
winDestroyIcon (hicon);
/* Remove any menu additions, use bRevert flag */
GetSystemMenu (hwnd, TRUE);
@ -200,7 +207,8 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam)
else
{
/* Make the icon default, dynamic, or from xwinrc */
SetClassLong (hwnd, GCL_HICON, (LONG)g_hiconX);
SetClassLong (hwnd, GCL_HICON, (LONG)g_hIconX);
SetClassLong (hwnd, GCL_HICONSM, (LONG)g_hSmallIconX);
wid = (Window)GetProp (hwnd, WIN_WID_PROP);
if (wid)
winUpdateIcon (wid);
@ -259,8 +267,10 @@ ReloadPrefs (void)
pref.iconItems = 0;
/* Free global default X icon */
if (g_hiconX)
DestroyIcon (g_hiconX);
if (g_hIconX)
DestroyIcon (g_hIconX);
if (g_hSmallIconX)
DestroyIcon (g_hSmallIconX);
/* Reset the custom command IDs */
g_cmdid = STARTMENUID;
@ -268,15 +278,10 @@ ReloadPrefs (void)
/* Load the updated resource file */
LoadPreferences();
/* Define global icon, load it */
g_hiconX = (HICON)winOverrideDefaultIcon();
/* Use LoadImage so we get a non-shared, safe-to-kill resource */
if (!g_hiconX)
g_hiconX = (HICON)LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
0, 0,
LR_DEFAULTSIZE);
g_hIconX = NULL;
g_hSmallIconX = NULL;
winInitGlobalIcons();
#ifdef XWIN_MULTIWINDOW
/* Rebuild the icons and menus */

View file

@ -69,12 +69,7 @@ winMWExtWMSetNativeProperty (RootlessWindowPtr pFrame);
Bool g_fNoConfigureWindow = FALSE;
/*
* External global variables
*/
extern HICON g_hiconX;
extern void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon);
/*
* Internal function to get the DIB format that is compatible with the screen
@ -224,9 +219,10 @@ winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen,
#define CLASS_NAME_LENGTH 512
Bool fResult = TRUE;
win32RootlessWindowPtr pRLWinPriv;
WNDCLASS wc;
WNDCLASSEX wc;
char pszClass[CLASS_NAME_LENGTH], pszWindowID[12];
HICON hIcon;
HICON hIconSmall;
char *res_name, *res_class, *res_role;
static int s_iWindowID = 0;
@ -251,25 +247,8 @@ winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen,
// Store the implementation private frame ID
pFrame->wid = (RootlessFrameID) pRLWinPriv;
/* Load default X icon in case it's not ready yet */
if (!g_hiconX)
g_hiconX = (HICON)winOverrideDefaultIcon();
winSelectIcons(pWin, &hIcon, &hIconSmall);
if (!g_hiconX)
g_hiconX = (HICON)LoadImage (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN),
IMAGE_ICON,
0, 0,
LR_DEFAULTSIZE);
/* Try and get the icon from WM_HINTS */
hIcon = winXIconToHICON (pFrame->win);
/* Use default X icon if no icon loaded from WM_HINTS */
if (!hIcon)
hIcon = g_hiconX;
/* Set standard class name prefix so we can identify window easily */
strncpy (pszClass, WINDOW_CLASS_X, sizeof(pszClass));
@ -305,17 +284,19 @@ winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen,
#endif
/* Setup our window class */
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = winMWExtWMWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInstance;
wc.hIcon = hIcon;
wc.hIconSm = hIconSmall;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = pszClass;
RegisterClass (&wc);
RegisterClassEx (&wc);
/* Create the window */
g_fNoConfigureWindow = TRUE;
@ -383,6 +364,7 @@ winMWExtWMDestroyFrame (RootlessFrameID wid)
{
win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid;
HICON hiconClass;
HICON hiconSmClass;
HMODULE hInstance;
int iReturn;
char pszClass[CLASS_NAME_LENGTH];
@ -414,6 +396,7 @@ winMWExtWMDestroyFrame (RootlessFrameID wid)
/* Store the info we need to destroy after this window is gone */
hInstance = (HINSTANCE) GetClassLong (pRLWinPriv->hWnd, GCL_HMODULE);
hiconClass = (HICON) GetClassLong (pRLWinPriv->hWnd, GCL_HICON);
hiconSmClass = (HICON) GetClassLong (pRLWinPriv->hWnd, GCL_HICONSM);
iReturn = GetClassName (pRLWinPriv->hWnd, pszClass, CLASS_NAME_LENGTH);
pRLWinPriv->fClose = TRUE;
@ -434,15 +417,8 @@ winMWExtWMDestroyFrame (RootlessFrameID wid)
ErrorF ("winMWExtWMDestroyFramew - %d Deleting Icon: ", iReturn);
#endif
/* Only delete if it's not the default */
if ((hiconClass != g_hiconX) &&
!winIconIsOverride((unsigned long)hiconClass))
{
iReturn = DestroyIcon (hiconClass);
#if CYGMULTIWINDOW_DEBUG
ErrorF ("winMWExtWMDestroyFrame - %d\n", iReturn);
#endif
}
winDestroyIcon(hiconClass);
winDestroyIcon(hiconSmClass);
}
#if CYGMULTIWINDOW_DEBUG

View file

@ -33,14 +33,6 @@
#include "win.h"
#include "winprefs.h"
/*
* External global variables
*/
extern HICON g_hiconX;
#if 0
/*
* winMWExtWMReorderWindows
@ -173,7 +165,7 @@ winMWExtWMUpdateIcon (Window id)
hIcon = (HICON)winOverrideIcon ((unsigned long)pWin);
if (!hIcon)
hIcon = winXIconToHICON (pWin);
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
if (hIcon)
{
@ -186,10 +178,7 @@ winMWExtWMUpdateIcon (Window id)
GCL_HICON,
(int) hIcon);
/* Delete the icon if its not the default */
if (hiconOld != g_hiconX &&
!winIconIsOverride((unsigned long)hiconOld))
DestroyIcon (hiconOld);
winDestroyIcon(hiconOld);
}
}
}

View file

@ -53,7 +53,6 @@
* Global variables
*/
extern HICON g_hiconX;
extern Bool g_fNoConfigureWindow;
extern Bool g_fSoftwareCursor;

View file

@ -129,5 +129,11 @@ winMinimizeWindow (Window id);
void
winUpdateIcon (Window id);
void
winInitGlobalIcons (void);
void
winDestroyIcon(HICON hIcon);
#endif /* XWIN_MULTIWINDOW */
#endif