[gtkmm-documentation] examples: Update for latest gtkmm4 (no Gdk::EventButton, etc.)



commit 71c2853e76a941b7794d8f6eeee46dcf84db005b
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Feb 25 13:12:40 2020 +0100

    examples: Update for latest gtkmm4 (no Gdk::EventButton, etc.)
    
    * examples/book/buttons/filechooserbutton/examplewindow.cc:
    Don't use removed Gtk::FileChooser::set_local_only().
    * examples/book/dialogs/filechooserdialog/examplewindow.cc:
    * examples/book/dialogs/filechoosernative/examplewindow.cc:
    * examples/book/recent_files/examplewindow.cc:
    Use FileChooser::get_file() instead of removed get_filename().
    * examples/book/drag_and_drop/dndwindow.[cc|h]:
    Use Gtk::DragSource::signal_prepare() instead of removed
    Gdk::ContentProvider::create() with callback function.
    * examples/book/infobar/examplewindow.cc: Use Gtk::Container::add()
    instead of removed Gtk::InfoBar::get_content_area().
    * examples/book/popover/examplewindow.cc: Don't cast the Gdk::Event to a
    subclass. Gdk::Event does not have subclasses now.
    * examples/book/treeview/drag_and_drop/treemodel_dnd.[cc|h]:
    Gtk::TreeDragDest::row_drop_possible_vfunc() has got a changed signature
    (Glib::ValueBase& instead of Gtk::SelectionData&).
    * examples/others/cellrenderercustom/cellrendererpopup.cc:
    * examples/others/cellrenderercustom/popupentry.cc:
    * examples/others/dnd/dndwindow.cc: The Gtk::Window ctor has no
    WindowType argument.

 examples/book/buttons/filechooserbutton/examplewindow.cc |  5 -----
 examples/book/dialogs/filechooserdialog/examplewindow.cc |  5 ++---
 examples/book/dialogs/filechoosernative/examplewindow.cc |  2 +-
 examples/book/drag_and_drop/dndwindow.cc                 | 15 +++++++--------
 examples/book/drag_and_drop/dndwindow.h                  |  4 ++--
 examples/book/infobar/examplewindow.cc                   |  5 +----
 examples/book/popover/examplewindow.cc                   | 12 ++----------
 examples/book/recent_files/examplewindow.cc              |  3 +--
 examples/book/treeview/drag_and_drop/treemodel_dnd.cc    | 13 ++++---------
 examples/book/treeview/drag_and_drop/treemodel_dnd.h     |  5 +----
 examples/others/cellrenderercustom/cellrendererpopup.cc  |  2 +-
 examples/others/cellrenderercustom/popupentry.cc         |  2 +-
 examples/others/dnd/dndwindow.cc                         |  2 +-
 13 files changed, 24 insertions(+), 51 deletions(-)
---
diff --git a/examples/book/buttons/filechooserbutton/examplewindow.cc 
b/examples/book/buttons/filechooserbutton/examplewindow.cc
index 5a738e6..a95766c 100644
--- a/examples/book/buttons/filechooserbutton/examplewindow.cc
+++ b/examples/book/buttons/filechooserbutton/examplewindow.cc
@@ -26,13 +26,8 @@ ExampleWindow::ExampleWindow()
 
   m_button.set_margin(10);
   add(m_button);
-
-  //Allow our file chooser to select remote URIs,
-  //for instance via bookmarked servers:
-  m_button.set_local_only(false);
 }
 
 ExampleWindow::~ExampleWindow()
 {
 }
-
diff --git a/examples/book/dialogs/filechooserdialog/examplewindow.cc 
b/examples/book/dialogs/filechooserdialog/examplewindow.cc
index b34e617..ea38aca 100644
--- a/examples/book/dialogs/filechooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/filechooserdialog/examplewindow.cc
@@ -60,8 +60,7 @@ void ExampleWindow::on_button_folder_clicked()
     case Gtk::ResponseType::OK:
     {
       std::cout << "Select clicked." << std::endl;
-      std::cout << "Folder selected: " << dialog.get_filename()
-          << std::endl;
+      std::cout << "Folder selected: " << dialog.get_file()->get_path() << std::endl;
       break;
     }
     case Gtk::ResponseType::CANCEL:
