[gtkmm-documentation] Update for the latest gtk+4 and gtkmm4 (Gdk::Surface etc.)
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Update for the latest gtk+4 and gtkmm4 (Gdk::Surface etc.)
- Date: Wed, 4 Apr 2018 09:08:05 +0000 (UTC)
commit 7d414fd4d39523c2eec4eae816c322beebf6c67a
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Wed Apr 4 11:04:02 2018 +0200
Update for the latest gtk+4 and gtkmm4 (Gdk::Surface etc.)
Gdk::Window has been renamed. It's now called Gdk::Surface.
Gtk::Snapshot is now a ref counted Glib::Object.
Gdk::Texture implements the Gdk::Paintable interface.
.../book/custom/custom_container/examplewindow.h | 6 ++--
.../book/custom/custom_container/mycontainer.cc | 2 +-
examples/book/custom/custom_widget/myextrainit.cc | 2 +-
examples/book/custom/custom_widget/mywidget.cc | 22 +++++++++---------
examples/book/custom/custom_widget/mywidget.h | 4 +-
examples/book/custom/custom_widget/mywidget2.cc | 18 +++++++-------
examples/book/custom/custom_widget/mywidget2.h | 2 +-
examples/book/drawingarea/clock/clock.cc | 10 +++-----
examples/book/drawingarea/joins/myarea.cc | 6 ++--
examples/book/drawingarea/thin_lines/myarea.cc | 8 +++---
examples/book/popover/examplewindow.cc | 2 +-
examples/book/printing/advanced/previewdialog.cc | 23 +++++++++++++-------
examples/book/printing/advanced/previewdialog.h | 1 +
.../others/cellrenderercustom/cellrendererpopup.cc | 12 +++++-----
.../cellrenderercustom/cellrenderertoggle.cc | 6 ++--
examples/others/dnd/dndwindow.cc | 2 +-
16 files changed, 66 insertions(+), 60 deletions(-)
---
diff --git a/examples/book/custom/custom_container/examplewindow.h
b/examples/book/custom/custom_container/examplewindow.h
index cc0873e..e8458e3 100644
--- a/examples/book/custom/custom_container/examplewindow.h
+++ b/examples/book/custom/custom_container/examplewindow.h
@@ -1,5 +1,3 @@
-//$Id: examplewindow.h 705 2006-07-19 02:55:32Z jjongsma $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2004 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -34,9 +32,11 @@ protected:
//Child widgets:
Gtk::Box m_VBox;
- MyContainer m_MyContainer;
Gtk::Button m_Button_One;
Gtk::Label m_Label_Two;
+ // A restriction with MyContainer is that it must be deleted before
+ // its children, meaning that it must be declared after its children.
+ MyContainer m_MyContainer;
Gtk::ButtonBox m_ButtonBox;
Gtk::Button m_Button_Quit;
};
diff --git a/examples/book/custom/custom_container/mycontainer.cc
b/examples/book/custom/custom_container/mycontainer.cc
index a3f6ac1..8a70939 100644
--- a/examples/book/custom/custom_container/mycontainer.cc
+++ b/examples/book/custom/custom_container/mycontainer.cc
@@ -21,7 +21,7 @@
MyContainer::MyContainer()
: m_child_one(nullptr), m_child_two(nullptr)
{
- set_has_window(false);
+ set_has_surface(false);
}
MyContainer::~MyContainer()
diff --git a/examples/book/custom/custom_widget/myextrainit.cc
b/examples/book/custom/custom_widget/myextrainit.cc
index f2875c4..21b2f85 100644
--- a/examples/book/custom/custom_widget/myextrainit.cc
+++ b/examples/book/custom/custom_widget/myextrainit.cc
@@ -38,7 +38,7 @@ void instance_init_function(GTypeInstance* instance, void* /* g_class */)
{
g_return_if_fail(GTK_IS_WIDGET(instance));
- gtk_widget_set_has_window(GTK_WIDGET(instance), true);
+ gtk_widget_set_has_surface(GTK_WIDGET(instance), true);
}
} // anonymous namespace
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 4375c51..6eb5da4 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -115,9 +115,9 @@ void MyWidget::on_size_allocate(const Gtk::Allocation& allocation,
//(We will not be given heights or widths less than we have requested, though
//we might get more)
- if(m_refGdkWindow)
+ if(m_refGdkSurface)
{
- m_refGdkWindow->move_resize( allocation.get_x(), allocation.get_y(),
+ m_refGdkSurface->move_resize( allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height() );
}
@@ -140,7 +140,7 @@ void MyWidget::on_unmap()
void MyWidget::on_realize()
{
//Do not call base class Gtk::Widget::on_realize().
- //It's intended only for widgets that set_has_window(false).
+ //It's intended only for widgets that set_has_surface(false).
set_realized();
@@ -152,26 +152,26 @@ void MyWidget::on_realize()
<< ", bottom=" << m_padding.get_bottom()
<< ", left=" << m_padding.get_left() << std::endl;
- if(!m_refGdkWindow)
+ if(!m_refGdkSurface)
{
- //Create the GdkWindow:
- m_refGdkWindow = Gdk::Window::create_child(get_parent_window(), get_allocation());
- set_window(m_refGdkWindow);
+ //Create the GdkSurface:
+ m_refGdkSurface = Gdk::Surface::create_child(get_parent_surface(), get_allocation());
+ set_surface(m_refGdkSurface);
//make the widget receive expose events
- m_refGdkWindow->set_user_data(gobj());
+ m_refGdkSurface->set_user_data(gobj());
}
}
void MyWidget::on_unrealize()
{
- m_refGdkWindow.reset();
+ m_refGdkSurface.reset();
//Call base class:
Gtk::Widget::on_unrealize();
}
-void MyWidget::snapshot_vfunc(Gtk::Snapshot& snapshot)
+void MyWidget::snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot)
{
const auto allocation = get_allocation();
auto clip = get_clip();
@@ -180,7 +180,7 @@ void MyWidget::snapshot_vfunc(Gtk::Snapshot& snapshot)
auto refStyleContext = get_style_context();
// Create a cairo context to draw on.
- auto cr = snapshot.append_cairo(clip, "MyCairoNode");
+ auto cr = snapshot->append_cairo(clip, "MyCairoNode");
// paint the background
refStyleContext->render_background(cr,
diff --git a/examples/book/custom/custom_widget/mywidget.h b/examples/book/custom/custom_widget/mywidget.h
index f35387d..3b7c1f2 100644
--- a/examples/book/custom/custom_widget/mywidget.h
+++ b/examples/book/custom/custom_widget/mywidget.h
@@ -44,13 +44,13 @@ protected:
void on_unmap() override;
void on_realize() override;
void on_unrealize() override;
- void snapshot_vfunc(Gtk::Snapshot& snapshot) override;
+ void snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot) override;
//Signal handler:
void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
Gtk::Border m_padding;
- Glib::RefPtr<Gdk::Window> m_refGdkWindow;
+ Glib::RefPtr<Gdk::Surface> m_refGdkSurface;
Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;
};
diff --git a/examples/book/custom/custom_widget/mywidget2.cc b/examples/book/custom/custom_widget/mywidget2.cc
index 6d52736..0a7ea10 100644
--- a/examples/book/custom/custom_widget/mywidget2.cc
+++ b/examples/book/custom/custom_widget/mywidget2.cc
@@ -114,9 +114,9 @@ void MyWidget2::on_size_allocate(const Gtk::Allocation& allocation,
//(We will not be given heights or widths less than we have requested, though
//we might get more)
- if(m_refGdkWindow)
+ if(m_refGdkSurface)
{
- m_refGdkWindow->move_resize( allocation.get_x(), allocation.get_y(),
+ m_refGdkSurface->move_resize( allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height() );
}
@@ -139,7 +139,7 @@ void MyWidget2::on_unmap()
void MyWidget2::on_realize()
{
//Do not call base class Gtk::Widget::on_realize().
- //It's intended only for widgets that set_has_window(false).
+ //It's intended only for widgets that set_has_surface(false).
set_realized();
@@ -151,20 +151,20 @@ void MyWidget2::on_realize()
<< ", bottom=" << m_padding.get_bottom()
<< ", left=" << m_padding.get_left() << std::endl;
- if(!m_refGdkWindow)
+ if(!m_refGdkSurface)
{
- //Create the GdkWindow:
- m_refGdkWindow = Gdk::Window::create_child(get_parent_window(), get_allocation());
- set_window(m_refGdkWindow);
+ //Create the GdkSurface:
+ m_refGdkSurface = Gdk::Surface::create_child(get_parent_surface(), get_allocation());
+ set_surface(m_refGdkSurface);
//make the widget receive expose events
- m_refGdkWindow->set_user_data(gobj());
+ m_refGdkSurface->set_user_data(gobj());
}
}
void MyWidget2::on_unrealize()
{
- m_refGdkWindow.reset();
+ m_refGdkSurface.reset();
//Call base class:
Gtk::Widget::on_unrealize();
diff --git a/examples/book/custom/custom_widget/mywidget2.h b/examples/book/custom/custom_widget/mywidget2.h
index 4a6ea80..5d63624 100644
--- a/examples/book/custom/custom_widget/mywidget2.h
+++ b/examples/book/custom/custom_widget/mywidget2.h
@@ -49,7 +49,7 @@ protected:
void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section, const Glib::Error& error);
Gtk::Border m_padding;
- Glib::RefPtr<Gdk::Window> m_refGdkWindow;
+ Glib::RefPtr<Gdk::Surface> m_refGdkSurface;
Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;
};
diff --git a/examples/book/drawingarea/clock/clock.cc b/examples/book/drawingarea/clock/clock.cc
index 46b7e5a..603677a 100644
--- a/examples/book/drawingarea/clock/clock.cc
+++ b/examples/book/drawingarea/clock/clock.cc
@@ -1,5 +1,3 @@
-//$Id: clock.cc 836 2007-05-09 03:02:38Z jjongsma $ -*- c++ -*-
-
/* gtkmm example Copyright (C) 2002 gtkmm development team
*
* This program is free software; you can redistribute it and/or modify
@@ -124,12 +122,12 @@ void Clock::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int heig
bool Clock::on_timeout()
{
// force our program to redraw the entire clock.
- auto win = get_window();
- if (win)
+ auto surface = get_surface();
+ if (surface)
{
- Gdk::Rectangle r(0, 0, get_allocation().get_width(),
+ Gdk::Rectangle rect(0, 0, get_allocation().get_width(),
get_allocation().get_height());
- win->invalidate_rect(r, false);
+ surface->invalidate_rect(rect);
}
return true;
}
diff --git a/examples/book/drawingarea/joins/myarea.cc b/examples/book/drawingarea/joins/myarea.cc
index 1910ec8..d7de919 100644
--- a/examples/book/drawingarea/joins/myarea.cc
+++ b/examples/book/drawingarea/joins/myarea.cc
@@ -28,9 +28,9 @@ MyArea::~MyArea()
void MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height)
{
- // This is where we draw on the window
- auto window = get_window();
- if(window)
+ // This is where we draw on the surface
+ auto surface = get_surface();
+ if(surface)
{
cr->set_line_width(10.0);
diff --git a/examples/book/drawingarea/thin_lines/myarea.cc b/examples/book/drawingarea/thin_lines/myarea.cc
index d4a8d75..368820d 100644
--- a/examples/book/drawingarea/thin_lines/myarea.cc
+++ b/examples/book/drawingarea/thin_lines/myarea.cc
@@ -56,10 +56,10 @@ void MyArea::fix_lines(bool fix)
// force the redraw of the image
void MyArea::force_redraw()
{
- auto win = get_window();
- if (win)
+ auto surface = get_surface();
+ if (surface)
{
- Gdk::Rectangle r(0, 0, get_allocation().get_width(), get_allocation().get_height());
- win->invalidate_rect(r, false);
+ Gdk::Rectangle rect(0, 0, get_allocation().get_width(), get_allocation().get_height());
+ surface->invalidate_rect(rect);
}
}
diff --git a/examples/book/popover/examplewindow.cc b/examples/book/popover/examplewindow.cc
index 508c2fe..3e6d191 100644
--- a/examples/book/popover/examplewindow.cc
+++ b/examples/book/popover/examplewindow.cc
@@ -157,7 +157,7 @@ void ExampleWindow::on_day_selected()
double x = 0.0;
double y = 0.0;
current_event_button->get_coords(x, y);
- current_event_button->get_window()->coords_to_parent(x, y, x, y);
+ current_event_button->get_surface()->coords_to_parent(x, y, x, y);
Gdk::Rectangle rect;
auto allocation = m_calendar.get_allocation();
rect.set_x(x - allocation.get_x());
diff --git a/examples/book/printing/advanced/previewdialog.cc
b/examples/book/printing/advanced/previewdialog.cc
index 7948ad3..fb532d1 100644
--- a/examples/book/printing/advanced/previewdialog.cc
+++ b/examples/book/printing/advanced/previewdialog.cc
@@ -37,17 +37,21 @@ PreviewDialog::PreviewDialog(
{
set_transient_for(parent);
set_title("Preview");
+ set_size_request(300, 300);
m_VBox.set_margin(2);
add(m_VBox);
m_HBox.pack_start(m_PageSpin, Gtk::PackOptions::EXPAND_WIDGET);
+ m_PageSpin.set_vexpand(false);
m_HBox.pack_start(m_CloseButton, Gtk::PackOptions::SHRINK);
m_VBox.pack_start(m_HBox, Gtk::PackOptions::SHRINK);
- m_DrawingArea.set_content_width(200);
- m_DrawingArea.set_content_height(300);
- m_VBox.pack_start(m_DrawingArea, Gtk::PackOptions::EXPAND_WIDGET);
+ m_ScrolledWindow.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);
+ m_VBox.pack_start(m_ScrolledWindow, Gtk::PackOptions::EXPAND_WIDGET);
+ m_DrawingArea.set_content_width(300);
+ m_DrawingArea.set_content_height(600);
+ m_ScrolledWindow.add(m_DrawingArea);
m_refPreview->signal_ready().connect(
sigc::mem_fun(*this, &PreviewDialog::on_popreview_ready));
@@ -74,12 +78,15 @@ PreviewDialog::~PreviewDialog()
void PreviewDialog::on_drawing_area_realized()
{
- auto gdk_window = m_DrawingArea.get_window();
- if (gdk_window)
+ auto gdk_surface = m_DrawingArea.get_surface();
+ if (gdk_surface)
{
- auto drawing_context = gdk_window->begin_draw_frame(gdk_window->get_clip_region());
- m_refCairoContext = drawing_context->get_cairo_context();
- gdk_window->end_draw_frame(drawing_context);
+ const int scale = gdk_surface->get_scale_factor();
+ const int width = gdk_surface->get_width() * scale;
+ const int height = gdk_surface->get_height() * scale;
+ auto cairo_surface = gdk_surface->create_similar_image_surface(
+ Cairo::Surface::Format::ARGB32, width, height, scale);
+ m_refCairoContext = Cairo::Context::create(cairo_surface);
if (m_refPrintContext)
m_refPrintContext->set_cairo_context(m_refCairoContext, 72, 72);
diff --git a/examples/book/printing/advanced/previewdialog.h b/examples/book/printing/advanced/previewdialog.h
index ad12aa9..b4c61e2 100644
--- a/examples/book/printing/advanced/previewdialog.h
+++ b/examples/book/printing/advanced/previewdialog.h
@@ -54,6 +54,7 @@ protected:
Glib::RefPtr<Gtk::Adjustment> m_SpinAdjustment;
Gtk::SpinButton m_PageSpin;
Gtk::Button m_CloseButton;
+ Gtk::ScrolledWindow m_ScrolledWindow;
Gtk::DrawingArea m_DrawingArea;
int m_Page;
diff --git a/examples/others/cellrenderercustom/cellrendererpopup.cc
b/examples/others/cellrenderercustom/cellrendererpopup.cc
index 5450b49..71f9db4 100644
--- a/examples/others/cellrenderercustom/cellrendererpopup.cc
+++ b/examples/others/cellrenderercustom/cellrendererpopup.cc
@@ -23,7 +23,7 @@
namespace
{
-bool grab_on_window(const Glib::RefPtr<Gdk::Window>& window)
+bool grab_on_window(const Glib::RefPtr<Gdk::Surface>& surface)
{
Glib::RefPtr<Gdk::Device> device (Glib::wrap(gtk_get_current_event_device(), true));
@@ -31,7 +31,7 @@ bool grab_on_window(const Glib::RefPtr<Gdk::Window>& window)
{
auto seat = device->get_seat();
if (seat &&
- seat->grab(window, Gdk::Seat::Capabilities::ALL, true) == Gdk::GrabStatus::SUCCESS)
+ seat->grab(surface, Gdk::Seat::Capabilities::ALL, true) == Gdk::GrabStatus::SUCCESS)
return true;
}
@@ -206,7 +206,7 @@ void CellRendererPopup::on_show_popup(const Glib::ustring&, int, int y1, int x2,
if(focus_widget_)
focus_widget_->grab_focus();
- grab_on_window(popup_window_.get_window());
+ grab_on_window(popup_window_.get_surface());
}
void CellRendererPopup::on_hide_popup()
@@ -243,7 +243,7 @@ void CellRendererPopup::on_popup_window_pressed(int /* n_press */, double /* x *
std::static_pointer_cast<const Gdk::EventButton>(event)->get_root_coords(x, y);
int xoffset = 0, yoffset = 0;
- popup_window_.get_window()->get_root_origin(xoffset, yoffset);
+ popup_window_.get_surface()->get_root_origin(xoffset, yoffset);
const auto alloc = popup_window_.get_allocation();
@@ -307,13 +307,13 @@ void CellRendererPopup::on_popup_arrow_clicked()
return;
}
- if(!grab_on_window(popup_entry_->get_window()))
+ if(!grab_on_window(popup_entry_->get_surface()))
return;
popup_entry_->select_region(0, 0);
int x = 0, y = 0;
- popup_entry_->get_window()->get_origin(x, y);
+ popup_entry_->get_surface()->get_origin(x, y);
const auto alloc = popup_entry_->get_allocation();
diff --git a/examples/others/cellrenderercustom/cellrenderertoggle.cc
b/examples/others/cellrenderercustom/cellrenderertoggle.cc
index 36761fe..697c86a 100644
--- a/examples/others/cellrenderercustom/cellrenderertoggle.cc
+++ b/examples/others/cellrenderercustom/cellrenderertoggle.cc
@@ -52,7 +52,7 @@ protected:
void get_preferred_height_for_width_vfunc(Gtk::Widget& widget, int width,
int& minimum_height, int& natural_height) const override;
- void snapshot_vfunc(Gtk::Snapshot& snapshot,
+ void snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot,
Gtk::Widget& widget,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
@@ -166,7 +166,7 @@ void MyCellRendererToggle::get_preferred_height_for_width_vfunc(Gtk::Widget& wid
get_preferred_height_vfunc(widget, minimum_height, natural_height);
}
-void MyCellRendererToggle::snapshot_vfunc(Gtk::Snapshot& snapshot,
+void MyCellRendererToggle::snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot,
Gtk::Widget& widget,
const Gdk::Rectangle& /* background_area */,
const Gdk::Rectangle& cell_area,
@@ -204,7 +204,7 @@ void MyCellRendererToggle::snapshot_vfunc(Gtk::Snapshot& snapshot,
style_context->set_state(state);
// Create a cairo context to draw on.
- auto cr = snapshot.append_cairo(cell_area, "MyCairoNode");
+ auto cr = snapshot->append_cairo(cell_area, "MyCairoNode");
if (property_radio_)
{
diff --git a/examples/others/dnd/dndwindow.cc b/examples/others/dnd/dndwindow.cc
index 14db382..5fe0bfe 100644
--- a/examples/others/dnd/dndwindow.cc
+++ b/examples/others/dnd/dndwindow.cc
@@ -83,7 +83,7 @@ DnDWindow::DnDWindow()
m_Button.drag_source_set(Gdk::ContentFormats::create(m_listTargets), Gdk::ModifierType::BUTTON1_MASK |
Gdk::ModifierType::BUTTON3_MASK,
Gdk::DragAction::COPY | Gdk::DragAction::MOVE);
- m_Button.drag_source_set_icon(Gdk::Cairo::create_surface_from_pixbuf(m_drag_icon, 1));
+ m_Button.drag_source_set_icon(Gdk::Texture::create_for_pixbuf(m_drag_icon));
m_Grid.attach(m_Button, 0, 1);
m_Button.set_hexpand(true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]