Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
bin.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Daniel Boles <dboles.src+inkscape@gmail.com>
8 *
9 * Copyright (C) 2023 Daniel Boles
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include "bin.h"
14#include <cassert>
15
16namespace Inkscape::UI::Widget {
17
19{
20 set_name("Bin");
21 set_overflow(Gtk::Overflow::HIDDEN);
22 containerize(*this);
23}
24
25Bin::Bin(Gtk::Widget *child)
26{
27 _construct();
29}
30
31Bin::Bin(BaseObjectType *cobject, Glib::RefPtr<Gtk::Builder> const &)
32 : Gtk::Widget(cobject)
33{
34 _construct();
35 // Add child from builder file. (For custom types, C++ wrapper must already be instantiated.)
36 _child = get_first_child();
37 assert(!_child || !_child->get_next_accessible_sibling());
38}
39
40void Bin::set_child(Gtk::Widget *child)
41{
42 if (child == _child || (child && child->get_parent())) {
43 return;
44 }
45
46 if (_child) {
47 _child->unparent();
48 }
49
50 _child = child;
51
52 if (_child) {
53 _child->set_parent(*this);
54 }
55}
56
57void Bin::on_size_allocate(int width, int height, int baseline)
58{
59 Gtk::Widget::size_allocate_vfunc(width, height, baseline);
60
61 if (_child && _child->get_visible()) {
62 int min_width, min_height, ignore;
63 _child->measure(Gtk::Orientation::HORIZONTAL, -1, min_width, ignore, ignore, ignore);
64 _child->measure(Gtk::Orientation::VERTICAL, -1, min_height, ignore, ignore, ignore);
65 _child->size_allocate({0, 0, std::max(width, min_width), std::max(height, min_height)}, baseline);
66 }
67}
68
69Gtk::SizeRequestMode Bin::get_request_mode_vfunc() const
70{
71 return _child ? _child->get_request_mode() : Gtk::SizeRequestMode::CONSTANT_SIZE;
72}
73
74void Bin::measure_vfunc(Gtk::Orientation orientation, int for_size, int &min, int &nat, int &min_baseline, int &nat_baseline) const
75{
76 if (_child && _child->get_visible()) {
77 _child->measure(orientation, for_size, min, nat, min_baseline, nat_baseline);
78 } else {
79 min = nat = min_baseline = nat_baseline = 0;
80 }
81}
82
83void Bin::size_allocate_vfunc(int width, int height, int baseline)
84{
85 _signal_before_resize.emit(width, height, baseline);
86 on_size_allocate(width, height, baseline);
87 _signal_after_resize.emit(width, height, baseline);
88}
89
90} // namespace Inkscape::UI::Widget
91
92/*
93 Local Variables:
94 mode:c++
95 c-file-style:"stroustrup"
96 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97 indent-tabs-mode:nil
98 fill-column:99
99 End:
100*/
101// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Bin: widget that can hold one child, useful as a base class of custom widgets.
sigc::signal< void(int, int, int)> _signal_before_resize
Definition bin.h:72
void measure_vfunc(Gtk::Orientation orientation, int for_size, int &min, int &nat, int &min_baseline, int &nat_baseline) const override
Definition bin.cpp:74
sigc::signal< void(int, int, int)> _signal_after_resize
Definition bin.h:73
Bin(Gtk::Widget *child=nullptr)
Definition bin.cpp:25
virtual void on_size_allocate(int width, int height, int baseline)
Definition bin.cpp:57
Gtk::Widget * _child
Definition bin.h:70
Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition bin.cpp:69
void size_allocate_vfunc(int width, int height, int baseline) override
Definition bin.cpp:83
void set_child(Gtk::Widget *child)
Sets (parents) the child widget, or unsets (unparents) it if child is null.
Definition bin.cpp:40
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126
static constexpr int height
void containerize(Gtk::Widget &widget)
Make a custom widget implement sensible memory management for its children.
Ocnode * child[8]
Definition quantize.cpp:33
double width