gtk2: improve notebook close button (it looks natively in gnome now)

- make it theme dependent
  - fix size

git-svn-id: trunk@19634 -
This commit is contained in:
paul 2009-04-26 14:14:31 +00:00
parent b46c4051e3
commit cd1570a15d
2 changed files with 29 additions and 35 deletions

View File

@ -412,7 +412,9 @@ end;
initialization initialization
{$IFDEF GTK1}
{$I gtkimages.lrs} {$I gtkimages.lrs}
{$ENDIF}
InternalInit; InternalInit;
finalization finalization

View File

@ -4142,13 +4142,11 @@ begin
end; end;
end; end;
{$IFDef GTK1}
var var
{$IFDef GTK1}
NoteBookCloseBtnPixmapImg: PGdkPixmap = nil; NoteBookCloseBtnPixmapImg: PGdkPixmap = nil;
NoteBookCloseBtnPixmapMask: PGdkPixmap = nil; NoteBookCloseBtnPixmapMask: PGdkPixmap = nil;
{$Else} {$EndIf}
NoteBookCloseBtnPixbuf: PGdkPixbuf = nil;
{$EndIf}
{------------------------------------------------------------------------------- {-------------------------------------------------------------------------------
procedure RemoveDummyNoteBookPage(NoteBookWidget: PGtkNotebook); procedure RemoveDummyNoteBookPage(NoteBookWidget: PGtkNotebook);
@ -4187,13 +4185,6 @@ begin
Img:=NoteBookCloseBtnPixmapImg; Img:=NoteBookCloseBtnPixmapImg;
Mask:=NoteBookCloseBtnPixmapMask; Mask:=NoteBookCloseBtnPixmapMask;
end; end;
{$Else}
procedure GetNoteBookCloseBtnImage(var Img: PGdkPixbuf);
begin
if (NoteBookCloseBtnPixbuf=nil) then
LoadPixbufFromLazResource('tnotebook_close_tab', NoteBookCloseBtnPixbuf);
Img:=NoteBookCloseBtnPixbuf;
end;
{$EndIF} {$EndIF}
{------------------------------------------------------------------------------- {-------------------------------------------------------------------------------
@ -4347,47 +4338,48 @@ var
Img: PGdkPixmap; Img: PGdkPixmap;
Mask: PGdkBitmap; Mask: PGdkBitmap;
{$Else} {$Else}
Img: PGdkPixbuf; style: PGtkRcStyle;
x, y: gInt;
{$EndIf} {$EndIf}
begin begin
{$IfDef GTK1} {$IfDef GTK1}
//debugln('UpdateTabCloseBtn ',GetWidgetDebugReport(NoteBookWidget)); //debugln('UpdateTabCloseBtn ',GetWidgetDebugReport(NoteBookWidget));
GetNoteBookCloseBtnImage(GetControlWindow(NoteBookWidget),Img,Mask); GetNoteBookCloseBtnImage(GetControlWindow(NoteBookWidget), Img, Mask);
{$Else}
GetNoteBookCloseBtnImage(Img);
{$EndIf} {$EndIf}
//debugln('UpdateTabCloseBtn ',dbgs(nboShowCloseButtons in TheNotebook.Options),' ',dbgs(Img<>nil)); //debugln('UpdateTabCloseBtn ',dbgs(nboShowCloseButtons in TheNotebook.Options),' ',dbgs(Img<>nil));
if (nboShowCloseButtons in TheNotebook.Options) and (Img<>nil) then begin if (nboShowCloseButtons in TheNotebook.Options)
{$ifdef GTK1}and (Img <> nil){$ENDIF} then
begin
// close buttons enabled // close buttons enabled
if TabCloseBtnWidget=nil then begin if TabCloseBtnWidget = nil then
begin
// there is no close button yet // there is no close button yet
// -> add one to the right side of the label in the tab // -> add one to the right side of the label in the tab
TabCloseBtnWidget:=gtk_button_new; TabCloseBtnWidget := gtk_button_new;
gtk_button_set_relief(PGtkButton(TabCloseBtnWidget), GTK_RELIEF_NONE);
{$ifdef gtk2} {$ifdef gtk2}
gtk_widget_get_size_request(TabWidget, @x, @y); gtk_button_set_focus_on_click(PGtkButton(TabCloseBtnWidget), False);
y := 0; // will make it default fit style := gtk_widget_get_modifier_style(TabCloseBtnWidget);
gtk_widget_set_size_request(TabCloseBtnWidget, x, y); style^.xthickness := 0;
style^.ythickness := 0;
gtk_widget_modify_style(TabCloseBtnWidget, style);
{$endif} {$endif}
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn',
TabCloseBtnWidget); TabCloseBtnWidget);
begin // put a pixmap into the button
// put a pixmap into the button {$IfDef GTK1}
{$IfDef GTK1} TabCloseBtnImageWidget:=gtk_pixmap_new(Img,Mask);
TabCloseBtnImageWidget:=gtk_pixmap_new(Img,Mask); {$Else}
{$Else} TabCloseBtnImageWidget:=gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
TabCloseBtnImageWidget:=gtk_image_new_from_pixbuf(Img); {$EndIf}
{$EndIf} gtk_object_set_data(PGtkObject(TabCloseBtnWidget),'TabCloseBtnImage',
gtk_object_set_data(PGtkObject(TabCloseBtnWidget),'TabCloseBtnImage',
TabCloseBtnImageWidget);
gtk_widget_show(TabCloseBtnImageWidget);
gtk_container_add(PGtkContainer(TabCloseBtnWidget),
TabCloseBtnImageWidget); TabCloseBtnImageWidget);
end; gtk_widget_show(TabCloseBtnImageWidget);
gtk_container_add(PGtkContainer(TabCloseBtnWidget),
TabCloseBtnImageWidget);
gtk_widget_show(TabCloseBtnWidget); gtk_widget_show(TabCloseBtnWidget);
g_signal_connect(PGtkObject(TabCloseBtnWidget), 'clicked', g_signal_connect(PGtkObject(TabCloseBtnWidget), 'clicked',
TGTKSignalFunc(@gtkNoteBookCloseBtnClicked), APage); TGTKSignalFunc(@gtkNoteBookCloseBtnClicked), APage);
gtk_box_pack_start_defaults(PGtkBox(TabWidget),TabCloseBtnWidget); gtk_box_pack_start(PGtkBox(TabWidget), TabCloseBtnWidget, False, False, 0);
end; end;
end else begin end else begin
// close buttons disabled // close buttons disabled