浏览代码

UPD: DialogAPI - MsgChoiceBox function

(cherry picked from commit 1fdccb4e36f68c8e922b2f21d767ccadad0988a8)
Alexander Koblov 1 年之前
父节点
当前提交
ab6c5c9316
共有 7 个文件被更改,包括 38 次插入22 次删除
  1. 1 1
      sdk/extension.h
  2. 1 1
      sdk/extension.pas
  3. 1 0
      src/fMsg.pas
  4. 3 3
      src/fdialogbox.pas
  5. 1 1
      src/filesources/gio/ugiofilesource.pas
  6. 30 15
      src/uShowMsg.pas
  7. 1 1
      src/uextension.pas

+ 1 - 1
sdk/extension.h

@@ -104,7 +104,7 @@ typedef intptr_t (DCPCALL *tDlgProc)(uintptr_t pDlg, char* DlgItemName, intptr_t
 /* Definition of callback functions called by the DLL */
 typedef BOOL (DCPCALL *tInputBoxProc)(char* Caption, char* Prompt, BOOL MaskInput, char* Value, int ValueMaxLen);
 typedef int (DCPCALL *tMessageBoxProc)(char* Text, char* Caption, long Flags);
-typedef int (DCPCALL *tMsgChoiceBoxProc)(char* Text, char* Caption, char** Buttons);
+typedef int (DCPCALL *tMsgChoiceBoxProc)(char* Text, char* Caption, char** Buttons, int BtnDef, int BtnEsc);
 typedef BOOL (DCPCALL *tDialogBoxLFMProc)(intptr_t LFMData, unsigned long DataSize, tDlgProc DlgProc);
 typedef BOOL (DCPCALL *tDialogBoxLRSProc)(intptr_t LRSData, unsigned long DataSize, tDlgProc DlgProc);
 typedef BOOL (DCPCALL *tDialogBoxLFMFileProc)(char* LFMFileName, tDlgProc DlgProc);

+ 1 - 1
sdk/extension.pas

@@ -111,7 +111,7 @@ type
   { Definition of callback functions called by the DLL }
   TInputBoxProc = function(Caption, Prompt: PAnsiChar; MaskInput: LongBool; Value: PAnsiChar; ValueMaxLen: Integer): LongBool; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
   TMessageBoxProc = function(Text, Caption: PAnsiChar; Flags: Longint): Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
-  TMsgChoiceBoxProc = function(Text, Caption: PAnsiChar; Buttons: PPAnsiChar): Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
+  TMsgChoiceBoxProc = function(Text, Caption: PAnsiChar; Buttons: PPAnsiChar; BtnDef, BtnEsc: Integer): Integer; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
   TDialogBoxLFMProc = function(LFMData: Pointer; DataSize: LongWord; DlgProc: TDlgProc): LongBool; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
   TDialogBoxLRSProc = function(LRSData: Pointer; DataSize: LongWord; DlgProc: TDlgProc): LongBool; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
   TDialogBoxLFMFileProc = function(lfmFileName: PAnsiChar; DlgProc: TDlgProc): LongBool; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};

+ 1 - 0
src/fMsg.pas

@@ -37,6 +37,7 @@ uses
 
 procedure TfrmMsg.FormCreate(Sender: TObject);
 begin
+  Escape:= -1;
   iSelected:= -1;
 end;
 

+ 3 - 3
src/fdialogbox.pas

@@ -112,7 +112,7 @@ type
 
 function InputBox(Caption, Prompt: PAnsiChar; MaskInput: LongBool; Value: PAnsiChar; ValueMaxLen: Integer): LongBool; dcpcall;
 function MessageBox(Text, Caption: PAnsiChar; Flags: Longint): Integer; dcpcall;
