1 /*
2  * gnote
3  *
4  * Copyright (C) 2019,2021 Aurimas Cernius
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <gtkmm/label.h>
21 #include <gtkmm/modelbutton.h>
22 
23 #include "iactionmanager.hpp"
24 #include "popoverwidgets.hpp"
25 
26 namespace gnote {
27   namespace {
28     class PopoverSubmenuBox
29       : public Gtk::Box
30       , public PopoverSubmenu
31     {
32     public:
PopoverSubmenuBox(const Glib::ustring & submenu)33       PopoverSubmenuBox(const Glib::ustring & submenu)
34         : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
35         , PopoverSubmenu(submenu)
36       {
37         utils::set_common_popover_widget_props(*this);
38       }
39     };
40 
41 
set_common_popover_button_props(Gtk::ModelButton & button)42     void set_common_popover_button_props(Gtk::ModelButton & button)
43     {
44       button.set_use_underline(true);
45       button.property_margin_top() = 3;
46       button.property_margin_bottom() = 3;
47       auto lbl = dynamic_cast<Gtk::Label*>(button.get_child());
48       if(lbl) {
49         lbl->set_xalign(0.0f);
50       }
51       utils::set_common_popover_widget_props(button);
52     }
53   }
54 
55 
56 const int APP_SECTION_NEW = 1;
57 const int APP_SECTION_MANAGE = 2;
58 const int APP_SECTION_LAST = 3;
59 const int APP_CUSTOM_SECTION = 1000;
60 
61 const int NOTE_SECTION_NEW = 1;
62 const int NOTE_SECTION_UNDO = 2;
63 const int NOTE_SECTION_CUSTOM_SECTIONS = 10;
64 const int NOTE_SECTION_FLAGS = 20;
65 const int NOTE_SECTION_ACTIONS = 30;
66 
create_for_app(int ord,Gtk::Widget * w)67 PopoverWidget PopoverWidget::create_for_app(int ord, Gtk::Widget *w)
68 {
69   return PopoverWidget(APP_SECTION_MANAGE, ord, w);
70 }
71 
create_for_note(int ord,Gtk::Widget * w)72 PopoverWidget PopoverWidget::create_for_note(int ord, Gtk::Widget *w)
73 {
74   return PopoverWidget(NOTE_SECTION_ACTIONS, ord, w);
75 }
76 
create_custom_section(Gtk::Widget * w)77 PopoverWidget PopoverWidget::create_custom_section(Gtk::Widget *w)
78 {
79   return PopoverWidget(APP_CUSTOM_SECTION, 0, w);
80 }
81 
82 namespace utils {
83 
create_popover_button(const Glib::ustring & action,const Glib::ustring & label)84   Gtk::Widget * create_popover_button(const Glib::ustring & action, const Glib::ustring & label)
85   {
86     Gtk::ModelButton *item = new Gtk::ModelButton;
87     gtk_actionable_set_action_name(GTK_ACTIONABLE(item->gobj()), action.c_str());
88     item->set_label(label);
89     set_common_popover_button_props(*item);
90     return item;
91   }
92 
93 
create_popover_submenu_button(const Glib::ustring & submenu,const Glib::ustring & label)94   Gtk::Widget * create_popover_submenu_button(const Glib::ustring & submenu, const Glib::ustring & label)
95   {
96     Gtk::ModelButton *button = new Gtk::ModelButton;
97     button->property_menu_name() = submenu;
98     button->set_label(label);
99     set_common_popover_button_props(*button);
100     return button;
101   }
102 
103 
create_popover_submenu(const Glib::ustring & name)104   Gtk::Box * create_popover_submenu(const Glib::ustring & name)
105   {
106     return new PopoverSubmenuBox(name);
107   }
108 
109 
set_common_popover_widget_props(Gtk::Widget & widget)110   void set_common_popover_widget_props(Gtk::Widget & widget)
111   {
112     widget.property_hexpand() = true;
113   }
114 
set_common_popover_widget_props(Gtk::Box & widget)115   void set_common_popover_widget_props(Gtk::Box & widget)
116   {
117     widget.property_margin_top() = 9;
118     widget.property_margin_bottom() = 9;
119     widget.property_margin_start() = 12;
120     widget.property_margin_end() = 12;
121     set_common_popover_widget_props(static_cast<Gtk::Widget&>(widget));
122   }
123 
124 }
125 
126 }
127 
128