{ ------------------------------------------------------------- }
{ Purpose : NxInspector 6                                       }
{ By      : Bojan Nikolic                                       }
{ For     : BergSoft                                            }
{ ------------------------------------------------------------- }
{ Copyright (C) BergSoft.net 2011. All Rights Reserved.         }
{ ------------------------------------------------------------- }
{$I '..\NxSuite6.inc'}
unit NxInspectorStylePaint6;

interface

uses
  { Standard }
  Classes, Types, Windows, Graphics, Controls, StdCtrls,
  {$IFDEF UI_TYPES}UITypes,{$ENDIF}
  { Next Standard 6 }
  NxIntf6, NxClasses6, NxTypes6, NxStylePaint6,
  { NextInspector 6 }
  NxInspectorNode6;

type
  { TNxInspectorStylePaint }

  TNxInspectorStylePaint = class(TNxNativeStylePaint, INxInspectorStyle)
  private
    FGlyphCollapse: TBitmap;
    FGlyphExpand: TBitmap;
    FGridColor: TColor;
    FSplitterColor: TColor;
    FToggleStyle: TNxToggleButtonStyle;
    FTopLevelColor: TColor;
    function GetToggleStyle: TNxToggleButtonStyle;
    procedure SetGridColor(const Value: TColor);
    procedure SetSplitterColor(const Value: TColor);
    procedure SetToggleGlyphs(const Expand, Collapse: TBitmap);
    procedure SetToggleStyle(const Value: TNxToggleButtonStyle);
    procedure SetTopLevelColor(const Value: TColor); virtual;
  protected
    function GetSplitterColor: TColor; virtual;
  public
    constructor Create(AOwner: TComponent); override;
    { Drawing Methods }
//    procedure PaintDropDownButton(ButtonRect: TRect; State: TNxButtonState); override;
//    procedure DrawFrame(FrameRect: TRect); virtual; abstract;
    { Color Methods }
    function GetBackgroundColor(const DefaultColor: TColor): TColor; virtual;
    function GetDividerColor: TColor; virtual; abstract;
    function GetGrayColor: TColor; virtual; abstract;
    function GetGridColor: TColor; virtual; abstract;
    function GetMarginColor(const Node: TNxInspectorNode6;
      const DefaultColor: TColor): TColor; virtual; abstract;
    function GetSelectionBorderColor: TColor; virtual; abstract;
    function GetSelectionColor: TColor; virtual; abstract;
    function GetTextColor(const Node: TNxInspectorNode6; Selected, Focused: Boolean): TColor; virtual;
    function GetTopLevelColor: TColor; virtual;
    { Measuring Methods }
    function GetToggleSize: TSize; virtual;
    { Methods }
    procedure DrawToggle(ButtonRect: TRect; Collapsed: Boolean); virtual;
    procedure PaintToggle(ToggleRect: TRect; Expanded: Boolean;
      State: TNxButtonState); virtual; abstract;
    procedure PaintTopLevelSelection(SelectionRect: TRect); virtual;
    { Properties }
    property SplitterColor: TColor read GetSplitterColor write SetSplitterColor;
    property ToggleStyle: TNxToggleButtonStyle read GetToggleStyle write SetToggleStyle;
  end;

  TNxNativeInspectorStyle = class(TNxInspectorStylePaint)
  public
    { Drawing Methods }
    procedure PaintDropDownButton(ButtonRect: TRect; ButtonState: TNxButtonState); override;
    procedure DrawFrame(FrmRect: TRect); override;
    { Colors Properties }
    function GetBackgroundColor(const DefaultColor: TColor): TColor; override;
    function GetDividerColor: TColor; override;
    function GetGrayColor: TColor; override;
    function GetGridColor: TColor; override;
    function GetMarginColor(const Node: TNxInspectorNode6; const DefaultColor: TColor): TColor; override;
    function GetSelectionBorderColor: TColor; override;
    function GetSelectionColor: TColor; override;
    function GetTextColor(const Node: TNxInspectorNode6; Selected, Focused: Boolean): TColor; override;
    { Paint }
    procedure PaintToggle(ToggleRect: TRect; Expanded: Boolean;
      State: TNxButtonState); override;
  end;

  TNxModernInspectorStyle = class(TNxInspectorStylePaint)
  public
    procedure DrawFrame(FrmRect: TRect); override;
    { Drawing Methods }
    procedure PaintCheckBox(CheckBoxRect: TRect; CheckBoxState: TCheckBoxState;
      ButtonState: TNxButtonState); override;
    procedure PaintDropDownButton(ButtonRect: TRect; State: TNxButtonState); override;
    procedure PaintToggle(ToggleRect: TRect; Expanded: Boolean;
      State: TNxButtonState); override;
    procedure PaintToolButton(ButtonRect: TRect; State: TNxButtonState); override;
    procedure PaintTopLevelSelection(SelectionRect: TRect); override;
    { Colors Properties }
    function GetBackgroundColor(const DefaultColor: TColor): TColor; override;
    function GetDividerColor: TColor; override;
    function GetGrayColor: TColor; override;
    function GetGridColor: TColor; override;
    function GetMarginColor(const Node: TNxInspectorNode6; const DefaultColor: TColor): TColor; override;
    function GetSelectionBorderColor: TColor; override;
    function GetSelectionColor: TColor; override;
    function GetTextColor(const Node: TNxInspectorNode6;
      Selected, Focused: Boolean): TColor; override;
    function GetToggleSize: TSize; override;
    function GetTopLevelColor: TColor; override;
  end;

  { TNxUserDefinedInspectorStyle }

  TNxUserDefinedInspectorStyle = class(TNxNativeInspectorStyle)
  protected
    function GetSplitterColor: TColor; override;
  end;