-function MsgChoiceBox(Text, Caption: PAnsiChar; Buttons: PPAnsiChar): Integer; dcpcall;
+function MsgChoiceBox(Text, Caption: PAnsiChar; Buttons: PPAnsiChar; BtnDef, BtnEsc: Integer): Integer; dcpcall;
 function DialogBoxLFM(LFMData: Pointer; DataSize: LongWord; DlgProc: TDlgProc): LongBool; dcpcall;
 function DialogBoxLRS(LRSData: Pointer; DataSize: LongWord; DlgProc: TDlgProc): LongBool; dcpcall;
 function DialogBoxLFMFile(lfmFileName: PAnsiChar; DlgProc: TDlgProc): LongBool; dcpcall;
@@ -142,7 +142,7 @@ begin
   Result:= ShowMessageBox(Text, Caption, Flags);
 end;
 
-function MsgChoiceBox(Text, Caption: PAnsiChar; Buttons: PPAnsiChar): Integer; dcpcall;
+function MsgChoiceBox(Text, Caption: PAnsiChar; Buttons: PPAnsiChar; BtnDef, BtnEsc: Integer): Integer; dcpcall;
 var
   AButtons: TStringArray;
 begin
@@ -152,7 +152,7 @@ begin
     AddString(AButtons, Buttons^);
     Inc(Buttons);
   end;
-  Result:= uShowMsg.MsgChoiceBox(nil, Text, Caption, AButtons);
+  Result:= uShowMsg.MsgChoiceBox(nil, Text, Caption, AButtons, BtnDef, BtnEsc);
 end;
 
 function LFMToLRS(const LFMData: String): String;

+ 1 - 1
src/filesources/gio/ugiofilesource.pas

@@ -272,7 +272,7 @@ begin
 
   DCDebug('  (II) Spawning callback_ask_question...');
   // At this moment, only SFTP uses ask_question and the second button is cancellation
-  choice:= MsgChoiceBox(nil, message, buttons);
+  choice:= MsgChoiceBox(nil, message, buttons, -1, -1);
   g_print('    (II) Received choice = %d\n', [choice]);
 
   if (choice < 0) then

+ 30 - 15
src/uShowMsg.pas

@@ -78,6 +78,7 @@ type
     FValue: String;
     FMaskInput: Boolean;
     FFlags: Longint;
+    FBtnDef, FBtnEsc: Integer;
     FButtons: array of TMyMsgButton;
     FButDefault,
     FButEscape: TMyMsgButton;
@@ -90,7 +91,7 @@ type
     destructor Destroy;override;
     function ShowMsgBox(const sMsg: String; const Buttons: array of TMyMsgButton; ButDefault, ButEscape:TMyMsgButton) : TMyMsgResult;
     function ShowMessageBox(const AText, ACaption: String; Flags: LongInt): LongInt;
-    function ShowMessageChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray): Integer;
+    function ShowMessageChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
     function ShowInputQuery(const ACaption, APrompt: String; MaskInput: Boolean; var Value: String) : Boolean;
   end;
 
