f1d5bed092087d33513026984fc9e7e3959e3258
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / pane.h
1 /*
2     Copyright (C) 2016 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __libgtkmm2ext_pane_h__
21 #define __libgtkmm2ext_pane_h__
22
23 #include <vector>
24 #include <algorithm>
25
26 #include <stdint.h>
27
28 #include <gdkmm/cursor.h>
29 #include <gtkmm/container.h>
30 #include <gtkmm/eventbox.h>
31
32 #include "gtkmm2ext/visibility.h"
33
34 namespace Gtk {
35         class Widget;
36 }
37
38 namespace Gtkmm2ext {
39
40 class LIBGTKMM2EXT_API Pane : public Gtk::Container
41 {
42   private:
43         class Divider;
44
45
46   public:
47         struct Child
48         {
49                 Gtk::Widget* w;
50                 int32_t minsize;
51
52                 Child (Gtk::Widget* widget, uint32_t ms) : w (widget), minsize (ms) {}
53         };
54
55         typedef std::list<Child> Children;
56
57         Pane (bool horizontal);
58         void set_divider (std::vector<float>::size_type divider, float fract);
59         float get_divider (std::vector<float>::size_type divider = 0);
60         void set_child_minsize (Gtk::Widget const &, int32_t);
61
62         GType child_type_vfunc() const;
63         void set_drag_cursor (Gdk::Cursor);
64
65   protected:
66         bool horizontal;
67
68         void on_add (Gtk::Widget*);
69         void on_remove (Gtk::Widget*);
70         void on_size_request (GtkRequisition*);
71         void on_size_allocate (Gtk::Allocation&);
72         bool on_expose_event (GdkEventExpose*);
73
74         bool handle_press_event (GdkEventButton*, Divider*);
75         bool handle_release_event (GdkEventButton*, Divider*);
76         bool handle_motion_event (GdkEventMotion*, Divider*);
77         bool handle_enter_event (GdkEventCrossing*, Divider*);
78         bool handle_leave_event (GdkEventCrossing*, Divider*);
79
80         void forall_vfunc (gboolean include_internals, GtkCallback callback, gpointer callback_data);
81
82   private:
83         Gdk::Cursor drag_cursor;
84         bool did_move;
85
86         void reallocate (Gtk::Allocation const &);
87
88         Children children;
89
90         struct Divider : public Gtk::EventBox {
91                 Divider ();
92
93                 float fract;
94                 bool dragging;
95
96                 bool on_expose_event (GdkEventExpose* ev);
97         };
98
99         typedef std::list<Divider*> Dividers;
100         Dividers dividers;
101         int divider_width;
102         void add_divider ();
103         void handle_child_visibility ();
104 };
105
106 class LIBGTKMM2EXT_API HPane : public Pane
107 {
108   public:
109         HPane () : Pane (true) {}
110 };
111
112 class LIBGTKMM2EXT_API VPane : public Pane
113 {
114   public:
115         VPane () : Pane (false) {}
116 };
117
118 } /* namespace */
119
120 #endif /* __libgtkmm2ext_pane_h__ */