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 #include "GXpmBtnTbl.h"
17 #include <boost/assert.hpp>
20 void GXpmBtnTbl::GXpmBtn::setXpm(XpmData xpm)
22 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
23 pixmap_ = Gdk::Pixmap::create_from_xpm(clrmap,
26 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap_, mask_));
32 void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
33 Glib::RefPtr<Gdk::Bitmap> mask)
38 Gtk::manage(new Gtk::Image(pixmap_, mask_));
44 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) :
45 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
53 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XbmData const & xbm) :
54 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
61 GXpmBtnTbl::~GXpmBtnTbl()
66 void GXpmBtnTbl::construct()
70 btns_.reset(new GXpmBtn[rows_ * cols_]);
71 BOOST_ASSERT(btns_.get());
73 for (int row = 0; row < rows_; ++row)
74 for (int col = 0; col < cols_; ++col) {
75 GXpmBtn * btn = &btns_[index(row, col)];
78 btn->signalClicked().connect(signalClicked_);
80 attach(*btn, col, col + 1, row, row + 1);
85 void GXpmBtnTbl::setBtnXpm(XpmData xpms[])
87 for (int row = 0; row < rows_; ++row)
88 for (int col = 0; col < cols_; ++col)
89 btns_[index(row, col)].setXpm(xpms[index(row, col)]);
93 void GXpmBtnTbl::setBtnXpm(XbmData const & xbm)
95 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
96 Gdk::Color fg(const_cast<GdkColor *>(&xbm.fg_));
97 clrmap->alloc_color(fg);
98 Glib::RefPtr<Gdk::Window> window = get_window();
100 Glib::RefPtr<Gdk::Pixmap> pixmap = Gdk::Pixmap::create_from_data(
102 reinterpret_cast<char const * const>(xbm.data_),
107 get_style()->get_bg(Gtk::STATE_NORMAL));
109 Glib::RefPtr<Gdk::Bitmap> mask = Gdk::Bitmap::create(
111 reinterpret_cast<char const * const>(xbm.data_),
117 Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
118 int const btnWidth = xbm.width_ / cols_;
119 int const btnHeight = xbm.height_ / rows_;
120 for (int row = 0; row < rows_; ++row)
121 for (int col = 0; col < cols_; ++col) {
122 Glib::RefPtr<Gdk::Pixmap> pixmapBtn =
127 window->get_depth());
128 pixmapBtn->draw_drawable(get_style()->get_black_gc(),
136 Glib::RefPtr<Gdk::Bitmap> maskBtn =
139 reinterpret_cast<char const * const>(xbm.data_),
142 maskBtn->draw_drawable(gc,
150 btns_[index(row, col)].setXpm(pixmapBtn, maskBtn);
155 void GXpmBtnTbl::on_realize()
157 Gtk::Table::on_realize();
164 void buttonSetXpm(Gtk::Button * btn, char const ** xpm)
166 Glib::RefPtr<Gdk::Colormap> clrmap = btn->get_colormap();
168 Glib::RefPtr<Gdk::Bitmap> mask;
169 Glib::RefPtr<Gdk::Pixmap> pixmap =
170 Gdk::Pixmap::create_from_xpm(clrmap, mask, xpm);
171 Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap, mask));