View Issue Details

IDProjectCategoryView StatusLast Update
0027477PatchesLCLpublic2015-02-18 21:16
Reportertheo Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.3 (SVN) 
Summary0027477: New function Gtk2_PixBufFromBitmap In gtk2wscustomlistview
DescriptionMake code shorter and better readable introducing Gtk2_PixBufFromBitmap for inline code which is repeated 3 times.

TagsNo tags attached.
Fixed in Revision47889
LazTarget-
Widgetset
Attached Files

Activities

theo

2015-02-15 18:45

reporter  

gtk2wscustomlistview.diff (6,128 bytes)   
Index: lcl/interfaces/gtk2/gtk2wscustomlistview.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2wscustomlistview.inc	(Revision 47808)
+++ lcl/interfaces/gtk2/gtk2wscustomlistview.inc	(Arbeitskopie)
@@ -23,6 +23,38 @@
   Result := (gtk_major_version = 2) and (gtk_minor_version < 10);
 end;
 
+procedure Gtk2_PixBufFromBitmap(const BitImage:TBitmap; out pixbuf:PGdkPixbuf);
+var
+GDIObj: PGDIObject;
+bitmap:PGdkBitmap;
+Width, Height:gint;
+pixmap: PGdkPixmap;
+begin
+GDIObj := {%H-}PGDIObject(BitImage.Handle);
+  case GDIObj^.GDIBitmapType of
+    gbBitmap:
+      begin
+        bitmap := GDIObj^.GDIBitmapObject;
+        gdk_drawable_get_size(bitmap, @Width, @Height);
+        pixbuf := CreatePixbufFromDrawable(bitmap, nil, False, 0, 0, 0, 0, Width, Height);
+      end;
+    gbPixmap:
+      begin
+        pixmap := GDIObj^.GDIPixmapObject.Image;
+        if pixmap <> nil then
+        begin
+          gdk_drawable_get_size(pixmap, @Width, @Height);
+          bitmap := CreateGdkMaskBitmap(BitImage.Handle, 0);
+          pixbuf := CreatePixbufFromImageAndMask(pixmap, 0, 0, Width, Height, nil, Bitmap);
+        end;
+      end;
+    gbPixbuf:
+      begin
+        pixbuf := gdk_pixbuf_copy(GDIObj^.GDIPixbufObject);
+      end;
+  end;
+end;
+
 procedure Gtk2_ItemCheckedChanged(renderer: PGtkCellRendererToggle; PathStr: Pgchar; WidgetInfo: PWidgetInfo);cdecl;
 var
   LV: TLVHack;
@@ -398,11 +430,7 @@
   APath: PGtkTreePath;
   ImageList: TCustomImageList;
   Bmp: TBitmap;
-  GDIObj: PGDIObject;
-  ABitmap: PGdkBitmap;
   pixbuf: PGdkPixbuf;
-  pixmap: PGdkPixmap;
-  AWidth, AHeight: gint;
 begin
   PGtkCellRendererPixbuf(cell)^.pixbuf := nil;
   Widgets := PTVWidgets(WidgetInfo^.UserData);
@@ -445,29 +473,7 @@
     try
       pixbuf := nil;
       ImageList.GetBitmap(ImageIndex, Bmp);
-      GDIObj := {%H-}PGDIObject(Bmp.Handle);
-      case GDIObj^.GDIBitmapType of
-        gbBitmap:
-          begin
-            ABitmap := GDIObj^.GDIBitmapObject;
-            gdk_drawable_get_size(ABitmap, @AWidth, @AHeight);
-            pixbuf := CreatePixbufFromDrawable(ABitmap, nil, False, 0, 0, 0, 0, AWidth, AHeight);
-          end;
-        gbPixmap:
-          begin
-            pixmap := GDIObj^.GDIPixmapObject.Image;
-            if pixmap <> nil then
-            begin
-              gdk_drawable_get_size(pixmap, @AWidth, @AHeight);
-              ABitmap := CreateGdkMaskBitmap(Bmp.Handle, 0);
-              pixbuf := CreatePixbufFromImageAndMask(pixmap, 0, 0, AWidth, AHeight, nil, ABitmap);
-            end;
-          end;
-        gbPixbuf:
-          begin
-            pixbuf := gdk_pixbuf_copy(GDIObj^.GDIPixbufObject);
-          end;
-      end;
+      Gtk2_PixBufFromBitmap(Bmp,pixbuf);
       PGtkCellRendererPixbuf(cell)^.pixbuf :=pixbuf;
     finally
       Bmp.Free;
@@ -1385,13 +1391,8 @@
   Widgets: PTVWidgets;
   Path: PGtkTreePath;
   ItemRect: TGdkRectangle;
-
   BitImage: TBitmap;
-  GDIObj: PGDIObject;
   pixbuf: PGDKPixBuf;
