{-----------------------------------------------------------------------------
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: JvQExControls.macros, released on 2004-09-21

The Initial Developer of the Original Code is André Snepvangers [asn att xs4all dott nl]
Portions created by André Snepvangers are Copyright (C) 2004 André Snepvangers.
All Rights Reserved.


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

Description:

This file contains macro's needed to build the JvExCLX classes.
You need the Pascal PreProcessor (dpp) from Andreas Hausladen [Andreas dott Hausladen att gmx dott de]
to process these files.
It is included in JVCL 3: devtools\dpp32

Known Issues:
-----------------------------------------------------------------------------}

// This comment is inserted into every JvQExXxx.pas file
(*$DEFINE WARNINGHEADER
{*****************************************************************************
 * WARNING: Do not edit this file.
 * This file is autogenerated from the source in devtools/JvExCLX/src.
 * If you do it despite this warning your changes will be discarded by the next
 * update of this file. Do your changes in the template files.
 ****************************************************************************}
*)


{$UNDEF CREATE_CUSTOMCODE}
{$UNDEF DESTROY_CUSTOMCODE}
{$UNDEF IFISNOTCUSTOMFORM}
{$UNDEF HITTEST_DECL}
{$UNDEF HITTEST_CODE}

{$DEFINE EMPTYLINE}
{$DEFINE CREATE_CUSTOMCODE}
{$DEFINE DESTROY_CUSTOMCODE}
{$DEFINE IFISNOTCUSTOMFORM}

(*$DEFINE UNITVERSION
const
  UnitVersion = UnitName;

initialization
  OutputDebugString(PChar('JvExCLX Loaded: ' + UnitVersion));

finalization
  OutputDebugString(PChar('JvExCLX Unloaded: ' + UnitVersion));
EMPTYLINE
*)

// *************************************************************************
// *************************** INTERFACE MACROS ****************************
// *************************************************************************
{$DEFINE HITTEST_DECL override}

(*$DEFINE JV_DECL_CONTROL
  { QControl }
  private
    FAboutJVCL: TJVCLAboutInfo;
    FDesktopFont: Boolean;
    FDragCursor: TCursor;
    FDragKind: TDragKind;
    FHintColor: TColor;
    FMouseOver: Boolean;
    FOnParentColorChanged: TNotifyEvent;
    FWindowProc: TWndMethod;
    procedure SetDesktopFont(Value: Boolean);
    procedure CMHitTest(var Mesg: TJvMessage); message CM_HITTEST;
    procedure CMHintShow(var Mesg: TJvMessage); message CM_HINTSHOW;
    procedure CMSysFontChanged(var Mesg: TMessage); message CM_SYSFONTCHANGED;
  protected
    procedure ColorChanged; override;
    procedure EnabledChanged; override;
    procedure FocusChanged; dynamic;
    function HitTest(X, Y: integer): Boolean; HITTEST_DECL;
    procedure MouseEnter(AControl: TControl); override;
    procedure MouseLeave(AControl: TControl); override;
    procedure ParentColorChanged; override;
    procedure TextChanged; override;
    procedure VisibleChanged; override;
    function HintShow(var HintInfo : THintInfo): Boolean; override;
    procedure WndProc(var Mesg: TMessage); dynamic;
    property DragCursor: TCursor read FDragCursor write FDragCursor default crDefault; { not implemented }
    property DragKind: TDragKind read FDragKind write FDragKind  default dkDrag; { not implemented }
    property OnParentColorChange: TNotifyEvent read FOnParentColorChanged write FOnParentColorChanged;
    property DesktopFont: Boolean read FDesktopFont write SetDesktopFont default false;
  public
    procedure Dispatch(var Mesg); override;
    function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
    function IsRightToLeft: Boolean;
    property WindowProc: TWndMethod read FWindowProc write FWindowProc;
    property MouseOver: Boolean read FMouseOver write FMouseOver;
  published
    property AboutJVCLX: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored False;
    property HintColor: TColor read FHintColor write FHintColor default clDefault;
*)

(*$DEFINE JV_CONTROL_BEGIN(NameOfClass)
  { QControl begin }
  TJvEx##NameOfClass = class(T##NameOfClass)
  JV_DECL_CONTROL
*)

(*$DEFINE JV_CONTROL_END(NameOfClass)
  protected
    procedure FontChanged; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

  { QControl }
  TJvExPub##NameOfClass = class(TJvEx##NameOfClass);
  EMPTYLINE
*)

(*$DEFINE JV_CONTROL(NameOfClass)
  JV_CONTROL_BEGIN(NameOfClass)
  JV_CONTROL_END(NameOfClass)
*)

