{********************************************************************} { } { Developer Express Visual Component Library } { ExpressLayoutControl Look & Feel design-time form } { } { Copyright (c) 2001-2009 Developer Express Inc. } { ALL RIGHTS RESERVED } { } { The entire contents of this file is protected by U.S. and } { International Copyright Laws. Unauthorized reproduction, } { reverse-engineering, and distribution of all or any portion of } { the code contained in this file is strictly prohibited and may } { result in severe civil and criminal penalties and will be } { prosecuted to the maximum extent possible under the law. } { } { RESTRICTIONS } { } { THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES } { (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE } { SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS } { LICENSED TO DISTRIBUTE THE EXPRESSLAYOUTCONTROL AND ALL } { ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM } { ONLY. } { } { THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED } { FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE } { COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE } { AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT } { AND PERMISSION FROM DEVELOPER EXPRESS INC. } { } { CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON } { ADDITIONAL RESTRICTIONS. } { } {********************************************************************} unit dxLayoutLookAndFeelListDesignForm; {$I cxVer.inc} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, ImgList, ActnList, {$IFDEF DELPHI6} Variants, DesignIntf, {$ELSE} DsgnIntf, {$ENDIF} cxControls, dxLayoutControl, dxLayoutLookAndFeels, cxDesignWindows, cxGraphics, Menus, dxLayoutControlAdapters; type TdxLayoutLookAndFeelListDesignForm = class(TcxDesignFormEditor, IdxLayoutLookAndFeelsDesigner) lcMain: TdxLayoutControl; lbItems: TListBox; lcMainItem1: TdxLayoutItem; lcMainGroup3: TdxLayoutGroup; lflMain: TdxLayoutLookAndFeelList; pnlPreview: TPanel; lcMainItem6: TdxLayoutItem; lcPreview: TdxLayoutControl; Edit1: TEdit; Edit2: TEdit; CheckBox1: TCheckBox; CheckBox2: TCheckBox; ListBox1: TListBox; dxLayoutControl1Group4: TdxLayoutGroup; dxLayoutGroup1: TdxLayoutGroup; dxLayoutItem1: TdxLayoutItem; dxLayoutControl1Item2: TdxLayoutItem; dxLayoutControl1Group2: TdxLayoutGroup; dxLayoutControl1Item3: TdxLayoutItem; dxLayoutControl1Item4: TdxLayoutItem; dxLayoutControl1Group3: TdxLayoutGroup; dxLayoutControl1Item5: TdxLayoutItem; alMain: TActionList; acAdd: TAction; acDelete: TAction; acClose: TAction; lcMainItem5: TdxLayoutItem; tlbGroups: TToolBar; tbAddItem: TToolButton; tbDelete: TToolButton; PopupMenu1: TPopupMenu; ilMain: TcxImageList; ilMainDisabled: TcxImageList; procedure btnAddClick(Sender: TObject); procedure lbItemsClick(Sender: TObject); procedure acDeleteExecute(Sender: TObject); procedure lbItemsKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private function CanModify: Boolean; function GetListBoxItemHeight: Integer; function GetList: TdxLayoutLookAndFeelList; procedure SynchronizeListBoxSelection; protected procedure SetComponent(AValue: TComponent); override; procedure UpdateCaption; override; procedure UpdateContent; override; procedure DeleteItems; function NeedRefreshItemsAfterDeleting(AComponent: TPersistent): Boolean; procedure Refresh(ARefreshSelection: Boolean = False); procedure RefreshEnableds; procedure RefreshListBox; procedure SetAddItemsActionEnabled(AEnabled: Boolean); procedure SetDeleteItemsActionEnabled(AEnabled: Boolean); procedure SynchronizeControlsSelection(AList: TList); procedure SynchronizeSelection(AList: TList); //IdxLayoutLookAndFeelsDesigner procedure ComponentNameChanged(ALookAndFeelList: TdxLayoutLookAndFeelList); procedure ItemsChanged(ALookAndFeelList: TdxLayoutLookAndFeelList); procedure SetList(ALookAndFeelList: TdxLayoutLookAndFeelList); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure AfterConstruction; override; procedure ItemDeleted(const ADesigner: IDesigner; AItem: TPersistent); override; procedure SelectionsChanged(const ASelection: TDesignerSelectionList); override; property List: TdxLayoutLookAndFeelList read GetList; end; implementation {$R *.dfm} uses Math, cxClasses, dxCore; { TdxLayoutLookAndFeelListDesignForm } constructor TdxLayoutLookAndFeelListDesignForm.Create(AOwner: TComponent); procedure PopulatePopupMenuItems; var I: Integer; AItem: TMenuItem; begin for I := 0 to dxLayoutLookAndFeelDefs.Count - 1 do begin AItem := TMenuItem.Create(PopupMenu1); AItem.Caption := dxLayoutLookAndFeelDefs[I].Description; AItem.Tag := I; AItem.OnClick := btnAddClick; PopupMenu1.Items.Add(AItem); end; end; begin inherited; dxLayoutLookAndFeelsDesigner := Self; {$IFDEF DELPHI9} PopupMode := pmExplicit; {$ENDIF} if not IsXPManifestEnabled then begin cxTransformImages(ilMain, clBtnFace); tlbGroups.DisabledImages := ilMainDisabled; cxTransformImages(ilMainDisabled, clBtnFace, False); end; PopulatePopupMenuItems; end; destructor TdxLayoutLookAndFeelListDesignForm.Destroy; begin dxLayoutLookAndFeelsDesigner := nil; inherited; end; procedure TdxLayoutLookAndFeelListDesignForm.AfterConstruction; begin inherited; lbItems.ItemHeight := GetListBoxItemHeight; end; procedure TdxLayoutLookAndFeelListDesignForm.ItemDeleted(const ADesigner: IDesigner; AItem: TPersistent); begin if (LockCount = 0) and (AItem <> Component) and not Closing and NeedRefreshItemsAfterDeleting(AItem) then Refresh(True); end; procedure TdxLayoutLookAndFeelListDesignForm.SelectionsChanged(const ASelection: TDesignerSelectionList); var AList: TList; begin inherited; if Component = nil then Exit; AList := TList.Create; try GetSelectionList(AList); SynchronizeSelection(AList); finally AList.Free; end; end; function TdxLayoutLookAndFeelListDesignForm.CanModify: Boolean; begin Result := not Designer.IsSourceReadOnly and (List <> nil) and not (csDestroying in List.ComponentState) and not (csInline in List.Owner.ComponentState); end; function TdxLayoutLookAndFeelListDesignForm.GetListBoxItemHeight: Integer; begin Result := 2 + lbItems.Canvas.TextHeight('Qq') + 2; end; function TdxLayoutLookAndFeelListDesignForm.GetList: TdxLayoutLookAndFeelList; begin Result := TdxLayoutLookAndFeelList(Component); end; procedure TdxLayoutLookAndFeelListDesignForm.SynchronizeListBoxSelection; var AList: TList; begin if LockCount > 0 then Exit; AList := TList.Create; try ListBoxGetSelection(lbItems, AList); SynchronizeSelection(AList); finally AList.Free; end; end; procedure TdxLayoutLookAndFeelListDesignForm.DeleteItems; procedure InternalDeleteItems; var AList: TcxObjectList; begin AList := TcxObjectList.Create; try GetSelectionList(AList); if AList.Count > 0 then begin BeginUpdate; try AList.Clear; UpdateContent; finally EndUpdate; end; Designer.Modified; end; finally AList.Free; end; end; var AIndex: Integer; begin AIndex := lbItems.ItemIndex; InternalDeleteItems; RefreshListBox; if lbItems.Count > 0 then begin AIndex := Min(AIndex, lbItems.Count - 1); lbItems.ItemIndex := AIndex; lbItems.Selected[AIndex] := True; end; SynchronizeListBoxSelection; end; procedure TdxLayoutLookAndFeelListDesignForm.SetComponent(AValue: TComponent); begin if Component <> nil then Component.RemoveFreeNotification(Self); inherited; if Component <> nil then Component.FreeNotification(Self); UpdateCaption; Refresh(True); end; procedure TdxLayoutLookAndFeelListDesignForm.UpdateCaption; begin Caption := cxGetFullComponentName(Component) + ' - Designer'; end; procedure TdxLayoutLookAndFeelListDesignForm.UpdateContent; begin inherited; Refresh(True); end; function TdxLayoutLookAndFeelListDesignForm.NeedRefreshItemsAfterDeleting(AComponent: TPersistent): Boolean; begin Result := (AComponent is TdxCustomLayoutLookAndFeel) and (TdxCustomLayoutLookAndFeel(AComponent).List = List); end; procedure TdxLayoutLookAndFeelListDesignForm.Refresh(ARefreshSelection: Boolean = False); begin if (LockCount > 0) or (Component = nil) then Exit; RefreshListBox; if ARefreshSelection then UpdateSelection; end; procedure TdxLayoutLookAndFeelListDesignForm.RefreshEnableds; var ACanModify: Boolean; begin ACanModify := CanModify; SetAddItemsActionEnabled(ACanModify); SetDeleteItemsActionEnabled(ACanModify and (lbItems.SelCount > 0)); end; procedure TdxLayoutLookAndFeelListDesignForm.RefreshListBox; var I: Integer; AItem: TdxCustomLayoutLookAndFeel; begin with lbItems.Items do begin BeginUpdate; try Clear; for I := 0 to List.Count - 1 do begin AItem := List[I]; AddObject(AItem.Name, AItem); end; finally EndUpdate; end; end; end; procedure TdxLayoutLookAndFeelListDesignForm.SetAddItemsActionEnabled(AEnabled: Boolean); begin acAdd.Enabled := AEnabled; end; procedure TdxLayoutLookAndFeelListDesignForm.SetDeleteItemsActionEnabled(AEnabled: Boolean); begin acDelete.Enabled := AEnabled; end; procedure TdxLayoutLookAndFeelListDesignForm.SynchronizeControlsSelection(AList: TList); begin ListBoxSyncSelection(lbItems, AList); end; procedure TdxLayoutLookAndFeelListDesignForm.SynchronizeSelection(AList: TList); begin SelectComponents(AList, nil); SynchronizeControlsSelection(AList); RefreshEnableds; lcPreview.Visible := (AList.Count = 1) and (TPersistent(AList[0]) is TdxCustomLayoutLookAndFeel); if lcPreview.Visible then lcPreview.LookAndFeel := TdxCustomLayoutLookAndFeel(AList[0]); end; procedure TdxLayoutLookAndFeelListDesignForm.ComponentNameChanged(ALookAndFeelList: TdxLayoutLookAndFeelList); begin if ALookAndFeelList = List then UpdateCaption; end; procedure TdxLayoutLookAndFeelListDesignForm.ItemsChanged(ALookAndFeelList: TdxLayoutLookAndFeelList); begin if ALookAndFeelList = List then UpdateContent; end; procedure TdxLayoutLookAndFeelListDesignForm.SetList(ALookAndFeelList: TdxLayoutLookAndFeelList); begin Component := ALookAndFeelList; end; procedure TdxLayoutLookAndFeelListDesignForm.btnAddClick(Sender: TObject); var ALookAndFeel: TdxCustomLayoutLookAndFeel; begin ALookAndFeel := List.CreateItem(dxLayoutLookAndFeelDefs.Items[(Sender as TComponent).Tag]); Designer.SelectComponent(ALookAndFeel); end; procedure TdxLayoutLookAndFeelListDesignForm.lbItemsClick(Sender: TObject); begin SynchronizeListBoxSelection; end; procedure TdxLayoutLookAndFeelListDesignForm.acDeleteExecute(Sender: TObject); begin DeleteItems; end; procedure TdxLayoutLookAndFeelListDesignForm.lbItemsKeyDown( Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_DELETE) and (lbItems.SelCount > 0) then DeleteItems; end; end.