lazarus/lcl/interfaces/win32/win32wsextctrls.pp
marc 04b4e27b62 * Implemented basic alpha support
* Implemented LCL side of imagelist
* restructured rawimage to more OO

Merged revisions 11289-11617 via svnmerge from 
http://svn.freepascal.org/svn/lazarus/branches/marc-lcl

........
  r11289 | marc | 2007-06-06 22:50:05 +0200 (Wed, 06 Jun 2007) | 1 line
  
  private branch for bitmap rework
........
  r11290 | marc | 2007-06-06 23:30:09 +0200 (Wed, 06 Jun 2007) | 2 lines
  
  * Initial linux and win32 implementation
........
  r11291 | paul | 2007-06-07 03:20:11 +0200 (Thu, 07 Jun 2007) | 3 lines
  
  - fix compilation with fpc 2.3.1
  - remove unneded code for converting cursor mask
  - enabled loading of standard windows status icons instead of LCL
........
  r11292 | paul | 2007-06-07 11:03:27 +0200 (Thu, 07 Jun 2007) | 1 line
  
  - some bugs with mask and alpha
........
  r11299 | marc | 2007-06-08 00:59:26 +0200 (Fri, 08 Jun 2007) | 2 lines
  
  * force alpha channel when PNG has alpha
........
  r11302 | paul | 2007-06-09 04:45:12 +0200 (Sat, 09 Jun 2007) | 1 line
  
  - fix black rectangles instead of manu item images
........
  r11303 | paul | 2007-06-09 04:46:14 +0200 (Sat, 09 Jun 2007) | 1 line
  
  formatting
........
  r11309 | marc | 2007-06-11 02:25:07 +0200 (Mon, 11 Jun 2007) | 3 lines
  
  * Added alpha premultiply
  * Published Colorbox selection property
........
  r11310 | paul | 2007-06-11 19:10:18 +0200 (Mon, 11 Jun 2007) | 1 line
  
  misc
........
  r11312 | marc | 2007-06-12 01:44:03 +0200 (Tue, 12 Jun 2007) | 2 lines
  
  * start with carbon
........
  r11313 | paul | 2007-06-12 14:02:48 +0200 (Tue, 12 Jun 2007) | 1 line
  
  - BitBtn glyph transparency
........
  r11315 | paul | 2007-06-13 05:20:40 +0200 (Wed, 13 Jun 2007) | 1 line
  
  - problems with internal bitmap saving/loading (is was 24bpp when 32bpp needed)
........
  r11319 | paul | 2007-06-14 06:32:04 +0200 (Thu, 14 Jun 2007) | 1 line
  
  - More LCL way of painting images through ThemeServices
........
  r11320 | paul | 2007-06-14 06:32:56 +0200 (Thu, 14 Jun 2007) | 1 line
  
  - ability to override bitbtn glyph to nothing
........
  r11321 | paul | 2007-06-14 06:34:49 +0200 (Thu, 14 Jun 2007) | 1 line
  
  painting headercontrol images through ThemeServices
........
  r11325 | paul | 2007-06-17 10:14:27 +0200 (Sun, 17 Jun 2007) | 1 line
  
  fixing painting of 32bpp bitmaps with no Alpha
........
  r11326 | paul | 2007-06-17 10:16:00 +0200 (Sun, 17 Jun 2007) | 1 line
  
  missed file
........
  r11337 | paul | 2007-06-20 03:44:47 +0200 (Wed, 20 Jun 2007) | 3 lines
  
  - revert previous commit
  - create 24bpp bitmaps by default
........
  r11342 | marc | 2007-06-21 01:47:30 +0200 (Thu, 21 Jun 2007) | 3 lines
  
  * Added Alpha support on Carbon
  * Simplified win32 rawimage_fromdevice
........
  r11343 | paul | 2007-06-21 04:36:28 +0200 (Thu, 21 Jun 2007) | 1 line
  
  - adopt gtk2 code
