15#include <gtkmm/eventcontrollerkey.h>
16#include <gtkmm/eventcontrollerscroll.h>
17#include <gtkmm/scrolledwindow.h>
18#include <gtkmm/viewport.h>
33 if (
auto const pos =
name.find(pattern); pos !=
name.npos) {
34 name.erase(pos, pattern.size());
48 , _dialog_type{
std::move(dialog_type)}
53 if (
auto const it = dialog_data.find(
_dialog_type); it != dialog_data.end()) {
54 _name = it->second.label;
65 auto const key = Gtk::EventControllerKey::create();
66 key->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);
83 parent_type::on_map();
87 unsigned keyval,
unsigned keycode, Gdk::ModifierType state)
103 Gtk::Notebook *notebook =
dynamic_cast<Gtk::Notebook *
>(get_parent()->get_parent());
106 notebook->set_current_page(notebook->page_num(*
this));
107 notebook->add_css_class(
"blink");
111 sigc::connection connection = Glib::signal_timeout().connect(slot, 1000);
117 if (
auto window =
dynamic_cast<Gtk::Window*
>(get_root())) {
121 if (
auto child = get_focus_child()) {
133 if (
auto wnd =
dynamic_cast<Gtk::Window*
>(get_root())) {
149 Gtk::Notebook *notebook =
dynamic_cast<Gtk::Notebook *
>(get_parent()->get_parent());
151 notebook->remove_css_class(
"blink");
202 Gtk::Widget *
child =
nullptr;
203 if (
auto const viewport =
dynamic_cast<Gtk::Viewport *
>(scrollwin.get_child())) {
204 child = viewport->get_child();
206 child = scrollwin.get_child();
212 auto controller = Gtk::EventControllerScroll::create();
213 controller->set_flags(Gtk::EventControllerScroll::Flags::VERTICAL);
214 controller->signal_scroll().connect(
215 [
this, adj = scrollwin.get_vadjustment()](
double dx,
double dy) ->
bool {
216 auto const parentscroll = dynamic_cast<Gtk::ScrolledWindow *>(get_first_child());
221 if (dy > 0 && adj->get_value() + adj->get_page_size() == adj->get_upper() ||
222 dy < 0 && adj->get_value() == adj->get_lower()) {
223 auto parent_adj = parentscroll->get_vadjustment();
225 double new_value = parent_adj->get_value() + dy * parent_adj->get_step_increment();
226 new_value = std::max(parent_adj->get_lower(),
227 std::min(parent_adj->get_upper() - parent_adj->get_page_size(), new_value));
228 parent_adj->set_value(new_value);
235 child->add_controller(controller);
242DialogBase::setShowing(
bool showing) {
244 if (showing && _changed_while_hidden) {
245 selectionChanged(getSelection());
246 _changed_while_hidden =
false;
248 if (showing && _modified_while_hidden) {
249 selectionModified(getSelection(), _modified_flags);
250 _modified_while_hidden =
false;
257void DialogBase::unsetDesktop()
262 _desktop_destroyed.disconnect();
263 _doc_replaced.disconnect();
264 _select_changed.disconnect();
265 _select_modified.disconnect();
268void DialogBase::desktopDestroyed(
SPDesktop* old_desktop)
274 set_sensitive(
false);
283 if (document != new_document) {
284 document = new_document;
static Application & instance()
Returns the current Inkscape::Application global object.
The set of selected SPObjects for a given document and layer model.
sigc::connection connectChanged(sigc::slot< void(Selection *)> slot)
Connects a slot to be notified of selection changes.
sigc::connection connectModified(sigc::slot< void(Selection *, unsigned)> slot)
Connects a slot to be notified of selected object modifications.
void setDesktop(SPDesktop *new_desktop)
Called when the desktop might have changed for this dialog.
void blink()
Highlight notebook where dialog already exists.
sigc::connection _doc_replaced
bool _changed_while_hidden
virtual void selectionChanged(Inkscape::Selection *selection)
sigc::connection _select_changed
bool blink_off()
Callback to reset the dialog highlight.
void unsetDesktop()
Called to destruct desktops, must not call virtuals.
bool _modified_while_hidden
virtual void update()
The update() method is essential to Gtk state management.
void setDocument(SPDocument *new_document)
Called when the document might have changed, called from setDesktop too.
bool on_key_pressed(Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
void desktopDestroyed(SPDesktop *old_desktop)
virtual void selectionModified(Inkscape::Selection *selection, guint flags)
DialogBase(char const *prefs_path=nullptr, Glib::ustring dialog_type={})
DialogBase constructor.
virtual void desktopReplaced()
Called when the desktop has certainly changed.
virtual void documentReplaced()
void fix_inner_scroll(Gtk::ScrolledWindow &scrollwin)
sigc::connection _desktop_destroyed
virtual void focus_dialog()
SPDesktop * getDesktop() const
sigc::connection _select_modified
Glib::ustring const _dialog_type
To do: update description of desktop.
Inkscape::UI::Widget::Canvas * getCanvas() const
sigc::connection connectDocumentReplaced(F &&slot)
SPDocument * getDocument() const
Inkscape::Selection * getSelection() const
sigc::connection connectDestroy(F &&slot)
Typed SVG document implementation.
Editable view implementation.
A base class for all dialogs.
const std::map< std::string, DialogData > & get_dialog_data()
Get the data about all existing dialogs.
void sp_dialog_defocus(Gtk::Window *win)
Remove focus from window to whoever it is transient for.
Event handler for dialog windows.
static void set_sensitive(Gtk::SearchEntry2 &entry, bool const sensitive)
static void remove_first(Glib::ustring &name, Glib::ustring const &pattern)
static Glib::ustring const prefs_path
Gtk::Widget * find_focusable_widget(Gtk::Widget &parent)
This function traverses a tree of widgets searching for first focusable widget.
static cairo_user_data_key_t key