mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 23:49:36 +02:00
Qt: Fix for #11796 - except for OI.Changed TabWidget behaviour, added some new routines, fixed focus problems with tabwidget.
git-svn-id: trunk@15958 -
This commit is contained in:
parent
64d1536bb4
commit
d85ac506ff
@ -607,8 +607,11 @@ type
|
||||
private
|
||||
FCurrentChangedHook: QTabWidget_hookH;
|
||||
FTabBarEventHook: QWidget_hookH;
|
||||
FTabBarChangedHook: QTabBar_hookH;
|
||||
FTabBar: QTabBarH;
|
||||
function getShowTabs: Boolean;
|
||||
function getTabBar: QTabBarH;
|
||||
procedure setShowTabs(const AValue: Boolean);
|
||||
protected
|
||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||
public
|
||||
@ -617,6 +620,7 @@ type
|
||||
|
||||
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
|
||||
procedure SignalCurrentChanged(Index: Integer); cdecl;
|
||||
procedure SignalTabBarCurrentChanged(Index: Integer); cdecl;
|
||||
function SlotTabBarMouse(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
|
||||
public
|
||||
function indexOf(const AWidget: QWidgetH): integer;
|
||||
@ -627,10 +631,13 @@ type
|
||||
function getTabPosition: QTabWidgetTabPosition;
|
||||
procedure removeTab(AIndex: Integer);
|
||||
procedure setCurrentIndex(AIndex: Integer);
|
||||
procedure setCurrentWidget(APage: TQtWidget);
|
||||
procedure setFocusPolicy(const APolicy: QtFocusPolicy); override;
|
||||
procedure setTabPosition(ATabPosition: QTabWidgetTabPosition);
|
||||
procedure setTabText(index: Integer; p2: WideString);
|
||||
function tabAt(APoint: TPoint): Integer;
|
||||
|
||||
property ShowTabs: Boolean read getShowTabs write setShowTabs;
|
||||
property TabBar: QTabBarH read getTabBar;
|
||||
end;
|
||||
|
||||
@ -2401,6 +2408,14 @@ var
|
||||
Modifiers: QtKeyboardModifiers;
|
||||
MousePos: TQtPoint;
|
||||
begin
|
||||
{$note fix for #11796, only OI is a black sheep}
|
||||
if Assigned(LCLObject.PopupMenu) then
|
||||
begin
|
||||
if (Self is TQtComboBox) and (TQtComboBox(Self).FLineEdit <> nil) then
|
||||
QWidget_setContextMenuPolicy(TQtComboBox(Self).FLineEdit.Widget, QtNoContextMenu);
|
||||
QWidget_setContextMenuPolicy(Widget, QtNoContextMenu);
|
||||
end;
|
||||
|
||||
FillChar(Msg, SizeOf(Msg), #0);
|
||||
MousePos := QContextMenuEvent_pos(QContextMenuEventH(Event))^;
|
||||
OffsetMousePos(@MousePos);
|
||||
@ -5205,10 +5220,23 @@ end;
|
||||
function TQtTabWidget.getTabBar: QTabBarH;
|
||||
begin
|
||||
if FTabBar = nil then
|
||||
begin
|
||||
FTabBar := QLCLTabWidget_tabBarHandle(QTabWidgetH(Widget));
|
||||
QWidget_setFocusPolicy(FTabBar, QtNoFocus);
|
||||
end;
|
||||
Result := FTabBar;
|
||||
end;
|
||||
|
||||
function TQtTabWidget.getShowTabs: Boolean;
|
||||
begin
|
||||
Result := QWidget_isVisible(TabBar);
|
||||
end;
|
||||
|
||||
procedure TQtTabWidget.setShowTabs(const AValue: Boolean);
|
||||
begin
|
||||
QWidget_setVisible(TabBar, AValue);
|
||||
end;
|
||||
|
||||
function TQtTabWidget.CreateWidget(const AParams: TCreateParams): QWidgetH;
|
||||
begin
|
||||
// Creates the widget
|
||||
@ -5233,9 +5261,12 @@ begin
|
||||
|
||||
FCurrentChangedHook := QTabWidget_hook_create(Widget);
|
||||
FTabBarEventHook := QWidget_hook_create(TabBar);
|
||||
FTabBarChangedHook := QTabBar_hook_create(TabBar);
|
||||
|
||||
QTabWidget_currentChanged_Event(Method) := @SignalCurrentChanged;
|
||||
QTabWidget_hook_hook_currentChanged(FCurrentChangedHook, Method);
|
||||
QTabBar_currentChanged_Event(Method) := @SignalTabBarCurrentChanged;
|
||||
QTabBar_hook_hook_currentChanged(FTabBarChangedHook, Method);
|
||||
TEventFilterMethod(Method) := @EventFilter;
|
||||
QObject_hook_hook_events(FTabBarEventHook, Method);
|
||||
end;
|
||||
@ -5337,10 +5368,15 @@ begin
|
||||
QTabWidget_setCurrentIndex(QTabWidgetH(Widget), AIndex);
|
||||
end;
|
||||
|
||||
procedure TQtTabWidget.setCurrentWidget(APage: TQtWidget);
|
||||
begin
|
||||
QTabWidget_setCurrentWidget(QTabWidgetH(Widget), APage.Widget);
|
||||
APage.setFocus;
|
||||
end;
|
||||
|
||||
procedure TQtTabWidget.setFocusPolicy(const APolicy: QtFocusPolicy);
|
||||
begin
|
||||
inherited setFocusPolicy(APolicy);
|
||||
QWidget_setFocusPolicy(TabBar, QtClickFocus);
|
||||
QWidget_setFocusPolicy(TabBar, QtNoFocus);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -5371,6 +5407,26 @@ begin
|
||||
Msg.Msg := LM_NOTIFY;
|
||||
FillChar(Hdr, SizeOf(Hdr), 0);
|
||||
|
||||
Hdr.hwndFrom := LCLObject.Handle;
|
||||
Hdr.Code := TCN_SELCHANGING;
|
||||
Hdr.idFrom := Index;
|
||||
Msg.NMHdr := @Hdr;
|
||||
Msg.Result := 0;
|
||||
DeliverMessage(Msg);
|
||||
end;
|
||||
|
||||
procedure TQtTabWidget.SignalTabBarCurrentChanged(Index: Integer); cdecl;
|
||||
var
|
||||
Msg: TLMNotify;
|
||||
Hdr: TNmHdr;
|
||||
begin
|
||||
if LCLObject = nil then
|
||||
Exit;
|
||||
|
||||
FillChar(Msg, SizeOf(Msg), 0);
|
||||
Msg.Msg := LM_NOTIFY;
|
||||
FillChar(Hdr, SizeOf(Hdr), 0);
|
||||
|
||||
Hdr.hwndFrom := LCLObject.Handle;
|
||||
Hdr.Code := TCN_SELCHANGE;
|
||||
Hdr.idFrom := Index;
|
||||
@ -5423,6 +5479,14 @@ begin
|
||||
QTabWidget_setTabText(QTabWidgetH(Widget), index, @p2);
|
||||
end;
|
||||
|
||||
function TQtTabWidget.tabAt(APoint: TPoint): Integer;
|
||||
var
|
||||
AQtPoint: TQtPoint;
|
||||
begin
|
||||
AQtPoint := QtPoint(APoint.x, APoint.y);
|
||||
Result := QTabBar_tabAt(TabBar, @AQtPoint);
|
||||
end;
|
||||
|
||||
{ TQtComboBox }
|
||||
|
||||
function TQtComboBox.GetLineEdit: TQtLineEdit;
|
||||
|
@ -37,7 +37,7 @@ uses
|
||||
SysUtils, Classes, Controls, Graphics, Forms, StdCtrls, ExtCtrls, LCLType,
|
||||
ImgList,
|
||||
// Widgetset
|
||||
WSExtCtrls, WSLCLClasses;
|
||||
WSExtCtrls, WSProc, WSLCLClasses;
|
||||
|
||||
type
|
||||
|
||||
@ -329,7 +329,6 @@ begin
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('TQtWSCustomNotebook.CreateHandle');
|
||||
{$endif}
|
||||
|
||||
QtTabWidget := TQtTabWidget.Create(AWinControl, AParams);
|
||||
QtTabWidget.SetTabPosition(QTabWidgetTabPositionMap[TCustomNoteBook(AWinControl).TabPosition]);
|
||||
QtTabWidget.AttachEvents;
|
||||
@ -375,45 +374,29 @@ begin
|
||||
WriteLn('TQtWSCustomNotebook.RemovePage');
|
||||
{$endif}
|
||||
TabWidget := TQtTabWidget(ANotebook.Handle);
|
||||
TabWidget.setUpdatesEnabled(false);
|
||||
TabWidget.removeTab(AIndex);
|
||||
TabWidget.setUpdatesEnabled(true);
|
||||
end;
|
||||
|
||||
class function TQtWSCustomNotebook.GetTabIndexAtPos(
|
||||
const ANotebook: TCustomNotebook; const AClientPos: TPoint): integer;
|
||||
var
|
||||
TabWidget: TQtTabWidget;
|
||||
APoint: TQtPoint;
|
||||
begin
|
||||
TabWidget := TQtTabWidget(ANotebook.Handle);
|
||||
if TabWidget.TabBar <> nil then
|
||||
begin
|
||||
APoint := QtPoint(AClientPos.x, AClientPos.y);
|
||||
|
||||
Result := QTabBar_tabAt(TabWidget.TabBar, @APoint);
|
||||
end
|
||||
else
|
||||
Result := -1;
|
||||
Result := TabWidget.tabAt(AClientPos);
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomNotebook.SetPageIndex(
|
||||
const ANotebook: TCustomNotebook; const AIndex: integer);
|
||||
var
|
||||
TabWidget: TQtTabWidget;
|
||||
OldIndex: Integer;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ANotebook, 'SetPageIndex') then
|
||||
Exit;
|
||||
TabWidget := TQtTabWidget(ANotebook.Handle);
|
||||
|
||||
// copy pasted from win32wsextctrls with corrections
|
||||
|
||||
OldIndex := TabWidget.getCurrentIndex;
|
||||
TabWidget.setCurrentIndex(AIndex);
|
||||
if not (csDestroying in ANotebook.ComponentState) then
|
||||
begin
|
||||
if (OldIndex >= 0) and (OldIndex <> AIndex) and
|
||||
(OldIndex < ANotebook.PageCount) and
|
||||
(ANotebook.CustomPage(OldIndex).HandleAllocated) then
|
||||
TQtWidget(ANotebook.CustomPage(OldIndex).Handle).setVisible(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomNotebook.SetTabCaption(
|
||||
@ -436,7 +419,7 @@ var
|
||||
begin
|
||||
TabWidget := TQtTabWidget(ANotebook.Handle);
|
||||
if TabWidget.TabBar <> nil then
|
||||
QWidget_setVisible(TabWidget.TabBar, AShowTabs);
|
||||
TabWidget.ShowTabs := AShowTabs;
|
||||
end;
|
||||
|
||||
{ TQtWSCustomRadioGroup }
|
||||
|
Loading…
Reference in New Issue
Block a user