unit QExport4Dsgn;

{$I QExport4VerCtrl.inc}

interface

uses
  {$IFDEF VCL16}
    System.Classes,
    Vcl.Controls,
    Vcl.Graphics,
    Winapi.Windows,
  {$ELSE}
    Classes,
    Controls,
    Graphics,
    Windows,
  {$ENDIF}
  {$IFDEF VCL6}
    DesignIntf,
    DesignEditors,
    VCLEditors
  {$ELSE}
    DsgnIntf
  {$ENDIF};

type

  TQExportEditor = class(TDefaultEditor)
  public
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportHTMLEditor = class(TQExportEditor)
  protected
  {$IFDEF VCL6}
  procedure EditProperty(const Prop: IProperty; var Continue: Boolean);
    override;
  {$ELSE}
  procedure EditProperty(PropertyEditor: TPropertyEditor;
    var Continue, FreeEditor: boolean); override;
  {$ENDIF}
  public
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportXLSEditor = class(TDefaultEditor)
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportODSEditor = class(TDefaultEditor)
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportODTEditor = class(TDefaultEditor)
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportXlsxEditor = class(TDefaultEditor)
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQExportDocxEditor = class(TDefaultEditor)
    function GetVerbCount: integer; override;
    function GetVerb(Index: integer): string; override;
    procedure ExecuteVerb(Index: integer); override;
    procedure Edit; override;
  end;

  TQHTMLTemplateProperty = class(TEnumProperty)
  public
    procedure Edit; override;
  end;

  TQDateTimeFormatProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TQDateFormatProperty = class(TQDateTimeFormatProperty)
  public
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TQTimeFormatProperty = class(TQDateTimeFormatProperty)
  public
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TQFileNameProperty = class(TStringProperty)
  protected
    function GetFilter: string; virtual; abstract;
    function GetDefaultExt: string; virtual; abstract;
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;

  TxlsColorProperty = class(TIntegerProperty
  {$IFDEF VCL6}, ICustomPropertyDrawing, ICustomPropertyListDrawing{$ENDIF})
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure GetValues(Proc: TGetStrProc); override;
    procedure SetValue(const Value: string); override;

    { ICustomPropertyListDrawing }
    {$IFDEF VCL5}
    procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas;
      var AWidth: Integer); {$IFNDEF VCL6}override;{$ENDIF}
    {$ENDIF}
    {$IFDEF VCL6}
    procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas;
      var AHeight: Integer);
    {$ENDIF}
    {$IFDEF VCL5}
    procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
      const ARect: TRect; ASelected: Boolean); {$IFNDEF VCL6}override;{$ENDIF}
    {$ENDIF}

    { CustomPropertyDrawing }
    {$IFDEF VCL6}
    procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect;
      ASelected: Boolean);
    {$ENDIF}
    {$IFDEF VCL5}
    procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
      ASelected: Boolean); {$IFNDEF VCL6}override;{$ENDIF}
    {$ENDIF}
  end;

  TQExcelFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQRTFFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQHTMLFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQHTMLBkgFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQLaTeXFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQASCIIFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQCSSFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQSQLFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQAppFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQXMLFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQDBFFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQODSFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQODTFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQXlsxFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQDocxFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQCFGFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQPDFFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQPictureFileNameProperty = class(TQFileNameProperty)
  protected
    function GetFilter: string; override;
    function GetDefaultExt: string; override;
  end;

  TQExportAboutProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure Edit; override;
  end;

  TQExportVersionProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
    procedure Edit; override;
  end;

  TQExcelFieldNameProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TQExcelPictureNameProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  {$IFDEF ADO}
  TQDatabaseNameProperty = class(TQFileNameProperty)
    protected
      function GetFilter: string; override;
      function GetDefaultExt: string; override;
  end;
  {$ENDIF}


implementation

uses
  {$IFDEF VCL16}
    System.SysUtils,
    Data.Db,
    Vcl.DBGrids,
    Vcl.ComCtrls,
    Vcl.Grids,
    Vcl.Dialogs,
    System.TypInfo,
  {$ELSE}
    SysUtils,
    Db,
    DBGrids,
    ComCtrls,
    Grids,
    Dialogs,
    TypInfo,
  {$ENDIF}
  QExport4,
  QExport4HTML,
  QExport4ASCII,
  QExport4XLS,
  QExport4Dialog,
  QExport4Common,
  QExport4XLSCommon,
  QExport4ODT,
  QExport4ODS,
  QExport4Xlsx,
  QExport4Docx,
  fuQExport4About,
  fuQExport4HTMLTemplateEditor,
  fuQExport4ColumnsEditor,
  fuQExport4XLSEditor,
  fuQExport4XLSColorEditor,
  fuQExport4ODSEditor,
  fuQExport4ODTEditor,
  fuQExport4XlsxEditor,
  fuQExport4DocxEditor;

