]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.h
Implement autosize() method for most widgets
[libs/gltk.git] / source / list.h
index edcec3395a8f18e3255b6023f6ebcce5620f1757..b3b3a88704207470ef3825b16ca30c9161644338 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -9,18 +9,17 @@ Distributed under the LGPL
 #define MSP_GLTK_LIST_H_
 
 #include <sigc++/signal.h>
-#include "widget.h"
+#include "container.h"
+#include "vslider.h"
 
 namespace Msp {
 namespace GLtk {
 
-class VSlider;
-
 /**
 Shows a list of items, allowing the user to select one.  A slider is included
 to allow scrolling through a long list.
 */
-class List: public Widget
+class List: virtual public Widget, private Container
 {
 public:
        class Loader: public Widget::Loader
@@ -31,41 +30,49 @@ public:
                void item(const std::string &);
        };
 
+       sigc::signal<void, unsigned, const std::string &> signal_item_selected;
+
 private:
        std::vector<std::string> items;
        int sel_index;
        unsigned first;
        unsigned n_visible;
+       unsigned row_height;
 
        const Part *items_part;
 
-       VSlider *slider;
-       bool slider_active;
+       VSlider slider;
 
 public:
-       sigc::signal<void, unsigned, const std::string &> signal_item_selected;
+       List();
+
+       virtual const char *get_class() const { return "list"; }
+
+       virtual void autosize();
+       void autosize_rows(unsigned);
+       void autosize_all();
 
-       List(const Resources &);
        void append(const std::string &);
        void insert(unsigned, const std::string &);
        void remove(unsigned);
        void clear();
+       unsigned get_n_items() const { return items.size(); }
 
+       void set_selected_index(int);
        const std::string &get_selected() const;
        int get_selected_index() const { return sel_index; }
 
-       virtual void button_press(int, int, unsigned);
-       virtual void button_release(int, int, unsigned);
-       virtual void pointer_motion(int, int);
-
 private:
-       virtual const char *get_class() const { return "list"; }
        virtual void render_special(const Part &) const;
 
+public:
+       virtual void button_press(int, int, unsigned);
+private:
        virtual void on_geometry_change();
        virtual void on_style_change();
+
        void reposition_slider();
-       void recalculate_parameters();
+       void check_view_range();
        void slider_value_changed(double);
 };