Difference between revisions of "List/Tree Widget"

From Adobe Open Source Wiki
Jump to: navigation, search
 
(14 intermediate revisions by one user not shown)
Line 10: Line 10:
 
== Related Docs ==
 
== Related Docs ==
  
[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/treeview.asp?hidetoc=true Win32 Tree Control API Documentation (Tree View)]
+
[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/treeview.asp?hidetoc=true Win32 Tree View Control Documentation]
  
[http://developer.apple.com/documentation/Carbon/Conceptual/display_databrowser/databrowser_intro/chapter_1_section_1.html| Carbon Tree Control API Documentation (Data Browser)]
+
[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/listview.asp?hidetoc=true Win32 List View Control Documentation]
  
== Typedefs ==
+
[http://developer.apple.com/documentation/Carbon/Reference/databrow_reference/index.html#//apple_ref/doc/uid/TP30000969 Carbon Tree Control API Documentation (Data Browser)]
  
Assume for the time being that the model_type is simple:
+
= API =
  
  typedef std::string                  value_type;
+
''This API set will be updated piecemeal as I am able to further the implementation''
  typedef std::vector<value_type>      model_type;
+
  typedef model_type::iterator          iterator;
+
  typedef std::pair<iterator, iterator> sequence_type;
+
  
== Model API ==
+
Assume for the time being that the model_type is a simple string for now...
  
   typedef boost::function<void (const value_type&)> monitor_value_callback_t;
+
== Model ==
   typedef boost::function<void (iterator who)> monitor_child_insert_callback_t;
+
 
 +
   template <typename T>
 +
   class sequence_model
 +
  {
 +
  public:
 +
      sequence_model(std::size_t count = 0);
 
    
 
    
  void insert(const value_type& what, iterator where);
+
      typedef T                                          value_type;
  void monitor_child_insert(iterator parent, const monitor_child_insert_callback_t& how);
+
      typedef dirty_value<T>                            dirty_type;
   void monitor_value(iterator where, const monitor_value_callback_t& how);
+
      typedef std::vector<dirty_type>                    model_type;
  void monitor_erase(...);
+
      typedef typename model_type::iterator              iterator;
   void monitor_child_erase(...);
+
      typedef typename model_type::const_iterator        const_iterator;
 +
      typedef boost::signals::connection                connection_type;
 +
      typedef typename model_type::size_type            size_type;
 +
      typedef boost::function<void (iterator, iterator)> inplace_operation_proc_t;
 +
    
 +
      typedef boost::function<void (size_type pos, const T* first, const T* last)> monitor_insert_proc_t;
 +
      typedef boost::function<void (size_type index, const T& value)>              monitor_set_proc_t;
 +
    
 +
      static const size_type npos;
  
== View API ==
+
npos is used as an out-of-bounds index, much like std::string::npos.
  
  void set(iterator where, const value_type& value);
+
      const_iterator begin() const;
  void erase(iterator who);
+
      const_iterator end() const;
  
== Controller API ==
+
These are const because the sequence is not modifiable via iterators outside of an inplace operation.
  
   typedef boost::function<void (const value_type&)> monitor_value_callback_t;
+
      size_type size() const;
 +
      size_type max_size() const;
 +
    
 +
      bool empty() const;
 +
 
 +
      const T& at(size_type n) const;
 +
      const T& operator[](size_type n);
  
   void monitor(iterator who, const monitor_child_insert_callback_t& how);
+
These are const because the sequence is not modifiable via iterators outside of an inplace operation.
   void erase(iterator who);
+
 
 +
      void push_back(const value_type& x);
 +
    
 +
      void set(size_type pos, const value_type& x);
 +
 
 +
Allows the setting of a single position's value.
 +
 
 +
      template <typename I>
 +
      void insert(size_type pos, I first, I last);
 +
 
 +
Allows the insertion of a range of values.
 +
 
 +
      void inplace_operation(const inplace_operation_proc_t& proc,
 +
                            size_type                      pos = 0,
 +
                            size_type                      n = sequence_model::npos);
 +
 
 +
given an index, a count, and an inplace operation, this function will allow for a mutable transaction to take place within the sequence. The inplace_operation_proc is given mutable iterators based on the requested position and count variables. When the operation completes, the sequence_model will iterate over the range and check to see which values (if any) changed, and make proper notification of these changes to the attached views.
 +
 
 +
      connection_type monitor_insert(const monitor_insert_proc_t& proc);
 +
      connection_type monitor_set(const monitor_set_proc_t& proc);
 +
 
 +
Allows for clients to register one or more views into the sequence model.
 +
 
 +
   };
 +
 
 +
=== Notes on the Sequence Model ===
 +
 
 +
dirty_type is an implementation-defined method of discovering what values have changed due to an inplace operation; the client of the sequence_model need not be concerned with it.
 +
 
 +
== View ==
 +
 
 +
  struct list_view_t
 +
  {
 +
    typedef model_type::value_type value_type;
 +
    typedef model_type::size_type  size_type;
 +
 
 +
    void set(size_type index, const value_type& value);
 +
 
 +
    void insert(size_type pos, const value_type* first, const value_type* last);
 +
  };
 +
 
 +
== Controller ==
 +
 
 +
  struct list_controller_t
 +
  {
 +
    typedef model_type::inplace_operation_proc_t inplace_operation_proc_t;
 +
    typedef boost::function<void (size_type, const value_type&)> monitor_set_callback_t;
 +
    typedef boost::function<void (size_type, const value_type*, const value_type*)> monitor_insert_callback_t;
 +
    typedef boost::function<void (const inplace_operation_proc_t& proc, size_type, size_type)> monitor_inplace_operation_callback_t;
 +
 
 +
    void enable(bool make_enabled);
 +
   
 +
    void monitor_set(const monitor_set_callback_t& how);
 +
   
 +
    void monitor_insert(const monitor_insert_callback_t& how);
 +
   
 +
    void monitor_inplace_operation(const monitor_inplace_operation_callback_t& how);
 +
  };

Latest revision as of 23:42, 31 January 2007

(For the time being the focus will be on lists, not heirarchical trees.)

The tricky part of a list controller/view is that you have a controller/view on a sequence. You need to figure out:

  1. How to communicate requests for changes to the sequence
  2. What those requests are
  3. How to communicate a change in the visible portion of the sequence to the view

We assume the sequences in a list are disjoint.

Contents

Related Docs

Win32 Tree View Control Documentation

Win32 List View Control Documentation

Carbon Tree Control API Documentation (Data Browser)

API

This API set will be updated piecemeal as I am able to further the implementation

Assume for the time being that the model_type is a simple string for now...

Model

 template <typename T>
 class sequence_model
 {
 public:
     sequence_model(std::size_t count = 0);
 
     typedef T                                          value_type;
     typedef dirty_value<T>                             dirty_type;
     typedef std::vector<dirty_type>                    model_type;
     typedef typename model_type::iterator              iterator;
     typedef typename model_type::const_iterator        const_iterator;
     typedef boost::signals::connection                 connection_type;
     typedef typename model_type::size_type             size_type;
     typedef boost::function<void (iterator, iterator)> inplace_operation_proc_t;
 
     typedef boost::function<void (size_type pos, const T* first, const T* last)> monitor_insert_proc_t;
     typedef boost::function<void (size_type index, const T& value)>              monitor_set_proc_t;
 
     static const size_type npos;

npos is used as an out-of-bounds index, much like std::string::npos.

     const_iterator begin() const;
     const_iterator end() const;

These are const because the sequence is not modifiable via iterators outside of an inplace operation.

     size_type size() const;
     size_type max_size() const;
 
     bool empty() const;
 
     const T& at(size_type n) const;
     const T& operator[](size_type n);

These are const because the sequence is not modifiable via iterators outside of an inplace operation.

     void push_back(const value_type& x);
 
     void set(size_type pos, const value_type& x);

Allows the setting of a single position's value.

     template <typename I>
     void insert(size_type pos, I first, I last);

Allows the insertion of a range of values.

     void inplace_operation(const inplace_operation_proc_t& proc,
                            size_type                       pos = 0,
                            size_type                       n = sequence_model::npos);

given an index, a count, and an inplace operation, this function will allow for a mutable transaction to take place within the sequence. The inplace_operation_proc is given mutable iterators based on the requested position and count variables. When the operation completes, the sequence_model will iterate over the range and check to see which values (if any) changed, and make proper notification of these changes to the attached views.

     connection_type monitor_insert(const monitor_insert_proc_t& proc);
     connection_type monitor_set(const monitor_set_proc_t& proc);

Allows for clients to register one or more views into the sequence model.

 };

Notes on the Sequence Model

dirty_type is an implementation-defined method of discovering what values have changed due to an inplace operation; the client of the sequence_model need not be concerned with it.

View

 struct list_view_t
 {
   typedef model_type::value_type value_type;
   typedef model_type::size_type  size_type;
 
   void set(size_type index, const value_type& value);
 
   void insert(size_type pos, const value_type* first, const value_type* last);
 };

Controller

 struct list_controller_t
 {
   typedef model_type::inplace_operation_proc_t inplace_operation_proc_t;
   typedef boost::function<void (size_type, const value_type&)> monitor_set_callback_t;
   typedef boost::function<void (size_type, const value_type*, const value_type*)> monitor_insert_callback_t;
   typedef boost::function<void (const inplace_operation_proc_t& proc, size_type, size_type)> monitor_inplace_operation_callback_t;
 
   void enable(bool make_enabled);
   
   void monitor_set(const monitor_set_callback_t& how);
   
   void monitor_insert(const monitor_insert_callback_t& how);
   
   void monitor_inplace_operation(const monitor_inplace_operation_callback_t& how);
 };