use GtkImage and Pixbuf for GTK2 instead of Deprecated GtkPixmap

git-svn-id: trunk@4659 -
This commit is contained in:
ajgenius 2003-09-22 15:34:07 +00:00
parent 5f08b0ed8e
commit 350ec0ab81
2 changed files with 141 additions and 46 deletions

View File

@ -46,6 +46,12 @@ interface
{off $Define Disable_GC_SysColors} {off $Define Disable_GC_SysColors}
{$IFDEF gtk2}
{$IFDEF NoGdkPixbufLib}
{$UNDEF NoGdkPixbufLib}
{$EndIF}
{$EndIF}
uses uses
InterfaceBase, InterfaceBase,
{$IFDEF gtk2} {$IFDEF gtk2}
@ -73,9 +79,13 @@ type
FRCFileAge: integer; FRCFileAge: integer;
FWidgetsWithResizeRequest: TDynHashArray; // hasharray of PGtkWidget FWidgetsWithResizeRequest: TDynHashArray; // hasharray of PGtkWidget
FGTKToolTips: PGtkToolTips; FGTKToolTips: PGtkToolTips;
{$IFDef GTK1}
FNoteBookCloseBtnPixmapImg: PGdkPixmap; FNoteBookCloseBtnPixmapImg: PGdkPixmap;
FNoteBookCloseBtnPixmapMask: PGdkPixmap; FNoteBookCloseBtnPixmapMask: PGdkPixmap;
{$Else}
FNoteBookCloseBtnPixbuf : PGdkPixbuf;
{$EndIf}
FStockNullBrush: HBRUSH; FStockNullBrush: HBRUSH;
FStockBlackBrush: HBRUSH; FStockBlackBrush: HBRUSH;
FStockLtGrayBrush: HBRUSH; FStockLtGrayBrush: HBRUSH;
@ -156,6 +166,10 @@ type
// images // images
procedure LoadXPMFromLazResource(const ResourceName: string; procedure LoadXPMFromLazResource(const ResourceName: string;
Window: PGdkWindow; var PixmapImg, PixmapMask: PGdkPixmap);virtual; Window: PGdkWindow; var PixmapImg, PixmapMask: PGdkPixmap);virtual;
{$IfNDef NoGdkPixbufLib}
procedure LoadPixbufFromLazResource(const ResourceName: string;
var Pixbuf: PGdkPixbuf);
{$EndIf}
procedure LoadFromXPMFile(Bitmap: TObject; Filename: PChar);virtual; procedure LoadFromXPMFile(Bitmap: TObject; Filename: PChar);virtual;
procedure LoadFromPixbufFile(Bitmap: TObject; Filename: PChar);virtual; procedure LoadFromPixbufFile(Bitmap: TObject; Filename: PChar);virtual;
procedure LoadFromPixbufData(Bitmap : hBitmap; Data : PByte);virtual; procedure LoadFromPixbufData(Bitmap : hBitmap; Data : PByte);virtual;
@ -172,8 +186,12 @@ type
procedure ParseRCFile;virtual; procedure ParseRCFile;virtual;
// notebook // notebook
procedure GetNoteBookCloseBtnPixmap(Window: PGdkWindow; {$IFDef GTK1}
procedure GetNoteBookCloseBtnImage(Window: PGdkWindow;
var Img, Mask: PGdkPixmap);virtual; var Img, Mask: PGdkPixmap);virtual;
{$Else}
procedure GetNoteBookCloseBtnImage(var Img: PGdkPixbuf);virtual;
{$EndIF}
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);virtual; procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);virtual;
procedure RemoveDummyNoteBookPage(NoteBookWidget: PGtkNotebook);virtual; procedure RemoveDummyNoteBookPage(NoteBookWidget: PGtkNotebook);virtual;
procedure UpdateNotebookPageTab(ANoteBook, APage: TObject);virtual; procedure UpdateNotebookPageTab(ANoteBook, APage: TObject);virtual;
@ -368,6 +386,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.151 2003/09/22 15:34:07 ajgenius
use GtkImage and Pixbuf for GTK2 instead of Deprecated GtkPixmap
Revision 1.150 2003/09/20 13:27:49 mattias Revision 1.150 2003/09/20 13:27:49 mattias
varois improvements for ParentColor from Micha varois improvements for ParentColor from Micha