@@ -117,7 +116,7 @@ void ExampleWindow::on_button_file_clicked()
       std::cout << "Open clicked." << std::endl;
 
       //Notice that this is a std::string, not a Glib::ustring.
-      auto filename = dialog.get_filename();
+      auto filename = dialog.get_file()->get_path();
       std::cout << "File selected: " <<  filename << std::endl;
       break;
     }
diff --git a/examples/book/dialogs/filechoosernative/examplewindow.cc 
b/examples/book/dialogs/filechoosernative/examplewindow.cc
index f6c7f8a..032cba8 100644
--- a/examples/book/dialogs/filechoosernative/examplewindow.cc
+++ b/examples/book/dialogs/filechoosernative/examplewindow.cc
@@ -56,7 +56,7 @@ void ExampleWindow::on_button_file_clicked(Gtk::FileChooser::Action action)
     std::cout << (open ? "Open" : "Save") << " clicked." << std::endl;
 
     // Notice that this is a std::string, not a Glib::ustring.
-    auto filename = dialog->get_filename();
+    auto filename = dialog->get_file()->get_path();
     std::cout << "File selected: " <<  filename << std::endl;
     break;
   }
diff --git a/examples/book/drag_and_drop/dndwindow.cc b/examples/book/drag_and_drop/dndwindow.cc
index a2cdc60..ece2383 100644
--- a/examples/book/drag_and_drop/dndwindow.cc
+++ b/examples/book/drag_and_drop/dndwindow.cc
@@ -34,9 +34,8 @@ DnDWindow::DnDWindow()
   //Make m_Label_Drag a DnD drag source:
   const GType ustring_type = Glib::Value<Glib::ustring>::value_type();
   auto source = Gtk::DragSource::create();
-  auto content = Gdk::ContentProvider::create(ustring_type,
-    sigc::mem_fun(*this, &DnDWindow::on_label_drag_get_data));
-  source->set_content(content);
+  source->signal_prepare().connect(
+    sigc::mem_fun(*this, &DnDWindow::on_label_drag_prepare_data), false);
   m_Label_Drag.add_controller(source);
 
   m_HBox.add(m_Label_Drag);
@@ -60,14 +59,14 @@ DnDWindow::~DnDWindow()
 }
 
 // In this simple example where just a small amount of data is copied,
-// it would be reasonable to store the data in the ContentProvider.
-// Then this callback routine would be unnecessary.
-void DnDWindow::on_label_drag_get_data(Glib::ValueBase& value)
+// it would be reasonable to store the ContentProvider in the DragSource.
+// Then this signal handler would be unnecessary.
+Glib::RefPtr<Gdk::ContentProvider> DnDWindow::on_label_drag_prepare_data(double, double)
 {
   Glib::Value<Glib::ustring> ustring_value;
-  ustring_value.init(value.gobj());
+  ustring_value.init(ustring_value.value_type());
   ustring_value.set("I'm Data!");
-  value = ustring_value;
+  return Gdk::ContentProvider::create(ustring_value);
 }
 
 bool DnDWindow::on_button_drop_drag_drop(const Glib::RefPtr<Gdk::Drop>& drop, int, int)
diff --git a/examples/book/drag_and_drop/dndwindow.h b/examples/book/drag_and_drop/dndwindow.h
index 1a50a6a..563837f 100644
--- a/examples/book/drag_and_drop/dndwindow.h
+++ b/examples/book/drag_and_drop/dndwindow.h
@@ -31,8 +31,8 @@ public:
   virtual ~DnDWindow();
 
 protected:
-  //Signal handlers and callbacks:
-  void on_label_drag_get_data(Glib::ValueBase& value);
+  //Signal handlers:
+  Glib::RefPtr<Gdk::ContentProvider> on_label_drag_prepare_data(double x, double y);
   bool on_button_drop_drag_drop(const Glib::RefPtr<Gdk::Drop>& drop, int x, int y);
   void on_button_drop_got_data(Glib::RefPtr<Gio::AsyncResult>& result,
     const Glib::RefPtr<Gdk::Drop>& drop);