implementation

uses
  { Standard }
  ExtCtrls, Math,
  { Next Standard 6 }
  NxConsts6, NxStyles6, NxGraphics6,
  { Visual Style }
{$IFDEF THEMES}
  UxTheme
{$ELSE}
  NxTheme6
{$ENDIF}
;

{ TNxVisualStudioInspectorStyle }

constructor TNxInspectorStylePaint.Create(AOwner: TComponent);
begin
  inherited;
  FGlyphCollapse := nil;
  FGlyphExpand := nil;
end;

procedure TNxInspectorStylePaint.DrawToggle(ButtonRect: TRect; Collapsed: Boolean);
var
  Glyph: TBitmap;
begin
  case ToggleStyle of

    tsStyleNative:
    begin
      PaintToggle(ButtonRect, not Collapsed, []);
    end;

    tsTriangle:
    begin

    end;

    tsGlyph:
    begin
      if Collapsed then Glyph := FGlyphExpand
      else Glyph := FGlyphCollapse;
      if Assigned(Glyph)
        and not Glyph.Empty then
      begin
        Glyph.Transparent := True;
        Glyph.TransparentColor := Glyph.Canvas.Pixels[0, Glyph.Height - 1];
        Canvas.Draw(ButtonRect.Left, ButtonRect.Top, Glyph)
      end;
    end;
  end;
end;

function TNxInspectorStylePaint.GetBackgroundColor(const DefaultColor: TColor): TColor;
begin
  Result := Color;
end;

function TNxInspectorStylePaint.GetSplitterColor: TColor;
begin
  Result := FGridColor;
end;

function TNxInspectorStylePaint.GetTextColor(const Node: TNxInspectorNode6;
  Selected, Focused: Boolean): TColor;
begin
  Result := Node.CaptionFont.Color;

  if Selected and Focused and not Node.IsTopLevel
    then Result := clHighlightText;
end;

function TNxInspectorStylePaint.GetToggleSize: TSize;
begin
  Result.cx := 9;
  Result.cy := 9;
  case ToggleStyle of
    tsStyleNative: ;
    tsTriangle: ;
    tsSquare: ;
    tsGlyph:
    begin
      Result := Size(Max(FGlyphExpand.Width, FGlyphCollapse.Width),
        Max(FGlyphExpand.Height, FGlyphCollapse.Height));
    end;
  end;
end;

function TNxInspectorStylePaint.GetToggleStyle: TNxToggleButtonStyle;
begin
  Result := FToggleStyle;
end;

function TNxInspectorStylePaint.GetTopLevelColor: TColor;
begin
  Result := FTopLevelColor;
end;

procedure TNxInspectorStylePaint.PaintTopLevelSelection(SelectionRect: TRect);
begin
  DrawFocusRect(Canvas, SelectionRect);
end;

procedure TNxInspectorStylePaint.SetGridColor(const Value: TColor);
begin
  FGridColor := Value;
end;

procedure TNxInspectorStylePaint.SetSplitterColor(const Value: TColor);
begin
  FSplitterColor := Value;
end;

procedure TNxInspectorStylePaint.SetToggleGlyphs(const Expand,
  Collapse: TBitmap);
begin
  FGlyphCollapse := Collapse;
  FGlyphExpand := Expand;
end;

