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

📄 mxoutlookbarproeditor.pas

📁 可以在C++中实现OutLook界面和windows资源管理器的效果。
💻 PAS
📖 第 1 页 / 共 2 页
字号:
// ****************************************************************************
// * An Outlook style sidebar component for Delphi.
// ****************************************************************************
// * Copyright 2002, Bitvad醩z Kft. Hungary . All Rights Reserved.
// ****************************************************************************
// * Feel free to contact me if you have any questions, comments or suggestions
// * at support@maxcomponents.net
// ****************************************************************************
// * Web page: www.maxcomponents.net
// ****************************************************************************
// * Date last modified: 11.10.2002
// ****************************************************************************
// * TmxOutlookBarPro v2.13
// ****************************************************************************
// * Description:
// *
// * The TmxOutlookBarPro 100% native VCL  component with many added features to
// * support the look, feel, and behavior introduced in Microsoft  Office 97,
// * 2000, and new Internet Explorer. It has got many features  including
// * scrolling headers, icon  highlighting and positioning, small and large
// * icons,gradient and bitmap Backgrounds. The header sections and buttons
// * can be  added, deleted and  moved  at design time. The  header tabs can
// * have individual  font,  alignment,  tabcolor,  glyph, tiled Background
// * images. And many many more posibilities.
// *
// * This component is an advanced version of TmxOutlookBar
// *
// ****************************************************************************

Unit mxOutlookBarProEditor;

Interface

{$I MAX.INC}

Uses Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Grids, Menus,
{$IFDEF DELPHI6_UP}
  DesignIntf, DesignWindows, DesignEditors,
{$ELSE}
  Dsgnintf, DsgnWnds,
{$ENDIF}
  mxOutlookBarPro, ComCtrls, ToolWin, ImgList;

Type
{$IFDEF DELPHI6_UP}
  TDesigner = DesignIntf.IDesigner;
  TFormDesigner = DesignIntf.IDesigner;
{$ELSE}
  TDesigner = IDesigner;
  TFormDesigner = IFormDesigner;
{$ENDIF}

  TmxHeaderEditor = Class( TDesignWindow )
    ClientPanel: TPanel;
    grid_Headers: TDrawGrid;
    PopupMenu: TPopupMenu;
    mnu_Delete: TMenuItem;
    N1: TMenuItem;
    mnu_New: TMenuItem;
    ImageList: TImageList;
    ImageList_Gray: TImageList;
    Splitter1: TSplitter;
    StatusBar: TStatusBar;
    CoolBar: TCoolBar;
    ToolBar: TToolBar;
    btn_New: TToolButton;
    btn_Delete: TToolButton;
    ToolButton1: TToolButton;
    btn_Clear: TToolButton;
    ToolButton4: TToolButton;
    btn_Close: TToolButton;
    btn_DeleteButton: TToolButton;
    grid_Buttons: TDrawGrid;
    ToolButton2: TToolButton;
    btn_NewButton: TToolButton;
    PopupMenu1: TPopupMenu;
    mnu_DelButton: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    Procedure FormClose( Sender: TObject; Var Action: TCloseAction );
    Procedure grid_HeadersDrawCell( Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState );
    Procedure grid_HeadersSelectCell( Sender: TObject; Col, Row: Longint; Var CanSelect: Boolean );
    Procedure btn_CloseClick( Sender: TObject );
    Procedure btn_DeleteClick( Sender: TObject );
    Procedure grid_HeadersKeyDown( Sender: TObject; Var Key: Word; Shift: TShiftState );
    Procedure FormResize( Sender: TObject );
    Procedure FormCreate( Sender: TObject );
    Procedure btn_NewClick( Sender: TObject );
    Procedure btn_ClearClick( Sender: TObject );
    Procedure Splitter1Moved( Sender: TObject );
    Procedure ClientPanelResize( Sender: TObject );
    Procedure FormShow( Sender: TObject );
    Procedure Grid_ButtonsDrawCell( Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState );
    Procedure Grid_ButtonsKeyDown( Sender: TObject; Var Key: Word; Shift: TShiftState );
    Procedure btn_DeleteButtonClick( Sender: TObject );
    Procedure Grid_ButtonsSelectCell( Sender: TObject; ACol, ARow: Integer; Var CanSelect: Boolean );
    Procedure btn_NewButtonClick( Sender: TObject );
  Private

    FDeleting: Boolean;
    FActiveHeader: TmxHeader;
    FOutlookBarPro: TmxOutlookBarPro;

    Function GetForm: TCustomForm;
    Function CheckCollection: Boolean;

    Function HeaderByRow( ARow: Integer ): TmxHeader;
    Function ButtonByRow( ARow: Integer ): TmxButton;
    Procedure SelectHeader( AHeader: TmxHeader );
    Procedure SelectButton( AButton: TmxButton );
    Procedure UpdateData;
    Procedure SetHeaderList( AValue: TmxOutlookBarPro );

  Protected

    Procedure Activated; Override;
    Function UniqueName( Component: TComponent ): String; Override;

  Public