diff --git a/examples/book/infobar/examplewindow.cc b/examples/book/infobar/examplewindow.cc
index 30bbb38..f885628 100644
--- a/examples/book/infobar/examplewindow.cc
+++ b/examples/book/infobar/examplewindow.cc
@@ -28,10 +28,7 @@ ExampleWindow::ExampleWindow()
   add(m_VBox);
 
   // Add the message label to the InfoBar:
-  auto infoBarContainer =
-    dynamic_cast<Gtk::Container*>(m_InfoBar.get_content_area());
-  if (infoBarContainer)
-    infoBarContainer->add(m_Message_Label);
+  m_InfoBar.add(m_Message_Label);
 
   // Add an ok button to the InfoBar:
   m_InfoBar.add_button("_OK", 0);
diff --git a/examples/book/popover/examplewindow.cc b/examples/book/popover/examplewindow.cc
index 0dd97eb..cd6f09e 100644
--- a/examples/book/popover/examplewindow.cc
+++ b/examples/book/popover/examplewindow.cc
@@ -137,22 +137,14 @@ void ExampleWindow::configure_cal_popover()
 
 void ExampleWindow::on_day_selected()
 {
-  auto current_event = Glib::wrap(gtk_get_current_event(), false);
+  const auto current_event = Glib::wrap(gtk_get_current_event(), false);
 
   if (current_event->get_event_type() != Gdk::Event::Type::BUTTON_PRESS)
-  {
     return;
-  }
-
-  // The event is a GdkEventButton.
-  // This suspicious-looking cast is okay because Gdk::EventButton
-  // does not add any data members to those of Gdk::Event.
-  const Glib::RefPtr<Gdk::EventButton> current_event_button =
-    std::static_pointer_cast<Gdk::EventButton>(current_event);
 
   double x = 0.0;
   double y = 0.0;
-  current_event_button->get_coords(x, y);
+  current_event->get_position(x, y);
   Gdk::Rectangle rect;
   auto allocation = m_calendar.get_allocation();
   rect.set_x(x - allocation.get_x());
diff --git a/examples/book/recent_files/examplewindow.cc b/examples/book/recent_files/examplewindow.cc
index 26525fc..8abc9bd 100644
--- a/examples/book/recent_files/examplewindow.cc
+++ b/examples/book/recent_files/examplewindow.cc
@@ -154,10 +154,9 @@ void ExampleWindow::on_menu_file_files_dialog()
   dialog.hide();
   if (response == Gtk::ResponseType::OK)
   {
-    auto selected_uri = dialog.get_uri();
+    auto selected_uri = dialog.get_file()->get_uri();
     std::cout << "URI selected = " << selected_uri << std::endl;
     std::cout << (m_refRecentManager->has_item(selected_uri) ? "A" : "Not a")
       << " recently used file" << std::endl;
   }
 }
-
diff --git a/examples/book/treeview/drag_and_drop/treemodel_dnd.cc 
b/examples/book/treeview/drag_and_drop/treemodel_dnd.cc
index 1eb7e78..54bc93b 100644
--- a/examples/book/treeview/drag_and_drop/treemodel_dnd.cc
+++ b/examples/book/treeview/drag_and_drop/treemodel_dnd.cc
@@ -51,7 +51,7 @@ TreeModel_Dnd::row_draggable_vfunc(const Gtk::TreeModel::Path& path) const
 
 bool
 TreeModel_Dnd::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest,
-        const Gtk::SelectionData& selection_data) const
+        const Glib::ValueBase& value) const
 {
   //Make the value of the "receives drags" column determine whether a row can be
   //dragged into it:
@@ -77,18 +77,13 @@ TreeModel_Dnd::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest,
     }
   }
 
