13c3486bdf4be942122380a73cc48bd5f1d759fc
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / window_proxy.h
1 /*
2   Copyright (C) 2015 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 __gtkmm2ext_window_proxy_h__
21 #define __gtkmm2ext_window_proxy_h__
22
23 #include <string>
24 #include <gdkmm/event.h>
25 #include <glibmm/refptr.h>
26 #include <sigc++/trackable.h>
27
28 #include "pbd/statefuldestructible.h"
29
30 #include "gtkmm2ext/visibility.h"
31
32 namespace Gtk {
33 class Window;
34 class Action;
35 }
36
37 namespace Gtkmm2ext {
38
39 class VisibilityTracker;
40
41 class LIBGTKMM2EXT_API WindowProxy : public PBD::StatefulDestructible, public virtual sigc::trackable
42 {
43   public:
44         WindowProxy (const std::string& name);
45         WindowProxy (const std::string& name, const std::string& menu_name);
46         WindowProxy (const std::string& name, const std::string& menu_name, const XMLNode&);
47         virtual ~WindowProxy();
48
49         void show ();
50         void show_all ();
51         void hide ();
52         void present ();
53         void maybe_show ();
54
55         bool visible() const;
56         bool fully_visible() const;
57         const std::string& name() const { return _name; }
58         const std::string& menu_name() const { return _menu_name; }
59
60         std::string action_name() const;
61         void set_action (Glib::RefPtr<Gtk::Action>);
62         Glib::RefPtr<Gtk::Action> action() const { return _action; };
63
64         void drop_window ();
65         void use_window (Gtk::Window&);
66
67         virtual Gtk::Window* get (bool create = false) = 0;
68
69         virtual int set_state (const XMLNode&, int version);
70         virtual XMLNode& get_state ();
71
72         enum StateMask {
73                 Position = 0x1,
74                 Size = 0x2
75         };
76
77         void set_state_mask (StateMask);
78         StateMask state_mask () const { return _state_mask; }
79
80         operator bool() const { return _window != 0; }
81
82         static std::string xml_node_name();
83
84   protected:
85         std::string  _name;
86         std::string  _menu_name;
87         Glib::RefPtr<Gtk::Action> _action;
88         Gtk::Window* _window;
89         mutable bool _visible; ///< true if the window should be visible on startup
90         mutable int  _x_off; ///< x position
91         mutable int  _y_off; ///< y position
92         mutable int  _width; ///< width
93         mutable int  _height; ///< height
94         Gtkmm2ext::VisibilityTracker* vistracker;
95         StateMask _state_mask;
96         sigc::connection delete_connection;
97         sigc::connection configure_connection;
98
99         void save_pos_and_size ();
100         void set_pos_and_size ();
101         void set_pos ();
102
103         virtual bool delete_event_handler (GdkEventAny *ev);
104         virtual bool configure_handler (GdkEventConfigure*);
105
106         virtual void setup ();
107         void toggle ();
108 };
109
110 }
111
112 #endif /* __gtkmm2ext_window_proxy_h__ */