[gtkmm-documentation] Add basic information on Gtk::Grid



commit e3cd1e062d07d1e6a11aacbcbf8ea28a47b781c6
Author: David King <davidk openismus com>
Date:   Mon Feb 21 15:21:24 2011 +0100

    Add basic information on Gtk::Grid
    
    * docs/tutorial/C/figures/grid.png: Add new screenshot.
    * docs/tutorial/C/gtkmm-tutorial-in.xml: Add section in multi-widget
    container chapter on Gtk::Grid.
    * docs/tutorial/Makefile.am:
    * examples/.gitignore:
    * examples/Makefile.am: Update.
    * examples/book/grid/examplewindow.cc:
    * examples/book/grid/examplewindow.h:
    * examples/book/grid/main.cc: Add example code for Gtk::Grid.

 ChangeLog                             |   14 +++++++
 docs/tutorial/C/figures/grid.png      |  Bin 0 -> 4839 bytes
 docs/tutorial/C/gtkmm-tutorial-in.xml |   60 +++++++++++++++++++++++++++++---
 docs/tutorial/Makefile.am             |    1 +
 examples/.gitignore                   |    3 +-
 examples/Makefile.am                  |    6 +++
 examples/book/grid/examplewindow.cc   |   61 +++++++++++++++++++++++++++++++++
 examples/book/grid/examplewindow.h    |   40 +++++++++++++++++++++
 examples/book/grid/main.cc            |   30 ++++++++++++++++
 9 files changed, 209 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a69aeab..478ea89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-02-21  David King  <davidk openismus com>
+
+	Add basic information on Gtk::Grid
+
+	* docs/tutorial/C/figures/grid.png: Add new screenshot.
+	* docs/tutorial/C/gtkmm-tutorial-in.xml: Add section in multi-widget
+	container chapter on Gtk::Grid.
+	* docs/tutorial/Makefile.am:
+	* examples/.gitignore:
+	* examples/Makefile.am: Update.
+	* examples/book/grid/examplewindow.cc:
+	* examples/book/grid/examplewindow.h:
+	* examples/book/grid/main.cc: Add example code for Gtk::Grid.
+
 2011-02-18  David King  <davidk openismus com>
 
 	Minor documentation updates for gtkmm 3
diff --git a/docs/tutorial/C/figures/grid.png b/docs/tutorial/C/figures/grid.png
new file mode 100644
index 0000000..135ce41
Binary files /dev/null and b/docs/tutorial/C/figures/grid.png differ
diff --git a/docs/tutorial/C/gtkmm-tutorial-in.xml b/docs/tutorial/C/gtkmm-tutorial-in.xml
index 4ea3f3b..ec77114 100644
--- a/docs/tutorial/C/gtkmm-tutorial-in.xml
+++ b/docs/tutorial/C/gtkmm-tutorial-in.xml
@@ -382,10 +382,10 @@ Openismus has more <ulink url="http://www.openismus.com/documents/linux/automake
 <sect1 id="sec-widgets-overview">
 <title>Widgets</title>
 <para>&gtkmm; applications consist of windows containing widgets, such as buttons and text boxes. In some other systems, widgets are called "controls". For each widget in your application's windows, there is a C++ object in your application's code. So you just need to call a method of the widget's class to affect the visible widget.</para>
- <para>Widgets are arranged inside container widgets such as frames and notebooks, in a hierarchy of widgets within widgets. Some of these container widgets, such as Gtk::VBox, are not visible - they exist only to arrange other widgets. Here is some example code that adds 2 Gtk::Button widgets to a Gtk::VBox container widgets:
+ <para>Widgets are arranged inside container widgets such as frames and notebooks, in a hierarchy of widgets within widgets. Some of these container widgets, such as <classname>Gtk::Grid</classname>, are not visible - they exist only to arrange other widgets. Here is some example code that adds 2 <classname>Gtk::Button</classname> widgets to a <classname>Gtk::VBox</classname> container widgets:
 <programlisting>m_box.pack_start(m_Button1);
 m_box.pack_start(m_Button2);</programlisting>
-and here is how to add the Gtk::VBox, containing those buttons, to a Gtk::Frame, which has a visible frame and title:
+and here is how to add the <classname>Gtk::VBox</classname>, containing those buttons, to a <classname>Gtk::Frame</classname>, which has a visible frame and title:
 <programlisting>m_frame.add(m_box);</programlisting>
 </para>
 <para>
