[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Boxygen-gtk/1=2E0=5D_src=3A_Moved_tabCloseButton_pix?=
From:       Hugo Pereira Da Costa <hugo () oxygen-icons ! org>
Date:       2011-02-01 9:57:31
Message-ID: 20110201095731.108EFA609B () git ! kde ! org
[Download RAW message or body]

Git commit 0f57942804da7499b6458c8525b8607bd4379317 by Hugo Pereira Da Costa.
Committed on 01/02/11 at 10:48.
Pushed by hpereiradacosta into branch '1.0'.

Moved tabCloseButton pixbufs to Oxygen::Style.

This prevents usage of static pixbufs, and makes sure they are properly unref'ed at \
                destruction.
TODO: these should be moved to cairo_surface_t.

M  +58   -4    src/oxygenstyle.cpp     
M  +39   -2    src/oxygenstyle.h     
M  +7    -51   src/oxygenstylewrapper.cpp     

http://commits.kde.org/oxygen-gtk/0f57942804da7499b6458c8525b8607bd4379317

diff --git a/src/oxygenstyle.cpp b/src/oxygenstyle.cpp
index 0db116e..6b684f2 100644
--- a/src/oxygenstyle.cpp
+++ b/src/oxygenstyle.cpp
@@ -46,10 +46,6 @@ namespace Oxygen
     }
 
     //__________________________________________________________________
-    Style::Style( void )
-    {}
-
-    //__________________________________________________________________
     void Style::initialize( void )
     {
         _settings.initialize();
@@ -66,6 +62,64 @@ namespace Oxygen
     }
 
     //__________________________________________________________________
