Moves TCustomNotebook to ComCtrls in preparation for renaming it

git-svn-id: trunk@31552 -
This commit is contained in:
sekelsenmat 2011-07-04 09:43:21 +00:00
parent 387a2566e5
commit bc7a2ba310
25 changed files with 1902 additions and 1850 deletions

3
.gitattributes vendored
View File

@ -5419,6 +5419,7 @@ lcl/interfaces/gtk/gtklistsl.inc svneol=native#text/pascal
lcl/interfaces/gtk/gtklistslh.inc svneol=native#text/pascal
lcl/interfaces/gtk/gtkmsgqueue.pp svneol=native#text/pascal
lcl/interfaces/gtk/gtkpagecallback.inc svneol=native#text/pascal
lcl/interfaces/gtk/gtkpagecontrol.inc svneol=native#text/pascal
lcl/interfaces/gtk/gtkprivatelist.inc svneol=native#text/pascal
lcl/interfaces/gtk/gtkprivatewidget.inc svneol=native#text/plain
lcl/interfaces/gtk/gtkproc.inc svneol=native#text/pascal
@ -5484,6 +5485,7 @@ lcl/interfaces/gtk2/gtk2listviewtreemodel.pas svneol=native#text/plain
lcl/interfaces/gtk2/gtk2memostrings.inc svneol=native#text/pascal
lcl/interfaces/gtk2/gtk2msgqueue.pp svneol=native#text/pascal
lcl/interfaces/gtk2/gtk2pagecallback.inc svneol=native#text/pascal
lcl/interfaces/gtk2/gtk2pagecontrol.inc svneol=native#text/pascal
lcl/interfaces/gtk2/gtk2privatelist.inc svneol=native#text/pascal
lcl/interfaces/gtk2/gtk2privatewidget.inc svneol=native#text/plain
lcl/interfaces/gtk2/gtk2proc.inc svneol=native#text/pascal
@ -5544,6 +5546,7 @@ lcl/interfaces/qt/qtlclintf.inc svneol=native#text/pascal
lcl/interfaces/qt/qtlclintfh.inc svneol=native#text/pascal
lcl/interfaces/qt/qtobject.inc svneol=native#text/pascal
lcl/interfaces/qt/qtobjects.pas svneol=native#text/plain
lcl/interfaces/qt/qtpagecontrol.inc svneol=native#text/pascal
lcl/interfaces/qt/qtprivate.pp svneol=native#text/plain
lcl/interfaces/qt/qtproc.pp svneol=native#text/pascal
lcl/interfaces/qt/qtthemes.pas svneol=native#text/pascal

View File

@ -36,7 +36,7 @@ uses
// RTL, FCL
Classes, SysUtils, resource,
// LCL
Controls, ExtCtrls, Graphics, LCLProc, FileUtil, LResources, Forms, Dialogs,
Controls, ExtCtrls, Graphics, LCLProc, FileUtil, LResources, Forms, Dialogs, ComCtrls,
// Synedit
SynEdit, SynEditAutoComplete, SynEditKeyCmds, SynEditTypes,
SynEditMiscClasses, SynBeautifier, SynEditTextTrimmer, SynEditMouseCmds,

View File

@ -25,7 +25,7 @@ unit editor_general_misc_options;
interface
uses
LCLProc, StdCtrls, SynEdit, ExtCtrls, EditorOptions,
LCLProc, StdCtrls, SynEdit, ExtCtrls, ComCtrls, EditorOptions,
LazarusIDEStrConsts, IDEProcs, IDEOptionsIntf, editor_general_options,
SynEditTextTrimmer;

View File

@ -39,7 +39,7 @@ uses
Graphics, StdCtrls, Buttons, Menus, LCLType, ExtCtrls, LCLIntf,
Dialogs, Grids, EditBtn, PropertyStorage, TextTools, FrmSelectProps,
StringsPropEditDlg, ColumnDlg, FileUtil, FileCtrl, ObjInspStrConsts,
CollectionPropEditForm, PropEditUtils;
CollectionPropEditForm, PropEditUtils, ComCtrls;
const
MaxIdentLength: Byte = 63;

View File

@ -27,7 +27,6 @@
@author(TCustomProgressBar - Stefan Hille <stoppok@osibisa.ms.sub.org>)
@author(TTrackBar - Stefan Hille <stoppok@osibisa.ms.sub.org>)
@created(1999)
@lastmod(1999)
}
unit ComCtrls;
@ -209,6 +208,200 @@ type
property OnStartDrag;
end;
{ TCustomPage }
TPageFlag = (
pfAdded, // handle of page added to notebook handle
pfAdding, // currently handle of page adding to notebook handle
pfRemoving, // currently removing page handle from notebook handle
pfInserting // currently inserting page into notebook
);
TPageFlags = set of TPageFlag;
TCustomPage = class(TWinControl)
private
FTabVisible: Boolean;
FFlags: TPageFlags;
FImageIndex: TImageIndex;
FOnHide: TNotifyEvent;
FOnShow: TNotifyEvent;
function GetTabVisible: Boolean;
procedure SetImageIndex(const AValue: TImageIndex);
procedure SetTabVisible(const AValue: Boolean);
protected
class procedure WSRegisterClass; override;
procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
procedure SetParent(AParent: TWinControl); override;
property Flags: TPageFlags read FFlags write FFlags;
procedure CMHitTest(var Message: TLMNCHITTEST); message CM_HITTEST;
function GetPageIndex: integer;
procedure SetPageIndex(AValue: Integer);
function DialogChar(var Message: TLMKey): boolean; override;
procedure DoHide; virtual;
procedure DoShow; virtual;
procedure DestroyHandle; override;
procedure RealSetText(const AValue: TCaption); override;
public
constructor Create(TheOwner: TComponent); override;
function CanTab: boolean; override;
function IsControlVisible: Boolean; override;
function HandleObjectShouldBeVisible: boolean; override;
function VisibleIndex: integer;
property PageIndex: Integer read GetPageIndex write SetPageIndex;
property TabVisible: Boolean read GetTabVisible write SetTabVisible default True;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
property Left stored False;
property Top stored False;
property Width stored False;
property Height stored False;
property TabOrder stored False;
property Visible stored false;
property OnHide: TNotifyEvent read FOnHide write FOnHide;
property OnShow: TNotifyEvent read FOnShow write FOnShow;
end;
TCustomPageClass = class of TCustomPage;
{ TNBPages }
TCustomNotebook = class;
TNBPages = class(TStrings)
private
FPageList: TListWithEvent;
FNotebook: TCustomNotebook;
procedure PageListChange(Ptr: Pointer; AnAction: TListNotification);
protected
function Get(Index: Integer): String; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure Put(Index: Integer; const S: String); override;
public
constructor Create(thePageList: TListWithEvent;
theNotebook: TCustomNotebook);
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: String); override;
procedure Move(CurIndex, NewIndex: Integer); override;
end;
{ TCustomNotebook }
TTabChangingEvent = procedure(Sender: TObject;
var AllowChange: Boolean) of object;
TTabPosition = (tpTop, tpBottom, tpLeft, tpRight);
TTabGetImageEvent = procedure(Sender: TObject; TabIndex: Integer;
var ImageIndex: Integer) of object;
TNoteBookOption = (nboShowCloseButtons, nboMultiLine, nboHidePageListPopup);
TNoteBookOptions = set of TNoteBookOption;
TNoteBookCapability = (nbcShowCloseButtons, nbcMultiLine, nbcPageListPopup);
TNoteBookCapabilities = set of TNoteBookCapability;
TCustomNotebook = class(TWinControl)
private
FAccess: TStrings; // TNBPages
FAddingPages: boolean;
FImages: TImageList;
FImageListChangeLink: TChangeLink;
FLoadedPageIndex: integer;
FOnChanging: TTabChangingEvent;
FOnCloseTabClicked: TNotifyEvent;
FOnGetImageIndex: TTabGetImageEvent;
FOnPageChanged: TNotifyEvent;
FOptions: TNoteBookOptions;
FPageIndex: Integer;
FPageIndexOnLastChange: integer;// needed for unique OnChange events
FPageIndexOnLastShow: integer;
FPageList: TList; // TListWithEvent of TCustomPage
FShowTabs: Boolean;
FTabPosition: TTabPosition;
procedure CNNotify(var Message: TLMNotify); message CN_NOTIFY;
procedure DoSendPageIndex;
procedure DoSendShowTabs;
procedure DoSendTabPosition;
procedure DoImageListChange(Sender: TObject);
function GetActivePage: String;
function GetActivePageComponent: TCustomPage;
function GetMultiLine: Boolean;
function GetPage(AIndex: Integer): TCustomPage;
function GetPageCount : integer;
function GetPageIndex: Integer;
function FindVisiblePage(Index: Integer): Integer;
procedure InsertPage(APage: TCustomPage; Index: Integer);
function IsStoredActivePage: boolean;
procedure AddRemovePageHandle(APage: TCustomPage);
procedure MoveTab(Sender: TObject; NewIndex: Integer);
procedure SetMultiLine(const AValue: Boolean);
procedure WSMovePage(APage: TCustomPage; NewIndex: Integer);
procedure PageRemoved(Index: Integer);
procedure RemovePage(Index: Integer);
procedure SetActivePage(const Value: String);
procedure SetActivePageComponent(const AValue: TCustomPage);
procedure SetImages(const AValue: TImageList);
procedure SetOptions(const AValue: TNoteBookOptions);
procedure SetPageIndex(AValue: Integer);
procedure SetPages(AValue: TStrings);
procedure SetShowTabs(AValue: Boolean);
procedure SetTabPosition(tabPos: TTabPosition);
procedure ShowCurrentPage;
procedure UpdateAllDesignerFlags;
procedure UpdateDesignerFlags(APageIndex: integer);
protected
PageClass: TCustomPageClass;
class procedure WSRegisterClass; override;
procedure CreateWnd; override;
procedure DoCreateWnd; virtual;
procedure DoChange; virtual;
procedure Change; virtual;
procedure Loaded; override;
procedure ReadState(Reader: TReader); override;
function DialogChar(var Message: TLMKey): boolean; override;
procedure ShowControl(APage: TControl); override;
procedure UpdateTabProperties; virtual;
function ChildClassAllowed(ChildClass: TClass): boolean; override;
class function GetControlClassDefaultSize: TSize; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property ActivePageComponent: TCustomPage read GetActivePageComponent
write SetActivePageComponent;
property ActivePage: String read GetActivePage write SetActivePage
stored IsStoredActivePage;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function TabIndexAtClientPos(ClientPos: TPoint): integer;
function TabRect(AIndex: Integer): TRect;
function GetImageIndex(ThePageIndex: Integer): Integer; virtual;
function IndexOf(APage: TCustomPage): integer;
function CustomPage(Index: integer): TCustomPage;
function CanChangePageIndex: boolean; virtual;
function GetMinimumTabWidth: integer; virtual;
function GetMinimumTabHeight: integer; virtual;
function GetCapabilities: TNoteBookCapabilities; virtual;
public
procedure DoCloseTabClicked(APage: TCustomPage); virtual;
property Images: TImageList read FImages write SetImages;
property MultiLine: Boolean read GetMultiLine write SetMultiLine default False;
property OnChanging: TTabChangingEvent read FOnChanging write FOnChanging;
property OnCloseTabClicked: TNotifyEvent read FOnCloseTabClicked
write FOnCloseTabClicked;
property OnGetImageIndex: TTabGetImageEvent read FOnGetImageIndex
write FOnGetImageIndex;
property OnPageChanged: TNotifyEvent read FOnPageChanged write FOnPageChanged;
property Options: TNoteBookOptions read FOptions write SetOptions default [];
property Page[Index: Integer]: TCustomPage read GetPage;
property PageCount: integer read GetPageCount;
property PageIndex: Integer read GetPageIndex write SetPageIndex default -1;
property PageList: TList read FPageList;
property Pages: TStrings read FAccess write SetPages;
property ShowTabs: Boolean read FShowTabs write SetShowTabs default True;
property TabPosition: TTabPosition read FTabPosition write SetTabPosition default tpTop;
published
property TabStop default true;
end;
{ TTabSheet }
TPageControl = class;
@ -3080,21 +3273,33 @@ type
property OnSectionTrack;
end;
const
TCN_First = 0-550;
TCN_SELCHANGE = TCN_FIRST - 1;
TCN_SELCHANGING = TCN_FIRST - 2;
function CompareExpandedNodes(Data1, Data2: Pointer): integer;
function CompareTextWithExpandedNode(Key, Data: Pointer): integer;
procedure Register;
{ WidgetSetRegistration }
procedure RegisterCustomPage;
procedure RegisterCustomNotebook;
implementation
// !!! Avoid unit circles. Only add units if really needed.
uses
WSComCtrls;
WSComCtrls, WSFactory, WSLCLClasses;
const
ScrollBarWidth = 0;
AllPanelsParts = [Low(TPanelPart)..High(TPanelPart)];
{$I custompage.inc}
{$I customnotebook.inc}
{$I statusbar.inc}
{$I statuspanel.inc}
{$I statuspanels.inc}
@ -3181,4 +3386,27 @@ begin
RegisterNoIcon([TToolButton,TTabSheet]);
end;
{ WidgetSetRegistration }
procedure RegisterCustomPage;
const
Done: Boolean = False;
begin
if Done then exit;
WSRegisterCustomPage;
// if not WSRegisterCustomPage then
// RegisterWSComponent(TCustomPage, TWSCustomPage);
Done := True;
end;
procedure RegisterCustomNotebook;
const
Done: Boolean = False;
begin
if Done then exit;
if not WSRegisterCustomNotebook then
RegisterWSComponent(TCustomNotebook, TWSCustomNotebook);
Done := True;
end;
end.

View File