View File

@ -6146,14 +6146,42 @@ begin
PixmapImg:=gdk_pixmap_create_from_xpm_d(Window,PixmapMask,nil,ImgData); PixmapImg:=gdk_pixmap_create_from_xpm_d(Window,PixmapMask,nil,ImgData);
FreeMem(ImgData); FreeMem(ImgData);
end; end;
{------------------------------------------------------------------------------- {-------------------------------------------------------------------------------
method TGtkObject GetNoteBookCloseBtnPixmap method TGtkObject LoadPixbufFromLazResource
Params: ANoteBook: TCustomNotebook; APage: TCustomPage Params: const ResourceName: string;
var Pixbuf: PGdkPixbuf
Result: none Result: none
Loads the pixmap for the close button in the tabs of the TCustomNoteBook(s). Loads a pixbuf from a lazarus resource. The resource must be a XPM file.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TgtkObject.GetNoteBookCloseBtnPixmap(Window: PGdkWindow; {$IfNDef NoGdkPixbufLib}
procedure TGtkObject.LoadPixbufFromLazResource(const ResourceName: string;
var Pixbuf: PGdkPixbuf);
var
ImgData: PPChar;
begin
Pixbuf:=nil;
try
ImgData:=LazResourceXPMToPPChar(ResourceName);
except
on e: Exception do
writeln('WARNING: TGtkObject.LoadXPMFromLazResource: '+e.Message);
end;
pixbuf:=gdk_pixbuf_new_from_xpm_data(ImgData);
FreeMem(ImgData);
end;
{$EndIF}
{-------------------------------------------------------------------------------
method TGtkObject GetNoteBookCloseBtnImage
Params:
Result: none
Loads the image for the close button in the tabs of the TCustomNoteBook(s).
-------------------------------------------------------------------------------}
{$IfDef GTK1}
procedure TgtkObject.GetNoteBookCloseBtnImage(Window: PGdkWindow;
var Img, Mask: PGdkPixmap); var Img, Mask: PGdkPixmap);
begin begin
if (FNoteBookCloseBtnPixmapImg=nil) if (FNoteBookCloseBtnPixmapImg=nil)
@ -6164,6 +6192,14 @@ begin
Img:=FNoteBookCloseBtnPixmapImg; Img:=FNoteBookCloseBtnPixmapImg;
Mask:=FNoteBookCloseBtnPixmapMask; Mask:=FNoteBookCloseBtnPixmapMask;
end; end;
{$Else}
procedure TgtkObject.GetNoteBookCloseBtnImage(var Img: PGdkPixbuf);
begin
if (FNoteBookCloseBtnPixbuf=nil) then
LoadPixbufFromLazResource('tnotebook_close_tab', FNoteBookCloseBtnPixbuf);
Img:=FNoteBookCloseBtnPixbuf;
end;
{$EndIF}
{------------------------------------------------------------------------------- {-------------------------------------------------------------------------------
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook); procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);
@ -6232,22 +6268,28 @@ var
PageWidget: PGtkWidget; // the page (content widget) PageWidget: PGtkWidget; // the page (content widget)
TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label TabWidget: PGtkWidget; // the tab (hbox containing a pixmap, a label
// and a close button) // and a close button)
TabPixmapWidget: PGtkWidget; // the pixmap in the tab TabImageWidget: PGtkWidget; // the pixmap in the tab
TabLabelWidget: PGtkWidget; // the label in the tab TabLabelWidget: PGtkWidget; // the label in the tab
TabCloseBtnWidget: PGtkWidget;// the close button in the tab TabCloseBtnWidget: PGtkWidget;// the close button in the tab
TabCloseBtnPixmapWidget: PGtkWidget; // the pixmap in the close button TabCloseBtnImageWidget: PGtkWidget; // the pixmap in the close button
MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and MenuWidget: PGtkWidget; // the popup menu (hbox containing a pixmap and
// a label) // a label)
MenuPixmapWidget: PGtkWidget;// the pixmap in the popup menu item MenuImageWidget: PGtkWidget;// the pixmap in the popup menu item
MenuLabelWidget: PGtkWidget; // the label in the popup menu item MenuLabelWidget: PGtkWidget; // the label in the popup menu item
procedure UpdateTabPixmap; procedure UpdateTabImage;
var var
{$IfDef GTK1}
Img: PGdkPixmap; Img: PGdkPixmap;
Mask: PGdkBitmap; Mask: PGdkBitmap;
{$Else}
Img: PGdkPixbuf;
{$EndIf}
begin begin
Img:=nil; Img:=nil;
{$IfDef GTK1}
Mask:=nil; Mask:=nil;
{$EndIf}
if (TheNoteBook.Images<>nil) if (TheNoteBook.Images<>nil)
and (ThePage.ImageIndex>=0) and (ThePage.ImageIndex>=0)
and (ThePage.ImageIndex<TheNoteBook.Images.Count) then begin and (ThePage.ImageIndex<TheNoteBook.Images.Count) then begin
@ -6259,47 +6301,63 @@ var
if Img<>nil then begin if Img<>nil then begin
// page has an image // page has an image
if TabPixmapWidget<>nil then begin if TabImageWidget<>nil then begin
// there is already a pixmap for the image in the tab // there is already a pixmap for the image in the tab
// -> replace the image // -> replace the image
gtk_pixmap_set(PGtkPixmap(TabPixmapWidget),Img,Mask); {$IfDef GTK1}
gtk_pixmap_set(PGtkPixmap(TabImageWidget),Img,Mask);
{$Else}
gtk_image_set_from_pixbuf(GTK_IMAGE(TabImageWidget), Img);
{$EndIf}
end else begin end else begin
// there is no pixmap for the image in the tab // there is no pixmap for the image in the tab
// -> insert one ot the left side of the label // -> insert one ot the left side of the label
TabPixmapWidget:=gtk_pixmap_new(Img,Mask); {$IfDef GTK1}
gtk_object_set_data(PGtkObject(TabWidget),'TabPixmap',TabPixmapWidget); TabImageWidget:=gtk_pixmap_new(Img,Mask);
gtk_widget_show(TabPixmapWidget); {$Else}
gtk_box_pack_start_defaults(PGtkBox(TabWidget),TabPixmapWidget); TabImageWidget:=gtk_image_new_from_pixbuf(Img);
gtk_box_reorder_child(PGtkBox(TabWidget),TabPixmapWidget,0); {$EndIf}
gtk_object_set_data(PGtkObject(TabWidget),'TabImage',TabImageWidget);
gtk_widget_show(TabImageWidget);
gtk_box_pack_start_defaults(PGtkBox(TabWidget),TabImageWidget);
gtk_box_reorder_child(PGtkBox(TabWidget),TabImageWidget,0);
end; end;
if MenuPixmapWidget<>nil then begin if MenuImageWidget<>nil then begin
// there is already a pixmap for the image in the menu // there is already a pixmap for the image in the menu
// -> replace the image // -> replace the image
gtk_pixmap_set(PGtkPixmap(MenuPixmapWidget),Img,Mask); {$IfDef GTK1}
gtk_pixmap_set(PGtkPixmap(MenuImageWidget),Img,Mask);
{$Else}
gtk_image_set_from_pixbuf(GTK_IMAGE(MenuImageWidget), Img);
{$EndIf}
end else begin end else begin
// there is no pixmap for the image in the menu // there is no pixmap for the image in the menu
// -> insert one at the left side of the label // -> insert one at the left side of the label
MenuPixmapWidget:=gtk_pixmap_new(Img,Mask); {$IfDef GTK1}
gtk_object_set_data(PGtkObject(MenuWidget),'TabPixmap',MenuPixmapWidget); MenuImageWidget:=gtk_pixmap_new(Img,Mask);
gtk_widget_show(MenuPixmapWidget); {$Else}
gtk_box_pack_start_defaults(PGtkBox(MenuWidget),MenuPixmapWidget); MenuImageWidget:=gtk_image_new_from_pixbuf(Img);
gtk_box_reorder_child(PGtkBox(MenuWidget),MenuPixmapWidget,0); {$EndIf}
gtk_object_set_data(PGtkObject(MenuWidget),'TabImage',MenuImageWidget);
gtk_widget_show(MenuImageWidget);
gtk_box_pack_start_defaults(PGtkBox(MenuWidget),MenuImageWidget);
gtk_box_reorder_child(PGtkBox(MenuWidget),MenuImageWidget,0);
end; end;
end else begin end else begin
// page does not have an image // page does not have an image
if TabPixmapWidget<>nil then begin if TabImageWidget<>nil then begin
// there is a pixmap for an old image in the tab // there is a pixmap for an old image in the tab
// -> remove the pixmap widget // -> remove the pixmap widget
DestroyWidget(TabPixmapWidget); DestroyWidget(TabImageWidget);
gtk_object_set_data(PGtkObject(TabWidget), 'TabPixmap', nil); gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
TabPixmapWidget:=nil; TabImageWidget:=nil;
end; end;
if MenuPixmapWidget<>nil then begin if MenuImageWidget<>nil then begin
// there is a pixmap for an old image in the menu // there is a pixmap for an old image in the menu
// -> remove the pixmap widget // -> remove the pixmap widget
DestroyWidget(MenuPixmapWidget); DestroyWidget(MenuImageWidget);
gtk_object_set_data(PGtkObject(MenuWidget), 'TabPixmap', nil); gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
MenuPixmapWidget:=nil; MenuImageWidget:=nil;
end; end;
end; end;
end; end;
@ -6317,9 +6375,18 @@ var
procedure UpdateTabCloseBtn; procedure UpdateTabCloseBtn;
var var
Img, Mask: PGdkPixmap; {$IfDef GTK1}
Img: PGdkPixmap;
Mask: PGdkBitmap;
{$Else}
Img: PGdkPixbuf;
{$EndIf}
begin begin
GetNoteBookCloseBtnPixmap(GetControlWindow(NoteBookWidget),Img,Mask); {$IfDef GTK1}
GetNoteBookCloseBtnImage(GetControlWindow(NoteBookWidget),Img,Mask);
{$Else}
GetNoteBookCloseBtnImage(Img);
{$EndIf}
if (nboShowCloseButtons in TheNotebook.Options) and (Img<>nil) then begin if (nboShowCloseButtons in TheNotebook.Options) and (Img<>nil) then begin
// close buttons enabled // close buttons enabled
if TabCloseBtnWidget=nil then begin if TabCloseBtnWidget=nil then begin
@ -6330,12 +6397,16 @@ var
TabCloseBtnWidget); TabCloseBtnWidget);
begin begin
// put a pixmap into the button // put a pixmap into the button
TabCloseBtnPixmapWidget:=gtk_pixmap_new(Img,Mask); {$IfDef GTK1}
gtk_object_set_data(PGtkObject(TabCloseBtnWidget),'TabCloseBtnPixmap', TabCloseBtnImageWidget:=gtk_pixmap_new(Img,Mask);
TabCloseBtnPixmapWidget); {$Else}
gtk_widget_show(TabCloseBtnPixmapWidget); TabCloseBtnImageWidget:=gtk_image_new_from_pixbuf(Img);
{$EndIf}
gtk_object_set_data(PGtkObject(TabCloseBtnWidget),'TabCloseBtnImage',
TabCloseBtnImageWidget);
gtk_widget_show(TabCloseBtnImageWidget);
gtk_container_add(PGtkContainer(TabCloseBtnWidget), gtk_container_add(PGtkContainer(TabCloseBtnWidget),
TabCloseBtnPixmapWidget); TabCloseBtnImageWidget);
end; end;
gtk_widget_show(TabCloseBtnWidget); gtk_widget_show(TabCloseBtnWidget);
g_signal_connect(PGtkObject(TabCloseBtnWidget), 'clicked', g_signal_connect(PGtkObject(TabCloseBtnWidget), 'clicked',
@ -6370,11 +6441,11 @@ begin
TabWidget:=gtk_notebook_get_tab_label(PGtkNoteBook(NotebookWidget), TabWidget:=gtk_notebook_get_tab_label(PGtkNoteBook(NotebookWidget),
PageWidget); PageWidget);
if TabWidget<>nil then begin if TabWidget<>nil then begin
TabPixmapWidget:=gtk_object_get_data(PGtkObject(TabWidget), 'TabPixmap'); TabImageWidget:=gtk_object_get_data(PGtkObject(TabWidget), 'TabImage');
TabLabelWidget:=gtk_object_get_data(PGtkObject(TabWidget), 'TabLabel'); TabLabelWidget:=gtk_object_get_data(PGtkObject(TabWidget), 'TabLabel');
TabCloseBtnWidget:=gtk_object_get_data(PGtkObject(TabWidget),'TabCloseBtn'); TabCloseBtnWidget:=gtk_object_get_data(PGtkObject(TabWidget),'TabCloseBtn');
end else begin end else begin
TabPixmapWidget:=nil; TabImageWidget:=nil;
TabLabelWidget:=nil; TabLabelWidget:=nil;
TabCloseBtnWidget:=nil; TabCloseBtnWidget:=nil;
end; end;
@ -6383,14 +6454,14 @@ begin
MenuWidget:=gtk_notebook_get_menu_label(PGtkNoteBook(NotebookWidget), MenuWidget:=gtk_notebook_get_menu_label(PGtkNoteBook(NotebookWidget),
PageWidget); PageWidget);
if MenuWidget<>nil then begin if MenuWidget<>nil then begin
MenuPixmapWidget:=gtk_object_get_data(PGtkObject(MenuWidget), 'TabPixmap'); MenuImageWidget:=gtk_object_get_data(PGtkObject(MenuWidget), 'TabImage');
MenuLabelWidget:=gtk_object_get_data(PGtkObject(MenuWidget), 'TabLabel'); MenuLabelWidget:=gtk_object_get_data(PGtkObject(MenuWidget), 'TabLabel');
end else begin end else begin
MenuPixmapWidget:=nil; MenuImageWidget:=nil;
MenuLabelWidget:=nil; MenuLabelWidget:=nil;
end; end;
UpdateTabPixmap; UpdateTabImage;
UpdateTabLabel; UpdateTabLabel;
UpdateTabCloseBtn; UpdateTabCloseBtn;
end; end;
@ -6425,7 +6496,7 @@ begin
// create the tab (hbox container) // create the tab (hbox container)
TabWidget:=gtk_hbox_new(false,1); TabWidget:=gtk_hbox_new(false,1);
begin begin
gtk_object_set_data(PGtkObject(TabWidget), 'TabPixmap', nil); gtk_object_set_data(PGtkObject(TabWidget), 'TabImage', nil);
gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil); gtk_object_set_data(PGtkObject(TabWidget), 'TabCloseBtn', nil);
// put a label into the tab // put a label into the tab
TabLabelWidget:=gtk_label_new(''); TabLabelWidget:=gtk_label_new('');
@ -6439,7 +6510,7 @@ begin
MenuWidget:=gtk_hbox_new(false,2); MenuWidget:=gtk_hbox_new(false,2);
begin begin
// put a pixmap into the menu // put a pixmap into the menu
gtk_object_set_data(PGtkObject(MenuWidget), 'TabPixmap', nil); gtk_object_set_data(PGtkObject(MenuWidget), 'TabImage', nil);
// put a label into the menu // put a label into the menu
MenuLabelWidget:=gtk_label_new(''); MenuLabelWidget:=gtk_label_new('');
gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget); gtk_object_set_data(PGtkObject(MenuWidget), 'TabLabel', MenuLabelWidget);
@ -8193,6 +8264,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.422 2003/09/22 15:34:07 ajgenius
use GtkImage and Pixbuf for GTK2 instead of Deprecated GtkPixmap
Revision 1.421 2003/09/20 13:27:49 mattias Revision 1.421 2003/09/20 13:27:49 mattias
varois improvements for ParentColor from Micha varois improvements for ParentColor from Micha