/*----------------------------------------------------------------------------
* $Id: walert.prg,v 1.0 2006/09/08 02:42:56 $
*
* Direct replacement for Clipper ALERT() function
*
* Copyright 2006 Ricardo Sassy <
rsassy@gmail.com>
* www -
http://www.harley.com.ar
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/*----------------------------------------------------------------------------
* FUNCTION walert( cMessage, aItems, cTitle ) ===> nValue returned
* cMessage: Message to be displayed inside ALERT frame. Can contain ";"
* character(s) to line feed efect.
* aItems : (optional) An array of choices. If empty, a "OK" button will
* be displayed and return "0" value.
* cTitle : (optional) A title for ALERT window. If empty, default to "choice" message.
*
* Function return numeric value from 1 to 4 according to button pressed
* or zero "0" value in case of interactive window close.
*
* In case of translate from original Clipper code to ooHG/Minigui code
* only replace "ALERT" word for "WALERT" word.
* Sample Clipper code : ALERT('Please;Choice output...',{'PRINTER','SCREEN'})
* Sample ooHG/Minigui code: WALERT('Please;Choice output...',{'PRINTER','SCREEN'})
* WARNING !!!!: Pay attention that function put "OFF" INTERACTIVECLOSE value before exit.
* This could be incorrect for you program structure.
/*----------------------------------------------------------------------------/*
FUNCTION walert( cMessage, aItems, cTitle )
LOCAL I:=0 , J:=0 , nStart:=1 , nValue:=0
DEFAULT aItems TO {}
DEFAULT cMessage TO ' '
IF SET( _SET_LANGUAGE )=='ES'
DEFAULT cTitle TO 'Seleccione...'
ELSE
DEFAULT cTitle TO 'Please, select'
ENDIF
cMessage := cMessage+';'
SET INTERACTIVECLOSE ON
DEFINE WINDOW walert ;
AT 0,0 ;
WIDTH 400 HEIGHT 215 ;
TITLE cTitle ;
ICON 'MAIN' ;
TOPMOST ;
NOMAXIMIZE NOSIZE ;
ON INTERACTIVECLOSE {|| nValue := 0, walert.Release }
//******************** DISPLAY MESSAGE *******************************
FOR I=1 TO LEN(cMessage)
IF SUBST(cMessage,I,1)=';'
++J
cTexLabel := 'text'+STR(J,1)
@ (J*15)-10,016 LABEL &cTexLabel WIDTH 368 HEIGHT 20 VALUE SUBST(cMessage,nStart,I-nStart) ;
FONT 'Sans serif' SIZE 10 CENTERALIGN
nStart := I+1
ENDIF
NEXT
//******************** DRAW BUTTONS ***********************************
IF LEN(aItems) <= 1
@ 150,160 BUTTON Button_1 ;
CAPTION '&OK' ;
ACTION {|| nValue := 0, walert.Release } ;
WIDTH 80
ENDIF
IF LEN(aItems) = 2
@ 150,105 BUTTON Button_1 ;
CAPTION '&'+aItems[1] ;
ACTION {|| nValue := 1, walert.Release } ;
WIDTH 80
@ 150,215 BUTTON Button_2 ;
CAPTION '&'+aItems[2] ;
ACTION {|| nValue := 2, walert.Release } ;
WIDTH 80
ENDIF
IF LEN(aItems) = 3
@ 150,055 BUTTON Button_1 ;
CAPTION '&'+aItems[1] ;
ACTION {|| nValue := 1, walert.Release } ;
WIDTH 80
@ 150,160 BUTTON Button_2 ;
CAPTION '&'+aItems[2] ;
ACTION {|| nValue := 2, walert.Release } ;
WIDTH 80
@ 150,265 BUTTON Button_3 ;
CAPTION '&'+aItems[3] ;
ACTION {|| nValue := 3, walert.Release } ;
WIDTH 80
ENDIF
IF LEN(aItems) = 4
@ 150,016 BUTTON Button_1 ;
CAPTION '&'+aItems[1] ;
ACTION {|| nValue := 1, walert.Release } ;
WIDTH 80
@ 150,112 BUTTON Button_2 ;
CAPTION '&'+aItems[2] ;
ACTION {|| nValue := 2, walert.Release } ;
WIDTH 80
@ 150,208 BUTTON Button_3 ;
CAPTION '&'+aItems[3] ;
ACTION {|| nValue := 3, walert.Release } ;
WIDTH 80
@ 150,304 BUTTON Button_4 ;
CAPTION '&'+aItems[4] ;
ACTION {|| nValue := 4, walert.Release } ;
WIDTH 80
ENDIF
END WINDOW
CENTER WINDOW walert
ACTIVATE WINDOW walert
SET INTERACTIVECLOSE OFF
RETURN(nValue)