diff src/video/wincommon/SDL_syswm.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 720f8bb49d7d
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/video/wincommon/SDL_syswm.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/video/wincommon/SDL_syswm.c	Sun May 28 13:04:16 2006 +0000
@@ -39,22 +39,25 @@
 #endif
 
 /* The screen icon -- needs to be freed on SDL_VideoQuit() */
-HICON   screen_icn = NULL;
+HICON screen_icn = NULL;
 
 #ifdef _WIN32_WCE
 
-BOOL (WINAPI *CoreCatchInput)(int flag) = NULL;
+BOOL (WINAPI * CoreCatchInput) (int flag) = NULL;
 int input_catched = 0;
 HINSTANCE coredll = NULL;
 
 // the same API call that gx.dll does to catch the input
-void LoadInputCatchFunc()
+void
+LoadInputCatchFunc ()
 {
-	coredll = SDL_LoadObject("coredll.dll");
-	if( coredll )
-	{
-		CoreCatchInput = (int (WINAPI *)(int)) GetProcAddress(coredll, (const unsigned short *) 1453);
-	}
+    coredll = SDL_LoadObject ("coredll.dll");
+    if (coredll) {
+        CoreCatchInput =
+            (int (WINAPI *) (int)) GetProcAddress (coredll,
+                                                   (const unsigned short *)
+                                                   1453);
+    }
 }
 
 #endif
@@ -66,257 +69,267 @@
    This means that the SDL mask needs to be applied to the icon and
    then inverted and passed to Win32.
 */
