⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagebuilder.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: PageBuilder.pas, released on 2004-03-29.

The Initial Developer of the Original Code is Andreas Hausladen
(Andreas dott Hausladen att gmx dott de)
Portions created by Andreas Hausladen are Copyright (C) 2004 Andreas Hausladen.
All Rights Reserved.

Contributor(s): -

You may retrieve the latest version of this file at the Project JEDI's JVCL
home page, located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: PageBuilder.pas,v 1.10 2004/12/30 00:11:10 ahuser Exp $

unit PageBuilder;

{$I jvcl.inc}

interface

uses
  Windows, SysUtils, Classes, Controls, Forms, Graphics, StdCtrls, ExtCtrls,
  ComCtrls, ActnList,
  JvWizard,
  Core;


function CreatePage(Page: TJvWizardInteriorPage; Inst: IInstallerPage): TWinControl;
  { returns the active control }
function PreparePage(Page: TJvWizardInteriorPage; Inst: IInstallerPage): TPanel;
procedure DestroyPage(Page: TJvWizardInteriorPage);

implementation

uses
  Main, Utils;

function CreateWelcomePage(Page: TJvWizardInteriorPage; Inst: IWelcomePage): TWinControl; forward;
  { returns the active control }
function CreateMultiChoosePage(Page: TJvWizardInteriorPage; Inst: IMultiChoosePage): TWinControl; forward;
  { returns the active control }
function CreateSingleChoosePage(Page: TJvWizardInteriorPage; Inst: ISingleChoosePage): TWinControl; forward;
  { returns the active control }
function CreateSummaryPage(Page: TJvWizardInteriorPage; Inst: ISummaryPage): TWinControl; forward;
  { returns the active control }

type
  TSingleChooseOptionClick = class(TComponent)
  public
    Index: Integer;
    Page: ISingleChoosePage;
    procedure Click(Sender: TObject);
  end;

  TMultiChooseCheckBoxClick = class(TComponent)
  public
    Index: Integer;
    Page: IMultiChoosePage;
    procedure Click(Sender: TObject);
  end;

procedure TSingleChooseOptionClick.Click(Sender: TObject);
begin
  Page.SetSelectedOption(Index);
end;

procedure TMultiChooseCheckBoxClick.Click(Sender: TObject);
begin
  Page.SetCheckBox(Index, (Sender as TCheckBox).Checked);
end;


function GetDefaultCheckBoxSize: TSize;
begin
{$IFDEF VCL}
  with TBitmap.Create do
  try
    Handle := LoadBitmap(0, PChar(OBM_CHECKBOXES));
    Result.cx := Width div 4;
    Result.cy := Height div 3;
  finally
    Free;
  end;
{$ENDIF VCL}
{$IFDEF VisualCLX}
  Result.cx := 12;
  Result.cy := 12;
{$ENDIF VisualCLX}
end;

// -----------------------------------------------------------------------------

function CreateLayoutPanel(Parent: TWinControl; const Name: string;
  const BoundsRect: TRect): TPanel;
begin
  Result := TPanel.Create(Parent);
  Result.Name := Name;
  Result.BevelInner := bvNone;
  Result.BevelOuter := bvNone;
  Result.BoundsRect := BoundsRect;
  Result.Caption := '';
  Result.Parent := Parent;
end;

function PreparePage(Page: TJvWizardInteriorPage; Inst: IInstallerPage): TPanel;
var
  Title, SubTitle: WideString;
begin
 // caption
  Title := '';
  SubTitle := '';
  Inst.Title(Title, SubTitle);
  Page.Title.Text := Title;
  Page.Subtitle.Text := SubTitle;
  Page.Caption := Title;
  Page.Header.Title.Indent := 5;
  Page.Header.Subtitle.Indent := 5;

  Page.Header.Visible := (Title <> '') or (SubTitle <> '');
  Result := nil;
end;

function CreatePage(Page: TJvWizardInteriorPage; Inst: IInstallerPage): TWinControl;
var
  Y: Integer;
  PageClient: TPanel;
  FocusControl: TWinControl;
