Skip to content

Commit

Permalink
Reworked the GUI code.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 7, 2006
1 parent 7c3334d commit 2321629
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 140 deletions.
4 changes: 0 additions & 4 deletions fileio.h
Expand Up @@ -7,10 +7,6 @@
extern "C" {
#endif

#ifndef SUPPORT_ZIP
#define SUPPORT_ZIP 1
#endif

/*
* File i/o may go through multiple layers: the archive attached to the binary,
* then an archive in there that's being read entirely out of memory that's
Expand Down
29 changes: 15 additions & 14 deletions gui.c
Expand Up @@ -11,15 +11,15 @@ typedef struct S_PLUGINLIST
{
char *filename;
void *lib;
MojoGui *gui;
const MojoGui *gui;
MojoGuiPluginPriority priority;
struct S_PLUGINLIST *next;
} PluginList;

MojoGui *GGui = NULL;
PluginList *pluginDetails = NULL;
const MojoGui *GGui = NULL;
static PluginList *pluginDetails = NULL;

static const MojoGuiEntryPoint staticGuiPlugins[] =
static const MojoGuiEntryPoint staticGui[] =
{
#if GUI_STATIC_LINK_STDIO
MojoGuiPlugin_stdio,
Expand All @@ -37,21 +37,21 @@ static const MojoGuiEntryPoint staticGuiPlugins[] =
};


static MojoGuiPluginPriority calcGuiPriority(MojoGui *gui)
static MojoGuiPluginPriority calcGuiPriority(const MojoGui *gui)
{
static char *envr = NULL;
MojoGuiPluginPriority retval;

if (envr == NULL)
envr = getenv("MOJOSETUP_GUI");

retval = gui->priority(gui);
retval = gui->priority();

// If the plugin isn't saying "don't try me at all" then see if the
// user explicitly wants this one.
if (retval != MOJOGUI_PRIORITY_NEVER_TRY)
{
if ((envr != NULL) && (strcasecmp(envr, gui->name(gui)) == 0))
if ((envr != NULL) && (strcasecmp(envr, gui->name()) == 0))
retval = MOJOGUI_PRIORITY_USER_REQUESTED;
} // if

Expand All @@ -67,7 +67,7 @@ static PluginList *initGuiPluginsByPriority(PluginList *plugins)
PluginList *i;
for (i = plugins->next; i != NULL; i = i->next)
{
if ( (i->priority == p) && (i->gui->init(i->gui)) )
if ( (i->priority == p) && (i->gui->init()) )
return i;
} // for
} // for
Expand All @@ -81,7 +81,7 @@ static void deleteGuiPlugin(PluginList *plugin)
if (plugin != NULL)
{
if (plugin->gui)
plugin->gui->deinit(plugin->gui);
plugin->gui->deinit();
if (plugin->lib)
dlclose(plugin->lib);
if (plugin->filename)
Expand All @@ -98,10 +98,11 @@ static void loadStaticGuiPlugins(PluginList *plugins)
{
int i;
STUBBED("See FIXME above.");
for (i = 0; staticGuiPlugins[i] != NULL; i++)
for (i = 0; staticGui[i] != NULL; i++)
{
PluginList *plug;
MojoGui *gui = staticGuiPlugins[i](MOJOGUI_INTERFACE_REVISION);
const MojoGui *gui;
gui = staticGui[i](MOJOGUI_INTERFACE_REVISION, &GEntryPoints);
if (gui == NULL)
continue;
plug = xmalloc(sizeof (PluginList));
Expand Down Expand Up @@ -142,12 +143,12 @@ static PluginList *loadDynamicGuiPlugin(MojoArchive *ar)
STUBBED("abstract out dlopen!");
if (lib != NULL)
{
MojoGui *gui = NULL;
const MojoGui *gui = NULL;
MojoGuiEntryPoint entry = NULL;
entry = (MojoGuiEntryPoint) dlsym(lib, MOJOGUI_ENTRY_POINT_STR);
if (entry != NULL)
{
gui = entry(MOJOGUI_INTERFACE_REVISION);
gui = entry(MOJOGUI_INTERFACE_REVISION, &GEntryPoints);
if (gui != NULL)
{
retval = xmalloc(sizeof (PluginList));
Expand Down Expand Up @@ -196,7 +197,7 @@ static void loadDynamicGuiPlugins(PluginList *plugins)
} // loadDynamicGuiPlugins


MojoGui *MojoGui_initGuiPlugin(void)
const MojoGui *MojoGui_initGuiPlugin(void)
{
PluginList plugins;

Expand Down
126 changes: 39 additions & 87 deletions gui.h
Expand Up @@ -31,126 +31,78 @@ typedef enum
typedef struct MojoGui MojoGui;
struct MojoGui
{
// public
uint8 (*priority)(MojoGui *gui);
const char* (*name)(MojoGui *gui);
boolean (*init)(MojoGui *gui);
void (*deinit)(MojoGui *gui);
void (*msgbox)(MojoGui *gui, const char *title, const char *text);
boolean (*promptyn)(MojoGui *gui, const char *title, const char *text);

// private
void *opaque;
uint8 (*priority)(void);
const char* (*name)(void);
boolean (*init)(void);
void (*deinit)(void);
void (*msgbox)(const char *title, const char *text);
boolean (*promptyn)(const char *title, const char *text);
};

typedef const MojoGui* (*MojoGuiEntryPoint)(int revision,
const MojoSetupEntryPoints *e);

typedef MojoGui* (*MojoGuiEntryPoint)(int revision);

#ifndef BUILDING_EXTERNAL_PLUGIN
extern MojoGui *GGui;
MojoGui *MojoGui_initGuiPlugin(void);
#if !BUILDING_EXTERNAL_PLUGIN
extern const MojoGui *GGui;
const MojoGui *MojoGui_initGuiPlugin(void);
void MojoGui_deinitGuiPlugin(void);
#else

__EXPORT__ MojoGui *MOJOGUI_ENTRY_POINT(int revision);
__EXPORT__ const MojoGui *MOJOGUI_ENTRY_POINT(int revision,
const MojoSetupEntryPoints *e);

/*
* We do this as a macro so we only have to update one place, and it
* enforces some details in the plugins. Without effort, plugins don't
* support anything but the latest version of the interface.
*/
#define MOJOGUI_PLUGIN(module) \
static const char* MojoGui_##module##_name(MojoGui *gui) { return #module; } \
MojoGui *MojoGuiPlugin_##module(int revision) \
static const MojoSetupEntryPoints *entry = NULL; \
static uint8 MojoGui_##module##_priority(void); \
static const char* MojoGui_##module##_name(void) { return #module; } \
static boolean MojoGui_##module##_init(void); \
static void MojoGui_##module##_deinit(void); \
static void MojoGui_##module##_msgbox(const char *title, const char *text); \
static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2); \
const MojoGui *MojoGuiPlugin_##module(int rev, const MojoSetupEntryPoints *e) \
{ \
if (revision == MOJOGUI_INTERFACE_REVISION) { \
static MojoGui retval; \
retval.priority = MojoGui_##module##_priority; \
retval.name = MojoGui_##module##_name; \
retval.init = MojoGui_##module##_init; \
retval.deinit = MojoGui_##module##_deinit; \
retval.msgbox = MojoGui_##module##_msgbox; \
retval.promptyn = MojoGui_##module##_promptyn; \
retval.opaque = NULL; \
if (rev == MOJOGUI_INTERFACE_REVISION) { \
static const MojoGui retval = { \
MojoGui_##module##_priority, \
MojoGui_##module##_name, \
MojoGui_##module##_init, \
MojoGui_##module##_deinit, \
MojoGui_##module##_msgbox, \
MojoGui_##module##_promptyn, \
}; \
entry = e; \
return &retval; \
} \
return NULL; \
} \

#define CREATE_MOJOGUI_ENTRY_POINT(module) \
MojoGui *MOJOGUI_ENTRY_POINT(int revision) \
const MojoGui *MOJOGUI_ENTRY_POINT(int rev, const MojoSetupEntryPoints *e) \
{ \
return MojoGuiPlugin_##module(revision); \
return MojoGuiPlugin_##module(rev, e); \
} \

#endif


/*
* make some decisions about which GUI plugins to build...
* We list them all here, but some are built, some aren't. Some are DLLs,
* some aren't...
*/

// Probably want to support this always, unless explicitly overridden.
MojoGui *MojoGuiPlugin_stdio(int revision);
#ifndef SUPPORT_GUI_STDIO
#define SUPPORT_GUI_STDIO 1
#endif

// Probably want to statically link it, too.
#if SUPPORT_GUI_STDIO
# ifndef GUI_STATIC_LINK_STDIO
# define GUI_STATIC_LINK_STDIO 1
# endif
#endif


const MojoGui *MojoGuiPlugin_stdio(int rev, const MojoSetupEntryPoints *e);
// !!! FIXME (Windows code isn't actually written yet...)
// Want to support this always on Windows, unless explicitly overridden.
MojoGui *MojoGuiPlugin_windows(int revision);
#ifndef SUPPORT_GUI_WINDOWS
# if PLATFORM_WINDOWS
# define SUPPORT_GUI_WINDOWS 1
# endif
#endif

// Probably want to statically link it, too.
#if SUPPORT_GUI_WINDOWS
# ifndef GUI_STATIC_LINK_WINDOWS
# define GUI_STATIC_LINK_WINDOWS 1
# endif
#endif


const MojoGui *MojoGuiPlugin_windows(int rev, const MojoSetupEntryPoints *e);
// !!! FIXME (GTK+ code isn't actually written yet...)
// Want to support this always on non-Mac Unix, unless explicitly overridden.
MojoGui *MojoGuiPlugin_gtkplus(int revision);
#ifndef SUPPORT_GUI_GTK_PLUS
# if ((PLATFORM_UNIX) && (!PLATFORM_MACOSX))
# define SUPPORT_GUI_GTK_PLUS 1
# endif
#endif

// Probably DON'T want to statically link it.
#if SUPPORT_GUI_GTK_PLUS
# ifndef GUI_STATIC_LINK_GTK_PLUS
# define GUI_STATIC_LINK_GTK_PLUS 0
# endif
#endif

// Probably want to support this always on Mac OS X.
MojoGui *MojoGuiPlugin_macosx(int revision);
#ifndef SUPPORT_GUI_MACOSX
# if PLATFORM_MACOSX
# define SUPPORT_GUI_MACOSX 1
# endif
#endif

// Probably want to statically link it, too.
#if SUPPORT_GUI_MACOSX
# ifndef GUI_STATIC_LINK_MACOSX
# define GUI_STATIC_LINK_MACOSX 1
# endif
#endif
const MojoGui *MojoGuiPlugin_gtkplus(int rev, const MojoSetupEntryPoints *e);
const MojoGui *MojoGuiPlugin_macosx(int rev, const MojoSetupEntryPoints *e);

// !!! FIXME: Qt? KDE? Gnome? Console? Cocoa?

Expand Down
29 changes: 14 additions & 15 deletions gui/gui_macosx.c
Expand Up @@ -3,21 +3,27 @@

#if SUPPORT_GUI_MACOSX

MOJOGUI_PLUGIN(macosx)

#if !GUI_STATIC_LINK_MACOSX
CREATE_MOJOGUI_ENTRY_POINT(macosx)
#endif

#include <Carbon/Carbon.h>

// (A lot of this is stolen from MojoPatch: http://icculus.org/mojopatch/ ...)

static uint8 MojoGui_macosx_priority(MojoGui *gui)
static uint8 MojoGui_macosx_priority(void)
{
return MOJOGUI_PRIORITY_TRY_FIRST;
} // MojoGui_macosx_priority

static boolean MojoGui_macosx_init(MojoGui *gui)
static boolean MojoGui_macosx_init(void)
{
return true;
} // MojoGui_macosx_init

static void MojoGui_macosx_deinit(MojoGui *gui)
static void MojoGui_macosx_deinit(void)
{
// no-op
} // MojoGui_macosx_deinit
Expand Down Expand Up @@ -56,8 +62,7 @@ static int do_msgbox(const char *_title, const char *str, AlertType alert_type,
return(retval);
} // do_msgbox

static void MojoGui_macosx_msgbox(MojoGui *gui, const char *title,
const char *text)
static void MojoGui_macosx_msgbox(const char *title, const char *text)
{
do_msgbox(title, text, kAlertNoteAlert, NULL, NULL);
} // MojoGui_macosx_msgbox
Expand All @@ -74,8 +79,9 @@ static boolean do_promptyn(const char *title, const char *text, boolean yes)
{
DialogItemIndex item;
CFStringRef yes, no;
yes = CFStringCreateWithCString(NULL, _("Yes"), kCFStringEncodingUTF8);
no = CFStringCreateWithCString(NULL, _("No"), kCFStringEncodingUTF8);
const CFStringEncoding enc = kCFStringEncodingUTF8;
yes = CFStringCreateWithCString(NULL, entry->_("Yes"), enc);
no = CFStringCreateWithCString(NULL, entry->_("No"), enc);

params.movable = TRUE;
params.helpButton = FALSE;
Expand All @@ -95,18 +101,11 @@ static boolean do_promptyn(const char *title, const char *text, boolean yes)
} // do_promptyn


static boolean MojoGui_macosx_promptyn(MojoGui *gui, const char *title,
const char *text)
static boolean MojoGui_macosx_promptyn(const char *title, const char *text)
{
return do_promptyn(title, text, true);
}

MOJOGUI_PLUGIN(macosx)

#if !GUI_STATIC_LINK_MACOSX
CREATE_MOJOGUI_ENTRY_POINT(macosx)
#endif

#endif // SUPPORT_GUI_MACOSX

// end of gui_macosx.c ...
Expand Down

0 comments on commit 2321629

Please sign in to comment.