{$IFDEF DELPHI6_UP}
    Procedure ItemDeleted( Const ADesigner: IDesigner; Item: TPersistent ); Override;

    Function EditAction( Action: TEditAction ): Boolean; Override;
    Procedure ItemsModified( Const Designer: IDesigner ); Override;
    Procedure DesignerClosed( Const ADesigner: IDesigner; AGoingDormant: Boolean ); Override;
{$ELSE}
    Procedure ComponentDeleted( Component: IPersistent ); Override;

    Procedure EditAction( Action: TEditAction ); Override;
    Procedure FormModified; Override;
    Procedure FormClosed( Form: TCustomForm ); Override;
{$ENDIF}

    Property OwnerForm: TCustomForm Read GetForm;

    Function GetEditState: TEditState; Override;
    Property OutlookBarPro: TmxOutlookBarPro Read FOutlookBarPro Write SetHeaderList;

  End;

Implementation

Uses Clipbrd, mxOutlookBarProReg;

{$R *.DFM}
{$D-}

Type
  TCustomClass = Class( TCustomControl );

Function Max( A, B: Integer ): Integer;
Begin
  If A > B Then Result := A Else Result := B;
End;

Procedure WriteText( ACanvas: TCanvas; ARect: TRect; DX, DY: Integer; Const Text: String; Alignment: TAlignment; WordWrap: Boolean; ARightToLeft: Boolean = False );
Const
  AlignFlags: Array[ TAlignment ] Of Integer = ( DT_LEFT Or DT_EXPANDTABS Or DT_NOPREFIX, DT_RIGHT Or DT_EXPANDTABS Or DT_NOPREFIX, DT_CENTER Or DT_EXPANDTABS Or DT_NOPREFIX );
  WrapFlags: Array[ Boolean ] Of Integer = ( 0, DT_WORDBREAK );
  RTL: Array[ Boolean ] Of Integer = ( 0, DT_RTLREADING );
Var
  Left: Integer;
Begin
  If ( ACanvas.CanvasOrientation = coRightToLeft ) And ( Not ARightToLeft ) Then
    ChangeBiDiModeAlignment( Alignment );
  Case Alignment Of
    taLeftJustify: Left := ARect.Left + DX;
    taRightJustify: Left := ARect.Right - ACanvas.TextWidth( Text ) - 3;
  Else { taCenter }
    Left := ARect.Left + ( ARect.Right - ARect.Left ) Shr 1 - ( ACanvas.TextWidth( Text ) Shr 1 );
  End;
  ACanvas.TextRect( ARect, Left, ARect.Top + DY, Text );
End;

Procedure TmxHeaderEditor.SetHeaderList( AValue: TmxOutlookBarPro );
Begin
  If FOutlookBarPro <> AValue Then
  Begin
    FOutlookBarPro := AValue;
    UpdateData;
  End;
End;

Function TmxHeaderEditor.GetEditState: TEditState;
Begin
  Result := [ ];
  If btn_Delete.Enabled Then Result := [ esCanDelete, esCanCut, esCanCopy ];
  If ClipboardComponents Then Include( Result, esCanPaste );
End;

{$IFDEF DELPHI6_UP}

Procedure TmxHeaderEditor.DesignerClosed( Const ADesigner: IDesigner; AGoingDormant: Boolean );
{$ELSE}