begin
  Result := nil;
  if (Page.FindComponent('piPageClient') <> nil) and not Supports(Inst, ISummaryPage) then // do not localize
    Exit;

  if Supports(Inst, ISummaryPage) then
    Page.FindComponent('piPageClient').Free;

  if Page.Header.Visible then
    Y := Page.Header.Height
  else
    Y := 0;
  PageClient := CreateLayoutPanel(Page, 'piPageClient', // do not localize
    Rect(0, Y, Page.ClientWidth, Page.ClientHeight));

  if Supports(Inst, IWelcomePage) then
    Result := CreateWelcomePage(Page, Inst as IWelcomePage)
  else
  if Supports(Inst, ISingleChoosePage) then
    Result := CreateSingleChoosePage(Page, Inst as ISingleChoosePage)
  else
  if Supports(Inst, IMultiChoosePage) then
    Result := CreateMultiChoosePage(Page, Inst as IMultiChoosePage)
  else
  if Supports(Inst, ISummaryPage) then
    Result := CreateSummaryPage(Page, Inst as ISummaryPage)
  ;

 // maybe the user wants some extra controls
  if Supports(Inst, IUserDefinedPage) then
  begin
    FocusControl := (Inst as IUserDefinedPage).SetupPage(PageClient);
    if FocusControl <> nil then
      Result := FocusControl;
  end;
end;

procedure DestroyPage(Page: TJvWizardInteriorPage);

  procedure RemoveActionLists(Owner: TComponent);
  var
    i: Integer;
  begin
    for i := Owner.ComponentCount - 1 downto 0 do
      RemoveActionLists(Owner.Components[i]);
    if (Owner is TCustomActionList) then
      Owner.Free;
  end;

var
  Panel: TPanel;
begin
  Panel := TPanel(Page.FindComponent('piPageClient')); // do not localize
  if Panel <> nil then
  begin
    RemoveActionLists(Panel); // Bug in VCL does not remove the action list from the frame's actionlist list.
    Panel.Free;
  end;
end;

function CreateSingleChooseControls(Parent: TWinControl; Inst: ISingleChoosePage;
  var LockedHorzOrientation: THorzOrientation): TWinControl;
var
  Options: TStrings;
  i, AbsH, X, Y, ps: Integer;
  RadioButton: TRadioButton;
  ItemIndex: Integer;
  S: string;
  HorzOrientation: THorzOrientation;
  Width, tmpWidth: Integer;
  Canvas: TControlCanvas;
begin
  Result := nil;
  Options := TStringList.Create;
  Canvas := TControlCanvas.Create;
  try
    Canvas.Control := Parent;

    // RadioButtons
    HorzOrientation := hoDefault;
    Inst.Options(Options, HorzOrientation);
    case LockedHorzOrientation of
      hoLeft:
        HorzOrientation := hoRight;
      hoRight:
        HorzOrientation := hoLeft;
      hoCenter:
        Exit; // error
    end;

    if HorzOrientation = hoDefault then
      HorzOrientation := hoLeft;
    LockedHorzOrientation := HorzOrientation;

    if Options.Count > 0 then
    begin
      ItemIndex := Inst.GetSelectedOption;

      // find text with largest width
      Width := 0;
      for i := 0 to Options.Count - 1 do
      begin
        S := Options[i];
        if S <> '' then
        begin
          ps := Pos('|', S);
          if ps = 0 then
            ps := Length(S) + 1;

          tmpWidth := Canvas.TextWidth(Copy(S, 1, ps - 1));
          if tmpWidth > Width then
             Width := tmpWidth;
        end;
      end;
      Inc(Width, GetDefaultCheckBoxSize.cx*4 div 2);  // add checkbox size

      if HorzOrientation = hoLeft then
        X := 8
      else if HorzOrientation = hoCenter then
        X := (Parent.ClientWidth - Width) div 2
      else
        X := Parent.ClientWidth - 8 - Width;

      // create radion buttons
      AbsH := (Parent.ClientHeight - 8) div Options.Count;
      Y := 8;
      for i := 0 to Options.Count - 1 do
      begin
        S := Options[i];
        if S <> '' then
        begin
          ps := Pos('|', S);
          if ps = 0 then
            ps := Length(S) + 1;
          RadioButton := TRadioButton.Create(Parent);
          RadioButton.Name := 'piOption_' + IntToStr(i); // do not localize

⌨️ 快捷键说明

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