home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
colour
/
modesel_1
/
!ModeSel
/
c
/
Main
< prev
next >
Wrap
Text File
|
1994-06-20
|
9KB
|
354 lines
#include "os.h"
#include "wimp.h"
#include "fileswitch.h"
#include "Icon_Bar.h"
#include "Menus.h"
#include "Windows.h"
#include "Modes.h"
#include "File.h"
#include "stdlib.h"
#include "kernel.h"
static osspriteop_area *sa; /* sprite area */
static wimp_i barIc; /* icon bar icon */
static int barMode; /* Current Screen Mode */
static int Opt[6];
static bool mainWindowOpen = FALSE;
void open_mode(bits *eventMask);
void update_main_window(bits *eventMask);
void handle_menu_sel(wimp_block *block, bool *finished, bits *eventMask);
void handle_message(wimp_block *block, bool *finished);
void handle_mouse_click(wimp_block *block, bits *eventMask);
void open_select(bits *eventMask);
void file_out(char *str, os_f handle);
void save_desktop (os_f handle);
void clickBar (wimp_block *block, bits *eventMask);
void clickSelect (wimp_block *block);
void clickMode (wimp_block *block);
void open_mode(bits *eventMask)
{
if(mainWindowOpen == FALSE)
{
wimp_window_state state;
state.w = get_mode();
if (got_modes()==FALSE)
{
get_all_modes();
end_modes_get(eventMask);
sort_modes(Opt[5]);
}
create_mode_icons(barMode, Opt);
wimp_get_window_state (&state);
wimp_open_window ((wimp_open *) &state);
mainWindowOpen = TRUE;
}
}
void open_select(bits *eventMask)
{
wimp_window_state state;
state.w = get_select();
if (got_modes()==FALSE)
{
get_all_modes();
end_modes_get(eventMask);
sort_modes(Opt[5]);
}
update_sel_icons(barMode);
wimp_get_window_state (&state);
wimp_open_window ((wimp_open *) &state);
}
void update_main_window(bits *eventMask)
{
if(mainWindowOpen)
{
close_mode_window(&mainWindowOpen);
open_mode(eventMask);
}
}
void handle_menu_sel(wimp_block *block, bool *finished, bits *eventMask)
{
int sel;
char selResStr[12];
switch (sel = decode_menu_sel(block))
{
case ib_refresh : start_modes_get (eventMask);
if(mainWindowOpen)
{
get_all_modes();
end_modes_get(eventMask);
sort_modes(Opt[5]);
update_main_window(eventMask);
}
break;
case ib_save : save_config(Opt);
break;
case ib_palette : _kernel_oscli("wimppalette <Modesel$dir>.palette");
break;
case ib_quit : *finished = TRUE;
break;
case opt_reinit : /* mode reinited in menu module - easier */
build_except_menu();
start_modes_get (eventMask);
if(mainWindowOpen)
{
get_all_modes();
end_modes_get(eventMask);
sort_modes(Opt[5]);
update_main_window(eventMask);
}
break;
case opt_remove : new_except(remove_no());
build_except_menu();
start_modes_get (eventMask);
if(mainWindowOpen)
{
get_all_modes();
end_modes_get(eventMask);
sort_modes(Opt[5]);
update_main_window(eventMask);
}
break;
case opt_kill_p : Opt[4] = 1- Opt[4];
break;
case col_2 :
case col_4 :
case col_16 :
case col_256 : Opt[sel-col_2] = 1- Opt[sel-col_2];
update_main_window(eventMask);
break;
case srt_mode :
case srt_X :
case srt_Y :
case srt_size :
case srt_area : Opt[5] = sel - srt_mode;
sort_modes(Opt[5]);
update_main_window(eventMask);
break;
case selCol_2 : set_sel_col(1);
get_last_res(1,selResStr);
set_sel_res(selResStr);
break;
case selCol_4 : set_sel_col(2);
get_last_res(2,selResStr);
set_sel_res(selResStr);
break;
case selCol_16 : set_sel_col(4);
get_last_res(4,selResStr);
set_sel_res(selResStr);
break;
case selCol_256 : set_sel_col(8);
get_last_res(8,selResStr);
set_sel_res(selResStr);
break;
case resMenu : get_res_str(block, selResStr); /* from menu */
set_sel_res(selResStr);
break;
}
check_redisplay();
}
void file_out(char *str, os_f handle)
{
int loop=0;
while (str[loop] != '\0')
xos_bput (str[loop++], handle);
}
void save_desktop (os_f handle)
{ char *ptr;
if ((ptr = getenv ("ModeSel$Dir")) != NULL && !EMPTY (ptr))
{
if(Opt[4]) file_out("RMkill PaletteUtil\n",handle);
file_out("Filer_Run ",handle);
file_out(ptr,handle);
}
}
void handle_message(wimp_block *block, bool *finished)
{
if (block->message.action == message_MODE_CHANGE)
{
int oldMode = barMode;
update_bar_icon(sa, &barIc, &barMode );
if (mainWindowOpen)
update_mode_icons(oldMode, barMode);
}
if ((block->message.action == message_QUIT) ||
(block->message.action == message_SHUTDOWN))
{
*finished=TRUE;
}
if (block->message.action == message_SAVE_DESKTOP)
{
save_desktop(block->message.data.save_desktop.file);
}
}
void clickBar (wimp_block *block, bits *eventMask)
{
if (block->pointer.buttons == wimp_CLICK_MENU)
show_icon_bar_menu(block->pointer.pos);
if (block->pointer.buttons == wimp_CLICK_SELECT)
open_mode(eventMask);
if (block->pointer.buttons == wimp_CLICK_ADJUST)
open_select(eventMask);
}
void clickMode (wimp_block *block)
{
if (block->pointer.buttons == wimp_CLICK_MENU)
show_options_menu(block->pointer.pos);
if ( (block->pointer.buttons == wimp_CLICK_SELECT) ||
(block->pointer.buttons == wimp_CLICK_ADJUST))
{
int mode = find_mode_clicked(block->pointer.i);
if (mode != -1)
{
wimp_set_mode ((os_mode) mode);
if (block->pointer.buttons == wimp_CLICK_SELECT)
close_mode_window(&mainWindowOpen);
}
}
}
void clickSelect (wimp_block *block)
{
if (block->pointer.i == selColMen)
show_colour_menu(block->pointer.pos);
if (block->pointer.i == selResMen)
show_res_menu(block->pointer.pos,get_sel_bpp());
if ((block->pointer.i == selCancel) && (block->pointer.buttons != wimp_CLICK_MENU))
close_select_window();
if ((block->pointer.i == selChange) && (block->pointer.buttons != wimp_CLICK_MENU))
{
wimp_set_mode ((os_mode) sel_find_mode(get_sel_bpp(), get_sel_res_str()));
if (block->pointer.buttons != wimp_CLICK_ADJUST)
close_select_window();
}
}
void handle_mouse_click(wimp_block *block, bits *eventMask)
{
if (block->pointer.w == wimp_ICON_BAR)
clickBar (block, eventMask);
else
{
if (block->pointer.w == get_mode())
clickMode (block);
else
if (block->pointer.w == get_select())
clickSelect (block);
}
}
int main (void)
{
bool finished = FALSE;
wimp_block block; /*get the block for wimp_poll()*/
int event;
int msgsList[]={ message_SAVE_DESKTOP ,
message_SHUTDOWN,
message_MODE_CHANGE ,
message_QUIT
};
bits eventMask = wimp_MASK_NULL |
wimp_MASK_LEAVING |
wimp_MASK_ENTERING |
wimp_QUEUE_MOUSE |
wimp_QUEUE_KEY |
wimp_MASK_LOSE |
wimp_MASK_GAIN ;
wimp_initialise ( wimp_VERSION_RO3, "Mode Selector",
(wimp_message_list *) msgsList,
NULL);
load_config(Opt);
init_sprites(&sa, &barMode, &barIc);
set_up_windows();
set_up_menus(Opt);
start_modes_get(&eventMask);
while (!finished)
{
xwimp_poll (eventMask, &block, NULL, &event);
switch (event)
{
case wimp_MOUSE_CLICK : handle_mouse_click(&block, &eventMask );
break;
case wimp_MENU_SELECTION : handle_menu_sel(&block,&finished, &eventMask);
break;
case wimp_OPEN_WINDOW_REQUEST : handle_open_win(&block);
break;
case wimp_CLOSE_WINDOW_REQUEST : handle_close_win(&block, &mainWindowOpen);
break;
case wimp_REDRAW_WINDOW_REQUEST : handle_redraw(&block);
break;
case wimp_NULL_REASON_CODE : if(get_modes())
{
end_modes_get(&eventMask);
sort_modes(Opt[5]);
}
break;
case wimp_USER_MESSAGE :
case wimp_USER_MESSAGE_RECORDED :
handle_message(&block,&finished);
break;
}
}
wimp_close_down ((wimp_t) 0);
return 0;
}