-void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
+void
+WIN_SetWMIcon (_THIS, SDL_Surface * icon, Uint8 * mask)
 {
 #ifdef DISABLE_ICON_SUPPORT
-	return;
+    return;
 #else
-	SDL_Palette *pal_256;
-	SDL_Surface *icon_256;
-	Uint8 *pdata, *pwin32;
-	Uint8 *mdata, *mwin32, m = 0;
-	int icon_len;
-	int icon_plen;
-	int icon_mlen;
-	int icon_pitch;
-	int mask_pitch;
-	SDL_Rect bounds;
-	int i, skip;
-	int row, col;
-	struct /* quasi-BMP format */ Win32Icon {
-		Uint32 biSize;
-		Sint32 biWidth;
-		Sint32 biHeight;
-		Uint16 biPlanes;
-		Uint16 biBitCount;
-		Uint32 biCompression;
-		Uint32 biSizeImage;
-		Sint32 biXPelsPerMeter;
-		Sint32 biYPelsPerMeter;
-		Uint32 biClrUsed;
-		Uint32 biClrImportant;
-		struct /* RGBQUAD -- note it's BGR ordered */ {
-			Uint8 rgbBlue;
-			Uint8 rgbGreen;
-			Uint8 rgbRed;
-			Uint8 rgbReserved;
-		} biColors[256];
-		/* Pixels:
-		Uint8 pixels[]
-		*/
-		/* Mask:
-		Uint8 mask[]
-		*/
-	} *icon_win32;
-	
-	/* Allocate the win32 bmp icon and set everything to zero */
-	icon_pitch = ((icon->w+3)&~3);
-	mask_pitch = ((icon->w+7)/8);
-	icon_plen = icon->h*icon_pitch;
-	icon_mlen = icon->h*mask_pitch;
-	icon_len = sizeof(*icon_win32)+icon_plen+icon_mlen;
-	icon_win32 = (struct Win32Icon *)SDL_stack_alloc(Uint8, icon_len);
-	if ( icon_win32 == NULL ) {
-		return;
-	}
-	SDL_memset(icon_win32, 0, icon_len);
+    SDL_Palette *pal_256;
+    SDL_Surface *icon_256;
+    Uint8 *pdata, *pwin32;
+    Uint8 *mdata, *mwin32, m = 0;
+    int icon_len;
+    int icon_plen;
+    int icon_mlen;
+    int icon_pitch;
+    int mask_pitch;
+    SDL_Rect bounds;
+    int i, skip;
+    int row, col;
+    struct /* quasi-BMP format */ Win32Icon
+    {
+        Uint32 biSize;
+        Sint32 biWidth;
+        Sint32 biHeight;
+        Uint16 biPlanes;
+        Uint16 biBitCount;
+        Uint32 biCompression;
+        Uint32 biSizeImage;
+        Sint32 biXPelsPerMeter;
+        Sint32 biYPelsPerMeter;
+        Uint32 biClrUsed;
+        Uint32 biClrImportant;
+        struct                  /* RGBQUAD -- note it's BGR ordered */
+        {
+            Uint8 rgbBlue;
+            Uint8 rgbGreen;
+            Uint8 rgbRed;
+            Uint8 rgbReserved;
+        } biColors[256];
+        /* Pixels:
+           Uint8 pixels[]
+         */
+        /* Mask:
+           Uint8 mask[]
+         */
+    } *icon_win32;
 
-	/* Set the basic BMP parameters */
-	icon_win32->biSize = sizeof(*icon_win32)-sizeof(icon_win32->biColors);
-	icon_win32->biWidth = icon->w;
-	icon_win32->biHeight = icon->h*2;
-	icon_win32->biPlanes = 1;
-	icon_win32->biBitCount = 8;
-	icon_win32->biSizeImage = icon_plen+icon_mlen;
+    /* Allocate the win32 bmp icon and set everything to zero */
+    icon_pitch = ((icon->w + 3) & ~3);
+    mask_pitch = ((icon->w + 7) / 8);
+    icon_plen = icon->h * icon_pitch;
+    icon_mlen = icon->h * mask_pitch;
+    icon_len = sizeof (*icon_win32) + icon_plen + icon_mlen;
+    icon_win32 = (struct Win32Icon *) SDL_stack_alloc (Uint8, icon_len);
+    if (icon_win32 == NULL) {
+        return;
+    }
+    SDL_memset (icon_win32, 0, icon_len);
+
+    /* Set the basic BMP parameters */
+    icon_win32->biSize = sizeof (*icon_win32) - sizeof (icon_win32->biColors);
+    icon_win32->biWidth = icon->w;
+    icon_win32->biHeight = icon->h * 2;
+    icon_win32->biPlanes = 1;
+    icon_win32->biBitCount = 8;
+    icon_win32->biSizeImage = icon_plen + icon_mlen;
 
-	/* Allocate a standard 256 color icon surface */
-	icon_256 = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
-					 icon_win32->biBitCount, 0, 0, 0, 0);
-	if ( icon_256 == NULL ) {
-		SDL_stack_free(icon_win32);
-		return;
-	}
-	pal_256 = icon_256->format->palette;
-	if (icon->format->palette && 
-		(icon->format->BitsPerPixel == icon_256->format->BitsPerPixel)){
-		Uint8 black;
-		SDL_memcpy(pal_256->colors, icon->format->palette->colors,
-					pal_256->ncolors*sizeof(SDL_Color));
-		/* Make sure that 0 is black! */
-		black = SDL_FindColor(pal_256, 0x00, 0x00, 0x00);
-		pal_256->colors[black] = pal_256->colors[0];
-		pal_256->colors[0].r = 0x00;
-		pal_256->colors[0].g = 0x00;
-		pal_256->colors[0].b = 0x00;
-	} else {
-		SDL_DitherColors(pal_256->colors,
-					icon_256->format->BitsPerPixel);
-	}
+    /* Allocate a standard 256 color icon surface */
+    icon_256 = SDL_CreateRGBSurface (SDL_SWSURFACE, icon->w, icon->h,
+                                     icon_win32->biBitCount, 0, 0, 0, 0);
+    if (icon_256 == NULL) {
+        SDL_stack_free (icon_win32);
+        return;
+    }
+    pal_256 = icon_256->format->palette;
+    if (icon->format->palette &&
+        (icon->format->BitsPerPixel == icon_256->format->BitsPerPixel)) {
+        Uint8 black;
+        SDL_memcpy (pal_256->colors, icon->format->palette->colors,
+                    pal_256->ncolors * sizeof (SDL_Color));
+        /* Make sure that 0 is black! */
+        black = SDL_FindColor (pal_256, 0x00, 0x00, 0x00);
+        pal_256->colors[black] = pal_256->colors[0];
+        pal_256->colors[0].r = 0x00;
+        pal_256->colors[0].g = 0x00;
+        pal_256->colors[0].b = 0x00;
+    } else {
+        SDL_DitherColors (pal_256->colors, icon_256->format->BitsPerPixel);
+    }
 