@ -39,200 +39,6 @@ uses
type
{ TCustomPage }
TPageFlag = (
pfAdded, // handle of page added to notebook handle
pfAdding, // currently handle of page adding to notebook handle
pfRemoving, // currently removing page handle from notebook handle
pfInserting // currently inserting page into notebook
);
TPageFlags = set of TPageFlag;
TCustomPage = class(TWinControl)
private
FTabVisible: Boolean;
FFlags: TPageFlags;
FImageIndex: TImageIndex;
FOnHide: TNotifyEvent;
FOnShow: TNotifyEvent;
function GetTabVisible: Boolean;
procedure SetImageIndex(const AValue: TImageIndex);
procedure SetTabVisible(const AValue: Boolean);
protected
class procedure WSRegisterClass; override;
procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
procedure SetParent(AParent: TWinControl); override;
property Flags: TPageFlags read FFlags write FFlags;
procedure CMHitTest(var Message: TLMNCHITTEST); message CM_HITTEST;
function GetPageIndex: integer;
procedure SetPageIndex(AValue: Integer);
function DialogChar(var Message: TLMKey): boolean; override;
procedure DoHide; virtual;
procedure DoShow; virtual;
procedure DestroyHandle; override;
procedure RealSetText(const AValue: TCaption); override;
public
constructor Create(TheOwner: TComponent); override;
function CanTab: boolean; override;
function IsControlVisible: Boolean; override;
function HandleObjectShouldBeVisible: boolean; override;
function VisibleIndex: integer;
property PageIndex: Integer read GetPageIndex write SetPageIndex;
property TabVisible: Boolean read GetTabVisible write SetTabVisible default True;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
property Left stored False;
property Top stored False;
property Width stored False;
property Height stored False;
property TabOrder stored False;
property Visible stored false;
property OnHide: TNotifyEvent read FOnHide write FOnHide;
property OnShow: TNotifyEvent read FOnShow write FOnShow;
end;
TCustomPageClass = class of TCustomPage;
{ TNBPages }
TCustomNotebook = class;
TNBPages = class(TStrings)
private
FPageList: TListWithEvent;
FNotebook: TCustomNotebook;
procedure PageListChange(Ptr: Pointer; AnAction: TListNotification);
protected
function Get(Index: Integer): String; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure Put(Index: Integer; const S: String); override;
public
constructor Create(thePageList: TListWithEvent;
theNotebook: TCustomNotebook);
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: String); override;
procedure Move(CurIndex, NewIndex: Integer); override;
end;
{ TCustomNotebook }
TTabChangingEvent = procedure(Sender: TObject;
var AllowChange: Boolean) of object;
TTabPosition = (tpTop, tpBottom, tpLeft, tpRight);
TTabGetImageEvent = procedure(Sender: TObject; TabIndex: Integer;
var ImageIndex: Integer) of object;
TNoteBookOption = (nboShowCloseButtons, nboMultiLine, nboHidePageListPopup);
TNoteBookOptions = set of TNoteBookOption;
TNoteBookCapability = (nbcShowCloseButtons, nbcMultiLine, nbcPageListPopup);
TNoteBookCapabilities = set of TNoteBookCapability;
TCustomNotebook = class(TWinControl)
private
FAccess: TStrings; // TNBPages
FAddingPages: boolean;
FImages: TImageList;
FImageListChangeLink: TChangeLink;
FLoadedPageIndex: integer;
FOnChanging: TTabChangingEvent;
FOnCloseTabClicked: TNotifyEvent;
FOnGetImageIndex: TTabGetImageEvent;
FOnPageChanged: TNotifyEvent;
FOptions: TNoteBookOptions;
FPageIndex: Integer;
FPageIndexOnLastChange: integer;// needed for unique OnChange events
FPageIndexOnLastShow: integer;
FPageList: TList; // TListWithEvent of TCustomPage
FShowTabs: Boolean;
FTabPosition: TTabPosition;
procedure CNNotify(var Message: TLMNotify); message CN_NOTIFY;
procedure DoSendPageIndex;
procedure DoSendShowTabs;
procedure DoSendTabPosition;
procedure DoImageListChange(Sender: TObject);
function GetActivePage: String;
function GetActivePageComponent: TCustomPage;
function GetMultiLine: Boolean;
function GetPage(AIndex: Integer): TCustomPage;
function GetPageCount : integer;
function GetPageIndex: Integer;
function FindVisiblePage(Index: Integer): Integer;
procedure InsertPage(APage: TCustomPage; Index: Integer);
function IsStoredActivePage: boolean;
procedure AddRemovePageHandle(APage: TCustomPage);
procedure MoveTab(Sender: TObject; NewIndex: Integer);
procedure SetMultiLine(const AValue: Boolean);
procedure WSMovePage(APage: TCustomPage; NewIndex: Integer);
procedure PageRemoved(Index: Integer);
procedure RemovePage(Index: Integer);
procedure SetActivePage(const Value: String);
procedure SetActivePageComponent(const AValue: TCustomPage);
procedure SetImages(const AValue: TImageList);
procedure SetOptions(const AValue: TNoteBookOptions);
procedure SetPageIndex(AValue: Integer);
procedure SetPages(AValue: TStrings);
procedure SetShowTabs(AValue: Boolean);
procedure SetTabPosition(tabPos: TTabPosition);
procedure ShowCurrentPage;
procedure UpdateAllDesignerFlags;
procedure UpdateDesignerFlags(APageIndex: integer);
protected
PageClass: TCustomPageClass;
class procedure WSRegisterClass; override;
procedure CreateWnd; override;
procedure DoCreateWnd; virtual;
procedure DoChange; virtual;
procedure Change; virtual;
procedure Loaded; override;
procedure ReadState(Reader: TReader); override;
function DialogChar(var Message: TLMKey): boolean; override;
procedure ShowControl(APage: TControl); override;
procedure UpdateTabProperties; virtual;
function ChildClassAllowed(ChildClass: TClass): boolean; override;
class function GetControlClassDefaultSize: TSize; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property ActivePageComponent: TCustomPage read GetActivePageComponent
write SetActivePageComponent;
property ActivePage: String read GetActivePage write SetActivePage
stored IsStoredActivePage;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function TabIndexAtClientPos(ClientPos: TPoint): integer;
function TabRect(AIndex: Integer): TRect;
function GetImageIndex(ThePageIndex: Integer): Integer; virtual;
function IndexOf(APage: TCustomPage): integer;
function CustomPage(Index: integer): TCustomPage;
function CanChangePageIndex: boolean; virtual;
function GetMinimumTabWidth: integer; virtual;
function GetMinimumTabHeight: integer; virtual;
function GetCapabilities: TNoteBookCapabilities; virtual;
public
procedure DoCloseTabClicked(APage: TCustomPage); virtual;
property Images: TImageList read FImages write SetImages;
property MultiLine: Boolean read GetMultiLine write SetMultiLine default False;
property OnChanging: TTabChangingEvent read FOnChanging write FOnChanging;
property OnCloseTabClicked: TNotifyEvent read FOnCloseTabClicked
write FOnCloseTabClicked;
property OnGetImageIndex: TTabGetImageEvent read FOnGetImageIndex
write FOnGetImageIndex;
property OnPageChanged: TNotifyEvent read FOnPageChanged write FOnPageChanged;
property Options: TNoteBookOptions read FOptions write SetOptions default [];
property Page[Index: Integer]: TCustomPage read GetPage;
property PageCount: integer read GetPageCount;
property PageIndex: Integer read GetPageIndex write SetPageIndex default -1;
property PageList: TList read FPageList;
property Pages: TStrings read FAccess write SetPages;
property ShowTabs: Boolean read FShowTabs write SetShowTabs default True;
property TabPosition: TTabPosition read FTabPosition write SetTabPosition default tpTop;
published
property TabStop default true;
end;
{ TPage }
TPage = class;
@ -1307,11 +1113,6 @@ type
property OnPaint;
end;
const
TCN_First = 0-550;
TCN_SELCHANGE = TCN_FIRST - 1;
TCN_SELCHANGING = TCN_FIRST - 2;
procedure Frame3D(ACanvas: TCanvas; var ARect: TRect;
TopColor, BottomColor: TColor; const FrameWidth: integer);
@ -1341,8 +1142,6 @@ begin
RegisterNoIcon([TPage]);
end;
{$I custompage.inc}
{$I customnotebook.inc}
{$I page.inc}
{$I notebook.inc}
{$I timer.inc}

View File

@ -101,12 +101,12 @@ end;
------------------------------------------------------------------------------}
procedure TUNBPages.Delete(Index: Integer);
var
APage: TCustomPage;
APage: TPage;
begin
// Make sure Index is in the range of valid pages to delete
if (Index < 0) or (Index >= fPageList.Count) then Exit;
APage := TCustomPage(fPageList[Index]);
APage := TPage(fPageList[Index]);
// delete handle
APage.Parent := nil;
// free the page

View File

@ -38,9 +38,9 @@ uses
{$endif CarbonUseCocoa}
// LCL
Classes, Controls, ExtCtrls, LCLType, LCLProc, Graphics, Math, SysUtils,
Menus,
Menus, ComCtrls,
// widgetset
WSExtCtrls, WSLCLClasses, WSControls, WSProc,
WSExtCtrls, WSLCLClasses, WSControls, WSProc, WSComCtrls,
// LCL Carbon
carbongdiobjects, CarbonWSControls;

View File

@ -30,11 +30,30 @@ uses
// Bindings
fpguiwsprivate,
// LCL
ComCtrls,
Classes,
ComCtrls, Controls, LCLType,
// Widgetset
WSComCtrls, WSLCLClasses;
type
{ TFpGuiWSCustomPage }
TFpGuiWSCustomPage = class(TWSCustomPage)
private
protected
public
end;
{ TFpGuiWSCustomNotebook }
TFpGuiWSCustomNotebook = class(TWSCustomNotebook)
private
protected
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
end;
{ TFpGuiWSStatusBar }
@ -143,6 +162,22 @@ type
implementation
{ TFpGuiWSCustomNotebook }
class function TFpGuiWSCustomNotebook.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams): HWND;
begin
Result := TLCLIntfHandle(TFPGUIPrivatePageControl.Create(AWinControl, AParams));
end;
class procedure TFpGuiWSCustomNotebook.DestroyHandle(
const AWinControl: TWinControl);
begin
TFPGUIPrivatePageControl(AWinControl.Handle).Free;
AWinControl.Handle := 0;
end;
initialization
////////////////////////////////////////////////////

View File

@ -37,25 +37,6 @@ uses
type
{ TFpGuiWSCustomPage }
TFpGuiWSCustomPage = class(TWSCustomPage)
private
protected
public
end;
{ TFpGuiWSCustomNotebook }
TFpGuiWSCustomNotebook = class(TWSCustomNotebook)
private
protected
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
end;
{ TFpGuiWSPage }
TFpGuiWSPage = class(TWSPage)
@ -208,22 +189,6 @@ type
implementation
{ TFpGuiWSCustomNotebook }
class function TFpGuiWSCustomNotebook.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams): HWND;
begin
Result := TLCLIntfHandle(TFPGUIPrivatePageControl.Create(AWinControl, AParams));
end;
class procedure TFpGuiWSCustomNotebook.DestroyHandle(
const AWinControl: TWinControl);
begin
TFPGUIPrivatePageControl(AWinControl.Handle).Free;
AWinControl.Handle := 0;
end;
{ TFpGuiWSCustomTrayIcon }
class function TFpGuiWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;

View File

@ -5,7 +5,7 @@ unit FpGuiWSFactory;
interface
uses
Classes, Controls, StdCtrls, Forms, Menus, ExtCtrls, Dialogs,
Classes, Controls, StdCtrls, Forms, Menus, ExtCtrls, Dialogs, ComCtrls,
WSLCLClasses;
// imglist
@ -102,6 +102,7 @@ uses
FpGuiWSButtons,
FpGuiWSControls,
FpGuiWSExtCtrls,
FpGuiWSComCtrls,
FpGuiWSForms,
FpGuiWSMenus,
FpGuiWSStdCtrls,

View File

