Back to index

unity  6.0.0
QuicklistView.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: Jay Taoko <jay.taoko@canonical.com>
00018  * Authored by: Mirco Müller <mirco.mueller@canonical.com
00019  */
00020 
00021 #ifndef QUICKLISTVIEW_H
00022 #define QUICKLISTVIEW_H
00023 
00024 #include <Nux/Nux.h>
00025 #include <Nux/BaseWindow.h>
00026 #include <NuxGraphics/GraphicsEngine.h>
00027 #include <Nux/TextureArea.h>
00028 #include <NuxGraphics/CairoGraphics.h>
00029 
00030 #include <pango/pango.h>
00031 #include <pango/pangocairo.h>
00032 
00033 #include "CairoBaseWindow.h"
00034 #include "QuicklistMenuItem.h"
00035 
00036 #include "unity-shared/Introspectable.h"
00037 
00038 namespace unity
00039 {
00040 
00041 class QuicklistView : public CairoBaseWindow, public debug::Introspectable
00042 {
00043   NUX_DECLARE_OBJECT_TYPE(QuicklistView, unity::CairoBaseWindow);
00044 public:
00045   QuicklistView();
00046   ~QuicklistView();
00047 
00048   void SetText(std::string const& text);
00049 
00050   void RemoveAllMenuItem();
00051 
00052   void AddMenuItem(QuicklistMenuItem* item);
00053 
00054   void RenderQuicklistView();
00055 
00056   void ShowQuicklistWithTipAt(int anchor_tip_x, int anchor_tip_y);
00057   virtual void ShowWindow(bool b, bool StartModal = false);
00058 
00059   void Show();
00060   void Hide();
00061 
00062   int GetNumItems();
00063   QuicklistMenuItem* GetNthItems(int index);
00064   QuicklistMenuItemType GetNthType(int index);
00065   int GetItemIndex(QuicklistMenuItem* item);
00066   std::list<QuicklistMenuItem*> GetChildren();
00067   void SelectFirstItem();
00068 
00069   void TestMenuItems(DbusmenuMenuitem* root);
00070 
00071   // Introspection
00072   std::string GetName() const;
00073   void AddProperties(GVariantBuilder* builder);
00074   IntrospectableList GetIntrospectableChildren();
00075 
00076   void EnableQuicklistForTesting(bool enable_testing);
00077 
00078   // Key navigation
00079   virtual bool InspectKeyEvent(unsigned int eventType,
00080                                unsigned int keysym,
00081                                const char* character);
00082 
00083   //Required for a11y
00084   QuicklistMenuItem* GetSelectedMenuItem();
00085   sigc::signal<void> selection_change;
00086 
00087 protected:
00088   void Draw(nux::GraphicsEngine& gfxContext, bool forceDraw);
00089   void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
00090 
00091 private:
00092   void RecvCairoTextChanged(QuicklistMenuItem* item);
00093   void RecvCairoTextColorChanged(QuicklistMenuItem* item);
00094   void RecvItemMouseClick(QuicklistMenuItem* item, int x, int y);
00095   void RecvItemMouseRelease(QuicklistMenuItem* item, int x, int y);
00096   void RecvItemMouseEnter(QuicklistMenuItem* item);
00097   void RecvItemMouseLeave(QuicklistMenuItem* item);
00098   void RecvItemMouseDrag(QuicklistMenuItem* item, int x, int y);
00099 
00100   void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00101   void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00102   void RecvMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00103   void RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00104   void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00105   void RecvMouseDownOutsideOfQuicklist(int x, int y, unsigned long button_flags, unsigned long key_flags);
00106 
00107   void RecvKeyPressed(unsigned long    eventType  ,   /*event type*/
00108                       unsigned long    keysym     ,   /*event keysym*/
00109                       unsigned long    state      ,   /*event state*/
00110                       const TCHAR*     character  ,   /*character*/
00111                       unsigned short   keyCount);
00112 
00113   void RecvStartFocus();
00114   void RecvEndFocus();
00115 
00116   void PreLayoutManagement();
00117 
00118   long PostLayoutManagement(long layoutResult);
00119 
00120   void PositionChildLayout(float offsetX, float offsetY);
00121 
00122   void LayoutWindowElements();
00123 
00124   void NotifyConfigurationChange(int width, int height);
00125 
00127   void FillInDefaultItems();
00128 
00129   void CancelItemsPrelightStatus();
00130 
00132   void CheckAndEmitItemSignal(int x, int y);
00133 
00134   void ActivateItem(QuicklistMenuItem* item);
00135 
00136   void SelectItem(int index);
00137   bool IsMenuItemSelectable(int index);
00138 
00139   //nux::CairoGraphics*   _cairo_graphics;
00140   int                   _anchorX;
00141   int                   _anchorY;
00142   std::string           _labelText;
00143   int                   _top_size; // size of the segment from point 13 to 14. See figure in ql_compute_full_mask_path.
00144 
00145   bool                  _mouse_down;
00146 
00147   //iIf true, suppress the Quicklist behaviour that is expected in Unity.
00148   // Keep the Quicklist on screen for testing and automation.
00149   bool                  _enable_quicklist_for_testing;
00150 
00151   float _anchor_width;
00152   float _anchor_height;
00153   float _corner_radius;
00154   float _padding;
00155   float _left_padding_correction;
00156   float _bottom_padding_correction_normal;
00157   float _bottom_padding_correction_single_item;
00158   float _offset_correction;
00159   nux::HLayout* _hlayout;
00160   nux::VLayout* _vlayout;
00161   nux::VLayout* _item_layout;
00162   nux::SpaceLayout* _left_space;  
00163   nux::SpaceLayout* _right_space; 
00164   nux::SpaceLayout* _top_space;  
00165   nux::SpaceLayout* _bottom_space; 
00166 
00167   bool _cairo_text_has_changed;
00168   void UpdateTexture();
00169   std::list<QuicklistMenuItem*> _item_list;
00170 
00171   // used by keyboard/a11y-navigation
00172   int _current_item_index;
00173 
00174   // list of introspectable children, used to return children in the correct order:
00175   IntrospectableList _introspectable_children;
00176 };
00177 
00178 } // NAMESPACE
00179 #endif // QUICKLISTVIEW_H