summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2004-05-19 20:52:14 +0000
committerAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2004-05-19 20:52:14 +0000
commit5435bdb071b487f2c021bc308188ab9ff6081f89 (patch)
tree9ae7714b19c9ee1f9b31521326ff9b1c09224fda
parent8bb17116d8164fae702d806ee58b030b88ccc16e (diff)
move common icon handling code to winmultiwindowicons.c set small icon for
window too
-rw-r--r--hw/xwin/ChangeLog25
-rw-r--r--hw/xwin/win.h2
-rw-r--r--hw/xwin/winglobals.c3
-rwxr-xr-xhw/xwin/winmultiwindowicons.c98
-rwxr-xr-xhw/xwin/winmultiwindowshape.c7
-rw-r--r--hw/xwin/winmultiwindowwindow.c43
-rw-r--r--hw/xwin/winprefs.c37
-rwxr-xr-xhw/xwin/winwin32rootless.c46
-rwxr-xr-xhw/xwin/winwin32rootlesswindow.c15
-rwxr-xr-xhw/xwin/winwin32rootlesswndproc.c1
-rw-r--r--hw/xwin/winwindow.h6
11 files changed, 169 insertions, 114 deletions
diff --git a/hw/xwin/ChangeLog b/hw/xwin/ChangeLog
index 26b12f249..3ec1fb319 100644
--- a/hw/xwin/ChangeLog
+++ b/hw/xwin/ChangeLog
@@ -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),
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 4aa1c7643..54ddae354 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -1181,7 +1181,7 @@ winSetShapeRootless (WindowPtr pWindow);
*/
HICON
-winXIconToHICON (WindowPtr pWin);
+winXIconToHICON (WindowPtr pWin, int iconSize);
#ifdef XWIN_MULTIWINDOW
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 6a7f889cf..da83b171a 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -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;
diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c
index a1fefbafe..9865f0e58 100755
--- a/hw/xwin/winmultiwindowicons.c
+++ b/hw/xwin/winmultiwindowicons.c
@@ -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);
}
diff --git a/hw/xwin/winmultiwindowshape.c b/hw/xwin/winmultiwindowshape.c
index be335fe32..bfec1a1ea 100755
--- a/hw/xwin/winmultiwindowshape.c
+++ b/hw/xwin/winmultiwindowshape.c
@@ -36,13 +36,6 @@
/*
- * External global variables
- */
-
-extern HICON g_hiconX;
-
-
-/*
* winSetShapeMultiWindow - See Porting Layer Definition - p. 42
*/
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index 6dd526d6a..2d7ae1176 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -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
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index 60eb17281..83adf173e 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -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 */
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index ae2e12073..f65d57c8d 100755
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -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();
-
- if (!g_hiconX)
- g_hiconX = (HICON)LoadImage (g_hInstance,
- MAKEINTRESOURCE(IDI_XWIN),
- IMAGE_ICON,
- 0, 0,
- LR_DEFAULTSIZE);
+ winSelectIcons(pWin, &hIcon, &hIconSmall);
- /* 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
diff --git a/hw/xwin/winwin32rootlesswindow.c b/hw/xwin/winwin32rootlesswindow.c
index 692c0cfaf..eedfe2f0c 100755
--- a/hw/xwin/winwin32rootlesswindow.c
+++ b/hw/xwin/winwin32rootlesswindow.c
@@ -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);
}
}
}
diff --git a/hw/xwin/winwin32rootlesswndproc.c b/hw/xwin/winwin32rootlesswndproc.c
index e6fb2944a..ede83d055 100755
--- a/hw/xwin/winwin32rootlesswndproc.c
+++ b/hw/xwin/winwin32rootlesswndproc.c
@@ -53,7 +53,6 @@
* Global variables
*/
-extern HICON g_hiconX;
extern Bool g_fNoConfigureWindow;
extern Bool g_fSoftwareCursor;
diff --git a/hw/xwin/winwindow.h b/hw/xwin/winwindow.h
index 53cf9d813..50d5f01fb 100644
--- a/hw/xwin/winwindow.h
+++ b/hw/xwin/winwindow.h
@@ -129,5 +129,11 @@ winMinimizeWindow (Window id);
void
winUpdateIcon (Window id);
+void
+winInitGlobalIcons (void);
+
+void
+winDestroyIcon(HICON hIcon);
+
#endif /* XWIN_MULTIWINDOW */
#endif