more changes to broken-out tempo code
[ardour.git] / gtk2_ardour / luadialog.h
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef _gtk2ardour_luadialog_h_
20 #define _gtk2ardour_luadialog_h_
21
22 #include <cassert>
23 #include <gtkmm/table.h>
24 #include <gtkmm/messagedialog.h>
25
26 #include "LuaBridge/LuaBridge.h"
27
28 namespace LuaDialog {
29
30 class Message {
31 public:
32
33         enum MessageType {
34                 Info, Warning, Question, Error
35         };
36
37         enum ButtonType {
38                 OK, Close, Cancel, Yes_No, OK_Cancel
39         };
40
41         Message (std::string const&, std::string const&, Message::MessageType, Message::ButtonType);
42
43         int run ();
44
45 private:
46         Message (Message const&); // prevent copy construction
47
48         static Gtk::ButtonsType to_gtk_bt (ButtonType bt);
49         static Gtk::MessageType to_gtk_mt (MessageType mt);
50
51         Gtk::MessageDialog _message_dialog;
52 };
53
54 class LuaDialogWidget {
55 public:
56         LuaDialogWidget (std::string const& key, std::string const& label, int col = 0, int colspan = -1)
57                 : _key (key), _label (label), _col (col), _colspan (colspan)
58         {
59                 if (_colspan < 0) {
60                         _colspan = label.empty () ? 1 : 2;
61                 }
62         }
63
64         virtual ~LuaDialogWidget () {}
65
66         virtual Gtk::Widget* widget () = 0;
67         virtual void assign (luabridge::LuaRef* rv) const = 0;
68         std::string const&  label () const { return _label; }
69         std::string const&  key   () const { return _key; }
70         int                 col   () const { return _col; }
71         int                 span  () const { return _colspan; }
72
73         void set_col  (int col)  { _col = col; }
74         void set_span (int span) { _colspan = span; }
75
76 protected:
77         std::string _key;
78         std::string _label;
79         int _col;
80         int _colspan;
81 };
82
83
84 class Dialog {
85 public:
86         Dialog (std::string const&, luabridge::LuaRef);
87         ~Dialog ();
88         int run (lua_State *L);
89
90 private:
91         Dialog (Dialog const&); // prevent copy construction
92         ArdourDialog _ad;
93         typedef std::vector<LuaDialogWidget*> DialogWidgets;
94         DialogWidgets _widgets;
95         std::string _title;
96 };
97
98 }; // namespace
99
100 #endif