home *** CD-ROM | disk | FTP | other *** search
- /* g4button.c Button Area Routines (c)Copyright Sequiter Software Inc., 1991. All rights reserved. */
-
- #include "c4window.h"
- #include "e4error.h"
-
- #ifdef __TURBOC__
- #pragma hdrstop
- #endif
-
- int button4_process_message( G4BUTTON *button, WORD message, WORD wParam,
- LONG lParam )
- {
- switch( message )
- {
- case WM_CHAR:
- switch( wParam )
- {
- case VK_SPACE:
- return button4_process_message( button, WM_LBUTTONUP, 0, 0 ) ;
-
- case VK_RETURN:
- if ( (button->ButtonType == BS_PUSHBUTTON) ||
- (button->ButtonType == BS_DEFPUSHBUTTON) )
- return button4_process_message( button, WM_LBUTTONUP, 0, 0 ) ;
- else
- {
- G4CONTROL *ca1 ;
- L4LIST *list = &button->ca.ew->ControlList ;
- for ( ca1 = 0 ; ca1 = (G4CONTROL *) l4next( list, ca1 ) ; )
- if ( ca1->is_default == 1 )
- return button4_process_message( (G4BUTTON *) ca1->area, WM_CHAR, VK_RETURN, 0 ) ;
- return 1 ;
- }
- }
- break ;
-
- case WM_LBUTTONUP:
- {
- char text[7] ;
- GetWindowText( g4handle( button ), text, 7 ) ;
- text[6] = 0 ;
- if ( memcmp( AnsiUpper( text ), AnsiUpper( E4_MESSAG_CAN ), 6 ) != 0 )
- if ( control4_ok( button->ca.ew, 1 ) != 0 ) return 1 ;
-
- if ( ! u4ptr_equal( (void *) 0, (void *) button->routine ) )
- {
- int rc = (*button->routine)( button ) ;
- if ( rc == c4cancel )
- {
- control4_process_message( &button->ca, WM_CHAR, VK_ESCAPE, 0 ) ;
- return 0 ;
- }
- if ( rc != 0 )
- {
- control4_process_message( &button->ca, WM_CHAR, VK_RETURN, 0 ) ;
- if ( button->ca.ew->return_code == VK_RETURN )
- button->ca.ew->return_code = rc ;
- }
- return 0 ;
- }
- }
- break ;
-
- case WM_LBUTTONDOWN:
- if ( control4_ok( button->ca.ew, 1 ) != 0 ) return 1 ;
- break ;
- }
- return control4_process_message( &button->ca, message, wParam, lParam ) ;
- }
-
- void button4_construct( G4BUTTON *button, W4ENTRY *ew )
- {
- control4_construct( &button->ca, ew ) ;
-
- button->ca.gw.OldWindowProc = 0 ;
- button->ca.gw.Id = 0 ;
- button->ca.hParent = 0 ;
- button->ca.area_type = c4button ;
- button->ca.area = (void *) button ;
-
- button->ButtonType = -1 ;
- button->routine = 0 ;
- button->routine_data = 0 ;
- button->isChecked = 0 ;
- button->internal = 0 ;
- }
-
- G4BUTTON *button4_create( W4ENTRY *ew, C4CONTROLITEM *control, char *text,
- int low, int high )
- {
- char *txt ;
- G4BUTTON *ba ;
- BYTE low_byte ;
-
- int len = lstrlen( text ) ;
- txt = (char *) u4alloc( len+1 ) ;
- if ( txt == 0 )
- {
- e4error( w4cb( ew ), e4memory, (char *) 0 ) ;
- return 0 ;
- }
- u4ncpy( txt, text, len+1 ) ;
-
- ba = (G4BUTTON *) u4alloc( sizeof(G4BUTTON) ) ;
- if ( ba == 0 )
- {
- e4error( w4cb( ew ), e4memory, (char *) 0 ) ;
- u4free( txt ) ;
- return 0 ;
- }
- button4_construct( ba, ew ) ;
- l4add( &ew->ControlList, (void *) &ba->ca ) ;
-
- if ( LOBYTE( LOWORD( control->Style )) == BS_GROUPBOX )
- ba->ca.gw.Style = control->Style | WS_VISIBLE ;
- else
- ba->ca.gw.Style = control->Style | WS_VISIBLE | WS_TABSTOP ;
-
- if ( low < 0 )
- ba->ca.gw.hWindow = w4create_window( "Button", text, control->Style,
- control->X, control->Y,
- control->CX, control->CY,
- w4handle( ew ), control->Id, w4hInst( ew ), 0 ) ;
- else
- ba->ca.gw.hWindow = w4create_window( "Button", text, control->Style,
- (control->X*low)/4, (control->Y*high)/8,
- (control->CX*low)/4, (control->CY*high)/8,
- w4handle( ew ), control->Id, w4hInst( ew ), 0 ) ;
-
- ba->ca.gw.OldWindowProc = (FARPROC) GetWindowLong( ba->ca.gw.hWindow,
- GWL_WNDPROC ) ;
- SetWindowLong( ba->ca.gw.hWindow, GWL_WNDPROC, (LONG) ew->gw.cw->button4_proc ) ;
-
- txt = AnsiUpper( txt ) ;
- if ( memcmp( txt, E4_MESSAG_OK, 2 ) == 0 )
- {
- g4button_function_work( ba, (S4BUTTON *) button4_okproc, (void *) 0 ) ;
- ba->internal = 1 ;
- ba->ButtonType = BS_PUSHBUTTON ;
- }
- if ( memcmp( txt, AnsiUpper( E4_MESSAG_CAN ), 6 ) == 0 )
- {
- g4button_function_work( ba, (S4BUTTON *) button4_cancelproc, (void *) 0 ) ;
- ba->internal = 1 ;
- ba->ButtonType = BS_PUSHBUTTON ;
- }
- u4free( txt ) ;
-
- low_byte = LOBYTE( LOWORD( control->Style )) ;
- if ( low_byte == BS_PUSHBUTTON )
- ba->ButtonType = BS_PUSHBUTTON ;
-
- if ( low_byte == BS_DEFPUSHBUTTON )
- {
- ba->ca.is_default = 1 ;
- ba->ButtonType = BS_DEFPUSHBUTTON ;
- }
-
- ba->ca.hParent = ew->gw.hWindow ;
- ba->ca.ew = ew ;
- ba->ca.gw.Id = control->Id ;
- ba->ca.gw.cw = ew->gw.cw ;
-
- return ba ;
- }
-
- G4BUTTON *S4FUNCTION g4button_work( W4ENTRY *ew, long style, int x, int y, int width,
- int height, char *text, S4BUTTON *routine, void *routine_data )
- {
- G4BUTTON *button ;
- C4CONTROLITEM control ;
-
- #ifdef S4DEBUG
- if ( ew == 0 )
- e4severe( e4parm, "g4button()", E4_PARM_ZER, (char *) 0 ) ;
- #endif
-
- if ( ew->gw.cw->cb.error_code < 0 ) return 0 ;
-
- control.X = x ;
- control.Y = y ;
- control.CX = width ;
- control.CY = height ;
-
- if ( LOBYTE( LOWORD( style )) == BS_GROUPBOX )
- control.Style = style | WS_CHILD | WS_VISIBLE ;
- else
- control.Style = style | WS_TABSTOP | WS_CHILD | WS_VISIBLE ;
-
- control.Id = entry4_nextid( ew ) ;
-
- button = button4_create( ew, &control, text, -1, -1 ) ;
- if ( button == 0 ) return 0 ;
- g4button_function_work( button, routine, routine_data ) ;
-
- return button ;
- }
-
- G4BUTTON *S4FUNCTION g4button_ok( W4ENTRY *ew, int x, int y )
- {
- return g4button_work( ew, BS_DEFPUSHBUTTON, x, y, 100, 24, E4_MESSAG_OK,
- (S4BUTTON *) button4_okproc, (void *) 0 ) ;
- }
-
- G4BUTTON *S4FUNCTION g4button_cancel( W4ENTRY *ew, int x, int y )
- {
- return g4button_work( ew, BS_PUSHBUTTON, x, y, 100, 24, E4_MESSAG_CAN,
- (S4BUTTON *) button4_cancelproc, (void *) 0 ) ;
- }
-
- int S4CALL button4_okproc( G4BUTTON *button )
- {
- return c4return ;
- }
-
- int S4CALL button4_cancelproc( G4BUTTON *button )
- {
- return c4cancel ;
- }
-
- void S4FUNCTION g4button_function_work( G4BUTTON *button, S4BUTTON *function,
- void *function_data )
- {
- #ifdef S4DLL
- if ( button->internal == 0 )
- {
- if ( ! u4ptr_equal( (void *) 0, (void *) button->routine ))
- FreeProcInstance( (FARPROC) button->routine ) ;
- }
- else
- button->internal=0 ;
- #endif
-
- button->routine = function ;
- button->routine_data = function_data ;
- }
-
- void *S4FUNCTION g4button_data( G4BUTTON *button )
- {
- return (void *) button->routine_data ;
- }
-
- void S4FUNCTION g4button_save( G4BUTTON *button )
- {
- if ( button->isChecked != 0 )
- {
- int rc = SendMessage( g4handle( button ), BM_GETCHECK, 0, 0 ) ;
- *button->isChecked = ( rc == 0 ) ? 0 : 1 ;
- }
- }
-
- void S4FUNCTION g4button_buffer( G4BUTTON *button, int *checked )
- {
- SendMessage( button->ca.gw.hWindow, BM_SETCHECK, *checked, 0L ) ;
- button->isChecked = checked ;
- }
-