@ -0,0 +1,516 @@
{%MainUnit gtkwscomctrls.pp}
{
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, 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. *
* *
*****************************************************************************
}
const
GtkPositionTypeMap: array[TTabPosition] of TGtkPositionType =
(
{ tpTop } GTK_POS_TOP,
{ tpBottom } GTK_POS_BOTTOM,
{ tpLeft } GTK_POS_LEFT,
{ tpRight } GTK_POS_RIGHT
);
LCL_NotebookManualPageSwitchKey = 'lcl_manual_page_switch';
{ TGtkWSCustomPage }
class procedure TGtkWSCustomPage.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtkWSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
Widget := GtkWidgetset.CreateSimpleClientAreaWidget(AWinControl, True);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(Widget));
WidgetInfo := GetWidgetInfo(Widget);
WidgetInfo^.LCLObject := AWinControl;
WidgetInfo^.Style := AParams.Style;
WidgetInfo^.ExStyle := AParams.ExStyle;
WidgetInfo^.WndProc := PtrUInt(AParams.WindowClass.lpfnWndProc);
Set_RC_Name(AWinControl, Widget);
SetCallBacks(Widget, WidgetInfo);
end;
class procedure TGtkWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
{$ifdef gtk2}
var
NoteBook: PGtkWidget;
PageWidget: PGtkWidget;
TabWidget: PGtkWidget;
TabImageWidget: PGtkWidget;
{$endif}
begin
UpdateNotebookPageTab(nil, ACustomPage);
{$ifdef gtk2}
{we must update our icon (if exists) otherwise it will be updated only
when our tab reach focus}
if not (csDesigning in ACustomPage.ComponentState)
and not ACustomPage.TabVisible
or not ACustomPage.HandleAllocated
or not Assigned(ACustomPage.Parent)
then
exit;
PageWidget := PGtkWidget(ACustomPage.Handle);
NoteBook := PGtkWidget(ACustomPage.Parent.Handle);
if (NoteBook = nil) or not GTK_IS_NOTEBOOK(NoteBook) then
exit;
TabWidget := gtk_notebook_get_tab_label(PGtkNoteBook(Notebook), PageWidget);
if (TabWidget = nil) or not GTK_WIDGET_VISIBLE(TabWidget) then
exit;
TabImageWidget := gtk_object_get_data(PGtkObject(TabWidget), 'TabImage');
if TabImageWidget <> nil then
gtk_widget_queue_draw(TabImageWidget);
{$endif}
end;
class procedure TGtkWSCustomPage.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
// ignore resizes from the LCL
end;
class procedure TGtkWSCustomPage.ShowHide(const AWinControl: TWinControl);
begin
{$ifdef gtk2}
if (csDesigning in AWinControl.ComponentState) then
TGtkWidgetSet(WidgetSet).SetVisible(AWinControl,
AWinControl.HandleObjectShouldBeVisible)
else
{$endif}
TGtkWidgetSet(WidgetSet).SetVisible(AWinControl,
TCustomPage(AWinControl).TabVisible);
end;
{ TGtkWSCustomNotebook }
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;
function GtkWSNotebook_SwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
IsManual: Boolean;
begin
Result := CallBackDefaultReturn;
EventTrace('switch-page', data);
UpdateNoteBookClientWidget(TObject(Data));
// remove flag
IsManual := gtk_object_get_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey) <> nil;
if IsManual then
gtk_object_set_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey, nil);
if PGtkNotebook(Widget)^.cur_page = nil then // for windows compatibility
Exit;
// gtkswitchpage is called before the switch
if not IsManual then
begin
// send first the TCN_SELCHANGING to ask if switch is allowed
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGING;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
Mess.Result := 0;
DeliverMessage(Data, Mess);
if Mess.Result <> 0 then
begin
g_signal_stop_emission_by_name(PGtkObject(Widget), 'switch-page');
Result := not CallBackDefaultReturn;
Exit;
end;
end;
// then send the new page
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGE;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
DeliverMessage(Data, Mess);
end;
class procedure TGtkWSCustomNotebook.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
ConnectSignal(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_SwitchPage, AWidgetInfo^.LCLObject);
end;
class function TGtkWSCustomNotebook.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
AWidget: PGtkNoteBook;
WidgetInfo: PWidgetInfo;
begin
AWidget := PGtkNoteBook(gtk_notebook_new());
WidgetInfo := CreateWidgetInfo(AWidget, AWinControl, AParams);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(AWidget), dbgsName(AWinControl));
{$ENDIF}
gtk_notebook_set_scrollable(AWidget, True);
if not (nboHidePageListPopup in TCustomNotebook(AWinControl).Options) then
gtk_notebook_popup_enable(AWidget);
if TCustomNotebook(AWinControl).PageCount=0 then
// a gtk notebook needs a page -> add dummy page
GTKWidgetSet.AddDummyNoteBookPage(AWidget);
gtk_notebook_set_tab_pos(AWidget, GtkPositionTypeMap[TCustomNotebook(AWinControl).TabPosition]);
Result := TLCLIntfHandle(PtrUInt(AWidget));
Set_RC_Name(AWinControl, PGtkWidget(AWidget));
SetCallBacks(PGtkWidget(AWidget), WidgetInfo);
end;
class procedure TGtkWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
{
Inserts a new page to a notebook at position Index. The ANotebook is a
TCustomNoteBook, the AChild one of its TCustomPage. Both handles must already
be created. ANoteBook Handle is a PGtkNoteBook and APage handle is a
PGtkHBox.
This procedure creates a new tab with an optional image, the page caption and
an optional close button. The image and the caption will also be added to the
tab popup menu.
}
var
NoteBookWidget: PGtkWidget; // the notebook
PageWidget: PGtkWidget; // the page (content widget)
TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label
// and a close button)
TabLabelWidget: PGtkWidget; // the label in the tab
MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and
// a label)
MenuLabelWidget: PGtkWidget; // the label in the popup menu item
begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage ',dbgsName(ANoteBook),' ',ANotebook.HandleAllocated,' AChild=',dbgsName(AChild),' ',AChild.HandleAllocated,' Child.TabVisible=',AChild.TabVisible]);
{$ENDIF}
NoteBookWidget := PGtkWidget(ANoteBook.Handle);
PageWidget := PGtkWidget(AChild.Handle);
// set LCL size
AChild.SetBounds(AChild.Left, AChild.Top, ANotebook.ClientWidth, ANotebook.ClientHeight);
if AChild.TabVisible then
gtk_widget_show(PageWidget);
// Check if already created. if so just show it because it is invisible
if gtk_notebook_get_tab_label(PGtkNoteBook(NoteBookWidget), PageWidget) <> nil
then begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage already added']);
{$ENDIF}
exit;
end;
// create the tab (hbox container)
TabWidget := gtk_hbox_new(false, 1);
gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil);
// put a label into the tab
TabLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(TabWidget), 'TabLabel', TabLabelWidget);
gtk_widget_show(TabLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(TabWidget), TabLabelWidget);
if AChild.TabVisible then
gtk_widget_show(TabWidget);
// create popup menu item
MenuWidget := gtk_hbox_new(false, 2);
// set icon widget to nil
gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
// put a label into the menu
MenuLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget);
gtk_widget_show(MenuLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(MenuWidget), MenuLabelWidget);
if AChild.TabVisible then
gtk_widget_show(MenuWidget);
// remove the dummy page (a gtk_notebook needs at least one page)
RemoveDummyNoteBookPage(PGtkNotebook(NoteBookWidget));
// insert the page
gtk_notebook_insert_page_menu(PGtkNotebook(NotebookWidget), PageWidget,
TabWidget, MenuWidget, AIndex);
UpdateNotebookPageTab(ANoteBook, AChild);
UpdateNoteBookClientWidget(ANoteBook);
// init the size of the page widget
//DebugLn(['TGtkWSCustomNotebook.AddPage ',DbgSName(ANoteBook),' ',dbgs(ANoteBook.BoundsRect)]);
{$IFDEF VerboseSizeMsg}
DebugLn(['TGtkWSCustomNotebook.AddPage PageWidget^.allocation=',dbgs(PageWidget^.allocation),' NotebookWidget=',dbgs(NotebookWidget^.allocation)]);
{$ENDIF}
end;
class procedure TGtkWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
NoteBookWidget: PGtkNotebook;
begin
NoteBookWidget:=PGtkNotebook(ANoteBook.Handle);
gtk_notebook_reorder_child(NoteBookWidget, PGtkWidget(AChild.Handle), NewIndex);
UpdateNoteBookClientWidget(ANoteBook);
end;
class procedure TGtkWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
PageWidget: PGtkWidget;
Page: TCustomPage;
begin
// The gtk does not provide a function to remove a page without destroying it.
// Luckily the LCL destroys the Handle, when a page is removed, so this
// function is not needed.
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.RemovePage AIndex=',AIndex,' ',DbgSName(ANotebook.Page[AIndex])]);
{$ENDIF}
Page:=ANotebook.Page[AIndex];
if not Page.HandleAllocated then exit;
PageWidget := PGtkWidget(Page.Handle);
gtk_widget_hide(PageWidget);
end;
class function TGtkWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[nbcPageListPopup, nbcShowCloseButtons];
end;
class function TGtkWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
var
NBWidget: PGTKWidget;
BorderWidth: Integer;
{$IFDEF Gtk1}
Requisition: TGtkRequisition;
{$ENDIF}
Page: PGtkNotebookPage;
begin
Result:=inherited GetNotebookMinTabHeight(AWinControl);
//debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(Result));
exit;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(AWinControl.HandleAllocated));
if AWinControl.HandleAllocated then
NBWidget:=PGTKWidget(AWinControl.Handle)
else
NBWidget:=GetStyleWidget(lgsNotebook);
// ToDo: find out how to create a fully working hidden Notebook style widget
if (NBWidget=nil) then begin
Result:=TWSCustomNotebook.GetNotebookMinTabHeight(AWinControl);
exit;
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight NBWidget: ',GetWidgetDebugReport(NBWidget),
' ',dbgs(NBWidget^.allocation.width),'x',dbgs(NBWidget^.allocation.height));
BorderWidth:=(PGtkContainer(NBWidget)^.flag0 and bm_TGtkContainer_border_width)
shr bp_TGtkContainer_border_width;
if PGtkNoteBook(NBWidget)^.first_tab<>nil then
Page:=PGtkNoteBook(NBWidget)^.cur_page;
Result:=BorderWidth;
{$IFDEF GTK2}
if (Page<>nil) then begin
debugln('TGtkWSCustomNotebook.RemovePage TODO');
end;
{$ELSE GTK2}
if (NBWidget^.thestyle<>nil) and (PGtkStyle(NBWidget^.thestyle)^.klass<>nil) then
inc(Result,PGtkStyle(NBWidget^.thestyle)^.klass^.ythickness);
if (Page<>nil) and (Page^.child<>nil) then begin
gtk_widget_size_request(Page^.Child, @Requisition);
gtk_widget_map(Page^.child);
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight B ',dbgs(Page^.child^.allocation.height),
' ',GetWidgetDebugReport(Page^.child),' Requisition=',dbgs(Requisition.height));
inc(Result,Page^.child^.allocation.height);
end;
{$ENDIF GTK2}
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight END ',dbgs(Result),' ',
GetWidgetDebugReport(NBWidget));
end;
class function TGtkWSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
begin
Result:=TWSCustomNotebook.GetNotebookMinTabWidth(AWinControl);
end;
class function TGtkWSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
NoteBookWidget: PGtkNotebook;
i: integer;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
NotebookPos: TPoint;
{$IFDEF GTK2}
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
{$ENDIF}
Count: guint;
begin
Result:=-1;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
{$IFDEF GTK2}
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
NotebookPos.X:= AClientPos.X + (ClientOrg.X-WindowOrg.X);
NotebookPos.Y:= AClientPos.Y + (ClientOrg.Y-WindowOrg.Y);
{$ELSE}
NotebookPos:=AClientPos;
{$ENDIF}
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
for i:=0 to Count-1 do
begin
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget,i);
if PageWidget<>nil then
begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if (TabWidget<>nil) and GTK_WIDGET_MAPPED(TabWidget) then
begin
// test if position is in tabwidget
if (TabWidget^.Allocation.X<=NoteBookPos.X)
and (TabWidget^.Allocation.Y<=NoteBookPos.Y)
and (TabWidget^.Allocation.X+TabWidget^.Allocation.Width>NoteBookPos.X)
and (TabWidget^.Allocation.Y+TabWidget^.Allocation.Height>NoteBookPos.Y)
then begin
Result:=i;
exit;
end;
end;
end;
end;
end;
class function TGtkWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
NoteBookWidget: PGtkNotebook;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
{$IFDEF GTK2}
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
{$ENDIF}
XOffset, YOffset: Integer;
Count: guint;
begin
Result := inherited;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
{$IFDEF GTK2}
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
XOffset := (ClientOrg.X-WindowOrg.X);
YOffset := (ClientOrg.Y-WindowOrg.Y);
{$ELSE}
XOffset := 0;
YOffset := 0;
{$ENDIF}
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget, AIndex);
if (PageWidget<>nil) and (AIndex < Count) then begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if TabWidget<>nil then begin
Result.Top := TabWidget^.Allocation.Y - YOffset;
Result.Bottom := TabWidget^.Allocation.Y - YOffset + TabWidget^.Allocation.Height;
Result.Left := TabWidget^.Allocation.X - XOffset;
Result.right := TabWidget^.Allocation.X - XOffset + TabWidget^.Allocation.Width;
exit;
end;
end;
end;
class procedure TGtkWSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
GtkNotebook: PGtkNotebook;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
GtkNotebook := PGtkNoteBook(ANotebook.Handle);
if gtk_notebook_get_current_page(GtkNotebook) <> AIndex then
begin
gtk_object_set_data(PGtkObject(GtkNotebook), LCL_NotebookManualPageSwitchKey, ANotebook);
gtk_notebook_set_page(GtkNotebook, AIndex);
end;
UpdateNoteBookClientWidget(ANotebook);
end;
class procedure TGtkWSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
gtk_notebook_set_tab_pos(PGtkNotebook(ANotebook.Handle),
GtkPositionTypeMap[ATabPosition]);
end;
class procedure TGtkWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
gtk_notebook_set_show_tabs(PGtkNotebook(ANotebook.Handle), AShowTabs);
end;
class procedure TGtkWSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
if (nboHidePageListPopup in ANoteBook.Options) then
gtk_notebook_popup_disable(PGtkNotebook(ANoteBook.Handle))
else
gtk_notebook_popup_enable(PGtkNotebook(ANoteBook.Handle));
end;

View File

@ -42,6 +42,45 @@ uses
GtkDef, GtkExtra, GtkWSPrivate;
type
{ TGtkWSCustomPage }
TGtkWSCustomPage = class(TWSCustomPage)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure ShowHide(const AWinControl: TWinControl); override;
end;
{ TGtkWSCustomNotebook }
TGtkWSCustomNotebook = class(TWSCustomNotebook)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; 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;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TGtkWSStatusBar }
TGtkWSStatusBar = class(TWSStatusBar)
@ -223,6 +262,7 @@ uses
const
DEFAULT_IMAGE_SPACING = 3;
{$include gtkpagecontrol.inc}
{$IFDEF GTK1}
{$I gtkwscustomlistview.inc }

View File

