home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
programs
/
desktop
/
newbar
/
Source
/
NewBar
/
c
/
main
< prev
next >
Wrap
Text File
|
1998-08-03
|
5KB
|
181 lines
/* main.c */
#include <stdlib.h>
#include <stdio.h>
#include "OS:menu.h"
#include "Dreamscape:task.h"
#include "Dreamscape:tboxevent.h"
#include "Dreamscape:wimpmsg.h"
#include "Dreamscape:x.h"
#ifdef MemCheck_MEMCHECK
#include "MemCheck:memcheck.h"
#endif
#ifdef HierProf_PROFILE
#include "HierProf:hierprof.h"
#endif
#include "iconbar.h"
#include "options.h"
#include "pinpatch.h"
#include "debug.h"
/* Prototypes, defines and variables */
#define ENTRY_QUIT 0x1
#define ENTRY_EDIT_OPTIONS 0x2
#define ENTRY_RELOAD_OPTIONS 0x3
#define OPTIONS_FILE "<NewIconbar$Choices>"
static bool quit_handler(const toolbox_action *event,
const toolbox_block *ids, void *handle);
static bool edit_options(const toolbox_action *event,
const toolbox_block *ids, void *handle);
static bool reload_options(const toolbox_action *event,
const toolbox_block *ids, void *handle);
static bool prequit_handler(const wimp_message *message, void *xhandle);
static void atexit_handler(void);
static bool shutdown_quit = 0;
iconbar_manager_task *iconbar_manager_this_task = 0;
thin_iconbar *the_iconbar = 0;
toolbox_o iconbar_menu = 0; /* Menu for the iconbar */
/* Initialisation and finalisation */
TaskDirectory("<NewIconbar$Dir>");
int main(int argc, char *argv[])
{
#ifdef MemCheck_MEMCHECK
MemCheck_Init();
MemCheck_InterceptSCLStringFunctions();
MemCheck_SetStoreMallocFunctions(1);
MemCheck_RegisterArgs(argc, argv);
#endif
#ifdef HierProf_PROFILE
HierProf_ProfileAllFunctions();
#endif
#ifdef DEBUG
/* Turn stderr buffering off -- I wasn't getting my debugging info! */
setvbuf(stderr, 0, _IONBF, 0);
#endif
DEBUGF("main() starting...\n");
/* Load options file. */
options = thiniconbar_options_create();
if(!options) x_throw_message(x_msg_memory());
thiniconbar_options_from_file(options, OPTIONS_FILE);
thiniconbar_options_from_cli(options, argc-1, argv+1);
/* If the first argument says --patch, we patch the Pinboard and exit. */
if(argc >= 2 && !strcmp(argv[1], "--patch")) {
patch_pinboard(options, !(argc >= 3 && !strcmp(argv[2], "--silent")));
return 0;
}
/* Create iconbar. */
the_iconbar = thiniconbar_create();
iconbar_manager_this_task = iconbar_manager_initialise(
thiniconbar_castto_arranger(the_iconbar));
/* Create our menu and attach it to the iconbar. */
iconbar_menu = toolbox_create_object(0, (toolbox_id) "MainMenu");
thiniconbar_set_menu(the_iconbar, iconbar_menu);
/* Register handlers for quitting. */
atexit(atexit_handler);
dscape_tboxevent_register_c_handler(action_MENU_SELECTION, iconbar_menu, 0,
ENTRY_QUIT, 0, quit_handler, 0);
dscape_wimpmsg_register_handler(message_PREQUIT, prequit_handler, 0);
/* Menu entry handlers */
dscape_tboxevent_register_c_handler(action_MENU_SELECTION, iconbar_menu, 0,
ENTRY_EDIT_OPTIONS, 0, edit_options, 0);
dscape_tboxevent_register_c_handler(action_MENU_SELECTION, iconbar_menu, 0,
ENTRY_RELOAD_OPTIONS, 0, reload_options, 0);
/* Let's go! */
DEBUGF("Beginning to poll\n");
dscape_task_poll_forever();
return 0;
}
static void atexit_handler(void)
{
DEBUGF("Entering main's atexit handler\n");
/* Destroy it so as to finalise properly. */
thiniconbar_destroy(the_iconbar);
iconbar_manager_finalise(iconbar_manager_this_task);
#ifdef MemCheck_MEMCHECK
thiniconbar_options_destroy(options); /* Quicker not to */
MemCheck_OutputBlocksInfo();
#endif
/* Not needed now that we can start with desktop. */
#if 0
/* If the task was quit individually, kill the IconbarPatch module.
Otherwise this was a desktop shutdown, so leave it intact to prevent
spurious errors. The type of quit is set by a Message_PreQuit or
through the program's quit menu entry. */
if(!shutdown_quit) xosmodule_kill("IconbarPatch");
#endif
DEBUGF("Finishing: goodbye!\n");
}
/* Event handlers */
static bool quit_handler(const toolbox_action *event,
const toolbox_block *ids, void *handle)
{
shutdown_quit = 0;
dscape_task_quit();
return 1;
}
static bool edit_options(const toolbox_action *event,
const toolbox_block *ids, void *handle)
{
os_cli("Filer_Run " OPTIONS_FILE);
return 1;
}
static bool reload_options(const toolbox_action *event,
const toolbox_block *ids, void *handle)
{
/* To reload options, re-create the whole iconbar at present. */
thiniconbar_destroy(the_iconbar);
iconbar_manager_finalise(iconbar_manager_this_task);
thiniconbar_options_destroy(options);
options = thiniconbar_options_create();
if(!options) x_throw_message(x_msg_memory());
thiniconbar_options_from_file(options, OPTIONS_FILE);
the_iconbar = thiniconbar_create();
iconbar_manager_this_task = iconbar_manager_initialise(
thiniconbar_castto_arranger(the_iconbar));
thiniconbar_set_menu(the_iconbar, iconbar_menu);
return 1;
}
static bool prequit_handler(const wimp_message *message, void *xhandle)
{
shutdown_quit = (message->size >= 24 &&
(~message->data.prequit.flags & wimp_PRE_QUIT_TASK_ONLY));
return 0;
}