@@ -114,10 +115,10 @@ function MsgBox(Thread: TThread; const sMsg: String; const Buttons: array of TMy
 
 function MsgTest:TMyMsgResult;
 
-function MsgChoiceBox(const Message: String; Buttons: TDynamicStringArray): Integer; overload;
-function MsgChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray): Integer; overload;
-function MsgChoiceBox(Thread: TThread; const Message: String; Buttons: TDynamicStringArray): Integer; overload;
-function MsgChoiceBox(Thread: TThread; const Message, ACaption: String; Buttons: TDynamicStringArray): Integer; overload;
+function MsgChoiceBox(const Message: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer; overload;
+function MsgChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer; overload;
+function MsgChoiceBox(Thread: TThread; const Message: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer; overload;
+function MsgChoiceBox(Thread: TThread; const Message, ACaption: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer; overload;
 
 function ShowMessageBox(const AText, ACaption: String; Flags: LongInt): LongInt; overload;
 function ShowMessageBox(Thread: TThread; const AText, ACaption: String; Flags: LongInt): LongInt; overload;
@@ -165,7 +166,7 @@ end;
 
 procedure TDialogMainThread.SyncMessageChoiceBox;
 begin
-  FMessageBoxResult:= MsgChoiceBox(FMessage, FCaption, FChoices);
+  FMessageBoxResult:= MsgChoiceBox(FMessage, FCaption, FChoices, FBtnDef, FBtnEsc);
 end;
 
 constructor TDialogMainThread.Create(AThread : TThread);
@@ -211,8 +212,10 @@ begin
 end;
 
 function TDialogMainThread.ShowMessageChoiceBox(const Message,
-  ACaption: String; Buttons: TDynamicStringArray): Integer;
+  ACaption: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
 begin
+  FBtnDef:= BtnDef;
+  FBtnEsc:= BtnEsc;
   FMessage:= Message;
   FChoices:= Buttons;
   FCaption:= ACaption;
@@ -774,19 +777,19 @@ begin
   result := InnerShowInputListBox(sCaption, sPrompt, True, slValueList, slOutputIndexSelected, sDummyValue, iDummySelectedChoice);
 end;
 
-function MsgChoiceBox(const Message: String; Buttons: TDynamicStringArray): Integer;
+function MsgChoiceBox(const Message: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
 begin
-  Result:= MsgChoiceBox(Message, EmptyStr, Buttons);
+  Result:= MsgChoiceBox(Message, EmptyStr, Buttons, BtnDef, BtnEsc);
 end;
 
-function MsgChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray): Integer;
+function MsgChoiceBox(const Message, ACaption: String; Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
 const
   cButtonSpace = 8;
 var
   Index: Integer;
   frmMsg: TfrmMsg;
   CaptionWidth: Integer;
-  MinButtonWidth: Integer;
+  MinButtonWidth, iCount: Integer;
 begin
   frmMsg:= TfrmMsg.Create(Application);
   try
@@ -818,6 +821,7 @@ begin
       if CaptionWidth >= (MinButtonWidth - cButtonSpace) then
         MinButtonWidth:= CaptionWidth + cButtonSpace;
     end;
+    iCount:= Length(Buttons);
 
     // Add all buttons
     for Index:= Low(Buttons) to High(Buttons) do
@@ -830,6 +834,17 @@ begin
         Parent:= frmMsg.pnlButtons;
         OnClick:= frmMsg.ButtonClick;
         Constraints.MinWidth:= MinButtonWidth;
+        if Index = BtnDef then
+          Default:= True
+        else if (Index = BtnEsc) then
+        begin
+          Cancel:= True;
+          frmMsg.Escape:= BtnEsc;
+        end;
+        if BtnDef > -1 then
+        begin
+          TabOrder:= (Tag + iCount - BtnDef) mod iCount;
+        end;
       end;
     end;
 
@@ -842,20 +857,20 @@ begin
 end;
 
 function MsgChoiceBox(Thread: TThread; const Message: String;
-  Buttons: TDynamicStringArray): Integer;
+  Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
 begin
-  Result:= MsgChoiceBox(Thread, Message, EmptyStr, Buttons);
+  Result:= MsgChoiceBox(Thread, Message, EmptyStr, Buttons, BtnDef, BtnEsc);
 end;
 
 function MsgChoiceBox(Thread: TThread; const Message, ACaption: String;
-  Buttons: TDynamicStringArray): Integer;
+  Buttons: TDynamicStringArray; BtnDef, BtnEsc: Integer): Integer;
 var
   DialogMainThread : TDialogMainThread;
 begin
   Result := -1;
   DialogMainThread:= TDialogMainThread.Create(Thread);
   try
-    Result:= DialogMainThread.ShowMessageChoiceBox(Message, ACaption, Buttons);
+    Result:= DialogMainThread.ShowMessageChoiceBox(Message, ACaption, Buttons, BtnDef, BtnEsc);
   finally
     DialogMainThread.Free;
   end;

+ 1 - 1
src/uextension.pas

@@ -75,7 +75,7 @@ end;
 
 procedure TDcxModule.InitializeExtension(StartupInfo: PExtensionStartupInfo);
 const
-  VERSION_API = 1;
+  VERSION_API = 2;
 var
   Language: String;
   AFileName, APath: String;