/* FILE: XCONTROL.C *========================================================================== * DATE: January 16, 1990 * DESCRIPTION: * * INCLUDE FILES: XCONTROL.H * XCONTRL2.H */ /* INCLUDE FILES *========================================================================== */ #include #include #include #include "country.h" #include "xcontrol.rsh" #include "xcontrol.h" #include "cpxdata.h" /* Keep these in order */ #include "xstructs.h" #include "cpxhandl.h" /* Cpxhandl Prototypes */ #include "slots.h" #include "fixrsh.h" /* Fixrsh Prototypes */ #include "popstuff.h" /* Popup Prototypes */ #include "sliders.h" /* Slider Prototypes */ #include "timedate.h" /* TimeDate Prototypes */ #include "xconfig.h" /* Xconfig Prototypes */ #include "xform_do.h" /* xformdo prototypes */ #include "windows.h" #include "xerror.h" #include "stuffptr.h" #include "xoptions.h" #include "cookie.h" #include "mover.h" #include "text.h" /* * TURN OFF Turbo C "parameter X is never used" warnings */ #pragma warn -par /* PROTOTYPES *========================================================================== */ void init_slider( void ); void handle_slider( int obj ); void draw_slider( void ); BOOLEAN AES_Check( void ); /* DEFINES *========================================================================== */ #define AES_VERSION 0x300 /* AES Version 3.01 */ /* GLOBALS *========================================================================== */ int ctrl_id; /* ACC id slot # */ int cur_slot = 0; /* Current top slot index into nodex*/ int old_slot = 0; /* Old Slot for when moving sliders */ int Event1_Mask = ( MU_BUTTON | MU_MESAG | MU_KEYBD | MU_TIMER ); int Event2_Mask = ( MU_MESAG ); int nplanes; /* FUNCTIONS *========================================================================== */ /* open_vwork(); *========================================================================== * Open the Virtual Workstation */ void open_vwork( void ) { int i; work_in[0] = Getrez()+2; /* let's not gag GDOS */ for( i = 1; i < 10; work_in[i++] = 1 ) ; work_in[10] = 2; /* raster coordinates */ vhandle = phys_handle; v_opnvwk( work_in, &vhandle, work_out ); xres = work_out[0]; yres = work_out[1]; } /* close_vwork(); *========================================================================== * Close the virtual workstation */ void close_vwork( void ) { if( vhandle != -1 ) { v_clsvwk( vhandle ); vhandle = -1; } } /* rsrc_init() *========================================================================== * Initialize resource and xcpb structure * * IN: void * OUT: BOOLEAN - We, uh, always return TRUE... * * GLOBALS: All of the rsh variables for the fixup... * XCPB xcpb: xcpb structure for passing to the cpx */ BOOLEAN rsrc_init(void) { fix_rsh( NUM_OBS, NUM_FRSTR, NUM_FRIMG, NUM_TREE, rs_object, rs_tedinfo, rs_strings, rs_iconblk, rs_bitblk, rs_frstr, rs_frimg, rs_trindex, rs_imdope ); vq_extnd( phys_handle, 1 , work_out ); nplanes = work_out[4]; /* * XCPB CPX Data Structure XCONTROL inits go here ... */ xcpb.handle = phys_handle; xcpb.booting = TRUE; /* TRUE = cold boot init */ /* FALSE = warm boot init */ xcpb.SkipRshFix = FALSE; /* Will Skip FixRsh only if */ /* Executing from resident */ xcpb.res1 = Get_Head_Node; xcpb.res2 = Save_Header; xcpb.rsh_fix = fix_rsh; xcpb.rsh_obfix = Rsrc_obfix; xcpb.Popup = Pop_Up; xcpb.Sl_size = sl_size; xcpb.Sl_x = sl_x; xcpb.Sl_y = sl_y; xcpb.Sl_arrow = sl_arrow; xcpb.Sl_dragx = sl_dragx; xcpb.Sl_dragy = sl_dragy; xcpb.Xform_do = xform_do; xcpb.GetFirstRect = GetFirstRect; xcpb.GetNextRect = GetNextRect; xcpb.Set_Evnt_Mask = SetEvntMask; xcpb.XGen_Alert = XGen_Alert; xcpb.CPX_Save = CPX_Save; xcpb.Get_Buffer = Get_Buffer; xcpb.getcookie = Get_Cookie; /* These are the country codes returned to the * CPX(s). They can be found on page 63 of the Rainbow * TOS Release Notes */ #if USA xcpb.Country_Code = 0; #endif #if UK xcpb.Country_Code = 3; #endif #if GERMAN xcpb.Country_Code = 1; #endif #if FRENCH xcpb.Country_Code = 2; #endif #if SPAIN xcpb.Country_Code = 4; #endif #if SWEDEN xcpb.Country_Code = 6; #endif #if ITALY xcpb.Country_Code = 5; #endif xcpb.MFsave = MFsave; /* if AES > 3.01, use only 2 menu items, not 3 */ if( AES_Check() ) num_xoptions = XOPT_NOCPX = XOPT1_NOCPX; else num_xoptions = XOPT_NOCPX = XOPT2_NOCPX; return(TRUE); } /* wind_init() *========================================================================== * Initialize window structure */ void wind_init(void) { if( !_app ) ctrl_id = menu_register( gl_apid, Menu_Text ); init_window(); get_defaults(); init_time(); graf_mouse( BUSYBEE, 0L ); init_cpxs(); graf_mouse( ARROW, 0L ); fsel_init(); linea_init(); xcpb.booting = FALSE; if( _app ) { open_window(); init_slider(); assign_slots( hdptr ); } } /* evnt_init() *========================================================================== * Initialize the event_multi with the proper messages, timers etc... */ void evnt_init(void) { /* evnt_set( Event1_Mask, 2, 1, 1, NULL, NULL, 30000L );*/ /* We are looking ONLY for evnt messages - ACC_OPEN and ACC_CLOSE */ evnt_set( Event2_Mask, -1, -1, -1, NULL, NULL, -1L ); if( _app ) evnt_set( Event1_Mask, 2, 1, 1, NULL, NULL, 30000L ); } /* do_windows() *========================================================================== * window handling... * * IN: int *msg: message buffer * int *event: flag to end the program * * OUT: void */ void do_windows( int *msg, int *event ) { switch( msg[0] ) { case WM_REDRAW: Wm_Redraw( msg ); break; case WM_NEWTOP: case WM_TOPPED: Wm_Topped( msg ); break; case WM_CLOSED: Wm_Closed( msg ); break; case WM_MOVED: Wm_Moved( msg ); break; default: break; } } /* acc_open() *========================================================================== * Accessory Open Messages * * IN: int *msg: message buffer * OUT: void * * GLOBAL: WINFO w: window structure * int ctrl_id: application id */ void acc_open( const int *msg ) { if( msg[4] == ctrl_id ) { if( hdptr ) { if( w.id == NO_WINDOW ) { if( open_window()) { evnt_set( Event1_Mask, 2, 1, 1, NULL, NULL, 30000L ); init_slider(); assign_slots( hdptr ); update_time(); clear_active_slot( FALSE ); SetCPXstate( CPX_INACTIVE ); } } else wind_set( w.id, WF_TOP ); } else form_alert( 1, Shut_String ); } } /* acc_close() *========================================================================== * Accessory Close message * * IN: int *msg: message buffer * OUT: void * * GLOBAL: int ctrl_id: application id * WINFO w: window structure * * Closing and deleting the window are unnecessary since the window * handles are already invalid by the time we get the acc_close() message */ void acc_close( const int *msg ) { if(( msg[3] == ctrl_id ) && ( w.id != NO_WINDOW ) ) { w.id = NO_WINDOW; clear_active_slot( FALSE ); close_xconfig( TRUE ); Close_Call_CPX( TRUE ); Shut_CPX_Down( FALSE ); evnt_set( Event2_Mask, -1, -1, -1, NULL, NULL, -1L ); } } /* do_button() *========================================================================== * Button handling routines * * IN: MRETS *mrets: mouse information * int nclicks: number of clicks; * int *event: flag to end program * * OUT: void * * GLOBAL: int xconfig: which xconfig option active? -1 if none * WINFO w: window structure */ void do_button( MRETS *mrets, int nclicks, int *event ) { OBJECT *tree = ( OBJECT *)rs_trindex[ XCONTROL ]; int top_window; int obj; if( w.id == NO_WINDOW ) return; wind_get( w.id, WF_TOP, &top_window ); if( w.id == top_window ) { if( IsCPXActive() ) { cpx_button( mrets, nclicks ); return; } obj = objc_find( tree, XCONTROL, MAX_DEPTH, mrets->x, mrets->y ); if( ( obj == TIME ) || ( obj == DATE ) ) { clear_active_slot( TRUE ); time_date_stamp( obj ); } if( !IsXconfigActive() ) { obj = objc_find( tree, XCONTROL, MAX_DEPTH, mrets->x, mrets->y ); switch( obj ) { case XOPTIONS: xoptions( obj ); clear_active_slot( !IsXconfigActive() ); break; case SLOT0: case SLOT1: case SLOT2: case SLOT3: handle_cpx( obj, nclicks ); break; case UARROW: case DARROW: case SLIDER: case BASE: handle_slider( obj ); break; default: clear_active_slot( TRUE ); break; } } else Xconfig_buttons( mrets ); } } /* do_timer() *========================================================================== */ void do_timer( int *event ) { if( !IsCPXActive() ) time_handle(); else cpx_timer(); } /* do_key() *========================================================================== */ void do_key( int kstate, int key, int *event ) { int top_window; int msg[8]; if( w.id == NO_WINDOW ) return; wind_get( w.id, WF_TOP, &top_window ); if( w.id == top_window ) { if( !IsCPXActive() && !IsXconfigActive() ) { if( ( key & 0xff ) == '\r') { msg[0] = WM_CLOSED; msg[1] = ctrl_id; msg[2] = 0; msg[3] = w.id; Wm_Closed( msg ); } } else { Xkeys_config( key ); cpx_key( kstate, key ); } } } /* do_m1() *========================================================================== */ void do_m1( MRETS *mrets, int *event ) { cpx_m1( mrets ); } /* do_m2() *========================================================================== */ void do_m2( MRETS *mrets, int *event ) { cpx_m2( mrets ); } /* evnt_hook() *========================================================================== * OUT: BOOLEAN - return true if one wants to skip event_multi processing */ BOOLEAN evnt_hook( int event, int *msg, MRETS *mrets, int *key, int *nclicks ) { return( cpx_hook( event, msg, mrets, key, nclicks ) ); } /* handle_slider() *========================================================================== * Slider manipulation routines for XCONTROL.ACC * * IN: int obj: slider object * OUT: void * * GLOBAL: int num_active: number of active cpxs * int cur_slot: current value of the slider */ void handle_slider( int obj ) { OBJECT *tree = ( OBJECT *)rs_trindex[ XCONTROL ]; MRETS mk; int ox,oy; clear_active_slot( TRUE ); old_slot = cur_slot; /* The slider code for vertical sliders have the zero at the bottom * and max numbers at the top. Since our vertical slider is the * other way around ( low on top, max on bottom ), we must swap * the min and max numbers, plus, swap the sign of the incrementing * and decrementing numbers. */ switch( obj ) { case UARROW: sl_arrow( tree, BASE, SLIDER, UARROW, -1, max( num_active - MAX_SLOTS, 0 ), 0, &cur_slot, VERTICAL, draw_slider ); break; case DARROW: sl_arrow( tree, BASE, SLIDER, DARROW, 1, max( num_active - MAX_SLOTS, 0 ), 0, &cur_slot, VERTICAL, draw_slider ); break; case SLIDER: MFsave( MFSAVE, &mfOther ); graf_mouse( FLAT_HAND, 0L ); sl_dragy( tree, BASE, SLIDER, max( num_active - MAX_SLOTS, 0 ), 0, &cur_slot, draw_slider ); MFsave( MFRESTORE, &mfOther ); break; case BASE: Graf_mkstate( &mk ); objc_offset( tree, SLIDER, &ox, &oy ); ox = ( ( mk.y < oy )?( -MAX_SLOTS ):( MAX_SLOTS ) ); sl_arrow( tree, BASE, SLIDER, -1, ox, max( num_active- MAX_SLOTS, 0 ), 0, &cur_slot, VERTICAL, draw_slider ); break; default: break; } } /* draw_slider() *========================================================================== * Redraw XCONTROL slider due to scrolling * * IN: the stuff for redrawing stupid...:-) * OUT: void * * GLOBAL: int cur_slot: Current value of the slider. We can use this * because it hasn't yet been updated with value. * cur_slot, in draw_slider(), is really the * OLD value. :-) */ void draw_slider( void ) { slot_offset_adjust( cur_slot ); blit_slots( old_slot, cur_slot ); old_slot = cur_slot; } /* init_slider() *========================================================================== * Initialize the slider by setting the ROOT Y coordinate and sizing the * slider. * * GLOBAL: int cur_slot: current value of the slider. */ void init_slider( void ) { OBJECT *tree = ( OBJECT *)rs_trindex[ XCONTROL ]; ObY( SLIDER ) = cur_slot = 0; sl_size( tree, BASE, SLIDER, num_active, MAX_SLOTS, VERTICAL, 0 ); } /* AES_Check() *========================================================================== * If the Current AES version number that this system is running on is * > 3.01 or AES_VERSION, we will not display the shutdown flag. */ BOOLEAN AES_Check( void ) { return( AES_Version >= AES_VERSION ); }