From d0a0a22443c21771cb40aaa688f226215cd33fcc Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 12 May 2008 17:55:06 +0000 Subject: [PATCH] Display sizegrip in the lower right corners of all resizable forms which have no TStatusbar. (For copyright notices see code in helpers.pas) --- source/exportsql.pas | 1 + source/helpers.pas | 149 +++++++++++++++++++++++++++++++++++++- source/insertfiles.pas | 1 + source/optimizetables.pas | 1 + source/selectdbobject.pas | 1 + source/tbl_properties.pas | 2 + source/usermanager.pas | 1 + source/view.pas | 1 + 8 files changed, 156 insertions(+), 1 deletion(-) diff --git a/source/exportsql.pas b/source/exportsql.pas index 4224be92..5feba0d7 100644 --- a/source/exportsql.pas +++ b/source/exportsql.pas @@ -167,6 +167,7 @@ begin // Assign images from main imagelist to speedbuttons btnFileBrowse.PngImage := Mainform.PngImageListMain.PngImages[10].PngImage; btnDirectoryBrowse.PngImage := Mainform.PngImageListMain.PngImages[51].PngImage; + SetWindowSizeGrip( Self.Handle, True ); end; diff --git a/source/helpers.pas b/source/helpers.pas index 4e5b67d9..693b769c 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -10,7 +10,7 @@ interface uses Classes, SysUtils, Graphics, db, clipbrd, dialogs, forms, controls, ShellApi, checklst, windows, ZDataset, ZAbstractDataset, - shlobj, ActiveX, StrUtils, VirtualTrees, SynRegExpr; + shlobj, ActiveX, StrUtils, VirtualTrees, SynRegExpr, Messages; type @@ -89,6 +89,7 @@ type function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer; function GetTempDir: String; function GetDBObjectType( TableStatus: TFields ): Byte; + procedure SetWindowSizeGrip(hWnd: HWND; Enable: boolean); var MYSQL_KEYWORDS : TStringList; @@ -104,6 +105,15 @@ type charset: string; end; + TWndProc = function (hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; + + PGripInfo = ^TGripInfo; + TGripInfo = record + OldWndProc: TWndProc; + Enabled: boolean; + GripRect: TRect; + end; + const charset_conv_table: array[0..4] of CharacterSet = ( (codepage: 1250; charset: 'cp1250'), // ANSI Central European; Central European (Windows) @@ -112,6 +122,7 @@ const (codepage: 1256; charset: 'cp1256'), // ANSI Arabic; Arabic (Windows) (codepage: 1257; charset: 'cp1257') // ANSI Baltic; Baltic (Windows) ); + SizeGripProp = 'SizeGrip'; var dbgCounter: Integer = 0; @@ -2196,6 +2207,142 @@ begin end; +{ + Code taken from SizeGripHWND.pas: + Copyright (C) 2005, 2006 Volker Siebert + Alle Rechte vorbehalten. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. +} +function SizeGripWndProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; +var + Info: PGripInfo; + dc: HDC; + pt: TPoint; + + // Invalidate the current grip rectangle + procedure InvalidateGrip; + begin + with Info^ do + if (GripRect.Right > GripRect.Left) and + (GripRect.Bottom > GripRect.Top) then + InvalidateRect(hWnd, @GripRect, true); + end; + + // Update (and invalidate) the current grip rectangle + procedure UpdateGrip; + begin + with Info^ do + begin + GetClientRect(hWnd, GripRect); + GripRect.Left := GripRect.Right - GetSystemMetrics(SM_CXHSCROLL); + GripRect.Top := GripRect.Bottom - GetSystemMetrics(SM_CYVSCROLL); + end; + + InvalidateGrip; + end; + + function CallOld: LRESULT; + begin + Result := CallWindowProc(@Info^.OldWndProc, hWnd, Msg, wParam, lParam); + end; + +begin + Info := PGripInfo(GetProp(hWnd, SizeGripProp)); + if Info = nil then + Result := DefWindowProc(hWnd, Msg, wParam, lParam) + else if not Info^.Enabled then + Result := CallOld + else + begin + case Msg of + WM_NCDESTROY: begin + Result := CallOld; + + SetWindowLong(hWnd, GWL_WNDPROC, LongInt(@Info^.OldWndProc)); + RemoveProp(hWnd, SizeGripProp); + Dispose(Info); + end; + + WM_PAINT: begin + Result := CallOld; + if wParam = 0 then + begin + dc := GetDC(hWnd); + DrawFrameControl(dc, Info^.GripRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); + ReleaseDC(hWnd, dc); + end; + end; + + WM_NCHITTEST: begin + pt.x := TSmallPoint(lParam).x; + pt.y := TSmallPoint(lParam).y; + ScreenToClient(hWnd, pt); + if PtInRect(Info^.GripRect, pt) then + Result := HTBOTTOMRIGHT + else + Result := CallOld; + end; + + WM_SIZE: begin + InvalidateGrip; + Result := CallOld; + UpdateGrip; + end; + + else + Result := CallOld; + end; + end; +end; + +{ Note that SetWindowSizeGrip(..., false) does not really remove the hook - + it just sets "Enabled" to false. The hook plus all data is removed when + the window is destroyed. +} +procedure SetWindowSizeGrip(hWnd: HWND; Enable: boolean); +var + Info: PGripInfo; +begin + Info := PGripInfo(GetProp(hWnd, SizeGripProp)); + if (Info = nil) and Enable then + begin + New(Info); + FillChar(Info^, SizeOf(TGripInfo), 0); + + with Info^ do + begin + Info^.OldWndProc := TWndProc(Pointer(GetWindowLong(hWnd, GWL_WNDPROC))); + + GetClientRect(hWnd, GripRect); + GripRect.Left := GripRect.Right - GetSystemMetrics(SM_CXHSCROLL); + GripRect.Top := GripRect.Bottom - GetSystemMetrics(SM_CYVSCROLL); + end; + + SetProp(hWnd, SizeGripProp, Cardinal(Info)); + SetWindowLong(hWnd, GWL_WNDPROC, LongInt(@SizeGripWndProc)); + end; + + if (Info <> nil) then + if Enable <> Info^.Enabled then + with Info^ do + begin + Enabled := Enable; + if (GripRect.Right > GripRect.Left) and + (GripRect.Bottom > GripRect.Top) then + InvalidateRect(hWnd, @GripRect, true); + end; +end; + + initialization diff --git a/source/insertfiles.pas b/source/insertfiles.pas index 6113feeb..91043902 100644 --- a/source/insertfiles.pas +++ b/source/insertfiles.pas @@ -307,6 +307,7 @@ begin ListViewFiles.LargeImages:=LargeImages; ListViewFiles.SmallImages:=SmallImages; DragAcceptFiles( Handle , True ); + SetWindowSizeGrip( Self.Handle, True ); end; diff --git a/source/optimizetables.pas b/source/optimizetables.pas index 3294189f..f8c929df 100644 --- a/source/optimizetables.pas +++ b/source/optimizetables.pas @@ -66,6 +66,7 @@ procedure Toptimize.FormCreate(Sender: TObject); begin Width := Mainform.GetRegValue(REGNAME_MAINTWINWIDTH, Width); Height := Mainform.GetRegValue(REGNAME_MAINTWINHEIGHT, Height); + SetWindowSizeGrip( Self.Handle, True ); end; diff --git a/source/selectdbobject.pas b/source/selectdbobject.pas index 0f4258c1..11079111 100644 --- a/source/selectdbobject.pas +++ b/source/selectdbobject.pas @@ -72,6 +72,7 @@ procedure TfrmSelectDBObject.FormCreate(Sender: TObject); begin Width := Mainform.GetRegValue(REGNAME_SELECTDBO_WINWIDTH, Width); Height := Mainform.GetRegValue(REGNAME_SELECTDBO_WINHEIGHT, Height); + SetWindowSizeGrip( Self.Handle, True ); end; procedure TfrmSelectDBObject.FormDestroy(Sender: TObject); diff --git a/source/tbl_properties.pas b/source/tbl_properties.pas index 45942ccc..733714c0 100644 --- a/source/tbl_properties.pas +++ b/source/tbl_properties.pas @@ -107,6 +107,8 @@ begin SynMemoCreate.Highlighter := Mainform.Childwin.SynSQLSyn1; SynMemoCreate.Font.Name := Mainform.Childwin.SynMemoQuery.Font.Name; SynMemoCreate.Font.Size := Mainform.Childwin.SynMemoQuery.Font.Size; + + SetWindowSizeGrip( Self.Handle, True ); end; diff --git a/source/usermanager.pas b/source/usermanager.pas index 0df37dbb..1bf540b8 100644 --- a/source/usermanager.pas +++ b/source/usermanager.pas @@ -229,6 +229,7 @@ begin Width := Mainform.GetRegValue(REGNAME_USERMNGR_WINWIDTH, Width); Height := Mainform.GetRegValue(REGNAME_USERMNGR_WINHEIGHT, Height); db := Mainform.Mask(DBNAME_MYSQL); + SetWindowSizeGrip( Self.Handle, True ); end; diff --git a/source/view.pas b/source/view.pas index 30c6f3d5..8875562c 100644 --- a/source/view.pas +++ b/source/view.pas @@ -48,6 +48,7 @@ begin Height := Mainform.GetRegValue(REGNAME_VIEWWINHEIGHT, Height); SynMemoSelect.Highlighter := Mainform.ChildWin.SynSQLSyn1; SynMemoSelect.Font := Mainform.ChildWin.SynMemoQuery.Font; + SetWindowSizeGrip( Self.Handle, True ); end;