Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 133

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ColorSelectionDialog</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="chapter-dialogs.html" title="Chapter 14. Dialogs">
<link rel="prev" href="sec-dialogs-filechooserdialog.html" title="FileChooserDialog">
<link rel="next" href="sec-font-selection-dialog.html" title="FontSelectionDialog">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">ColorSelectionDialog</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-dialogs-filechooserdialog.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 14. Dialogs</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-font-selection-dialog.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="ColorSelectionDialog">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-color-selection-dialog"></a>ColorSelectionDialog</h2></div></div></div>
<p>
The <code class="classname">ColorSelectionDialog</code> allows the user to choose a
color.
</p>
<p><a class="ulink" href="http://library.gnome.org/devel/gtkmm/unstable/classGtk_1_1ColorSelectionDialog.html" target="_top">Reference</a></p>
<div class="sect2" title="Example">
<div class="titlepage"><div><div><h3 class="title">
<a name="colorselectiondialog-example"></a>Example</h3></div></div></div>
<div class="figure">
<a name="figure-dialogs-colorselectiondialog"></a><p class="title"><b>Figure 14.3. ColorSelectionDialog</b></p>
<div class="figure-contents"><div class="screenshot"><div><img src="figures/dialogs_colorselectiondialog.png" alt="ColorSelectionDialog"></div></div></div>
</div>
<br class="figure-break"><p><a class="ulink" href="http://git.gnome.org/cgit/gtkmm-documentation/tree/examples/book/dialogs/colorselectiondialog" target="_top">Source Code</a></p>
<p>File: <code class="filename">examplewindow.h</code>
</p>
<pre class="programlisting">
#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include &lt;gtkmm.h&gt;

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_button_color_set();

  //Child widgets:
  Gtk::VBox m_VBox;
  Gtk::ColorButton m_Button;
  Gtk::DrawingArea m_DrawingArea; //To show the color.

  Gdk::Color m_Color;
};

#endif //GTKMM_EXAMPLEWINDOW_H
</pre>
<p>File: <code class="filename">examplewindow.cc</code>
</p>
<pre class="programlisting">
#include "examplewindow.h"
#include &lt;iostream&gt;


ExampleWindow::ExampleWindow()
{
  set_title("Gtk::ColorButton example");
  set_default_size(200, 200);

  add(m_VBox);

  m_VBox.pack_start(m_Button, Gtk::PACK_SHRINK);
  m_Button.signal_color_set().connect(sigc::mem_fun(*this,
              &amp;ExampleWindow::on_button_color_set) );

  //Set start color:
  m_Color.set_red(0);
  m_Color.set_blue(65535);
  m_Color.set_green(0);
  m_Button.set_color(m_Color);

  m_DrawingArea.modify_bg(Gtk::STATE_NORMAL, m_Color);

  m_VBox.pack_start(m_DrawingArea);

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_color_set()
{
  //Store the chosen color, and show it:
  m_Color = m_Button.get_color();
  m_DrawingArea.modify_bg(Gtk::STATE_NORMAL, m_Color);
}
</pre>
<p>File: <code class="filename">main.cc</code>
</p>
<pre class="programlisting">
#include &lt;gtkmm/main.h&gt;
#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;
}
</pre>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-dialogs-filechooserdialog.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-dialogs.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-font-selection-dialog.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">FileChooserDialog </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> FontSelectionDialog</td>
</tr>
</table>
</div>
</body>
</html>