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 _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
18 #include "GXpmBtnTbl.h"
22 #include <boost/assert.hpp>
25 void GXpmBtnTbl::GXpmBtn::setXpm(XpmData xpm)
27 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
28 pixmap_ = Gdk::Pixmap::create_from_xpm(clrmap,
31 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
37 void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
38 Glib::RefPtr<Gdk::Bitmap> mask)
43 Gtk::manage(new Gtk::Image(pixmap_, mask_));
49 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) :
50 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
58 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XbmData const & xbm) :
59 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
66 GXpmBtnTbl::~GXpmBtnTbl()
71 void GXpmBtnTbl::construct()
75 btns_.reset(new GXpmBtn[rows_ * cols_]);
76 BOOST_ASSERT(btns_.get());
78 for (int row = 0; row < rows_; ++row)
79 for (int col = 0; col < cols_; ++col) {
80 GXpmBtn * btn = &btns_[index(row, col)];
83 btn->signalClicked().connect(signalClicked_);
85 attach(*btn, col, col + 1, row, row + 1);
90 void GXpmBtnTbl::setBtnXpm(XpmData xpms[])
92 for (int row = 0; row < rows_; ++row)
93 for (int col = 0; col < cols_; ++col)
94 btns_[index(row, col)].setXpm(xpms[index(row, col)]);
98 void GXpmBtnTbl::setBtnXpm(XbmData const & xbm)
100 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
101 Gdk::Color fg(const_cast<GdkColor *>(&xbm.fg_));
102 clrmap->alloc_color(fg);
103 Glib::RefPtr<Gdk::Window> window = get_window();
105 Glib::RefPtr<Gdk::Pixmap> pixmap = Gdk::Pixmap::create_from_data(
107 reinterpret_cast<char const * const>(xbm.data_),
112 get_style()->get_bg(Gtk::STATE_NORMAL));
114 Glib::RefPtr<Gdk::Bitmap> mask = Gdk::Bitmap::create(
116 reinterpret_cast<char const * const>(xbm.data_),
122 Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
123 int const btnWidth = xbm.width_ / cols_;
124 int const btnHeight = xbm.height_ / rows_;
125 for (int row = 0; row < rows_; ++row)
126 for (int col = 0; col < cols_; ++col) {
127 Glib::RefPtr<Gdk::Pixmap> pixmapBtn =
132 window->get_depth());
133 pixmapBtn->draw_drawable(get_style()->get_black_gc(),
141 Glib::RefPtr<Gdk::Bitmap> maskBtn =
144 reinterpret_cast<char const * const>(xbm.data_),
147 maskBtn->draw_drawable(gc,
155 btns_[index(row, col)].setXpm(pixmapBtn, maskBtn);
160 void GXpmBtnTbl::on_realize()
162 Gtk::Table::on_realize();
169 void buttonSetXpm(Gtk::Button * btn, char const ** xpm)
171 Glib::RefPtr<Gdk::Colormap> clrmap = btn->get_colormap();
173 Glib::RefPtr<Gdk::Bitmap> mask;
174 Glib::RefPtr<Gdk::Pixmap> pixmap =
175 Gdk::Pixmap::create_from_xpm(clrmap, mask, xpm);
176 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap, mask));