procedure TNxInspectorStylePaint.SetToggleStyle(
  const Value: TNxToggleButtonStyle);
begin
  FToggleStyle := Value;
end;

procedure TNxInspectorStylePaint.SetTopLevelColor(const Value: TColor);
begin
  FTopLevelColor := Value;
end;

{ TNxNativeInspectorStyle }

procedure TNxNativeInspectorStyle.PaintDropDownButton(ButtonRect: TRect;
  ButtonState: TNxButtonState);
var
  DrawFlags, State: Integer;
  Theme: HTHEME;
begin
	if Themed then
 	begin
    Theme := OpenThemeData(Control.Handle, teComboBox);

    State := tiRadioNormal;
    if bsHover in ButtonState then State := tiRadioHover;
    if bsPressed in ButtonState then State := tiRadioDown;
    if bsDisabled in ButtonState then State := tiRadioDisabled;

    DrawThemeBackground(Theme, Canvas.Handle, 1, State, ButtonRect, nil);

    CloseThemeData(Theme);
  end else
  begin
    { Classic Drawing }
    DrawFlags := DFCS_SCROLLCOMBOBOX or DFCS_ADJUSTRECT;
    with Canvas do
    begin
      if bsPressed in ButtonState then DrawFlags := DrawFlags or DFCS_PUSHED;
      if bsDisabled in ButtonState then DrawFlags := DrawFlags or DFCS_INACTIVE;
      DrawFrameControl(Canvas.Handle, ButtonRect, DFC_SCROLL, DrawFlags)
    end;
  end;

end;

procedure TNxNativeInspectorStyle.PaintToggle(ToggleRect: TRect; Expanded: Boolean;
  State: TNxButtonState);
begin
  TNxTreeStyledView6.PaintToggle(Canvas, Control.Handle, ToggleRect, Expanded,
    State, StyleOptions);
end;

procedure TNxNativeInspectorStyle.DrawFrame(FrmRect: TRect);
begin
  Frame3D(Canvas, FrmRect, clBtnShadow, clBtnHighlight, 1);
end;

function TNxNativeInspectorStyle.GetBackgroundColor(const DefaultColor: TColor): TColor;
begin
  if aoStyleColors in GetAppearanceOptions
    then Result := TNxTreeStyledView6.GetFillColor(Control, Color)
      else Result := DefaultColor;
end;

function TNxNativeInspectorStyle.GetDividerColor: TColor;
begin
  Result := clBtnFace;
end;

function TNxNativeInspectorStyle.GetGrayColor: TColor;
begin
  Result := clGrayText;
end;

function TNxNativeInspectorStyle.GetGridColor: TColor;
begin
  Result := FGridColor;
end;

function TNxNativeInspectorStyle.GetMarginColor(
  const Node: TNxInspectorNode6; const DefaultColor: TColor): TColor;
begin
  Result := DefaultColor;
end;

function TNxNativeInspectorStyle.GetSelectionBorderColor: TColor;
begin
  Result := GetSelectionColor;
end;

function TNxNativeInspectorStyle.GetSelectionColor: TColor;
begin
  if Control.Focused then Result := clHighlight else Result := clBtnFace;
end;

function TNxNativeInspectorStyle.GetTextColor(const Node: TNxInspectorNode6; Selected, Focused: Boolean): TColor;
var
  Details: TNxStyleDetails;
begin
  Result := inherited GetTextColor(Node, Selected, Focused);
  if aoStyleColors in GetAppearanceOptions then
  begin
    Details := [];
    if Selected then Include(Details, sdSelected);
    Result := TNxTreeStyledView6.GetTextColor(Control, Details, Result);
  end;
end;

{ TNxModerInspectorStyle }

procedure TNxModernInspectorStyle.PaintCheckBox(CheckBoxRect: TRect;
  CheckBoxState: TCheckBoxState; ButtonState: TNxButtonState);
begin

  with Canvas do
  begin
    { Paint Box }
    Pen.Color := ColorOf(seBtnFrame);
    Brush.Color := clWhite;

    if bsHover in ButtonState then
    begin

      Pen.Color := ColorOf(seBtnFacePressed);
      Brush.Color := ColorOf(seBtnFace);

      if bsPressed in ButtonState then
      begin
        Pen.Color := ColorOf(seBtnFacePressed);
        Brush.Color := ColorOf(seBtnFacePressed);
      end;

    end;

    Rectangle(CheckBoxRect);

    { Paint CheckMark }

  end;
end;

procedure TNxModernInspectorStyle.PaintDropDownButton(ButtonRect: TRect;
  State: TNxButtonState);