@@ -1836,8 +1836,8 @@ in &gtkmm; are descendants of <classname>Gtk::Bin</classname>, including
 Yes, that's correct: a Window can contain at most one widget.  How, then, can
 we use a window for anything useful?  By placing a multiple-child container in
 the window. The most useful container widgets are
-<classname>Gtk:VBox</classname>, <classname>Gtk::HBox</classname>, and
-<classname>Gtk::Table</classname>.
+<classname>Gtk:Grid</classname>, <classname>Gtk:VBox</classname>,
+<classname>Gtk::HBox</classname>, and <classname>Gtk::Table</classname>.
 </para>
 
 
@@ -1845,6 +1845,15 @@ the window. The most useful container widgets are
 
 <listitem>
 <para>
+<classname>Gtk::Grid</classname> arranges its child widgets in rows and
+columns. Use <methodname>attach()</methodname>,
+<methodname>attach_next_to()</methodname> and <methodname>add()</methodname> to
+insert child widgets.
+</para>
+</listitem>
+
+<listitem>
+<para>
 <classname>Gtk::VBox</classname> and <classname>Gtk::HBox</classname> arrange
 their child widgets vertically and horizontally, respectively. Use
 <methodname>pack_start()</methodname> and <methodname>pack_end()</methodname> to insert
@@ -2065,11 +2074,52 @@ changed using <methodname>get_layout()</methodname> and
 
 </sect2>
 
+<sect2 id="sec-grid">
+<title>Grid</title>
+
+<para>
+<classname>Grid</classname> allows us to place widgets in a grid. The grid
+dynamically lays out child widgets, so the dimensions of the grid do not need
+to be specified in the constructor.
+</para>
+
+<para>
+Children can span multiple rows or columns, using
+<methodname>attach()</methodname>, or added next to an existing widget inside
+the grid with <methodname>attach_next_to()</methodname>. Individual rows and columns of the grid can be set to have uniform height or width with
+<methodname>set_row_homogeneous()</methodname> and
+<methodname>set_column_homogeneous()</methodname>. Set the
+<emphasis>margin</emphasis> and <emphasis>expand</emphasis> properties of the
+<classname>Widget</classname>s that are added to the grid, in order to control
+the geometry management.
+</para>
+
+<sect3 id="grid-example"><title>Example</title>
+<para>
+In the following example, we make a window with three buttons in a grid.
+The first two buttons will be placed in the upper row, from left to right. A
+third button is attached underneath the first buttion, in a new lower row,
+spanning two columns.
+</para>
+
+<figure id="figure-grid">
+  <title>Grid</title>
+  <screenshot>
+    <graphic format="PNG" fileref="&url_figures_base;grid.png"/>
+  </screenshot>
+</figure>
+
+<para><ulink url="&url_examples_base;grid">Source Code</ulink></para>
+
+</sect3>
+
+</sect2>
+
 <sect2 id="sec-table">
 <title>Table</title>
 
 <para>
-Tables allows us to place widgets in a grid.
+Tables allows us to place widgets in a grid, similar to <classname>Gtk::Grid</classname>.
 </para>
 
 <sect3 id="table-constructor"><title>Constructor</title>
diff --git a/docs/tutorial/Makefile.am b/docs/tutorial/Makefile.am
index 1d376ba..024b4b6 100644
--- a/docs/tutorial/Makefile.am
+++ b/docs/tutorial/Makefile.am
@@ -56,6 +56,7 @@ DOC_FIGURES =					\
 	figures/expander.png			\
 	figures/filechooserbutton.png		\
 	figures/frame.png			\
+	figures/grid.png			\
 	figures/helloworld.png			\
 	figures/helloworld2.png			\
 	figures/idle.png			\
diff --git a/examples/.gitignore b/examples/.gitignore
index ced36f8..b3c81f1 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -5,6 +5,7 @@
 .libs/
 example
 !example/
+/book/base/base
 /book/buttons/button/buttons
 /book/buttons/radiobutton/radiobuttons
 /book/drag_and_drop/drag_and_drop
@@ -16,6 +17,7 @@ example
 /book/giomm/getline/getline
 /book/giomm/monitor_directory/monitor_directory
 /book/giomm/usage/usage
+/boox/grid/example
 /book/helloworld/helloworld
 /book/helloworld2/helloworld2
 /book/idle/idle
@@ -26,7 +28,6 @@ example
 /book/timeout/timeout
 /others/arrow/arrow
 /others/arrow/direction
-/others/base/base
 /others/calendar/calendar
 /others/cellrenderercustom/cellrenderertoggle
 /others/cellrenderercustom/testpopup
diff --git a/examples/Makefile.am b/examples/Makefile.am
index b67a00d..bd1836e 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -56,6 +56,7 @@ check_PROGRAMS =					\
 	book/giomm/usage/usage				\
 	book/giomm/volumes/example			\
 	book/giomm/write_file/example			\
+	book/grid/example				\
 	book/helloworld/helloworld			\
 	book/helloworld2/helloworld2			\
 	book/iconview/example				\
@@ -372,6 +373,11 @@ book_giomm_write_file_example_LDADD = $(GIOMM_LIBS)
 book_giomm_write_file_example_SOURCES = \
 	book/giomm/write_file/main.cc
 
+book_grid_example_SOURCES = \
+	book/grid/examplewindow.cc \
+	book/grid/examplewindow.h \
+	book/grid/main.cc
+
 book_helloworld_helloworld_SOURCES =	\
 	book/helloworld/helloworld.cc	\
 	book/helloworld/helloworld.h	\
diff --git a/examples/book/grid/examplewindow.cc b/examples/book/grid/examplewindow.cc
new file mode 100644
index 0000000..8b0c8a8
--- /dev/null
+++ b/examples/book/grid/examplewindow.cc
@@ -0,0 +1,61 @@
+/* gtkmm example Copyright (C) 2011 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#include <iostream>
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow()
+: button_1_("button 1"),
+  button_2_("button 2"),
+  button_quit_("Quit")
+{
+  set_title("Gtk::Grid");
+  set_border_width(12);
+
+  add(grid_);
+
+  grid_.add(button_1_);
+  grid_.add(button_2_);
+  grid_.attach_next_to(button_quit_, button_1_, Gtk::POS_BOTTOM, 2, 1);
+
+  button_1_.signal_clicked().connect(
+    sigc::bind<Glib::ustring>( sigc::mem_fun(*this,
+      &ExampleWindow::on_button_numbered), "button 1") );
+  button_2_.signal_clicked().connect(
+    sigc::bind<Glib::ustring>( sigc::mem_fun(*this,
+      &ExampleWindow::on_button_numbered), "button 2") );
+
+  button_quit_.signal_clicked().connect(sigc::mem_fun(*this,
+    &ExampleWindow::on_button_quit) );
+
+  show_all_children();
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_button_quit()
+{
+  hide();
+}
+
+void
+ExampleWindow::on_button_numbered(Glib::ustring data)
+{
+  std::cout << data << " was pressed" << std::endl;
+}
diff --git a/examples/book/grid/examplewindow.h b/examples/book/grid/examplewindow.h
new file mode 100644
index 0000000..b96e1ca
--- /dev/null
+++ b/examples/book/grid/examplewindow.h
@@ -0,0 +1,40 @@
+/* gtkmm example Copyright (C) 2011 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+  ExampleWindow();
+  virtual ~ExampleWindow();
+
+private:
+  // Signal handlers:
+  void on_button_quit();
+  void on_button_numbered(Glib::ustring data);
+
+  // Child widgets:
+  Gtk::Grid grid_;
+  Gtk::Button button_1_, button_2_, button_quit_;
+
+};
+
+#endif /* GTKMM_EXAMPLEWINDOW_H */
diff --git a/examples/book/grid/main.cc b/examples/book/grid/main.cc
new file mode 100644
index 0000000..385aec8
--- /dev/null
+++ b/examples/book/grid/main.cc
@@ -0,0 +1,30 @@
+/* gtkmm example Copyright (C) 2011 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#include "examplewindow.h"
+#include <gtkmm/main.h>
+
+int main(int argc, char *argv[])
+{
+  Gtk::Main kit(argc, argv);
+
+  ExampleWindow window;
+  // Shows the window and returns when it is closed.
+  Gtk::Main::run(window);
+
+  return 0;
+}



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