-  // You could also examine the row being dragged (via selection_data)
+  // You could also examine the row being dragged (via value)
   // if you must look at both rows to see whether a drop should be allowed.
   // You could use
   //   Glib::RefPtr<const Gtk::TreeModel> model_dragged_row;
   //   Gtk::TreeModel::Path path_dragged_row;
-  //   Gtk::TreeModel::Path::get_from_selection_data(selection_data,
+  //   Gtk::TreeModel::Path::get_row_drag_data(value,
   //     model_dragged_row, path_dragged_row);
-  // This is risky, though. If the row being dragged, and thus selection_data,
-  // does not originate in the process that's calling get_from_selection_data(),
-  // you'll most likely get a segmentation fault. See the documentation of
-  // Gtk::TreePath::get_from_selection_data() or gtk_tree_get_row_drag_data().
 
-  return Gtk::TreeStore::row_drop_possible_vfunc(dest, selection_data);
+  return Gtk::TreeStore::row_drop_possible_vfunc(dest, value);
 }
-
diff --git a/examples/book/treeview/drag_and_drop/treemodel_dnd.h 
b/examples/book/treeview/drag_and_drop/treemodel_dnd.h
index 98a308d..e03c989 100644
--- a/examples/book/treeview/drag_and_drop/treemodel_dnd.h
+++ b/examples/book/treeview/drag_and_drop/treemodel_dnd.h
@@ -1,5 +1,3 @@
-//$Id: treemodel_dnd.h 852 2007-06-10 09:12:36Z murrayc $ -*- c++ -*-
-
 /* gtkmm example Copyright (C) 2002 gtkmm development team
  *
  * This program is free software; you can redistribute it and/or modify
@@ -49,8 +47,7 @@ public:
 protected:
   //Overridden virtual functions:
   bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const override;
-  bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Gtk::SelectionData& selection_data) 
const override;
-
+  bool row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Glib::ValueBase& value) const 
override;
 };
 
 #endif //GTKMM_EXAMPLE_TREEMODEL_DND_H
diff --git a/examples/others/cellrenderercustom/cellrendererpopup.cc 
b/examples/others/cellrenderercustom/cellrendererpopup.cc
index 40baf0d..2deeaa3 100644
--- a/examples/others/cellrenderercustom/cellrendererpopup.cc
+++ b/examples/others/cellrenderercustom/cellrendererpopup.cc
@@ -47,7 +47,7 @@ CellRendererPopup::CellRendererPopup()
   Glib::ObjectBase      (typeid(CellRendererPopup)),
   Gtk::CellRendererText (),
   button_width_         (-1),
-  popup_window_         (Gtk::WindowType::POPUP),
+  popup_window_         (),
   focus_widget_         (nullptr),
   popup_entry_          (nullptr),
   shown_                (false),
diff --git a/examples/others/cellrenderercustom/popupentry.cc 
b/examples/others/cellrenderercustom/popupentry.cc
index 9afebad..2e04b5b 100644
--- a/examples/others/cellrenderercustom/popupentry.cc
+++ b/examples/others/cellrenderercustom/popupentry.cc
@@ -77,7 +77,7 @@ bool PopupEntry::get_editing_canceled() const
 // static
 int PopupEntry::get_button_width()
 {
-  Gtk::Window window (Gtk::WindowType::POPUP);
+  Gtk::Window window;
 
   Gtk::Button *const button = new Gtk::Button();
   window.add(*Gtk::manage(button));
diff --git a/examples/others/dnd/dndwindow.cc b/examples/others/dnd/dndwindow.cc
index 3f31759..1308cc8 100644
--- a/examples/others/dnd/dndwindow.cc
+++ b/examples/others/dnd/dndwindow.cc
@@ -25,7 +25,7 @@ DnDWindow::DnDWindow()
 : m_Label_Drop("Drop here\n"),
   m_Label_Drag("Drag Here\n"),
   m_Label_Popup("Popup\n"),
-  m_PopupWindow(Gtk::WindowType::POPUP)
+  m_PopupWindow()
 {
   set_title("Drag-and-drop example");
   set_default_size(300, 150);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]