function GetObjDelimiter: string;
begin
{$IFDEF BCB}
  Result := '->'
{$ELSE}
  Result := '.';
{$ENDIF}
end;

{ TQExportEditor }

procedure TQExportEditor.Edit;
begin
  inherited;
end;

procedure TQExportEditor.ExecuteVerb(Index: integer);
var
  FExport: TQExport4;
  FDialog: TQExport4Dialog;
begin
  case Index of
    0: begin
      FExport := nil;
      FDialog := nil;
      if Component is TQExport4
        then FExport := Component as TQExport4
        else if Component is TQExport4Dialog
               then FDialog := Component as TQExport4Dialog;

      if Assigned(FExport) then begin
        with FExport do
          if RunQExportColumnsEditor(ExportSource, DataSet, CustomSource, DBGrid,
            ListView, StringGrid, ExportedFields)
            then Designer.Modified
      end else begin
        if Assigned(FDialog) then
          with FDialog do
            if RunQExportColumnsEditor(ExportSource, DataSet, CustomSource, DBGrid,
                 ListView, StringGrid, ExportedFields)
              then Designer.Modified
      end;
    end;
    1: ShowAboutForm;
  end;
end;

function TQExportEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'F&ields editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

function TQExportEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

{ TVHTMLTemplateProperty }

procedure TQHTMLTemplateProperty.Edit;
var
  QHE: TQExport4HTML;
  HT: THTMLTemplate;
begin
  QHE := GetComponent(0) as TQExport4HTML;
  with TfmQExport4HTMLTemplateEditor.Create(nil) do begin
    try
      Caption := Format('%s%s%s -- HTML Template Editor', [QHE.Owner.Name,
        GetObjDelimiter, QHE.Name]);
      HT := THTMLTemplate(GetOrdValue);
      Template := HT;
      if HT = htCustom then begin
        BackGroundColor := QHE.HTMLOptions.BackgroundColor;
        DefaultTextColor := QHE.HTMLOptions.TextFont.Color;
        LinkColor := QHE.HTMLOptions.LinkColor;
        VLinkColor := QHE.HTMLOptions.VLinkColor;
        ALinkColor := QHE.HTMLOptions.ALinkColor;
        TextFontName := QHE.HTMLOptions.TextFont.Name;
        HeadersRowBgColor := QHE.TableOptions.HeadersRowBgColor;
        HeadersRowFontColor := QHE.TableOptions.HeadersRowFontColor;
        TableBgColor := QHE.TableOptions.TableBgColor;
        TableFontColor := QHE.TableOptions.TableFontColor;
        OddRowBgColor := QHE.TableOptions.OddRowBgColor;
      end;
      if ShowModal = mrOk then begin
        SetOrdValue(Integer(Template));
        if Template = htCustom then begin
          QHE.HTMLOptions.BackGroundColor := BackgroundColor;
          QHE.HTMLOptions.TextFont.Color := DefaultTextColor;
          QHE.HTMLOptions.LinkColor := LinkColor;
          QHE.HTMLOptions.VLinkColor := VLinkColor;
          QHE.HTMLOptions.ALinkColor := ALinkColor;
          QHE.HTMLOptions.TextFont.Name := TextFontName;
          QHE.TableOptions.HeadersRowBgColor := HeadersRowBgColor;
          QHE.TableOptions.HeadersRowFontColor := HeadersRowFontColor;
          QHE.TableOptions.TableBgColor := TableBgColor;
          QHE.TableOptions.TableFontColor := TableFontColor;
          QHE.TableOptions.OddRowBgColor := OddRowBgColor;
        end;
      end;
    finally
      Free;
    end;
  end;
end;

{ TQDateTimeFormatProperty }

function TQDateTimeFormatProperty.GetAttributes: TPropertyAttributes;
begin
  Result := inherited GetAttributes + [paValueList];
end;

procedure TQDateTimeFormatProperty.GetValues(Proc: TGetStrProc);
begin
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortDateFormat + ' ' + {$IFDEF VCL17}FormatSettings.{$ENDIF}ShortTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortDateFormat + ' ' + {$IFDEF VCL17}FormatSettings.{$ENDIF}LongTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongDateFormat + ' ' +  {$IFDEF VCL17}FormatSettings.{$ENDIF}ShortTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongDateFormat + ' ' +  {$IFDEF VCL17}FormatSettings.{$ENDIF}LongTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortDateFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongDateFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongTimeFormat);
end;

{ TQDateFormatProperty }

procedure TQDateFormatProperty.GetValues(Proc: TGetStrProc);
begin
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortDateFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongDateFormat);
end;

{ TQTimeFormatProperty }

procedure TQTimeFormatProperty.GetValues(Proc: TGetStrProc);
begin
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}ShortTimeFormat);
  Proc({$IFDEF VCL17}FormatSettings.{$ENDIF}LongTimeFormat);
end;

{ TQHTMLExportEdtor }

function TQExportHTMLEditor.GetVerbCount: integer;
begin
  Result := 3;
end;

function TQExportHTMLEditor.GetVerb(Index: integer): string;
begin
  case Index of
   2: Result := 'Edit HTML template...';
   else
     Result:= inherited GetVerb(Index);
  end;
end;

procedure TQExportHTMLEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    2: Edit
    else inherited ExecuteVerb(Index);
  end;
end;

procedure TQExportHTMLEditor.Edit;
begin
  inherited;
end;

{$IFDEF VCL6}
procedure TQExportHTMLEditor.EditProperty(const Prop: IProperty; var Continue: Boolean);
begin
  if CompareText(Prop.GetName, 'HTMLTemplate') = 0 then begin
    Prop.Edit;
    Continue := False;
  end;
end;
{$ELSE}
procedure TQExportHTMLEditor.EditProperty(PropertyEditor: TPropertyEditor;
  var Continue, FreeEditor: boolean);
begin
  if CompareText(PropertyEditor.GetName, 'HTMLTemplate') = 0 then begin
    PropertyEditor.Edit;
    Continue := false;
  end;
end;
{$ENDIF}

{ TQXLSExportEdtor }

function TQExportXLSEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

function TQExportXLSEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'Component editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

procedure TQExportXLSEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    0: if RunQExportXLSEditor(Component as TQExport4XLS, Designer)
         then Designer.Modified;
    1: ShowAboutForm;
  end;
end;

procedure TQExportXLSEditor.Edit;
begin
  ExecuteVerb(0);
end;

{ TQFileNameProperty }

procedure TQFileNameProperty.Edit;
var
  OpenDialog: TOpenDialog;
begin
  OpenDialog := TOpenDialog.Create(nil);
  try
    OpenDialog.Filter := GetFilter;
    OpenDialog.DefaultExt := GetDefaultExt;
    OpenDialog.FileName := GetStrValue;
    if OpenDialog.Execute then
      SetStrValue(OpenDialog.FileName);
  finally
    OpenDialog.Free;
  end;
end;

function TQFileNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result := inherited GetAttributes + [paDialog];
end;

{ TQExcelFileNameProperty }

function TQExcelFileNameProperty.GetDefaultExt: string;
begin
  Result := 'xls';
end;

function TQExcelFileNameProperty.GetFilter: string;
begin
  Result := 'Microsoft Excel files (*.xls)|*.xls';
end;

{ TVRTFFileNameProperty }

function TQRTFFileNameProperty.GetDefaultExt: string;
begin
  Result := 'doc';
end;

function TQRTFFileNameProperty.GetFilter: string;
begin
  Result := 'Microsoft Word files (*.doc)|*.doc|RTF files (*.rtf)|*.rtf'
end;

{ TQHTMLFileNameProperty }

function TQHTMLFileNameProperty.GetDefaultExt: string;
begin
  Result := 'html';
end;

function TQHTMLFileNameProperty.GetFilter: string;
begin
  Result := 'HTML files (*.html, *.htm)|*.html;*.htm';
end;

{ TQLaTeXFileNameProperty }

function TQLaTeXFileNameProperty.GetDefaultExt: string;
begin
  Result := 'tex';
end;

function TQLaTeXFileNameProperty.GetFilter: string;
begin
  Result := 'LaTeX files (*.tex)|*.tex';
end;

{ TQASCIIFileNameProperty }

function TQASCIIFileNameProperty.GetDefaultExt: string;
var
  QExport: TQExport4ASCII;
begin
  QExport := GetComponent(0) as TQExport4ASCII;
  case QExport.ExportType of
    etTxt:  Result := 'txt';
    etCSV:  Result := 'csv';
    etDIF:  Result := 'dif';
    etSYLK: Result := 'slk';
  end;
end;

function TQASCIIFileNameProperty.GetFilter: string;
var
  QExport: TQExport4ASCII;