@ -40,45 +40,6 @@ uses
type
{ TGtkWSCustomPage }
TGtkWSCustomPage = class(TWSCustomPage)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure ShowHide(const AWinControl: TWinControl); override;
end;
{ TGtkWSCustomNotebook }
TGtkWSCustomNotebook = class(TWSCustomNotebook)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; 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;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TGtkWSPage }
TGtkWSPage = class(TWSPage)
@ -205,507 +166,6 @@ uses
x, xlib, xutil;
{$ENDIF}
const
GtkPositionTypeMap: array[TTabPosition] of TGtkPositionType =
(
{ tpTop } GTK_POS_TOP,
{ tpBottom } GTK_POS_BOTTOM,
{ tpLeft } GTK_POS_LEFT,
{ tpRight } GTK_POS_RIGHT
);
LCL_NotebookManualPageSwitchKey = 'lcl_manual_page_switch';
{ TGtkWSCustomPage }
class procedure TGtkWSCustomPage.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtkWSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
Widget := GtkWidgetset.CreateSimpleClientAreaWidget(AWinControl, True);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(Widget));
WidgetInfo := GetWidgetInfo(Widget);
WidgetInfo^.LCLObject := AWinControl;
WidgetInfo^.Style := AParams.Style;
WidgetInfo^.ExStyle := AParams.ExStyle;
WidgetInfo^.WndProc := PtrUInt(AParams.WindowClass.lpfnWndProc);
Set_RC_Name(AWinControl, Widget);
SetCallBacks(Widget, WidgetInfo);
end;
class procedure TGtkWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
{$ifdef gtk2}
var
NoteBook: PGtkWidget;
PageWidget: PGtkWidget;
TabWidget: PGtkWidget;
TabImageWidget: PGtkWidget;
{$endif}
begin
UpdateNotebookPageTab(nil, ACustomPage);
{$ifdef gtk2}
{we must update our icon (if exists) otherwise it will be updated only
when our tab reach focus}
if not (csDesigning in ACustomPage.ComponentState)
and not ACustomPage.TabVisible
or not ACustomPage.HandleAllocated
or not Assigned(ACustomPage.Parent)
then
exit;
PageWidget := PGtkWidget(ACustomPage.Handle);
NoteBook := PGtkWidget(ACustomPage.Parent.Handle);
if (NoteBook = nil) or not GTK_IS_NOTEBOOK(NoteBook) then
exit;
TabWidget := gtk_notebook_get_tab_label(PGtkNoteBook(Notebook), PageWidget);
if (TabWidget = nil) or not GTK_WIDGET_VISIBLE(TabWidget) then
exit;
TabImageWidget := gtk_object_get_data(PGtkObject(TabWidget), 'TabImage');
if TabImageWidget <> nil then
gtk_widget_queue_draw(TabImageWidget);
{$endif}
end;
class procedure TGtkWSCustomPage.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
// ignore resizes from the LCL
end;
class procedure TGtkWSCustomPage.ShowHide(const AWinControl: TWinControl);
begin
{$ifdef gtk2}
if (csDesigning in AWinControl.ComponentState) then
TGtkWidgetSet(WidgetSet).SetVisible(AWinControl,
AWinControl.HandleObjectShouldBeVisible)
else
{$endif}
TGtkWidgetSet(WidgetSet).SetVisible(AWinControl,
TCustomPage(AWinControl).TabVisible);
end;
{ TGtkWSCustomNotebook }
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;
function GtkWSNotebook_SwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
IsManual: Boolean;
begin
Result := CallBackDefaultReturn;
EventTrace('switch-page', data);
UpdateNoteBookClientWidget(TObject(Data));
// remove flag
IsManual := gtk_object_get_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey) <> nil;
if IsManual then
gtk_object_set_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey, nil);
if PGtkNotebook(Widget)^.cur_page = nil then // for windows compatibility
Exit;
// gtkswitchpage is called before the switch
if not IsManual then
begin
// send first the TCN_SELCHANGING to ask if switch is allowed
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGING;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
Mess.Result := 0;
DeliverMessage(Data, Mess);
if Mess.Result <> 0 then
begin
g_signal_stop_emission_by_name(PGtkObject(Widget), 'switch-page');
Result := not CallBackDefaultReturn;
Exit;
end;
end;
// then send the new page
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGE;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
DeliverMessage(Data, Mess);
end;
class procedure TGtkWSCustomNotebook.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
ConnectSignal(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_SwitchPage, AWidgetInfo^.LCLObject);
end;
class function TGtkWSCustomNotebook.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
AWidget: PGtkNoteBook;
WidgetInfo: PWidgetInfo;
begin
AWidget := PGtkNoteBook(gtk_notebook_new());
WidgetInfo := CreateWidgetInfo(AWidget, AWinControl, AParams);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(AWidget), dbgsName(AWinControl));
{$ENDIF}
gtk_notebook_set_scrollable(AWidget, True);
if not (nboHidePageListPopup in TCustomNotebook(AWinControl).Options) then
gtk_notebook_popup_enable(AWidget);
if TCustomNotebook(AWinControl).PageCount=0 then
// a gtk notebook needs a page -> add dummy page
GTKWidgetSet.AddDummyNoteBookPage(AWidget);
gtk_notebook_set_tab_pos(AWidget, GtkPositionTypeMap[TCustomNotebook(AWinControl).TabPosition]);
Result := TLCLIntfHandle(PtrUInt(AWidget));
Set_RC_Name(AWinControl, PGtkWidget(AWidget));
SetCallBacks(PGtkWidget(AWidget), WidgetInfo);
end;
class procedure TGtkWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
{
Inserts a new page to a notebook at position Index. The ANotebook is a
TCustomNoteBook, the AChild one of its TCustomPage. Both handles must already
be created. ANoteBook Handle is a PGtkNoteBook and APage handle is a
PGtkHBox.
This procedure creates a new tab with an optional image, the page caption and
an optional close button. The image and the caption will also be added to the
tab popup menu.
}
var
NoteBookWidget: PGtkWidget; // the notebook
PageWidget: PGtkWidget; // the page (content widget)
TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label
// and a close button)
TabLabelWidget: PGtkWidget; // the label in the tab
MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and
// a label)
MenuLabelWidget: PGtkWidget; // the label in the popup menu item
begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage ',dbgsName(ANoteBook),' ',ANotebook.HandleAllocated,' AChild=',dbgsName(AChild),' ',AChild.HandleAllocated,' Child.TabVisible=',AChild.TabVisible]);
{$ENDIF}
NoteBookWidget := PGtkWidget(ANoteBook.Handle);
PageWidget := PGtkWidget(AChild.Handle);
// set LCL size
AChild.SetBounds(AChild.Left, AChild.Top, ANotebook.ClientWidth, ANotebook.ClientHeight);
if AChild.TabVisible then
gtk_widget_show(PageWidget);
// Check if already created. if so just show it because it is invisible
if gtk_notebook_get_tab_label(PGtkNoteBook(NoteBookWidget), PageWidget) <> nil
then begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage already added']);
{$ENDIF}
exit;
end;
// create the tab (hbox container)
TabWidget := gtk_hbox_new(false, 1);
gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil);
// put a label into the tab
TabLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(TabWidget), 'TabLabel', TabLabelWidget);
gtk_widget_show(TabLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(TabWidget), TabLabelWidget);
if AChild.TabVisible then
gtk_widget_show(TabWidget);
// create popup menu item
MenuWidget := gtk_hbox_new(false, 2);
// set icon widget to nil
gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
// put a label into the menu
MenuLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget);
gtk_widget_show(MenuLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(MenuWidget), MenuLabelWidget);
if AChild.TabVisible then
gtk_widget_show(MenuWidget);
// remove the dummy page (a gtk_notebook needs at least one page)
RemoveDummyNoteBookPage(PGtkNotebook(NoteBookWidget));
// insert the page
gtk_notebook_insert_page_menu(PGtkNotebook(NotebookWidget), PageWidget,
TabWidget, MenuWidget, AIndex);
UpdateNotebookPageTab(ANoteBook, AChild);
UpdateNoteBookClientWidget(ANoteBook);
// init the size of the page widget
//DebugLn(['TGtkWSCustomNotebook.AddPage ',DbgSName(ANoteBook),' ',dbgs(ANoteBook.BoundsRect)]);
{$IFDEF VerboseSizeMsg}
DebugLn(['TGtkWSCustomNotebook.AddPage PageWidget^.allocation=',dbgs(PageWidget^.allocation),' NotebookWidget=',dbgs(NotebookWidget^.allocation)]);
{$ENDIF}
end;
class procedure TGtkWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
NoteBookWidget: PGtkNotebook;
begin
NoteBookWidget:=PGtkNotebook(ANoteBook.Handle);
gtk_notebook_reorder_child(NoteBookWidget, PGtkWidget(AChild.Handle), NewIndex);
UpdateNoteBookClientWidget(ANoteBook);
end;
class procedure TGtkWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
PageWidget: PGtkWidget;
Page: TCustomPage;
begin
// The gtk does not provide a function to remove a page without destroying it.
// Luckily the LCL destroys the Handle, when a page is removed, so this
// function is not needed.
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.RemovePage AIndex=',AIndex,' ',DbgSName(ANotebook.Page[AIndex])]);
{$ENDIF}
Page:=ANotebook.Page[AIndex];
if not Page.HandleAllocated then exit;
PageWidget := PGtkWidget(Page.Handle);
gtk_widget_hide(PageWidget);
end;
class function TGtkWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[nbcPageListPopup, nbcShowCloseButtons];
end;
class function TGtkWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
var
NBWidget: PGTKWidget;
BorderWidth: Integer;
{$IFDEF Gtk1}
Requisition: TGtkRequisition;
{$ENDIF}
Page: PGtkNotebookPage;
begin
Result:=inherited GetNotebookMinTabHeight(AWinControl);
//debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(Result));
exit;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(AWinControl.HandleAllocated));
if AWinControl.HandleAllocated then
NBWidget:=PGTKWidget(AWinControl.Handle)
else
NBWidget:=GetStyleWidget(lgsNotebook);
// ToDo: find out how to create a fully working hidden Notebook style widget
if (NBWidget=nil) then begin
Result:=TWSCustomNotebook.GetNotebookMinTabHeight(AWinControl);
exit;
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight NBWidget: ',GetWidgetDebugReport(NBWidget),
' ',dbgs(NBWidget^.allocation.width),'x',dbgs(NBWidget^.allocation.height));
BorderWidth:=(PGtkContainer(NBWidget)^.flag0 and bm_TGtkContainer_border_width)
shr bp_TGtkContainer_border_width;
if PGtkNoteBook(NBWidget)^.first_tab<>nil then
Page:=PGtkNoteBook(NBWidget)^.cur_page;
Result:=BorderWidth;
{$IFDEF GTK2}
if (Page<>nil) then begin
debugln('TGtkWSCustomNotebook.RemovePage TODO');
end;
{$ELSE GTK2}
if (NBWidget^.thestyle<>nil) and (PGtkStyle(NBWidget^.thestyle)^.klass<>nil) then
inc(Result,PGtkStyle(NBWidget^.thestyle)^.klass^.ythickness);
if (Page<>nil) and (Page^.child<>nil) then begin
gtk_widget_size_request(Page^.Child, @Requisition);
gtk_widget_map(Page^.child);
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight B ',dbgs(Page^.child^.allocation.height),
' ',GetWidgetDebugReport(Page^.child),' Requisition=',dbgs(Requisition.height));
inc(Result,Page^.child^.allocation.height);
end;
{$ENDIF GTK2}
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight END ',dbgs(Result),' ',
GetWidgetDebugReport(NBWidget));
end;
class function TGtkWSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
begin
Result:=TWSCustomNotebook.GetNotebookMinTabWidth(AWinControl);
end;
class function TGtkWSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
NoteBookWidget: PGtkNotebook;
i: integer;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
NotebookPos: TPoint;
{$IFDEF GTK2}
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
{$ENDIF}
Count: guint;
begin
Result:=-1;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
{$IFDEF GTK2}
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
NotebookPos.X:= AClientPos.X + (ClientOrg.X-WindowOrg.X);
NotebookPos.Y:= AClientPos.Y + (ClientOrg.Y-WindowOrg.Y);
{$ELSE}
NotebookPos:=AClientPos;
{$ENDIF}
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
for i:=0 to Count-1 do
begin
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget,i);
if PageWidget<>nil then
begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if (TabWidget<>nil) and GTK_WIDGET_MAPPED(TabWidget) then
begin
// test if position is in tabwidget
if (TabWidget^.Allocation.X<=NoteBookPos.X)
and (TabWidget^.Allocation.Y<=NoteBookPos.Y)
and (TabWidget^.Allocation.X+TabWidget^.Allocation.Width>NoteBookPos.X)
and (TabWidget^.Allocation.Y+TabWidget^.Allocation.Height>NoteBookPos.Y)
then begin
Result:=i;
exit;
end;
end;
end;
end;
end;
class function TGtkWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
NoteBookWidget: PGtkNotebook;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
{$IFDEF GTK2}
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
{$ENDIF}
XOffset, YOffset: Integer;
Count: guint;
begin
Result := inherited;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
{$IFDEF GTK2}
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
XOffset := (ClientOrg.X-WindowOrg.X);
YOffset := (ClientOrg.Y-WindowOrg.Y);
{$ELSE}
XOffset := 0;
YOffset := 0;
{$ENDIF}
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget, AIndex);
if (PageWidget<>nil) and (AIndex < Count) then begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if TabWidget<>nil then begin
Result.Top := TabWidget^.Allocation.Y - YOffset;
Result.Bottom := TabWidget^.Allocation.Y - YOffset + TabWidget^.Allocation.Height;
Result.Left := TabWidget^.Allocation.X - XOffset;
Result.right := TabWidget^.Allocation.X - XOffset + TabWidget^.Allocation.Width;
exit;
end;
end;
end;
class procedure TGtkWSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
GtkNotebook: PGtkNotebook;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
GtkNotebook := PGtkNoteBook(ANotebook.Handle);
if gtk_notebook_get_current_page(GtkNotebook) <> AIndex then
begin
gtk_object_set_data(PGtkObject(GtkNotebook), LCL_NotebookManualPageSwitchKey, ANotebook);
gtk_notebook_set_page(GtkNotebook, AIndex);
end;
UpdateNoteBookClientWidget(ANotebook);
end;
class procedure TGtkWSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
gtk_notebook_set_tab_pos(PGtkNotebook(ANotebook.Handle),
GtkPositionTypeMap[ATabPosition]);
end;
class procedure TGtkWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
gtk_notebook_set_show_tabs(PGtkNotebook(ANotebook.Handle), AShowTabs);
end;
class procedure TGtkWSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
if (nboHidePageListPopup in ANoteBook.Options) then
gtk_notebook_popup_disable(PGtkNotebook(ANoteBook.Handle))
else
gtk_notebook_popup_enable(PGtkNotebook(ANoteBook.Handle));
end;
class procedure TGtkWSCustomPanel.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin

View File

