#include "Gui.ch" //--------------------------------------------------------------------------// //--------------------------------------------------------------------------// ****************** FUNCIO xMessageDlg() ******************** //--------------------------------------------------------------------------// //--------------------------------------------------------------------------// #define N_SI 1 #define N_NO 2 #define N_ACEPTAR 3 #define N_CANCELAR 4 #define N_REINTENTAR 5 #define N_IGNORAR 6 Function xMessageDlg( cMessage, nType, nButtonType, poPosition, cTitle, aCaptionButtons, nIDI, nBtn ) Local oForm, oLabel, oImage, oButton1, oButton2, oButton3, nWidth, nHeight, nButtons local oOwner If aCaptionButtons == Nil aCaptionButtons := {} Endif If Len( aCaptionButtons ) == 0 Aadd( aCaptionButtons, "&Si" ) Endif If Len( aCaptionButtons ) == 1 Aadd( aCaptionButtons, "&No" ) Endif If Len( aCaptionButtons ) == 2 Aadd( aCaptionButtons, "&Aceptar" ) Endif If Len( aCaptionButtons ) == 3 Aadd( aCaptionButtons, "&Cancelar" ) Endif If Len( aCaptionButtons ) == 4 Aadd( aCaptionButtons, "&Reintentar" ) Endif If Len( aCaptionButtons ) == 5 Aadd( aCaptionButtons, "&Ignorar" ) Endif oForm := TForm():Create( oOwner ) oForm:OnClose := { | nAction | nAction := caFree } oLabel := TLabel():Create( oForm ) oLabel:SetPos( 54, 17 ) oImage := TImage():Create( oForm ) oImage:SetPos( 10, 10 ) oButton1 := TButton():Create( oForm ) oButton2 := TButton():Create( oForm ) oButton3 := TButton():Create( oForm ) If nType == mtCustom oForm:BorderStyle := bsNone nHeight := 74 Else oForm:BorderStyle := bsDialog nHeight := 115 EndIf oLabel:Caption := cMessage nWidth := 72 + oLabel:Width Do Case Case nType == mtWarning oForm:Caption := If( Empty( cTitle ), "Aviso", cTitle ) oImage:Picture:Icon:Name := If( nIDI == Nil, IDI_EXCLAMATION, nIDI ) Case nType == mtError oForm:Caption := If( Empty( cTitle ), "Error", cTitle ) oImage:Picture:Icon:Name := If( nIDI == Nil, IDI_HAND, nIDI ) Case nType == mtInformation oForm:Caption := If( Empty( cTitle ), "Información", cTitle ) oImage:Picture:Icon:Name := If( nIDI == Nil, IDI_ASTERISK, nIDI ) Case nType == mtConfirmation oForm:Caption := If( Empty( cTitle ), "Confirmación", cTitle ) oImage:Picture:Icon:Name := If( nIDI == Nil, IDI_QUESTION, nIDI ) Case nType == mtCustom oImage:Picture:Icon:Name := If( nIDI == Nil, IDI_QUESTION, nIDI ) EndCase Do Case Case nButtonType == mbYes oButton1:Caption := aCaptionButtons[ N_SI ] oButton1:Cancel := .T. oButton1:ModalResult := mrYes nButtons := 1 Case nButtonType == mbYesNo oButton1:Caption := aCaptionButtons[ N_SI ] oButton1:Cancel := .F. oButton1:ModalResult := mrYes oButton2:Caption := aCaptionButtons[ N_NO ] oButton2:Cancel := .T. oButton2:ModalResult := mrNo nButtons := 2 Case nButtonType == mbYesNoCancel oButton1:Caption := aCaptionButtons[ N_SI ] oButton1:Cancel := .F. oButton1:ModalResult := mrYes oButton2:Caption := aCaptionButtons[ N_NO ] oButton2:Cancel := .F. oButton2:ModalResult := mrNo oButton3:Caption := aCaptionButtons[ N_CANCELAR ] oButton3:Cancel := .T. oButton3:ModalResult := mrCancel nButtons := 3 Case nButtonType == mbOk oButton1:Caption := aCaptionButtons[ N_ACEPTAR ] oButton1:Cancel := .T. oButton1:ModalResult := mrOk nButtons := 1 Case nButtonType == mbOkCancel oButton1:Caption := aCaptionButtons[ N_ACEPTAR ] oButton1:Cancel := .F. oButton1:ModalResult := mrOk oButton2:Caption := aCaptionButtons[ N_CANCELAR ] oButton2:Cancel := .T. oButton2:ModalResult := mrCancel nButtons := 2 Case nButtonType == mbAbortRetryIgnore oButton1:Caption := aCaptionButtons[ N_CANCELAR ] oButton1:Cancel := .F. oButton1:ModalResult := mrAbort oButton2:Caption := aCaptionButtons[ N_REINTENTAR ] oButton2:Cancel := .F. oButton2:ModalResult := mrRetry oButton3:Caption := aCaptionButtons[ N_IGNORAR ] oButton3:Cancel := .T. oButton3:ModalResult := mrIgnore nButtons := 3 OtherWise nButtons := 0 EndCase Do Case Case nButtons == 0 oButton1:Visible := .F. oButton2:Visible := .F. oButton3:Visible := .F. nWidth += 4 nHeight -= 26 Case nButtons == 1 oButton1:Visible := .T. oButton2:Visible := .F. oButton3:Visible := .F. If nWidth < 120 nWidth := 120 EndIf oButton1:SetPos( Int( ( nWidth - 70 ) / 2 ) - 3, 51 ) Case nButtons == 2 oButton1:Visible := .T. oButton2:Visible := .T. oButton3:Visible := .F. If nWidth < 76 * 2 + 80 nWidth := 76 * 2 + 80 EndIf oButton1:SetPos( Int( ( nWidth - 140 ) / 16 ) * 5 - 3, 51 ) oButton2:SetPos( nWidth - ( Int( ( nWidth - 140 ) / 16 ) * 5 - 3 ) - 77, 51 ) Case nButtons == 3 oButton1:Visible := .T. oButton2:Visible := .T. oButton3:Visible := .T. If nWidth < 76 * 3 + 80 nWidth := 76 * 3 + 80 EndIf oButton1:SetPos( Int( ( nWidth - 140 ) / 20 ) * 5 - 3, 51 ) oButton2:SetPos( Int( ( nWidth - 70 ) / 2 ) - 3, 51 ) oButton3:SetPos( nWidth - ( Int( ( nWidth - 140 ) / 20 ) * 5 - 3 ) - 77, 51 ) EndCase oForm:OnEnter := {|| If( nBtn == Nil .or. nBtn == 1, oButton1:SetFocus(), If( nBtn == 2, oButton2:SetFocus(), oButton3:SetFocus() ) ) } oForm:SetSize( nWidth, nHeight ) oForm:Position := If( poPosition == Nil, poScreenCenter, poPosition ) //poActiveCenter oForm:ShowModal() Application:ProcessMessages() If nType == mtCustom oForm:Close() Return oForm Else oForm:Destroy() EndIf Return oForm:ModalResult