cxstylesheetsload.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 471 行 · 第 1/2 页

PAS
471
字号
  if CurrentStyleSheetClass = nil then
  begin
    FStyleSheetsListBox.Items.Clear;
    //AForm.Width := AForm.pnlStyles.Width;
  end
  else
  begin
    AList := TList.Create;
    try
      for I := 0 to FList.Count - 1 do
        TcxPredefinedStyleSheets(FList[I]).GetStyleSheetsByClass(CurrentStyleSheetClass, AList);

      with FStyleSheetsListBox.Items do
      begin
        BeginUpdate;
        try
          Clear;
          for I := 0 to AList.Count - 1 do
          begin
            StyleSheet := TcxCustomStyleSheet(AList[I]);
            AddObject(StyleSheet.Caption, StyleSheet);
          end;
        finally
          EndUpdate;
        end;
      end;
    finally
      AList.Free;
    end;
  end;

  FreeAndNil(FPreview);

  PreviewClass := nil;
  if CurrentStyleSheetClass <> nil then
    PreviewClass := GetPreviewByStyleSheetClass(CurrentStyleSheetClass);
  if PreviewClass <> nil then
  begin
    FPreview := PreviewClass.Create(AForm);
    AForm.SetShowPreview(True);
    FPreview.Control.Parent := AForm.pnlPreviewClient;
    FPreview.Control.Align := alClient;
    FPreview.SetStyleSheet(nil);

    if AForm.pnlPreviewClient.Width < FPreview.GetSize.X then
      AForm.Width := AForm.Width + FPreview.GetSize.X - AForm.pnlPreviewClient.Width;
    if AForm.pnlPreviewClient.Height < FPreview.GetSize.Y then
      AForm.Height := AForm.Height + FPreview.GetSize.Y - AForm.pnlPreviewClient.Height;
  end
  else
    AForm.SetShowPreview(False);

  UpdateButton;
end;

procedure TcxPredefinedStyleSheetsList.FreeAndNilItems;
var
  I: Integer;
begin
  for I := 0 to FList.Count - 1 do
    TObject(FList[I]).Free;
  FList.Free;
end;

procedure TcxPredefinedStyleSheetsList.UpdateButton;
begin
  FLoadButton.Enabled := FStyleSheetsListBox.SelCount > 0;
end;

procedure TcxPredefinedStyleSheetsList.StyleSheetClassComboBoxClick(Sender: TObject);
begin
  FillListBox;
end;

procedure TcxPredefinedStyleSheetsList.StyleSheetsListBoxClick(Sender: TObject);
begin
  UpdateButton;
  if FPreview <> nil then
    FPreview.SetStyleSheet(CurrentStyleSheet);
end;

procedure ShowLoadStyleSheetsFromIniFile(const AIniFileName: string;
                AStyleRepository: TcxStyleRepository;
                AOwner: TComponent; const AStyleSheetList: TList;
                AStyleGetName: TcxStyleGetName);

  procedure SelectAllItems(AForm: TfrmcxStyleSheetsLoad);
//{$IFNDEF DELPHI6}
  var
    I: Integer;
//{$ENDIF}
  begin
//  {$IFDEF DELPHI6}
//    AForm.lbStyleSheets.SelectAll;
//  {$ELSE}
    for I := 0 to AForm.lbStyleSheets.Items.Count - 1 do
      AForm.lbStyleSheets.Selected[I] := True;
//  {$ENDIF}
  end;

var
  AForm: TfrmcxStyleSheetsLoad;
  I: Integer;
  AIniFile: TMemIniFile;
  AStrings: TStringList;
begin
  AIniFile := TMemIniFile.Create(AIniFileName);
  AForm := TfrmcxStyleSheetsLoad.Create(nil);
  AForm.SetShowPreview(False);
  AStrings := TStringList.Create;
  try
    AIniFile.ReadSections(AForm.lbStyleSheets.Items);
    SelectAllItems(AForm);
    AForm.btnLoad.Enabled := (AForm.CurrentStyleSheetClass <> nil) and
        (AForm.lbStyleSheets.Items.Count > 0);
    AForm.ShowModal;
    if AForm.ModalResult = mrOk then
    begin
      for I := 0 to AForm.lbStyleSheets.Items.Count - 1 do
         if AForm.lbStyleSheets.Selected[I] then
           AStrings.Add(AForm.lbStyleSheets.Items[I]);
      LoadStyleSheetsFromIniFile(AIniFileName, AStyleRepository,
       AForm.CurrentStyleSheetClass,
       AStrings, AOwner, AStyleSheetList, AStyleGetName);
    end;
  finally
    AStrings.Free;
    AForm.Free;
    AIniFile.Free;
  end;
