Back to index

unity  6.0.0
PlacesGroup.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 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: Gordon Allott <gord.allott@canonical.com>
00018  */
00019 
00020 #ifndef UNITYSHELL_PLACES_GROUP_H
00021 #define UNITYSHELL_PLACES_GROUP_H
00022 
00023 #include <Nux/Nux.h>
00024 #include <Nux/VLayout.h>
00025 #include <Nux/HLayout.h>
00026 #include <Nux/TextureArea.h>
00027 #include <UnityCore/GLibSource.h>
00028 
00029 #include "AbstractPlacesGroup.h"
00030 #include "unity-shared/IconTexture.h"
00031 #include "unity-shared/Introspectable.h"
00032 #include "unity-shared/StaticCairoText.h"
00033 #include "unity-shared/UBusWrapper.h"
00034 #include "ResultView.h"
00035 
00036 namespace nux
00037 {
00038 class AbstractPaintLayer;
00039 }
00040 
00041 namespace unity
00042 {
00043 
00044 
00045 class HSeparator;
00046 
00047 class PlacesGroup : public dash::AbstractPlacesGroup, public debug::Introspectable
00048 {
00049   NUX_DECLARE_OBJECT_TYPE(PlacesGroup, dash::AbstractPlacesGroup);
00050 public:
00051 
00052   PlacesGroup();
00053 
00054   void SetIcon(std::string const& icon);
00055   void SetName(std::string const& name);
00056 
00057   nux::StaticCairoText* GetLabel();
00058   nux::StaticCairoText* GetExpandLabel();
00059 
00060   void SetChildView(dash::ResultView* view);
00061   nux::View* GetChildView();
00062 
00063   void SetChildLayout(nux::Layout* layout);
00064 
00065   void Relayout();
00066 
00067   void SetCounts(guint n_visible_items_in_unexpand_mode, guint n_total_items);
00068 
00069   void SetExpanded(bool is_expanded);
00070   bool GetExpanded() const;
00071 
00072   int  GetHeaderHeight() const;
00073   bool HeaderIsFocusable() const;
00074   nux::View* GetHeaderFocusableView() const;
00075 
00076   sigc::signal<void, PlacesGroup*> expanded;
00077 
00078 protected:
00079   long ComputeContentSize();
00080   void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw);
00081   void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw);
00082   void PostDraw (nux::GraphicsEngine &graphics_engine, bool force_draw);
00083 
00084   // Key navigation
00085   virtual bool AcceptKeyNavFocus();
00086 
00087   // Introspection
00088   virtual std::string GetName() const;
00089   virtual void AddProperties(GVariantBuilder* builder);
00090 
00091 private:
00092   void Refresh();
00093 
00094   bool HeaderHasKeyFocus() const;
00095   bool ShouldBeHighlighted() const;
00096 
00097   void DrawSeparatorChanged(bool draw);
00098   void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00099   void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
00100   void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
00101   void OnLabelActivated(nux::Area* label);
00102   void OnLabelFocusChanged(nux::Area* label, bool has_focus, nux::KeyNavDirection direction);
00103   bool OnIdleRelayout();
00104   void RefreshLabel();
00105 
00106 private:
00107   nux::VLayout* _group_layout;
00108   nux::View* _header_view;
00109   nux::HLayout* _header_layout;
00110   nux::HLayout* _text_layout;
00111   nux::HLayout* _expand_label_layout;
00112   nux::HLayout* _expand_layout;
00113   nux::View*  _child_view;
00114   nux::ObjectPtr<nux::HLayout> separator_layout_;
00115   HSeparator* separator_;
00116   std::unique_ptr<nux::AbstractPaintLayer> _focus_layer;
00117 
00118   IconTexture*          _icon;
00119   nux::StaticCairoText* _name;
00120   nux::StaticCairoText* _expand_label;
00121   IconTexture*          _expand_icon;
00122 
00123   bool  _is_expanded;
00124   guint _n_visible_items_in_unexpand_mode;
00125   guint _n_total_items;
00126   std::string _cached_name;
00127   nux::Geometry _cached_geometry;
00128 
00129   glib::Source::UniquePtr _relayout_idle;
00130   UBusManager _ubus;
00131 };
00132 
00133 }
00134 
00135 #endif