//
//  used by WinCustomControl, WinControl, CustomControl, EditControl
//
(*$DEFINE JV_DECL_WINCONTROL
  { QWinControl }
  private
    FInternalFontChanged: TNotifyEvent;
    FOnEvent: TEventEvent;
    procedure DoOnFontChanged(Sender: TObject);
    procedure CMDesignHitTest(var Mesg: TJvMessage); message CM_DESIGNHITTEST;
  protected
    procedure CreateWidget; override;
    procedure CreateWnd; virtual;
    procedure CursorChanged; override;
    procedure DoEnter; override;
    function DoEraseBackground(Canvas: TCanvas; Param: Integer): Boolean; virtual;
    procedure DoExit; override;
    procedure DoKillFocus(NextWnd: HWND); dynamic;
    procedure DoSetFocus(PreviousWnd: HWND); dynamic;
    function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; override;
    procedure PaintWindow(PaintDevice: QPaintDeviceH);
    procedure RecreateWnd;
    procedure ShowingChanged; override;
    function WidgetFlags: Integer; override;
  public
    function ColorToRGB(Value: TColor): TColor;
    procedure PaintTo(PaintDevice: QPaintDeviceH; X, Y: Integer);
  published
    property OnEvent: TEventEvent read FOnEvent write FOnEvent;
*)
//
// WidgetControls without a Canvas property.
// used by WinControl & EditControl
//
(*$DEFINE JV_WINCONTROL_END(NameOfClass)
  { QWinControl }
  private
    FCanvas: TControlCanvas;
    FDoubleBuffered: Boolean;
    function GetCanvas: TCanvas;
  protected
    procedure Paint; virtual;
    procedure Painting(Sender: QObjectH; EventRegion: QRegionH); override;
    property DoubleBuffered: Boolean read FDoubleBuffered write FDoubleBuffered;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas: TCanvas read GetCanvas;
  end;

  { QWinControl }
  TJvExPub##NameOfClass = class(TJvEx##NameOfClass)
  end;
  EMPTYLINE
*)

//
// ListViews, TreeViews, IconViews, Forms with a Canvas.
// - No Paint override;
//
(*$DEFINE JV_WINCUSTOMCONTROL_END(NameOfClass)
  { QWinCustomControl }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

  { QWinCustomControl }
  TJvExPub##NameOfClass = class(TJvEx##NameOfClass);
  EMPTYLINE
*)

//
// CustomControls do not require Paint & Canvas
//
(*$DEFINE JV_CUSTOMCONTROL_END(NameOfClass)
  private
    FDoubleBuffered: Boolean;
  protected
    property DoubleBuffered: Boolean read FDoubleBuffered write FDoubleBuffered;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

  { QCustomControl }
  TJvExPub##NameOfClass = class(TJvEx##NameOfClass);
  EMPTYLINE
*)

(*$DEFINE JV_CUSTOMFORM_END(NameOfClass)
  { QCustomForm }
  public
    constructor Create(AOwner: TComponent); override;
    constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
    destructor Destroy; override;
  end;

  TJvExPub##NameOfClass = class(TJvEx##NameOfClass)
  end;
  EMPTYLINE
*)


(*$DEFINE JV_WINCONTROL_BEGIN(NameOfClass)
  { QWinControl Begin }
  TJvEx##NameOfClass = class(T##NameOfClass)
  JV_DECL_CONTROL
  JV_DECL_WINCONTROL
*)

(*$DEFINE JV_WINCUSTOMCONTROL_BEGIN(NameOfClass)
  { QWinCustomControl }
  JV_WINCONTROL_BEGIN(NameOfClass)
*)

(*$DEFINE JV_CUSTOMCONTROL_BEGIN(NameOfClass)
  { QCustomControl Begin }
  JV_WINCONTROL_BEGIN(NameOfClass)
*)

(*$DEFINE JV_CUSTOMFORM_BEGIN(NameOfClass)
  { QCustomForm }
  JV_WINCONTROL_BEGIN(NameOfClass)
*)

(*$DEFINE JV_WINCONTROL(NameOfClass)
  JV_WINCONTROL_BEGIN(NameOfClass)
  JV_WINCONTROL_END(NameOfClass)
*)

(*$DEFINE JV_WINCUSTOMCONTROL(NameOfClass)
  JV_WINCONTROL_BEGIN(NameOfClass)
  JV_WINCUSTOMCONTROL_END(NameOfClass)
*)


(*$DEFINE JV_CUSTOMCONTROL(NameOfClass)
  JV_WINCONTROL_BEGIN(NameOfClass)
  JV_CUSTOMCONTROL_END(NameOfClass)
*)

(*$DEFINE JV_CUSTOMFORM(NameOfClass)
  JV_WINCONTROL_BEGIN(NameOfClass)
  JV_CUSTOMFORM_END(NameOfClass)
*)