+    GdkPixbuf* Style::tabCloseButton( const StyleOptions& options )
+    {
+
+        // active tab
+        GError* err( 0L );
+        if( options&Focus )
+        {
+            // create button
+            if( !_tabCloseButtons.active )
+            {
+                const std::string filename( std::string(GTK_THEME_DIR)+ \
"/special-icons/standardbutton-closetab-down-16.png" ); +                \
_tabCloseButtons.active = gdk_pixbuf_new_from_file( filename.c_str(), &err ); +            }
+
+            return _tabCloseButtons.active;
+        }
+
+        // prelight
+        if( options&Hover )
+        {
+            // create button
+            if( !_tabCloseButtons.prelight )
+            {
+                const std::string filename( std::string(GTK_THEME_DIR) + \
"/special-icons/standardbutton-closetab-hover-16.png" ); +                \
_tabCloseButtons.prelight = gdk_pixbuf_new_from_file( filename.c_str(), &err ); +            }
+
+            return _tabCloseButtons.prelight;
+
+        }
+
+        // normal or inactive
+        if( !_tabCloseButtons.normal )
+        {
+            const std::string filename( std::string(GTK_THEME_DIR) + \
"/special-icons/standardbutton-closetab-16.png" ); +            _tabCloseButtons.normal = \
gdk_pixbuf_new_from_file( filename.c_str(), &err ); +        }
+
+        // inactive
+        if( (options&Disabled) && _tabCloseButtons.normal )
+        {
+
+            if( !_tabCloseButtons.inactive )
+            {
+                _tabCloseButtons.inactive = Gtk::gdk_pixbuf_set_alpha( \
_tabCloseButtons.normal, 0.5 ); +                gdk_pixbuf_saturate_and_pixelate( \
_tabCloseButtons.inactive, _tabCloseButtons.inactive , 0.1, false ); +            }
+
+            return _tabCloseButtons.inactive;
+
+        }
+
+        // fallback to normal
+        return _tabCloseButtons.normal;
+
+    }
+
+    //__________________________________________________________________
     void Style::fill( GdkWindow* window, GdkRectangle* clipRect, gint x, gint y, gint w, gint \
h, const ColorUtils::Rgba& color ) const  {
 
diff --git a/src/oxygenstyle.h b/src/oxygenstyle.h
index 552f644..8409540 100644
--- a/src/oxygenstyle.h
+++ b/src/oxygenstyle.h
@@ -51,7 +51,7 @@ namespace Oxygen
 
         //! destructor
         virtual ~Style( void )
-        { _instance = 0L; }
+        {}
 
         //! initialize
         void initialize( void );
@@ -88,6 +88,9 @@ namespace Oxygen
         WindowManager& windowManager( void )
         { return _windowManager; }
 
+        //! return tabCloseButton for given set of options
+        GdkPixbuf* tabCloseButton( const StyleOptions& );
+
         //!@name primitives
         //@{
 
@@ -291,7 +294,8 @@ namespace Oxygen
         protected:
 
         //! constructor
-        explicit Style( void );
+        explicit Style( void )
+        {}
 
         //! get color matching role from either style option or default palette
         const ColorUtils::Rgba& color( Palette::Role role, const StyleOptions& option ) const
@@ -408,6 +412,39 @@ namespace Oxygen
         //! window manager
         WindowManager _windowManager;
 
+        //! Tab close buttons
+        class TabCloseButtons
+        {
+            public:
+
+            //! constructor
+            TabCloseButtons( void ):
+                normal(0L),
+                active(0L),
+                inactive(0L),
+                prelight(0L)
+            {}
+
+            //! destructor
+            virtual ~TabCloseButtons( void )
+            {
+
+                if( normal ) g_object_unref( normal );
+                if( active ) g_object_unref( active );
+                if( inactive ) g_object_unref( inactive );
+                if( prelight ) g_object_unref( prelight );
+
+            }
+
+            GdkPixbuf* normal;
+            GdkPixbuf* active;
+            GdkPixbuf* inactive;
+            GdkPixbuf* prelight;
+        };
+
+        //! Tab close buttons
+        TabCloseButtons _tabCloseButtons;
+
         //! singleton
         static Style* _instance;
 
diff --git a/src/oxygenstylewrapper.cpp b/src/oxygenstylewrapper.cpp
index 324f0e1..b78a557 100644
--- a/src/oxygenstylewrapper.cpp
+++ b/src/oxygenstylewrapper.cpp
@@ -503,23 +503,11 @@ namespace Oxygen
         std::cout << "Oxygen::processTabCloseButton" << std::endl;
         #endif
 
-        static GdkPixbuf* pbNormalColored(0L);
-        static GdkPixbuf* pbNormalGray(0L);
-        static GdkPixbuf* pbPrelight(0L);
-        static GdkPixbuf* pbActive(0L);
-        GdkPixbuf* toDraw( 0L );
-        GError* err( 0L );
         switch (state)
         {
             case GTK_STATE_NORMAL:
             {
 
-                if(!pbNormalColored)
-                {
-                    std::string buttonIconName = std::string(GTK_THEME_DIR) + \
                "/special-icons/standardbutton-closetab-16.png";
-                    pbNormalColored=gdk_pixbuf_new_from_file(buttonIconName.c_str(),&err);
-                }
-
                 // check if our button is on active page and if not, make it gray
                 GtkNotebook* notebook=GTK_NOTEBOOK(Gtk::gtk_parent_notebook(widget));
                 GtkWidget* \
page=gtk_notebook_get_nth_page(notebook,gtk_notebook_get_current_page(notebook)); @@ -528,55 \
                +516,23 @@ namespace Oxygen
                 GtkWidget* tabLabel=gtk_notebook_get_tab_label(notebook,page);
                 if( !tabLabel ) break;
 
-                if( !Gtk::gtk_widget_is_parent( widget, tabLabel ) )
-                {
-                    pbNormalGray = Gtk::gdk_pixbuf_set_alpha(pbNormalColored, 0.5);
-                    gdk_pixbuf_saturate_and_pixelate( pbNormalGray, pbNormalGray , 0.1, false \
                );
-                    toDraw=pbNormalGray;
-                }
-                else toDraw = pbNormalColored;
-            }
-
-            break;
-
-            case GTK_STATE_ACTIVE:
-            {
-                if(!pbActive) {
-
-                    std::string buttonIconName = std::string(GTK_THEME_DIR)+ \
                "/special-icons/standardbutton-closetab-down-16.png";
-                    pbActive = gdk_pixbuf_new_from_file(buttonIconName.c_str(),&err);
+                if( !Gtk::gtk_widget_is_parent( widget, tabLabel ) ) return \
Style::instance().tabCloseButton( Disabled ); +                else return \
Style::instance().tabCloseButton( StyleOptions() );  
-                }
-
-                if(pbActive) toDraw = pbActive;
             }
 
             break;
 
-            case GTK_STATE_PRELIGHT:
-            {
-                if(!pbPrelight)
-                {
-                    std::string buttonIconName = std::string(GTK_THEME_DIR) + \
                "/special-icons/standardbutton-closetab-hover-16.png";
-                    pbPrelight = gdk_pixbuf_new_from_file(buttonIconName.c_str(),&err);
-                }
-                if(pbPrelight) toDraw = pbPrelight;
-            }
-
-            break;
-
-            default:
-            toDraw = 0L;
-            break;
+            case GTK_STATE_ACTIVE: return Style::instance().tabCloseButton( Focus );
+            case GTK_STATE_PRELIGHT: return Style::instance().tabCloseButton( Hover );
+            default: break;
 
         }
 
-        // TODO: should the error be deallocated ?
-        if( err )
-        { std::cerr << "Oxygen::processTabCloseButton - " << err->message << std::endl; }
+        return 0L;
 
-        return toDraw;
     }
+
     //___________________________________________________________________________________________________________
  static void draw_box( GtkStyle* style,
         GdkWindow* window,


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic