[gtkmm-documentation] examples/book/[cd]*: Update some examples after Gtk::Container was removed
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] examples/book/[cd]*: Update some examples after Gtk::Container was removed
- Date: Tue, 26 May 2020 07:08:31 +0000 (UTC)
commit 3f6af47370e3710d701bb5e0f2d937e4ed28e101
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue May 26 09:06:25 2020 +0200
examples/book/[cd]*: Update some examples after Gtk::Container was removed
Gtk::Bin, Gtk::Container and Gtk::Dialog::run() have been removed.
This removal affects most example programs. This commit fixes
example programs in examples/book/[cd]*, i.e. subdirectories with names
beginning with c or d.
Some of these examples contain dialogs. Modal dialogs became more
complicated when gtk_dialog_run() and Gtk::Dialog::run() were removed.
examples/book/clipboard/ideal/examplewindow.cc | 12 +--
examples/book/clipboard/simple/examplewindow.cc | 12 +--
examples/book/combobox/complex/examplewindow.cc | 2 +-
.../book/combobox/entry_complex/examplewindow.cc | 2 +-
examples/book/combobox/entry_text/examplewindow.cc | 2 +-
examples/book/combobox/text/examplewindow.cc | 2 +-
.../book/custom/custom_container/examplewindow.cc | 8 +-
.../book/custom/custom_container/mycontainer.cc | 5 +-
.../book/custom/custom_container/mycontainer.h | 10 +-
.../book/custom/custom_widget/examplewindow.cc | 4 +-
examples/book/custom/custom_widget/mywidget.cc | 4 +-
examples/book/dialogs/aboutdialog/examplewindow.cc | 9 +-
.../dialogs/colorchooserdialog/examplewindow.cc | 35 ++++---
.../dialogs/colorchooserdialog/examplewindow.h | 3 +
.../dialogs/filechooserdialog/examplewindow.cc | 109 ++++++++++++---------
.../book/dialogs/filechooserdialog/examplewindow.h | 2 +
.../dialogs/filechoosernative/examplewindow.cc | 23 +++--
.../book/dialogs/filechoosernative/examplewindow.h | 3 +
.../dialogs/fontchooserdialog/examplewindow.cc | 30 ++++--
.../book/dialogs/fontchooserdialog/examplewindow.h | 4 +
.../book/dialogs/messagedialog/examplewindow.cc | 34 ++++---
.../book/dialogs/messagedialog/examplewindow.h | 4 +
examples/book/dialogs/simple/examplewindow.cc | 17 ++--
examples/book/dialogs/simple/examplewindow.h | 2 +
examples/book/drag_and_drop/dndwindow.cc | 6 +-
examples/book/drawingarea/arcs/main.cc | 3 +-
examples/book/drawingarea/clock/main.cc | 3 +-
examples/book/drawingarea/curve/main.cc | 3 +-
examples/book/drawingarea/image/main.cc | 3 +-
examples/book/drawingarea/joins/main.cc | 3 +-
examples/book/drawingarea/pango_text/main.cc | 3 +-
examples/book/drawingarea/simple/main.cc | 3 +-
.../book/drawingarea/thin_lines/examplewindow.cc | 11 +--
.../book/drawingarea/thin_lines/examplewindow.h | 4 +-
34 files changed, 227 insertions(+), 153 deletions(-)
---
diff --git a/examples/book/clipboard/ideal/examplewindow.cc b/examples/book/clipboard/ideal/examplewindow.cc
index 80fd286..762d066 100644
--- a/examples/book/clipboard/ideal/examplewindow.cc
+++ b/examples/book/clipboard/ideal/examplewindow.cc
@@ -37,12 +37,12 @@ ExampleWindow::ExampleWindow()
set_title("Gtk::Clipboard example");
m_VBox.set_margin(12);
- add(m_VBox);
+ set_child(m_VBox);
- m_VBox.add(m_Label);
+ m_VBox.append(m_Label);
//Fill Grid:
- m_VBox.add(m_Grid);
+ m_VBox.append(m_Grid);
m_Grid.set_expand(true);
m_Grid.set_row_homogeneous(true);
m_Grid.set_column_homogeneous(true);
@@ -52,16 +52,16 @@ ExampleWindow::ExampleWindow()
m_Grid.attach(m_ButtonB2, 1, 1);
//Add ButtonBox to bottom:
- m_VBox.add(m_ButtonBox);
+ m_VBox.append(m_ButtonBox);
m_VBox.set_spacing(6);
//Fill ButtonBox:
- m_ButtonBox.add(m_Button_Copy);
+ m_ButtonBox.append(m_Button_Copy);
m_Button_Copy.set_hexpand(true);
m_Button_Copy.set_halign(Gtk::Align::END);
m_Button_Copy.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_copy) );
- m_ButtonBox.add(m_Button_Paste);
+ m_ButtonBox.append(m_Button_Paste);
m_Button_Paste.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_paste) );
diff --git a/examples/book/clipboard/simple/examplewindow.cc b/examples/book/clipboard/simple/examplewindow.cc
index 4794176..40ac684 100644
--- a/examples/book/clipboard/simple/examplewindow.cc
+++ b/examples/book/clipboard/simple/examplewindow.cc
@@ -27,12 +27,12 @@ ExampleWindow::ExampleWindow()
set_title("Gtk::Clipboard example");
m_VBox.set_margin(12);
- add(m_VBox);
+ set_child(m_VBox);
- m_VBox.add(m_Label);
+ m_VBox.append(m_Label);
//Fill Grid:
- m_VBox.add(m_Grid);
+ m_VBox.append(m_Grid);
m_Grid.set_expand(true);
m_Grid.set_row_homogeneous(true);
m_Grid.set_column_homogeneous(true);
@@ -42,16 +42,16 @@ ExampleWindow::ExampleWindow()
m_Grid.attach(m_ButtonB2, 1, 1);
//Add ButtonBox to bottom:
- m_VBox.add(m_ButtonBox);
+ m_VBox.append(m_ButtonBox);
m_VBox.set_spacing(6);
//Fill ButtonBox:
- m_ButtonBox.add(m_Button_Copy);
+ m_ButtonBox.append(m_Button_Copy);
m_Button_Copy.set_hexpand(true);
m_Button_Copy.set_halign(Gtk::Align::END);
m_Button_Copy.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_copy) );
- m_ButtonBox.add(m_Button_Paste);
+ m_ButtonBox.append(m_Button_Paste);
m_Button_Paste.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_paste) );
}
diff --git a/examples/book/combobox/complex/examplewindow.cc b/examples/book/combobox/complex/examplewindow.cc
index 1643368..78c1b24 100644
--- a/examples/book/combobox/complex/examplewindow.cc
+++ b/examples/book/combobox/complex/examplewindow.cc
@@ -73,7 +73,7 @@ ExampleWindow::ExampleWindow()
m_Combo.pack_start(m_cell);
//Add the ComboBox to the window.
- add(m_Combo);
+ set_child(m_Combo);
//Connect signal handler:
m_Combo.signal_changed().connect( sigc::mem_fun(*this, &ExampleWindow::on_combo_changed) );
diff --git a/examples/book/combobox/entry_complex/examplewindow.cc
b/examples/book/combobox/entry_complex/examplewindow.cc
index d8aa211..6b241d5 100644
--- a/examples/book/combobox/entry_complex/examplewindow.cc
+++ b/examples/book/combobox/entry_complex/examplewindow.cc
@@ -65,7 +65,7 @@ ExampleWindow::ExampleWindow()
m_Combo.set_active(1);
//Add the ComboBox to the window.
- add(m_Combo);
+ set_child(m_Combo);
//Connect signal handlers:
m_Combo.signal_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_combo_changed));
diff --git a/examples/book/combobox/entry_text/examplewindow.cc
b/examples/book/combobox/entry_text/examplewindow.cc
index 9877844..fb95935 100644
--- a/examples/book/combobox/entry_text/examplewindow.cc
+++ b/examples/book/combobox/entry_text/examplewindow.cc
@@ -28,7 +28,7 @@ ExampleWindow::ExampleWindow()
m_Combo.append("something or other");
m_Combo.set_active(0);
- add(m_Combo);
+ set_child(m_Combo);
//Connect signal handlers:
m_Combo.signal_changed().connect(sigc::mem_fun(*this,
diff --git a/examples/book/combobox/text/examplewindow.cc b/examples/book/combobox/text/examplewindow.cc
index 85dfc10..285819a 100644
--- a/examples/book/combobox/text/examplewindow.cc
+++ b/examples/book/combobox/text/examplewindow.cc
@@ -27,7 +27,7 @@ ExampleWindow::ExampleWindow()
m_Combo.append("something or other");
m_Combo.set_active(1);
- add(m_Combo);
+ set_child(m_Combo);
//Connect signal handler:
m_Combo.signal_changed().connect(sigc::mem_fun(*this,
diff --git a/examples/book/custom/custom_container/examplewindow.cc
b/examples/book/custom/custom_container/examplewindow.cc
index adae209..cc8a0f5 100644
--- a/examples/book/custom/custom_container/examplewindow.cc
+++ b/examples/book/custom/custom_container/examplewindow.cc
@@ -27,16 +27,16 @@ ExampleWindow::ExampleWindow()
set_default_size(400, 200);
m_VBox.set_margin(6);
- add(m_VBox);
+ set_child(m_VBox);
//Add the child widgets to the custom container:
m_MyContainer.set_child_widgets(m_Button_One, m_Label_Two);
m_MyContainer.set_expand();
- m_VBox.add(m_MyContainer);
- m_VBox.add(m_ButtonBox);
+ m_VBox.append(m_MyContainer);
+ m_VBox.append(m_ButtonBox);
- m_ButtonBox.add(m_Button_Quit);
+ m_ButtonBox.append(m_Button_Quit);
m_ButtonBox.set_margin(6);
m_Button_Quit.set_hexpand(true);
m_Button_Quit.set_halign(Gtk::Align::END);
diff --git a/examples/book/custom/custom_container/mycontainer.cc
b/examples/book/custom/custom_container/mycontainer.cc
index 2e7ec41..e17047f 100644
--- a/examples/book/custom/custom_container/mycontainer.cc
+++ b/examples/book/custom/custom_container/mycontainer.cc
@@ -124,7 +124,7 @@ void MyContainer::measure_vfunc(Gtk::Orientation orientation, int for_size,
}
}
-void MyContainer::on_size_allocate(int width, int height, int baseline)
+void MyContainer::size_allocate_vfunc(int width, int height, int baseline)
{
//Do something with the space that we have actually been given:
//(We will not be given heights or widths less than we have requested, though
@@ -180,7 +180,7 @@ void MyContainer::on_size_allocate(int width, int height, int baseline)
m_child_two->size_allocate(child_allocation_two, baseline);
}
}
-
+#if 0
void MyContainer::forall_vfunc(const ForeachSlot& slot)
{
if (m_child_one)
@@ -244,3 +244,4 @@ GType MyContainer::child_type_vfunc() const
return G_TYPE_NONE;
}
}
+#endif
diff --git a/examples/book/custom/custom_container/mycontainer.h
b/examples/book/custom/custom_container/mycontainer.h
index 20be76b..6e0d86c 100644
--- a/examples/book/custom/custom_container/mycontainer.h
+++ b/examples/book/custom/custom_container/mycontainer.h
@@ -17,9 +17,9 @@
#ifndef GTKMM_CUSTOM_CONTAINER_MYCONTAINER_H
#define GTKMM_CUSTOM_CONTAINER_MYCONTAINER_H
-#include <gtkmm/container.h>
+#include <gtkmm/widget.h>
-class MyContainer : public Gtk::Container
+class MyContainer : public Gtk::Widget
{
public:
MyContainer();
@@ -33,14 +33,14 @@ protected:
Gtk::SizeRequestMode get_request_mode_vfunc() const override;
void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
int& minimum_baseline, int& natural_baseline) const override;
- void on_size_allocate(int width, int height, int baseline) override;
-
+ void size_allocate_vfunc(int width, int height, int baseline) override;
+#if 0
void forall_vfunc(const ForeachSlot& slot) override;
void on_add(Gtk::Widget* child) override;
void on_remove(Gtk::Widget* child) override;
GType child_type_vfunc() const override;
-
+#endif
Gtk::Widget* m_child_one;
Gtk::Widget* m_child_two;
};
diff --git a/examples/book/custom/custom_widget/examplewindow.cc
b/examples/book/custom/custom_widget/examplewindow.cc
index 29956b0..3f3c0f4 100644
--- a/examples/book/custom/custom_widget/examplewindow.cc
+++ b/examples/book/custom/custom_widget/examplewindow.cc
@@ -26,14 +26,14 @@ ExampleWindow::ExampleWindow()
m_Grid.set_row_spacing(10);
m_Grid.set_column_spacing(10);
- add(m_Grid);
+ set_child(m_Grid);
m_Grid.attach(m_MyWidgetS1, 0, 0);
m_Grid.attach(m_MyWidgetS2, 1, 1);
m_Grid.attach(m_ButtonBox, 0, 2, 2, 1);
- m_ButtonBox.add(m_Button_Quit);
+ m_ButtonBox.append(m_Button_Quit);
m_ButtonBox.set_margin(6);
m_Button_Quit.set_hexpand(true);
m_Button_Quit.set_halign(Gtk::Align::END);
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 7583a6e..c2106f8 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -16,7 +16,6 @@
#include "mywidget.h"
#include <gdkmm/general.h> // for cairo helper functions
-#include <gtkmm/container.h>
#include <gtkmm/snapshot.h>
#include <iostream>
//#include <gtk/gtkwidget.h> //For GTK_IS_WIDGET()
@@ -31,8 +30,7 @@ MyWidget::MyWidget() :
m_padding()
{
// Expand, if there is extra space.
- set_hexpand(true);
- set_vexpand(true);
+ set_expand(true);
//This shows the GType name.
std::cout << "GType name: " << G_OBJECT_TYPE_NAME(gobj()) << std::endl;
diff --git a/examples/book/dialogs/aboutdialog/examplewindow.cc
b/examples/book/dialogs/aboutdialog/examplewindow.cc
index e24635e..b69374a 100644
--- a/examples/book/dialogs/aboutdialog/examplewindow.cc
+++ b/examples/book/dialogs/aboutdialog/examplewindow.cc
@@ -26,15 +26,15 @@ ExampleWindow::ExampleWindow()
{
set_title("Gtk::AboutDialog example");
- add(m_VBox);
+ set_child(m_VBox);
- m_VBox.add(m_Label);
+ m_VBox.append(m_Label);
m_Label.set_expand(true);
m_Label.set_wrap(true);
m_Label.set_selectable(true);
- m_VBox.add(m_ButtonBox);
- m_ButtonBox.add(m_Button);
+ m_VBox.append(m_ButtonBox);
+ m_ButtonBox.append(m_Button);
m_Button.set_expand(true);
m_Button.set_halign(Gtk::Align::CENTER);
m_Button.set_valign(Gtk::Align::CENTER);
@@ -42,6 +42,7 @@ ExampleWindow::ExampleWindow()
&ExampleWindow::on_button_clicked) );
m_Dialog.set_transient_for(*this);
+ m_Dialog.set_hide_on_close();
m_Dialog.set_logo(Gdk::Texture::create_for_pixbuf(
Gdk::Pixbuf::create_from_resource("/about/gtkmm_logo.gif", -1, 40, true)));
diff --git a/examples/book/dialogs/colorchooserdialog/examplewindow.cc
b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
index acdc8d2..55ce98f 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.cc
@@ -24,13 +24,13 @@ ExampleWindow::ExampleWindow()
set_title("Gtk::ColorChooserDialog example");
set_default_size(200, 200);
- add(m_VBox);
+ set_child(m_VBox);
- m_VBox.add(m_ColorButton);
+ m_VBox.append(m_ColorButton);
m_ColorButton.signal_color_set().connect(sigc::mem_fun(*this,
&ExampleWindow::on_color_button_color_set) );
- m_VBox.add(m_Button_Dialog);
+ m_VBox.append(m_Button_Dialog);
m_Button_Dialog.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_dialog_clicked) );
@@ -41,7 +41,7 @@ ExampleWindow::ExampleWindow()
m_Color.set_alpha(1.0); //opaque
m_ColorButton.set_rgba(m_Color);
- m_VBox.add(m_DrawingArea);
+ m_VBox.append(m_DrawingArea);
m_DrawingArea.set_expand(true);
m_DrawingArea.set_draw_func(sigc::mem_fun(*this, &ExampleWindow::on_drawing_area_draw));
}
@@ -54,26 +54,39 @@ void ExampleWindow::on_color_button_color_set()
{
//Store the chosen color:
m_Color = m_ColorButton.get_rgba();
+ m_DrawingArea.queue_draw();
}
void ExampleWindow::on_button_dialog_clicked()
{
- Gtk::ColorChooserDialog dialog("Please choose a color");
- dialog.set_transient_for(*this);
+ if (!m_pDialog)
+ {
+ m_pDialog.reset(new Gtk::ColorChooserDialog("Please choose a color", *this));
+ m_pDialog->set_modal(true);
+ m_pDialog->set_hide_on_close(true);
+ m_pDialog->signal_response().connect(
+ sigc::mem_fun(*this, &ExampleWindow::on_dialog_response));
+ }
//Get the previously selected color:
- dialog.set_rgba(m_Color);
+ m_pDialog->set_rgba(m_Color);
- const int result = dialog.run();
+ m_pDialog->show();
+}
+
+void ExampleWindow::on_dialog_response(int response_id)
+{
+ m_pDialog->hide();
//Handle the response:
- switch(result)
+ switch (response_id)
{
case Gtk::ResponseType::OK:
{
//Store the chosen color:
- m_Color = dialog.get_rgba();
+ m_Color = m_pDialog->get_rgba();
m_ColorButton.set_rgba(m_Color);
+ m_DrawingArea.queue_draw();
break;
}
case Gtk::ResponseType::CANCEL:
@@ -83,7 +96,7 @@ void ExampleWindow::on_button_dialog_clicked()
}
default:
{
- std::cout << "Unexpected button clicked: " << result << std::endl;
+ std::cout << "Unexpected button clicked: " << response_id << std::endl;
break;
}
}
diff --git a/examples/book/dialogs/colorchooserdialog/examplewindow.h
b/examples/book/dialogs/colorchooserdialog/examplewindow.h
index 4253071..4cd9c1f 100644
--- a/examples/book/dialogs/colorchooserdialog/examplewindow.h
+++ b/examples/book/dialogs/colorchooserdialog/examplewindow.h
@@ -18,6 +18,7 @@
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm.h>
+#include <memory>
class ExampleWindow : public Gtk::Window
{
@@ -29,6 +30,7 @@ protected:
//Signal handlers:
void on_color_button_color_set();
void on_button_dialog_clicked();
+ void on_dialog_response(int response_id);
//Draw function:
void on_drawing_area_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
@@ -39,6 +41,7 @@ protected:
Gtk::Button m_Button_Dialog;
Gtk::DrawingArea m_DrawingArea; //To show the color.
+ std::unique_ptr<Gtk::ColorChooserDialog> m_pDialog;
Gdk::RGBA m_Color;
};
diff --git a/examples/book/dialogs/filechooserdialog/examplewindow.cc
b/examples/book/dialogs/filechooserdialog/examplewindow.cc
index ea38aca..af22fca 100644
--- a/examples/book/dialogs/filechooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/filechooserdialog/examplewindow.cc
@@ -25,14 +25,14 @@ ExampleWindow::ExampleWindow()
{
set_title("Gtk::FileSelection example");
- add(m_ButtonBox);
+ set_child(m_ButtonBox);
- m_ButtonBox.add(m_Button_File);
+ m_ButtonBox.append(m_Button_File);
m_Button_File.set_expand(true);
m_Button_File.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_file_clicked) );
- m_ButtonBox.add(m_Button_Folder);
+ m_ButtonBox.append(m_Button_Folder);
m_Button_Folder.set_expand(true);
m_Button_Folder.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_folder_clicked) );
@@ -42,25 +42,54 @@ ExampleWindow::~ExampleWindow()
{
}
-void ExampleWindow::on_button_folder_clicked()
+void ExampleWindow::on_button_file_clicked()
{
- Gtk::FileChooserDialog dialog("Please choose a folder",
- Gtk::FileChooser::Action::SELECT_FOLDER);
- dialog.set_transient_for(*this);
+ auto dialog = new Gtk::FileChooserDialog("Please choose a file",
+ Gtk::FileChooser::Action::OPEN);
+ dialog->set_transient_for(*this);
+ dialog->set_modal(true);
+ dialog->signal_response().connect(sigc::bind(
+ sigc::mem_fun(*this, &ExampleWindow::on_file_dialog_response), dialog));
+
+ //Add response buttons to the dialog:
+ dialog->add_button("_Cancel", Gtk::ResponseType::CANCEL);
+ dialog->add_button("_Open", Gtk::ResponseType::OK);
+
+ //Add filters, so that only certain file types can be selected:
+
+ auto filter_text = Gtk::FileFilter::create();
+ filter_text->set_name("Text files");
+ filter_text->add_mime_type("text/plain");
+ dialog->add_filter(filter_text);
+
+ auto filter_cpp = Gtk::FileFilter::create();
+ filter_cpp->set_name("C/C++ files");
+ filter_cpp->add_mime_type("text/x-c");
+ filter_cpp->add_mime_type("text/x-c++");
+ filter_cpp->add_mime_type("text/x-c-header");
+ dialog->add_filter(filter_cpp);
- //Add response buttons the the dialog:
- dialog.add_button("_Cancel", Gtk::ResponseType::CANCEL);
- dialog.add_button("Select", Gtk::ResponseType::OK);
+ auto filter_any = Gtk::FileFilter::create();
+ filter_any->set_name("Any files");
+ filter_any->add_pattern("*");
+ dialog->add_filter(filter_any);
- int result = dialog.run();
+ //Show the dialog and wait for a user response:
+ dialog->show();
+}
+void ExampleWindow::on_file_dialog_response(int response_id, Gtk::FileChooserDialog* dialog)
+{
//Handle the response:
- switch(result)
+ switch (response_id)
{
case Gtk::ResponseType::OK:
{
- std::cout << "Select clicked." << std::endl;
- std::cout << "Folder selected: " << dialog.get_file()->get_path() << std::endl;
+ std::cout << "Open clicked." << std::endl;
+
+ //Notice that this is a std::string, not a Glib::ustring.
+ auto filename = dialog->get_file()->get_path();
+ std::cout << "File selected: " << filename << std::endl;
break;
}
case Gtk::ResponseType::CANCEL:
@@ -74,50 +103,35 @@ void ExampleWindow::on_button_folder_clicked()
break;
}
}
+ delete dialog;
}
-void ExampleWindow::on_button_file_clicked()
+void ExampleWindow::on_button_folder_clicked()
{
- Gtk::FileChooserDialog dialog("Please choose a file",
- Gtk::FileChooser::Action::OPEN);
- dialog.set_transient_for(*this);
-
- //Add response buttons the the dialog:
- dialog.add_button("_Cancel", Gtk::ResponseType::CANCEL);
- dialog.add_button("_Open", Gtk::ResponseType::OK);
-
- //Add filters, so that only certain file types can be selected:
-
- auto filter_text = Gtk::FileFilter::create();
- filter_text->set_name("Text files");
- filter_text->add_mime_type("text/plain");
- dialog.add_filter(filter_text);
-
- auto filter_cpp = Gtk::FileFilter::create();
- filter_cpp->set_name("C/C++ files");
- filter_cpp->add_mime_type("text/x-c");
- filter_cpp->add_mime_type("text/x-c++");
- filter_cpp->add_mime_type("text/x-c-header");
- dialog.add_filter(filter_cpp);
+ auto dialog = new Gtk::FileChooserDialog("Please choose a folder",
+ Gtk::FileChooser::Action::SELECT_FOLDER);
+ dialog->set_transient_for(*this);
+ dialog->set_modal(true);
+ dialog->signal_response().connect(sigc::bind(
+ sigc::mem_fun(*this, &ExampleWindow::on_folder_dialog_response), dialog));
- auto filter_any = Gtk::FileFilter::create();
- filter_any->set_name("Any files");
- filter_any->add_pattern("*");
- dialog.add_filter(filter_any);
+ //Add response buttons to the dialog:
+ dialog->add_button("_Cancel", Gtk::ResponseType::CANCEL);
+ dialog->add_button("Select", Gtk::ResponseType::OK);
//Show the dialog and wait for a user response:
- int result = dialog.run();
+ dialog->show();
+}
+void ExampleWindow::on_folder_dialog_response(int response_id, Gtk::FileChooserDialog* dialog)
+{
//Handle the response:
- switch(result)
+ switch (response_id)
{
case Gtk::ResponseType::OK:
{
- std::cout << "Open clicked." << std::endl;
-
- //Notice that this is a std::string, not a Glib::ustring.
- auto filename = dialog.get_file()->get_path();
- std::cout << "File selected: " << filename << std::endl;
+ std::cout << "Select clicked." << std::endl;
+ std::cout << "Folder selected: " << dialog->get_file()->get_path() << std::endl;
break;
}
case Gtk::ResponseType::CANCEL:
@@ -131,4 +145,5 @@ void ExampleWindow::on_button_file_clicked()
break;
}
}
+ delete dialog;
}
diff --git a/examples/book/dialogs/filechooserdialog/examplewindow.h
b/examples/book/dialogs/filechooserdialog/examplewindow.h
index c5fafa8..f8cab32 100644
--- a/examples/book/dialogs/filechooserdialog/examplewindow.h
+++ b/examples/book/dialogs/filechooserdialog/examplewindow.h
@@ -29,6 +29,8 @@ protected:
//Signal handlers:
void on_button_file_clicked();
void on_button_folder_clicked();
+ void on_file_dialog_response(int response_id, Gtk::FileChooserDialog* dialog);
+ void on_folder_dialog_response(int response_id, Gtk::FileChooserDialog* dialog);
//Child widgets:
Gtk::Box m_ButtonBox;
diff --git a/examples/book/dialogs/filechoosernative/examplewindow.cc
b/examples/book/dialogs/filechoosernative/examplewindow.cc
index 032cba8..850a78f 100644
--- a/examples/book/dialogs/filechoosernative/examplewindow.cc
+++ b/examples/book/dialogs/filechoosernative/examplewindow.cc
@@ -23,14 +23,14 @@ ExampleWindow::ExampleWindow()
{
set_title("Gtk::FileChooserNative example");
- add(m_ButtonBox);
+ set_child(m_ButtonBox);
- m_ButtonBox.add(m_Button_File_Open);
+ m_ButtonBox.append(m_Button_File_Open);
m_Button_File_Open.set_expand(true);
m_Button_File_Open.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
&ExampleWindow::on_button_file_clicked), Gtk::FileChooser::Action::OPEN));
- m_ButtonBox.add(m_Button_File_Save);
+ m_ButtonBox.append(m_Button_File_Save);
m_Button_File_Save.set_expand(true);
m_Button_File_Save.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
&ExampleWindow::on_button_file_clicked), Gtk::FileChooser::Action::SAVE));
@@ -42,21 +42,28 @@ ExampleWindow::~ExampleWindow()
void ExampleWindow::on_button_file_clicked(Gtk::FileChooser::Action action)
{
- const bool open = (action == Gtk::FileChooser::Action::OPEN);
- auto dialog = Gtk::FileChooserNative::create("Please choose a file", *this, action);
+ m_pDialog = Gtk::FileChooserNative::create("Please choose a file", *this, action);
+ m_pDialog->set_modal(true);
+ m_pDialog->signal_response().connect(sigc::mem_fun(*this, &ExampleWindow::on_dialog_response));
// Show the dialog and wait for a user response:
- const int result = dialog->run();
+ m_pDialog->show();
+}
+
+void ExampleWindow::on_dialog_response(int response_id)
+{
+ m_pDialog->hide();
// Handle the response:
- switch (result)
+ switch (response_id)
{
case Gtk::ResponseType::ACCEPT:
{
+ const bool open = m_pDialog->get_action() == Gtk::FileChooser::Action::OPEN;
std::cout << (open ? "Open" : "Save") << " clicked." << std::endl;
// Notice that this is a std::string, not a Glib::ustring.
- auto filename = dialog->get_file()->get_path();
+ auto filename = m_pDialog->get_file()->get_path();
std::cout << "File selected: " << filename << std::endl;
break;
}
diff --git a/examples/book/dialogs/filechoosernative/examplewindow.h
b/examples/book/dialogs/filechoosernative/examplewindow.h
index f705b85..c532304 100644
--- a/examples/book/dialogs/filechoosernative/examplewindow.h
+++ b/examples/book/dialogs/filechoosernative/examplewindow.h
@@ -27,11 +27,14 @@ public:
protected:
// Signal handlers:
void on_button_file_clicked(Gtk::FileChooser::Action action);
+ void on_dialog_response(int response_id);
// Child widgets:
Gtk::Box m_ButtonBox;
Gtk::Button m_Button_File_Open;
Gtk::Button m_Button_File_Save;
+
+ Glib::RefPtr<Gtk::FileChooserNative> m_pDialog;
};
#endif // GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/dialogs/fontchooserdialog/examplewindow.cc
b/examples/book/dialogs/fontchooserdialog/examplewindow.cc
index 2c99945..598fa2c 100644
--- a/examples/book/dialogs/fontchooserdialog/examplewindow.cc
+++ b/examples/book/dialogs/fontchooserdialog/examplewindow.cc
@@ -24,16 +24,16 @@ ExampleWindow::ExampleWindow()
{
set_title("Gtk::FontChooserDialog example");
- add(m_ButtonBox);
+ set_child(m_ButtonBox);
- m_ButtonBox.add(m_FontButton);
+ m_ButtonBox.append(m_FontButton);
m_FontButton.set_expand(true);
m_FontButton.set_use_font(true);
m_FontButton.set_use_size(true);
m_FontButton.signal_font_set().connect(sigc::mem_fun(*this,
&ExampleWindow::on_font_button_font_set) );
- m_ButtonBox.add(m_Button_Dialog);
+ m_ButtonBox.append(m_Button_Dialog);
m_Button_Dialog.set_expand(true);
m_Button_Dialog.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_dialog_clicked) );
@@ -51,19 +51,31 @@ void ExampleWindow::on_font_button_font_set()
void ExampleWindow::on_button_dialog_clicked()
{
- Gtk::FontChooserDialog dialog("Please choose a font", *this);
+ if (!m_pDialog)
+ {
+ m_pDialog.reset(new Gtk::FontChooserDialog("Please choose a font", *this));
+ m_pDialog->set_modal(true);
+ m_pDialog->set_hide_on_close(true);
+ m_pDialog->signal_response().connect(
+ sigc::mem_fun(*this, &ExampleWindow::on_dialog_response));
+ }
//Get the previously selected font name from the FontButton:
- dialog.set_font(m_FontButton.get_font());
+ m_pDialog->set_font(m_FontButton.get_font());
- int result = dialog.run();
+ m_pDialog->show();
+}
+
+void ExampleWindow::on_dialog_response(int response_id)
+{
+ m_pDialog->hide();
//Handle the response:
- switch(result)
+ switch (response_id)
{
case Gtk::ResponseType::OK:
{
- auto font_name = dialog.get_font();
+ auto font_name = m_pDialog->get_font();
std::cout << "Font chosen: " << font_name << std::endl;
m_FontButton.set_font(font_name);
break;
@@ -75,7 +87,7 @@ void ExampleWindow::on_button_dialog_clicked()
}
default:
{
- std::cout << "Unexpected button clicked: " << result << std::endl;
+ std::cout << "Unexpected button clicked: " << response_id << std::endl;
break;
}
}
diff --git a/examples/book/dialogs/fontchooserdialog/examplewindow.h
b/examples/book/dialogs/fontchooserdialog/examplewindow.h
index e7ad9f1..2193923 100644
--- a/examples/book/dialogs/fontchooserdialog/examplewindow.h
+++ b/examples/book/dialogs/fontchooserdialog/examplewindow.h
@@ -18,6 +18,7 @@
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm.h>
+#include <memory>
class ExampleWindow : public Gtk::Window
{
@@ -29,11 +30,14 @@ protected:
//Signal handlers:
void on_font_button_font_set();
void on_button_dialog_clicked();
+ void on_dialog_response(int response_id);
//Child widgets:
Gtk::Box m_ButtonBox;
Gtk::FontButton m_FontButton;
Gtk::Button m_Button_Dialog;
+
+ std::unique_ptr<Gtk::FontChooserDialog> m_pDialog;
};
#endif //GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/dialogs/messagedialog/examplewindow.cc
b/examples/book/dialogs/messagedialog/examplewindow.cc
index 1d2943d..eeb7165 100644
--- a/examples/book/dialogs/messagedialog/examplewindow.cc
+++ b/examples/book/dialogs/messagedialog/examplewindow.cc
@@ -26,14 +26,14 @@ ExampleWindow::ExampleWindow()
{
set_title("Gtk::MessageDialog example");
- add(m_ButtonBox);
+ set_child(m_ButtonBox);
- m_ButtonBox.add(m_Button_Info);
+ m_ButtonBox.append(m_Button_Info);
m_Button_Info.set_expand(true);
m_Button_Info.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_info_clicked) );
- m_ButtonBox.add(m_Button_Question);
+ m_ButtonBox.append(m_Button_Question);
m_Button_Question.set_expand(true);
m_Button_Question.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_question_clicked) );
@@ -45,25 +45,37 @@ ExampleWindow::~ExampleWindow()
void ExampleWindow::on_button_info_clicked()
{
- Gtk::MessageDialog dialog(*this, "This is an INFO MessageDialog");
- dialog.set_secondary_text(
+ m_pDialog.reset(new Gtk::MessageDialog(*this, "This is an INFO MessageDialog"));
+ m_pDialog->set_secondary_text(
"And this is the secondary text that explains things.");
+ m_pDialog->set_modal(true);
+ m_pDialog->set_hide_on_close(true);
+ m_pDialog->signal_response().connect(
+ sigc::hide(sigc::mem_fun(*m_pDialog, &Gtk::Widget::hide)));
- dialog.run();
+ m_pDialog->show();
}
void ExampleWindow::on_button_question_clicked()
{
- Gtk::MessageDialog dialog(*this, "This is a QUESTION MessageDialog",
+ m_pDialog.reset(new Gtk::MessageDialog(*this, "This is a QUESTION MessageDialog",
false /* use_markup */, Gtk::MessageType::QUESTION,
- Gtk::ButtonsType::OK_CANCEL);
- dialog.set_secondary_text(
+ Gtk::ButtonsType::OK_CANCEL, true /* modal */));
+ m_pDialog->set_secondary_text(
"And this is the secondary text that explains things.");
+ m_pDialog->set_hide_on_close(true);
+ m_pDialog->signal_response().connect(
+ sigc::mem_fun(*this, &ExampleWindow::on_question_dialog_response));
- int result = dialog.run();
+ m_pDialog->show();
+}
+
+void ExampleWindow::on_question_dialog_response(int response_id)
+{
+ m_pDialog->hide();
//Handle the response:
- switch(result)
+ switch (response_id)
{
case Gtk::ResponseType::OK:
{
diff --git a/examples/book/dialogs/messagedialog/examplewindow.h
b/examples/book/dialogs/messagedialog/examplewindow.h
index 172b667..3535b46 100644
--- a/examples/book/dialogs/messagedialog/examplewindow.h
+++ b/examples/book/dialogs/messagedialog/examplewindow.h
@@ -18,6 +18,7 @@
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm.h>
+#include <memory>
class ExampleWindow : public Gtk::Window
{
@@ -29,10 +30,13 @@ protected:
//Signal handlers:
void on_button_info_clicked();
void on_button_question_clicked();
+ void on_question_dialog_response(int response_id);
//Child widgets:
Gtk::Box m_ButtonBox;
Gtk::Button m_Button_Info, m_Button_Question;
+
+ std::unique_ptr<Gtk::MessageDialog> m_pDialog;
};
#endif //GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/dialogs/simple/examplewindow.cc b/examples/book/dialogs/simple/examplewindow.cc
index 6ab59bb..c1fd714 100644
--- a/examples/book/dialogs/simple/examplewindow.cc
+++ b/examples/book/dialogs/simple/examplewindow.cc
@@ -17,15 +17,22 @@
#include "examplewindow.h"
#include <gtkmm/dialog.h>
-
ExampleWindow::ExampleWindow()
-: m_Button("Show Dialog")
+: m_Button("Show Dialog"),
+ m_Dialog("The Dialog")
{
set_title("Gtk::Dialog example");
- add(m_Button);
+ set_child(m_Button);
m_Button.signal_clicked().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_clicked) );
+
+ m_Dialog.set_default_size(150, 100);
+ m_Dialog.set_transient_for(*this);
+ m_Dialog.set_modal();
+ m_Dialog.set_hide_on_close();
+ m_Dialog.signal_response().connect(
+ sigc::hide(sigc::mem_fun(m_Dialog, &Gtk::Widget::hide)));
}
ExampleWindow::~ExampleWindow()
@@ -34,7 +41,5 @@ ExampleWindow::~ExampleWindow()
void ExampleWindow::on_button_clicked()
{
- Gtk::Dialog dialog;
- dialog.set_default_size(100,100);
- dialog.run();
+ m_Dialog.show();
}
diff --git a/examples/book/dialogs/simple/examplewindow.h b/examples/book/dialogs/simple/examplewindow.h
index d0e63e3..544bed2 100644
--- a/examples/book/dialogs/simple/examplewindow.h
+++ b/examples/book/dialogs/simple/examplewindow.h
@@ -33,6 +33,8 @@ protected:
//Child widgets:
Gtk::Button m_Button;
+
+ Gtk::Dialog m_Dialog;
};
#endif //GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/drag_and_drop/dndwindow.cc b/examples/book/drag_and_drop/dndwindow.cc
index 8f760be..4390a37 100644
--- a/examples/book/drag_and_drop/dndwindow.cc
+++ b/examples/book/drag_and_drop/dndwindow.cc
@@ -26,7 +26,7 @@ DnDWindow::DnDWindow()
{
set_title("DnD example");
- add(m_HBox);
+ set_child(m_HBox);
//Drag site:
@@ -37,7 +37,7 @@ DnDWindow::DnDWindow()
sigc::mem_fun(*this, &DnDWindow::on_label_drag_prepare_data), false);
m_Label_Drag.add_controller(source);
- m_HBox.add(m_Label_Drag);
+ m_HBox.append(m_Label_Drag);
m_Label_Drag.set_expand(true);
//Drop site:
@@ -49,7 +49,7 @@ DnDWindow::DnDWindow()
sigc::mem_fun(*this, &DnDWindow::on_button_drop_drop_data), false);
m_Button_Drop.add_controller(target);
- m_HBox.add(m_Button_Drop);
+ m_HBox.append(m_Button_Drop);
m_Button_Drop.set_expand(true);
}
diff --git a/examples/book/drawingarea/arcs/main.cc b/examples/book/drawingarea/arcs/main.cc
index 190c0d1..be3741a 100644
--- a/examples/book/drawingarea/arcs/main.cc
+++ b/examples/book/drawingarea/arcs/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char** argv)
win.set_title("DrawingArea");
MyArea area;
- win.add(area);
- area.show();
+ win.set_child(area);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/clock/main.cc b/examples/book/drawingarea/clock/main.cc
index 957f78e..07b3255 100644
--- a/examples/book/drawingarea/clock/main.cc
+++ b/examples/book/drawingarea/clock/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char** argv)
win.set_title("Cairomm Clock");
Clock c;
- win.add(c);
- c.show();
+ win.set_child(c);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/curve/main.cc b/examples/book/drawingarea/curve/main.cc
index 190c0d1..be3741a 100644
--- a/examples/book/drawingarea/curve/main.cc
+++ b/examples/book/drawingarea/curve/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char** argv)
win.set_title("DrawingArea");
MyArea area;
- win.add(area);
- area.show();
+ win.set_child(area);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/image/main.cc b/examples/book/drawingarea/image/main.cc
index 5422ea0..e134b27 100644
--- a/examples/book/drawingarea/image/main.cc
+++ b/examples/book/drawingarea/image/main.cc
@@ -27,8 +27,7 @@ int main(int argc, char** argv)
win.set_default_size(300, 200);
MyArea area;
- win.add(area);
- area.show();
+ win.set_child(area);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/joins/main.cc b/examples/book/drawingarea/joins/main.cc
index 190c0d1..be3741a 100644
--- a/examples/book/drawingarea/joins/main.cc
+++ b/examples/book/drawingarea/joins/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char** argv)
win.set_title("DrawingArea");
MyArea area;
- win.add(area);
- area.show();
+ win.set_child(area);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/pango_text/main.cc b/examples/book/drawingarea/pango_text/main.cc
index 2f727aa..9fac47e 100644
--- a/examples/book/drawingarea/pango_text/main.cc
+++ b/examples/book/drawingarea/pango_text/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char* argv[])
window.set_title("Drawing text example");
MyArea area;
- window.add(area);
- area.show();
+ window.set_child(area);
return app->run(window, argc, argv);
}
diff --git a/examples/book/drawingarea/simple/main.cc b/examples/book/drawingarea/simple/main.cc
index 190c0d1..be3741a 100644
--- a/examples/book/drawingarea/simple/main.cc
+++ b/examples/book/drawingarea/simple/main.cc
@@ -26,8 +26,7 @@ int main(int argc, char** argv)
win.set_title("DrawingArea");
MyArea area;
- win.add(area);
- area.show();
+ win.set_child(area);
return app->run(win, argc, argv);
}
diff --git a/examples/book/drawingarea/thin_lines/examplewindow.cc
b/examples/book/drawingarea/thin_lines/examplewindow.cc
index dd3e711..3b3509b 100644
--- a/examples/book/drawingarea/thin_lines/examplewindow.cc
+++ b/examples/book/drawingarea/thin_lines/examplewindow.cc
@@ -17,16 +17,15 @@
#include "examplewindow.h"
ExampleWindow::ExampleWindow()
-: m_Button_FixLines("Fix lines")
+: m_HBox(Gtk::Orientation::HORIZONTAL),
+ m_Button_FixLines("Fix lines")
{
set_title("Thin lines example");
- m_Container.set_orientation(Gtk::Orientation::HORIZONTAL);
+ m_HBox.append(m_Area_Lines);
+ m_HBox.append(m_Button_FixLines);
- m_Container.add(m_Area_Lines);
- m_Container.add(m_Button_FixLines);
-
- add(m_Container);
+ set_child(m_HBox);
m_Button_FixLines.signal_toggled().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_toggled));
diff --git a/examples/book/drawingarea/thin_lines/examplewindow.h
b/examples/book/drawingarea/thin_lines/examplewindow.h
index dc2996b..041bb65 100644
--- a/examples/book/drawingarea/thin_lines/examplewindow.h
+++ b/examples/book/drawingarea/thin_lines/examplewindow.h
@@ -18,7 +18,7 @@
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm/window.h>
-#include <gtkmm/grid.h>
+#include <gtkmm/box.h>
#include <gtkmm/checkbutton.h>
#include "myarea.h"
@@ -33,7 +33,7 @@ protected:
void on_button_toggled();
private:
- Gtk::Grid m_Container;
+ Gtk::Box m_HBox;
MyArea m_Area_Lines;
Gtk::CheckButton m_Button_FixLines;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]