-  pixmap: PGdkDrawable;
-  bitmap: PGdkBitmap;
-  Width, Height: integer;
   i: Integer;
   ImgList: TImageList;
 
@@ -1445,29 +1446,7 @@
             BitImage := TBitmap.Create;
             try
               ImgList.GetBitmap(AImageIndex, BitImage);
-              GDIObj := {%H-}PGDIObject(BitImage.Handle);
-              case GDIObj^.GDIBitmapType of
-                gbBitmap:
-                  begin
-                    bitmap := GDIObj^.GDIBitmapObject;
-                    gdk_drawable_get_size(bitmap, @Width, @Height);
-                    pixbuf := CreatePixbufFromDrawable(bitmap, nil, False, 0, 0, 0, 0, Width, Height);
-                  end;
-                gbPixmap:
-                  begin
-                    pixmap := GDIObj^.GDIPixmapObject.Image;
-                    if pixmap <> nil then
-                    begin
-                      gdk_drawable_get_size(pixmap, @Width, @Height);
-                      bitmap := CreateGdkMaskBitmap(BitImage.Handle, 0);
-                      pixbuf := CreatePixbufFromImageAndMask(pixmap, 0, 0, Width, Height, nil, Bitmap);
-                    end;
-                  end;
-                gbPixbuf:
-                  begin
-                    pixbuf := gdk_pixbuf_copy(GDIObj^.GDIPixbufObject);
-                  end;
-              end;
+              Gtk2_PixBufFromBitmap(BitImage,pixbuf);
               Widgets^.Images.Items[AImageIndex] := pixbuf;
               if GTK_IS_TREE_VIEW(MainView) then
                 gtk_tree_view_column_queue_resize(gtk_tree_view_get_column(PGtkTreeView(MainView), ASubIndex));
@@ -2178,11 +2157,7 @@
 var
   Widgets: PTVWidgets;
   BitImage: TBitmap;
-  GDIObj: PGDIObject;
   pixbuf: PGDKPixBuf;
-  pixmap: PGdkDrawable;
-  bitmap: PGdkBitmap;
-  Width, Height: integer;
   i: Integer;
   APGList: PGList;
   pixrenderer: PGtkCellRenderer;
@@ -2221,29 +2196,7 @@
       BitImage := TBitmap.Create;
       try
         AValue.GetBitmap(i, BitImage);
-        GDIObj := {%H-}PGDIObject(BitImage.Handle);
-        case GDIObj^.GDIBitmapType of
-          gbBitmap:
-            begin
-              bitmap := GDIObj^.GDIBitmapObject;
-              gdk_drawable_get_size(bitmap, @Width, @Height);
-              pixbuf := CreatePixbufFromDrawable(bitmap, nil, False, 0, 0, 0, 0, Width, Height);
-            end;
-          gbPixmap:
-            begin
-              pixmap := GDIObj^.GDIPixmapObject.Image;
-              if pixmap <> nil then
-              begin
-                gdk_drawable_get_size(pixmap, @Width, @Height);
-                bitmap := CreateGdkMaskBitmap(BitImage.Handle, 0);
-                pixbuf := CreatePixbufFromImageAndMask(pixmap, 0, 0, Width, Height, nil, Bitmap);
-              end;
-            end;
-          gbPixbuf:
-            begin
-              pixbuf := gdk_pixbuf_copy(GDIObj^.GDIPixbufObject);
-            end;
-        end;
+        Gtk2_PixBufFromBitmap(BitImage, pixbuf);
         if GTK_IS_TREE_VIEW(Widgets^.MainView) and (TLVHack(ALV).Columns.Count > 0) and
           not TLVHack(ALV).OwnerDraw then
         begin
gtk2wscustomlistview.diff (6,128 bytes)   

Zeljan Rikalo

2015-02-18 20:35

developer   ~0081221

Please test and close if ok. Thanks for the patch.

theo

2015-02-18 21:16

reporter   ~0081223

Thank you!

Issue History

Date Modified Username Field Change
2015-02-15 18:45 theo New Issue
2015-02-15 18:45 theo File Added: gtk2wscustomlistview.diff
2015-02-15 20:28 Zeljan Rikalo Assigned To => Zeljan Rikalo
2015-02-15 20:28 Zeljan Rikalo Status new => assigned
2015-02-18 20:35 Zeljan Rikalo Fixed in Revision => 47889
2015-02-18 20:35 Zeljan Rikalo LazTarget => -
2015-02-18 20:35 Zeljan Rikalo Note Added: 0081221
2015-02-18 20:35 Zeljan Rikalo Status assigned => resolved
2015-02-18 20:35 Zeljan Rikalo Resolution open => fixed
2015-02-18 21:16 theo Note Added: 0081223
2015-02-18 21:16 theo Status resolved => closed