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"
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 = SigC::manage(new Gtk::Image(pixmap_, mask_));
32 void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
33 Glib::RefPtr<Gdk::Bitmap> mask)
37 Gtk::Image * image = SigC::manage(new Gtk::Image(pixmap_, mask_));
43 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) :
44 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
52 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XbmData const & xbm) :
53 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
60 GXpmBtnTbl::~GXpmBtnTbl()
65 void GXpmBtnTbl::construct()
69 btns_.reset(new GXpmBtn[rows_ * cols_]);
72 for (int row = 0; row < rows_; ++row)
73 for (int col = 0; col < cols_; ++col) {
74 GXpmBtn * btn = &btns_[index(row, col)];
77 btn->signalClicked().connect(signalClicked_.slot());
79 attach(*btn, col, col + 1, row, row + 1);
84 void GXpmBtnTbl::setBtnXpm(XpmData xpms[])
86 for (int row = 0; row < rows_; ++row)
87 for (int col = 0; col < cols_; ++col)
88 btns_[index(row, col)].setXpm(xpms[index(row, col)]);
92 void GXpmBtnTbl::setBtnXpm(XbmData const & xbm)
94 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
95 Gdk::Color fg(const_cast<GdkColor *>(&xbm.fg_));
96 clrmap->alloc_color(fg);
97 Glib::RefPtr<Gdk::Window> window = get_window();
99 Glib::RefPtr<Gdk::Pixmap> pixmap = Gdk::Pixmap::create_from_data(
101 reinterpret_cast<char const * const>(xbm.data_),
106 get_style()->get_bg(Gtk::STATE_NORMAL));
108 Glib::RefPtr<Gdk::Bitmap> mask = Gdk::Bitmap::create(
110 reinterpret_cast<char const * const>(xbm.data_),
116 Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
117 int const btnWidth = xbm.width_ / cols_;
118 int const btnHeight = xbm.height_ / rows_;
119 for (int row = 0; row < rows_; ++row)
120 for (int col = 0; col < cols_; ++col) {
121 Glib::RefPtr<Gdk::Pixmap> pixmapBtn =
126 window->get_depth());
127 pixmapBtn->draw_drawable(get_style()->get_black_gc(),
135 Glib::RefPtr<Gdk::Bitmap> maskBtn =
138 reinterpret_cast<char const * const>(xbm.data_),
141 maskBtn->draw_drawable(gc,
149 btns_[index(row, col)].setXpm(pixmapBtn, maskBtn);
154 void GXpmBtnTbl::on_realize()
156 Gtk::Table::on_realize();
163 void buttonSetXpm(Gtk::Button * btn, char const ** xpm)
165 Glib::RefPtr<Gdk::Bitmap> mask;
167 Glib::RefPtr<Gdk::Colormap> clrmap = btn->get_colormap();
169 Glib::RefPtr<Gdk::Pixmap> pixmap =
170 Gdk::Pixmap::create_from_xpm(clrmap,
173 Gtk::Image * image = SigC::manage(new Gtk::Image(pixmap, mask));