Skip to content

Commit

Permalink
Handle missing .nib file, etc more gracefully in Carbon UI initializa…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
icculus committed May 25, 2004
1 parent 864edfa commit 7481892
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions ui_carbon.c
Expand Up @@ -10,6 +10,7 @@
static WindowPtr window;
static ControlRef progress;
static ControlRef status;
static int carbon_ui_initialized = 0;

/* user interface stuff you implement. */
int ui_init(void)
Expand All @@ -20,18 +21,38 @@ int ui_init(void)
OSStatus err;
Boolean b = TRUE;

CreateNibReference( CFSTR("mojopatch"), &nibRef );
if (carbon_ui_initialized) /* already initialized? */
return(1);

if (CreateNibReference(CFSTR("mojopatch"), &nibRef) != noErr)
return(0); /* usually .nib isn't found. */

err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
CreateWindowFromNib( nibRef, CFSTR("MainWindow"), &window );
if (err == noErr)
err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
DisposeNibReference( nibRef );
GetControlByID(window, &statusID, &status);
GetControlByID(window, &progressID, &progress);
ShowWindow( window );
ActivateWindow(window, TRUE);
SetControlData(progress, kControlEntireControl,
kControlProgressBarAnimatingTag,
sizeof (b), &b);
return(1);

if (err == noErr)
err = GetControlByID(window, &statusID, &status);

if (err == noErr)
err = GetControlByID(window, &progressID, &progress);

if (err == noErr)
{
ShowWindow(window);
err = ActivateWindow(window, TRUE);
} /* if */

if (err == noErr)
{
err = SetControlData(progress, kControlEntireControl,
kControlProgressBarAnimatingTag,
sizeof (b), &b);
} /* if */

carbon_ui_initialized = 1;
return(err == noErr);
} /* ui_init */


Expand All @@ -46,13 +67,19 @@ void ui_title(const char *str)
void ui_deinit(void)
{
/* !!! FIXME */
/* carbon_ui_initialized = 0; */
} /* ui_deinit */


void ui_pump(void)
{
EventRef theEvent;
EventTargetRef theTarget = GetEventDispatcherTarget();
EventTargetRef theTarget;

if (!carbon_ui_initialized)
return;

theTarget = GetEventDispatcherTarget();
if (ReceiveNextEvent(0, NULL, 0, true, &theEvent) == noErr)
{
SendEventToEventTarget(theEvent, theTarget);
Expand Down Expand Up @@ -196,7 +223,10 @@ int manually_locate_product(char *buf, size_t bufsize)

void ui_fatal(const char *str)
{
do_msgbox(str, kAlertStopAlert, NULL, NULL);
if (!carbon_ui_initialized)
fprintf(stderr, "FATAL ERROR: %s\n", str);
else
do_msgbox(str, kAlertStopAlert, NULL, NULL);
} /* ui_fatal */


Expand Down

0 comments on commit 7481892

Please sign in to comment.