........
  r11344 | paul | 2007-06-21 04:41:41 +0200 (Thu, 21 Jun 2007) | 1 line
  
  make gtk2 work
........
  r11353 | paul | 2007-06-22 10:12:19 +0200 (Fri, 22 Jun 2007) | 1 line
  
  - default WS imagelist implementation
........
  r11358 | marc | 2007-06-23 13:29:06 +0200 (Sat, 23 Jun 2007) | 2 lines
  
  * Implemented MaskBlit
........
  r11359 | paul | 2007-06-23 20:02:52 +0200 (Sat, 23 Jun 2007) | 1 line
  
  draw new imagelist bitmap on widget canvas
........
  r11371 | marc | 2007-06-25 23:50:13 +0200 (Mon, 25 Jun 2007) | 2 lines
  
  * Rawimage rework
........
  r11372 | marc | 2007-06-25 23:51:00 +0200 (Mon, 25 Jun 2007) | 2 lines
  
  + Added header
........
  r11373 | marc | 2007-06-26 00:05:55 +0200 (Tue, 26 Jun 2007) | 2 lines
  
  * Swapped RGBA <-> ARGB defualt format since most widgetsets use ARGB
........
  r11374 | marc | 2007-06-26 00:09:36 +0200 (Tue, 26 Jun 2007) | 2 lines
  
  * added
........
  r11462 | marc | 2007-07-12 00:16:02 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  + added header
........
  r11463 | marc | 2007-07-12 00:18:49 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  * Added alpha/masked strechblt support
........
  r11464 | marc | 2007-07-12 00:21:27 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  * create DIBSection instead of DIBitmap
........
  r11502 | marc | 2007-07-14 00:23:42 +0200 (Sat, 14 Jul 2007) | 2 lines
  
  * Fixed transparentcolor after loading bitmap
........
  r11505 | marc | 2007-07-14 15:10:56 +0200 (Sat, 14 Jul 2007) | 2 lines
  
  - Removed ARGB dataconversion, internal format is by default the same now
........
  r11531 | marc | 2007-07-17 01:23:34 +0200 (Tue, 17 Jul 2007) | 2 lines
  
  * changed TRawImage into object
........
  r11533 | paul | 2007-07-17 05:10:31 +0200 (Tue, 17 Jul 2007) | 3 lines
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init
  - change imagelist defines to use old imagelist (new is crashes ide)
  - change TWin32ThemeServices to use old imagelist
........
  r11534 | paul | 2007-07-17 05:19:02 +0200 (Tue, 17 Jul 2007) | 3 lines
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in Qt widgetset
  - change TRawImageDescription.IsEqual and TRawImage.IsEqual
........
  r11535 | paul | 2007-07-17 05:23:53 +0200 (Tue, 17 Jul 2007) | 1 line
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in wince widgetset
........
  r11554 | marc | 2007-07-18 00:10:11 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed compilation on 2.0.4
........
  r11555 | marc | 2007-07-18 00:10:44 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed compilation
........
  r11556 | marc | 2007-07-18 00:11:43 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed fillchar on TRawImage object
........
  r11572 | marc | 2007-07-19 01:41:35 +0200 (Thu, 19 Jul 2007) | 2 lines
  
  * fixed crash when object has vmt
........
  r11573 | marc | 2007-07-19 01:42:14 +0200 (Thu, 19 Jul 2007) | 2 lines
  
  * Made TRawimage compatible with record again
........
  r11580 | marc | 2007-07-20 01:33:20 +0200 (Fri, 20 Jul 2007) | 2 lines
  
  * enabled newimagelist
........
  r11581 | marc | 2007-07-20 01:33:48 +0200 (Fri, 20 Jul 2007) | 2 lines
  
  * fixed font
........

git-svn-id: trunk@11861 -
2007-08-25 01:49:40 +00:00

