Back to index

unity  6.0.0
QuicklistMenuItem.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Mirco Müller <mirco.mueller@canonical.com>
00018  * Authored by: Jay Taoko <jay.taoko@canonical.com>
00019  */
00020 
00021 #ifndef QUICKLISTMENUITEM_H
00022 #define QUICKLISTMENUITEM_H
00023 
00024 #include <libdbusmenu-glib/menuitem.h>
00025 #include <libdbusmenu-glib/client.h>
00026 
00027 #include <Nux/Nux.h>
00028 #include <Nux/View.h>
00029 #include <NuxGraphics/CairoGraphics.h>
00030 
00031 #include <pango/pango.h>
00032 #include <pango/pangocairo.h>
00033 
00034 #include "unity-shared/Introspectable.h"
00035 
00036 namespace unity
00037 {
00038 
00039 enum QuicklistMenuItemType
00040 {
00041   MENUITEM_TYPE_UNKNOWN = 0,
00042   MENUITEM_TYPE_LABEL,
00043   MENUITEM_TYPE_SEPARATOR,
00044   MENUITEM_TYPE_CHECK,
00045   MENUITEM_TYPE_RADIO,
00046 };
00047 
00048 class QuicklistMenuItem : public nux::View, public debug::Introspectable
00049 {
00050   NUX_DECLARE_OBJECT_TYPE(QuicklistMenuItem, nux::View);
00051 public:
00052   QuicklistMenuItem(DbusmenuMenuitem* item,
00053                     NUX_FILE_LINE_PROTO);
00054 
00055   QuicklistMenuItem(DbusmenuMenuitem* item,
00056                     bool              debug,
00057                     NUX_FILE_LINE_PROTO);
00058 
00059   virtual ~QuicklistMenuItem();
00060 
00061   void PreLayoutManagement();
00062 
00063   long PostLayoutManagement(long layoutResult);
00064 
00065   void Draw(nux::GraphicsEngine& gfxContext,
00066             bool                 forceDraw);
00067 
00068   void DrawContent(nux::GraphicsEngine& gfxContext,
00069                    bool                 forceDraw);
00070 
00071   void PostDraw(nux::GraphicsEngine& gfxContext,
00072                 bool                 forceDraw);
00073 
00074   QuicklistMenuItemType GetItemType();
00075 
00076   void ItemActivated();
00077   void EnableLabelMarkup(bool enabled);
00078   bool IsMarkupEnabled();
00079 
00080   sigc::signal<void, QuicklistMenuItem&> sigChanged;
00081   sigc::signal<void, QuicklistMenuItem*> sigTextChanged;
00082   sigc::signal<void, QuicklistMenuItem*> sigColorChanged;
00083 
00084   virtual const gchar* GetLabel();
00085   virtual bool GetEnabled();
00086   virtual bool GetActive();
00087   virtual bool GetVisible();
00088   virtual bool GetSelectable();
00089 
00090 protected:
00091   // Introspection
00092   std::string GetName() const;
00093   void AddProperties(GVariantBuilder* builder);
00094 
00095   static const int ITEM_INDENT_ABS = 16;
00096   static const int ITEM_CORNER_RADIUS_ABS = 3;
00097   static const int ITEM_MARGIN = 4;
00098 
00099   std::string           _text;
00100   nux::Color            _textColor;
00101   int                   _pre_layout_width;
00102   int                   _pre_layout_height;
00103   nux::CairoGraphics*   _cairoGraphics;
00104 
00105   nux::BaseTexture*     _normalTexture[2];
00106   nux::BaseTexture*     _prelightTexture[2];
00107 
00108   void Initialize(DbusmenuMenuitem* item, bool debug);
00109   void InitializeText();
00110   virtual const gchar* GetDefaultText();
00111 
00112   gchar* GetText();
00114   void GetTextExtents(int& width, int& height);
00115   void GetTextExtents(const gchar* font, int& width, int& height);
00116   virtual void UpdateTexture() = 0;
00117   virtual int CairoSurfaceWidth() = 0;
00118 
00119   void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
00120   void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
00121   void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00122   void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00123   void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00124 
00125   sigc::signal<void, QuicklistMenuItem*> sigMouseEnter;
00126   sigc::signal<void, QuicklistMenuItem*> sigMouseLeave;
00127   sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseReleased;
00128   sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseClick;
00129   sigc::signal<void, QuicklistMenuItem*, int, int> sigMouseDrag;
00130 
00131   DbusmenuMenuitem* _menuItem;
00132   QuicklistMenuItemType _item_type;
00133 
00134   nux::Color        _color;   
00135   bool              _debug;
00136 
00137   bool _prelight;   
00138 
00139   void DrawText(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color);
00140   void DrawPrelight(nux::CairoGraphics* cairo, int width, int height, nux::Color const& color);
00141 
00142   // Introspection
00143   std::string _name;
00144 
00145   friend class QuicklistView;
00146 };
00147 
00148 } // NAMESPACE
00149 
00150 #endif // QUICKLISTMENUITEM_H