begin
  QExport := GetComponent(0) as TQExport4ASCII;
  case QExport.ExportType of
    etTxt:  Result := 'Text files (*.txt)|*.txt';
    etCSV:  Result := 'CSV files (*.csv)|*.csv';
    etDIF:  Result := 'DIF files (*.dif)|*.dif';
    etSYLK: Result := 'SYLK files (*.slk)|*.slk';
  end;
end;

{ TQCSSFileNameProperty }

function TQCSSFileNameProperty.GetDefaultExt: string;
begin
  Result := 'css';
end;

function TQCSSFileNameProperty.GetFilter: string;
begin
  Result := 'Cascading style sheets files (*.css)|*.css';
end;

{ TQSQLFileNameProperty }

function TQSQLFileNameProperty.GetDefaultExt: string;
begin
  Result := 'sql';
end;

function TQSQLFileNameProperty.GetFilter: string;
begin
  Result := 'SQL files (*.sql)|*.sql';
end;

{ TQAppFileNameProperty }

function TQAppFileNameProperty.GetDefaultExt: string;
begin
  Result := 'exe';
end;

function TQAppFileNameProperty.GetFilter: string;
begin
  Result := 'Executable files (*.exe)|*.exe';
end;

{ TQXMLFileNameProperty }

function TQXMLFileNameProperty.GetDefaultExt: string;
begin
  Result := 'xml';
end;

function TQXMLFileNameProperty.GetFilter: string;
begin
  Result := 'XML files (*.xml)|*.xml';
end;

{ TQXlsxFileNameProperty }

function TQXlsxFileNameProperty.GetDefaultExt: string;
begin
  Result := 'xlsx';
end;

function TQXlsxFileNameProperty.GetFilter: string;
begin
  Result := 'Microsoft Excel 2007 files (*.xlsx)|*.xlsx';
end;

{ TQDocxFileNameProperty }

function TQDocxFileNameProperty.GetDefaultExt: string;
begin
  Result := 'docx';
end;

function TQDocxFileNameProperty.GetFilter: string;
begin
  Result := 'Microsoft Word 2007 files (*.docx)|*.docx';
end;

{ TQDBFFileNameProperty }

function TQDBFFileNameProperty.GetDefaultExt: string;
begin
  Result := 'dbf';
end;

function TQDBFFileNameProperty.GetFilter: string;
begin
  Result := 'DBF files (*.dbf)|*.dbf';
end;

{ TQCFGFileNameProperty }

function TQCFGFileNameProperty.GetDefaultExt: string;
begin
  Result := 'cfg';
end;

function TQCFGFileNameProperty.GetFilter: string;
begin
  Result := 'Configurations files (*.cfg)|*.cfg';
end;

{ TQPDFFileNameProperty }

function TQPDFFileNameProperty.GetDefaultExt: string;
begin
  Result := 'pdf';
end;

function TQPDFFileNameProperty.GetFilter: string;
begin
  Result := 'PDF Document files (*.pdf)|*.pdf';
end;

{ TQPictureFileNameProperty }

function TQPictureFileNameProperty.GetDefaultExt: string;
begin
  Result := 'bmp';
end;

function TQPictureFileNameProperty.GetFilter: string;
begin
  Result := 'All Images (*.bmp;*.wmf;*.emf;*.jpg;*.jpeg;*.png;*.gif)|' +
            '*.bmp;*.wmf;*.emf;*.jpg;*.jpeg;*.png;*.gif|' +
            'Bitmaps (*.bmp)|*.bmp|' +
            'Metafiles (*.wmf)|*.wmf|' +
            'Enhanced Metafiles (*.emf)|*.emf|' +
            'JPEG Image File (*.jpg)|*.jpg|' +
            'JPEG Image File (*.jpeg)|*.jpeg|' +
            'PNG Image (*.png)|*.png|' +
            'GIF Image (*.gif)|*.gif';
end;

{ TQExportAboutProperty }

procedure TQExportAboutProperty.Edit;
begin
  ShowAboutForm;
end;

function TQExportAboutProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paReadOnly, paDialog];
end;

function TQExportAboutProperty.GetValue: string;
begin
  Result := S_ABOUT;
end;

{ TQExportVersionProperty }

procedure TQExportVersionProperty.Edit;
begin
  ShowAboutForm;
end;

function TQExportVersionProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paReadOnly, paDialog];
end;

function TQExportVersionProperty.GetValue: string;
begin
  Result := S_VERSION_NUMBER;
end;

{ TQExcelFieldNameProperty }

function TQExcelFieldNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList]
end;

