3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
21 #include "GXpmBtnTbl.h"
25 #include <boost/assert.hpp>
28 void GXpmBtnTbl::GXpmBtn::setXpm(XpmData xpm)
30 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
31 pixmap_ = Gdk::Pixmap::create_from_xpm(clrmap,
34 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
40 void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
41 Glib::RefPtr<Gdk::Bitmap> mask)
46 Gtk::manage(new Gtk::Image(pixmap_, mask_));
52 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) :
53 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
61 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XbmData const & xbm) :
62 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
69 GXpmBtnTbl::~GXpmBtnTbl()
74 void GXpmBtnTbl::construct()
78 btns_.reset(new GXpmBtn[rows_ * cols_]);
79 BOOST_ASSERT(btns_.get());
81 for (int row = 0; row < rows_; ++row)
82 for (int col = 0; col < cols_; ++col) {
83 GXpmBtn * btn = &btns_[index(row, col)];
86 btn->signalClicked().connect(signalClicked_);
88 attach(*btn, col, col + 1, row, row + 1);
93 void GXpmBtnTbl::setBtnXpm(XpmData xpms[])
95 for (int row = 0; row < rows_; ++row)
96 for (int col = 0; col < cols_; ++col)
97 btns_[index(row, col)].setXpm(xpms[index(row, col)]);
101 void GXpmBtnTbl::setBtnXpm(XbmData const & xbm)
103 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
104 Gdk::Color fg(const_cast<GdkColor *>(&xbm.fg_));
105 clrmap->alloc_color(fg);
106 Glib::RefPtr<Gdk::Window> window = get_window();
108 Glib::RefPtr<Gdk::Pixmap> pixmap = Gdk::Pixmap::create_from_data(
110 reinterpret_cast<char const * const>(xbm.data_),
115 get_style()->get_bg(Gtk::STATE_NORMAL));
117 Glib::RefPtr<Gdk::Bitmap> mask = Gdk::Bitmap::create(
119 reinterpret_cast<char const * const>(xbm.data_),
125 Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
126 int const btnWidth = xbm.width_ / cols_;
127 int const btnHeight = xbm.height_ / rows_;
128 for (int row = 0; row < rows_; ++row)
129 for (int col = 0; col < cols_; ++col) {
130 Glib::RefPtr<Gdk::Pixmap> pixmapBtn =
135 window->get_depth());
136 pixmapBtn->draw_drawable(get_style()->get_black_gc(),
144 Glib::RefPtr<Gdk::Bitmap> maskBtn =
147 reinterpret_cast<char const * const>(xbm.data_),
150 maskBtn->draw_drawable(gc,
158 btns_[index(row, col)].setXpm(pixmapBtn, maskBtn);
163 void GXpmBtnTbl::on_realize()
165 Gtk::Table::on_realize();
172 void buttonSetXpm(Gtk::Button * btn, char const ** xpm)
174 Glib::RefPtr<Gdk::Colormap> clrmap = btn->get_colormap();
176 Glib::RefPtr<Gdk::Bitmap> mask;
177 Glib::RefPtr<Gdk::Pixmap> pixmap =
178 Gdk::Pixmap::create_from_xpm(clrmap, mask, xpm);
179 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap, mask));