Skip to content

Commit

Permalink
Added initial Mac OS X gui work.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 1, 2006
1 parent c110cc8 commit 699ef2c
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 5 deletions.
3 changes: 3 additions & 0 deletions gui.c
Expand Up @@ -27,6 +27,9 @@ static const MojoGuiEntryPoint staticGuiPlugins[] =
#if GUI_STATIC_LINK_WINDOWS
MojoGuiPlugin_windows,
#endif
#if GUI_STATIC_LINK_MACOSX
MojoGuiPlugin_macosx,
#endif
#if GUI_STATIC_LINK_GTK_PLUS
MojoGuiPlugin_gtkplus,
#endif
Expand Down
16 changes: 16 additions & 0 deletions gui.h
Expand Up @@ -60,6 +60,7 @@ __EXPORT__ MojoGui *MOJOGUI_ENTRY_POINT(int revision);
* 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) \
{ \
if (revision == MOJOGUI_INTERFACE_REVISION) { \
Expand Down Expand Up @@ -136,6 +137,21 @@ MojoGui *MojoGuiPlugin_gtkplus(int revision);
# 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

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

#ifdef __cplusplus
Expand Down
101 changes: 101 additions & 0 deletions gui/gui_macosx.c
@@ -0,0 +1,101 @@
#define BUILDING_EXTERNAL_PLUGIN 1
#include "../gui.h"

#if SUPPORT_GUI_MACOSX

#include <Carbon/Carbon.h>

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

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

static void MojoGui_macosx_deinit(MojoGui *gui)
{
// no-op
} // MojoGui_macosx_deinit

static int do_msgbox(const char *_title, const char *str, AlertType alert_type,
AlertStdCFStringAlertParamRec *param,
DialogItemIndex *idx)
{
int retval = 0;
DialogItemIndex val = 0;
CFStringRef title = CFStringCreateWithBytes(NULL,
(const unsigned char *) _title,
strlen(_title),
kCFStringEncodingISOLatin1, 0);
CFStringRef msg = CFStringCreateWithBytes(NULL,
(const unsigned char *) str,
strlen(str),
kCFStringEncodingISOLatin1, 0);
if ((msg != NULL) && (title != NULL))
{
DialogRef dlg = NULL;

if (CreateStandardAlert(alert_type, title, msg, param, &dlg) == noErr)
{
RunStandardAlert(dlg, NULL, (idx) ? idx : &val);
retval = 1;
} /* if */
} /* if */

if (msg != NULL)
CFRelease(msg);

if (title != NULL)
CFRelease(title);

return(retval);
} // do_msgbox

static void MojoGui_macosx_msgbox(MojoGui *gui, const char *title,
const char *text)
{
do_msgbox(title, text, kAlertNoteAlert, NULL, NULL);
} // MojoGui_macosx_msgbox

static boolean do_promptyn(const char *title, const char *text, boolean yes)
{
OSStatus err;
DialogItemIndex item;
AlertStdCFStringAlertParamRec params;
err = GetStandardAlertDefaultParams(&params, kStdCFStringAlertVersionOne);
if (err != noErr)
return false;

params.movable = TRUE;
params.helpButton = FALSE;
params.defaultText = CFSTR("Yes"); // !!! FIXME: localize
params.cancelText = CFSTR("No");
params.defaultButton = (yes) ? kAlertStdAlertOKButton :
kAlertStdAlertCancelButton;
params.cancelButton = kAlertStdAlertCancelButton;
if (!do_msgbox(title, text, kAlertCautionAlert, &params, &item))
return false; /* oh well. */

return(item == kAlertStdAlertOKButton);
} // do_promptyn


static boolean MojoGui_macosx_promptyn(MojoGui *gui, 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 ...

5 changes: 0 additions & 5 deletions gui/gui_stdio.c
Expand Up @@ -10,11 +10,6 @@ static uint8 MojoGui_stdio_priority(MojoGui *gui)
return MOJOGUI_PRIORITY_TRY_LAST;
}

static const char* MojoGui_stdio_name(MojoGui *gui)
{
return "stdio";
}

static boolean MojoGui_stdio_init(MojoGui *gui)
{
return true;
Expand Down
10 changes: 10 additions & 0 deletions makefile
Expand Up @@ -115,6 +115,7 @@ SRCS := \
fileio.c \
archive_zip.c \
gui/gui_stdio.c \
gui/gui_macosx.c \

# !!! FIXME: Optionally strip out the parser and add-on libraries...
LUASRCS := \
Expand Down Expand Up @@ -162,6 +163,7 @@ ZLIBSRCS := \

GUIPLUGINS := \
gui_stdio \
gui_macosx \

SRCS += $(LUASRCS)

Expand Down Expand Up @@ -267,6 +269,14 @@ bin/gui/stdio$(DLLEXT): bin/gui/gui_stdio.o
$(CC) $(CFLAGS) -c -o bin/buildver.o buildver.c
$(LD) $(SHARED_LDFLAGS) -o $@ $^ $(LIBS)

.PHONY: gui_macosx
gui_macosx: bin/gui/macosx$(DLLEXT)

bin/gui/macosx$(DLLEXT): bin/gui/gui_macosx.o
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o bin/buildver.o buildver.c
$(LD) $(SHARED_LDFLAGS) -o $@ $^ $(LIBS)

bin/gui/%.o : gui/%.c
@mkdir -p $(dir $@)
$(CC) $(SHARED_CFLAGS) -c -o $@ $<
Expand Down

0 comments on commit 699ef2c

Please sign in to comment.