procedure TQExcelFieldNameProperty.GetValues(Proc: TGetStrProc);
var
  WasInActive: Boolean;
  Holder: TPersistent;
  i: Integer;
  PropInfo: PPropInfo;
  ExportSource: TQExportSource;
  DataSet: TDataSet;
  DBGrid: TDBGrid;
  ListView: TListView;
  StringGrid: TStringGrid;
begin
  Holder := (((GetComponent(0) as TxlsFieldFormat).Collection as TxlsFieldFormats).Holder);

  PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'ExportSource');
  if not Assigned(PropInfo) then Exit;

  ExportSource := TQExportSource({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));

  case ExportSource of
    esDataSet: begin
      PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'DataSet');
      if not Assigned(PropInfo) then Exit;
      DataSet := TDataSet({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));
      if not Assigned(DataSet) then Exit;

      WasInActive :=  not Dataset.Active;
      if WasInActive then
      try
        Dataset.Open;
      except
        Exit;
      end;
      for i := 0 to DataSet.FieldCount - 1 do begin
        Proc(DataSet.Fields[I].FieldName);
      end;
      if WasInActive then
      try
        Dataset.Close;
      except
      end;
    end; //esDataSet
    esDBGrid: begin
      PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'DBGrid');
      if not Assigned(PropInfo) then Exit;
      DBGrid := TDBGrid({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));
      if not Assigned(DBGrid) then Exit;

      if DBGrid.Columns.Count > 0 then begin
        for i := 0 to DBGrid.Columns.Count - 1 do begin
          Proc(DBGrid.Columns[i].Title.Caption);
        end;
      end
      else if Assigned(DBGrid.DataSource) and
              Assigned(DBGrid.DataSource.DataSet) then begin
        DataSet := DBGrid.DataSource.DataSet;
        WasInActive :=  not Dataset.Active;
        if WasInActive then
        try
          Dataset.Open;
        except
          Exit;
        end;
        for i := 0 to DataSet.FieldCount - 1 do begin
          Proc(DataSet.Fields[I].FieldName);
        end;
        if WasInActive then
        try
          Dataset.Close;
        except
        end;
        end;
    end; //esDBGrid
    esListView: begin
      PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'ListView');
      if not Assigned(PropInfo) then Exit;
      ListView := TListView({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));
      if not Assigned(ListView) then Exit;

      for i := 0 to ListView.Columns.Count - 1 do begin
        Proc(ListView.Columns[i].Caption);
      end;
    end;//esListView
    esStringGrid: begin
      PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'StringGrid');
      if not Assigned(PropInfo) then Exit;
      StringGrid := TStringGrid({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));
      if not Assigned(StringGrid) then Exit;

      for i := 0 to StringGrid.ColCount - 1 do begin
        Proc(IntToStr(i));
      end;
    end;//esStringGrid;
  end;
end;

{ TQExcelPictureNameProperty }

function TQExcelPictureNameProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList]
end;

procedure TQExcelPictureNameProperty.GetValues(Proc: TGetStrProc);
var
//  WasInActive: Boolean;
  Holder: TPersistent;
  i: integer;
  PropInfo: PPropInfo;
//  ExportSource: TQExportSource;
//  DataSet: TDataSet;
//  DBGrid: TDBGrid;
//  ListView: TListView;
//  StringGrid: TStringGrid;
  Pictures: TxlsPictures;
