src/video/macrom/SDL_romvideo.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/src/video/macrom/SDL_romvideo.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/macrom/SDL_romvideo.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -53,24 +53,26 @@
     1.4  #include "../maccommon/SDL_macevents_c.h"
     1.5  
     1.6  /* Initialization/Query functions */
     1.7 -static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat);
     1.8 -static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
     1.9 -static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    1.10 -static int ROM_SetColors(_THIS, int firstcolor, int ncolors,
    1.11 -			 SDL_Color *colors);
    1.12 -static void ROM_VideoQuit(_THIS);
    1.13 +static int ROM_VideoInit (_THIS, SDL_PixelFormat * vformat);
    1.14 +static SDL_Rect **ROM_ListModes (_THIS, SDL_PixelFormat * format,
    1.15 +                                 Uint32 flags);
    1.16 +static SDL_Surface *ROM_SetVideoMode (_THIS, SDL_Surface * current, int width,
    1.17 +                                      int height, int bpp, Uint32 flags);
    1.18 +static int ROM_SetColors (_THIS, int firstcolor, int ncolors,
    1.19 +                          SDL_Color * colors);
    1.20 +static void ROM_VideoQuit (_THIS);
    1.21  
    1.22  /* Hardware surface functions */
    1.23 -static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface);
    1.24 -static int ROM_LockHWSurface(_THIS, SDL_Surface *surface);
    1.25 -static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface);
    1.26 -static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface);
    1.27 +static int ROM_AllocHWSurface (_THIS, SDL_Surface * surface);
    1.28 +static int ROM_LockHWSurface (_THIS, SDL_Surface * surface);
    1.29 +static void ROM_UnlockHWSurface (_THIS, SDL_Surface * surface);
    1.30 +static void ROM_FreeHWSurface (_THIS, SDL_Surface * surface);
    1.31  
    1.32 -#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
    1.33 +#if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
    1.34  /* Saved state for the menu bar */
    1.35 -static RgnHandle	gSaveGrayRgn = nil;
    1.36 -static short		gSaveMenuBar = 0;
    1.37 -static Boolean		gSaveCSVis = true;
    1.38 +static RgnHandle gSaveGrayRgn = nil;
    1.39 +static short gSaveMenuBar = 0;
    1.40 +static Boolean gSaveCSVis = true;
    1.41  
    1.42  #if powerc
    1.43  /* Mixed mode glue to activate the 68K emulator and twiddle a register */
    1.44 @@ -87,648 +89,674 @@
    1.45  		  0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
    1.46  
    1.47  /* ControlStrip inline glue for PowerPC */
    1.48 -static pascal Boolean SBIsControlStripVisible(void)
    1.49 +static pascal Boolean
    1.50 +SBIsControlStripVisible (void)
    1.51  {
    1.52 -	static short procData[] = TWOWORDSTUB(0x7000, 0xAAF2);
    1.53 -	ProcInfoType procInfo = kD0DispatchedPascalStackBased
    1.54 -				| RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
    1.55 -            	| DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode);
    1.56 -            				
    1.57 -	return((Boolean) CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x00));
    1.58 +    static short procData[] = TWOWORDSTUB (0x7000, 0xAAF2);
    1.59 +    ProcInfoType procInfo = kD0DispatchedPascalStackBased
    1.60 +        | RESULT_SIZE (SIZE_CODE (sizeof (Boolean)))
    1.61 +        | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode);
    1.62 +
    1.63 +    return ((Boolean)
    1.64 +            CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x00));
    1.65  }
    1.66  
    1.67 -static pascal void SBShowHideControlStrip(Boolean showIt)
    1.68 +static pascal void
    1.69 +SBShowHideControlStrip (Boolean showIt)
    1.70  {
    1.71 -	static short procData[] = THREEWORDSTUB(0x303C, 0x0101, 0xAAF2);
    1.72 -	ProcInfoType procInfo = kD0DispatchedPascalStackBased
    1.73 -				| DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
    1.74 -				| DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Boolean)));
    1.75 +    static short procData[] = THREEWORDSTUB (0x303C, 0x0101, 0xAAF2);
    1.76 +    ProcInfoType procInfo = kD0DispatchedPascalStackBased
    1.77 +        | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode)
    1.78 +        | DISPATCHED_STACK_ROUTINE_PARAMETER (1,
    1.79 +                                              SIZE_CODE (sizeof (Boolean)));
    1.80  
    1.81 -	CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x01, showIt);
    1.82 +    CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x01, showIt);
    1.83  }
    1.84  #endif /* powerc */
    1.85  #endif /* !TARGET_API_MAC_CARBON */
    1.86  
    1.87  /* Macintosh toolbox driver bootstrap functions */
    1.88  
    1.89 -static int ROM_Available(void)
    1.90 +static int
    1.91 +ROM_Available (void)
    1.92  {
    1.93 -	return(1);
    1.94 +    return (1);
    1.95  }
    1.96  
    1.97 -static void ROM_DeleteDevice(SDL_VideoDevice *device)
    1.98 +static void
    1.99 +ROM_DeleteDevice (SDL_VideoDevice * device)
   1.100  {
   1.101 -	SDL_free(device->hidden);
   1.102 -	SDL_free(device);
   1.103 +    SDL_free (device->hidden);
   1.104 +    SDL_free (device);
   1.105  }
   1.106  
   1.107 -static SDL_VideoDevice *ROM_CreateDevice(int devindex)
   1.108 +static SDL_VideoDevice *
   1.109 +ROM_CreateDevice (int devindex)
   1.110  {
   1.111 -	SDL_VideoDevice *device;
   1.112 +    SDL_VideoDevice *device;
   1.113  
   1.114 -	/* Initialize all variables that we clean on shutdown */
   1.115 -	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   1.116 -	if ( device ) {
   1.117 -		SDL_memset(device, 0, (sizeof *device));
   1.118 -		device->hidden = (struct SDL_PrivateVideoData *)
   1.119 -				SDL_malloc((sizeof *device->hidden));
   1.120 -	}
   1.121 -	if ( (device == NULL) || (device->hidden == NULL) ) {
   1.122 -		SDL_OutOfMemory();
   1.123 -		if ( device ) {
   1.124 -			SDL_free(device);
   1.125 -		}
   1.126 -		return(0);
   1.127 -	}
   1.128 -	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   1.129 +    /* Initialize all variables that we clean on shutdown */
   1.130 +    device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
   1.131 +    if (device) {
   1.132 +        SDL_memset (device, 0, (sizeof *device));
   1.133 +        device->hidden = (struct SDL_PrivateVideoData *)
   1.134 +            SDL_malloc ((sizeof *device->hidden));
   1.135 +    }
   1.136 +    if ((device == NULL) || (device->hidden == NULL)) {
   1.137 +        SDL_OutOfMemory ();
   1.138 +        if (device) {
   1.139 +            SDL_free (device);
   1.140 +        }
   1.141 +        return (0);
   1.142 +    }
   1.143 +    SDL_memset (device->hidden, 0, (sizeof *device->hidden));
   1.144  
   1.145 -	/* Set the function pointers */
   1.146 -	device->VideoInit = ROM_VideoInit;
   1.147 -	device->ListModes = ROM_ListModes;
   1.148 -	device->SetVideoMode = ROM_SetVideoMode;
   1.149 -	device->SetColors = ROM_SetColors;
   1.150 -	device->UpdateRects = NULL;
   1.151 -	device->VideoQuit = ROM_VideoQuit;
   1.152 -	device->AllocHWSurface = ROM_AllocHWSurface;
   1.153 -	device->CheckHWBlit = NULL;
   1.154 -	device->FillHWRect = NULL;
   1.155 -	device->SetHWColorKey = NULL;
   1.156 -	device->SetHWAlpha = NULL;
   1.157 -	device->LockHWSurface = ROM_LockHWSurface;
   1.158 -	device->UnlockHWSurface = ROM_UnlockHWSurface;
   1.159 -	device->FlipHWSurface = NULL;
   1.160 -	device->FreeHWSurface = ROM_FreeHWSurface;
   1.161 +    /* Set the function pointers */
   1.162 +    device->VideoInit = ROM_VideoInit;
   1.163 +    device->ListModes = ROM_ListModes;
   1.164 +    device->SetVideoMode = ROM_SetVideoMode;
   1.165 +    device->SetColors = ROM_SetColors;
   1.166 +    device->UpdateRects = NULL;
   1.167 +    device->VideoQuit = ROM_VideoQuit;
   1.168 +    device->AllocHWSurface = ROM_AllocHWSurface;
   1.169 +    device->CheckHWBlit = NULL;
   1.170 +    device->FillHWRect = NULL;
   1.171 +    device->SetHWColorKey = NULL;
   1.172 +    device->SetHWAlpha = NULL;
   1.173 +    device->LockHWSurface = ROM_LockHWSurface;
   1.174 +    device->UnlockHWSurface = ROM_UnlockHWSurface;
   1.175 +    device->FlipHWSurface = NULL;
   1.176 +    device->FreeHWSurface = ROM_FreeHWSurface;
   1.177  #if SDL_VIDEO_OPENGL
   1.178 -	device->GL_MakeCurrent = Mac_GL_MakeCurrent;
   1.179 -	device->GL_SwapBuffers = Mac_GL_SwapBuffers;
   1.180 -	device->GL_LoadLibrary = Mac_GL_LoadLibrary;
   1.181 -	device->GL_GetProcAddress = Mac_GL_GetProcAddress;
   1.182 -#endif	// Have OpenGL
   1.183 -	device->SetCaption = Mac_SetCaption;
   1.184 -	device->SetIcon = NULL;
   1.185 -	device->IconifyWindow = NULL;
   1.186 -	device->GrabInput = NULL;
   1.187 -	device->GetWMInfo = NULL;
   1.188 -	device->FreeWMCursor = Mac_FreeWMCursor;
   1.189 -	device->CreateWMCursor = Mac_CreateWMCursor;
   1.190 -	device->ShowWMCursor = Mac_ShowWMCursor;
   1.191 -	device->WarpWMCursor = Mac_WarpWMCursor;
   1.192 -	device->InitOSKeymap = Mac_InitOSKeymap;
   1.193 -	device->PumpEvents = Mac_PumpEvents;
   1.194 +    device->GL_MakeCurrent = Mac_GL_MakeCurrent;
   1.195 +    device->GL_SwapBuffers = Mac_GL_SwapBuffers;
   1.196 +    device->GL_LoadLibrary = Mac_GL_LoadLibrary;
   1.197 +    device->GL_GetProcAddress = Mac_GL_GetProcAddress;
   1.198 +#endif // Have OpenGL
   1.199 +    device->SetCaption = Mac_SetCaption;
   1.200 +    device->SetIcon = NULL;
   1.201 +    device->IconifyWindow = NULL;
   1.202 +    device->GrabInput = NULL;
   1.203 +    device->GetWMInfo = NULL;
   1.204 +    device->FreeWMCursor = Mac_FreeWMCursor;
   1.205 +    device->CreateWMCursor = Mac_CreateWMCursor;
   1.206 +    device->ShowWMCursor = Mac_ShowWMCursor;
   1.207 +    device->WarpWMCursor = Mac_WarpWMCursor;
   1.208 +    device->InitOSKeymap = Mac_InitOSKeymap;
   1.209 +    device->PumpEvents = Mac_PumpEvents;
   1.210  
   1.211 -	device->free = ROM_DeleteDevice;
   1.212 +    device->free = ROM_DeleteDevice;
   1.213  
   1.214 -	return device;
   1.215 +    return device;
   1.216  }
   1.217  
   1.218  VideoBootStrap TOOLBOX_bootstrap = {
   1.219 -	"toolbox", "MacOS ROM Toolbox",
   1.220 -	ROM_Available, ROM_CreateDevice
   1.221 +    "toolbox", "MacOS ROM Toolbox",
   1.222 +    ROM_Available, ROM_CreateDevice
   1.223  };
   1.224  
   1.225  
   1.226 -static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat)
   1.227 +static int
   1.228 +ROM_VideoInit (_THIS, SDL_PixelFormat * vformat)
   1.229  {
   1.230 -	long info;
   1.231 -	
   1.232 -	/* Check out some things about the system */
   1.233 -	Gestalt(gestaltQuickdrawVersion, &info);
   1.234 -	if ( info == gestaltOriginalQD ) {
   1.235 -		SDL_SetError("Color Quickdraw not available");
   1.236 -		return(-1);
   1.237 -	}
   1.238 +    long info;
   1.239  
   1.240 -	/* Start ROMintosh events */
   1.241 -	Mac_InitEvents(this);
   1.242 +    /* Check out some things about the system */
   1.243 +    Gestalt (gestaltQuickdrawVersion, &info);
   1.244 +    if (info == gestaltOriginalQD) {
   1.245 +        SDL_SetError ("Color Quickdraw not available");
   1.246 +        return (-1);
   1.247 +    }
   1.248  
   1.249 -	/* Get a handle to the main monitor */
   1.250 -	SDL_Display = GetMainDevice();
   1.251 +    /* Start ROMintosh events */
   1.252 +    Mac_InitEvents (this);
   1.253  
   1.254 -	/* Determine the current screen size */
   1.255 -	this->info.current_w = (**SDL_Display).gdRect.right;
   1.256 -	this->info.current_h = (**SDL_Display).gdRect.bottom;
   1.257 +    /* Get a handle to the main monitor */
   1.258 +    SDL_Display = GetMainDevice ();
   1.259  
   1.260 -	/* Determine pixel format */
   1.261 -	vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize;
   1.262 -	switch (vformat->BitsPerPixel) {
   1.263 -		case 16:	/* 5-5-5 RGB */
   1.264 -			vformat->Rmask = 0x00007c00;
   1.265 -			vformat->Gmask = 0x000003e0;
   1.266 -			vformat->Bmask = 0x0000001f;
   1.267 -			break;
   1.268 -		default:
   1.269 -			break;
   1.270 -	}
   1.271 +    /* Determine the current screen size */
   1.272 +    this->info.current_w = (**SDL_Display).gdRect.right;
   1.273 +    this->info.current_h = (**SDL_Display).gdRect.bottom;
   1.274  
   1.275 -	/* Create our palette */
   1.276 -	SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8);
   1.277 -	if ( SDL_CTab == nil ) {
   1.278 -		SDL_OutOfMemory();
   1.279 -		return(-1);
   1.280 -	}
   1.281 -	(**SDL_CTab).ctSeed = GetCTSeed();
   1.282 -	(**SDL_CTab).ctFlags = 0;
   1.283 -	(**SDL_CTab).ctSize = 255;
   1.284 -	CTabChanged(SDL_CTab);
   1.285 -	SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0);
   1.286 +    /* Determine pixel format */
   1.287 +    vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize;
   1.288 +    switch (vformat->BitsPerPixel) {
   1.289 +    case 16:                   /* 5-5-5 RGB */
   1.290 +        vformat->Rmask = 0x00007c00;
   1.291 +        vformat->Gmask = 0x000003e0;
   1.292 +        vformat->Bmask = 0x0000001f;
   1.293 +        break;
   1.294 +    default:
   1.295 +        break;
   1.296 +    }
   1.297  
   1.298 -	/* Get a list of available fullscreen modes */
   1.299 -	SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
   1.300 -	if ( SDL_modelist ) {
   1.301 -		SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
   1.302 -		if ( SDL_modelist[0] ) {
   1.303 -			SDL_modelist[0]->x = 0;
   1.304 -			SDL_modelist[0]->y = 0;
   1.305 -			SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
   1.306 -			SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
   1.307 -		}
   1.308 -		SDL_modelist[1] = NULL;
   1.309 -	}
   1.310 +    /* Create our palette */
   1.311 +    SDL_CTab = (CTabHandle) NewHandle (sizeof (ColorSpec) * 256 + 8);
   1.312 +    if (SDL_CTab == nil) {
   1.313 +        SDL_OutOfMemory ();
   1.314 +        return (-1);
   1.315 +    }
   1.316 +    (**SDL_CTab).ctSeed = GetCTSeed ();
   1.317 +    (**SDL_CTab).ctFlags = 0;
   1.318 +    (**SDL_CTab).ctSize = 255;
   1.319 +    CTabChanged (SDL_CTab);
   1.320 +    SDL_CPal = NewPalette (256, SDL_CTab, pmExplicit + pmTolerant, 0);
   1.321  
   1.322 -	/* Fill in some window manager capabilities */
   1.323 -	this->info.wm_available = 1;
   1.324 +    /* Get a list of available fullscreen modes */
   1.325 +    SDL_modelist = (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
   1.326 +    if (SDL_modelist) {
   1.327 +        SDL_modelist[0] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
   1.328 +        if (SDL_modelist[0]) {
   1.329 +            SDL_modelist[0]->x = 0;
   1.330 +            SDL_modelist[0]->y = 0;
   1.331 +            SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
   1.332 +            SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
   1.333 +        }
   1.334 +        SDL_modelist[1] = NULL;
   1.335 +    }
   1.336  
   1.337 -	/* We're done! */
   1.338 -	return(0);
   1.339 +    /* Fill in some window manager capabilities */
   1.340 +    this->info.wm_available = 1;
   1.341 +
   1.342 +    /* We're done! */
   1.343 +    return (0);
   1.344  }
   1.345  
   1.346 -static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   1.347 +static SDL_Rect **
   1.348 +ROM_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
   1.349  {
   1.350 -	if ( this->screen->format->BitsPerPixel == format->BitsPerPixel ) {
   1.351 -		if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
   1.352 -			return(SDL_modelist);
   1.353 -		} else {
   1.354 -			return((SDL_Rect **)-1);
   1.355 -		}
   1.356 -	} else {
   1.357 -		return((SDL_Rect **)0);
   1.358 -	}
   1.359 +    if (this->screen->format->BitsPerPixel == format->BitsPerPixel) {
   1.360 +        if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   1.361 +            return (SDL_modelist);
   1.362 +        } else {
   1.363 +            return ((SDL_Rect **) - 1);
   1.364 +        }
   1.365 +    } else {
   1.366 +        return ((SDL_Rect **) 0);
   1.367 +    }
   1.368  }
   1.369  
   1.370 -static void ROM_HideMenuBar(_THIS)
   1.371 +static void
   1.372 +ROM_HideMenuBar (_THIS)
   1.373  {
   1.374 -#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
   1.375 -	RgnHandle		drawRgn = nil;
   1.376 -	RgnHandle		tempRgn = nil;
   1.377 -	RgnHandle		grayRgn = nil;
   1.378 -	WindowPtr		window = nil;
   1.379 -	GDHandle		gd = nil;
   1.380 -	GrafPtr			savePort;
   1.381 -	long			response;
   1.382 -	short			height;
   1.383 -	EventRecord		theEvent;
   1.384 +#if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   1.385 +    RgnHandle drawRgn = nil;
   1.386 +    RgnHandle tempRgn = nil;
   1.387 +    RgnHandle grayRgn = nil;
   1.388 +    WindowPtr window = nil;
   1.389 +    GDHandle gd = nil;
   1.390 +    GrafPtr savePort;
   1.391 +    long response;
   1.392 +    short height;
   1.393 +    EventRecord theEvent;
   1.394  
   1.395 -	height = GetMBarHeight();
   1.396 -	
   1.397 -	if ( height > 0 ) {
   1.398 -		tempRgn = NewRgn();
   1.399 -		drawRgn = NewRgn();
   1.400 -		gSaveGrayRgn = NewRgn();
   1.401 -		if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) {
   1.402 -			goto CLEANUP;
   1.403 -		}
   1.404 -		grayRgn = GetGrayRgn(); /* No need to check for this */
   1.405 -	
   1.406 -		GetPort(&savePort);
   1.407 +    height = GetMBarHeight ();
   1.408  
   1.409 -		/* Hide the control strip if it's present, and record its 
   1.410 -		   previous position into the dirty region for redrawing. 
   1.411 -		   This isn't necessary, but may help catch stray bits. */
   1.412 -		CopyRgn(grayRgn, tempRgn);
   1.413 -		if (!Gestalt(gestaltControlStripAttr, &response) && 
   1.414 -			(response & (1L << gestaltControlStripExists))) {
   1.415 -			gSaveCSVis = SBIsControlStripVisible();
   1.416 -			if (gSaveCSVis)
   1.417 -				SBShowHideControlStrip(false);
   1.418 -		}
   1.419 -		DiffRgn(grayRgn, tempRgn, drawRgn);
   1.420 +    if (height > 0) {
   1.421 +        tempRgn = NewRgn ();
   1.422 +        drawRgn = NewRgn ();
   1.423 +        gSaveGrayRgn = NewRgn ();
   1.424 +        if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   1.425 +            goto CLEANUP;
   1.426 +        }
   1.427 +        grayRgn = GetGrayRgn ();        /* No need to check for this */
   1.428  
   1.429 -		/* Save the gray region once the control strip is hidden*/
   1.430 -		CopyRgn(grayRgn, gSaveGrayRgn);
   1.431 +        GetPort (&savePort);
   1.432  
   1.433 -		/* Change the menu height in lowmem */
   1.434 -		gSaveMenuBar = height;
   1.435 -		LMSetMBarHeight(0);
   1.436 -		
   1.437 -		/* Walk the monitor rectangles, and combine any pieces that
   1.438 -		   aren't in GrayRgn: menubar, round corners, fake floaters. */
   1.439 -		for(gd = GetDeviceList(); gd; gd = GetNextDevice(gd)) 
   1.440 -			{
   1.441 -			if (!TestDeviceAttribute(gd, screenDevice)) continue;
   1.442 -			if (!TestDeviceAttribute(gd, screenActive)) continue;
   1.443 +        /* Hide the control strip if it's present, and record its 
   1.444 +           previous position into the dirty region for redrawing. 
   1.445 +           This isn't necessary, but may help catch stray bits. */
   1.446 +        CopyRgn (grayRgn, tempRgn);
   1.447 +        if (!Gestalt (gestaltControlStripAttr, &response) &&
   1.448 +            (response & (1L << gestaltControlStripExists))) {
   1.449 +            gSaveCSVis = SBIsControlStripVisible ();
   1.450 +            if (gSaveCSVis)
   1.451 +                SBShowHideControlStrip (false);
   1.452 +        }
   1.453 +        DiffRgn (grayRgn, tempRgn, drawRgn);
   1.454  
   1.455 -			RectRgn(tempRgn, &(*gd)->gdRect);	/* Get the whole screen */
   1.456 -			DiffRgn(tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */
   1.457 -			UnionRgn(tempRgn, drawRgn, drawRgn);/* Combine all the bits */
   1.458 -			}
   1.459 -			
   1.460 -		/* Add the bits into the GrayRgn */
   1.461 -		UnionRgn(drawRgn, grayRgn, grayRgn);
   1.462 +        /* Save the gray region once the control strip is hidden */
   1.463 +        CopyRgn (grayRgn, gSaveGrayRgn);
   1.464  
   1.465 -		/* Modify the vis regions of exposed windows */
   1.466 -		window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L;
   1.467 -		PaintBehind(window, drawRgn);
   1.468 -		CalcVisBehind(window, drawRgn);
   1.469 +        /* Change the menu height in lowmem */
   1.470 +        gSaveMenuBar = height;
   1.471 +        LMSetMBarHeight (0);
   1.472  
   1.473 -		SetPort(savePort);
   1.474 -		
   1.475 -		/* Yield time so that floaters can catch up */
   1.476 -		EventAvail(0, &theEvent);
   1.477 -		EventAvail(0, &theEvent);
   1.478 -		EventAvail(0, &theEvent);
   1.479 -		EventAvail(0, &theEvent);
   1.480 -		}
   1.481 +        /* Walk the monitor rectangles, and combine any pieces that
   1.482 +           aren't in GrayRgn: menubar, round corners, fake floaters. */
   1.483 +        for (gd = GetDeviceList (); gd; gd = GetNextDevice (gd)) {
   1.484 +            if (!TestDeviceAttribute (gd, screenDevice))
   1.485 +                continue;
   1.486 +            if (!TestDeviceAttribute (gd, screenActive))
   1.487 +                continue;
   1.488  
   1.489 -CLEANUP:
   1.490 +            RectRgn (tempRgn, &(*gd)->gdRect);  /* Get the whole screen */
   1.491 +            DiffRgn (tempRgn, grayRgn, tempRgn);        /* Subtract out GrayRgn */
   1.492 +            UnionRgn (tempRgn, drawRgn, drawRgn);       /* Combine all the bits */
   1.493 +        }
   1.494  
   1.495 -	if (tempRgn) DisposeRgn(tempRgn);
   1.496 -	if (drawRgn) DisposeRgn(drawRgn);
   1.497 +        /* Add the bits into the GrayRgn */
   1.498 +        UnionRgn (drawRgn, grayRgn, grayRgn);
   1.499 +
   1.500 +        /* Modify the vis regions of exposed windows */
   1.501 +        window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
   1.502 +        PaintBehind (window, drawRgn);
   1.503 +        CalcVisBehind (window, drawRgn);
   1.504 +
   1.505 +        SetPort (savePort);
   1.506 +
   1.507 +        /* Yield time so that floaters can catch up */
   1.508 +        EventAvail (0, &theEvent);
   1.509 +        EventAvail (0, &theEvent);
   1.510 +        EventAvail (0, &theEvent);
   1.511 +        EventAvail (0, &theEvent);
   1.512 +    }
   1.513 +
   1.514 +  CLEANUP:
   1.515 +
   1.516 +    if (tempRgn)
   1.517 +        DisposeRgn (tempRgn);
   1.518 +    if (drawRgn)
   1.519 +        DisposeRgn (drawRgn);
   1.520  #endif /* !TARGET_API_MAC_CARBON */
   1.521  }
   1.522 -	
   1.523 -static void ROM_ShowMenuBar(_THIS)
   1.524 +
   1.525 +static void
   1.526 +ROM_ShowMenuBar (_THIS)
   1.527  {
   1.528 -#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
   1.529 -	RgnHandle		drawRgn = nil;
   1.530 -	RgnHandle		menuRgn = nil;
   1.531 -	RgnHandle		tempRgn = nil;
   1.532 -	RgnHandle		grayRgn = nil;
   1.533 -	WindowPtr		window = nil;
   1.534 -	GrafPtr			wMgrPort;
   1.535 -	GrafPtr			savePort;
   1.536 -	Rect			menuRect;
   1.537 -	long			response;
   1.538 -	short			height;
   1.539 -	EventRecord		theEvent;
   1.540 -	RGBColor		saveRGB;
   1.541 -	RGBColor		blackRGB = { 0, 0, 0 };
   1.542 +#if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   1.543 +    RgnHandle drawRgn = nil;
   1.544 +    RgnHandle menuRgn = nil;
   1.545 +    RgnHandle tempRgn = nil;
   1.546 +    RgnHandle grayRgn = nil;
   1.547 +    WindowPtr window = nil;
   1.548 +    GrafPtr wMgrPort;
   1.549 +    GrafPtr savePort;
   1.550 +    Rect menuRect;
   1.551 +    long response;
   1.552 +    short height;
   1.553 +    EventRecord theEvent;
   1.554 +    RGBColor saveRGB;
   1.555 +    RGBColor blackRGB = { 0, 0, 0 };
   1.556  
   1.557 -	height = GetMBarHeight();
   1.558 -	
   1.559 -	if ((height <= 0) && (gSaveMenuBar > 0)) {
   1.560 -		drawRgn = NewRgn();
   1.561 -		menuRgn = NewRgn();
   1.562 -		tempRgn = NewRgn();
   1.563 -		if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) {
   1.564 -			goto CLEANUP;
   1.565 -		}
   1.566 -		grayRgn = GetGrayRgn(); /* No need to check for this */
   1.567 -	
   1.568 -		GetPort(&savePort);
   1.569 -		GetWMgrPort(&wMgrPort);
   1.570 +    height = GetMBarHeight ();
   1.571  
   1.572 -		/* Set the height properly */
   1.573 -		LMSetMBarHeight(gSaveMenuBar);
   1.574 +    if ((height <= 0) && (gSaveMenuBar > 0)) {
   1.575 +        drawRgn = NewRgn ();
   1.576 +        menuRgn = NewRgn ();
   1.577 +        tempRgn = NewRgn ();
   1.578 +        if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   1.579 +            goto CLEANUP;
   1.580 +        }
   1.581 +        grayRgn = GetGrayRgn ();        /* No need to check for this */
   1.582  
   1.583 -		/* Restore the old GrayRgn: rounded corners, etc, but not
   1.584 -		   the menubar -- subtract that out first! */
   1.585 -		if (gSaveGrayRgn)
   1.586 -			{
   1.587 -			menuRect = (*GetMainDevice())->gdRect;
   1.588 -			menuRect.bottom = menuRect.top + gSaveMenuBar;
   1.589 -			RectRgn(menuRgn, &menuRect);
   1.590 +        GetPort (&savePort);
   1.591 +        GetWMgrPort (&wMgrPort);
   1.592  
   1.593 -			DiffRgn(grayRgn, gSaveGrayRgn, drawRgn); 	/* What do we inval? */
   1.594 -			DiffRgn(drawRgn, menuRgn, drawRgn);			/* Clip out the menu */
   1.595 -			
   1.596 -			/* Now redraw the corners and other bits black */
   1.597 -			SetPort(wMgrPort);
   1.598 -			GetClip(tempRgn);
   1.599 -			SetClip(drawRgn);
   1.600 -			GetForeColor(&saveRGB);
   1.601 -			RGBForeColor(&blackRGB);
   1.602 -			PaintRgn(drawRgn);
   1.603 -			RGBForeColor(&saveRGB);
   1.604 -			SetClip(tempRgn);
   1.605 -			SetPort(savePort);
   1.606 -			
   1.607 -			UnionRgn(drawRgn, menuRgn, drawRgn);		/* Put back the menu */
   1.608 +        /* Set the height properly */
   1.609 +        LMSetMBarHeight (gSaveMenuBar);
   1.610  
   1.611 -			/* Now actually restore the GrayRgn */
   1.612 -			CopyRgn(gSaveGrayRgn, grayRgn);
   1.613 -			DisposeRgn(gSaveGrayRgn);
   1.614 -			gSaveGrayRgn = nil;
   1.615 -			}
   1.616 +        /* Restore the old GrayRgn: rounded corners, etc, but not
   1.617 +           the menubar -- subtract that out first! */
   1.618 +        if (gSaveGrayRgn) {
   1.619 +            menuRect = (*GetMainDevice ())->gdRect;
   1.620 +            menuRect.bottom = menuRect.top + gSaveMenuBar;
   1.621 +            RectRgn (menuRgn, &menuRect);
   1.622  
   1.623 -		/* Modify the vis regions of exposed windows and draw menubar */
   1.624 -		window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L;
   1.625 -		PaintBehind(window, drawRgn);
   1.626 -		CalcVisBehind(window, drawRgn);
   1.627 -		DrawMenuBar();
   1.628 +            DiffRgn (grayRgn, gSaveGrayRgn, drawRgn);   /* What do we inval? */
   1.629 +            DiffRgn (drawRgn, menuRgn, drawRgn);        /* Clip out the menu */
   1.630  
   1.631 -		SetPort(savePort);
   1.632 -		gSaveMenuBar = 0;
   1.633 +            /* Now redraw the corners and other bits black */
   1.634 +            SetPort (wMgrPort);
   1.635 +            GetClip (tempRgn);
   1.636 +            SetClip (drawRgn);
   1.637 +            GetForeColor (&saveRGB);
   1.638 +            RGBForeColor (&blackRGB);
   1.639 +            PaintRgn (drawRgn);
   1.640 +            RGBForeColor (&saveRGB);
   1.641 +            SetClip (tempRgn);
   1.642 +            SetPort (savePort);
   1.643  
   1.644 -		/* Now show the control strip if it's present */
   1.645 -		if (!Gestalt(gestaltControlStripAttr, &response) && 
   1.646 -				(response & (1L << gestaltControlStripExists)))
   1.647 -			{
   1.648 -			if (gSaveCSVis && !SBIsControlStripVisible())
   1.649 -				SBShowHideControlStrip(true);
   1.650 -			gSaveCSVis = true;
   1.651 -			}
   1.652 +            UnionRgn (drawRgn, menuRgn, drawRgn);       /* Put back the menu */
   1.653  
   1.654 -		/* Yield time so that floaters can catch up */
   1.655 -		EventAvail(0, &theEvent);
   1.656 -		EventAvail(0, &theEvent);
   1.657 -		EventAvail(0, &theEvent);
   1.658 -		EventAvail(0, &theEvent);
   1.659 -		}
   1.660 +            /* Now actually restore the GrayRgn */
   1.661 +            CopyRgn (gSaveGrayRgn, grayRgn);
   1.662 +            DisposeRgn (gSaveGrayRgn);
   1.663 +            gSaveGrayRgn = nil;
   1.664 +        }
   1.665  
   1.666 -CLEANUP:
   1.667 +        /* Modify the vis regions of exposed windows and draw menubar */
   1.668 +        window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
   1.669 +        PaintBehind (window, drawRgn);
   1.670 +        CalcVisBehind (window, drawRgn);
   1.671 +        DrawMenuBar ();
   1.672  
   1.673 -	if (drawRgn) DisposeRgn(drawRgn);
   1.674 -	if (menuRgn) DisposeRgn(menuRgn);
   1.675 -	if (tempRgn) DisposeRgn(tempRgn);
   1.676 +        SetPort (savePort);
   1.677 +        gSaveMenuBar = 0;
   1.678 +
   1.679 +        /* Now show the control strip if it's present */
   1.680 +        if (!Gestalt (gestaltControlStripAttr, &response) &&
   1.681 +            (response & (1L << gestaltControlStripExists))) {
   1.682 +            if (gSaveCSVis && !SBIsControlStripVisible ())
   1.683 +                SBShowHideControlStrip (true);
   1.684 +            gSaveCSVis = true;
   1.685 +        }
   1.686 +
   1.687 +        /* Yield time so that floaters can catch up */
   1.688 +        EventAvail (0, &theEvent);
   1.689 +        EventAvail (0, &theEvent);
   1.690 +        EventAvail (0, &theEvent);
   1.691 +        EventAvail (0, &theEvent);
   1.692 +    }
   1.693 +
   1.694 +  CLEANUP:
   1.695 +
   1.696 +    if (drawRgn)
   1.697 +        DisposeRgn (drawRgn);
   1.698 +    if (menuRgn)
   1.699 +        DisposeRgn (menuRgn);
   1.700 +    if (tempRgn)
   1.701 +        DisposeRgn (tempRgn);
   1.702  #endif /* !TARGET_API_MAC_CARBON */
   1.703  }
   1.704  
   1.705  /* Various screen update functions available */
   1.706 -static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
   1.707 -static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects);
   1.708 +static void ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects);
   1.709 +static void ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects);
   1.710  
   1.711 -static void ROM_UnsetVideoMode(_THIS, SDL_Surface *current)
   1.712 +static void
   1.713 +ROM_UnsetVideoMode (_THIS, SDL_Surface * current)
   1.714  {
   1.715 -	/* Free the current window, if any */
   1.716 -	if ( SDL_Window != nil ) {
   1.717 -		GWorldPtr memworld;
   1.718 -		
   1.719 -		/* Handle OpenGL support */
   1.720 -		Mac_GL_Quit(this);
   1.721 +    /* Free the current window, if any */
   1.722 +    if (SDL_Window != nil) {
   1.723 +        GWorldPtr memworld;
   1.724  
   1.725 -		memworld = (GWorldPtr)GetWRefCon(SDL_Window);
   1.726 -		if ( memworld != nil ) {
   1.727 -			UnlockPixels(GetGWorldPixMap(memworld));
   1.728 -			DisposeGWorld(memworld);
   1.729 -		}
   1.730 -		if ( (current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
   1.731 +        /* Handle OpenGL support */
   1.732 +        Mac_GL_Quit (this);
   1.733 +
   1.734 +        memworld = (GWorldPtr) GetWRefCon (SDL_Window);
   1.735 +        if (memworld != nil) {
   1.736 +            UnlockPixels (GetGWorldPixMap (memworld));
   1.737 +            DisposeGWorld (memworld);
   1.738 +        }
   1.739 +        if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   1.740  #if USE_QUICKTIME
   1.741 -			EndFullScreen(fullscreen_ctx, nil);
   1.742 -			SDL_Window = nil;
   1.743 +            EndFullScreen (fullscreen_ctx, nil);
   1.744 +            SDL_Window = nil;
   1.745  #else
   1.746 -			ROM_ShowMenuBar(this);
   1.747 +            ROM_ShowMenuBar (this);
   1.748  #endif
   1.749 -		}
   1.750 -	}
   1.751 -	current->pixels = NULL;
   1.752 -	current->flags &= ~(SDL_HWSURFACE|SDL_FULLSCREEN);
   1.753 +        }
   1.754 +    }
   1.755 +    current->pixels = NULL;
   1.756 +    current->flags &= ~(SDL_HWSURFACE | SDL_FULLSCREEN);
   1.757  }
   1.758  
   1.759 -static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current,
   1.760 -				int width, int height, int bpp, Uint32 flags)
   1.761 +static SDL_Surface *
   1.762 +ROM_SetVideoMode (_THIS, SDL_Surface * current,
   1.763 +                  int width, int height, int bpp, Uint32 flags)
   1.764  {
   1.765 -	Rect wrect, orect;
   1.766 +    Rect wrect, orect;
   1.767  #if TARGET_API_MAC_CARBON
   1.768 -	Rect tmprect;
   1.769 +    Rect tmprect;
   1.770  #endif
   1.771  
   1.772 -	/* Free any previous video mode */
   1.773 -	ROM_UnsetVideoMode(this, current);
   1.774 +    /* Free any previous video mode */
   1.775 +    ROM_UnsetVideoMode (this, current);
   1.776  
   1.777 -	/* Create the ROM window and SDL video surface */
   1.778 -	current->flags = 0;		/* Clear flags */
   1.779 -	current->w = width;
   1.780 -	current->h = height;
   1.781 -	SetRect(&wrect, 0, 0, width, height);
   1.782 -	if ( SDL_Window ) {
   1.783 -		/* If we recreate the window, don't move it around */
   1.784 +    /* Create the ROM window and SDL video surface */
   1.785 +    current->flags = 0;         /* Clear flags */
   1.786 +    current->w = width;
   1.787 +    current->h = height;
   1.788 +    SetRect (&wrect, 0, 0, width, height);
   1.789 +    if (SDL_Window) {
   1.790 +        /* If we recreate the window, don't move it around */
   1.791  #if TARGET_API_MAC_CARBON
   1.792 -		orect = *GetWindowPortBounds(SDL_Window, &tmprect);
   1.793 +        orect = *GetWindowPortBounds (SDL_Window, &tmprect);
   1.794  #else
   1.795 -		orect = SDL_Window->portRect;
   1.796 +        orect = SDL_Window->portRect;
   1.797  #endif
   1.798 -		OffsetRect(&wrect, orect.left, orect.top);
   1.799 -	} else {
   1.800 -		/* Center the window the first time we show it */
   1.801 -		OffsetRect(&wrect,
   1.802 -		(SDL_modelist[0]->w-width)/2, (SDL_modelist[0]->h-height)/2);
   1.803 -	}
   1.804 +        OffsetRect (&wrect, orect.left, orect.top);
   1.805 +    } else {
   1.806 +        /* Center the window the first time we show it */
   1.807 +        OffsetRect (&wrect,
   1.808 +                    (SDL_modelist[0]->w - width) / 2,
   1.809 +                    (SDL_modelist[0]->h - height) / 2);
   1.810 +    }
   1.811  
   1.812  #if defined(__MACOSX__) && !USE_QUICKTIME
   1.813 -	/* Hum.. fullscreen mode is broken */
   1.814 -	flags &= ~SDL_FULLSCREEN;
   1.815 +    /* Hum.. fullscreen mode is broken */
   1.816 +    flags &= ~SDL_FULLSCREEN;
   1.817  #endif
   1.818 -	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
   1.819 -		/* Create the fullscreen window and use screen bits */
   1.820 -		current->flags |= SDL_HWSURFACE|SDL_FULLSCREEN;
   1.821 -		if ( SDL_Window ) {
   1.822 -			DisposeWindow(SDL_Window);
   1.823 -		}
   1.824 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   1.825 +        /* Create the fullscreen window and use screen bits */
   1.826 +        current->flags |= SDL_HWSURFACE | SDL_FULLSCREEN;
   1.827 +        if (SDL_Window) {
   1.828 +            DisposeWindow (SDL_Window);
   1.829 +        }
   1.830  #if USE_QUICKTIME
   1.831 -		BeginFullScreen(&fullscreen_ctx, nil, 0,0, &SDL_Window, nil, 0);
   1.832 +        BeginFullScreen (&fullscreen_ctx, nil, 0, 0, &SDL_Window, nil, 0);
   1.833  #else
   1.834 -		SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox,
   1.835 -						(WindowPtr)-1, false, 0);
   1.836 -		ROM_HideMenuBar(this);
   1.837 +        SDL_Window = NewCWindow (nil, &wrect, "\p", true, plainDBox,
   1.838 +                                 (WindowPtr) - 1, false, 0);
   1.839 +        ROM_HideMenuBar (this);
   1.840  #endif
   1.841 -		current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
   1.842 -		current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
   1.843 -		this->UpdateRects = ROM_DirectUpdate;
   1.844 -	} else {
   1.845 -		GWorldPtr memworld;
   1.846 -		PixMapHandle pixmap;
   1.847 -		int style;
   1.848 +        current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
   1.849 +        current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
   1.850 +        this->UpdateRects = ROM_DirectUpdate;
   1.851 +    } else {
   1.852 +        GWorldPtr memworld;
   1.853 +        PixMapHandle pixmap;
   1.854 +        int style;
   1.855  
   1.856 -		style = noGrowDocProc;
   1.857 -		if ( flags & SDL_NOFRAME ) {
   1.858 -			style = plainDBox;
   1.859 -			current->flags |= SDL_NOFRAME;
   1.860 -		} else
   1.861 -		if ( flags & SDL_RESIZABLE ) {
   1.862 -			style = zoomDocProc;
   1.863 -			current->flags |= SDL_RESIZABLE;
   1.864 -		}
   1.865 -		if ( SDL_Window && (style == current_style) ) {
   1.866 -			/* Resize existing window, if necessary */
   1.867 -			if ( ((orect.right-orect.left) != width) ||
   1.868 -			     ((orect.bottom-orect.top) != height) ) {
   1.869 -				SizeWindow(SDL_Window, width, height, false);
   1.870 -			}
   1.871 -		} else {
   1.872 -			/* Recreate the window in the new style */
   1.873 -			if ( SDL_Window ) {
   1.874 -				DisposeWindow(SDL_Window);
   1.875 -			}
   1.876 -			SDL_Window = NewCWindow(nil, &wrect, "\p", true,
   1.877 -			                        style, (WindowPtr)-1, true, 0);
   1.878 +        style = noGrowDocProc;
   1.879 +        if (flags & SDL_NOFRAME) {
   1.880 +            style = plainDBox;
   1.881 +            current->flags |= SDL_NOFRAME;
   1.882 +        } else if (flags & SDL_RESIZABLE) {
   1.883 +            style = zoomDocProc;
   1.884 +            current->flags |= SDL_RESIZABLE;
   1.885 +        }
   1.886 +        if (SDL_Window && (style == current_style)) {
   1.887 +            /* Resize existing window, if necessary */
   1.888 +            if (((orect.right - orect.left) != width) ||
   1.889 +                ((orect.bottom - orect.top) != height)) {
   1.890 +                SizeWindow (SDL_Window, width, height, false);
   1.891 +            }
   1.892 +        } else {
   1.893 +            /* Recreate the window in the new style */
   1.894 +            if (SDL_Window) {
   1.895 +                DisposeWindow (SDL_Window);
   1.896 +            }
   1.897 +            SDL_Window = NewCWindow (nil, &wrect, "\p", true,
   1.898 +                                     style, (WindowPtr) - 1, true, 0);
   1.899  
   1.900 -			/* Set the window title, if any */
   1.901 -			{ char *title;
   1.902 -				SDL_WM_GetCaption(&title, NULL);
   1.903 -				if ( title ) {
   1.904 -					Mac_SetCaption(this, title, NULL);
   1.905 -				}
   1.906 -			}
   1.907 -		}
   1.908 -		current_style = style;
   1.909 -		SetPalette(SDL_Window, SDL_CPal, false);
   1.910 -		ActivatePalette(SDL_Window);
   1.911 -		if ( NewGWorld(&memworld, 0,
   1.912 +            /* Set the window title, if any */
   1.913 +            {
   1.914 +                char *title;
   1.915 +                SDL_WM_GetCaption (&title, NULL);
   1.916 +                if (title) {
   1.917 +                    Mac_SetCaption (this, title, NULL);
   1.918 +                }
   1.919 +            }
   1.920 +        }
   1.921 +        current_style = style;
   1.922 +        SetPalette (SDL_Window, SDL_CPal, false);
   1.923 +        ActivatePalette (SDL_Window);
   1.924 +        if (NewGWorld (&memworld, 0,
   1.925  #if TARGET_API_MAC_CARBON
   1.926 -			       GetWindowPortBounds(SDL_Window, &tmprect),
   1.927 +                       GetWindowPortBounds (SDL_Window, &tmprect),
   1.928  #else
   1.929 -			       &SDL_Window->portRect,
   1.930 +                       &SDL_Window->portRect,
   1.931  #endif
   1.932 -			       SDL_CTab, nil, 0) != noErr ) {
   1.933 -			SDL_SetError("NewGWorld() failed");
   1.934 -			return(NULL);
   1.935 -		}
   1.936 -		SetWRefCon(SDL_Window, (long)memworld);
   1.937 -		pixmap = GetGWorldPixMap(memworld);
   1.938 -		LockPixels(pixmap);
   1.939 -		current->pitch = (**pixmap).rowBytes & 0x3FFF;
   1.940 -		current->pixels = GetPixBaseAddr(pixmap);
   1.941 -		this->UpdateRects = ROM_WindowUpdate;
   1.942 -	}
   1.943 -	SetPortWindowPort(SDL_Window);
   1.944 -	SelectWindow(SDL_Window);
   1.945 +                       SDL_CTab, nil, 0) != noErr) {
   1.946 +            SDL_SetError ("NewGWorld() failed");
   1.947 +            return (NULL);
   1.948 +        }
   1.949 +        SetWRefCon (SDL_Window, (long) memworld);
   1.950 +        pixmap = GetGWorldPixMap (memworld);
   1.951 +        LockPixels (pixmap);
   1.952 +        current->pitch = (**pixmap).rowBytes & 0x3FFF;
   1.953 +        current->pixels = GetPixBaseAddr (pixmap);
   1.954 +        this->UpdateRects = ROM_WindowUpdate;
   1.955 +    }
   1.956 +    SetPortWindowPort (SDL_Window);
   1.957 +    SelectWindow (SDL_Window);
   1.958  
   1.959 -	/* Handle OpenGL support */
   1.960 -	if ( flags & SDL_INTERNALOPENGL ) {
   1.961 -		if ( Mac_GL_Init(this) == 0 ) {
   1.962 -			current->flags |= SDL_INTERNALOPENGL;
   1.963 -		} else {
   1.964 -			current = NULL;
   1.965 -		}
   1.966 -	}
   1.967 -	
   1.968 -	if ( (flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN) )
   1.969 -	   current->flags |= SDL_HWPALETTE;
   1.970 -	   
   1.971 -	/* We're live! */
   1.972 -	return(current);
   1.973 +    /* Handle OpenGL support */
   1.974 +    if (flags & SDL_INTERNALOPENGL) {
   1.975 +        if (Mac_GL_Init (this) == 0) {
   1.976 +            current->flags |= SDL_INTERNALOPENGL;
   1.977 +        } else {
   1.978 +            current = NULL;
   1.979 +        }
   1.980 +    }
   1.981 +
   1.982 +    if ((flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN))
   1.983 +        current->flags |= SDL_HWPALETTE;
   1.984 +
   1.985 +    /* We're live! */
   1.986 +    return (current);
   1.987  }
   1.988  
   1.989  /* We don't actually allow hardware surfaces other than the main one */
   1.990 -static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface)
   1.991 +static int
   1.992 +ROM_AllocHWSurface (_THIS, SDL_Surface * surface)
   1.993  {
   1.994 -	return(-1);
   1.995 +    return (-1);
   1.996  }
   1.997 -static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface)
   1.998 +static void
   1.999 +ROM_FreeHWSurface (_THIS, SDL_Surface * surface)
  1.1000  {
  1.1001 -	return;
  1.1002 +    return;
  1.1003  }
  1.1004 -static int ROM_LockHWSurface(_THIS, SDL_Surface *surface)
  1.1005 +static int
  1.1006 +ROM_LockHWSurface (_THIS, SDL_Surface * surface)
  1.1007  {
  1.1008 -	return(0);
  1.1009 +    return (0);
  1.1010  }
  1.1011 -static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface)
  1.1012 +static void
  1.1013 +ROM_UnlockHWSurface (_THIS, SDL_Surface * surface)
  1.1014  {
  1.1015 -	return;
  1.1016 +    return;
  1.1017  }
  1.1018  
  1.1019 -static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
  1.1020 +static void
  1.1021 +ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects)
  1.1022  {
  1.1023 -	/* The application is already updating the visible video memory */
  1.1024 -	return;
  1.1025 +    /* The application is already updating the visible video memory */
  1.1026 +    return;
  1.1027  }
  1.1028  
  1.1029 -static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects)
  1.1030 +static void
  1.1031 +ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects)
  1.1032  {
  1.1033 -	GWorldPtr memworld;
  1.1034 -	GrafPtr saveport;
  1.1035 -	CGrafPtr thePort;
  1.1036 -	const BitMap *memBits;
  1.1037 -	const BitMap *winBits;
  1.1038 -	int i;
  1.1039 -	Rect update;
  1.1040 -	
  1.1041 -	/* Copy from the offscreen GWorld to the window port */
  1.1042 -	GetPort(&saveport);
  1.1043 -	SetPortWindowPort(SDL_Window);
  1.1044 -	thePort = GetWindowPort(SDL_Window);
  1.1045 -	memworld = (GWorldPtr)GetWRefCon(SDL_Window);
  1.1046 +    GWorldPtr memworld;
  1.1047 +    GrafPtr saveport;
  1.1048 +    CGrafPtr thePort;
  1.1049 +    const BitMap *memBits;
  1.1050 +    const BitMap *winBits;
  1.1051 +    int i;
  1.1052 +    Rect update;
  1.1053 +
  1.1054 +    /* Copy from the offscreen GWorld to the window port */
  1.1055 +    GetPort (&saveport);
  1.1056 +    SetPortWindowPort (SDL_Window);
  1.1057 +    thePort = GetWindowPort (SDL_Window);
  1.1058 +    memworld = (GWorldPtr) GetWRefCon (SDL_Window);
  1.1059  #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
  1.1060 -	memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
  1.1061 +    memBits = GetPortBitMapForCopyBits ((CGrafPtr) memworld);
  1.1062  #else
  1.1063 -	memBits = &((GrafPtr)memworld)->portBits;
  1.1064 +    memBits = &((GrafPtr) memworld)->portBits;
  1.1065  #endif
  1.1066  #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
  1.1067 -	winBits = GetPortBitMapForCopyBits(thePort);
  1.1068 +    winBits = GetPortBitMapForCopyBits (thePort);
  1.1069  #else
  1.1070 -	winBits = &SDL_Window->portBits;
  1.1071 +    winBits = &SDL_Window->portBits;
  1.1072  #endif
  1.1073 -	for ( i=0; i<numrects; ++i ) {
  1.1074 -		update.left = rects[i].x;
  1.1075 -		update.right = rects[i].x+rects[i].w;
  1.1076 -		update.top = rects[i].y;
  1.1077 -		update.bottom = rects[i].y+rects[i].h;
  1.1078 -		CopyBits(memBits, winBits,
  1.1079 -			 &update, &update, srcCopy, nil);
  1.1080 -	}
  1.1081 +    for (i = 0; i < numrects; ++i) {
  1.1082 +        update.left = rects[i].x;
  1.1083 +        update.right = rects[i].x + rects[i].w;
  1.1084 +        update.top = rects[i].y;
  1.1085 +        update.bottom = rects[i].y + rects[i].h;
  1.1086 +        CopyBits (memBits, winBits, &update, &update, srcCopy, nil);
  1.1087 +    }
  1.1088  #if TARGET_API_MAC_CARBON
  1.1089 -	if ( QDIsPortBuffered(thePort) ) {
  1.1090 -		QDFlushPortBuffer(thePort, NULL);
  1.1091 -	}
  1.1092 +    if (QDIsPortBuffered (thePort)) {
  1.1093 +        QDFlushPortBuffer (thePort, NULL);
  1.1094 +    }
  1.1095  #endif
  1.1096 -	SetPort(saveport);
  1.1097 +    SetPort (saveport);
  1.1098  }
  1.1099  
  1.1100 -static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  1.1101 +static int
  1.1102 +ROM_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
  1.1103  {
  1.1104 -	CTabHandle cTab;
  1.1105 -	int i;
  1.1106 +    CTabHandle cTab;
  1.1107 +    int i;
  1.1108  
  1.1109 -	/* Get the colortable from the either the display or window */
  1.1110 -	if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
  1.1111 -		cTab = (**(**SDL_Display).gdPMap).pmTable;
  1.1112 -	} else {
  1.1113 -		cTab = SDL_CTab;
  1.1114 -	}
  1.1115 +    /* Get the colortable from the either the display or window */
  1.1116 +    if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
  1.1117 +        cTab = (**(**SDL_Display).gdPMap).pmTable;
  1.1118 +    } else {
  1.1119 +        cTab = SDL_CTab;
  1.1120 +    }
  1.1121  
  1.1122 -	/* Verify the range of colors */
  1.1123 -	if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) {
  1.1124 -		return(0);
  1.1125 -	}
  1.1126 -	
  1.1127 -	/* Set the screen palette and update the display */
  1.1128 -	for ( i=0; i< ncolors; ++i ) {
  1.1129 -	        int j = firstcolor + i;
  1.1130 -		(**cTab).ctTable[j].value = j;
  1.1131 -		(**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r;
  1.1132 -		(**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g;
  1.1133 -		(**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
  1.1134 -	}
  1.1135 -//	if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) 
  1.1136 -{
  1.1137 -		GDevice **odisplay;
  1.1138 -		odisplay = GetGDevice();
  1.1139 -		SetGDevice(SDL_Display);
  1.1140 -		SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable);
  1.1141 -		SetGDevice(odisplay);
  1.1142 -	}
  1.1143 -	return(1);
  1.1144 +    /* Verify the range of colors */
  1.1145 +    if ((firstcolor + ncolors) > ((**cTab).ctSize + 1)) {
  1.1146 +        return (0);
  1.1147 +    }
  1.1148 +
  1.1149 +    /* Set the screen palette and update the display */
  1.1150 +    for (i = 0; i < ncolors; ++i) {
  1.1151 +        int j = firstcolor + i;
  1.1152 +        (**cTab).ctTable[j].value = j;
  1.1153 +        (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r;
  1.1154 +        (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g;
  1.1155 +        (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
  1.1156 +    }
  1.1157 +//      if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) 
  1.1158 +    {
  1.1159 +        GDevice **odisplay;
  1.1160 +        odisplay = GetGDevice ();
  1.1161 +        SetGDevice (SDL_Display);
  1.1162 +        SetEntries (0, (**cTab).ctSize, (ColorSpec *) & (**cTab).ctTable);
  1.1163 +        SetGDevice (odisplay);
  1.1164 +    }
  1.1165 +    return (1);
  1.1166  }
  1.1167  
  1.1168 -void ROM_VideoQuit(_THIS)
  1.1169 +void
  1.1170 +ROM_VideoQuit (_THIS)
  1.1171  {
  1.1172 -	int i;
  1.1173 +    int i;
  1.1174  
  1.1175 -	/* Free current video mode */
  1.1176 -	ROM_UnsetVideoMode(this, this->screen);
  1.1177 -	if ( SDL_Window ) {
  1.1178 -		DisposeWindow(SDL_Window);
  1.1179 -		SDL_Window = nil;
  1.1180 -	}
  1.1181 +    /* Free current video mode */
  1.1182 +    ROM_UnsetVideoMode (this, this->screen);
  1.1183 +    if (SDL_Window) {
  1.1184 +        DisposeWindow (SDL_Window);
  1.1185 +        SDL_Window = nil;
  1.1186 +    }
  1.1187  
  1.1188 -	/* Free palette and restore original one */
  1.1189 -	if ( SDL_CTab != nil ) {
  1.1190 -		DisposeHandle((Handle)SDL_CTab);
  1.1191 -		SDL_CTab = nil;
  1.1192 -	}
  1.1193 -	if ( SDL_CPal != nil ) {
  1.1194 -		DisposePalette(SDL_CPal);
  1.1195 -		SDL_CPal = nil;
  1.1196 -	}
  1.1197 -	RestoreDeviceClut(GetMainDevice());
  1.1198 +    /* Free palette and restore original one */
  1.1199 +    if (SDL_CTab != nil) {
  1.1200 +        DisposeHandle ((Handle) SDL_CTab);
  1.1201 +        SDL_CTab = nil;
  1.1202 +    }
  1.1203 +    if (SDL_CPal != nil) {
  1.1204 +        DisposePalette (SDL_CPal);
  1.1205 +        SDL_CPal = nil;
  1.1206 +    }
  1.1207 +    RestoreDeviceClut (GetMainDevice ());
  1.1208  
  1.1209 -	/* Free list of video modes */
  1.1210 -	if ( SDL_modelist != NULL ) {
  1.1211 -		for ( i=0; SDL_modelist[i]; ++i ) {
  1.1212 -			SDL_free(SDL_modelist[i]);
  1.1213 -		}
  1.1214 -		SDL_free(SDL_modelist);
  1.1215 -		SDL_modelist = NULL;
  1.1216 -	}
  1.1217 +    /* Free list of video modes */
  1.1218 +    if (SDL_modelist != NULL) {
  1.1219 +        for (i = 0; SDL_modelist[i]; ++i) {
  1.1220 +            SDL_free (SDL_modelist[i]);
  1.1221 +        }
  1.1222 +        SDL_free (SDL_modelist);
  1.1223 +        SDL_modelist = NULL;
  1.1224 +    }
  1.1225  }
  1.1226  
  1.1227 +/* vi: set ts=4 sw=4 expandtab: */