Back to index

unity  6.0.0
ResultViewGrid.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser 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, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Gordon Allott <gord.allott@canonical.com>
00020  *
00021  */
00022 
00023 #ifndef UNITYSHELL_RESULTVIEWGRID_H
00024 #define UNITYSHELL_RESULTVIEWGRID_H
00025 
00026 #include <UnityCore/Categories.h>
00027 #include <UnityCore/GLibSource.h>
00028 
00029 #include "ResultView.h"
00030 #include "unity-shared/UBusWrapper.h"
00031 
00032 namespace unity
00033 {
00034 namespace dash
00035 {
00036 
00037 // will order its elements in to a grid that expands horizontally before vertically
00038 class ResultViewGrid : public ResultView
00039 {
00040 public:
00041   NUX_DECLARE_OBJECT_TYPE(ResultViewGrid, ResultView);
00042 
00043   ResultViewGrid(NUX_FILE_LINE_DECL);
00044 
00045   void SetModelRenderer(ResultRenderer* renderer);
00046   void AddResult(Result& result);
00047   void RemoveResult(Result& result);
00048 
00049   nux::Property<int> horizontal_spacing;
00050   nux::Property<int> vertical_spacing;
00051   nux::Property<int> padding;
00052 
00053   sigc::signal<void> selection_change;
00054 
00055   int GetSelectedIndex();
00056   virtual uint GetIndexAtPosition(int x, int y);
00057 
00058 protected:
00059   void MouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00060   void MouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00061 
00062   virtual bool                    DndSourceDragBegin();
00063   virtual nux::NBitmapData*       DndSourceGetDragImage();
00064   virtual std::list<const char*>  DndSourceGetDragTypes();
00065   virtual const char*             DndSourceGetDataForType(const char* type, int* size, int* format);
00066   virtual void                    DndSourceDragFinished(nux::DndAction result);
00067 
00068   virtual bool InspectKeyEvent(unsigned int eventType, unsigned int keysym, const char* character);
00069   virtual bool AcceptKeyNavFocus();
00070   virtual nux::Area* KeyNavIteration(nux::KeyNavDirection direction);
00071   virtual void OnKeyNavFocusChange(nux::Area* area, bool has_focus, nux::KeyNavDirection direction);
00072   void OnKeyDown(unsigned long event_type, unsigned long event_keysym, unsigned long event_state, const TCHAR* character, unsigned short key_repeat_count);
00073 
00074   virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);;
00075   virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
00076   virtual long ComputeContentSize();
00077 
00078 private:
00079   typedef std::tuple <int, int> ResultListBounds;
00080   ResultListBounds GetVisableResults();
00081 
00082   void QueueLazyLoad();
00083   void QueueViewChanged();
00084   bool DoLazyLoad();
00085 
00086   int GetItemsPerRow();
00087   void SizeReallocate();
00088 
00089   uint mouse_over_index_;
00090   int active_index_;
00091   nux::Property<int> selected_index_;
00092   std::string focused_uri_;
00093 
00094   int last_lazy_loaded_result_;
00095   int last_mouse_down_x_;
00096   int last_mouse_down_y_;
00097   std::string current_drag_uri_;
00098   std::string current_drag_icon_name_;
00099 
00100   int recorded_dash_width_;
00101   int recorded_dash_height_;
00102 
00103   int mouse_last_x_;
00104   int mouse_last_y_;
00105 
00106   int extra_horizontal_spacing_;
00107 
00108   UBusManager ubus_;
00109   glib::Source::UniquePtr lazy_load_source_;
00110   glib::Source::UniquePtr view_changed_idle_;
00111 };
00112 
00113 } // namespace dash
00114 } // namespace unity
00115 
00116 #endif // UNITYSHELL_RESULTVIEWGRID_H