begin
  Holder := (((GetComponent(0) as TxlsImage).Collection as TxlsImages).Holder);

  if Holder is TxlsSheet then
    Holder := ((Holder as TxlsSheet).Collection as TxlsSheets).QExportXLS;

  PropInfo := {$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetPropInfo(Holder.ClassInfo, 'Pictures');
  if not Assigned(PropInfo) then Exit;

  Pictures := TxlsPictures({$IFDEF VCL16}System.TypInfo{$ELSE}TypInfo{$ENDIF}.GetOrdProp(Holder, PropInfo));
  for i := 0 to Pictures.Count - 1 do
    Proc(Pictures[i].Name);
{  ExportSource := TQExportSource(TypInfo.GetOrdProp(Holder, PropInfo));

  case ExportSource of
    esDataSet: begin
      PropInfo := TypInfo.GetPropInfo(Holder.ClassInfo, 'DataSet');
      if not Assigned(PropInfo) then Exit;
      DataSet := TDataSet(TypInfo.GetOrdProp(Holder, PropInfo));
      if not Assigned(DataSet) then Exit;

      WasInActive :=  not Dataset.Active;
      if WasInActive then
      try
        Dataset.Open;
      except
        Exit;
      end;
      for i := 0 to DataSet.FieldCount - 1 do begin
        Proc(DataSet.Fields[I].FieldName);
      end;
      if WasInActive then
      try
        Dataset.Close;
      except
      end;
    end; //esDataSet
    esDBGrid: begin
      PropInfo := TypInfo.GetPropInfo(Holder.ClassInfo, 'DBGrid');
      if not Assigned(PropInfo) then Exit;
      DBGrid := TDBGrid(TypInfo.GetOrdProp(Holder, PropInfo));
      if not Assigned(DBGrid) then Exit;

      if DBGrid.Columns.Count > 0 then begin
        for i := 0 to DBGrid.Columns.Count - 1 do begin
          Proc(DBGrid.Columns[i].Title.Caption);
        end;
      end
      else if Assigned(DBGrid.DataSource) and
              Assigned(DBGrid.DataSource.DataSet) then begin
        DataSet := DBGrid.DataSource.DataSet;
        WasInActive :=  not Dataset.Active;
        if WasInActive then
        try
          Dataset.Open;
        except
          Exit;
        end;
        for i := 0 to DataSet.FieldCount - 1 do begin
          Proc(DataSet.Fields[I].FieldName);
        end;
        if WasInActive then
        try
          Dataset.Close;
        except
        end;
        end;
    end; //esDBGrid
    esListView: begin
      PropInfo := TypInfo.GetPropInfo(Holder.ClassInfo, 'ListView');
      if not Assigned(PropInfo) then Exit;
      ListView := TListView(TypInfo.GetOrdProp(Holder, PropInfo));
      if not Assigned(ListView) then Exit;

      for i := 0 to ListView.Columns.Count - 1 do begin
        Proc(ListView.Columns[i].Caption);
      end;
    end;//esListView
    esStringGrid: begin
      PropInfo := TypInfo.GetPropInfo(Holder.ClassInfo, 'StringGrid');
      if not Assigned(PropInfo) then Exit;
      StringGrid := TStringGrid(TypInfo.GetOrdProp(Holder, PropInfo));
      if not Assigned(StringGrid) then Exit;

      for i := 0 to StringGrid.ColCount - 1 do begin
        Proc(IntToStr(i));
      end;
    end;//esStringGrid;
  end;}
end;

{ TQDatabaseNameProperty }

{$IFDEF ADO}
function TQDatabaseNameProperty.GetFilter: string;
begin
  Result := 'MS Access files (*.mdb, *.accdb)|*.mdb;*.accdb';
end;

function TQDatabaseNameProperty.GetDefaultExt: string;
begin
  Result := 'mdb';
end;
{$ENDIF}

{ TxlsColorProperty }

const
  xlsColors: array[0..39] of TIdentMapEntry = (
    (Value: Integer(clrBlack); Name: 'clrBlack'),
    (Value: Integer(clrBrown); Name: 'clrBrown'),
    (Value: Integer(clrOliveGreen); Name: 'clrOliveGreen'),
    (Value: Integer(clrDarkGreen); Name: 'clrDarkGreen'),
    (Value: Integer(clrDarkTeal); Name: 'clrDarkTeal'),
    (Value: Integer(clrDarkBlue); Name: 'clrDarkBlue'),
    (Value: Integer(clrIndigo); Name: 'clrIndigo'),
    (Value: Integer(clrGray80Percent); Name: 'clrGray80Percent'),
    (Value: Integer(clrDarkRed); Name: 'clrDarkRed'),
    (Value: Integer(clrOrange); Name: 'clrOrange'),
    (Value: Integer(clrDarkYellow); Name: 'clrDarkYellow'),
    (Value: Integer(clrGreen); Name: 'clrGreen'),
    (Value: Integer(clrTeal); Name: 'clrTeal'),
    (Value: Integer(clrBlue); Name: 'clrBlue'),
    (Value: Integer(clrBlueGray); Name: 'clrBlueGray'),
    (Value: Integer(clrGray50Percent); Name: 'clrGray50Percent'),
    (Value: Integer(clrRed); Name: 'clrRed'),
    (Value: Integer(clrLightOrange); Name: 'clrLightOrange'),
    (Value: Integer(clrLime); Name: 'clrLime'),
    (Value: Integer(clrSeaGreen); Name: 'clrSeaGreen'),
    (Value: Integer(clrAqua); Name: 'clrAqua'),
    (Value: Integer(clrLightBlue); Name: 'clrLightBlue'),
    (Value: Integer(clrViolet); Name: 'clrViolet'),
    (Value: Integer(clrGray40Percent); Name: 'clrGray40Percent'),
    (Value: Integer(clrPink); Name: 'clrPink'),
    (Value: Integer(clrGold); Name: 'clrGold'),
    (Value: Integer(clrYellow); Name: 'clrYellow'),
    (Value: Integer(clrBrightGreen); Name: 'clrBrightGreen'),
    (Value: Integer(clrTurquoise); Name: 'clrTurquoise'),
    (Value: Integer(clrSkyBlue); Name: 'clrSkyBlue'),
    (Value: Integer(clrPlum); Name: 'clrPlum'),
    (Value: Integer(clrGray25Percent); Name: 'clrGray25Percent'),
    (Value: Integer(clrRose); Name: 'clrRose'),
    (Value: Integer(clrTan); Name: 'clrTan'),
    (Value: Integer(clrLightYellow); Name: 'clrLightYellow'),
    (Value: Integer(clrLihtGreen); Name: 'clrLihtGreen'),
    (Value: Integer(clrLightTurquoise); Name: 'clrLightTurquoise'),
    (Value: Integer(clrPaleBlue); Name: 'clrPaleBlue'),
    (Value: Integer(clrLavender); Name: 'clrLavender'),
    (Value: Integer(clrWhite); Name: 'clrWhite'));

function ExcelColorToIdent(xlsColor: TxlsColor; var Ident: string): Boolean;
begin
  Result := IntToIdent(Integer(xlsColor), Ident, xlsColors);
end;

function IdentToExcelColor(const Ident: string; var xlsColor: TxlsColor): Boolean;
var
  iColor: integer;
begin
  iColor := Integer(xlsColor);
  Result := IdentToInt(Ident, iColor, xlsColors);
  xlsCOlor := TxlsColor(iColor);
end;

function ExcelColorToString(Color: TxlsColor): string;
begin
  ExcelColorToIdent(Color, Result);
end;

{$IFDEF VCL5}
function StringToExcelColor(const S: string): TxlsColor;
begin
  if not IdentToExcelColor(S, Result) then
    Result := clrBlack;
end;

function ExcelColorToColor(Color: TxlsColor): TColor;
begin
  Result := XLS_STANDARD_PALETTE[Integer(Color)];
end;
{$ENDIF}

procedure TxlsColorProperty.Edit;
var
  OClr, NClr: TxlsColor;
begin
  OClr := TxlsColor(GetOrdValue);
  NClr := RunXLSColorEditor(OClr);
  if NClr <> OClr then begin
    SetOrdValue(Integer(NClr));
    SetStrValue(ExcelColorToString(NClr));
  end;
end;

function TxlsColorProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;

function TxlsColorProperty.GetValue: string;
begin
  Result := ExcelColorToString(TxlsColor(GetOrdValue));
end;

procedure TxlsColorProperty.GetValues(Proc: TGetStrProc);
var
  i: integer;
begin
  for i := Integer(Low(TxlsColor)) to Integer(High(TxlsColor)) do
    Proc(xlsColors[i].Name);
end;

{$IFDEF VCL5}
procedure TxlsColorProperty.ListDrawValue(const Value: string;
  ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);

  function ColorToBorderColor(AColor: TxlsColor): TColor;
  type
    TColorQuad = record
      Red,
      Green,
      Blue,
      Alpha: Byte;
    end;
  var
    FColor: TColor;
  begin
    FColor := ExcelColorToColor(AColor);
    if (TColorQuad(FColor).Red > 192) or
       (TColorQuad(FColor).Green > 192) or
       (TColorQuad(FColor).Blue > 192) then
      Result := clBlack
    else if ASelected then
      Result := clWhite
    else
      Result := ExcelColorToColor(AColor);
  end;
  
var
  vRight: Integer;
  vOldPenColor, vOldBrushColor: TColor;
begin
  vRight := (ARect.Bottom - ARect.Top) {* 2} + ARect.Left;
  with ACanvas do
  try
    // save off things
    vOldPenColor := Pen.Color;
    vOldBrushColor := Brush.Color;

    // frame things
    Pen.Color := Brush.Color;
    Rectangle(ARect.Left, ARect.Top, vRight, ARect.Bottom);

    // set things up and do the work
    Brush.Color := ExcelColorToColor(StringToExcelColor(Value));
    Pen.Color := ColorToBorderColor(StringToExcelColor(Value));
    Rectangle(ARect.Left + 1, ARect.Top + 1, vRight - 1, ARect.Bottom - 1);

    // restore the things we twiddled with
    Brush.Color := vOldBrushColor;
    Pen.Color := vOldPenColor;
  finally
    {$IFDEF VCL6}
    DefaultPropertyListDrawValue(Value, ACanvas, Rect(vRight, ARect.Top,
      ARect.Right, ARect.Bottom), ASelected);
    {$ELSE}
    inherited ListDrawValue(Value, ACanvas, Rect(vRight, ARect.Top, ARect.Right,
      ARect.Bottom), ASelected);
    {$ENDIF}
  end;
end;
{$ENDIF}

{$IFDEF VCL5}
procedure TxlsColorProperty.ListMeasureWidth(const Value: string;
  ACanvas: TCanvas; var AWidth: Integer);
begin
  AWidth := AWidth + ACanvas.TextHeight('M') {* 2};
end;
{$ENDIF}

{$IFDEF VCL6}
procedure TxlsColorProperty.ListMeasureHeight(const Value: string;
  ACanvas: TCanvas; var AHeight: Integer);
begin
  // No implemenation necessary
end;
{$ENDIF}

{$IFDEF VCL5}
procedure TxlsColorProperty.PropDrawValue(ACanvas: TCanvas;
  const ARect: TRect; ASelected: Boolean);
begin
  if GetVisualValue <> '' then
    ListDrawValue(GetVisualValue, ACanvas, ARect, True{ASelected})
  else
  {$IFDEF VCL6}
  DefaultPropertyDrawValue(Self, ACanvas, ARect);
  {$ELSE}
  inherited PropDrawValue(ACanvas, ARect, ASelected);
  {$ENDIF}
end;
{$ENDIF}

{$IFDEF VCL6}
procedure TxlsColorProperty.PropDrawName(ACanvas: TCanvas; const ARect: TRect;
  ASelected: Boolean);
begin
  DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
{$ENDIF}

procedure TxlsColorProperty.SetValue(const Value: string);
var
  NewValue: TxlsColor;
begin
  if IdentToExcelColor(Value, NewValue) then
    SetOrdValue(Integer(NewValue))
  else inherited SetValue(Value);
end;

{ TQHTMLBkgFileNameProperty }

function TQHTMLBkgFileNameProperty.GetDefaultExt: string;
begin
  Result := 'jpg';
end;

function TQHTMLBkgFileNameProperty.GetFilter: string;
begin
  Result := 'Graphics files (*.jpg, *.jpeg, *.gif, *.png)|*.jpg;*.jpeg;*.gif;*.png|All files (*.*)|*.*';
end;

{ TQODSFileNameProperty }

function TQODSFileNameProperty.GetDefaultExt: string;
begin
  Result := 'ods';
end;

function TQODSFileNameProperty.GetFilter: string;
begin
  Result := 'ODS files (*.ods)|*.ods';
end;

{ TQODTFileNameProperty }

function TQODTFileNameProperty.GetDefaultExt: string;
begin
  Result := 'odt';
end;

function TQODTFileNameProperty.GetFilter: string;
begin
  Result := 'ODT files (*.odt)|*.odt';
end;

{ TQExportODSEditor }

procedure TQExportODSEditor.Edit;
begin
  ExecuteVerb(0);
end;

procedure TQExportODSEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    0: if RunQExportODSEditor(Component as TQExport4ODS)
         then Designer.Modified;
    1: ShowAboutForm;
  end;
end;

function TQExportODSEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'Component editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

function TQExportODSEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

{ TQExportODTEditor }

procedure TQExportODTEditor.Edit;
begin
  ExecuteVerb(0);
end;

procedure TQExportODTEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    0: if RunQExportODTEditor(Component as TQExport4ODT)
         then Designer.Modified;
    1: ShowAboutForm;
  end;
end;

function TQExportODTEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'Component editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

function TQExportODTEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

{ TQExportXlsxEditor }

function TQExportXlsxEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

function TQExportXlsxEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'Component editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

procedure TQExportXlsxEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    0: if RunQExportXlsxEditor(Component as TQExport4Xlsx)
         then Designer.Modified;
    1: ShowAboutForm;
  end;
end;

procedure TQExportXlsxEditor.Edit;
begin
  ExecuteVerb(0);
end;

{ TQExportDocxEditor }

function TQExportDocxEditor.GetVerbCount: integer;
begin
  Result := 2;
end;

function TQExportDocxEditor.GetVerb(Index: integer): string;
begin
  case Index of
    0: Result := 'Component editor...';
    1: Result := '&About EMS QuickExport...';
  end;
end;

procedure TQExportDocxEditor.ExecuteVerb(Index: integer);
begin
  case Index of
    0: if RunQExportDocxEditor(Component as TQExport4Docx)
         then Designer.Modified;
    1: ShowAboutForm;
  end;
end;

procedure TQExportDocxEditor.Edit;
begin
  ExecuteVerb(0);
end;

end.
