浏览代码

Extension option controls can be grouped using @option - group

Source commit: 9a87b9052c448afb1c908ba4c597b46e410e9bbe
Martin Prikryl 9 年之前
父节点
当前提交
cfe6e06cd0

+ 50 - 11
source/forms/Custom.cpp

@@ -35,6 +35,7 @@ __fastcall TCustomDialog::TCustomDialog(UnicodeString AHelpKeyword)
   FPrePos = FPos;
   FHorizontalMargin = ScaleByTextHeight(this, 8);
   FIndent = FHorizontalMargin;
+  FGroupBox = NULL;
 
   HelpKeyword = AHelpKeyword;
 
@@ -114,7 +115,7 @@ void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
 {
   TImage * Image = new TImage(this);
   Image->Name = L"Image";
-  Image->Parent = this;
+  Image->Parent = GetDefaultParent();
   LoadDialogImage(Image, ImageName);
   Image->SetBounds(FIndent, FPos + ScaleByTextHeight(this, 3), Image->Picture->Width, Image->Picture->Height);
   FIndent += Image->Width + ScaleByTextHeight(this, 12);
@@ -122,13 +123,23 @@ void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
 //---------------------------------------------------------------------------
 int __fastcall TCustomDialog::GetMaxControlWidth(TControl * Control)
 {
-  return ClientWidth - Control->Left - FHorizontalMargin;
+  return GetDefaultParent()->ClientWidth - Control->Left - FHorizontalMargin;
+}
+//---------------------------------------------------------------------------
+TWinControl * __fastcall TCustomDialog::GetDefaultParent()
+{
+  return (FGroupBox != NULL) ? FGroupBox : static_cast<TWinControl *>(this);
 }
 //---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AdjustHeight(TControl * Control)
 {
   FPos = Control->Top + Control->Height + FControlPadding;
-  ClientHeight = ClientHeight + (FPos - FPrePos);
+  int Delta = (FPos - FPrePos);
+  ClientHeight = ClientHeight + Delta;
+  if (FGroupBox != NULL)
+  {
+    FGroupBox->Height = FGroupBox->Height + Delta;
+  }
   FPrePos = FPos;
 }
 //---------------------------------------------------------------------------
@@ -155,11 +166,11 @@ TLabel * __fastcall TCustomDialog::CreateLabel(UnicodeString Label)
 //---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * Label, bool OneLine)
 {
-  Edit->Parent = this;
+  Edit->Parent = GetDefaultParent();
   // this updates Height property to real value
   Edit->HandleNeeded();
 
-  Label->Parent = this;
+  Label->Parent = GetDefaultParent();
   Label->Left = FIndent;
 
   if (OneLine)
@@ -177,7 +188,7 @@ void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * L
   Edit->Top = FPos;
   if (OneLine)
   {
-    Edit->Left = ClientWidth - FHorizontalMargin - Edit->Width;
+    Edit->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Edit->Width;
   }
   else
   {
@@ -231,7 +242,7 @@ void __fastcall TCustomDialog::AddComboBox(TCustomCombo * Combo, TLabel * Label,
     Width = Max(Width, HelpButton->Width);
 
     Combo->Width = Width;
-    Combo->Left = ClientWidth - FHorizontalMargin - Width;
+    Combo->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Width;
   }
 
   TComboBox * PublicCombo = reinterpret_cast<TComboBox *>(Combo);
@@ -251,7 +262,7 @@ void __fastcall TCustomDialog::ScaleButtonControl(TButtonControl * Control)
 //---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
 {
-  Control->Parent = this;
+  Control->Parent = GetDefaultParent();
   Control->Left = FIndent + ScaleByTextHeight(this, 6);
   Control->Top = FPos;
   Control->Width = GetMaxControlWidth(Control);
@@ -270,7 +281,7 @@ void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
 //---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AddText(TLabel * Label)
 {
-  Label->Parent = this;
+  Label->Parent = GetDefaultParent();
 
   Label->WordWrap = true;
   Label->Left = FIndent;
@@ -290,7 +301,7 @@ void __fastcall TCustomDialog::AddText(TLabel * Label)
 //---------------------------------------------------------------------------
 void __fastcall TCustomDialog::AddText(TStaticText * Label)
 {
-  Label->Parent = this;
+  Label->Parent = GetDefaultParent();
 
   Label->Left = FIndent;
   Label->Width = GetMaxControlWidth(Label);
@@ -304,7 +315,7 @@ void __fastcall TCustomDialog::AddText(TStaticText * Label)
 void __fastcall TCustomDialog::AddSeparator()
 {
   TBevel * Bevel = new TBevel(this);
-  Bevel->Parent = this;
+  Bevel->Parent = GetDefaultParent();
 
   Bevel->Left = FIndent;
   Bevel->Top = FPos;
@@ -314,6 +325,34 @@ void __fastcall TCustomDialog::AddSeparator()
   AdjustHeight(Bevel);
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomDialog::StartGroup(const UnicodeString & Caption)
+{
+  if (FGroupBox != NULL)
+  {
+    FIndent = FGroupBox->Left;
+    FPos = FGroupBox->Top + FGroupBox->Height + FControlPadding;
+    FPrePos = FPos;
+    FGroupBox = NULL;
+  }
+
+  TGroupBox * GroupBox = new TGroupBox(this);
+  GroupBox->Parent = this;
+  GroupBox->Caption = Caption;
+
+  GroupBox->Left = FIndent;
+  GroupBox->Top = FPos;
+  GroupBox->Height = ScaleByTextHeight(GroupBox, 20);
+  GroupBox->Width = GetMaxControlWidth(GroupBox);
+
+  AdjustHeight(GroupBox);
+
+  FPos = ScaleByTextHeight(this, 16);
+  FPrePos = FPos;
+  FIndent = FHorizontalMargin;
+
+  FGroupBox = GroupBox;
+}
+//---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 class TSaveSessionDialog : public TCustomDialog
 {

+ 3 - 3
source/forms/Custom.dfm

@@ -16,7 +16,7 @@ object CustomDialog: TCustomDialog
   PixelsPerInch = 96
   TextHeight = 13
   object OKButton: TButton
-    Left = 69
+    Left = 68
     Top = 9
     Width = 75
     Height = 25
@@ -27,7 +27,7 @@ object CustomDialog: TCustomDialog
     TabOrder = 2
   end
   object CancelButton: TButton
-    Left = 157
+    Left = 156
     Top = 9
     Width = 75
     Height = 25
@@ -38,7 +38,7 @@ object CustomDialog: TCustomDialog
     TabOrder = 0
   end
   object HelpButton: TButton
-    Left = 244
+    Left = 243
     Top = 9
     Width = 75
     Height = 25

+ 5 - 0
source/forms/Custom.h

@@ -23,10 +23,12 @@ private:
   int FHorizontalMargin;
   int FControlPadding;
   short FCount;
+  TGroupBox * FGroupBox;
 
   void __fastcall Change(TObject * Sender);
   void __fastcall Changed();
   int __fastcall GetMaxControlWidth(TControl * Control);
+  int __fastcall GetParentClientWidth();
   void __fastcall AdjustHeight(TControl * Control);
 
 protected:
@@ -40,6 +42,7 @@ protected:
 public:
   __fastcall TCustomDialog(UnicodeString HelpKeyword);
 
+  void __fastcall StartGroup(const UnicodeString & Caption);
   TLabel * __fastcall CreateLabel(UnicodeString Label);
   TCheckBox * __fastcall CreateAndAddCheckBox(const UnicodeString & Caption);
   void __fastcall AddEditLikeControl(TWinControl * Edit, TLabel * Label, bool OneLine = false);
@@ -53,6 +56,8 @@ public:
   void __fastcall AddSeparator();
 
   void __fastcall ScaleButtonControl(TButtonControl * Control);
+  TWinControl * __fastcall GetDefaultParent();
+  __property int HorizontalMargin = { read = FHorizontalMargin };
 
   bool __fastcall Execute();
 };

+ 7 - 3
source/forms/Preferences.cpp

@@ -2733,6 +2733,10 @@ __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
       AddText(Label);
       Control = Label;
     }
+    else if (Option.Kind == TCustomCommandType::okGroup)
+    {
+      StartGroup(Option.Caption);
+    }
     else if (Option.Kind == TCustomCommandType::okSeparator)
     {
       AddSeparator();
@@ -2745,10 +2749,10 @@ __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
     {
       THistoryComboBox * ComboBox = CreateHistoryComboBox(Option, Value);
       TButton * Button = new TButton(this);
-      Button->Parent = this;
+      Button->Parent = GetDefaultParent();
       Button->Width = HelpButton->Width;
-      Button->Left = HelpButton->Left;
-      ComboBox->Width = HelpButton->Left - ComboBox->Left - ScaleByTextHeight(this, 6);
+      Button->Left = GetDefaultParent()->ClientWidth - Button->Width - HorizontalMargin;
+      ComboBox->Width = Button->Left - ComboBox->Left - ScaleByTextHeight(this, 6);
       Button->Top = ComboBox->Top - ScaleByTextHeight(this, 2);
       Button->Tag = Index;
       Button->Caption = LoadStr(EXTENSION_OPTIONS_BROWSE);

+ 6 - 0
source/windows/WinConfiguration.cpp

@@ -2969,6 +2969,11 @@ bool __fastcall TCustomCommandType::ParseOption(const UnicodeString & Value, TOp
       Option.Kind = okSeparator;
       Result = !Option.IsControl;
     }
+    else if (KindName == L"group")
+    {
+      Option.Kind = okGroup;
+      Result = !Option.IsControl;
+    }
     else if (KindName == L"textbox")
     {
       Option.Kind = okTextBox;
@@ -3082,6 +3087,7 @@ UnicodeString __fastcall TCustomCommandType::GetOptionCommand(const TOption & Op
     case okLabel:
     case okLink:
     case okSeparator:
+    case okGroup:
     default:
       DebugFail();
   }

+ 1 - 1
source/windows/WinConfiguration.h

@@ -711,7 +711,7 @@ public:
   __fastcall TCustomCommandType();
   __fastcall TCustomCommandType(const TCustomCommandType & Other);
 
-  enum TOptionKind { okUnknown, okLabel, okLink, okSeparator, okTextBox, okFile, okDropDownList, okComboBox, okCheckBox };
+  enum TOptionKind { okUnknown, okLabel, okLink, okSeparator, okGroup, okTextBox, okFile, okDropDownList, okComboBox, okCheckBox };
 
   class TOption
   {