Jump to content


MouseEnter method & improved TrackBarItem


  • Please log in to reply
2 replies to this topic

#1 Guest_Markus_*

Guest_Markus_*
  • Guests

Posted 10 February 2006 - 07:36 PM

In order to improve the handling of NextInspector's TrackBarItem, we need to add a MouseEnter method to its parent control, because Berg's TrackBarItem has serious problems when the mouse enters/leaves the (slider) control (cf. http://forum.bergsof...opic.php?t=378).

This patch implements the missing parts and fixes the most obvious bugs:

CODE
Index: NxInspector.pas

===================================================================

--- NxInspector.pas    (revision 3.3.5)

+++ NxInspector.pas    (working copy)

@@ -47,6 +47,7 @@

    FIsMouseDown: Boolean;

    FImages: TImageList;

    FMarginColor: TColor;

+    FMousePt: TPoint;

    FOldWidth: Integer;

    FOldHeight: Integer;

    FOptions: TPropertyViewOptions;

@@ -142,6 +143,7 @@

    procedure ValueChanged(Item: TNxCustomPropertyItem; const Value: WideString); virtual;

    procedure CMDesignHitTest(var Message: TCMDesignHitTest); message CM_DESIGNHITTEST;

    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;

+    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;

    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

    procedure WMKillFocus(var Message: TWMSetFocus); message WM_KILLFOCUS;

    procedure WMSize(var Message: TWMSize); message WM_SIZE;

@@ -173,6 +175,7 @@

    property Font;

    property GridColor: TColor read FGridColor write SetGridColor default clBtnFace;

    property Images: TImageList read FImages write SetImages;

+    property IsMouseDown: Boolean read FIsMouseDown;

    property ItemCount: Integer read GetItemCount;

    property MarginColor: TColor read FMarginColor write SetMarginColor default clBtnFace;

    property Options: TPropertyViewOptions read FOptions write SetOptions default [poGrid, poEnterSelectNext, poSplitterMoving, poUniformSelect];

@@ -283,6 +286,7 @@

  FEnableVisualStyles := False;

  FExpandGlyph := TBitmap.Create;

  FMarginColor := clBtnFace;

+  FMousePt := Point(-1, -1);

  FOptions := [poGrid, poEnterSelectNext, poSplitterMoving, poUniformSelect];

  FRowHeight := 16;

  FSelectedItem := nil;

@@ -350,6 +354,12 @@

 end;

end;



+procedure TNxCustomInspector.CMMouseEnter(var Message: TMessage);

+begin

+  if Assigned(HoverItem) then

+    HoverItem.Display.MouseEnter;

+end;

+

procedure TNxCustomInspector.CMMouseLeave(var Message: TMessage);

begin

  if Assigned(HoverItem) then

@@ -969,6 +979,10 @@

  begin

    if (HoverItem <> AHoverItem) or (X < SplitterPosition) then HoverItem.Display.MouseLeave;

  end;

+  if Assigned(AHoverItem) and ((AHoverItem <> HoverItem) or

+    (FMousePt.X < SplitterPosition)) and (X >= SplitterPosition) then

+    AHoverItem.Display.MouseEnter;

+  FMousePt := Point(X, Y);

  HoverItem := AHoverItem;

  if Assigned(AHoverItem) then

  begin

Index: NxPropertyItemDisplay.pas

===================================================================

--- NxPropertyItemDisplay.pas    (revision 3.3.5)

+++ NxPropertyItemDisplay.pas    (working copy)

@@ -81,6 +81,7 @@

    FHover: Boolean;

    function GetTextWidth: Integer;

    function GetTrackWidth: Integer;

+    function PtInSliderRect(pt: TPoint): Boolean;

  protected

    function GetPositionAtPos(X, Y: Integer): Integer;

    procedure DrawClassicTrackBar(ARect: TRect);

@@ -89,6 +90,7 @@

    constructor Create(AItem: TNxCustomPropertyItem); override;

    procedure KeyDown(var Key: Word; Shift: TShiftState); override;

    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

+    procedure MouseEnter; override;

    procedure MouseLeave; override;

    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;

    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

@@ -589,16 +591,12 @@



function TNxTrackBarItemDisplay.GetPositionAtPos(X, Y: Integer): Integer;

var

-  AreaRect: TRect;

  Spot: Integer;

begin

  Result := -1;

  with Item as TNxTrackBarItem do

  begin

-    AreaRect := ClientRect;

-    OffsetRect(AreaRect, -AreaRect.Left, -AreaRect.Top);

-    InflateRect(AreaRect, -Margin, 0);

-    if PtInRect(AreaRect, Point(X, Y)) then

+    if PtInSliderRect(Point(X, Y)) then

    begin

      X := X - GetTextWidth;

      Spot := X - Margin;

@@ -649,6 +647,12 @@

  FDown := True;

end;



+procedure TNxTrackBarItemDisplay.MouseEnter;

+begin

+  inherited;

+  FDown := (Item.GetParentControl as TNextInspector).IsMouseDown;

+end;

+

procedure TNxTrackBarItemDisplay.MouseLeave;

begin

  inherited;

@@ -669,7 +673,7 @@

    PaintValue;

  end;

  with Item as TNxTrackBarItem do

-    if FDown then

+    if FDown and PtInSliderRect(Point(X, Y)) then

    begin

      Position := GetPositionAtPos(X, Y);

      PaintValue;

@@ -706,6 +710,19 @@

  end;

end;



+function TNxTrackBarItemDisplay.PtInSliderRect(pt: TPoint): Boolean;

+var

+  AreaRect: TRect;

+begin

+  with Item as TNxTrackBarItem do

+  begin

+    AreaRect := ClientRect;

+    OffsetRect(AreaRect, -AreaRect.Left, -AreaRect.Top);

+    InflateRect(AreaRect, -Margin, 0);

+  end;

+  Result := PtInRect(AreaRect, pt);

+end;

+

{ TNxRadioItemDisplay }



constructor TNxRadioItemDisplay.Create(AItem: TNxCustomPropertyItem);

Index: NxPropertyItems.pas

===================================================================

--- NxPropertyItems.pas    (revision 3.3.5)

+++ NxPropertyItems.pas    (working copy)

@@ -271,6 +271,7 @@

    procedure EndUpdate;

    procedure KeyDown(var Key: Word; Shift: TShiftState); virtual;

    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;

+    procedure MouseEnter; virtual;

    procedure MouseLeave; virtual;

    procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual;

    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;

@@ -1208,6 +1209,11 @@



end;



+procedure TNxItemDisplay.MouseEnter;

+begin

+

+end;

+

procedure TNxItemDisplay.MouseLeave;

begin


#2 Guest_Markus_*

Guest_Markus_*
  • Guests

Posted 11 February 2006 - 05:26 PM

I forgot to mention that this should only be a temporary workaround for TNxTrackBarItem until someone implements a WH_MOUSE hook for TNxItemDisplay.

#3 Guest_Markus_*

Guest_Markus_*
  • Guests

Posted 25 February 2006 - 09:00 PM

My patch has some problems with the inconsistent behavior of the FIsMouseDown property. If a TNxCustomEdit derived editor is displayed due to a mouse click FIsMouseDown will stay 'true'. This in turn means that the slider is movable when an inplace editor was displayed before entering the TrackBar.

I'm not sure if there's any interest in an improved patch as I did not yet get any response to the patch above.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users