@ -0,0 +1,550 @@
{%MainUnit gtk2wscomctrls.pp}
{
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, 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. *
* *
*****************************************************************************
}
const
GtkPositionTypeMap: array[TTabPosition] of TGtkPositionType =
(
{ tpTop } GTK_POS_TOP,
{ tpBottom } GTK_POS_BOTTOM,
{ tpLeft } GTK_POS_LEFT,
{ tpRight } GTK_POS_RIGHT
);
LCL_NotebookManualPageSwitchKey = 'lcl_manual_page_switch';
type
GtkNotebookPressEventProc = function (widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl;
var
OldNoteBookButtonPress: GtkNotebookPressEventProc = nil;
// this was created as a workaround of a tnotebook eating rightclick of custom controls
function Notebook_Button_Press(widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl;
begin
Result := True;
if gtk_get_event_widget(PGdkEvent(event)) <> widget then exit;
if OldNoteBookButtonPress = nil then exit;
Result := OldNoteBookButtonPress(widget, event);
end;
procedure HookNoteBookClass;
var
WidgetClass: PGtkWidgetClass;
begin
WidgetClass := GTK_WIDGET_CLASS(gtk_type_class(gtk_notebook_get_type));
OldNoteBookButtonPress := GtkNotebookPressEventProc(WidgetClass^.button_press_event);
WidgetClass^.button_press_event := @Notebook_Button_Press;
end;
{ TGtk2WSCustomNotebook }
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;
function GtkWSNotebook_AfterSwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
begin
// then send the new page
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGE;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
DeliverMessage(Data, Mess);
end;
function GtkWSNotebook_SwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
IsManual: Boolean;
begin
Result := CallBackDefaultReturn;
EventTrace('switch-page', data);
UpdateNoteBookClientWidget(TObject(Data));
// remove flag
IsManual := gtk_object_get_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey) <> nil;
if IsManual then
gtk_object_set_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey, nil);
if PGtkNotebook(Widget)^.cur_page = nil then // for windows compatibility
Exit;
// gtkswitchpage is called before the switch
if not IsManual then
begin
// send first the TCN_SELCHANGING to ask if switch is allowed
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGING;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
Mess.Result := 0;
DeliverMessage(Data, Mess);
if Mess.Result <> 0 then
begin
g_signal_stop_emission_by_name(PGtkObject(Widget), 'switch-page');
Result := not CallBackDefaultReturn;
Exit;
end;
end;
end;
class procedure TGtk2WSCustomNotebook.SetCallbacks(
const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
ConnectSignal(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_SwitchPage, AWidgetInfo^.LCLObject);
ConnectSignalAfter(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_AfterSwitchPage, AWidgetInfo^.LCLObject);
end;
class function TGtk2WSCustomNotebook.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
AWidget: PGtkNoteBook;
WidgetInfo: PWidgetInfo;
begin
if OldNoteBookButtonPress = nil then
HookNoteBookClass;
//DebugLn(['TGtk2WSCustomNotebook.CreateHandle ',DbgSName(AWinControl)]);
AWidget := PGtkNoteBook(gtk_notebook_new());
WidgetInfo := CreateWidgetInfo(AWidget, AWinControl, AParams);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(AWidget), dbgsName(AWinControl));
{$ENDIF}
gtk_notebook_set_scrollable(AWidget, True);
if not (nboHidePageListPopup in TCustomNotebook(AWinControl).Options) then
gtk_notebook_popup_enable(AWidget);
if TCustomNotebook(AWinControl).PageCount=0 then
// a gtk notebook needs a page -> add dummy page
Gtk2WidgetSet.AddDummyNoteBookPage(AWidget);
gtk_notebook_set_tab_pos(AWidget, GtkPositionTypeMap[TCustomNotebook(AWinControl).TabPosition]);
Result := HWND(TLCLIntfHandle(PtrUInt(AWidget)));
Set_RC_Name(AWinControl, PGtkWidget(AWidget));
SetCallBacks(PGtkWidget(AWidget), WidgetInfo);
end;
class function TGtk2WSCustomNotebook.GetDefaultClientRect(
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
var aClientRect: TRect): boolean;
var
FrameBorders: TRect;
begin
Result:=false;
//DebugLn(['TGtk2WSCustomNotebook.GetDefaultClientRect ',DbgSName(AWinControl),' ',aWidth,'x',aHeight]);
if AWinControl.HandleAllocated then begin
end else begin
FrameBorders:=GetStyleNotebookFrameBorders;
aClientRect:=Rect(0,0,
Max(0,aWidth-FrameBorders.Left-FrameBorders.Right),
Max(0,aHeight-FrameBorders.Top-FrameBorders.Bottom));
Result:=true;
end;
{$IFDEF VerboseSizeMsg}
if Result then DebugLn(['TGtk2WSCustomNotebook.GetDefaultClientRect END FrameBorders=',dbgs(FrameBorders),' aClientRect=',dbgs(aClientRect)]);
{$ENDIF}
end;
class procedure TGtk2WSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
{
Inserts a new page to a notebook at position Index. The ANotebook is a
TCustomNoteBook, the AChild one of its TCustomPage. Both handles must already
be created. ANoteBook Handle is a PGtkNoteBook and APage handle is a
PGtkHBox.
This procedure creates a new tab with an optional image, the page caption and
an optional close button. The image and the caption will also be added to the
tab popup menu.
}
var
NoteBookWidget: PGtkWidget; // the notebook
PageWidget: PGtkWidget; // the page (content widget)
TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label
// and a close button)
TabLabelWidget: PGtkWidget; // the label in the tab
MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and
// a label)
MenuLabelWidget: PGtkWidget; // the label in the popup menu item
begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage ',dbgsName(ANoteBook),' ',ANotebook.HandleAllocated,' AChild=',dbgsName(AChild),' ',AChild.HandleAllocated,' Child.TabVisible=',AChild.TabVisible]);
{$ENDIF}
NoteBookWidget := PGtkWidget(ANoteBook.Handle);
PageWidget := PGtkWidget(AChild.Handle);
// set LCL size
AChild.SetBounds(AChild.Left, AChild.Top, ANotebook.ClientWidth, ANotebook.ClientHeight);
if AChild.TabVisible then
gtk_widget_show(PageWidget);
// Check if already created. if so just show it because it is invisible
if gtk_notebook_get_tab_label(PGtkNoteBook(NoteBookWidget), PageWidget) <> nil
then begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage already added']);
{$ENDIF}
exit;
end;
// create the tab (hbox container)
TabWidget := gtk_hbox_new(false, 1);
gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil);
// put a label into the tab
TabLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(TabWidget), 'TabLabel', TabLabelWidget);
gtk_widget_show(TabLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(TabWidget), TabLabelWidget);
if AChild.TabVisible then
gtk_widget_show(TabWidget);
// create popup menu item
MenuWidget := gtk_hbox_new(false, 2);
// set icon widget to nil
gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
// put a label into the menu
MenuLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget);
gtk_widget_show(MenuLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(MenuWidget), MenuLabelWidget);
if AChild.TabVisible then
gtk_widget_show(MenuWidget);
// remove the dummy page (a gtk_notebook needs at least one page)
RemoveDummyNoteBookPage(PGtkNotebook(NoteBookWidget));
// insert the page
gtk_notebook_insert_page_menu(PGtkNotebook(NotebookWidget), PageWidget,
TabWidget, MenuWidget, AIndex);
UpdateNotebookPageTab(ANoteBook, AChild);
UpdateNoteBookClientWidget(ANoteBook);
// init the size of the page widget
//DebugLn(['TGtkWSCustomNotebook.AddPage ',DbgSName(ANoteBook),' ',dbgs(ANoteBook.BoundsRect)]);
{$IFDEF VerboseSizeMsg}
DebugLn(['TGtkWSCustomNotebook.AddPage PageWidget^.allocation=',dbgs(PageWidget^.allocation),' NotebookWidget=',dbgs(NotebookWidget^.allocation)]);
{$ENDIF}
end;
class procedure TGtk2WSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
NoteBookWidget: PGtkNotebook;
begin
NoteBookWidget:=PGtkNotebook(ANoteBook.Handle);
gtk_notebook_reorder_child(NoteBookWidget, PGtkWidget(AChild.Handle), NewIndex);
UpdateNoteBookClientWidget(ANoteBook);
end;
class procedure TGtk2WSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
PageWidget: PGtkWidget;
Page: TCustomPage;
begin
// The gtk does not provide a function to remove a page without destroying it.
// Luckily the LCL destroys the Handle, when a page is removed, so this
// function is not needed.
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.RemovePage AIndex=',AIndex,' ',DbgSName(ANotebook.Page[AIndex])]);
{$ENDIF}
Page:=ANotebook.Page[AIndex];
if not Page.HandleAllocated then exit;
PageWidget := PGtkWidget(Page.Handle);
gtk_widget_hide(PageWidget);
end;
class function TGtk2WSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[nbcPageListPopup, nbcShowCloseButtons];
end;
class function TGtk2WSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
var
NBWidget: PGTKWidget;
BorderWidth: Integer;
Page: PGtkNotebookPage;
begin
Result:=inherited GetNotebookMinTabHeight(AWinControl);
//debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(Result));
exit;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(AWinControl.HandleAllocated));
if AWinControl.HandleAllocated then
NBWidget:=PGTKWidget(AWinControl.Handle)
else
NBWidget:=GetStyleWidget(lgsNotebook);
// ToDo: find out how to create a fully working hidden Notebook style widget
if (NBWidget=nil) then begin
Result:=TWSCustomNotebook.GetNotebookMinTabHeight(AWinControl);
exit;
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight NBWidget: ',GetWidgetDebugReport(NBWidget),
' ',dbgs(NBWidget^.allocation.width),'x',dbgs(NBWidget^.allocation.height));
BorderWidth:=(PGtkContainer(NBWidget)^.flag0 and bm_TGtkContainer_border_width)
shr bp_TGtkContainer_border_width;
if PGtkNoteBook(NBWidget)^.first_tab<>nil then
Page:=PGtkNoteBook(NBWidget)^.cur_page;
Result:=BorderWidth;
if (Page<>nil) then begin
debugln('TGtkWSCustomNotebook.RemovePage TODO');
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight END ',dbgs(Result),' ',
GetWidgetDebugReport(NBWidget));
end;
class function TGtk2WSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
begin
Result:=TWSCustomNotebook.GetNotebookMinTabWidth(AWinControl);
end;
class function TGtk2WSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
NoteBookWidget: PGtkNotebook;
i: integer;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
NotebookPos: TPoint;
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
Count: guint;
begin
Result:=-1;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
NotebookPos.X:= AClientPos.X + (ClientOrg.X-WindowOrg.X);
NotebookPos.Y:= AClientPos.Y + (ClientOrg.Y-WindowOrg.Y);
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
for i:=0 to Count-1 do
begin
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget,i);
if PageWidget<>nil then
begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if (TabWidget<>nil) and GTK_WIDGET_MAPPED(TabWidget) then
begin
// test if position is in tabwidget
if (TabWidget^.Allocation.X<=NoteBookPos.X)
and (TabWidget^.Allocation.Y<=NoteBookPos.Y)
and (TabWidget^.Allocation.X+TabWidget^.Allocation.Width>NoteBookPos.X)
and (TabWidget^.Allocation.Y+TabWidget^.Allocation.Height>NoteBookPos.Y)
then begin
Result:=i;
exit;
end;
end;
end;
end;
end;
class function TGtk2WSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
NoteBookWidget: PGtkNotebook;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
Count: guint;
begin
Result := inherited;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
Count := g_list_length(NoteBookWidget^.Children);
PageWidget := gtk_notebook_get_nth_page(NoteBookWidget, AIndex);
if (PageWidget<>nil) and (AIndex < Count) then
begin
TabWidget := gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if TabWidget <> nil then
Result := RectFromGdkRect(TabWidget^.allocation);
end;
end;
class procedure TGtk2WSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
GtkNotebook: PGtkNotebook;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
GtkNotebook := PGtkNoteBook(ANotebook.Handle);
if gtk_notebook_get_current_page(GtkNotebook) <> AIndex then
begin
gtk_object_set_data(PGtkObject(GtkNotebook), LCL_NotebookManualPageSwitchKey, ANotebook);
gtk_notebook_set_page(GtkNotebook, AIndex);
end;
UpdateNoteBookClientWidget(ANotebook);
end;
class procedure TGtk2WSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
gtk_notebook_set_tab_pos(PGtkNotebook(ANotebook.Handle),
GtkPositionTypeMap[ATabPosition]);
end;
class procedure TGtk2WSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
gtk_notebook_set_show_tabs(PGtkNotebook(ANotebook.Handle), AShowTabs);
end;
class procedure TGtk2WSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
if (nboHidePageListPopup in ANoteBook.Options) then
gtk_notebook_popup_disable(PGtkNotebook(ANoteBook.Handle))
else
gtk_notebook_popup_enable(PGtkNotebook(ANoteBook.Handle));
end;
{ TGtk2WSCustomPage }
class procedure TGtk2WSCustomPage.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtk2WSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
Widget := Gtk2Widgetset.CreateSimpleClientAreaWidget(AWinControl, True);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(Widget));
WidgetInfo := GetWidgetInfo(Widget);
WidgetInfo^.LCLObject := AWinControl;
WidgetInfo^.Style := AParams.Style;
WidgetInfo^.ExStyle := AParams.ExStyle;
WidgetInfo^.WndProc := PtrUInt(AParams.WindowClass.lpfnWndProc);
Set_RC_Name(AWinControl, Widget);
SetCallBacks(Widget, WidgetInfo);
end;
class procedure TGtk2WSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
var
NoteBook: PGtkWidget;
PageWidget: PGtkWidget;
TabWidget: PGtkWidget;
TabImageWidget: PGtkWidget;
begin
UpdateNotebookPageTab(nil, ACustomPage);
{we must update our icon (if exists) otherwise it will be updated only
when our tab reach focus}
if not (csDesigning in ACustomPage.ComponentState)
and not ACustomPage.TabVisible
or not ACustomPage.HandleAllocated
or not Assigned(ACustomPage.Parent)
then
exit;
PageWidget := PGtkWidget(ACustomPage.Handle);
NoteBook := PGtkWidget(ACustomPage.Parent.Handle);
if (NoteBook = nil) or not GTK_IS_NOTEBOOK(NoteBook) then
exit;
TabWidget := gtk_notebook_get_tab_label(PGtkNoteBook(Notebook), PageWidget);
if (TabWidget = nil) or not GTK_WIDGET_VISIBLE(TabWidget) then
exit;
TabImageWidget := gtk_object_get_data(PGtkObject(TabWidget), 'TabImage');
if TabImageWidget <> nil then
gtk_widget_queue_draw(TabImageWidget);
end;
class procedure TGtk2WSCustomPage.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
// ignore resizes from the LCL
end;
class procedure TGtk2WSCustomPage.ShowHide(const AWinControl: TWinControl);
begin
if (csDesigning in AWinControl.ComponentState) then
TGtk2WidgetSet(WidgetSet).SetVisible(AWinControl,
AWinControl.HandleObjectShouldBeVisible)
else
TGtk2WidgetSet(WidgetSet).SetVisible(AWinControl,
TCustomPage(AWinControl).TabVisible);
end;
class function TGtk2WSCustomPage.GetDefaultClientRect(
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
var aClientRect: TRect): boolean;
begin
Result:=false;
if AWinControl.Parent=nil then exit;
if AWinControl.HandleAllocated and AWinControl.Parent.HandleAllocated
and (PGtkWidget(AWinControl.Handle)^.parent<>nil) then
begin
end else begin
Result:=true;
aClientRect:=AWinControl.Parent.ClientRect;
//DebugLn(['TGtk2WSCustomPage.GetDefaultClientRect ',DbgSName(AWinControl),' Parent=',DbgSName(AWinControl.Parent),' ParentBounds=',dbgs(AWinControl.Parent.BoundsRect),' ParentClient=',dbgs(AWinControl.Parent.ClientRect)]);
end;
{$IFDEF VerboseSizeMsg}
if Result then DebugLn(['TGtk2WSCustomPage.GetDefaultClientRect ',DbgSName(AWinControl),' aClientRect=',dbgs(aClientRect)]);
{$ENDIF}
end;

View File

@ -57,6 +57,50 @@ type
end;
type
{ TGtk2WSCustomPage }
TGtk2WSCustomPage = class(TWSCustomPage)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure ShowHide(const AWinControl: TWinControl); override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
end;
{ TGtk2WSCustomNotebook }
TGtk2WSCustomNotebook = class(TWSCustomNotebook)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; 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;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TGtk2WSStatusBar }
@ -240,6 +284,8 @@ implementation
uses Gtk2CellRenderer, Gtk2Extra{$IFNDEF USEORIGTREEMODEL}, Gtk2ListViewTreeModel{$ENDIF};
{$I gtk2pagecontrol.inc}
// Will be used commonly for ListViews and TreeViews
procedure GetCommonTreeViewWidgets(ATreeViewHandle: PGtkWidget;
var TVWidgets: PTVWidgets);

View File

