Native message box on MacOSX; platform-specific separation of box drivers
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3252 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Changes towards version 0.7:
|
||||
- Added a native error box for MacOSX (like we have for Windows) - Alex
|
||||
- Fix for weird colors problem on MacOSX w/ SDL 1.2.14; also improves
|
||||
overall compatibility on all platforms - Alex
|
||||
- Unix build system cleanups, fix detection of SDL, libmikmod, pthread - SvdB
|
||||
|
||||
@@ -1 +1,13 @@
|
||||
uqm_CFILES="uqmlog.c"
|
||||
|
||||
case "$HOST_SYSTEM" in
|
||||
Darwin)
|
||||
uqm_MFILES="msgbox_macosx.m"
|
||||
;;
|
||||
MINGW32*|CYGWIN*)
|
||||
uqm_CFILES="$uqm_CFILES msgbox_win.c"
|
||||
;;
|
||||
*)
|
||||
uqm_CFILES="$uqm_CFILES msgbox_stub.c"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef UQM_LOGINTERNAL_H_INCL__
|
||||
#define UQM_LOGINTERNAL_H_INCL__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern FILE *streamOut;
|
||||
|
||||
#endif /* UQM_LOGINTERNAL_H_INCL__ */
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef UQM_MSGBOX_H_INCL__
|
||||
#define UQM_MSGBOX_H_INCL__
|
||||
|
||||
extern void log_displayBox (const /*UTF-8*/char *title, int isError,
|
||||
const /*UTF-8*/char *msg);
|
||||
|
||||
#endif /* UQM_MSGBOX_H_INCL__ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "msgbox.h"
|
||||
|
||||
void
|
||||
log_displayBox (const /*UTF-8*/char *title, int isError,
|
||||
const /*UTF-8*/char *msg)
|
||||
{
|
||||
NSString *titleStr = [NSString stringWithUTF8String:title];
|
||||
NSString *msgStr = [NSString stringWithUTF8String:msg];
|
||||
|
||||
if (!titleStr || !msgStr)
|
||||
return; // Oops, out of memory?
|
||||
|
||||
if (isError)
|
||||
NSRunCriticalAlertPanel (titleStr, msgStr, nil, nil, nil);
|
||||
else
|
||||
NSRunInformationalAlertPanel (titleStr, msgStr, nil, nil, nil);
|
||||
|
||||
// titleStr and msgStr are autoreleased
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "msgbox.h"
|
||||
#include "loginternal.h"
|
||||
|
||||
void
|
||||
log_displayBox (const /*UTF-8*/char *title, int isError,
|
||||
const /*UTF-8*/char *msg)
|
||||
{
|
||||
// We do not know how to display a box. Perhaps it's done with a
|
||||
// hefty dose of pixie dust, or perhaps with a hammer and nails.
|
||||
// So just inform the user of our predicament
|
||||
fprintf (streamOut, "Do not know how to display %s box\n",
|
||||
isError ? "an error" : "a");
|
||||
|
||||
// Suppress the compiler warnings in any case.
|
||||
(void)title;
|
||||
(void)msg;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "msgbox.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
// Converts a UTF-8 string to Windows WideChar.
|
||||
// Caller is responsible for free()ing the returned string.
|
||||
static LPWSTR
|
||||
toWideChar (const /*UTF-8*/char *str)
|
||||
{
|
||||
int cch;
|
||||
LPWSTR wstr;
|
||||
|
||||
cch = MultiByteToWideChar (CP_UTF8, 0, str, -1, NULL, 0);
|
||||
if (cch == 0)
|
||||
return NULL; // failed, probably no UTF8 converter
|
||||
|
||||
wstr = malloc (cch * sizeof (WCHAR));
|
||||
if (!wstr)
|
||||
return NULL; // out of memory
|
||||
|
||||
cch = MultiByteToWideChar (CP_UTF8, 0, str, -1, wstr, cch);
|
||||
if (cch == 0)
|
||||
{ // Failed. It should not fail here if it succeeded just above,
|
||||
// but it did. Not much can be done about it.
|
||||
free (wstr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return wstr;
|
||||
}
|
||||
|
||||
void
|
||||
log_displayBox (const /*UTF-8*/char *title, int isError,
|
||||
const /*UTF-8*/char *msg)
|
||||
{
|
||||
LPWSTR swTitle = toWideChar (title);
|
||||
LPWSTR swMsg = toWideChar (msg);
|
||||
UINT uType = isError ? MB_ICONWARNING : MB_ICONINFORMATION;
|
||||
|
||||
if (swTitle && swMsg)
|
||||
MessageBoxW (NULL, swMsg, swTitle, uType);
|
||||
else // Could not convert; let's try ASCII, though it may look ugly
|
||||
MessageBoxA (NULL, msg, title, uType);
|
||||
|
||||
free (swTitle);
|
||||
free (swMsg);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
|
||||
#include "uqmlog.h"
|
||||
#include "loginternal.h"
|
||||
#include "msgbox.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@@ -48,14 +50,13 @@ static volatile bool noThreadReady = false;
|
||||
static bool showBox = true;
|
||||
static bool errorBox = true;
|
||||
|
||||
static FILE *streamOut;
|
||||
FILE *streamOut;
|
||||
|
||||
static volatile int qlock = 0;
|
||||
static Mutex qmutex;
|
||||
|
||||
static void exitCallback (void);
|
||||
static void displayLog (bool isError);
|
||||
static void displayBox (const char *title, bool isError, const char *msg);
|
||||
|
||||
static void
|
||||
lockQueue (void)
|
||||
@@ -324,45 +325,6 @@ displayLog (bool isError)
|
||||
|
||||
*p = '\0';
|
||||
|
||||
displayBox ("The Ur-Quan Masters", isError, msgBuf);
|
||||
log_displayBox ("The Ur-Quan Masters", isError, msgBuf);
|
||||
}
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
|
||||
extern int __stdcall MessageBoxA (void *hWnd, const char* lpText,
|
||||
const char* lpCaption, uint32 uType);
|
||||
|
||||
#define MB_ICONEXCLAMATION 0x00000030L
|
||||
#define MB_ICONASTERISK 0x00000040L
|
||||
|
||||
static void
|
||||
displayBox (const char *title, bool isError, const char *msg)
|
||||
{
|
||||
MessageBoxA (0, msg, title,
|
||||
isError ? MB_ICONEXCLAMATION : MB_ICONASTERISK);
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
static void
|
||||
displayBox (const char *title, bool isError, const char *msg)
|
||||
{
|
||||
(void) title;
|
||||
(void) isError;
|
||||
(void) msg;
|
||||
// do something here
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
displayBox (const char *title, bool isError, const char *msg)
|
||||
{
|
||||
(void) title;
|
||||
(void) isError;
|
||||
(void) msg;
|
||||
// do nothing here
|
||||
}
|
||||
|
||||
#endif /* OS disjunction */
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _UQMLOG_H
|
||||
#define _UQMLOG_H
|
||||
#ifndef UQMLOG_H_INCL__
|
||||
#define UQMLOG_H_INCL__
|
||||
|
||||
#include "port.h"
|
||||
#include "types.h"
|
||||
@@ -56,5 +56,4 @@ extern void log_add_nothreadV (log_Level, const char *fmt, va_list)
|
||||
VPRINTF_FUNCTION(2);
|
||||
|
||||
|
||||
#endif /* _UQMLOG_H */
|
||||
|
||||
#endif /* UQMLOG_H_INCL__ */
|
||||
|
||||
Reference in New Issue
Block a user