(*$DEFINE JV_DECL_EDITCONTROL
  { QEditControl }
  private
    FClipboardCommands: TJvClipboardCommands;
    procedure WMClear(var Mesg: TMessage); message WM_CLEAR;
    procedure WMCopy(var Mesg: TMessage); message WM_COPY;
    procedure WMCut(var Mesg: TMessage); message WM_CUT;
    procedure WMPaste(var Mesg: TMessage); message WM_PASTE;
    procedure WMUndo(var Mesg: TMessage); message WM_UNDO;
  public
    procedure PasteFromClipboard; override;
    procedure CopyToClipboard; override;
    procedure Clear; override;
    procedure CutToClipboard; override;
    procedure Undo; override;
  published
    property ClipboardCommands: TJvClipboardCommands read FClipboardCommands
      write FClipboardCommands default [caCopy..caUndo];
*)

(*$DEFINE JV_DECL_CUSTOMEDIT
  { QCustomEdit }
  private
    FCharCase: TEditCharCase;
    FEdit: TEdit;
    function GetAutoSelect: Boolean;
    function GetCanUndo: Boolean;
    function GetCanRedo: Boolean;
    function GetCursorPos: Integer;
    function GetModified: Boolean;
    procedure SetCharCase(Value: TEditCharCase);
    procedure SetEchoMode(const Value: TEchoMode);
  protected
    procedure DoEnter; override;
    procedure DoExit; override;
    procedure SetMaxLength(const Value: Integer); dynamic;
    procedure SetModified(const Value: Boolean); override;
    function GetSelLength: Integer; override;
    function GetSelStart: Integer; override;
    function GetSelText: TCaption; override;
    function GetText: TCaption; override;
    procedure SetAutoSelect(const Value: Boolean); overide;
    procedure SetCursorPos(const Value: Integer); override;
    procedure SetSelLength(Value: Integer); override;
    procedure SetSelStart(Value: Integer); override;
    procedure SetSelText(const Value: WideString); override;
    procedure SetText(const Value: TCaption); override;
  public
    procedure ClearSelection; override;
    procedure Redo; override;
    procedure SetFocus; override;
    procedure SelectAll; override
    property CanRedo: Boolean read GetCanRedo;
    property CanUndo: Boolean read GetCanUndo;
    property CursorPos: Integer read GetCursorPos write SetCursorPos;
    property Modified: Integer read GetModified write SetModified;
  published
    property CharCase: TEditCharCase read GetCharCase write SetCharCase default ecNormal;
*)

(*$DEFINE JV_EDITCONTROL_BEGIN(NameOfClass)
  { QEditControl Begin }
  TJvEx##NameOfClass = class(T##NameOfClass)
  JV_DECL_CONTROL
  JV_DECL_WINCONTROL
  JV_DECL_EDITCONTROL
*)

(*$DEFINE JV_CUSTOMEDIT_BEGIN(NameOfClass)
  { QCustomEdit Begin }
  TJvEx##NameOfClass = class(T##NameOfClass)
  JV_DECL_CONTROL
  JV_DECL_WINCONTROL
  JV_DECL_EDITCONTROL
  JV_DECL_CUSTOMEDIT
*)


(*$DEFINE JV_EDITCONTROL_END(NameOfClass)
JV_WINCONTROL_END(NameOfClass)
*)

(*$DEFINE JV_CUSTOMEDIT_END(NameOfClass)
JV_WINCONTROL_END(NameOfClass)
*)

(*$DEFINE JV_EDITCONTROL(NameOfClass)
  JV_EDITCONTROL_BEGIN(NameOfClass)
  JV_WINCONTROL_END(NameOfClass)
*)

(*$DEFINE JV_CUSTOMEDIT(NameOfClass)
  JV_CUSTOMEDIT_BEGIN(NameOfClass)
  JV_WINCONTROL_END(NameOfClass)
*)


// *************************************************************************
// ************************* IMPLEMENTATION MACROS *************************
// *************************************************************************
{$DEFINE HITTEST_CODE Handled := inherited HitTest(XPos, YPos);}

(*$DEFINE JV_IMPL_CONTROL_CREATE(NameOfClass)
{ QControl Create }
constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHintColor := clDefault;
  FWindowProc := WndProc;
  CREATE_CUSTOMCODE
end;

destructor TJvEx##NameOfClass.Destroy;
begin
  DESTROY_CUSTOMCODE
  inherited Destroy;
end;
 EMPTYLINE
*)

(*$DEFINE JV_IMPL_CONTROL_MESSAGES
    { Control Messages }
      CM_FOCUSCHANGED: FocusChanged;
      CM_MOUSEENTER: FMouseOver := True;
      CM_MOUSELEAVE: FMouseOver := False;

*)