Procedure TmxHeaderEditor.FormClosed( Form: TCustomForm );
{$ENDIF}
Begin
  If {$IFDEF DELPHI6_UP}ADesigner.Root{$ELSE}Form{$ENDIF} = OwnerForm Then Free;
End;

{$IFDEF DELPHI6_UP}

Procedure TmxHeaderEditor.ItemsModified( Const Designer: IDesigner );
{$ELSE}

Procedure TmxHeaderEditor.FormModified;
{$ENDIF}
Begin
  If Not ( csDestroying In ComponentState ) Then UpdateData;
End;

Procedure TmxHeaderEditor.UpdateData;
Var
  Empty: Boolean;
Begin
  If CheckCollection Then
  Begin
    Caption := OutlookBarPro.Name;
    Empty := OutlookBarPro.HeaderCount = 0;

    If OutlookBarPro.HeaderCount = 0 Then
      StatusBar.SimpleText := 'This bar has not got any headers yet.' Else
      If OutlookBarPro.HeaderCount = 1 Then
        StatusBar.SimpleText := 'This bar has only one header' Else
        StatusBar.SimpleText := Format( '%d headers exit', [ OutlookBarPro.HeaderCount ] );
  End
  Else Empty := True;

  If Empty Then
  Begin
    StatusBar.SimpleText := 'This bar has not got any headers yet.';
    grid_Headers.RowCount := 2;
    grid_Buttons.RowCount := 2;
    SelectHeader( Nil );
  End
  Else
  Begin
    grid_Headers.RowCount := OutlookBarPro.HeaderCount + 1;
    grid_Buttons.Invalidate;
  End;

  If FActiveHeader <> Nil Then
  Begin
    btn_DeleteButton.Enabled := FActiveHeader.ButtonCount <> 0;
    mnu_DelButton.Enabled := btn_DeleteButton.Enabled;
    btn_NewButton.Enabled := True;
    grid_Buttons.Enabled := True;
  End
  Else
  Begin
    btn_DeleteButton.Enabled := False;
    mnu_DelButton.Enabled := btn_DeleteButton.Enabled;
    btn_NewButton.Enabled := False;
    grid_Buttons.Enabled := False;
  End;

  btn_Delete.Enabled := Not Empty;
  btn_Clear.Enabled := Not Empty;
  mnu_Delete.Enabled := Not Empty;

     //grid_Headers.Invalidate;
End;

Function TmxHeaderEditor.GetForm: TCustomForm;
Begin
  Result := {$IFDEF DELPHI6_UP}TCustomForm( Designer.Root ){$ELSE}Designer.Form{$ENDIF};
End;

Function TmxHeaderEditor.CheckCollection: Boolean;
Begin
  Result := ( OutlookBarPro <> Nil ) And ( OutlookBarPro.Owner <> Nil )
    And ( {$IFDEF DELPHI6_UP}Designer.Root{$ELSE}Designer.Form{$ENDIF} <> Nil );
End;

Procedure TmxHeaderEditor.FormClose( Sender: TObject; Var Action: TCloseAction );
Begin
  Action := caFree;
End;

{$IFDEF DELPHI6_UP}
Type
  TDesignerSelectionList = IDesignerSelections;
{$ENDIF}

Procedure TmxHeaderEditor.SelectHeader( AHeader: TmxHeader );
Var
  FComponents: TDesignerSelectionList;
Begin
  If CheckCollection And Active Then
  Begin
    FComponents := {$IFDEF DELPHI6_UP}TDesignerSelections{$ELSE}TDesignerSelectionList{$ENDIF}.Create;

    If AHeader <> Nil Then
    Begin
      FComponents.Add( AHeader );

      If AHeader.ButtonCount <> 0 Then
        grid_Buttons.RowCount := AHeader.ButtonCount + 1 Else
        grid_Buttons.RowCount := 2;

      FActiveHeader := AHeader;
    End
    Else
    Begin
      FComponents.Add( OutlookBarPro );
      grid_Buttons.RowCount := 2;
      FActiveHeader := Nil;
    End;

    SetSelection( FComponents );
    If Assigned( FActiveHeader ) Then UpdateData;
  End;
End;

⌨️ 快捷键说明

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