{ FSIWinControls Copyright (C) 2011 by Bart Broersma and Flying Sheep Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version with the following modification: As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules,and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. 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. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } unit FSIWinControls; {$mode objfpc}{$H+} {$ifndef mswindows} {$fatal This unit is for use with Windows (desktop) only} {$endif} interface uses Classes, SysUtils, StdCtrls, FSIWinUtils, FsiIoDefs; type { TFSICustomDriveComboBox } { A simple version of the old Delphi's TDriveComboBox. Added feature: - it lets you select which kind of drives are listed in the combobox } TFSICustomDriveComboBox = class(TCustomComboBox) private FSelectFirstDriveOnRefreshDriveList: Boolean; FDriveTypes: TDriveTypes; FEmptyStr: String; FAutoFill: Boolean; FMountedDrivesOnly: Boolean; FRefreshOnDropDown: Boolean; procedure SetDriveTypes(AValue: TDriveTypes); protected procedure Loaded; override; procedure DropDown; override; procedure CloseUp; override; public constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure RefreshDriveList; public property AutoFill: Boolean read FAutoFill write FAutoFill default True; property DriveTypes: TDriveTypes read FDriveTypes write SetDriveTypes default AllDriveTypes; property MountedDrivesOnly: Boolean read FMountedDrivesOnly write FMountedDrivesOnly default True; property RefreshOnDropDown: Boolean read FRefreshOnDropDown write FRefreshOnDropDown default True; property SelectFirstDriveOnRefreshDriveList: Boolean read FSelectFirstDriveOnRefreshDriveList write FSelectFirstDriveOnRefreshDriveList default False; published property Style default csDropDownList; end; TFSIDriveComboBox = class(TFSICustomDriveComboBox) published property Autofill; property DriveTypes; property MountedDrivesOnly; property RefreshOnDropDown; property SelectFirstDriveOnRefreshDriveList; // from TComboBox property Align; property Anchors; property ArrowKeysTraverseList; property AutoComplete; property AutoCompleteText; property AutoDropDown; property AutoSelect; property AutoSize;// Note: windows has a fixed height in some styles property BidiMode; property BorderSpacing; property BorderStyle; property CharCase; property Color; property Constraints; property DoubleBuffered; property DragCursor; property DragKind; property DragMode; property DropDownCount; property Enabled; property Font; property ItemHeight; property ItemIndex; property Items; property ItemWidth; property MaxLength; property OnChange; property OnChangeBounds; property OnClick; property OnCloseUp; property OnContextPopup; property OnDblClick; property OnDragDrop; property OnDragOver; property OnDrawItem; property OnEndDrag; property OnDropDown; property OnEditingDone; property OnEnter; property OnExit; property OnGetItems; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMeasureItem; property OnMouseDown; property OnMouseEnter; property OnMouseLeave; property OnMouseMove; property OnMouseUp; property OnMouseWheel; property OnMouseWheelDown; property OnMouseWheelUp; property OnSelect; property OnStartDrag; property OnUTF8KeyPress; property ParentBidiMode; property ParentColor; property ParentDoubleBuffered; property ParentFont; property ParentShowHint; property PopupMenu; property ShowHint; property Sorted; property Style; property TabOrder; property TabStop; property Text; property Visible; end; implementation { TFSICustomDriveComboBox } procedure TFSICustomDriveComboBox.SetDriveTypes(AValue: TDriveTypes); begin if FDriveTypes = AValue then Exit; FDriveTypes := AValue; RefreshDriveList; end; procedure TFSICustomDriveComboBox.RefreshDriveList; var C: Char; begin if (csDesigning in ComponentState) then Exit; Items.Clear; for C in GetAvailableDrives(FMountedDrivesOnly, DriveTypes) do begin //ADriveType := GetDriveType(C); //if ADriveType in DriveTypes then Items.Add(C + ':\'); end; if FSelectFirstDriveOnRefreshDriveList and (not DroppedDown) and (Items.Count > 0) then ItemIndex := 0; end; procedure TFSICustomDriveComboBox.Loaded; begin inherited Loaded; if FAutoFill then RefreshDriveList; end; procedure TFSICustomDriveComboBox.DropDown; begin if FRefreshOnDropDown then RefreshDriveList; inherited DropDown; end; procedure TFSICustomDriveComboBox.CloseUp; begin inherited CloseUp; if (Items.Count = 0) then Text := FEmptyStr; end; constructor TFSICustomDriveComboBox.Create(TheOwner: TComponent); begin inherited Create(TheOwner); FEmptyStr := ''; FDriveTypes := AllDriveTypes; FAutoFill := True; FMountedDrivesOnly := True; FRefreshOnDropDown := True; FSelectFirstDriveOnRefreshDriveList := False; Style := csDropDownList; end; destructor TFSICustomDriveComboBox.Destroy; begin inherited Destroy; end; end.