Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
listareaimpl.hh
Go to the documentation of this file.
00001 /* Rapicorn
00002  * Copyright (C) 2008 Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library 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 GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * A copy of the GNU Lesser General Public License should ship along
00015  * with this library; if not, see http://www.gnu.org/copyleft/.
00016  */
00017 #ifndef __RAPICORN_LIST_AREA_IMPL_HH__
00018 #define __RAPICORN_LIST_AREA_IMPL_HH__
00019 
00020 #include <ui/listarea.hh>
00021 #include <ui/container.hh>
00022 #include <ui/adjustment.hh>
00023 #include <ui/layoutcontainers.hh>
00024 #include <ui/table.hh>
00025 #include <ui/models.hh>
00026 #include <deque>
00027 
00028 namespace Rapicorn {
00029 
00030 struct ListRow {
00031   vector<ItemImpl*> cols;
00032   ContainerImpl *rowbox;
00033   Allocation     area;
00034   uint           allocated : 1;
00035   ListRow() : rowbox (NULL), allocated (0) {}
00036 };
00037 
00038 struct ModelSizes {
00039   vector<int>    row_sizes;
00040   map<int64,int> size_cache; // ca. 28bytes per node
00041   int64          total_height;
00042   ListRow       *measurement_row;
00043   explicit ModelSizes() : total_height (0), measurement_row (NULL) {}
00044   void     clear     () { row_sizes.clear(); size_cache.clear(); total_height = 0; }
00045 };
00046 
00047 class ItemListImpl : public virtual MultiContainerImpl,
00048                      public virtual ItemList,
00049                      public virtual AdjustmentSource,
00050                      public virtual EventHandler
00051 {
00052   typedef map<int64,ListRow*>  RowMap;
00053   typedef std::deque<int>      SizeQueue;
00054   ListModelIface        *m_model;
00055   vector<bool>           m_selection;
00056   mutable Adjustment    *m_hadjustment, *m_vadjustment;
00057   bool                   m_browse;
00058   uint                   m_n_cols;
00059   RowMap                 m_row_map;
00060   vector<ListRow*>       m_row_cache;
00061   vector<SizeGroup*>     m_size_groups;
00062   bool                   m_need_resize_scroll;
00063   bool                   m_block_invalidate;
00064   uint64                 m_current_row;
00065   ModelSizes             m_model_sizes;
00066   void                  model_inserted          (int first, int last);
00067   void                  model_changed           (int first, int last);
00068   void                  model_removed           (int first, int last);
00069   void                  selection_changed       (int first, int last);
00070   virtual void          invalidate_parent ();
00071 protected:
00072   virtual bool          handle_event            (const Event    &event);
00073   virtual void          reset                   (ResetMode       mode);
00074   virtual bool          can_focus               () const { return true; }
00075   SelectionMode         selection_mode          () { return SELECTION_MULTIPLE; }
00076   bool                  selected                (int row) { return size_t (row) < m_selection.size() && m_selection[row]; }
00077   void                  toggle_selected         (int row);
00078 public:
00079   explicit              ItemListImpl            ();
00080   virtual              ~ItemListImpl            ();
00081   virtual void          constructed             ();
00082   virtual bool          browse                  () const        { return m_browse; }
00083   virtual void          browse                  (bool b)        { m_browse = b; invalidate(); }
00084   virtual void          model                   (const String &modelurl);
00085   virtual String        model                   () const;
00086   virtual void          hierarchy_changed       (ItemImpl *old_toplevel);
00087   Adjustment&           hadjustment             () const;
00088   Adjustment&           vadjustment             () const;
00089   Adjustment*           get_adjustment          (AdjustmentSourceType adj_source,
00090                                                  const String        &name);
00091   void                  invalidate_model        (bool invalidate_heights,
00092                                                  bool invalidate_widgets);
00093   virtual void          visual_update           ();
00094   virtual void          size_request            (Requisition &requisition);
00095   virtual void          size_allocate           (Allocation area);
00096   /* sizing and positioning */
00097   bool                  pixel_positioning       (const int64       mcount,
00098                                                  const ModelSizes &ms) const;
00099   void                  measure_rows            (int64    maxpixels);
00100   int64                 position2row            (double   list_fraction,
00101                                                  double  *row_fraction);
00102   double                row2position            (int64    list_row,
00103                                                  double   list_alignment = 0.5);
00104   int                   row_height              (ModelSizes &ms,
00105                                                  int64       list_row);
00106   int64                 row_layout              (double      vscrollpos,
00107                                                  int64       mcount,
00108                                                  ModelSizes &ms,
00109                                                  int64       list_row);
00110 
00111   void                  measure_rows            (int64    maxpixels,
00112                                                  double   fraction);
00113   int64                 scroll_row_layout       (ListRow *lr_current,
00114                                                  int64 *scrollrowy,
00115                                                  int64 *scrollrowupper,
00116                                                  int64 *scrollrowlower,
00117                                                  int64 *listupperp,
00118                                                  int64 *listheightp);
00119   void                  resize_scroll           ();
00120   void                  resize_scroll_preserving();
00121   void                  cache_row               (ListRow *lr);
00122   void                  fill_row                (ListRow *lr,
00123                                                  uint64   row);
00124   ListRow*              create_row              (uint64 row,
00125                                                  bool   with_size_groups = true);
00126   ListRow*              lookup_row              (uint64 row);
00127   ListRow*              fetch_row               (uint64 row);
00128   uint64                measure_row             (ListRow *lr,
00129                                                  uint64  *allocation_offset = NULL);
00130 };
00131 
00132 } // Rapicorn
00133 
00134 #endif  /* __RAPICORN_LIST_AREA_IMPL_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines