mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 17:41:31 +02:00
LCL: Remove styles properly in GTK2. Issue #20625, patch from cobines
git-svn-id: trunk@33592 -
This commit is contained in:
parent
35b15acebe
commit
3c946347ae
@ -55,6 +55,7 @@ end;
|
|||||||
|
|
||||||
var
|
var
|
||||||
gtkhandle: tlibhandle;
|
gtkhandle: tlibhandle;
|
||||||
|
glibhandle: tlibhandle;
|
||||||
libIter: Integer;
|
libIter: Integer;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
@ -67,7 +68,18 @@ initialization
|
|||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
for libIter := High(GLibNames) downto Low(GLibNames) do
|
||||||
|
begin
|
||||||
|
glibhandle := LoadLibrary(GLibNames[libIter]);
|
||||||
|
if glibhandle <> 0 then
|
||||||
|
begin
|
||||||
|
pointer(g_object_ref_sink):=GetProcAddress(glibhandle,'g_object_ref_sink');
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
if gtkhandle <> 0 then
|
if gtkhandle <> 0 then
|
||||||
FreeLibrary(gtkhandle);
|
FreeLibrary(gtkhandle);
|
||||||
|
if glibhandle <> 0 then
|
||||||
|
FreeLibrary(glibhandle);
|
||||||
|
@ -26,6 +26,19 @@ uses
|
|||||||
{$endif}
|
{$endif}
|
||||||
Pango;
|
Pango;
|
||||||
|
|
||||||
|
const
|
||||||
|
{ This is equired when people don't have -dev/-devel packages on linux.
|
||||||
|
I'm not sure how Darwin is handled tho }
|
||||||
|
{$ifdef windows}
|
||||||
|
GLibNames: array[1..1] of string = (gliblib);
|
||||||
|
{$else}
|
||||||
|
{$ifdef darwin} // Mac/Darwin
|
||||||
|
GLibNames: array[1..1] of string = (gliblib); // TODO: I don't know this one!
|
||||||
|
{$else} // BSD, Solaris, Linux
|
||||||
|
GLibNames: array[1..2] of string = (gliblib, gliblib + '.0');
|
||||||
|
{$endif}
|
||||||
|
{$endif}
|
||||||
|
|
||||||
const
|
const
|
||||||
gdkdll = gdklib;
|
gdkdll = gdklib;
|
||||||
|
|
||||||
@ -214,6 +227,7 @@ function gdk_screen_is_composited(screen: PGdkScreen): gboolean; cdecl; external
|
|||||||
|
|
||||||
var
|
var
|
||||||
gtk_window_set_opacity: procedure(window: PGtkWindow; opacity: gdouble); cdecl;
|
gtk_window_set_opacity: procedure(window: PGtkWindow; opacity: gdouble); cdecl;
|
||||||
|
g_object_ref_sink: function(anObject: PGObject): gpointer; cdecl;
|
||||||
|
|
||||||
{$ifdef ver2_2}
|
{$ifdef ver2_2}
|
||||||
{$ifdef darwin}
|
{$ifdef darwin}
|
||||||
|
@ -7503,14 +7503,14 @@ procedure FreeStyleObject(var StyleObject : PStyleObject);
|
|||||||
begin
|
begin
|
||||||
if StyleObject <> nil then
|
if StyleObject <> nil then
|
||||||
begin
|
begin
|
||||||
if StyleObject^.Obj <> nil then
|
if StyleObject^.Owner <> nil then
|
||||||
gtk_object_destroy(StyleObject^.Obj);
|
|
||||||
if StyleObject^.Widget <> nil then
|
|
||||||
begin
|
begin
|
||||||
// first unref
|
// GTK owns the reference to top level widgets created by application,
|
||||||
gtk_widget_unref(StyleObject^.Widget);
|
// so they cannot be destroyed by unreferencing.
|
||||||
// then destroy
|
if GTK_WIDGET_TOPLEVEL(StyleObject^.Owner) then
|
||||||
gtk_widget_destroy(StyleObject^.Widget);
|
gtk_widget_destroy(StyleObject^.Owner)
|
||||||
|
else
|
||||||
|
g_object_unref(StyleObject^.Owner);
|
||||||
end;
|
end;
|
||||||
if StyleObject^.Style <> nil then
|
if StyleObject^.Style <> nil then
|
||||||
if StyleObject^.Style^.attach_count > 0 then
|
if StyleObject^.Style^.attach_count > 0 then
|
||||||
@ -7655,8 +7655,8 @@ var
|
|||||||
NoName: PGChar;
|
NoName: PGChar;
|
||||||
lgs: TLazGtkStyle;
|
lgs: TLazGtkStyle;
|
||||||
WidgetName: String;
|
WidgetName: String;
|
||||||
//VBox: PGtkWidget;
|
|
||||||
AddToStyleWindow: Boolean;
|
AddToStyleWindow: Boolean;
|
||||||
|
AddReference: Boolean;
|
||||||
StyleWindowWidget: PGtkWidget;
|
StyleWindowWidget: PGtkWidget;
|
||||||
Requisition: TGtkRequisition;
|
Requisition: TGtkRequisition;
|
||||||
WindowFixedWidget: PGtkWidget;
|
WindowFixedWidget: PGtkWidget;
|
||||||
@ -7683,6 +7683,7 @@ begin
|
|||||||
lgs := lgsUserDefined;
|
lgs := lgsUserDefined;
|
||||||
Tp := nil;
|
Tp := nil;
|
||||||
AddToStyleWindow := True;
|
AddToStyleWindow := True;
|
||||||
|
AddReference := True;
|
||||||
WidgetName := 'LazStyle' + WName;
|
WidgetName := 'LazStyle' + WName;
|
||||||
// create a style widget
|
// create a style widget
|
||||||
If CompareText(WName,LazGtkStyleNames[lgsButton])=0 then begin
|
If CompareText(WName,LazGtkStyleNames[lgsButton])=0 then begin
|
||||||
@ -7698,18 +7699,21 @@ begin
|
|||||||
If CompareText(WName,LazGtkStyleNames[lgsDefault])=0 then begin
|
If CompareText(WName,LazGtkStyleNames[lgsDefault])=0 then begin
|
||||||
lgs:=lgsDefault;
|
lgs:=lgsDefault;
|
||||||
AddToStyleWindow:=false;
|
AddToStyleWindow:=false;
|
||||||
|
AddReference:=false;
|
||||||
NoName:=nil;
|
NoName:=nil;
|
||||||
StyleObject^.Widget :=
|
// GTK2 does not allow to instantiate the abstract base Widget
|
||||||
// GTK2 does not allow to instantiate the abstract base Widget
|
// so we use the "invisible" widget, which should never be defined
|
||||||
// so we use the "invisible" widget, which should never be defined
|
// by the theme.
|
||||||
// by the theme
|
// It is created with a real reference count=1 (not floating)
|
||||||
GTK_WIDGET_NEW( GTK_TYPE_INVISIBLE, NoName,[]);
|
// because it is a treated as top level widget.
|
||||||
|
StyleObject^.Widget := gtk_invisible_new;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
If CompareText(WName,LazGtkStyleNames[lgsWindow])=0 then begin
|
If CompareText(WName,LazGtkStyleNames[lgsWindow])=0 then begin
|
||||||
lgs:=lgsWindow;
|
lgs:=lgsWindow;
|
||||||
StyleObject^.Widget := GTK_WINDOW_NEW(GTK_WINDOW_TOPLEVEL);
|
StyleObject^.Widget := GTK_WINDOW_NEW(GTK_WINDOW_TOPLEVEL);
|
||||||
AddToStyleWindow:=false;
|
AddToStyleWindow:=false;
|
||||||
|
AddReference:=false;
|
||||||
gtk_widget_hide(StyleObject^.Widget);
|
gtk_widget_hide(StyleObject^.Widget);
|
||||||
// create the fixed widget
|
// create the fixed widget
|
||||||
// (where to put all style widgets, that need a parent for realize)
|
// (where to put all style widgets, that need a parent for realize)
|
||||||
@ -7798,13 +7802,12 @@ begin
|
|||||||
Tp := gtk_tooltips_new;
|
Tp := gtk_tooltips_new;
|
||||||
gtk_tooltips_force_window(Tp);
|
gtk_tooltips_force_window(Tp);
|
||||||
StyleObject^.Widget := PGTKTooltips(Tp)^.Tip_Window;
|
StyleObject^.Widget := PGTKTooltips(Tp)^.Tip_Window;
|
||||||
gtk_widget_ref(StyleObject^.Widget);// MG: why is this needed?
|
|
||||||
|
|
||||||
g_signal_connect(StyleObject^.Widget, 'style-set',
|
g_signal_connect(StyleObject^.Widget, 'style-set',
|
||||||
TGCallback(@tooltip_window_style_set), StyleObject);
|
TGCallback(@tooltip_window_style_set), StyleObject);
|
||||||
|
|
||||||
WidgetName := 'gtk-tooltip-lcl';
|
WidgetName := 'gtk-tooltip-lcl';
|
||||||
StyleObject^.Obj := Tp;
|
StyleObject^.Owner := Tp;
|
||||||
Tp := nil;
|
Tp := nil;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -7844,7 +7847,8 @@ begin
|
|||||||
else
|
else
|
||||||
If CompareText(WName,LazGtkStyleNames[lgsToolButton])=0 then begin
|
If CompareText(WName,LazGtkStyleNames[lgsToolButton])=0 then begin
|
||||||
lgs:=lgsToolButton;
|
lgs:=lgsToolButton;
|
||||||
StyleObject^.Widget := gtk_toolbar_append_item(PGtkToolBar(GetStyleWidget(lgsToolBar)), 'B', nil, nil, nil, nil, nil);
|
StyleObject^.Widget := PGtkWidget(gtk_tool_button_new(nil, 'B'));
|
||||||
|
gtk_toolbar_insert(PGtkToolbar(GetStyleWidget(lgsToolBar)), PGtkToolItem(StyleObject^.Widget), -1);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if CompareText(WName,LazGtkStyleNames[lgsScrolledWindow])=0 then begin
|
if CompareText(WName,LazGtkStyleNames[lgsScrolledWindow])=0 then begin
|
||||||
@ -7872,15 +7876,33 @@ begin
|
|||||||
|
|
||||||
// ensure style of the widget
|
// ensure style of the widget
|
||||||
If (StyleObject^.Widget <> nil) then begin
|
If (StyleObject^.Widget <> nil) then begin
|
||||||
gtk_widget_ref(StyleObject^.Widget);
|
|
||||||
|
|
||||||
// put style widget on style window, so that it can be realized
|
if not Assigned(StyleObject^.Owner) then
|
||||||
|
StyleObject^.Owner := StyleObject^.Widget;
|
||||||
|
|
||||||
|
// Widgets are created with a floating reference, except for top level.
|
||||||
|
// Here the floating reference is acquired, or reference count increased
|
||||||
|
// in case the floating reference is already owned (the widget has been
|
||||||
|
// added to a container).
|
||||||
|
if AddReference then
|
||||||
|
begin
|
||||||
|
if g_object_ref_sink = nil then
|
||||||
|
begin
|
||||||
|
// Deprecated since 2.10.
|
||||||
|
gtk_object_ref(PGtkObject(StyleObject^.Owner));
|
||||||
|
gtk_object_sink(PGtkObject(StyleObject^.Owner));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
g_object_ref_sink(PGObject(StyleObject^.Owner));
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Put style widget on style window, so that it can be realized.
|
||||||
if AddToStyleWindow then
|
if AddToStyleWindow then
|
||||||
begin
|
begin
|
||||||
gtk_widget_show_all(StyleObject^.Widget);
|
gtk_widget_show_all(StyleObject^.Widget);
|
||||||
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU) then
|
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU) then
|
||||||
begin
|
begin
|
||||||
// attach menu to window
|
// Attach menu to window. Increases reference count for the menu.
|
||||||
gtk_menu_attach_to_widget(PGtkMenu(StyleObject^.Widget),
|
gtk_menu_attach_to_widget(PGtkMenu(StyleObject^.Widget),
|
||||||
GetStyleWidget(lgsWindow), nil);
|
GetStyleWidget(lgsWindow), nil);
|
||||||
end
|
end
|
||||||
@ -7899,15 +7921,6 @@ begin
|
|||||||
gtk_menu_bar_append( GetStyleWidget(lgsMenuBar), StyleObject^.Widget);
|
gtk_menu_bar_append( GetStyleWidget(lgsMenuBar), StyleObject^.Widget);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
if GtkWidgetIsA(StyleObject^.Widget, GTK_TYPE_TOOL_BUTTON) then
|
|
||||||
begin
|
|
||||||
//gtk_toolbar_insert();
|
|
||||||
gtk_toolbar_append_widget(GTK_TOOLBAR(GetStyleWidget(lgsToolBar)),
|
|
||||||
StyleObject^.Widget, nil, nil);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
|
|
||||||
if (lgs = lgsToolButton) or
|
if (lgs = lgsToolButton) or
|
||||||
(lgs = lgsTooltip) then
|
(lgs = lgsTooltip) then
|
||||||
begin
|
begin
|
||||||
|
@ -693,9 +693,9 @@ function CreateFormContents(AForm: TCustomForm;
|
|||||||
type
|
type
|
||||||
PStyleObject = ^TStyleObject;
|
PStyleObject = ^TStyleObject;
|
||||||
TStyleObject = Record
|
TStyleObject = Record
|
||||||
Obj: PGtkObject;
|
|
||||||
Style: PGTKStyle;
|
Style: PGTKStyle;
|
||||||
Widget: PGTKWidget;
|
Owner: PGtkWidget; // The widget that we hold a reference to.
|
||||||
|
Widget: PGTKWidget; // This is the style widget.
|
||||||
FrameBordersValid: boolean;
|
FrameBordersValid: boolean;
|
||||||
FrameBorders: TRect;
|
FrameBorders: TRect;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user