[gtkmm-documentation] Book: Add a Gtk::InfoBar example.



commit 0f71d672331ad69d938d2c222ab0ae3426f2587a
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Tue Sep 22 00:44:55 2009 -0400

    	Book: Add a Gtk::InfoBar example.
    
    	* examples/book/infobar/examplewindow.cc:
    	* examples/book/infobar/examplewindow.h:
    	* examples/book/infobar/main.cc: Add these to exemplify the usage of a
    	Gtk::InfoBar.
    	* examples/Makefile.am (check_PROGRAMS): Add the new Gtk::InfoBar
    	example to the check.
    	(book_infobar_example_SOURCES): Declare the Gtk::InfoBar example
    	sources.

 ChangeLog                              |   13 ++++
 examples/Makefile.am                   |    6 ++
 examples/book/infobar/examplewindow.cc |  112 ++++++++++++++++++++++++++++++++
 examples/book/infobar/examplewindow.h  |   50 ++++++++++++++
 examples/book/infobar/main.cc          |   29 ++++++++
 5 files changed, 210 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e98ac6f..ef6c285 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-09-22  José Alburquerque  <jaalburqu svn gnome org>
+
+	Book: Add a Gtk::InfoBar example.
+
+	* examples/book/infobar/examplewindow.cc:
+	* examples/book/infobar/examplewindow.h:
+	* examples/book/infobar/main.cc: Add these to exemplify the usage of a
+	Gtk::InfoBar.
+	* examples/Makefile.am (check_PROGRAMS): Add the new Gtk::InfoBar
+	example to the check.
+	(book_infobar_example_SOURCES): Declare the Gtk::InfoBar example
+	sources.
+
 2009-09-16  Daniel Elstner  <daniel kitta gmail com>
 
 	Replace deprecated GTK+ symbols in example code
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 59c9b59..0668484 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -59,6 +59,7 @@ check_PROGRAMS =					\
 	book/helloworld2/helloworld2			\
 	book/iconview/example				\
 	book/idle/idle					\
+	book/infobar/example				\
 	book/input/example				\
 	book/label/example				\
 	book/menus/main_menu/main_menu			\
@@ -385,6 +386,11 @@ book_idle_idle_SOURCES =		\
 	book/idle/idleexample.h		\
 	book/idle/main.cc
 
+book_infobar_example_SOURCES =		\
+	book/infobar/examplewindow.cc	\
+	book/infobar/examplewindow.h	\
+	book/infobar/main.cc
+
 book_input_example_SOURCES = \
 	book/input/main.cc
 
diff --git a/examples/book/infobar/examplewindow.cc b/examples/book/infobar/examplewindow.cc
new file mode 100644
index 0000000..1232ce5
--- /dev/null
+++ b/examples/book/infobar/examplewindow.cc
@@ -0,0 +1,112 @@
+/* gtkmm example Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow()
+: m_Button_Quit(Gtk::Stock::QUIT),
+  m_Button_Clear("Clear")
+{
+  set_title("Gtk::InfoBar example");
+  set_border_width(5);
+  set_default_size(400, 200);
+
+  add(m_VBox);
+
+  // Create the buffer and set it on the TextView:
+  m_refTextBuffer = Gtk::TextBuffer::create();
+  m_TextView.set_buffer(m_refTextBuffer);
+
+  // Add the TreeView, inside a ScrolledWindow:
+  m_ScrolledWindow.add(m_TextView);
+
+  // Show the scrollbars only when they are necessary:
+  m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+
+  m_VBox.pack_start(m_ScrolledWindow);
+
+  // Add button box:
+  m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK);
+
+  m_ButtonBox.pack_start(m_Button_Clear, Gtk::PACK_SHRINK);
+  m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
+  m_ButtonBox.set_border_width(5);
+  m_ButtonBox.set_spacing(5);
+  m_ButtonBox.set_layout(Gtk::BUTTONBOX_END);
+
+  // Add the message label to the InfoBar:
+  Gtk::Container* infoBarContainer =
+    static_cast<Gtk::Container*>(m_InfoBar.get_content_area());
+
+  if (infoBarContainer)
+    infoBarContainer->add(m_Message_Label);
+
+
+  // Add an ok button to the InfoBar:
+  m_InfoBar.add_button(Gtk::Stock::OK, 0);
+
+  // Add the InfoBar:
+  m_VBox.pack_start(m_InfoBar, Gtk::PACK_SHRINK);
+
+  // Connect signals:
+  m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this,
+              &ExampleWindow::on_button_quit) );
+  m_Button_Clear.signal_clicked().connect(sigc::mem_fun(*this,
+              &ExampleWindow::on_button_clear) );
+  m_refTextBuffer->signal_changed().connect(sigc::mem_fun(*this,
+              &ExampleWindow::on_textbuffer_changed) );
+  m_InfoBar.signal_response().connect(sigc::mem_fun(*this,
+              &ExampleWindow::on_infobar_response) );
+
+  show_all_children();
+
+  // Keep the InfoBar hidden until a message needs to be shown:
+  m_InfoBar.hide();
+
+  // Make the clear button insensitive until text is typed in the buffer.  When
+  // the button is sensitive and it is pressed, the InfoBar is displayed with a
+  // message.
+  m_Button_Clear.set_sensitive(false);
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_button_quit()
+{
+  hide();
+}
+
+void ExampleWindow::on_button_clear()
+{
+  m_refTextBuffer->set_text("");
+  m_Message_Label.set_text("Cleared the TextBuffer.");
+  m_InfoBar.set_message_type(Gtk::MESSAGE_INFO);
+  m_InfoBar.show();
+}
+
+void ExampleWindow::on_textbuffer_changed()
+{
+  m_Button_Clear.set_sensitive(m_refTextBuffer->size() > 0);
+}
+
+void ExampleWindow::on_infobar_response(int)
+{
+  // Clear the message and hide the info bar:
+  m_Message_Label.set_text("");
+  m_InfoBar.hide();
+}
diff --git a/examples/book/infobar/examplewindow.h b/examples/book/infobar/examplewindow.h
new file mode 100644
index 0000000..e48c537
--- /dev/null
+++ b/examples/book/infobar/examplewindow.h
@@ -0,0 +1,50 @@
+/* gtkmm example Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+  ExampleWindow();
+  virtual ~ExampleWindow();
+
+protected:
+  //Signal handlers:
+  virtual void on_button_quit();
+  virtual void on_button_clear();
+  virtual void on_textbuffer_changed();
+  virtual void on_infobar_response(int response);
+
+  //Child widgets:
+  Gtk::VBox m_VBox;
+
+  Gtk::ScrolledWindow m_ScrolledWindow;
+  Gtk::TextView m_TextView;
+  
+  Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer;
+
+  Gtk::HButtonBox m_ButtonBox;
+  Gtk::Button m_Button_Quit, m_Button_Clear;
+
+  Gtk::InfoBar m_InfoBar;
+  Gtk::Label m_Message_Label;
+};
+
+#endif //GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/infobar/main.cc b/examples/book/infobar/main.cc
new file mode 100644
index 0000000..318b3a3
--- /dev/null
+++ b/examples/book/infobar/main.cc
@@ -0,0 +1,29 @@
+/* gtkmm example Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <gtkmm/main.h>
+#include "examplewindow.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]