From: Peter T. <pe...@us...> - 2002-10-27 11:06:38
|
Update of /cvsroot/jvcl/jvcl/source In directory usw-pr-cvs1:/tmp/cvs-serv25513/source Modified Files: JvCaptionButton.pas Log Message: Mantis #394 Index: JvCaptionButton.pas =================================================================== RCS file: /cvsroot/jvcl/jvcl/source/JvCaptionButton.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JvCaptionButton.pas 20 Jul 2002 11:52:35 -0000 1.4 --- JvCaptionButton.pas 27 Oct 2002 11:06:35 -0000 1.5 *************** *** 15,19 **** All Rights Reserved. ! Contributor(s): Last Modified: 2002-05-26 --- 15,19 ---- All Rights Reserved. ! Contributor(s): Last Modified: 2002-05-26 *************** *** 34,112 **** uses ! Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Buttons, CommCtrl, JvComponent; type ! TJvStandardButton=(tsbNone,tsbClose,tsbHelp,tsbMax,tsbMin,tsbRestore); TJvCaptionButton = class(TJvComponent) private { Private declarations } ! FOwner:TForm; ! FGlyph:TBitmap; ! IL:TImageList; ! FCaption:string; ! FOnClick:TNotifyEvent; ! FButtonRect:TRect; ! FLeft,FTop,FWidth,FHeight:integer; ! FDrawFlags:integer; ! FAlignment:TAlignment; ! FToggle,FDown:boolean; ! FStandard:TJvStandardButton; ! FFont:TFont; ! FOnMouseDown:TMouseEvent; ! FOnMouseUp:TMouseEvent; ! FHandle : THandle; ! FDefProc : Pointer; ! FWndProc : Pointer; ! procedure SetFont(Value:TFont); ! procedure SetAlignment(Value:TAlignment); ! procedure SetCaption(Value:string); ! procedure SetStandard(Value:TJvStandardButton); ! procedure SetLeft(Value:integer); ! procedure SetTop(Value:integer); ! procedure SetWidth(Value:integer); ! procedure SetHeight(Value:integer); ! procedure SetGlyph(Value:TBitmap); ! procedure WndProc(var Msg:TMessage); procedure GetWndProc; procedure ResetWndProc; procedure DrawButton; {Paint-related messages} ! procedure WMSize(var Msg:TWMSize); message WM_SIZE; ! procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT; ! procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT; ! procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE; {Mouse down-related messages} ! procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST; ! procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN; ! procedure WMNCLButtonUp(var Msg : TWMNCLButtonUp); message WM_NCLBUTTONUP; protected { Protected declarations } procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; public { Public declarations } ! constructor Create(AOwner:TComponent);override; ! destructor Destroy;override; procedure ResetButton; published { Published declarations } ! property Alignment:TAlignment read FAlignment write SetAlignment default taLeftJustify; ! property Caption:string read FCaption write SetCaption; ! property Glyph:TBitmap read FGlyph write SetGlyph; ! property Font:TFont read FFont write SetFont; ! property ButtonLeft:integer read FLeft write SetLeft default 1; ! property ButtonTop:integer read FTop write SetTop default 1; ! property ButtonWidth:integer read FWidth write SetWidth; ! property ButtonHeight:integer read FHeight write SetHeight; ! property Toggle:boolean read FToggle write FToggle default False; property Down: boolean read FDown; ! property Standard:TJvStandardButton read FStandard write SetStandard default tsbNone; ! property OnClick:TNotifyEvent read FOnClick write FOnClick; ! property OnMouseUp:TMouseEvent read FOnMouseUp write FOnMouseUp; ! property OnMouseDown:TMouseEvent read FOnMouseDown write FOnMouseDown; end; - const htCaptionButton = htSizeLast + 1; --- 34,115 ---- uses ! Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Buttons, CommCtrl, JvComponent; type ! TJvStandardButton = (tsbNone, tsbClose, tsbHelp, tsbMax, tsbMin, tsbRestore); TJvCaptionButton = class(TJvComponent) private { Private declarations } ! FGlyph: TBitmap; ! IL: TImageList; ! FCaption: string; ! FOnClick: TNotifyEvent; ! FButtonRect: TRect; ! FLeft, FTop, FWidth, FHeight: integer; ! FDrawFlags: integer; ! FAlignment: TAlignment; ! FToggle, FDown: boolean; ! FStandard: TJvStandardButton; ! FFont: TFont; ! FOnMouseDown: TMouseEvent; ! FOnMouseUp: TMouseEvent; ! FWindowHandle: THandle; ! FDefaultWndProc: Pointer; ! FWndProc: Pointer; ! FParentForm: TCustomForm; ! procedure SetFont(Value: TFont); ! procedure SetAlignment(Value: TAlignment); ! procedure SetCaption(Value: string); ! procedure SetStandard(Value: TJvStandardButton); ! procedure SetLeft(Value: integer); ! procedure SetTop(Value: integer); ! procedure SetWidth(Value: integer); ! procedure SetHeight(Value: integer); ! procedure SetGlyph(Value: TBitmap); ! procedure WndProc(var Msg: TMessage); procedure GetWndProc; procedure ResetWndProc; procedure DrawButton; {Paint-related messages} ! procedure WMSize(var Msg: TWMSize); message WM_SIZE; ! procedure WMSetText(var Msg: TWMSetText); message WM_SETTEXT; ! procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT; ! procedure WMNCActivate(var Msg: TWMNCActivate); message WM_NCACTIVATE; {Mouse down-related messages} ! procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST; ! procedure WMNCLButtonDown(var Msg: TWMNCLButtonDown); message WM_NCLBUTTONDOWN; ! procedure WMNCLButtonUp(var Msg: TWMNCLButtonUp); message WM_NCLBUTTONUP; ! procedure SetParentForm(const Value: TCustomForm); protected { Protected declarations } procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; + procedure Notification(AComponent: TComponent; Operation: TOperation); + override; + property ParentForm: TCustomForm read FParentForm write SetParentForm; public { Public declarations } ! constructor Create(AOwner: TComponent); override; ! destructor Destroy; override; procedure ResetButton; published { Published declarations } ! property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify; ! property Caption: string read FCaption write SetCaption; ! property Glyph: TBitmap read FGlyph write SetGlyph; ! property Font: TFont read FFont write SetFont; ! property ButtonLeft: integer read FLeft write SetLeft default 1; ! property ButtonTop: integer read FTop write SetTop default 1; ! property ButtonWidth: integer read FWidth write SetWidth; ! property ButtonHeight: integer read FHeight write SetHeight; ! property Toggle: boolean read FToggle write FToggle default False; property Down: boolean read FDown; ! property Standard: TJvStandardButton read FStandard write SetStandard default tsbNone; ! property OnClick: TNotifyEvent read FOnClick write FOnClick; ! property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp; ! property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown; end; const htCaptionButton = htSizeLast + 1; *************** *** 114,138 **** implementation ! constructor TJvCaptionButton.Create(AOwner:TComponent); ! var SysInfoPara:TNonClientMetrics; begin inherited Create(AOwner); SysInfoPara.cbSize := sizeof(TNonClientMetrics); ! SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,@SysInfoPara,0); with SysInfoPara do begin ! FLeft := iCaptionWidth * 4 + 4; ! FTop := GetSystemMetrics(SM_CXFRAME) + 2; ! FWidth := iCaptionWidth; FHeight := iCaptionHeight - 4; end; ! FGlyph := TBitmap.Create; FFont := TFont.Create; ! FOwner := TForm(AOwner); ! FFont.Assign(FOwner.Font); ! IL := TImageList.CreateSize(FWidth,FHeight); ! FDown := False; FToggle := False; ! FStandard := tsbNone; FDrawFlags := 0; FCaption := ''; --- 117,139 ---- implementation ! constructor TJvCaptionButton.Create(AOwner: TComponent); ! var SysInfoPara: TNonClientMetrics; begin inherited Create(AOwner); SysInfoPara.cbSize := sizeof(TNonClientMetrics); ! SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @SysInfoPara, 0); with SysInfoPara do begin ! FLeft := iCaptionWidth * 4 + 4; ! FTop := GetSystemMetrics(SM_CXFRAME) + 2; ! FWidth := iCaptionWidth; FHeight := iCaptionHeight - 4; end; ! FGlyph := TBitmap.Create; FFont := TFont.Create; ! IL := TImageList.CreateSize(FWidth, FHeight); ! FDown := False; FToggle := False; ! FStandard := tsbNone; FDrawFlags := 0; FCaption := ''; *************** *** 143,152 **** procedure TJvCaptionButton.ResetButton; begin ! if FHandle <> 0 then ! ResetWndProc; ! if Owner <> nil then ! FOwner := TForm(Owner); ! FHandle := 0; ! GetWndProc; DrawButton; end; --- 144,151 ---- procedure TJvCaptionButton.ResetButton; begin ! if Owner is TControl then ! ParentForm := GetParentForm(TControl(Owner)) ! else ! ParentForm := nil; DrawButton; end; *************** *** 154,161 **** destructor TJvCaptionButton.Destroy; begin ! FGlyph.Free; ! IL.Free; ! ResetWndProc; FFont.Free; inherited Destroy; end; --- 153,160 ---- destructor TJvCaptionButton.Destroy; begin ! ParentForm := nil; FFont.Free; + IL.Free; + FGlyph.Free; inherited Destroy; end; *************** *** 163,182 **** procedure TJvCaptionButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ! if Assigned(FOnMouseDown) then FOnMouseDown(self,Button,Shift,X,Y); end; procedure TJvCaptionButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ! if Assigned(FOnMouseUp) then FOnMouseUp(self,Button,Shift,X,Y); end; ! ! procedure TJvCaptionButton.SetFont(Value:TFont); begin FFont.Assign(Value); DrawButton; end; ! ! procedure TJvCaptionButton.SetAlignment(Value:TAlignment); begin if FAlignment <> Value then --- 162,182 ---- procedure TJvCaptionButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ! if Assigned(FOnMouseDown) then ! FOnMouseDown(self, Button, Shift, X, Y); end; procedure TJvCaptionButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ! if Assigned(FOnMouseUp) then ! FOnMouseUp(self, Button, Shift, X, Y); end; ! procedure TJvCaptionButton.SetFont(Value: TFont); begin FFont.Assign(Value); DrawButton; end; ! ! procedure TJvCaptionButton.SetAlignment(Value: TAlignment); begin if FAlignment <> Value then *************** *** 185,189 **** end; ! procedure TJvCaptionButton.SetCaption(Value:string); begin if FCaption <> Value then --- 185,189 ---- end; ! procedure TJvCaptionButton.SetCaption(Value: string); begin if FCaption <> Value then *************** *** 192,196 **** end; ! procedure TJvCaptionButton.SetStandard(Value:TJvStandardButton); begin if FStandard <> Value then --- 192,196 ---- end; ! procedure TJvCaptionButton.SetStandard(Value: TJvStandardButton); begin if FStandard <> Value then *************** *** 209,213 **** end; ! procedure TJvCaptionButton.SetLeft(Value:integer); begin if FLeft <> Value then --- 209,213 ---- end; ! procedure TJvCaptionButton.SetLeft(Value: integer); begin if FLeft <> Value then *************** *** 216,220 **** end; ! procedure TJvCaptionButton.SetWidth(Value:integer); begin if FWidth <> Value then --- 216,220 ---- end; ! procedure TJvCaptionButton.SetWidth(Value: integer); begin if FWidth <> Value then *************** *** 223,227 **** end; ! procedure TJvCaptionButton.SetHeight(Value:integer); begin if FHeight <> Value then --- 223,227 ---- end; ! procedure TJvCaptionButton.SetHeight(Value: integer); begin if FHeight <> Value then *************** *** 230,235 **** end; ! ! procedure TJvCaptionButton.SetTop(Value:integer); begin if FTop <> Value then --- 230,234 ---- end; ! procedure TJvCaptionButton.SetTop(Value: integer); begin if FTop <> Value then *************** *** 238,242 **** end; ! procedure TJvCaptionButton.SetGlyph(Value:TBitmap); begin FGlyph.Assign(Value); --- 237,241 ---- end; ! procedure TJvCaptionButton.SetGlyph(Value: TBitmap); begin FGlyph.Assign(Value); *************** *** 246,312 **** IL.Width := FGlyph.Width; IL.Height := FGlyph.Height; ! Il.AddMasked(FGlyph,FGlyph.TransparentColor); end; DrawButton; end; - procedure TJvCaptionButton.DrawButton; ! var X,Y,tmpFlags:integer; Canvas:TCanvas;R:TRect; begin ! Canvas := TControlCanvas.Create; ! Canvas.Handle := GetWindowDC(FOwner.Handle); ! ! FButtonRect := Bounds(FOwner.Width - FLeft, FTop,FWidth,FHeight); ! if FDown then ! tmpFlags := FDrawFlags or DFCS_PUSHED ! else ! tmpFlags := FDrawFlags; ! DrawButtonFace(Canvas, FButtonRect, 1, bsAutoDetect, False, FDown, False); ! if (FStandard <> tsbNone) then ! DrawFrameControl(Canvas.Handle,FButtonRect,DFC_CAPTION,tmpFlags) ! else ! begin ! R := FButtonRect; ! X := 0; ! if Assigned(FGlyph) then begin ! Y := ((R.Bottom - R.Top) - FGlyph.Height) div 2; ! case FAlignment of ! taLeftJustify: X := FWidth - (FGlyph.Width) - 4; ! taRightJustify: X := 4; ! taCenter: X := ((FWidth - FGlyph.Width) div 2); end; - { ImageList_DrawEx(IL.Handle,0,Canvas.Handle, - FButtonRect.Left + X + Ord(FDown),FButtonRect.Top + Y + Ord(FDown),0,0, - clNone,clNone,ILD_TRANSPARENT);} - Canvas.Draw(FButtonRect.Left + X + Ord(FDown),FButtonRect.Top + Y + Ord(FDown),FGlyph); - end; ! if Length(FCaption) > 0 then ! begin ! Canvas.Font.Height := FFont.Height; ! case FAlignment of ! taLeftJustify: Inc(R.Left,4); ! taRightJustify: R.Left := R.Right - (Canvas.TextWidth(FCaption) + 4); ! taCenter: R.Left := R.Left + (FWidth - Canvas.TextWidth(FCaption)) div 2; end; - SetBkMode(Canvas.Handle,Windows.Transparent); - OffsetRect(R,Ord(FDown),Ord(FDown)); - DrawText(Canvas.Handle,PChar(FCaption),-1,R,DT_NOPREFIX); - end; end; - - ReleaseDC(FOwner.Handle, Canvas.Handle); - Canvas.Handle := 0; - Canvas.Free; end; {Paint triggering events} ! procedure TJvCaptionButton.WMNCActivate(var Msg : TWMNCActivate); begin inherited; --- 245,313 ---- IL.Width := FGlyph.Width; IL.Height := FGlyph.Height; ! Il.AddMasked(FGlyph, FGlyph.TransparentColor); end; DrawButton; end; procedure TJvCaptionButton.DrawButton; ! var X, Y, tmpFlags: integer; Canvas: TCanvas; R: TRect; begin ! if ParentForm = nil then ! Exit; Canvas := TControlCanvas.Create; ! try ! Canvas.Handle := GetWindowDC(ParentForm.Handle); ! FButtonRect := Bounds(ParentForm.Width - FLeft, FTop, FWidth, FHeight); ! if FDown then ! tmpFlags := FDrawFlags or DFCS_PUSHED ! else ! tmpFlags := FDrawFlags; ! DrawButtonFace(Canvas, FButtonRect, 1, bsAutoDetect, False, FDown, False); ! if (FStandard <> tsbNone) then ! DrawFrameControl(Canvas.Handle, FButtonRect, DFC_CAPTION, tmpFlags) ! else begin ! R := FButtonRect; ! X := 0; ! if Assigned(FGlyph) then ! begin ! Y := ((R.Bottom - R.Top) - FGlyph.Height) div 2; ! case FAlignment of ! taLeftJustify: X := FWidth - (FGlyph.Width) - 4; ! taRightJustify: X := 4; ! taCenter: X := ((FWidth - FGlyph.Width) div 2); ! end; ! { ImageList_DrawEx(IL.Handle,0,Canvas.Handle, ! FButtonRect.Left + X + Ord(FDown),FButtonRect.Top + Y + Ord(FDown),0,0, ! clNone,clNone,ILD_TRANSPARENT);} ! Canvas.Draw(FButtonRect.Left + X + Ord(FDown), FButtonRect.Top + Y + Ord(FDown), FGlyph); end; ! if Length(FCaption) > 0 then ! begin ! Canvas.Font.Height := FFont.Height; ! case FAlignment of ! taLeftJustify: Inc(R.Left, 4); ! taRightJustify: R.Left := R.Right - (Canvas.TextWidth(FCaption) + 4); ! taCenter: R.Left := R.Left + (FWidth - Canvas.TextWidth(FCaption)) div 2; ! end; ! SetBkMode(Canvas.Handle, Windows.Transparent); ! OffsetRect(R, Ord(FDown), Ord(FDown)); ! DrawText(Canvas.Handle, PChar(FCaption), -1, R, DT_NOPREFIX); end; + end; + finally + ReleaseDC(ParentForm.Handle, Canvas.Handle); + Canvas.Handle := 0; + Canvas.Free; end; end; {Paint triggering events} ! ! procedure TJvCaptionButton.WMNCActivate(var Msg: TWMNCActivate); begin inherited; *************** *** 316,320 **** { Painting events } ! procedure TJvCaptionButton.WMNCPaint(var Msg : TWMNCPaint); begin inherited; --- 317,321 ---- { Painting events } ! procedure TJvCaptionButton.WMNCPaint(var Msg: TWMNCPaint); begin inherited; *************** *** 322,333 **** end; ! procedure TJvCaptionButton.WMSize(var Msg:TWMSize); begin inherited; ! FOwner.Perform(WM_NCACTIVATE, Word(FOwner.Active), 0); DrawButton; end; ! procedure TJvCaptionButton.WMSetText(var Msg : TWMSetText); begin inherited; --- 323,336 ---- end; ! procedure TJvCaptionButton.WMSize(var Msg: TWMSize); begin inherited; ! if ParentForm = nil then ! Exit; ! ParentForm.Perform(WM_NCACTIVATE, Word(ParentForm.Active), 0); DrawButton; end; ! procedure TJvCaptionButton.WMSetText(var Msg: TWMSetText); begin inherited; *************** *** 336,351 **** {Mouse-related procedures} ! procedure TJvCaptionButton.WMNCHitTest(var Msg : TWMNCHitTest); begin ! Inherited; ! {Check to see if the mouse was clicked in the area of the button} ! if PtInRect(FButtonRect, Point(Msg.XPos - FOwner.Left, Msg.YPos - FOwner.Top)) then ! Msg.Result := htCaptionButton; ! // DrawButton; end; ! procedure TJvCaptionButton.WMNCLButtonDown(var Msg : TWMNCLButtonDown); begin inherited; if (Msg.HitTest = htCaptionButton) then begin --- 339,359 ---- {Mouse-related procedures} ! ! procedure TJvCaptionButton.WMNCHitTest(var Msg: TWMNCHitTest); begin ! inherited; ! if ParentForm = nil then ! Exit; ! {Check to see if the mouse was clicked in the area of the button} ! if PtInRect(FButtonRect, Point(Msg.XPos - ParentForm.Left, Msg.YPos - ParentForm.Top)) then ! Msg.Result := htCaptionButton; ! // DrawButton; end; ! procedure TJvCaptionButton.WMNCLButtonDown(var Msg: TWMNCLButtonDown); begin inherited; + if ParentForm = nil then + Exit; if (Msg.HitTest = htCaptionButton) then begin *************** *** 355,387 **** FDown := True; with TWMMouse(Msg) do ! MouseDown(mbLeft,KeysToShiftState(Keys),XPos,YPos); end else ! FDown := False; DrawButton; end; ! procedure TJvCaptionButton.WMNCLButtonUp(var Msg : TWMNCLButtonUp); begin inherited; if (Msg.HitTest = htCaptionButton) then begin with TWMMouse(Msg) do ! MouseUp(mbLeft,KeysToShiftState(Keys),XPos,YPos); ! if FDown then if Assigned(FOnClick) then FOnClick(self); end; ! if not FToggle then FDown := False; DrawButton; end; - procedure TJvCaptionButton.GetWndProc; begin ! if Owner is TForm then begin ! FHandle := TForm(Owner).Handle; FWndProc := {$IFDEF COMPILER6_UP}Classes.{$ENDIF}MakeObjectInstance(WndProc); ! FDefProc := Pointer(GetWindowLong(FHandle,GWL_WNDPROC )); ! SetWindowLong(FHandle,GWL_WNDPROC,longint(FWndProc)); end; end; --- 363,399 ---- FDown := True; with TWMMouse(Msg) do ! MouseDown(mbLeft, KeysToShiftState(Keys), XPos, YPos); end else ! FDown := False; DrawButton; end; ! procedure TJvCaptionButton.WMNCLButtonUp(var Msg: TWMNCLButtonUp); begin inherited; + if ParentForm = nil then + Exit; if (Msg.HitTest = htCaptionButton) then begin with TWMMouse(Msg) do ! MouseUp(mbLeft, KeysToShiftState(Keys), XPos, YPos); ! if FDown then ! if Assigned(FOnClick) then ! FOnClick(self); end; ! if not FToggle then ! FDown := False; DrawButton; end; procedure TJvCaptionButton.GetWndProc; begin ! if ParentForm <> nil then begin ! FWindowHandle := ParentForm.Handle; FWndProc := {$IFDEF COMPILER6_UP}Classes.{$ENDIF}MakeObjectInstance(WndProc); ! FDefaultWndProc := Pointer(GetWindowLong(FWindowHandle, GWL_WNDPROC)); ! SetWindowLong(FWindowHandle, GWL_WNDPROC, longint(FWndProc)); end; end; *************** *** 389,420 **** procedure TJvCaptionButton.ResetWndProc; begin ! if FHandle <> 0 then begin ! SetWindowLong(FHandle,GWL_WNDPROC,longint(FDefProc)); ! {$IFDEF COMPILER6_UP}Classes.{$ENDIF}FreeObjectInstance(FWndProc); ! end end; ! procedure TJvCaptionButton.WndProc(var Msg:TMessage); begin ! { allways let Windows do it's thing } with Msg do ! Result := CallWindowProc( FDefProc, FHandle, Msg, WParam, LParam); case Msg.Msg of WM_DESTROY: - begin ResetWndProc; ! FHandle := 0; ! end; ! WM_SETTEXT: WMSetText(TWmSetText(Msg)); ! WM_NCPAINT: WMNCPaint(TWMNCPaint(Msg)); ! WM_NCACTIVATE: WMNCActivate(TWMNCActivate(Msg)); ! WM_NCHITTEST: WMNCHitTest(TWMNcHitTest(Msg)); ! WM_NCLBUTTONDOWN,WM_LBUTTONDOWN: WMNCLButtondown(TWMNCLButtondown(Msg)); ! WM_NCLBUTTONUP,WM_LBUTTONUP: WMNCLButtonUp(TWMNCLButtonUp(Msg)); ! WM_SIZE,WM_WINDOWPOSCHANGED: WMSize(TWMSize(Msg)); end; end; end. --- 401,456 ---- procedure TJvCaptionButton.ResetWndProc; begin ! if FWindowHandle <> 0 then begin ! SetWindowLong(FWindowHandle, GWL_WNDPROC, longint(FDefaultWndProc)); ! {$IFDEF COMPILER6_UP}Classes.{$ENDIF}FreeObjectInstance(FWndProc); ! end; ! FWindowHandle := 0; end; ! procedure TJvCaptionButton.WndProc(var Msg: TMessage); begin ! { always let Windows do it's thing } with Msg do ! Result := CallWindowProc(FDefaultWndProc, FWindowHandle, Msg, WParam, LParam); case Msg.Msg of WM_DESTROY: ResetWndProc; ! WM_SETTEXT: ! WMSetText(TWmSetText(Msg)); ! WM_NCPAINT: ! WMNCPaint(TWMNCPaint(Msg)); ! WM_NCACTIVATE: ! WMNCActivate(TWMNCActivate(Msg)); ! WM_NCHITTEST: ! WMNCHitTest(TWMNcHitTest(Msg)); ! WM_NCLBUTTONDOWN, WM_LBUTTONDOWN: ! WMNCLButtondown(TWMNCLButtondown(Msg)); ! WM_NCLBUTTONUP, WM_LBUTTONUP: ! WMNCLButtonUp(TWMNCLButtonUp(Msg)); ! WM_SIZE, WM_WINDOWPOSCHANGED: ! WMSize(TWMSize(Msg)); end; end; + procedure TJvCaptionButton.Notification(AComponent: TComponent; + Operation: TOperation); + begin + inherited; + // this should never happen, but better safe than sorry... + if (Operation = opRemove) and (AComponent = ParentForm) then + ParentForm := nil; + end; + + procedure TJvCaptionButton.SetParentForm(const Value: TCustomForm); + begin + if FParentForm <> nil then + ResetWndProc; + FParentForm := Value; + GetWndProc; + if (FParentForm <> nil) then + FFont.Assign(FParentForm.Font); + end; end. + |