(*$DEFINE JV_IMPL_CONTROL(NameOfClass)
procedure TJvEx##NameOfClass.WndProc(var Mesg: TMessage);
begin
  //OutputDebugString(PAnsiChar(Format('JV_CONTROL %s: %s Msg $%x',[Name, ClassName, Mesg.Msg])));
  with TJvMessage(Mesg) do
  begin
    case Msg of
      JV_IMPL_CONTROL_MESSAGES
      CM_HINTSHOW:
      begin
        case FHintColor of
          clNone   : HintInfo^.HintColor := Application.HintColor;
          clDefault: HintInfo^.HintColor := GetHintColor(Parent);
        else
          HintInfo^.HintColor := FHintcolor;
        end;
      end;
    else
      inherited Dispatch(Mesg);
    end;
  end;
end;

procedure TJvEx##NameOfClass.CMHitTest(var Mesg: TJvMessage);
begin
  with Mesg do
  begin
    Handled := inherited HitTest(XPos, YPos);
    if Handled then
      Result := HTCLIENT;
  end;
end;

procedure TJvEx##NameOfClass.ColorChanged;
begin
  Perform(CM_COLORCHANGED, 0, 0);
  inherited ColorChanged;
end;

procedure TJvEx##NameOfClass.FontChanged;
begin
  Perform(CM_FONTCHANGED, 0, 0);
  inherited FontChanged;
end;

procedure TJvEx##NameOfClass.FocusChanged;
begin
  { notification }
end;
 EMPTYLINE
*)

(*$DEFINE JV_IMPL_CONTROL_COMMON(NameOfClass)
{ QControl Common}

function TJvEx##NameOfClass.HitTest(X, Y: integer): Boolean;
begin
   Result := Perform(CM_HITTEST, 0, 0) <> HTNOWHERE;
end;

procedure TJvEx##NameOfClass.CMHintShow(var Mesg: TJvMessage);
begin
  with Mesg do
  begin
    Handled := inherited HintShow(HintInfo^);
  end;
end;

procedure TJvEx##NameOfClass.CMSysFontChanged(var Mesg: TMessage);
begin
  if FDesktopFont then
  begin
    Font.Assign(Application.Font);
    FDesktopFont := True;
  end;
end;

procedure TJvEx##NameOfClass.EnabledChanged;
begin
  Perform(CM_ENABLEDCHANGED, 0, 0);
  inherited EnabledChanged;
end;

procedure TJvEx##NameOfClass.TextChanged;
begin
  Perform(CM_TEXTCHANGED, 0, 0);
  inherited TextChanged;
end;

procedure TJvEx##NameOfClass.VisibleChanged;
begin
  Perform(CM_VISIBLECHANGED, 0, 0);
  inherited VisibleChanged;
end;

function TJvEx##NameOfClass.HintShow(var HintInfo : THintInfo): Boolean;
begin
  Result := Perform(CM_HINTSHOW, 0, Integer(@HintInfo)) <> 0;
end;

procedure TJvEx##NameOfClass.MouseEnter(AControl: TControl);
begin
  Perform(CM_MOUSEENTER, 0, 0);
  inherited MouseEnter(AControl);
end;

procedure TJvEx##NameOfClass.MouseLeave(AControl: TControl);
begin
  Perform(CM_MOUSELEAVE, 0, 0);
  inherited MouseLeave(AControl);
end;

procedure TJvEx##NameOfClass.ParentColorChanged;
begin
  inherited ParentColorChanged;
  if Assigned(FOnParentColorChanged) then
    FOnParentColorChanged(Self);
end;

procedure TJvEx##NameOfClass.SetDesktopFont(Value: Boolean);
begin
  if FDesktopFont <> Value then
  begin
    FDesktopFont := Value;
    Perform(CM_SYSFONTCHANGED, 0, 0);
  end;
end;

procedure TJvEx##NameOfClass.Dispatch(var Mesg);
begin
  if Assigned(FWindowProc) then
    FWindowProc(TMessage(Mesg))
  else
    WndProc(TMessage(Mesg))
end;

function TJvEx##NameOfClass.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
var
  Mesg: TMessage;
begin
  Mesg.Msg := Msg;
  Mesg.WParam := WParam;
  Mesg.LParam := LParam;
  Mesg.Result := 0;
  Dispatch(Mesg);
  Result := Mesg.Result;
end;

function TJvEx##NameOfClass.IsRightToLeft: Boolean;
begin
  Result := False;
end;
  EMPTYLINE
*) // MACRO END JV_IMPL_CONTROL

