Difference between revisions of "List/Tree Widget"

From Adobe Open Source Wiki
Jump to: navigation, search
Line 24: Line 24:
 
== Model ==
 
== Model ==
  
   class list_model_t
+
  template <typename T>
 +
   class sequence_model
 
   {
 
   {
 
   public:
 
   public:
    typedef std::string                  value_type;
+
      sequence_model(std::size_t count = 0);
    typedef std::list<value_type>        model_type;
+
    typedef model_type::const_iterator    iterator;
+
    typedef std::pair<iterator, iterator> range_type;
+
    typedef std::vector<range_type>      selection_type;
+
    typedef boost::signals::connection    connection_type;
+
 
    
 
    
    typedef boost::function<void (iterator, const selection_type&)> monitor_splice_callback_t;
+
      typedef T                                          value_type;
    typedef boost::function<void (iterator)>                       monitor_value_callback_t;
+
      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;
 
    
 
    
    void push_front(const value_type& value);
+
      typedef boost::function<void (size_type pos, const T* first, const T* last)> monitor_insert_proc_t;
    void push_back(const value_type& value);
+
      typedef boost::function<void (size_type index, const T& value)>              monitor_set_proc_t;
 
    
 
    
    void splice(iterator before, const selection_type& value);
+
      static const size_type npos;
 
    
 
    
    void set(iterator who, const value_type& value);
+
      const_iterator begin() const;
 +
      const_iterator end() const;
 
    
 
    
    connection_type monitor_splice(const monitor_splice_callback_t& how);
+
      size_type size() const;
    connection_type monitor_value(const monitor_value_callback_t& how);
+
      size_type max_size() const;
 
    
 
    
  private:
+
      bool empty() const;
    typedef boost::signal<void (iterator, const selection_type&)> splice_callback_set_t;
+
    typedef boost::signal<void (iterator)>                        value_callback_set_t;
+
 
    
 
    
    model_type            model_m;
+
      const T& at(size_type n) const;
    splice_callback_set_t splice_callback_set_m;
+
      const T& operator[](size_type n);
    value_callback_set_t  value_callback_set_m;
+
 
 +
      void push_back(const value_type& x);
 +
 
 +
      void set(size_type pos, const value_type& x);
 +
 
 +
      template <typename I>
 +
      void insert(size_type pos, I first, I last);
 +
 
 +
      void inplace_operation(const inplace_operation_proc_t& proc,
 +
                            size_type                      pos = 0,
 +
                            size_type                      n = sequence_model::npos);
 +
 
 +
      connection_type monitor_insert(const monitor_insert_proc_t& proc);
 +
      connection_type monitor_set(const monitor_set_proc_t& proc);
 
   };
 
   };
  
Line 60: Line 74:
 
   struct list_view_t
 
   struct list_view_t
 
   {
 
   {
     typedef model_type::const_iterator    iterator;
+
     typedef model_type::value_type value_type;
     typedef std::vector<range_type>      selection_type;
+
     typedef model_type::size_type  size_type;
 
    
 
    
     void set(iterator who);
+
     void set(size_type index, const value_type& value);
 
    
 
    
     void splice(iterator before, const selection_type& value);
+
     void insert(size_type pos, const value_type* first, const value_type* last);
 
   };
 
   };
  
Line 72: Line 86:
 
   struct list_controller_t
 
   struct list_controller_t
 
   {
 
   {
     typedef adobe::list_model_t::monitor_splice_callback_t          monitor_splice_callback_t;
+
     typedef model_type::inplace_operation_proc_t inplace_operation_proc_t;
     typedef boost::function<void (const value_type&)>               monitor_push_back_callback_t;
+
     typedef boost::function<void (size_type, const value_type&)> monitor_set_callback_t;
     typedef boost::function<void (const value_type&)>               monitor_push_front_callback_t;
+
     typedef boost::function<void (size_type, const value_type*, const value_type*)> monitor_insert_callback_t;
     typedef boost::function<void (iterator who, const value_type&)> monitor_value_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 enable(bool make_enabled);
 
+
   
     void monitor_value(const monitor_value_callback_t& how);
+
     void monitor_set(const monitor_set_callback_t& how);
 
+
   
     void monitor_splice(const monitor_splice_callback_t& how);
+
     void monitor_insert(const monitor_insert_callback_t& how);
 
+
      
     void monitor_push_front(const monitor_push_front_callback_t& how);
+
     void monitor_inplace_operation(const monitor_inplace_operation_callback_t& how);
 
+
     void monitor_push_back(const monitor_push_back_callback_t& how);
+
 
   };
 
   };

Revision as of 23:36, 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;
 
     const_iterator begin() const;
     const_iterator end() const;
 
     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 push_back(const value_type& x);
 
     void set(size_type pos, const value_type& x);
 
     template <typename I>
     void insert(size_type pos, I first, I last);
 
     void inplace_operation(const inplace_operation_proc_t& proc,
                            size_type                       pos = 0,
                            size_type                       n = sequence_model::npos);
 
     connection_type monitor_insert(const monitor_insert_proc_t& proc);
     connection_type monitor_set(const monitor_set_proc_t& proc);
 };

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);
 };