begin
  PaintToolButton(ButtonRect, State);
end;

procedure TNxModernInspectorStyle.DrawFrame(FrmRect: TRect);
begin
  with Canvas do
  begin
    Brush.Color := $00e7e4e2;
    FrameRect(FrmRect);
  end;
end;

procedure TNxModernInspectorStyle.PaintToggle(ToggleRect: TRect; Expanded: Boolean;
  State: TNxButtonState);
var
  ToggleSize: TSize;
  X, Y, C: Integer;
begin
  X := ToggleRect.Left;
  Y := ToggleRect.Top;
  ToggleSize := Size(RectWidth(ToggleRect), RectHeight(ToggleRect));
//  with Canvas do
//  begin
//    Brush.Color := clRed;
//    FillRect(ToggleRect);
//  end;
  with Canvas do
    if Expanded then
    begin
      if bsHover in State then
      begin
        Brush.Color := ColorOf(seMenu);
      end else
      begin
        Brush.Color := $00444444;
      end;
      Pen.Color := Brush.Color;

      C := ToggleSize.cy - 1;

      Polygon([
        Point(X, Y + C),
        Point(X + C, Y + C),
        Point(X + C, Y),
        Point(X, Y + C)
      ]);
    end else
    begin
      Dec(Y);
//      Y := Y - Pred(ToggleSize.cy);

      if bsHover in State then
      begin
        Brush.Color := ColorOf(seBtnFramePressed);
        Pen.Color := Brush.Color;
      end else
      begin
        Brush.Color := clWhite;
        Pen.Color := $00888683;
      end;

      Polygon([
        Point(X, Y),
        Point(X + ToggleSize.cx - 2, Y + ToggleSize.cx - 2),
        Point(X, Y + (ToggleSize.cx - 2) * 2),
        Point(X, Y)
      ]);
    end;
end;

procedure TNxModernInspectorStyle.PaintToolButton(ButtonRect: TRect;
  State: TNxButtonState);
begin
  with Canvas do
  begin
    { Draw Frame }
    if State <> [] then
    begin
      Brush.Color := ColorOf(seBtnFace);

      if bsPressed in State then
      begin
        if bsHover in State
          then Brush.Color := ColorOf(seBtnFacePressed)
          else Brush.Color := clWindow; { ToDo: Color of background }
      end
      else if bsChecked in State then
      begin
        if bsHover in State
          then Brush.Color := ColorOf(seBtnFace)
          else Brush.Color := ColorOf(seBtnFaceChecked);
      end;

      FillRect(ButtonRect);

    end;
  end;

end;

procedure TNxModernInspectorStyle.PaintTopLevelSelection(SelectionRect: TRect);
begin
  with Canvas do
  begin
    Brush.Color := $00444444;
    FrameRect(SelectionRect);
  end;
end;

function TNxModernInspectorStyle.GetBackgroundColor(const DefaultColor: TColor): TColor;
begin
  Result := DefaultColor;
end;

function TNxModernInspectorStyle.GetDividerColor: TColor;
begin
  Result := ColorOf(seDivider);
end;

function TNxModernInspectorStyle.GetGrayColor: TColor;
begin
  Result := $00777777;
end;

function TNxModernInspectorStyle.GetGridColor: TColor;
begin
  Result := ColorOf(seDivider);
end;

function TNxModernInspectorStyle.GetMarginColor(
  const Node: TNxInspectorNode6; const DefaultColor: TColor): TColor;
begin
  if Node.IsTopLevel then Result := ColorOf(seDivider) else Result := clWhite;
end;

function TNxModernInspectorStyle.GetSelectionBorderColor: TColor;
begin
  Result := clHighlight;
end;

function TNxModernInspectorStyle.GetSelectionColor: TColor;
begin
  Result := ColorOf(seBtnFace);
end;

function TNxModernInspectorStyle.GetTextColor(const Node: TNxInspectorNode6;
  Selected, Focused: Boolean): TColor;
begin
  Result := Node.CaptionFont.Color;
end;

function TNxModernInspectorStyle.GetToggleSize: TSize;
begin
  Result := inherited GetToggleSize;
  if ToggleStyle = tsStyleNative then Result := Size(7, 7);
end;

function TNxModernInspectorStyle.GetTopLevelColor: TColor;
begin
  Result := ColorOf(seDivider);
end;

{ TNxUserDefinedInspectorStyle }

function TNxUserDefinedInspectorStyle.GetSplitterColor: TColor;
begin
  Result := FSplitterColor;
end;

end.