-	/* Now copy color data to the icon BMP */
-	for ( i=0; i<(1<<icon_win32->biBitCount); ++i ) {
-		icon_win32->biColors[i].rgbRed = pal_256->colors[i].r;
-		icon_win32->biColors[i].rgbGreen = pal_256->colors[i].g;
-		icon_win32->biColors[i].rgbBlue = pal_256->colors[i].b;
-	}
+    /* Now copy color data to the icon BMP */
+    for (i = 0; i < (1 << icon_win32->biBitCount); ++i) {
+        icon_win32->biColors[i].rgbRed = pal_256->colors[i].r;
+        icon_win32->biColors[i].rgbGreen = pal_256->colors[i].g;
+        icon_win32->biColors[i].rgbBlue = pal_256->colors[i].b;
+    }
 
-	/* Convert icon to a standard surface format.  This may not always
-	   be necessary, as Windows supports a variety of BMP formats, but
-	   it greatly simplifies our code.
-	*/ 
+    /* Convert icon to a standard surface format.  This may not always
+       be necessary, as Windows supports a variety of BMP formats, but
+       it greatly simplifies our code.
+     */
     bounds.x = 0;
     bounds.y = 0;
     bounds.w = icon->w;
     bounds.h = icon->h;
-    if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) {
-	    SDL_stack_free(icon_win32);
-		SDL_FreeSurface(icon_256);
+    if (SDL_LowerBlit (icon, &bounds, icon_256, &bounds) < 0) {
+        SDL_stack_free (icon_win32);
+        SDL_FreeSurface (icon_256);
         return;
-	}
+    }
 
-	/* Copy pixels upside-down to icon BMP, masked with the icon mask */
-	if ( SDL_MUSTLOCK(icon_256) || (icon_256->pitch != icon_pitch) ) {
-		SDL_stack_free(icon_win32);
-		SDL_FreeSurface(icon_256);
-		SDL_SetError("Warning: Unexpected icon_256 characteristics");
-		return;
-	}
-	pdata = (Uint8 *)icon_256->pixels;
-	mdata = mask;
-	pwin32 = (Uint8 *)icon_win32+sizeof(*icon_win32)+icon_plen-icon_pitch;
-	skip = icon_pitch - icon->w;
-	for ( row=0; row<icon->h; ++row ) {
-		for ( col=0; col<icon->w; ++col ) {
-			if ( (col%8) == 0 ) {
-				m = *mdata++;
-			}
-			if ( (m&0x80) != 0x00 ) {
-				*pwin32 = *pdata;
-			}
-			m <<= 1;
-			++pdata;
-			++pwin32;
-		}
-		pdata  += skip;
-		pwin32 += skip;
-		pwin32 -= 2*icon_pitch;
-	}
-	SDL_FreeSurface(icon_256);
+    /* Copy pixels upside-down to icon BMP, masked with the icon mask */
+    if (SDL_MUSTLOCK (icon_256) || (icon_256->pitch != icon_pitch)) {
+        SDL_stack_free (icon_win32);
+        SDL_FreeSurface (icon_256);
+        SDL_SetError ("Warning: Unexpected icon_256 characteristics");
+        return;
+    }
+    pdata = (Uint8 *) icon_256->pixels;
+    mdata = mask;
+    pwin32 =
+        (Uint8 *) icon_win32 + sizeof (*icon_win32) + icon_plen - icon_pitch;
+    skip = icon_pitch - icon->w;
+    for (row = 0; row < icon->h; ++row) {
+        for (col = 0; col < icon->w; ++col) {
+            if ((col % 8) == 0) {
+                m = *mdata++;
+            }
+            if ((m & 0x80) != 0x00) {
+                *pwin32 = *pdata;
+            }
+            m <<= 1;
+            ++pdata;
+            ++pwin32;
+        }
+        pdata += skip;
+        pwin32 += skip;
+        pwin32 -= 2 * icon_pitch;
+    }
+    SDL_FreeSurface (icon_256);
 
