home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / delphi / kolekce / d6 / rxlibsetup.exe / {app} / units / FDUALLST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-02-19  |  6.6 KB  |  228 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 2001,2002 SGB Software          }
  6. {         Copyright (c) 1997, 1998 Fedor Koshevnikov,   }
  7. {                        Igor Pavluk and Serge Korolev  }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit FDualLst;
  12.  
  13. {$I RX.INC}
  14. {$L-,S-}
  15.  
  16. interface
  17.  
  18. uses SysUtils, {$IFDEF WIN32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  19.   Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, RXCtrls,
  20.   ExtCtrls, Buttons;
  21.  
  22. type
  23.   TDualListForm = class(TForm)
  24.     SrcList: TTextListBox;
  25.     DstList: TTextListBox;
  26.     SrcLabel: TLabel;
  27.     DstLabel: TLabel;
  28.     IncBtn: TButton;
  29.     IncAllBtn: TButton;
  30.     ExclBtn: TButton;
  31.     ExclAllBtn: TButton;
  32.     OkBtn: TButton;
  33.     CancelBtn: TButton;
  34.     HelpBtn: TButton;
  35.     Bevel1: TBevel;
  36.     procedure IncBtnClick(Sender: TObject);
  37.     procedure IncAllBtnClick(Sender: TObject);
  38.     procedure ExclBtnClick(Sender: TObject);
  39.     procedure ExclAllBtnClick(Sender: TObject);
  40.     procedure SrcListDragOver(Sender, Source: TObject; X, Y: Integer;
  41.       State: TDragState; var Accept: Boolean);
  42.     procedure DstListDragOver(Sender, Source: TObject; X, Y: Integer;
  43.       State: TDragState; var Accept: Boolean);
  44.     procedure SrcListDragDrop(Sender, Source: TObject; X, Y: Integer);
  45.     procedure DstListDragDrop(Sender, Source: TObject; X, Y: Integer);
  46.     procedure SrcListKeyDown(Sender: TObject; var Key: Word;
  47.       Shift: TShiftState);
  48.     procedure DstListKeyDown(Sender: TObject; var Key: Word;
  49.       Shift: TShiftState);
  50.     procedure HelpBtnClick(Sender: TObject);
  51.     procedure FormCreate(Sender: TObject);
  52.     procedure ListClick(Sender: TObject);
  53.   private
  54.     { Private declarations }
  55.     function GetShowHelp: Boolean;
  56.     procedure SetShowHelp(Value: Boolean);
  57.   protected
  58.     procedure CreateParams(var Params: TCreateParams); override;
  59.   public
  60.     { Public declarations }
  61.     procedure SetButtons;
  62.     property ShowHelp: Boolean read GetShowHelp write SetShowHelp
  63.       default True;
  64. end;
  65.  
  66. implementation
  67.  
  68. uses Consts, VCLUtils, BoxProcs;
  69.  
  70. {$R *.DFM}
  71.  
  72. { TDualListForm }
  73.  
  74. procedure TDualListForm.CreateParams(var Params: TCreateParams);
  75. begin
  76.   inherited CreateParams(Params);
  77. end;
  78.  
  79. procedure TDualListForm.SetButtons;
  80. var
  81.   SrcEmpty, DstEmpty: Boolean;
  82. begin
  83.   SrcEmpty := (SrcList.Items.Count = 0);
  84.   DstEmpty := (DstList.Items.Count = 0);
  85.   IncBtn.Enabled := not SrcEmpty and (SrcList.SelCount > 0);
  86.   IncAllBtn.Enabled := not SrcEmpty;
  87.   ExclBtn.Enabled := not DstEmpty and (DstList.SelCount > 0);
  88.   ExclAllBtn.Enabled := not DstEmpty;
  89. end;
  90.  
  91. function TDualListForm.GetShowHelp: Boolean;
  92. begin
  93.   Result := (HelpBtn.Enabled) and (HelpBtn.Visible);
  94. end;
  95.  
  96. procedure TDualListForm.SetShowHelp(Value: Boolean);
  97. const
  98.   x_FrmBtn = 16;
  99.   x_GrpBtn = 15;
  100.   x_BtnBtn = 8;
  101. begin
  102.   with HelpBtn do begin
  103.     Enabled := Value;
  104.     Visible := Value;
  105.   end;
  106.   if Value then begin
  107.     HelpBtn.Left := Width - HelpBtn.Width - x_FrmBtn;
  108.     CancelBtn.Left := HelpBtn.Left - CancelBtn.Width - x_GrpBtn;
  109.     OkBtn.Left := CancelBtn.Left - OkBtn.Width - x_BtnBtn;;
  110.   end
  111.   else begin
  112.     CancelBtn.Left := Width - CancelBtn.Width - x_FrmBtn;
  113.     OkBtn.Left := CancelBtn.Left - OkBtn.Width - x_BtnBtn;;
  114.   end;
  115. end;
  116.  
  117. procedure TDualListForm.IncBtnClick(Sender: TObject);
  118. begin
  119.   BoxMoveSelectedItems(SrcList, DstList);
  120.   SetButtons;
  121. end;
  122.  
  123. procedure TDualListForm.IncAllBtnClick(Sender: TObject);
  124. begin
  125.   BoxMoveAllItems(SrcList, DstList);
  126.   SetButtons;
  127. end;
  128.  
  129. procedure TDualListForm.ExclBtnClick(Sender: TObject);
  130. begin
  131.   BoxMoveSelectedItems(DstList, SrcList);
  132.   SetButtons;
  133. end;
  134.  
  135. procedure TDualListForm.ExclAllBtnClick(Sender: TObject);
  136. begin
  137.   BoxMoveAllItems(DstList, SrcList);
  138.   SetButtons;
  139. end;
  140.  
  141. procedure TDualListForm.SrcListDragOver(Sender, Source: TObject; X,
  142.   Y: Integer; State: TDragState; var Accept: Boolean);
  143. begin
  144.   BoxDragOver(SrcList, Source, X, Y, State, Accept, SrcList.Sorted);
  145.   if State = dsDragLeave then
  146.     (Source as TTextListBox).DragCursor := crDrag;
  147.   if (State = dsDragEnter) and ((Source as TTextListBox).SelCount > 1) then
  148.     (Source as TTextListBox).DragCursor := crMultiDrag;
  149. end;
  150.  
  151. procedure TDualListForm.DstListDragOver(Sender, Source: TObject; X,
  152.   Y: Integer; State: TDragState; var Accept: Boolean);
  153. begin
  154.   BoxDragOver(DstList, Source, X, Y, State, Accept, DstList.Sorted);
  155.   if State = dsDragLeave then
  156.     (Source as TTextListBox).DragCursor := crDrag;
  157.   if (State = dsDragEnter) and ((Source as TTextListBox).SelCount > 1) then
  158.     (Source as TTextListBox).DragCursor := crMultiDrag;
  159. end;
  160.  
  161. procedure TDualListForm.SrcListDragDrop(Sender, Source: TObject; X,
  162.   Y: Integer);
  163. begin
  164.   if Source = DstList then ExclBtnClick(SrcList)
  165.   else if Source = SrcList then begin
  166.     BoxMoveFocusedItem(SrcList, SrcList.ItemAtPos(Point(X, Y), True));
  167.   end;
  168. end;
  169.  
  170. procedure TDualListForm.DstListDragDrop(Sender, Source: TObject; X,
  171.   Y: Integer);
  172. begin
  173.   if Source = SrcList then IncBtnClick(DstList)
  174.   else if Source = DstList then begin
  175.     BoxMoveFocusedItem(DstList, DstList.ItemAtPos(Point(X, Y), True));
  176.   end;
  177. end;
  178.  
  179. procedure TDualListForm.SrcListKeyDown(Sender: TObject; var Key: Word;
  180.   Shift: TShiftState);
  181. var
  182.   Incr: Integer;
  183. begin
  184.   if not SrcList.Sorted then begin
  185.     if (ssCtrl in Shift) and ((Key = VK_DOWN) or (Key = VK_UP)) then begin
  186.       if Key = VK_DOWN then Incr := 1
  187.       else Incr := -1;
  188.       BoxMoveFocusedItem(SrcList, SrcList.ItemIndex + Incr);
  189.       Key := 0;
  190.     end;
  191.   end;
  192. end;
  193.  
  194. procedure TDualListForm.DstListKeyDown(Sender: TObject; var Key: Word;
  195.   Shift: TShiftState);
  196. var
  197.   Incr: Integer;
  198. begin
  199.   if not DstList.Sorted then begin
  200.     if (ssCtrl in Shift) and ((Key = VK_DOWN) or (Key = VK_UP)) then begin
  201.       if Key = VK_DOWN then Incr := 1
  202.       else Incr := -1;
  203.       BoxMoveFocusedItem(DstList, DstList.ItemIndex + Incr);
  204.       Key := 0;
  205.     end;
  206.   end;
  207. end;
  208.  
  209. procedure TDualListForm.HelpBtnClick(Sender: TObject);
  210. begin
  211.   Application.HelpContext(HelpContext);
  212. end;
  213.  
  214. procedure TDualListForm.FormCreate(Sender: TObject);
  215. begin
  216.   OkBtn.Caption := ResStr(SOKButton);
  217.   CancelBtn.Caption := ResStr(SCancelButton);
  218.   HelpBtn.Caption := ResStr(SHelpButton);
  219.   if NewStyleControls then Font.Style := [];
  220. end;
  221.  
  222. procedure TDualListForm.ListClick(Sender: TObject);
  223. begin
  224.   SetButtons;
  225. end;
  226.  
  227. end.
  228.