end;

procedure CreateStyleSheetByPredefine(AStyleRepository: TcxStyleRepository;
                AOwner: TComponent; const AStyleSheetList: TList;
                AStyleGetName: TcxStyleGetName; ASource: TcxCustomStyleSheet);
var
  AStyleSheet: TcxCustomStyleSheet;
begin
  AStyleSheet := AStyleRepository.CreateStyleSheetEx(TcxCustomStyleSheetClass(ASource.ClassType),
        AOwner);
  if AStyleSheetList <> nil then
    AStyleSheetList.Add(AStyleSheet);
  if AOwner.FindComponent(ASource.Name) = nil then
    AStyleSheet.Name := ASource.Name;
  AStyleSheet.Caption := ASource.Caption;
  CreateStyleSheetStyles(AStyleSheet, ASource, AStyleGetName);
end;

procedure ShowLoadStyleSheetsFromPreDefineStyles(AStyleRepository: TcxStyleRepository;
                AOwner: TComponent; const AStyleSheetList: TList;
                AStyleGetName: TcxStyleGetName);
var
  AForm: TfrmcxStyleSheetsLoad;
  APredefinedList: TcxPredefinedStyleSheetsList;
  I: Integer;
begin
  AForm := TfrmcxStyleSheetsLoad.Create(nil);
  APredefinedList := TcxPredefinedStyleSheetsList.Create(
      AForm.cbStyleSheetClasses, AForm.lbStyleSheets, AForm.btnLoad);
  try
    APredefinedList.FillListBox;
    AForm.ShowModal;
    if AForm.ModalResult = mrOk then
    begin
      for I := 0 to AForm.lbStyleSheets.Items.Count - 1 do
         if AForm.lbStyleSheets.Selected[I] then
           CreateStyleSheetByPredefine(AStyleRepository,
             AOwner, AStyleSheetList, AStyleGetName,
             TcxCustomStyleSheet(AForm.lbStyleSheets.Items.Objects[I]));
    end;
  finally
    APredefinedList.Free;
    AForm.Free;
  end;
end;

{ TfrmcxStyleSheetsLoad }

constructor TfrmcxStyleSheetsLoad.Create(AOwner: TComponent);
var
  I: Integer;
  AList: TList;
  StyleSheetClass: TcxCustomStyleSheetClass;
begin
  inherited Create(AOwner);
  AList := TList.Create;
  try
    GetRegisteredStyleSheetClasses(AList);
    for I := 0 to AList.Count - 1 do
    begin
      StyleSheetClass := TcxCustomStyleSheetClass(AList[I]);
      cbStyleSheetClasses.Items.AddObject(StyleSheetClass.ClassName, TObject(StyleSheetClass));
    end;

    with cbStyleSheetClasses do
      if Items.Count > 0 then ItemIndex := 0;
  finally
    AList.Free;
  end;
end;

function TfrmcxStyleSheetsLoad.CurrentStyleSheetClass: TcxCustomStyleSheetClass;
begin
  with cbStyleSheetClasses do
    if ItemIndex > - 1 then
      Result := TcxCustomStyleSheetClass(Items.Objects[ItemIndex])
    else
      Result := nil;
end;

procedure TfrmcxStyleSheetsLoad.SetShowPreview(Value: Boolean);
begin
  if pnlPreview.Visible <> Value then
    if Value then
    begin
      Constraints.MaxWidth := 0;
      ClientWidth := ClientWidth + pnlPreview.Width;
      pnlPreview.Visible := Value;
    end
    else
    begin
      pnlPreview.Visible := Value;
      ClientWidth := ClientWidth - pnlPreview.Width;
      Constraints.MaxWidth := Width;
    end;
end;

procedure TfrmcxStyleSheetsLoad.FormCreate(Sender: TObject);
begin
  lbStyleSheetClass.Height := cbStyleSheetClasses.Height;
  lbPreview.Height := cbStyleSheetClasses.Height;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?