@ -41,51 +41,6 @@ uses
type
{ TGtk2WSCustomPage }
TGtk2WSCustomPage = class(TWSCustomPage)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure ShowHide(const AWinControl: TWinControl); override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
end;
{ TGtk2WSCustomNotebook }
TGtk2WSCustomNotebook = class(TWSCustomNotebook)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const aLeft, aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; 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;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TGtk2WSPage }
TGtk2WSPage = class(TWSPage)
@ -222,542 +177,6 @@ uses
{$endif}
interfacebase;
const
GtkPositionTypeMap: array[TTabPosition] of TGtkPositionType =
(
{ tpTop } GTK_POS_TOP,
{ tpBottom } GTK_POS_BOTTOM,
{ tpLeft } GTK_POS_LEFT,
{ tpRight } GTK_POS_RIGHT
);
LCL_NotebookManualPageSwitchKey = 'lcl_manual_page_switch';
type
GtkNotebookPressEventProc = function (widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl;
var
OldNoteBookButtonPress: GtkNotebookPressEventProc = nil;
// this was created as a workaround of a tnotebook eating rightclick of custom controls
function Notebook_Button_Press(widget:PGtkWidget; event:PGdkEventButton):gboolean; cdecl;
begin
Result := True;
if gtk_get_event_widget(PGdkEvent(event)) <> widget then exit;
if OldNoteBookButtonPress = nil then exit;
Result := OldNoteBookButtonPress(widget, event);
end;
procedure HookNoteBookClass;
var
WidgetClass: PGtkWidgetClass;
begin
WidgetClass := GTK_WIDGET_CLASS(gtk_type_class(gtk_notebook_get_type));
OldNoteBookButtonPress := GtkNotebookPressEventProc(WidgetClass^.button_press_event);
WidgetClass^.button_press_event := @Notebook_Button_Press;
end;
{ TGtk2WSCustomNotebook }
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;
function GtkWSNotebook_AfterSwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
begin
// then send the new page
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGE;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
DeliverMessage(Data, Mess);
end;
function GtkWSNotebook_SwitchPage(widget: PGtkWidget; page: Pgtkwidget; pagenum: integer; data: gPointer): GBoolean; cdecl;
var
Mess: TLMNotify;
NMHdr: tagNMHDR;
IsManual: Boolean;
begin
Result := CallBackDefaultReturn;
EventTrace('switch-page', data);
UpdateNoteBookClientWidget(TObject(Data));
// remove flag
IsManual := gtk_object_get_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey) <> nil;
if IsManual then
gtk_object_set_data(PGtkObject(Widget), LCL_NotebookManualPageSwitchKey, nil);
if PGtkNotebook(Widget)^.cur_page = nil then // for windows compatibility
Exit;
// gtkswitchpage is called before the switch
if not IsManual then
begin
// send first the TCN_SELCHANGING to ask if switch is allowed
FillChar(Mess, SizeOf(Mess), 0);
Mess.Msg := LM_NOTIFY;
FillChar(NMHdr, SizeOf(NMHdr), 0);
NMHdr.code := TCN_SELCHANGING;
NMHdr.hwndFrom := PtrUInt(widget);
NMHdr.idFrom := NotebookPageRealToLCLIndex(TCustomNotebook(Data), pagenum); //use this to set pageindex to the correct page.
Mess.NMHdr := @NMHdr;
Mess.Result := 0;
DeliverMessage(Data, Mess);
if Mess.Result <> 0 then
begin
g_signal_stop_emission_by_name(PGtkObject(Widget), 'switch-page');
Result := not CallBackDefaultReturn;
Exit;
end;
end;
end;
class procedure TGtk2WSCustomNotebook.SetCallbacks(
const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
ConnectSignal(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_SwitchPage, AWidgetInfo^.LCLObject);
ConnectSignalAfter(PGtkObject(AGtkWidget), 'switch_page', @GtkWSNotebook_AfterSwitchPage, AWidgetInfo^.LCLObject);
end;
class function TGtk2WSCustomNotebook.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
AWidget: PGtkNoteBook;
WidgetInfo: PWidgetInfo;
begin
if OldNoteBookButtonPress = nil then
HookNoteBookClass;
//DebugLn(['TGtk2WSCustomNotebook.CreateHandle ',DbgSName(AWinControl)]);
AWidget := PGtkNoteBook(gtk_notebook_new());
WidgetInfo := CreateWidgetInfo(AWidget, AWinControl, AParams);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Pointer(AWidget), dbgsName(AWinControl));
{$ENDIF}
gtk_notebook_set_scrollable(AWidget, True);
if not (nboHidePageListPopup in TCustomNotebook(AWinControl).Options) then
gtk_notebook_popup_enable(AWidget);
if TCustomNotebook(AWinControl).PageCount=0 then
// a gtk notebook needs a page -> add dummy page
Gtk2WidgetSet.AddDummyNoteBookPage(AWidget);
gtk_notebook_set_tab_pos(AWidget, GtkPositionTypeMap[TCustomNotebook(AWinControl).TabPosition]);
Result := HWND(TLCLIntfHandle(PtrUInt(AWidget)));
Set_RC_Name(AWinControl, PGtkWidget(AWidget));
SetCallBacks(PGtkWidget(AWidget), WidgetInfo);
end;
class function TGtk2WSCustomNotebook.GetDefaultClientRect(
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
var aClientRect: TRect): boolean;
var
FrameBorders: TRect;
begin
Result:=false;
//DebugLn(['TGtk2WSCustomNotebook.GetDefaultClientRect ',DbgSName(AWinControl),' ',aWidth,'x',aHeight]);
if AWinControl.HandleAllocated then begin
end else begin
FrameBorders:=GetStyleNotebookFrameBorders;
aClientRect:=Rect(0,0,
Max(0,aWidth-FrameBorders.Left-FrameBorders.Right),
Max(0,aHeight-FrameBorders.Top-FrameBorders.Bottom));
Result:=true;
end;
{$IFDEF VerboseSizeMsg}
if Result then DebugLn(['TGtk2WSCustomNotebook.GetDefaultClientRect END FrameBorders=',dbgs(FrameBorders),' aClientRect=',dbgs(aClientRect)]);
{$ENDIF}
end;
class procedure TGtk2WSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
{
Inserts a new page to a notebook at position Index. The ANotebook is a
TCustomNoteBook, the AChild one of its TCustomPage. Both handles must already
be created. ANoteBook Handle is a PGtkNoteBook and APage handle is a
PGtkHBox.
This procedure creates a new tab with an optional image, the page caption and
an optional close button. The image and the caption will also be added to the
tab popup menu.
}
var
NoteBookWidget: PGtkWidget; // the notebook
PageWidget: PGtkWidget; // the page (content widget)
TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label
// and a close button)
TabLabelWidget: PGtkWidget; // the label in the tab
MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and
// a label)
MenuLabelWidget: PGtkWidget; // the label in the popup menu item
begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage ',dbgsName(ANoteBook),' ',ANotebook.HandleAllocated,' AChild=',dbgsName(AChild),' ',AChild.HandleAllocated,' Child.TabVisible=',AChild.TabVisible]);
{$ENDIF}
NoteBookWidget := PGtkWidget(ANoteBook.Handle);
PageWidget := PGtkWidget(AChild.Handle);
// set LCL size
AChild.SetBounds(AChild.Left, AChild.Top, ANotebook.ClientWidth, ANotebook.ClientHeight);
if AChild.TabVisible then
gtk_widget_show(PageWidget);
// Check if already created. if so just show it because it is invisible
if gtk_notebook_get_tab_label(PGtkNoteBook(NoteBookWidget), PageWidget) <> nil
then begin
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.AddPage already added']);
{$ENDIF}
exit;
end;
// create the tab (hbox container)
TabWidget := gtk_hbox_new(false, 1);
gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil);
// put a label into the tab
TabLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(TabWidget), 'TabLabel', TabLabelWidget);
gtk_widget_show(TabLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(TabWidget), TabLabelWidget);
if AChild.TabVisible then
gtk_widget_show(TabWidget);
// create popup menu item
MenuWidget := gtk_hbox_new(false, 2);
// set icon widget to nil
gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
// put a label into the menu
MenuLabelWidget := gtk_label_new('');
gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget);
gtk_widget_show(MenuLabelWidget);
gtk_box_pack_start_defaults(PGtkBox(MenuWidget), MenuLabelWidget);
if AChild.TabVisible then
gtk_widget_show(MenuWidget);
// remove the dummy page (a gtk_notebook needs at least one page)
RemoveDummyNoteBookPage(PGtkNotebook(NoteBookWidget));
// insert the page
gtk_notebook_insert_page_menu(PGtkNotebook(NotebookWidget), PageWidget,
TabWidget, MenuWidget, AIndex);
UpdateNotebookPageTab(ANoteBook, AChild);
UpdateNoteBookClientWidget(ANoteBook);
// init the size of the page widget
//DebugLn(['TGtkWSCustomNotebook.AddPage ',DbgSName(ANoteBook),' ',dbgs(ANoteBook.BoundsRect)]);
{$IFDEF VerboseSizeMsg}
DebugLn(['TGtkWSCustomNotebook.AddPage PageWidget^.allocation=',dbgs(PageWidget^.allocation),' NotebookWidget=',dbgs(NotebookWidget^.allocation)]);
{$ENDIF}
end;
class procedure TGtk2WSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
NoteBookWidget: PGtkNotebook;
begin
NoteBookWidget:=PGtkNotebook(ANoteBook.Handle);
gtk_notebook_reorder_child(NoteBookWidget, PGtkWidget(AChild.Handle), NewIndex);
UpdateNoteBookClientWidget(ANoteBook);
end;
class procedure TGtk2WSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
PageWidget: PGtkWidget;
Page: TCustomPage;
begin
// The gtk does not provide a function to remove a page without destroying it.
// Luckily the LCL destroys the Handle, when a page is removed, so this
// function is not needed.
{$IFDEF NOTEBOOK_DEBUG}
DebugLn(['TGtkWSCustomNotebook.RemovePage AIndex=',AIndex,' ',DbgSName(ANotebook.Page[AIndex])]);
{$ENDIF}
Page:=ANotebook.Page[AIndex];
if not Page.HandleAllocated then exit;
PageWidget := PGtkWidget(Page.Handle);
gtk_widget_hide(PageWidget);
end;
class function TGtk2WSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[nbcPageListPopup, nbcShowCloseButtons];
end;
class function TGtk2WSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
var
NBWidget: PGTKWidget;
BorderWidth: Integer;
Page: PGtkNotebookPage;
begin
Result:=inherited GetNotebookMinTabHeight(AWinControl);
//debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(Result));
exit;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight A ',dbgs(AWinControl.HandleAllocated));
if AWinControl.HandleAllocated then
NBWidget:=PGTKWidget(AWinControl.Handle)
else
NBWidget:=GetStyleWidget(lgsNotebook);
// ToDo: find out how to create a fully working hidden Notebook style widget
if (NBWidget=nil) then begin
Result:=TWSCustomNotebook.GetNotebookMinTabHeight(AWinControl);
exit;
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight NBWidget: ',GetWidgetDebugReport(NBWidget),
' ',dbgs(NBWidget^.allocation.width),'x',dbgs(NBWidget^.allocation.height));
BorderWidth:=(PGtkContainer(NBWidget)^.flag0 and bm_TGtkContainer_border_width)
shr bp_TGtkContainer_border_width;
if PGtkNoteBook(NBWidget)^.first_tab<>nil then
Page:=PGtkNoteBook(NBWidget)^.cur_page;
Result:=BorderWidth;
if (Page<>nil) then begin
debugln('TGtkWSCustomNotebook.RemovePage TODO');
end;
debugln('TGtkWSCustomNotebook.GetNotebookMinTabHeight END ',dbgs(Result),' ',
GetWidgetDebugReport(NBWidget));
end;
class function TGtk2WSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
begin
Result:=TWSCustomNotebook.GetNotebookMinTabWidth(AWinControl);
end;
class function TGtk2WSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
NoteBookWidget: PGtkNotebook;
i: integer;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
NotebookPos: TPoint;
Window: PGdkWindow;
WindowOrg,ClientOrg: TPoint;
Count: guint;
begin
Result:=-1;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
//DebugLn(['TGtkWSCustomNotebook.GetTabIndexAtPos ',GetWidgetDebugReport(PGtkWidget(NotebookWidget))]);
Window := GetControlWindow(NoteBookWidget);
gdk_window_get_origin(Window,@WindowOrg.X,@WindowOrg.Y);
ClientOrg:=GetWidgetClientOrigin(PGtkWidget(NotebookWidget));
NotebookPos.X:= AClientPos.X + (ClientOrg.X-WindowOrg.X);
NotebookPos.Y:= AClientPos.Y + (ClientOrg.Y-WindowOrg.Y);
// go through all tabs
Count:=g_list_length(NoteBookWidget^.Children);
for i:=0 to Count-1 do
begin
PageWidget:=gtk_notebook_get_nth_page(NoteBookWidget,i);
if PageWidget<>nil then
begin
TabWidget:=gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if (TabWidget<>nil) and GTK_WIDGET_MAPPED(TabWidget) then
begin
// test if position is in tabwidget
if (TabWidget^.Allocation.X<=NoteBookPos.X)
and (TabWidget^.Allocation.Y<=NoteBookPos.Y)
and (TabWidget^.Allocation.X+TabWidget^.Allocation.Width>NoteBookPos.X)
and (TabWidget^.Allocation.Y+TabWidget^.Allocation.Height>NoteBookPos.Y)
then begin
Result:=i;
exit;
end;
end;
end;
end;
end;
class function TGtk2WSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
NoteBookWidget: PGtkNotebook;
TabWidget: PGtkWidget;
PageWidget: PGtkWidget;
Count: guint;
begin
Result := inherited;
NoteBookWidget:=PGtkNotebook(ANotebook.Handle);
if (NotebookWidget=nil) then exit;
Count := g_list_length(NoteBookWidget^.Children);
PageWidget := gtk_notebook_get_nth_page(NoteBookWidget, AIndex);
if (PageWidget<>nil) and (AIndex < Count) then
begin
TabWidget := gtk_notebook_get_tab_label(NoteBookWidget, PageWidget);
if TabWidget <> nil then
Result := RectFromGdkRect(TabWidget^.allocation);
end;
end;
class procedure TGtk2WSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
GtkNotebook: PGtkNotebook;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
GtkNotebook := PGtkNoteBook(ANotebook.Handle);
if gtk_notebook_get_current_page(GtkNotebook) <> AIndex then
begin
gtk_object_set_data(PGtkObject(GtkNotebook), LCL_NotebookManualPageSwitchKey, ANotebook);
gtk_notebook_set_page(GtkNotebook, AIndex);
end;
UpdateNoteBookClientWidget(ANotebook);
end;
class procedure TGtk2WSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
gtk_notebook_set_tab_pos(PGtkNotebook(ANotebook.Handle),
GtkPositionTypeMap[ATabPosition]);
end;
class procedure TGtk2WSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
gtk_notebook_set_show_tabs(PGtkNotebook(ANotebook.Handle), AShowTabs);
end;
class procedure TGtk2WSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
if (nboHidePageListPopup in ANoteBook.Options) then
gtk_notebook_popup_disable(PGtkNotebook(ANoteBook.Handle))
else
gtk_notebook_popup_enable(PGtkNotebook(ANoteBook.Handle));
end;
{ TGtk2WSCustomPage }
class procedure TGtk2WSCustomPage.SetCallbacks(const AGtkWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtk2WSWinControl.SetCallbacks(PGtkObject(AGtkWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtk2WSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
Widget := Gtk2Widgetset.CreateSimpleClientAreaWidget(AWinControl, True);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
Result := TLCLIntfHandle(PtrUInt(Widget));
WidgetInfo := GetWidgetInfo(Widget);
WidgetInfo^.LCLObject := AWinControl;
WidgetInfo^.Style := AParams.Style;
WidgetInfo^.ExStyle := AParams.ExStyle;
WidgetInfo^.WndProc := PtrUInt(AParams.WindowClass.lpfnWndProc);
Set_RC_Name(AWinControl, Widget);
SetCallBacks(Widget, WidgetInfo);
end;
class procedure TGtk2WSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
var
NoteBook: PGtkWidget;
PageWidget: PGtkWidget;
TabWidget: PGtkWidget;
TabImageWidget: PGtkWidget;
begin
UpdateNotebookPageTab(nil, ACustomPage);
{we must update our icon (if exists) otherwise it will be updated only
when our tab reach focus}
if not (csDesigning in ACustomPage.ComponentState)
and not ACustomPage.TabVisible
or not ACustomPage.HandleAllocated
or not Assigned(ACustomPage.Parent)
then
exit;
PageWidget := PGtkWidget(ACustomPage.Handle);
NoteBook := PGtkWidget(ACustomPage.Parent.Handle);
if (NoteBook = nil) or not GTK_IS_NOTEBOOK(NoteBook) then
exit;
TabWidget := gtk_notebook_get_tab_label(PGtkNoteBook(Notebook), PageWidget);
if (TabWidget = nil) or not GTK_WIDGET_VISIBLE(TabWidget) then
exit;
TabImageWidget := gtk_object_get_data(PGtkObject(TabWidget), 'TabImage');
if TabImageWidget <> nil then
gtk_widget_queue_draw(TabImageWidget);
end;
class procedure TGtk2WSCustomPage.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
// ignore resizes from the LCL
end;
class procedure TGtk2WSCustomPage.ShowHide(const AWinControl: TWinControl);
begin
if (csDesigning in AWinControl.ComponentState) then
TGtk2WidgetSet(WidgetSet).SetVisible(AWinControl,
AWinControl.HandleObjectShouldBeVisible)
else
TGtk2WidgetSet(WidgetSet).SetVisible(AWinControl,
TCustomPage(AWinControl).TabVisible);
end;
class function TGtk2WSCustomPage.GetDefaultClientRect(
const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
var aClientRect: TRect): boolean;
begin
Result:=false;
if AWinControl.Parent=nil then exit;
if AWinControl.HandleAllocated and AWinControl.Parent.HandleAllocated
and (PGtkWidget(AWinControl.Handle)^.parent<>nil) then
begin
end else begin
Result:=true;
aClientRect:=AWinControl.Parent.ClientRect;
//DebugLn(['TGtk2WSCustomPage.GetDefaultClientRect ',DbgSName(AWinControl),' Parent=',DbgSName(AWinControl.Parent),' ParentBounds=',dbgs(AWinControl.Parent.BoundsRect),' ParentClient=',dbgs(AWinControl.Parent.ClientRect)]);
end;
{$IFDEF VerboseSizeMsg}
if Result then DebugLn(['TGtk2WSCustomPage.GetDefaultClientRect ',DbgSName(AWinControl),' aClientRect=',dbgs(aClientRect)]);
{$ENDIF}
end;
{ TGtk2WSCustomPanel }
class procedure TGtk2WSCustomPanel.SetCallbacks(const AGtkWidget: PGtkWidget;

View File

@ -0,0 +1,272 @@
{%MainUnit qtwscomctrls.pp}
{
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, 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. *
* *
*****************************************************************************
}
const
QTabWidgetTabPositionMap: array[TTabPosition] of QTabWidgetTabPosition =
(
{ tpTop } QTabWidgetNorth,
{ tpBottom } QTabWidgetSouth,
{ tpLeft } QTabWidgetWest,
{ tpRight } QTabWidgetEast
);
{ TQtWSCustomPage }
{------------------------------------------------------------------------------
Method: TQtWSCustomPage.CreateHandle
Params: None
Returns: Nothing
Allocates memory and resources for the control and shows it
------------------------------------------------------------------------------}
class function TQtWSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
QtPage: TQtPage;
begin
{$ifdef VerboseQt}
WriteLn('Trace:> [TQtWSCustomPage.CreateHandle]');
{$endif}
QtPage := TQtPage.Create(AWinControl, AParams);
QtPage.AttachEvents;
// Returns the Handle
Result := TLCLIntfHandle(QtPage);
{$ifdef VerboseQt}
WriteLn('Trace:< [TQtWSCustomPage.CreateHandle] Result: ', IntToStr(Result));
{$endif}
end;
class procedure TQtWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
var
ImageList: TCustomImageList;
ImageIndex: Integer;
Bmp: TBitmap;
begin
ImageList := TCustomNoteBook(ACustomPage.Parent).Images;
if Assigned(ImageList) then
begin
ImageIndex := TCustomNoteBook(ACustomPage.Parent).GetImageIndex(ACustomPage.PageIndex);
if (ImageIndex >= 0) and (ImageIndex < ImageList.Count) then
begin
Bmp := TBitmap.Create;
try
ImageList.GetBitmap(ACustomPage.ImageIndex, Bmp);
TQtPage(ACustomPage.Handle).setIcon(TQtImage(Bmp.Handle).AsIcon);
finally
Bmp.Free;
end;
end;
end;
end;
{ TQtWSCustomNotebook }
{------------------------------------------------------------------------------
Method: TQtWSCustomNotebook.CreateHandle
Params: None
Returns: Nothing
Allocates memory and resources for the control and shows it
------------------------------------------------------------------------------}
class function TQtWSCustomNotebook.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var
QtTabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.CreateHandle');
{$endif}
QtTabWidget := TQtTabWidget.Create(AWinControl, AParams);
QtTabWidget.setTabPosition(QTabWidgetTabPositionMap[TCustomNoteBook(AWinControl).TabPosition]);
QtTabWidget.setTabsClosable(nboShowCloseButtons in TCustomNotebook(AWinControl).Options);
QtTabWidget.AttachEvents;
// Returns the Handle
Result := TLCLIntfHandle(QtTabWidget);
end;
class procedure TQtWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
var
QtTabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.AddPage');
{$endif}
QtTabWidget := TQtTabWidget(ANotebook.Handle);
QtTabWidget.setUpdatesEnabled(False);
QtTabWidget.BeginUpdate;
try
QtTabWidget.insertTab(AIndex, TQtPage(AChild.Handle).Widget,
GetUtf8String(AChild.Caption));
finally
QtTabWidget.EndUpdate;
QtTabWidget.setUpdatesEnabled(True);
end;
TQtPage(AChild.Handle).ChildOfComplexWidget := ccwTabWidget;
TQtWsCustomPage.UpdateProperties(AChild);
end;
class procedure TQtWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
TabWidget: TQtTabWidget;
Index: Integer;
Page: TQtPage;
begin
Page := TQtPage(AChild.Handle);
TabWidget := TQtTabWidget(ANotebook.Handle);
Index := AChild.PageIndex;
if Index < 0 then
Index := ANoteBook.IndexOf(AChild);
TabWidget.BeginUpdate;
TabWidget.setUpdatesEnabled(false);
TabWidget.removeTab(Index);
TabWidget.insertTab(NewIndex, Page.Widget, Page.getIcon, Page.getText);
TabWidget.setUpdatesEnabled(true);
if TabWidget.getCurrentIndex <> NewIndex then
TabWidget.setCurrentWidget(Page);
TabWidget.EndUpdate;
end;
class procedure TQtWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
TabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.RemovePage');
{$endif}
TabWidget := TQtTabWidget(ANotebook.Handle);
TabWidget.setUpdatesEnabled(false);
TabWidget.BeginUpdate;
try
TabWidget.removeTab(AIndex);
finally
TabWidget.EndUpdate;
TabWidget.setUpdatesEnabled(true);
end;
end;
class function TQtWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result := [nbcShowCloseButtons];
end;
class function TQtWSCustomNotebook.GetDesignInteractive(
const AWinControl: TWinControl; AClientPos: TPoint): Boolean;
var
TabWidget: TQtTabWidget;
TabBar: TQtTabBar;
TabIndex: Integer;
p: TQtPoint;
begin
Result := False;
if not WSCheckHandleAllocated(AWinControl, 'GetDesignInteractive') then
Exit;
TabWidget := TQtTabWidget(AWinControl.Handle);
TabBar := TabWidget.TabBar;
p := QtPoint(AClientPos.x, AClientPos.y);
TabIndex := QTabBar_tabAt(QTabBarH(TabBar.Widget), @p);
Result := (TabIndex >= 0) and (TabWidget.getCurrentIndex <> TabIndex);
end;
class function TQtWSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
TabWidget: TQtTabWidget;
NewPos: TPoint;
R: TRect;
begin
TabWidget := TQtTabWidget(ANotebook.Handle);
NewPos := AClientPos;
R := TabWidget.TabBar.getGeometry;
case ANoteBook.TabPosition of
tpTop: if NewPos.Y < 0 then NewPos.Y := R.Bottom + NewPos.Y;
tpLeft: if NewPos.X < 0 then NewPos.X := R.Left + NewPos.X;
tpRight: NewPos.X := R.Right - NewPos.X;
tpBottom: NewPos.Y := R.Bottom - NewPos.Y;
end;
Result := TabWidget.tabAt(NewPos);
end;
class function TQtWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
TabWidget: TQtTabWidget;
begin
Result := Rect(-1, -1, -1, -1);
if not WSCheckHandleAllocated(ANotebook, 'GetTabRect') then
Exit;
TabWidget := TQtTabWidget(ANotebook.Handle);
Result := TabWidget.TabBar.GetTabRect(AIndex);
case ANoteBook.TabPosition of
tpTop: OffsetRect(Result, 0, -Result.Bottom);
tpLeft: OffsetRect(Result, -Result.Right, 0);
tpRight: OffsetRect(Result, Result.Left, 0);
tpBottom: OffsetRect(Result, Result.Top, 0);
end;
end;
class procedure TQtWSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
TabWidget: TQtTabWidget;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
TabWidget := TQtTabWidget(ANotebook.Handle);
TabWidget.BeginUpdate;
TabWidget.setCurrentIndex(AIndex);
TabWidget.EndUpdate;
end;
class procedure TQtWSCustomNotebook.SetTabCaption(
const ANotebook: TCustomNotebook; const AChild: TCustomPage;
const AText: string);
var
Index: Integer;
begin
Index := AChild.PageIndex;
if Index < 0 then
Index := ANotebook.IndexOf(AChild);
TQtTabWidget(ANotebook.Handle).setTabText(Index, GetUtf8String(AText));
end;
class procedure TQtWSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
TQtTabWidget(ANotebook.Handle).SetTabPosition(QTabWidgetTabPositionMap[ATabPosition]);
end;
class procedure TQtWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
var
TabWidget: TQtTabWidget;
begin
TabWidget := TQtTabWidget(ANotebook.Handle);
if TabWidget.TabBar <> nil then
TabWidget.ShowTabs := AShowTabs;
end;
class procedure TQtWSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
TQtTabWidget(ANotebook.Handle).setTabsClosable(nboShowCloseButtons in ANotebook.Options);
end;

View File

@ -34,11 +34,44 @@ uses
qtwidgets, qtobjects, qtproc,
// LCL
SysUtils, Classes, Types, ComCtrls, Controls, LCLType, Graphics, StdCtrls,
LCLProc, LCLIntf, Forms,
LCLProc, LCLIntf, Forms, ImgList,
// Widgetset
WSProc, WSComCtrls, WSLCLClasses;
type
{ TQtWSCustomPage }
TQtWSCustomPage = class(TWSCustomPage)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
end;
{ TQtWSCustomNotebook }
TQtWSCustomNotebook = class(TWSCustomNotebook)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetDesignInteractive(const AWinControl: TWinControl; AClientPos: TPoint): Boolean; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; override;
class procedure SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer); override;
class procedure SetTabCaption(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AText: string); override;
class procedure SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition); override;
class procedure ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean); override;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TQtWSStatusBar }
@ -227,6 +260,8 @@ type
implementation
{$include qtpagecontrol.inc}
const
TickMarkToQtSliderTickPositionMap: array[TTickMark] of QSliderTickPosition =
(

View File

@ -40,41 +40,6 @@ uses
WSExtCtrls, WSProc, WSLCLClasses;
type
{ TQtWSCustomPage }
TQtWSCustomPage = class(TWSCustomPage)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
end;
{ TQtWSCustomNotebook }
TQtWSCustomNotebook = class(TWSCustomNotebook)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
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 RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer); override;
class function GetCapabilities: TNoteBookCapabilities; override;
class function GetDesignInteractive(const AWinControl: TWinControl; AClientPos: TPoint): Boolean; override;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; override;
class procedure SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer); override;
class procedure SetTabCaption(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AText: string); override;
class procedure SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition); override;
class procedure ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean); override;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); override;
end;
{ TQtWSPage }
TQtWSPage = class(TWSPage)
@ -196,15 +161,6 @@ type
implementation
const
QTabWidgetTabPositionMap: array[TTabPosition] of QTabWidgetTabPosition =
(
{ tpTop } QTabWidgetNorth,
{ tpBottom } QTabWidgetSouth,
{ tpLeft } QTabWidgetWest,
{ tpRight } QTabWidgetEast
);
{ TQtWSCustomPanel }
{------------------------------------------------------------------------------
@ -229,255 +185,6 @@ begin
Result := TLCLIntfHandle(QtFrame);
end;
{ TQtWSCustomPage }
{------------------------------------------------------------------------------
Method: TQtWSCustomPage.CreateHandle
Params: None
Returns: Nothing
Allocates memory and resources for the control and shows it
------------------------------------------------------------------------------}
class function TQtWSCustomPage.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
QtPage: TQtPage;
begin
{$ifdef VerboseQt}
WriteLn('Trace:> [TQtWSCustomPage.CreateHandle]');
{$endif}
QtPage := TQtPage.Create(AWinControl, AParams);
QtPage.AttachEvents;
// Returns the Handle
Result := TLCLIntfHandle(QtPage);
{$ifdef VerboseQt}
WriteLn('Trace:< [TQtWSCustomPage.CreateHandle] Result: ', IntToStr(Result));
{$endif}
end;
class procedure TQtWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
var
ImageList: TCustomImageList;
ImageIndex: Integer;
Bmp: TBitmap;
begin
ImageList := TCustomNoteBook(ACustomPage.Parent).Images;
if Assigned(ImageList) then
begin
ImageIndex := TCustomNoteBook(ACustomPage.Parent).GetImageIndex(ACustomPage.PageIndex);
if (ImageIndex >= 0) and (ImageIndex < ImageList.Count) then
begin
Bmp := TBitmap.Create;
try
ImageList.GetBitmap(ACustomPage.ImageIndex, Bmp);
TQtPage(ACustomPage.Handle).setIcon(TQtImage(Bmp.Handle).AsIcon);
finally
Bmp.Free;
end;
end;
end;
end;
{ TQtWSCustomNotebook }
{------------------------------------------------------------------------------
Method: TQtWSCustomNotebook.CreateHandle
Params: None
Returns: Nothing
Allocates memory and resources for the control and shows it
------------------------------------------------------------------------------}
class function TQtWSCustomNotebook.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var
QtTabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.CreateHandle');
{$endif}
QtTabWidget := TQtTabWidget.Create(AWinControl, AParams);
QtTabWidget.setTabPosition(QTabWidgetTabPositionMap[TCustomNoteBook(AWinControl).TabPosition]);
QtTabWidget.setTabsClosable(nboShowCloseButtons in TCustomNotebook(AWinControl).Options);
QtTabWidget.AttachEvents;
// Returns the Handle
Result := TLCLIntfHandle(QtTabWidget);
end;
class procedure TQtWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AIndex: integer);
var
QtTabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.AddPage');
{$endif}
QtTabWidget := TQtTabWidget(ANotebook.Handle);
QtTabWidget.setUpdatesEnabled(False);
QtTabWidget.BeginUpdate;
try
QtTabWidget.insertTab(AIndex, TQtPage(AChild.Handle).Widget,
GetUtf8String(AChild.Caption));
finally
QtTabWidget.EndUpdate;
QtTabWidget.setUpdatesEnabled(True);
end;
TQtPage(AChild.Handle).ChildOfComplexWidget := ccwTabWidget;
TQtWsCustomPage.UpdateProperties(AChild);
end;
class procedure TQtWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
var
TabWidget: TQtTabWidget;
Index: Integer;
Page: TQtPage;
begin
Page := TQtPage(AChild.Handle);
TabWidget := TQtTabWidget(ANotebook.Handle);
Index := AChild.PageIndex;
if Index < 0 then
Index := ANoteBook.IndexOf(AChild);
TabWidget.BeginUpdate;
TabWidget.setUpdatesEnabled(false);
TabWidget.removeTab(Index);
TabWidget.insertTab(NewIndex, Page.Widget, Page.getIcon, Page.getText);
TabWidget.setUpdatesEnabled(true);
if TabWidget.getCurrentIndex <> NewIndex then
TabWidget.setCurrentWidget(Page);
TabWidget.EndUpdate;
end;
class procedure TQtWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook;
const AIndex: integer);
var
TabWidget: TQtTabWidget;
begin
{$ifdef VerboseQt}
WriteLn('TQtWSCustomNotebook.RemovePage');
{$endif}
TabWidget := TQtTabWidget(ANotebook.Handle);
TabWidget.setUpdatesEnabled(false);
TabWidget.BeginUpdate;
try
TabWidget.removeTab(AIndex);
finally
TabWidget.EndUpdate;
TabWidget.setUpdatesEnabled(true);
end;
end;
class function TQtWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result := [nbcShowCloseButtons];
end;
class function TQtWSCustomNotebook.GetDesignInteractive(
const AWinControl: TWinControl; AClientPos: TPoint): Boolean;
var
TabWidget: TQtTabWidget;
TabBar: TQtTabBar;
TabIndex: Integer;
p: TQtPoint;
begin
Result := False;
if not WSCheckHandleAllocated(AWinControl, 'GetDesignInteractive') then
Exit;
TabWidget := TQtTabWidget(AWinControl.Handle);
TabBar := TabWidget.TabBar;
p := QtPoint(AClientPos.x, AClientPos.y);
TabIndex := QTabBar_tabAt(QTabBarH(TabBar.Widget), @p);
Result := (TabIndex >= 0) and (TabWidget.getCurrentIndex <> TabIndex);
end;
class function TQtWSCustomNotebook.GetTabIndexAtPos(
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
var
TabWidget: TQtTabWidget;
NewPos: TPoint;
R: TRect;
begin
TabWidget := TQtTabWidget(ANotebook.Handle);
NewPos := AClientPos;
R := TabWidget.TabBar.getGeometry;
case ANoteBook.TabPosition of
tpTop: if NewPos.Y < 0 then NewPos.Y := R.Bottom + NewPos.Y;
tpLeft: if NewPos.X < 0 then NewPos.X := R.Left + NewPos.X;
tpRight: NewPos.X := R.Right - NewPos.X;
tpBottom: NewPos.Y := R.Bottom - NewPos.Y;
end;
Result := TabWidget.tabAt(NewPos);
end;
class function TQtWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
var
TabWidget: TQtTabWidget;
begin
Result := Rect(-1, -1, -1, -1);
if not WSCheckHandleAllocated(ANotebook, 'GetTabRect') then
Exit;
TabWidget := TQtTabWidget(ANotebook.Handle);
Result := TabWidget.TabBar.GetTabRect(AIndex);
case ANoteBook.TabPosition of
tpTop: OffsetRect(Result, 0, -Result.Bottom);
tpLeft: OffsetRect(Result, -Result.Right, 0);
tpRight: OffsetRect(Result, Result.Left, 0);
tpBottom: OffsetRect(Result, Result.Top, 0);
end;
end;
class procedure TQtWSCustomNotebook.SetPageIndex(
const ANotebook: TCustomNotebook; const AIndex: integer);
var
TabWidget: TQtTabWidget;
begin
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
Exit;
TabWidget := TQtTabWidget(ANotebook.Handle);
TabWidget.BeginUpdate;
TabWidget.setCurrentIndex(AIndex);
TabWidget.EndUpdate;
end;
class procedure TQtWSCustomNotebook.SetTabCaption(
const ANotebook: TCustomNotebook; const AChild: TCustomPage;
const AText: string);
var
Index: Integer;
begin
Index := AChild.PageIndex;
if Index < 0 then
Index := ANotebook.IndexOf(AChild);
TQtTabWidget(ANotebook.Handle).setTabText(Index, GetUtf8String(AText));
end;
class procedure TQtWSCustomNotebook.SetTabPosition(
const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition);
begin
TQtTabWidget(ANotebook.Handle).SetTabPosition(QTabWidgetTabPositionMap[ATabPosition]);
end;
class procedure TQtWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
var
TabWidget: TQtTabWidget;
begin
TabWidget := TQtTabWidget(ANotebook.Handle);
if TabWidget.TabBar <> nil then
TabWidget.ShowTabs := AShowTabs;
end;
class procedure TQtWSCustomNotebook.UpdateProperties(const ANotebook: TCustomNotebook);
begin
TQtTabWidget(ANotebook.Handle).setTabsClosable(nboShowCloseButtons in ANotebook.Options);
end;
{ TQtWSCustomRadioGroup }
{------------------------------------------------------------------------------

View File

@ -36,10 +36,10 @@ uses
// rtl
Windows, CommCtrl, SysUtils, Classes,
// lcl
ExtCtrls, Controls, ImgList, LCLType, LCLIntf, LCLProc, Themes, LCLMessageGlue,
ExtCtrls, Controls, ImgList, LCLType, LCLIntf, LCLProc, Themes, LCLMessageGlue, ComCtrls,
// ws
WSControls, WSExtCtrls, WSLCLClasses, WSProc, Win32Extra, Win32Int, Win32Proc,
InterfaceBase, Win32WSControls;
InterfaceBase, Win32WSControls, WSComCtrls;
type

View File

@ -33,10 +33,10 @@ uses
{$ifdef Win32}win32compat,{$endif}
// LCL
ExtCtrls, Classes, Controls, ImgList, Forms, LCLType, LCLIntf, LCLMessageGlue,
LCLProc,
LCLProc, ComCtrls,
// widgetset
WSControls, WSExtCtrls, WSLCLClasses, WinCEInt, WinCEProc, InterfaceBase,
WinCEWSControls, WSProc;
WinCEWSControls, WSProc, WSComCtrls;
type

View File

@ -32,7 +32,7 @@ interface
uses
Math, Types, Classes, SysUtils, LCLProc, LCLType, LCLStrConsts,
Graphics, Controls, ExtCtrls, Forms, Menus, Themes, LCLIntf,
LMessages, LResources, typinfo;
ComCtrls, LMessages, LResources, typinfo;
type
TLazDockPages = class;

View File

@ -50,6 +50,37 @@ uses
WSLCLClasses, WSControls, WSExtCtrls, WSToolwin, WSFactory;
type
{ TWSCustomPage }
TWSCustomPageClass = class of TWSCustomPage;
TWSCustomPage = class(TWSWinControl)
published
class procedure UpdateProperties(const ACustomPage: TCustomPage); virtual;
end;
{ TWSCustomNotebook }
TWSCustomNotebook = class(TWSWinControl)
published
class procedure AddPage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AIndex: integer); virtual;
class procedure MovePage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const NewIndex: integer); virtual;
class procedure RemovePage(const ANotebook: TCustomNotebook; const AIndex: integer); virtual;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; virtual;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; virtual;
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; virtual;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; virtual;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; virtual;
class function GetCapabilities: TNoteBookCapabilities; virtual;
class procedure SetImageList(const ANotebook: TCustomNotebook; const AImageList: TCustomImageList); virtual;
class procedure SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer); virtual;
class procedure SetTabCaption(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AText: string); virtual;
class procedure SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition); virtual;
class procedure ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean); virtual;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); virtual;
end;
TWSCustomNotebookClass = class of TWSCustomNotebook;
{ TWSStatusBar }
TWSStatusBarClass = class of TWSStatusBar;
@ -235,6 +266,132 @@ implementation
uses
LResources;
{ TWSCustomPage }
class procedure TWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
begin
end;
{ TWSCustomNotebook }
{ -----------------------------------------------------------------------------
Method: TWSCustomNotebook.AddPage
Params: ANotebook - A notebook control
AChild - Page to insert
AIndex - The position in the notebook to insert the page
Returns: Nothing
Adds a new page to a notebook
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AIndex: integer);
begin
end;
{------------------------------------------------------------------------------
Method: TWSCustomNotebook.MovePage
Params: ANotebook - The notebook control
AChild - The page to move
NewIndex - The new index of the page
Returns: Nothing
Moves a page in a notebook control
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
begin
end;
{------------------------------------------------------------------------------
Method: TWSCustomNotebook.RemovePage
Params: ANotebook - The notebook control
AIndex - The index of the page to delete
Returns: Nothing
Removes a page from a notebook control
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook; const AIndex: integer);
begin
end;
{-------------------------------------------------------------------------------
function TWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
Returns the minimum height of the horizontal tabs of a notebook. That is the
Notebook with TabPosition in [tpTop,tpBottom] without the client panel.
-------------------------------------------------------------------------------}
class function TWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
begin
Result:=30;
end;
{-------------------------------------------------------------------------------
function TWSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
Returns the minimum width of the vertical tabs of a notebook. That is the
Notebook with TabPosition in [tpLeft,tpRight] without the client panel.
-------------------------------------------------------------------------------}
class function TWSCustomNotebook.GetNotebookMinTabWidth(const AWinControl: TWinControl
): integer;
begin
Result:=60;
end;
class function TWSCustomNotebook.GetPageRealIndex(const ANotebook: TCustomNotebook;
AIndex: Integer): Integer;
begin
Result := AIndex;
end;
class function TWSCustomNotebook.GetTabIndexAtPos(const ANotebook: TCustomNotebook;
const AClientPos: TPoint): integer;
begin
Result := -1;
end;
class function TWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
begin
Result := Rect(-1,-1,-1,-1);
end;
class function TWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[];
end;
class procedure TWSCustomNotebook.SetImageList(
const ANotebook: TCustomNotebook; const AImageList: TCustomImageList);
begin
end;
class procedure TWSCustomNotebook.SetPageIndex(const ANotebook: TCustomNotebook;
const AIndex: integer);
begin
end;
class procedure TWSCustomNotebook.SetTabCaption(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AText: string);
begin
end;
class procedure TWSCustomNotebook.SetTabPosition(const ANotebook: TCustomNotebook;
const ATabPosition: TTabPosition);
begin
end;
class procedure TWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
end;
class procedure TWSCustomNotebook.UpdateProperties(
const ANotebook: TCustomNotebook);
begin
end;
{ TWSStatusBar }

View File

@ -49,46 +49,15 @@ uses
WSLCLClasses, WSControls, WSStdCtrls, WSFactory;
type
{ TWSCustomPage }
TWSCustomPageClass = class of TWSCustomPage;
TWSCustomPage = class(TWSWinControl)
published
class procedure UpdateProperties(const ACustomPage: TCustomPage); virtual;
end;
{ TWSCustomNotebook }
TWSCustomNotebook = class(TWSWinControl)
published
class procedure AddPage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AIndex: integer); virtual;
class procedure MovePage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const NewIndex: integer); virtual;
class procedure RemovePage(const ANotebook: TCustomNotebook; const AIndex: integer); virtual;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; virtual;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; virtual;
class function GetPageRealIndex(const ANotebook: TCustomNotebook; AIndex: Integer): Integer; virtual;
class function GetTabIndexAtPos(const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer; virtual;
class function GetTabRect(const ANotebook: TCustomNotebook; const AIndex: Integer): TRect; virtual;
class function GetCapabilities: TNoteBookCapabilities; virtual;
class procedure SetImageList(const ANotebook: TCustomNotebook; const AImageList: TCustomImageList); virtual;
class procedure SetPageIndex(const ANotebook: TCustomNotebook; const AIndex: integer); virtual;
class procedure SetTabCaption(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AText: string); virtual;
class procedure SetTabPosition(const ANotebook: TCustomNotebook; const ATabPosition: TTabPosition); virtual;
class procedure ShowTabs(const ANotebook: TCustomNotebook; AShowTabs: boolean); virtual;
class procedure UpdateProperties(const ANotebook: TCustomNotebook); virtual;
end;
TWSCustomNotebookClass = class of TWSCustomNotebook;
{ TWSPage }
TWSPage = class(TWSCustomPage)
TWSPage = class(TWSCustomControl)
published
end;
{ TWSNotebook }
TWSNotebook = class(TWSCustomNotebook)
TWSNotebook = class(TWSCustomControl)
published
end;
@ -197,8 +166,6 @@ type
{ WidgetSetRegistration }
procedure RegisterCustomPage;
procedure RegisterCustomNotebook;
procedure RegisterShape;
procedure RegisterCustomSplitter;
procedure RegisterPaintBox;
@ -212,133 +179,6 @@ type
implementation
{ TWSCustomPage }
class procedure TWSCustomPage.UpdateProperties(const ACustomPage: TCustomPage);
begin
end;
{ TWSCustomNotebook }
{ -----------------------------------------------------------------------------
Method: TWSCustomNotebook.AddPage
Params: ANotebook - A notebook control
AChild - Page to insert
AIndex - The position in the notebook to insert the page
Returns: Nothing
Adds a new page to a notebook
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.AddPage(const ANotebook: TCustomNotebook; const AChild: TCustomPage; const AIndex: integer);
begin
end;
{------------------------------------------------------------------------------
Method: TWSCustomNotebook.MovePage
Params: ANotebook - The notebook control
AChild - The page to move
NewIndex - The new index of the page
Returns: Nothing
Moves a page in a notebook control
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.MovePage(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const NewIndex: integer);
begin
end;
{------------------------------------------------------------------------------
Method: TWSCustomNotebook.RemovePage
Params: ANotebook - The notebook control
AIndex - The index of the page to delete
Returns: Nothing
Removes a page from a notebook control
------------------------------------------------------------------------------}
class procedure TWSCustomNotebook.RemovePage(const ANotebook: TCustomNotebook; const AIndex: integer);
begin
end;
{-------------------------------------------------------------------------------
function TWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
Returns the minimum height of the horizontal tabs of a notebook. That is the
Notebook with TabPosition in [tpTop,tpBottom] without the client panel.
-------------------------------------------------------------------------------}
class function TWSCustomNotebook.GetNotebookMinTabHeight(
const AWinControl: TWinControl): integer;
begin
Result:=30;
end;
{-------------------------------------------------------------------------------
function TWSCustomNotebook.GetNotebookMinTabWidth(
const AWinControl: TWinControl): integer;
Returns the minimum width of the vertical tabs of a notebook. That is the
Notebook with TabPosition in [tpLeft,tpRight] without the client panel.
-------------------------------------------------------------------------------}
class function TWSCustomNotebook.GetNotebookMinTabWidth(const AWinControl: TWinControl
): integer;
begin
Result:=60;
end;
class function TWSCustomNotebook.GetPageRealIndex(const ANotebook: TCustomNotebook;
AIndex: Integer): Integer;
begin
Result := AIndex;
end;
class function TWSCustomNotebook.GetTabIndexAtPos(const ANotebook: TCustomNotebook;
const AClientPos: TPoint): integer;
begin
Result := -1;
end;
class function TWSCustomNotebook.GetTabRect(const ANotebook: TCustomNotebook;
const AIndex: Integer): TRect;
begin
Result := Rect(-1,-1,-1,-1);
end;
class function TWSCustomNotebook.GetCapabilities: TNoteBookCapabilities;
begin
Result:=[];
end;
class procedure TWSCustomNotebook.SetImageList(
const ANotebook: TCustomNotebook; const AImageList: TCustomImageList);
begin
end;
class procedure TWSCustomNotebook.SetPageIndex(const ANotebook: TCustomNotebook;
const AIndex: integer);
begin
end;
class procedure TWSCustomNotebook.SetTabCaption(const ANotebook: TCustomNotebook;
const AChild: TCustomPage; const AText: string);
begin
end;
class procedure TWSCustomNotebook.SetTabPosition(const ANotebook: TCustomNotebook;
const ATabPosition: TTabPosition);
begin
end;
class procedure TWSCustomNotebook.ShowTabs(const ANotebook: TCustomNotebook;
AShowTabs: boolean);
begin
end;
class procedure TWSCustomNotebook.UpdateProperties(
const ANotebook: TCustomNotebook);
begin
end;
{ TWSCustomTrayIcon }
class function TWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;
@ -380,27 +220,6 @@ end;
{ WidgetSetRegistration }
procedure RegisterCustomPage;
const
Done: Boolean = False;
begin
if Done then exit;
WSRegisterCustomPage;
// if not WSRegisterCustomPage then
// RegisterWSComponent(TCustomPage, TWSCustomPage);
Done := True;
end;
procedure RegisterCustomNotebook;
const
Done: Boolean = False;
begin
if Done then exit;
if not WSRegisterCustomNotebook then
RegisterWSComponent(TCustomNotebook, TWSCustomNotebook);
Done := True;
end;
procedure RegisterShape;
const
Done: Boolean = False;