File: example_colorsel.cc

package info (click to toggle)
gtkmm2.4 1%3A2.20.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 73,860 kB
  • ctags: 20,553
  • sloc: xml: 79,575; sh: 10,120; cpp: 8,347; makefile: 290
file content (99 lines) | stat: -rw-r--r-- 2,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
 /* Color Selector
 *
 * GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is
 * a prebuilt dialog containing a GtkColorSelection.
 *
 */

#include <gtkmm.h>

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

protected:
  //Signal handlers:
  virtual void on_button_clicked();

  //Member widgets:
  Gtk::VBox m_VBox;
  Gtk::Frame m_Frame;
  Gtk::DrawingArea m_DrawingArea;
  Gtk::Button m_Button;
  Gdk::Color m_Color;
  Gtk::Alignment m_Alignment;
};

//Called by DemoWindow;
Gtk::Window* do_colorsel()
{
  return new Example_ColorSel();
}

Example_ColorSel::Example_ColorSel()
: m_VBox(false, 8),
  m_Button("_Change the above color", true),
  m_Alignment(Gtk::ALIGN_RIGHT, Gtk::ALIGN_BOTTOM, 0.0, 0.0)
{
  set_title("Color Selection");
  set_border_width(8);

  m_VBox.set_border_width(8);
  add(m_VBox);

  /*
   * Create the color swatch area
   */

  m_Frame.set_shadow_type(Gtk::SHADOW_IN);
  m_VBox.pack_start(m_Frame);

  // set a fixed size
  m_DrawingArea.set_size_request(200, 200);

  // Unset the background pixmap (as used by pixmap themes)
  // because it takes precedence over the background color.
  m_DrawingArea.modify_bg_pixmap(Gtk::STATE_NORMAL, "<none>");

  // set the color
  m_Color.set_rgb(0, 0, 65535);
  m_DrawingArea.modify_bg(Gtk::STATE_NORMAL, m_Color);

  m_Frame.add(m_DrawingArea);

  m_Alignment.add(m_Button);

  m_VBox.pack_start(m_Alignment,Gtk::PACK_SHRINK);

  m_Button.signal_clicked().connect(sigc::mem_fun(*this, &Example_ColorSel::on_button_clicked));

  show_all();
}

Example_ColorSel::~Example_ColorSel()
{
}

void Example_ColorSel::on_button_clicked()
{
  Gtk::ColorSelectionDialog dialog ("Changing color");
  dialog.set_transient_for(*this);

  Gtk::ColorSelection *const pColorSel = dialog.get_color_selection();

  pColorSel->set_previous_color(m_Color);
  pColorSel->set_current_color(m_Color);
  pColorSel->set_has_palette();

  const int response = dialog.run();

  if(response == Gtk::RESPONSE_OK)
  {
    m_Color = pColorSel->get_current_color();

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