mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 21:00:23 +02:00
gtk: improve toolbar elements painting
git-svn-id: trunk@12889 -
This commit is contained in:
parent
b101883850
commit
b5b7109b34
@ -58,7 +58,7 @@ begin
|
||||
csDoubleClicks, csMenuEvents, csSetCaption];
|
||||
FButtonWidth := 23;
|
||||
FButtonHeight := 22;
|
||||
FDropDownWidth := {$ifdef UseThemes}12{$else}10{$endif};
|
||||
FDropDownWidth := {$ifdef UseThemes}13{$else}10{$endif};
|
||||
FNewStyle := True;
|
||||
FWrapable := True;
|
||||
FButtons := TList.Create;
|
||||
|
@ -122,7 +122,9 @@ type
|
||||
lgsHScale,
|
||||
lgsVScale,
|
||||
lgsGroupBox,
|
||||
lgsTreeView, // for gtk2
|
||||
lgsTreeView, // for gtk2
|
||||
lgsToolBar, // toolbar
|
||||
lgsToolButton, // button placed on toolbar
|
||||
// user defined
|
||||
lgsUserDefined
|
||||
);
|
||||
@ -151,6 +153,8 @@ const
|
||||
'vscale',
|
||||
'groupbox',
|
||||
'treeview',
|
||||
'toolbar',
|
||||
'toolbutton',
|
||||
''
|
||||
);
|
||||
|
||||
|
@ -8203,6 +8203,16 @@ begin
|
||||
StyleObject^.Widget := gtk_tree_view_new;
|
||||
end
|
||||
{$endif}
|
||||
else
|
||||
If CompareText(WName,LazGtkStyleNames[lgsToolBar])=0 then begin
|
||||
lgs:=lgsToolBar;
|
||||
StyleObject^.Widget := gtk_toolbar_new;
|
||||
end
|
||||
else
|
||||
If CompareText(WName,LazGtkStyleNames[lgsToolButton])=0 then begin
|
||||
lgs:=lgsToolButton;
|
||||
StyleObject^.Widget := gtk_toolbar_append_item(PGtkToolBar(GetStyleWidget(lgsToolBar)), 'B', nil, nil, nil, nil, nil);
|
||||
end
|
||||
else
|
||||
If CompareText(WName,LazGtkStyleNames[lgsGTK_Default])=0 then begin
|
||||
lgs:=lgsGTK_Default;
|
||||
@ -8227,19 +8237,27 @@ begin
|
||||
gtk_widget_ref(StyleObject^.Widget);
|
||||
|
||||
// put style widget on style window, so that it can be realized
|
||||
if AddToStyleWindow then begin
|
||||
if AddToStyleWindow then
|
||||
begin
|
||||
gtk_widget_show_all(StyleObject^.Widget);
|
||||
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU) then begin
|
||||
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU) then
|
||||
begin
|
||||
StyleWindowWidget:=GetStyleWidget(lgsWindow);
|
||||
// add menu above the forms client area (fixed widget)
|
||||
VBox:=PGTKWidget(
|
||||
gtk_object_get_data(PGtkObject(StyleWindowWidget),'vbox'));
|
||||
DebugLn(['GetStyleWithName adding menu to form']);
|
||||
gtk_box_pack_start(PGTKBox(VBox), StyleObject^.Widget, false, True, 0);
|
||||
end else if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU_BAR) then begin
|
||||
end
|
||||
else
|
||||
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU_BAR) then
|
||||
begin
|
||||
DebugLn(['GetStyleWithName adding menubar to menu']);
|
||||
gtk_menu_append(GetStyleWidget(lgsMenu),StyleObject^.Widget);
|
||||
end else if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU_ITEM) then begin
|
||||
end
|
||||
else
|
||||
if GtkWidgetIsA(StyleObject^.Widget,GTK_TYPE_MENU_ITEM) then
|
||||
begin
|
||||
DebugLn(['GetStyleWithName adding menuitem to menubar']);
|
||||
gtk_menu_bar_append({$IFDEF Gtk1}
|
||||
PGtkMenuBar(GetStyleWidget(lgsMenuBar)),
|
||||
@ -8247,13 +8265,25 @@ begin
|
||||
GetStyleWidget(lgsMenuBar),
|
||||
{$ENDIF}
|
||||
StyleObject^.Widget);
|
||||
end else begin
|
||||
end
|
||||
else
|
||||
{$ifdef gtk2}
|
||||
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
|
||||
{$endif}
|
||||
begin
|
||||
StyleWindowWidget:=GetStyleWidget(lgsWindow);
|
||||
// add widget on client area of form
|
||||
WindowFixedWidget:=PGTKWidget(
|
||||
gtk_object_get_data(PGtkObject(StyleWindowWidget),'fixedwidget'));
|
||||
//DebugLn('GetStyleWithName adding on hidden stylewindow ',WName,' ',GetWidgetDebugReport(StyleObject^.Widget));
|
||||
gtk_fixed_put(PGtkFixed(WindowFixedWidget),StyleObject^.Widget,10,10);
|
||||
if WindowFixedWidget <> nil then
|
||||
gtk_fixed_put(PGtkFixed(WindowFixedWidget),StyleObject^.Widget,10,10);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -35,7 +35,8 @@ type
|
||||
gptHandle,
|
||||
gptExpander,
|
||||
gptResizeGrip,
|
||||
gptFocus
|
||||
gptFocus,
|
||||
gptArrow
|
||||
);
|
||||
|
||||
TGtkStyleParams = record
|
||||
@ -48,6 +49,8 @@ type
|
||||
Shadow : TGtkShadowType; // Shadow
|
||||
Detail : String; // Detail (button, checkbox, ...)
|
||||
Orientation: TGtkOrientation; // Orientation (horizontal/vertical)
|
||||
ArrowType : TGtkArrowType; // type of arrow
|
||||
Fill : Boolean; // fill inside area
|
||||
{$ifdef gtk2}
|
||||
Expander : TGtkExpanderStyle; // treeview expander
|
||||
Edge : TGdkWindowEdge;
|
||||
@ -63,7 +66,8 @@ type
|
||||
private
|
||||
protected
|
||||
function GdkRectFromRect(R: TRect): TGdkRectangle;
|
||||
function GetGtkStyleParams(DC: HDC; Details: TThemedElementDetails): TGtkStyleParams; virtual;
|
||||
function GetParamsCount(Details: TThemedElementDetails): Integer;
|
||||
function GetGtkStyleParams(DC: HDC; Details: TThemedElementDetails; AIndex: Integer): TGtkStyleParams; virtual;
|
||||
|
||||
function InitThemes: Boolean; override;
|
||||
function UseThemes: Boolean; override;
|
||||
@ -92,7 +96,7 @@ const
|
||||
{ pressed } GTK_STATE_ACTIVE,
|
||||
{ disabled } GTK_STATE_INSENSITIVE,
|
||||
{ defaulted/checked } GTK_STATE_ACTIVE,
|
||||
{ hot + checked } GTK_STATE_INSENSITIVE // PRELIGHT IS TOO LIGHT
|
||||
{ hot + checked } GTK_STATE_ACTIVE
|
||||
);
|
||||
GtkRadioCheckBoxMap: array[0..12] of TGtkStateType =
|
||||
(
|
||||
@ -127,8 +131,16 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TGtkThemeServices.GetParamsCount(Details: TThemedElementDetails
|
||||
): Integer;
|
||||
begin
|
||||
Result := 1;
|
||||
if (Details.Element = teToolBar) and (Details.Part = TP_SPLITBUTTONDROPDOWN) then
|
||||
inc(Result); // + Arrow
|
||||
end;
|
||||
|
||||
function TGtkThemeServices.GetGtkStyleParams(DC: HDC;
|
||||
Details: TThemedElementDetails): TGtkStyleParams;
|
||||
Details: TThemedElementDetails; AIndex: Integer): TGtkStyleParams;
|
||||
var
|
||||
ClientWidget: PGtkWidget;
|
||||
begin
|
||||
@ -151,6 +163,8 @@ begin
|
||||
Result.State := GTK_STATE_NORMAL;
|
||||
Result.Detail := '';
|
||||
Result.Shadow := GTK_SHADOW_NONE;
|
||||
Result.ArrowType := GTK_ARROW_UP;
|
||||
Result.Fill := False;
|
||||
Result.IsHot := False;
|
||||
|
||||
case Details.Element of
|
||||
@ -215,25 +229,49 @@ begin
|
||||
teToolBar:
|
||||
begin
|
||||
case Details.Part of
|
||||
TP_BUTTON:
|
||||
TP_BUTTON,
|
||||
TP_DROPDOWNBUTTON,
|
||||
TP_SPLITBUTTON,
|
||||
TP_SPLITBUTTONDROPDOWN:
|
||||
begin
|
||||
Result.Widget := GetStyleWidget(lgsButton);
|
||||
Result.State := GtkButtonMap[Details.State];
|
||||
if Details.State in [TS_PRESSED, TS_CHECKED, TS_HOTCHECKED] then
|
||||
Result.Shadow := GTK_SHADOW_IN
|
||||
if (Details.Part = TP_SPLITBUTTONDROPDOWN) and (AIndex = 1) then
|
||||
begin
|
||||
Result.Detail := 'arrow';
|
||||
Result.ArrowType := GTK_ARROW_DOWN;
|
||||
Result.Fill := True;
|
||||
Result.Painter := gptArrow;
|
||||
end
|
||||
else
|
||||
if Details.State in [TS_HOT] then
|
||||
Result.Shadow := GTK_SHADOW_ETCHED_IN
|
||||
else
|
||||
Result.Shadow := GTK_SHADOW_NONE;
|
||||
begin
|
||||
Result.Widget := GetStyleWidget(lgsToolButton);
|
||||
Result.State := GtkButtonMap[Details.State];
|
||||
if Details.State in [TS_PRESSED, TS_CHECKED, TS_HOTCHECKED] then
|
||||
Result.Shadow := GTK_SHADOW_IN
|
||||
else
|
||||
if Details.State in [TS_HOT] then
|
||||
Result.Shadow := GTK_SHADOW_ETCHED_IN
|
||||
else
|
||||
Result.Shadow := GTK_SHADOW_NONE;
|
||||
|
||||
Result.IsHot := Details.State in [TS_HOT, TS_HOTCHECKED];
|
||||
Result.IsHot := Details.State in [TS_HOT, TS_HOTCHECKED];
|
||||
|
||||
Result.Detail := 'togglebutton';
|
||||
if Result.Shadow = GTK_SHADOW_NONE then
|
||||
Result.Painter := gptNone
|
||||
Result.Detail := 'button';
|
||||
if Result.Shadow = GTK_SHADOW_NONE then
|
||||
Result.Painter := gptNone
|
||||
else
|
||||
Result.Painter := gptBox;
|
||||
end;
|
||||
end;
|
||||
TP_SEPARATOR,
|
||||
TP_SEPARATORVERT:
|
||||
begin
|
||||
Result.State := GTK_STATE_NORMAL;
|
||||
Result.Shadow := GTK_SHADOW_NONE;
|
||||
Result.Detail := 'toolbar';
|
||||
if Details.Part = TP_SEPARATOR then
|
||||
Result.Painter := gptVLine
|
||||
else
|
||||
Result.Painter := gptBox;
|
||||
Result.Painter := gptHLine;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -301,7 +339,7 @@ var
|
||||
StyleParams: TGtkStyleParams;
|
||||
begin
|
||||
Result := BoundingRect;
|
||||
StyleParams := GetGtkStyleParams(DC, Details);
|
||||
StyleParams := GetGtkStyleParams(DC, Details, 0);
|
||||
if StyleParams.Style <> nil then
|
||||
InflateRect(Result,
|
||||
-StyleParams.Style^.{$ifndef gtk2}klass^.{$endif}xthickness,
|
||||
@ -313,100 +351,112 @@ procedure TGtkThemeServices.DrawElement(DC: HDC;
|
||||
var
|
||||
Area: TGdkRectangle;
|
||||
StyleParams: TGtkStyleParams;
|
||||
i: integer;
|
||||
begin
|
||||
StyleParams := GetGtkStyleParams(DC, Details);
|
||||
if StyleParams.Style <> nil then
|
||||
for i := 0 to GetParamsCount(Details) - 1 do
|
||||
begin
|
||||
if ClipRect <> nil then
|
||||
Area := GdkRectFromRect(ClipRect^)
|
||||
else
|
||||
Area := GdkRectFromRect(R);
|
||||
|
||||
inc(Area.x, StyleParams.Origin.x);
|
||||
inc(Area.y, StyleParams.Origin.y);
|
||||
|
||||
with StyleParams do
|
||||
StyleParams := GetGtkStyleParams(DC, Details, i);
|
||||
if StyleParams.Style <> nil then
|
||||
begin
|
||||
case Painter of
|
||||
gptBox,
|
||||
gptDefault: gtk_paint_box(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptHLine : gtk_paint_hline(
|
||||
Style, Window,
|
||||
State, @Area,
|
||||
Widget, PChar(Detail),
|
||||
Area.x, Area.x + Area.Width, Area.y);
|
||||
gptVLine : gtk_paint_vline(
|
||||
Style, Window,
|
||||
State, @Area,
|
||||
Widget, PChar(Detail),
|
||||
Area.y, Area.y + Area.Height, Area.x);
|
||||
gptShadow : gtk_paint_shadow(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptFlatBox: gtk_paint_flat_box(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptCheck : gtk_paint_check(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptOption : gtk_paint_option(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptTab : gtk_paint_tab(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptSlider : gtk_paint_slider(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height,
|
||||
Orientation);
|
||||
gptHandle : gtk_paint_handle(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height,
|
||||
Orientation);
|
||||
{$ifdef gtk2}
|
||||
gptExpander: gtk_paint_expander(
|
||||
Style, Window, State,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Expander);
|
||||
gptResizeGrip: gtk_paint_resize_grip(
|
||||
Style, Window, State,
|
||||
@Area, Widget,
|
||||
PChar(Detail), Edge,
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
{$endif}
|
||||
gptFocus : gtk_paint_focus(
|
||||
Style, Window, {$ifdef gtk2}State,{$endif}
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
if ClipRect <> nil then
|
||||
Area := GdkRectFromRect(ClipRect^)
|
||||
else
|
||||
Area := GdkRectFromRect(R);
|
||||
|
||||
// move to origin
|
||||
inc(Area.x, StyleParams.Origin.x);
|
||||
inc(Area.y, StyleParams.Origin.y);
|
||||
|
||||
with StyleParams do
|
||||
begin
|
||||
case Painter of
|
||||
gptBox,
|
||||
gptDefault: gtk_paint_box(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptHLine : gtk_paint_hline(
|
||||
Style, Window,
|
||||
State, @Area,
|
||||
Widget, PChar(Detail),
|
||||
Area.x, Area.x + Area.Width, Area.y);
|
||||
gptVLine : gtk_paint_vline(
|
||||
Style, Window,
|
||||
State, @Area,
|
||||
Widget, PChar(Detail),
|
||||
Area.y, Area.y + Area.Height, Area.x);
|
||||
gptShadow : gtk_paint_shadow(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptFlatBox: gtk_paint_flat_box(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptCheck : gtk_paint_check(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptOption : gtk_paint_option(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptTab : gtk_paint_tab(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptSlider : gtk_paint_slider(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height,
|
||||
Orientation);
|
||||
gptHandle : gtk_paint_handle(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height,
|
||||
Orientation);
|
||||
{$ifdef gtk2}
|
||||
gptExpander: gtk_paint_expander(
|
||||
Style, Window, State,
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Expander);
|
||||
gptResizeGrip: gtk_paint_resize_grip(
|
||||
Style, Window, State,
|
||||
@Area, Widget,
|
||||
PChar(Detail), Edge,
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
{$endif}
|
||||
gptFocus : gtk_paint_focus(
|
||||
Style, Window, {$ifdef gtk2}State,{$endif}
|
||||
@Area, Widget, PChar(Detail),
|
||||
Area.x, Area.y,
|
||||
Area.Width, Area.Height);
|
||||
gptArrow: gtk_paint_arrow(
|
||||
Style, Window,
|
||||
State, Shadow,
|
||||
@Area, Widget, PChar(Detail),
|
||||
ArrowType, Fill,
|
||||
Area.x, Area.y, Area.width, Area.height
|
||||
);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -453,7 +503,7 @@ var
|
||||
P: PChar;
|
||||
tmpRect: TRect;
|
||||
begin
|
||||
StyleParams := GetGtkStyleParams(DC, Details);
|
||||
StyleParams := GetGtkStyleParams(DC, Details, 0);
|
||||
if StyleParams.Style <> nil then
|
||||
with StyleParams do
|
||||
begin
|
||||
|
@ -53,6 +53,9 @@ type
|
||||
PPPangoAttrList = ^PPangoAttrList;
|
||||
procedure gtk_im_context_get_preedit_string_laz(context:PGtkIMContext; str:PPgchar; attrs:PPPangoAttrList; cursor_pos:Pgint); cdecl; external gtklib name 'gtk_im_context_get_preedit_string';
|
||||
|
||||
// gtk 2.4
|
||||
procedure gtk_toolbar_insert(toolbar: PGtkToolBar; item: PGtkToolItem; pos: gint); cdecl; external gtklib name 'gtk_toolbar_insert';
|
||||
|
||||
// gtk 2.6
|
||||
function gtk_cell_view_get_displayed_row(cell_view: Pointer): PGtkTreePath; cdecl; external gtklib name 'gtk_cell_view_get_displayed_row';
|
||||
|
||||
|
@ -19,7 +19,7 @@ type
|
||||
|
||||
TGtk2ThemeServices = class(TGtkThemeServices)
|
||||
protected
|
||||
function GetGtkStyleParams(DC: HDC; Details: TThemedElementDetails): TGtkStyleParams; override;
|
||||
function GetGtkStyleParams(DC: HDC; Details: TThemedElementDetails; AIndex: Integer): TGtkStyleParams; override;
|
||||
public
|
||||
function GetDetailSize(Details: TThemedElementDetails): Integer; override;
|
||||
end;
|
||||
@ -29,9 +29,9 @@ implementation
|
||||
{ TGtk2ThemeServices }
|
||||
|
||||
function TGtk2ThemeServices.GetGtkStyleParams(DC: HDC;
|
||||
Details: TThemedElementDetails): TGtkStyleParams;
|
||||
Details: TThemedElementDetails; AIndex: Integer): TGtkStyleParams;
|
||||
begin
|
||||
Result := inherited GetGtkStyleParams(DC, Details);
|
||||
Result := inherited GetGtkStyleParams(DC, Details, AIndex);
|
||||
|
||||
// override some styles
|
||||
if Result.Style <> nil then
|
||||
|
Loading…
Reference in New Issue
Block a user