(*$DEFINE JV_CONTROL_IMPL(NameOfClass)
JV_IMPL_CONTROL_CREATE(NameOfClass)
JV_IMPL_CONTROL(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
*)


(*$DEFINE JV_IMPL_WINCONTROL_CREATE(NameOfClass)
{ QWinControl Create }

constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FWindowProc := WndProc;
  FInternalFontChanged := Font.OnChange;
  Font.OnChange := DoOnFontChanged;
  FHintColor := clDefault;
  FDoubleBuffered := True;
  CREATE_CUSTOMCODE
end;

destructor TJvEx##NameOfClass.Destroy;
begin
  DESTROY_CUSTOMCODE
  FCanvas.Free;
  inherited Destroy;
end;
  EMPTYLINE
*) // end macro JV_IMPL_WINCONTROL_CREATE

(*$DEFINE JV_IMPL_CUSTOMCONTROL_CREATE(NameOfClass)
{ QCustomControl Create }

constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FWindowProc := WndProc;
  FInternalFontChanged := Font.OnChange;
  Font.OnChange := DoOnFontChanged;
  FHintColor := clDefault;
  FDoubleBuffered := True;
  CREATE_CUSTOMCODE
end;

destructor TJvEx##NameOfClass.Destroy;
begin
  DESTROY_CUSTOMCODE
  inherited Destroy;
end;
  EMPTYLINE
*) // end macro JV_IMPL_CUSTOMCONTROL_CREATE

//
// used by WinCustomControl & CustomForm
//

(*$DEFINE JV_IMPL_WINCUSTOMCONTROL_CREATE(NameOfClass)
{ QWinCustomControl Create }

constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FWindowProc := WndProc;
  FInternalFontChanged := Font.OnChange;
  Font.OnChange := DoOnFontChanged;
  FHintColor := clDefault;
  CREATE_CUSTOMCODE
end;

destructor TJvEx##NameOfClass.Destroy;
begin
  DESTROY_CUSTOMCODE
  inherited Destroy;
end;
EMPTYLINE
*)

(*$DEFINE JV_IMPL_CUSTOMFORM_CREATE(NameOfClass)

{ QWinCustomControl Create }
constructor TJvEx##NameOfClass.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
  inherited CreateNew(AOwner, Dummy);
  FWindowProc := WndProc;
  FHintColor := clDefault;
  CREATE_CUSTOMCODE
end;

JV_IMPL_WINCUSTOMCONTROL_CREATE(NameOfClass)
EMPTYLINE
*)

// ************************************************


(*$DEFINE JV_IMPL_WINCONTROL_MESSAGES
      { WinControl Messages }
      WM_GETDLGCODE   : Result := InputKeysToDlgCodes(InputKeys);
      WM_KILLFOCUS    : DoKillFocus(FocusedWnd);
      WM_SETFOCUS     : DoSetFocus(FocusedWnd);
      CM_FONTCHANGED  : FInternalFontChanged(Font);

      CM_HINTSHOW:
      begin
        HintInfo^.HintColor := GetHintcolor(Self);
      end;

      WM_ERASEBKGND:
      begin
        Canvas.Start;
        try
          Handled := DoEraseBackGround(Canvas, LParam);
        finally
          Canvas.Stop;
        end;
      end;
*)

(*$DEFINE JV_IMPL_WINCONTROL(NameOfClass)
procedure TJvEx##NameOfClass.WndProc(var Mesg: TMessage);
begin
  //OutputDebugString(PAnsiChar(Format('WINCONTROL %s: %s Msg $%x',[Name, ClassName, Mesg.Msg])));
  with TJvMessage(Mesg) do
  begin
    case Msg of
      JV_IMPL_WINCONTROL_MESSAGES
      JV_IMPL_CONTROL_MESSAGES

    else
      inherited Dispatch(Mesg);
    end;
  end;
end;

*)

(*$DEFINE JV_IMPL_WINCONTROL_COMMON(NameOfClass)
{ QWinControl Common }
procedure TJvEx##NameOfClass.CMDesignHitTest(var Mesg: TJvMessage);
begin
  with Mesg do
  begin
    HITTEST_CODE
    if Handled then
      Result := HTCLIENT;
  end;
end;

procedure TJvEx##NameOfClass.CMHitTest(var Mesg: TJvMessage);
begin
  with Mesg do
  begin
    if csDesigning in ComponentState then
      Result := Perform(CM_DESIGNHITTEST, XPos, YPos)
    else
    begin
      HITTEST_CODE
      if Handled then
        Result := HTCLIENT;
    end;
  end;
end;

function TJvEx##NameOfClass.DoEraseBackground(Canvas: TCanvas; Param: Integer): Boolean;
begin
  Result := false;
end;

procedure TJvEx##NameOfClass.ShowingChanged;
begin
  Perform(CM_SHOWINGCHANGED, 0 ,0);
  inherited;
end;

procedure TJvEx##NameOfClass.ColorChanged;
begin
  Perform(CM_COLORCHANGED, 0, 0);
  inherited;
end;

procedure TJvEx##NameOfClass.CursorChanged;
begin
  Perform(CM_CURSORCHANGED, 0, 0);
  inherited;
end;

procedure TJvEx##NameOfClass.DoSetFocus(PreviousWnd: QWidgetH);
begin
  { notification }
end;

procedure TJvEx##NameOfClass.DoKillFocus(NextWnd: QWidgetH);
begin
  { notification }
end;

procedure TJvEx##NameOfClass.DoEnter;
begin
  Perform(CM_ENTER, 0 ,0);
  inherited DoEnter;
end;

procedure TJvEx##NameOfClass.DoExit;
begin
  Perform(CM_EXIT, 0 ,0);
  inherited DoExit;
end;

function TJvEx##NameOfClass.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
begin
  Result := False;
  if Assigned(FOnEvent) then
    FOnEvent(Sender, Event, Result);
  if not Result then
    Result := inherited EventFilter(Sender, Event); 
end;

procedure TJvEx##NameOfClass.FocusChanged;
begin
  NotifyControls(CM_FOCUSCHANGED);
end;

procedure TJvEx##NameOfClass.DoOnFontChanged(Sender: TObject);
begin
  ParentFont := False;
  PostMessage(Self, CM_FONTCHANGED, 0, 0);
end;

procedure TJvEx##NameOfClass.CreateWidget;
begin
  CreateWnd;
end;

procedure TJvEx##NameOfClass.CreateWnd;
begin
  inherited CreateWidget;
end;

procedure TJvEx##NameOfClass.RecreateWnd;
begin
  RecreateWidget;
end;

procedure TJvEx##NameOfClass.PaintTo(PaintDevice: QPaintDeviceH; X, Y: Integer);
begin
  WidgetControl_PaintTo(self, PaintDevice, X, Y);
end;

procedure TJvEx##NameOfClass.PaintWindow(PaintDevice: QPaintDeviceH);
begin
  PaintTo(PaintDevice, 0, 0);
end;

function TJvEx##NameOfClass.WidgetFlags: Integer;
begin
  Result := inherited WidgetFlags or
    Integer(WidgetFlags_WRepaintNoErase) or
    Integer(WidgetFlags_WMouseNoMask);
end;

function TJvEx##NameOfClass.ColorToRGB(Value: TColor): TColor;
begin
  Result := QWindows.ColorToRGB(Value, self);
end;
  EMPTYLINE
*) // MACRO END WINCONTROL_COMMON

//
// implement paint for native Qt Widgets.
//
(*$DEFINE JV_IMPL_WINCONTROL_PAINT(NameOfClass)
{ WinControl Paint }

function TJvEx##NameOfClass.GetCanvas: TCanvas;
begin
  if not Assigned(FCanvas) then
  begin
    FCanvas := TControlCanvas.Create;
    FCanvas.Control := self;
  end;
  Result := FCanvas;
end;


//procedure TJvEx##NameOfClass.Paint;
//begin
//  TControlCanvas(Canvas).StopPaint;
//  inherited Painting(Handle, QPainter_clipRegion(Canvas.Handle));
//  TControlCanvas(Canvas).StartPaint;
//end;


procedure TJvEx##NameOfClass.Paint;
var
  ForcedPaintEvent: QPaintEventH;
begin
//  ForcedPaintEvent := QPaintEvent_create(QPainter_clipRegion(Canvas.Handle), False);
    ForcedPaintEvent := QPaintEvent_create(QPainter_clipRegion(Canvas.Handle), True);
  try
    ControlState := ControlState + [csWidgetPainting];
    TControlCanvas(Canvas).StopPaint;
    try
      QObject_event(Handle, ForcedPaintEvent);
    finally
      ControlState := ControlState - [csWidgetPainting];
    end;
  finally
    QPaintEvent_destroy(ForcedPaintEvent);
    TControlCanvas(Canvas).StartPaint;
  end;
end;

procedure TJvEx##NameOfClass.Painting(Sender: QObjectH; EventRegion: QRegionH);
begin
  TControlCanvas(Canvas).StartPaint;
  try
    Canvas.Brush.Assign(Brush);
    Canvas.Font.Assign(Font);
    RequiredState(Canvas, [csHandleValid, csFontValid, csBrushValid]);
    QPainter_setClipping(Canvas.Handle, True);
    Paint;
  finally
    TControlCanvas(Canvas).StopPaint;
  end;
end;
 EMPTYLINE
*)


(*$DEFINE JV_CUSTOMCONTROL_IMPL(NameOfClass)
JV_IMPL_CUSTOMCONTROL_CREATE(NameOfClass)
JV_IMPL_WINCONTROL(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
 EMPTYLINE
*)

(*$DEFINE JV_WINCONTROL_IMPL(NameOfClass)
JV_IMPL_WINCONTROL_CREATE(NameOfClass)
JV_IMPL_WINCONTROL_PAINT(NameOfClass)
JV_IMPL_WINCONTROL(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
 EMPTYLINE
*)

(*$DEFINE JV_WINCUSTOMCONTROL_IMPL(NameOfClass)
JV_IMPL_WINCUSTOMCONTROL_CREATE(NameOfClass)
JV_IMPL_WINCONTROL(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
 EMPTYLINE
*)

(*$DEFINE JV_CUSTOMFORM_IMPL(NameOfClass)
JV_IMPL_CUSTOMFORM_CREATE(NameOfClass)
JV_IMPL_WINCONTROL(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
*)


(*$DEFINE JV_IMPL_EDITCONTROL_MESSAGES

      WM_GETTEXTLENGTH : Result := Length(GetText);

      WM_CLEAR, WM_COPY,
      WM_CUT, WM_PASTE, WM_UNDO :
        if DoClipBoardCommands(msg, FClipBoardCommands) then
          inherited Dispatch(msg);

      EM_UNDO:  Result := Perform(WM_UNDO, 0, 0);
*)

(*$DEFINE JV_IMPL_EDITCONTROL_COMMON(NameOfClass)
{ QEditControl Common}

procedure TJvEx##NameOfClass.WndProc(var Mesg: TMessage);
begin
  //OutputDebugString(PAnsiChar(Format('EDITCONTROL %s: %s Msg $%x',[Name, ClassName, Mesg.Msg])));
  with TJvMessage(Mesg) do
  begin
    case Msg of
      JV_IMPL_EDITCONTROL_MESSAGES
      JV_IMPL_WINCONTROL_MESSAGES
      JV_IMPL_CONTROL_MESSAGES
    else
      inherited Dispatch(Mesg);
    end;
  end;
end;

procedure TJvEx##NameOfClass.Undo;
begin
  SendMessage(Handle, WM_UNDO, 0, 0);
end;

procedure TJvEx##NameOfClass.CopyToClipboard;
begin
  SendMessage(Handle, WM_COPY, 0, 0);
end;

procedure TJvEx##NameOfClass.CutToClipboard;
begin
  if not ReadOnly then
    SendMessage(Handle, WM_CUT, 0, 0);
end;

procedure TJvEx##NameOfClass.Clear;
begin
  if not ReadOnly then
    SendMessage(Handle, WM_CLEAR, 0, 0);
end;

procedure TJvEx##NameOfClass.PasteFromClipboard;
begin
  if not ReadOnly then
    SendMessage(Handle, WM_PASTE, 0, 0);
end;
 EMPTYLINE
*)

(*$DEFINE JV_IMPL_EDITCONTROL(NameOfClass)
procedure TJvEx##NameOfClass.WMClear(var Mesg: TMessage);
begin
  inherited Clear;
end;

procedure TJvEx##NameOfClass.WMCopy(var Mesg: TMessage);
begin
  inherited CopyToClipBoard;
end;

procedure TJvEx##NameOfClass.WMCut(var Mesg: TMessage);
begin
  inherited CutToClipBoard;
end;

procedure TJvEx##NameOfClass.WMPaste(var Mesg: TMessage);
begin
  inherited PasteFromClipBoard;
end;

procedure TJvEx##NameOfClass.WMUndo(var Mesg: TMessage);
begin
  inherited Undo;
end;
 EMPTYLINE
*)

(*$DEFINE JV_IMPL_CUSTOMEDIT(NameOfClass)
procedure TJvEx##NameOfClass.WMClear(var Mesg: TMessage);
begin
  inherited Clear;
  FEdit.Clear;
end;

procedure TJvEx##NameOfClass.WMCopy(var Mesg: TMessage);
begin
  FEdit.CopyToClipBoard;
end;

procedure TJvEx##NameOfClass.WMCut(var Mesg: TMessage);
begin
  FEdit.CutToClipBoard;
end;

procedure TJvEx##NameOfClass.WMPaste(var Mesg: TMessage);
begin
  FEdit.PasteFromClipBoard;
end;

procedure TJvEx##NameOfClass.WMUndo(var Mesg: TMessage);
begin
  FEdit.Undo;
end;

procedure TJvEx##NameOfClass.ClearSelection;
begin
  if not ReadOnly then
  begin
    inherited;
    FEdit.ClearSelection;
  end;
end;

procedure TJvEx##NameOfClass.EMGetRect(var Msg: TJvMessage);
begin
  Msg.Rect := FEdit.BoundsRect;
end;

procedure TJvEx##NameOfClass.EMSetRect(var Msg: TJvMessage);
begin
  FEdit.BoundsRect := Msg.Rect^;
end;

function TCustomEdit.GetAutoSelect: Boolean;
begin
  Result := FEdit.AutoSelect;
  inherited SetAutoSelect(Result);
end;

procedure TCustomEdit.SetAutoSelect(const Value: Boolean);
begin
  inherited SetAutoSelect(Value);
  FEdit.AutoSelect := Value;
end;

function TJvEx##NameOfClass.GetSelStart: Integer;
begin
  Result := FEdit.SelStart;
end;

function TJvEx##NameOfClass.GetSelText: WideString;
begin
  Result := FEdit.SelText;
end;

function TJvEx##NameOfClass.GetText: TCaption;
begin
  Result := FEdit.Text;
end;

function TJvEx##NameOfClass.GetModified: Boolean;
begin
  Result := FEdit.Modified;
end;

procedure TJvEx##NameOfClass.SelectAll;
begin
  inherited;
  FEdit.SelectAll;
end;

function TJvEx##NameOfClass.GetEchoMode: TEchoMode;
begin
  Result := FEdit.EchoMode;
end;

procedure TCustomEdit.SetCursorPos(const Value: Integer);
begin
  inherited;
  FEdit.CursorPos := Value;
end;

procedure TJvEx##NameOfClass.SetEchoMode(const Value: TEchoMode);
begin
  inherited;
  FEdit.EchoMode := Value;
end;

procedure TJvEx##NameOfClass.SetText(const Value: TCaption);
begin
  FEdit.Text := Value;
  inherited;
end;

procedure TJvEx##NameOfClass.SetMaxLength(const Value: Integer);
begin
  FEdit.MaxLenght := Value;
  inherited;
end;

procedure TJvEx##NameOfClass.SetModified(const Value: Boolean);
begin
  inherited;
  FEdit.Modified := Value;
end;

procedure TJvEx##NameOfClass.SetSelLength(Value: Integer);
begin
  inherited;
  FEdit.SelLenght := Value;
end;

procedure TJvEx##NameOfClass.SetSelStart(Value: Integer);
begin
  inherited;
  FEdit.SelStart := Value;
end;

procedure TJvEx##NameOfClass.SetSelText(const Value: WideString);
begin
  inherited;
  FEdit.SelText := Value;
end;

function TCustomEdit.GetCanRedo: Boolean;
begin
  Result := FEdit.CanRedo;
end;

function TCustomEdit.GetCanUndo: Boolean;
begin
  Result := FEdit.CanUndo;
end;
 EMPTYLINE

*) // end of JV_IMPL_CUSTOMEDIT

(*$DEFINE JV_IMPL_EDITCONTROL_CREATE(NameOfClass)
{ QEditControl Create }

constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FInternalFontChanged := Font.OnChange;
  Font.OnChange := DoOnFontChanged;
  FHintColor := clDefault;
  FDoubleBuffered := True;
  FClipBoardCommands := [caUndo, caCopy, caPaste, caCut];
  CREATE_CUSTOMCODE
end;

destructor TJvEx##NameOfClass.Destroy;
begin
  DESTROY_CUSTOMCODE
  FCanvas.Free;
  inherited Destroy;
end;
 EMPTYLINE
*) // end of JV_IMPL_EDITCONTROL_CREATE

(*$DEFINE JV_IMPL_CUSTOMEDIT_CREATE(NameOfClass)
{ QCustomEdit Create }

constructor TJvEx##NameOfClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FInternalFontChanged := Font.OnChange;
  Font.OnChange := DoOnFontChanged;
  FHintColor := clDefault;
  FDoubleBuffered := True;
  FEdit := TEdit.Create(Self);
  with FEdit do
  begin
    AutoSize := false;
    Height := Self.Height - 4;
    Width := Self.Width - 4;
    Anchors := [akBottom, akLeft, akRight, akTop];
    BorderStyle := bsNone;
    FEdit.ControlStyle := FEdit.ControlStyle + [csNoFocus];
    ParentColor := True;
    ParentFont := True;
    ParentHint := True;
    ParentShowHint := True;
    TabStop := False;
    Parent := Self;
  end
  CREATE_CUSTOMCODE
end;

*)

(*$DEFINE JV_EDITCONTROL_IMPL(NameOfClass)
JV_IMPL_EDITCONTROL_CREATE(NameOfClass)
JV_IMPL_EDITCONTROL(NameOfClass)
JV_IMPL_EDITCONTROL_COMMON(NameOfClass)
JV_IMPL_WINCONTROL_PAINT(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
*)

(*$DEFINE JV_CUSTOMEDIT_IMPL(NameOfClass)
JV_IMPL_CUSTOMEDIT_CREATE(NameOfClass)
JV_IMPL_CUSTOMEDIT(NameOfClass)
JV_IMPL_EDITCONTROL_COMMON(NameOfClass)
JV_IMPL_WINCONTROL_PAINT(NameOfClass)
JV_IMPL_WINCONTROL_COMMON(NameOfClass)
JV_IMPL_CONTROL_COMMON(NameOfClass)
*)