669 lines
20 KiB
ObjectPascal

{
*****************************************************************************
* Win32WSExtCtrls.pp *
* ------------------ *
* *
* *
*****************************************************************************
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit Win32WSExtCtrls;
{$mode objfpc}{$H+}
interface
uses
////////////////////////////////////////////////////
// I M P O R T A N T
////////////////////////////////////////////////////
// To get as little as posible circles,
// uncomment only when needed for registration
////////////////////////////////////////////////////
SysUtils, Windows, ExtCtrls, Classes, Controls, LCLType, LCLIntf, Themes,
////////////////////////////////////////////////////
WSExtCtrls, WSLCLClasses, Win32Extra, Win32Int, Win32Proc, InterfaceBase,
Win32WSControls;
type
{ TWin32WSCustomPage }
TWin32WSCustomPage = class(TWSCustomPage)
private
protected
public
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
end;
{ TWin32WSCustomNotebook }
TWin32WSCustomNotebook = class(TWSCustomNotebook)
private
protected
public
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure AddAllNBPages(const ANotebook: TCustomNotebook);
class procedure AdjustSizeNotebookPages(const ANotebook: TCustomNotebook);
class procedure AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer); override;
class procedure MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer); override;
class procedure RemoveAllNBPages(const ANotebook: TCustomNotebook);
class procedure RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class procedure SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer); override;
class procedure SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition); override;
class procedure ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean); override;
end;
{ TWin32WSPage }
TWin32WSPage = class(TWSPage)
private
protected
public
end;
{ TWin32WSNotebook }
TWin32WSNotebook = class(TWSNotebook)
private
protected
public
end;
{ TWin32WSShape }
TWin32WSShape = class(TWSShape)
private
protected
public
end;
{ TWin32WSCustomSplitter }
TWin32WSCustomSplitter = class(TWSCustomSplitter)
private
protected
public
class procedure DrawSplitter(const ASplitter: TCustomSplitter); override;
end;
{ TWin32WSSplitter }
TWin32WSSplitter = class(TWSSplitter)
private
protected
public
end;
{ TWin32WSPaintBox }
TWin32WSPaintBox = class(TWSPaintBox)
private
protected
public
end;
{ TWin32WSCustomImage }
TWin32WSCustomImage = class(TWSCustomImage)
private
protected
public
end;
{ TWin32WSImage }
TWin32WSImage = class(TWSImage)
private
protected
public
end;
{ TWin32WSBevel }
TWin32WSBevel = class(TWSBevel)
private
protected
public
end;
{ TWin32WSCustomRadioGroup }
TWin32WSCustomRadioGroup = class(TWSCustomRadioGroup)
private
protected
public
end;
{ TWin32WSRadioGroup }
TWin32WSRadioGroup = class(TWSRadioGroup)
private
protected
public
end;
{ TWin32WSCustomCheckGroup }
TWin32WSCustomCheckGroup = class(TWSCustomCheckGroup)
private
protected
public
end;
{ TWin32WSCheckGroup }
TWin32WSCheckGroup = class(TWSCheckGroup)
private
protected
public
end;
{ TWin32WSCustomLabeledEdit }
TWin32WSCustomLabeledEdit = class(TWSCustomLabeledEdit)
private
protected
public
end;
{ TWin32WSLabeledEdit }
TWin32WSLabeledEdit = class(TWSLabeledEdit)
private
protected
public
end;
{ TWin32WSCustomPanel }
TWin32WSCustomPanel = class(TWSCustomPanel)
private
protected
public
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
end;
{ TWin32WSPanel }
TWin32WSPanel = class(TWSPanel)
private
protected
public
end;
procedure NotebookFocusNewControl(const ANotebook: TCustomNotebook; NewIndex: integer);
function NotebookPageRealToLCLIndex(const ANotebook: TCustomNotebook; AIndex: integer): integer;
implementation
uses
LMessages;
function IsNotebookGroupFocused(const ANotebook: TCustomNotebook): boolean;
var
lNotebookHandle, lWindow: HWND;
begin
result := false;
if not ANotebook.HandleAllocated then exit;
lNotebookHandle := ANotebook.Handle;
lWindow := Windows.GetFocus;
while (lWindow <> 0) and (lWindow <> lNotebookHandle) do
lWindow := Windows.GetParent(lWindow);
if lWindow = 0 then exit;
result := true;
end;
{ sets focus to a control on the newly focused tab page }
procedure NotebookFocusNewControl(const ANotebook: TCustomNotebook; NewIndex: integer);
var
Page: TCustomPage;
ControlList: TFPList;
lWinControl: TWinControl;
I: integer;
begin
{ see if currently focused control is within notebook }
if not IsNotebookGroupFocused(ANotebook) then exit;
{ focus was/is within notebook, pick a new control to focus }
Page := ANotebook.CustomPage(NewIndex);
ControlList := TFPList.Create;
try
Page.GetTabOrderList(ControlList);
I := 0;
while I < ControlList.Count do
begin
lWinControl := TWinControl(ControlList[I]);
if lWinControl.TabStop and lWinControl.Enabled and lWinControl.CanFocus then
begin
lWinControl.SetFocus;
break;
end;
Inc(I);
end;
if I = ControlList.Count then
Windows.SetFocus(Page.Handle);
finally
ControlList.Free;
end;
end;
function NotebookPageRealToLCLIndex(const ANotebook: TCustomNotebook; AIndex: integer): integer;
var
I: Integer;
begin
Result := AIndex;
if csDesigning in ANotebook.ComponentState then exit;
I := 0;
while (I < ANotebook.PageCount) and (I <= Result) do
begin
if not ANotebook.Page[I].TabVisible then Inc(Result);
Inc(I);
end;
end;
{ TWin32WSCustomPage }
class function TWin32WSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Params: TCreateWindowExParams;
begin
// general initialization of Params
PrepareCreateWindow(AWinControl, Params);
// customization of Params
with Params do
begin
pClassName := @ClsName[0];
Flags := Flags and not WS_VISIBLE;
SubClassWndProc := nil;
end;
// create window
FinishCreateWindow(AWinControl, Params, false);
// return window handle
Result := Params.Window;
if ThemeServices.ThemesEnabled then
with Params.WindowInfo^ do
begin
needParentPaint := true;
isTabPage := true;
end;
end;
class procedure TWin32WSCustomPage.SetText(const AWinControl: TWinControl; const AText: string);
var
TCI: TC_ITEM;
PageIndex: integer;
NotebookHandle: HWND;
begin
PageIndex := TCustomPage(AWinControl).PageIndex;
NotebookHandle := AWinControl.Parent.Handle;
// We can't set label of a page not yet added,
// Check for valid page index
if (PageIndex>=0) and
(PageIndex < Windows.SendMessage(NotebookHandle, TCM_GETITEMCOUNT,0,0)) then
begin
// retrieve page handle from tab as extra check (in case page isn't added yet).
TCI.mask := TCIF_PARAM;
Windows.SendMessage(NotebookHandle, TCM_GETITEM, PageIndex, LPARAM(@TCI));
if PtrUInt(TCI.lParam)=PtrUInt(AWinControl) then
begin
Assert(False, Format('Trace:TWin32WSCustomPage.SetText --> %S', [AText]));
TCI.mask := TCIF_TEXT;
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
TCI.pszText := PChar(PWideChar(Utf8Decode(AText)));
Windows.SendMessage(NotebookHandle, TCM_SETITEMW, PageIndex, LPARAM(@TCI));
end
else
begin
TCI.pszText := PChar(UTF8ToAnsi(AText));
Windows.SendMessage(NotebookHandle, TCM_SETITEM, PageIndex, LPARAM(@TCI));
end;
{$else}
TCI.pszText := PChar(AText);
Windows.SendMessage(NotebookHandle, TCM_SETITEM, PageIndex, LPARAM(@TCI));
{$endif}
end;
end;
end;
class procedure TWin32WSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
begin
// TODO: implement me!
end;
{ TWin32WSCustomNotebook }
class function TWin32WSCustomNotebook.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Params: TCreateWindowExParams;
begin
// general initialization of Params
PrepareCreateWindow(AWinControl, Params);
// customization of Params
with Params do
begin
case TCustomNoteBook(AWinControl).TabPosition of
tpTop:
Flags := Flags and not(TCS_VERTICAL or TCS_MULTILINE or TCS_BOTTOM);
tpBottom:
Flags := (Flags or TCS_BOTTOM) and not (TCS_VERTICAL or TCS_MULTILINE);
tpLeft:
Flags := (Flags or TCS_VERTICAL or TCS_MULTILINE) and not TCS_RIGHT;
tpRight:
Flags := Flags or (TCS_VERTICAL or TCS_RIGHT or TCS_MULTILINE);
end;
pClassName := WC_TABCONTROL;
end;
// create window
FinishCreateWindow(AWinControl, Params, false);
Result := Params.Window;
// although we may be child of tabpage, cut the paint chain
// to improve speed and possible paint anomalities
Params.WindowInfo^.needParentPaint := false;
end;
class procedure TWin32WSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
var
TCI: TC_ITEM;
begin
with ANotebook do
begin
TCI.Mask := TCIF_TEXT or TCIF_PARAM;
// store object as extra, so we can verify we got the right page later
TCI.lParam := PtrUInt(AChild);
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
TCI.pszText := PChar(PWideChar(Utf8Decode(AChild.Caption)));
Windows.SendMessage(Handle, TCM_INSERTITEMW, AIndex, LPARAM(@TCI));
end
else
begin
TCI.pszText := PChar(Utf8ToAnsi(AChild.Caption));
Windows.SendMessage(Handle, TCM_INSERTITEM, AIndex, LPARAM(@TCI));
end;
{$else}
TCI.pszText := PChar(AChild.Caption);
Windows.SendMessage(Handle, TCM_INSERTITEM, AIndex, LPARAM(@TCI));
{$endif}
// clientrect possible changed, adding first tab, or deleting last
// windows should send a WM_SIZE message because of this, but it doesn't
// send it ourselves
LCLControlSizeNeedsUpdate(ANotebook, true);
end;
end;
class procedure TWin32WSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
begin
RemovePage(ANotebook, AChild.PageIndex);
AddPage(ANotebook,AChild,NewIndex);
end;
class procedure TWin32WSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
begin
Windows.SendMessage(ANotebook.Handle, TCM_DELETEITEM, Windows.WPARAM(AIndex), 0);
end;
{ -----------------------------------------------------------------------------
Method: AddAllNBPages
Params: Notebook - A notebook control
Returns: Nothing
Adds all pages to notebook (showtabs becomes true)
------------------------------------------------------------------------------}
class procedure TWin32WSCustomNotebook.AddAllNBPages(const ANotebook: TCustomNotebook);
var
TCI: TC_ITEM;
I, Res, RealIndex: Integer;
lPage: TCustomPage;
WinHandle: HWND;
begin
WinHandle := ANotebook.Handle;
RealIndex := 0;
for I := 0 to ANotebook.PageCount - 1 do
begin
lPage := ANotebook.Page[I];
if not lPage.TabVisible and not (csDesigning in lPage.ComponentState) then
continue;
// check if already shown
TCI.Mask := TCIF_PARAM;
Res := Windows.SendMessage(ANotebook.Handle, TCM_GETITEM, RealIndex, LPARAM(@TCI));
if (Res = 0) or (PtrUInt(TCI.lParam) <> PtrUInt(lPage)) then
begin
TCI.Mask := TCIF_TEXT or TCIF_PARAM;
TCI.lParam := PtrUInt(lPage);
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin
TCI.pszText := PChar(PWideChar(Utf8Decode(lPage.Caption)));
Windows.SendMessage(WinHandle, TCM_INSERTITEMW, RealIndex, LPARAM(@TCI));
end
else
begin
TCI.pszText := PChar(Utf8ToAnsi(lPage.Caption));
Windows.SendMessage(WinHandle, TCM_INSERTITEM, RealIndex, LPARAM(@TCI));
end;
{$else}
TCI.pszText := PChar(lPage.Caption);
Windows.SendMessage(WinHandle, TCM_INSERTITEM, RealIndex, LPARAM(@TCI));
{$endif}
end;
Inc(RealIndex);
end;
AdjustSizeNotebookPages(ANotebook);
end;
class procedure TWin32WSCustomNotebook.AdjustSizeNotebookPages(const ANotebook: TCustomNotebook);
var
I: Integer;
R: TRect;
WinHandle: HWND;
lPage: TCustomPage;
begin
WinHandle := ANotebook.Handle;
// Adjust page size to fit in tabcontrol, need bounds of notebook in client of parent
TWin32WidgetSet(WidgetSet).GetClientRect(WinHandle, R);
R.Right := R.Right - R.Left;
R.Bottom := R.Bottom - R.Top;
for I := 0 to ANotebook.PageCount - 1 do
begin
lPage := ANotebook.Page[I];
// we don't need to resize non-existing pages yet, they will be sized when created
if lPage.HandleAllocated then
SetBounds(lPage, R.Left, R.Top, R.Right, R.Bottom);
end;
end;
{------------------------------------------------------------------------------
Method: RemoveAllNBPages
Params: Notebook - The notebook control
Returns: Nothing
Removes all pages from a notebook control (showtabs becomes false)
------------------------------------------------------------------------------}
class procedure TWin32WSCustomNotebook.RemoveAllNBPages(const ANotebook: TCustomNotebook);
var
I: Integer;
WinHandle: HWND;
begin
WinHandle := ANotebook.Handle;
for I := ANotebook.PageCount - 1 downto 0 do
Windows.SendMessage(WinHandle, TCM_DELETEITEM, Windows.WPARAM(I), 0);
AdjustSizeNotebookPages(ANotebook);
end;
class function TWin32WSCustomNotebook.GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer;
var
X: Integer;
begin
Result := AIndex;
if csDesigning in ANotebook.ComponentState then exit;
for X := 0 to AIndex-1 do
if ANotebook.Page[X].TabVisible = False then Dec(Result);
end;
procedure SendSelChangeMessage(const ANotebook: TCustomNotebook; const AHandle: HWND;
const APageIndex: integer);
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
begin
FillChar(Mess,SizeOf(Mess),0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr,SizeOf(NMHdr),0);
NMHdr.code := TCN_SELCHANGE;
NMHdr.hwndfrom := AHandle;
NMHdr.idfrom := APageIndex; //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
DeliverMessage(ANotebook, TLMessage(Mess));
end;
class function TWin32WSCustomNotebook.GetTabIndexAtPos(const ANotebook: TCustomNotebook;
const AClientPos: TPoint): integer;
var
hittestInfo: TC_HITTESTINFO;
begin
hittestInfo.pt.X := AClientPos.X;
hittestInfo.pt.Y := AClientPos.Y;
Result := Windows.SendMessage(ANotebook.Handle, TCM_HITTEST, 0, LPARAM(@hittestInfo));
end;
class procedure TWin32WSCustomNotebook.SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer);
var
Handle: HWND;
PageHandle: HWND;
OldIndex, OldRealIndex, NewRealIndex: Integer;
begin
Handle := ANotebook.Handle;
OldRealIndex := SendMessage(Handle, TCM_GETCURSEL, 0, 0);
OldIndex := NotebookPageRealToLCLIndex(ANotebook, OldRealIndex);
NewRealIndex := GetPageRealIndex(ANotebook, AIndex);
SendMessage(Handle, TCM_SETCURSEL, Windows.WParam(NewRealIndex), 0);
if not (csDestroying in ANotebook.ComponentState) then
begin
// create handle if not already done, need to show!
if (AIndex >= 0) and (AIndex < ANotebook.PageCount) then
begin
PageHandle := ANotebook.CustomPage(AIndex).Handle;
SetWindowPos(PageHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
SendSelChangeMessage(ANotebook, Handle, AIndex);
NotebookFocusNewControl(ANotebook, AIndex);
end;
if (OldIndex >= 0) and (OldIndex <> AIndex)
and (OldIndex < ANotebook.PageCount)
and (ANotebook.CustomPage(OldIndex).HandleAllocated) then
ShowWindow(ANotebook.CustomPage(OldIndex).Handle, SW_HIDE);
end;
end;
class procedure TWin32WSCustomNotebook.SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
if ANoteBook.HandleAllocated then
RecreateWnd(ANoteBook);
end;
class procedure TWin32WSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean);
begin
if AShowTabs then
begin
AddAllNBPages(ANotebook);
end else begin
RemoveAllNBPages(ANotebook);
end;
end;
{ TWin32WSCustomPanel }
class function TWin32WSCustomPanel.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
Params: TCreateWindowExParams;
begin
// general initialization of Params
PrepareCreateWindow(AWinControl, Params);
// customization of Params
with Params do
begin
pClassName := @ClsName[0];
SubClassWndProc := nil;
end;
// create window
FinishCreateWindow(AWinControl, Params, false);
Result := Params.Window;
end;
{ TWin32WSCustomSplitter }
class procedure TWin32WSCustomSplitter.DrawSplitter(const ASplitter: TCustomSplitter);
var
ARect: TRect;
begin
if ASplitter.Beveled then
begin
ARect := Rect(0, 0, ASplitter.Width, ASplitter.Height);
Frame3D(ASplitter.Canvas.Handle, ARect, 1, bvRaised);
end;
end;
initialization
////////////////////////////////////////////////////
// I M P O R T A N T
////////////////////////////////////////////////////
// To improve speed, register only classes
// which actually implement something
////////////////////////////////////////////////////
RegisterWSComponent(TCustomPage, TWin32WSCustomPage);
RegisterWSComponent(TCustomNotebook, TWin32WSCustomNotebook);
// RegisterWSComponent(TPage, TWin32WSPage);
// RegisterWSComponent(TNotebook, TWin32WSNotebook);
// RegisterWSComponent(TShape, TWin32WSShape);
RegisterWSComponent(TCustomSplitter, TWin32WSCustomSplitter);
// RegisterWSComponent(TSplitter, TWin32WSSplitter);
// RegisterWSComponent(TPaintBox, TWin32WSPaintBox);
// RegisterWSComponent(TCustomImage, TWin32WSCustomImage);
// RegisterWSComponent(TImage, TWin32WSImage);
// RegisterWSComponent(TBevel, TWin32WSBevel);
// RegisterWSComponent(TCustomRadioGroup, TWin32WSCustomRadioGroup);
// RegisterWSComponent(TRadioGroup, TWin32WSRadioGroup);
// RegisterWSComponent(TCustomCheckGroup, TWin32WSCustomCheckGroup);
// RegisterWSComponent(TCheckGroup, TWin32WSCheckGroup);
// RegisterWSComponent(TCustomLabeledEdit, TWin32WSCustomLabeledEdit);
// RegisterWSComponent(TLabeledEdit, TWin32WSLabeledEdit);
RegisterWSComponent(TCustomPanel, TWin32WSCustomPanel);
// RegisterWSComponent(TPanel, TWin32WSPanel);
////////////////////////////////////////////////////
end.