-	/* Copy mask inverted and upside-down to icon BMP */
-	mdata = mask;
-	mwin32 = (Uint8 *)icon_win32
-			+sizeof(*icon_win32)+icon_plen+icon_mlen-mask_pitch;
-	for ( row=0; row<icon->h; ++row ) {
-		for ( col=0; col<mask_pitch; ++col ) {
-			*mwin32++ = ~*mdata++;
-		}
-		mwin32 -= 2*mask_pitch;
-	}
+    /* Copy mask inverted and upside-down to icon BMP */
+    mdata = mask;
+    mwin32 = (Uint8 *) icon_win32
+        + sizeof (*icon_win32) + icon_plen + icon_mlen - mask_pitch;
+    for (row = 0; row < icon->h; ++row) {
+        for (col = 0; col < mask_pitch; ++col) {
+            *mwin32++ = ~*mdata++;
+        }
+        mwin32 -= 2 * mask_pitch;
+    }
 
-	/* Finally, create the icon handle and set the window icon */
-	screen_icn = CreateIconFromResourceEx((Uint8 *)icon_win32, icon_len,
-			TRUE, 0x00030000, icon->w, icon->h, LR_DEFAULTCOLOR);
-	if ( screen_icn == NULL ) {
-		SDL_SetError("Couldn't create Win32 icon handle");
-	} else {
-		SetClassLongPtr(SDL_Window, GCLP_HICON, (LONG_PTR)screen_icn);
-	}
-	SDL_stack_free(icon_win32);
+    /* Finally, create the icon handle and set the window icon */
+    screen_icn = CreateIconFromResourceEx ((Uint8 *) icon_win32, icon_len,
+                                           TRUE, 0x00030000, icon->w, icon->h,
+                                           LR_DEFAULTCOLOR);
+    if (screen_icn == NULL) {
+        SDL_SetError ("Couldn't create Win32 icon handle");
+    } else {
+        SetClassLongPtr (SDL_Window, GCLP_HICON, (LONG_PTR) screen_icn);
+    }
+    SDL_stack_free (icon_win32);
 #endif /* DISABLE_ICON_SUPPORT */
 }
 
-void WIN_SetWMCaption(_THIS, const char *title, const char *icon)
+void
+WIN_SetWMCaption (_THIS, const char *title, const char *icon)
 {
 #ifdef _WIN32_WCE
-	/* WinCE uses the UNICODE version */
-	LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title);
-	SetWindowText(SDL_Window, lpszW);
-	SDL_free(lpszW);
+    /* WinCE uses the UNICODE version */
+    LPWSTR lpszW = SDL_iconv_utf8_ucs2 ((char *) title);
+    SetWindowText (SDL_Window, lpszW);
+    SDL_free (lpszW);
 #else
-	char *lpsz = SDL_iconv_utf8_latin1((char *)title);
-	SetWindowText(SDL_Window, lpsz);
-	SDL_free(lpsz);
+    char *lpsz = SDL_iconv_utf8_latin1 ((char *) title);
+    SetWindowText (SDL_Window, lpsz);
+    SDL_free (lpsz);
 #endif
 }
 
-int WIN_IconifyWindow(_THIS)
+int
+WIN_IconifyWindow (_THIS)
 {
-	ShowWindow(SDL_Window, SW_MINIMIZE);
-	return(1);
+    ShowWindow (SDL_Window, SW_MINIMIZE);
+    return (1);
 }
 
-SDL_GrabMode WIN_GrabInput(_THIS, SDL_GrabMode mode)
+SDL_GrabMode
+WIN_GrabInput (_THIS, SDL_GrabMode mode)
 {
-	if ( mode == SDL_GRAB_OFF ) {
-		ClipCursor(NULL);
-		if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) {
-		/*	RJR: March 28, 2000
-			must be leaving relative mode, move mouse from
-			center of window to where it belongs ... */
-			POINT pt;
-			int x, y;
-			SDL_GetMouseState(&x,&y);
-			pt.x = x;
-			pt.y = y;
-			ClientToScreen(SDL_Window, &pt);
-			SetCursorPos(pt.x,pt.y);
-		}
+    if (mode == SDL_GRAB_OFF) {
+        ClipCursor (NULL);
+        if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
+            /*      RJR: March 28, 2000
+               must be leaving relative mode, move mouse from
+               center of window to where it belongs ... */
+            POINT pt;
+            int x, y;
+            SDL_GetMouseState (&x, &y);
+            pt.x = x;
+            pt.y = y;
+            ClientToScreen (SDL_Window, &pt);
+            SetCursorPos (pt.x, pt.y);
+        }
 #ifdef _WIN32_WCE
-		if( input_catched )
-		{
-			if( !CoreCatchInput ) LoadInputCatchFunc();
+        if (input_catched) {
+            if (!CoreCatchInput)
+                LoadInputCatchFunc ();
 
-			if( CoreCatchInput )
-				CoreCatchInput(0);
-		}
+            if (CoreCatchInput)
+                CoreCatchInput (0);
+        }
 #endif
-	} else {
-		ClipCursor(&SDL_bounds);
-		if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) {
-		/*	RJR: March 28, 2000
-			must be entering relative mode, get ready by
-			moving mouse to	center of window ... */
-			POINT pt;
-			pt.x = (SDL_VideoSurface->w/2);
-			pt.y = (SDL_VideoSurface->h/2);
-			ClientToScreen(SDL_Window, &pt);
-			SetCursorPos(pt.x, pt.y);
-		}
+    } else {
+        ClipCursor (&SDL_bounds);
+        if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
+            /*      RJR: March 28, 2000
+               must be entering relative mode, get ready by
+               moving mouse to      center of window ... */
+            POINT pt;
+            pt.x = (SDL_VideoSurface->w / 2);
+            pt.y = (SDL_VideoSurface->h / 2);
+            ClientToScreen (SDL_Window, &pt);
+            SetCursorPos (pt.x, pt.y);
+        }
 #ifdef _WIN32_WCE
-		if( !input_catched )
-		{
-			if( !CoreCatchInput ) LoadInputCatchFunc();
+        if (!input_catched) {
+            if (!CoreCatchInput)
+                LoadInputCatchFunc ();
 
-			if( CoreCatchInput )
-				CoreCatchInput(1);
-		}
+            if (CoreCatchInput)
+                CoreCatchInput (1);
+        }
 #endif
-	}
-	return(mode);
+    }
+    return (mode);
 }
 
 /* If 'info' is the right version, this function fills it and returns 1.
    Otherwise, in case of a version mismatch, it returns -1.
 */
-int WIN_GetWMInfo(_THIS, SDL_SysWMinfo *info)
+int
+WIN_GetWMInfo (_THIS, SDL_SysWMinfo * info)
 {
-	if ( info->version.major <= SDL_MAJOR_VERSION ) {
-		info->window = SDL_Window;
-		if ( SDL_VERSIONNUM(info->version.major,
-		                    info->version.minor,
-		                    info->version.patch) >=
-		     SDL_VERSIONNUM(1, 2, 5) ) {
+    if (info->version.major <= SDL_MAJOR_VERSION) {
+        info->window = SDL_Window;
+        if (SDL_VERSIONNUM (info->version.major,
+                            info->version.minor,
+                            info->version.patch) >=
+            SDL_VERSIONNUM (1, 2, 5)) {
 #if SDL_VIDEO_OPENGL
-			info->hglrc = GL_hrc;
+            info->hglrc = GL_hrc;
 #else
-			info->hglrc = NULL;
+            info->hglrc = NULL;
 #endif
-		}
-		return(1);
-	} else {
-		SDL_SetError("Application not compiled with SDL %d.%d\n",
-					SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
-		return(-1);
-	}
+        }
+        return (1);
+    } else {
+        SDL_SetError ("Application not compiled with SDL %d.%d\n",
+                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+        return (-1);
+    }
 }
+
+/* vi: set ts=4 sw=4 expandtab: */