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.
14 #include "GXpmBtnTbl.h"
17 void GXpmBtnTbl::GXpmBtn::setXpm(XpmData xpm)
19 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
21 pixmap_ = Gdk::Pixmap::create_from_xpm(clrmap,
24 image = SigC::manage(new Gtk::Image(pixmap_, mask_));
30 void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
31 Glib::RefPtr<Gdk::Bitmap> mask)
36 image = SigC::manage(new Gtk::Image(pixmap_, mask_));
42 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) :
43 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
51 GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, const XbmData& xbm) :
52 Gtk::Table(rows, cols, true), rows_(rows), cols_(cols),
59 GXpmBtnTbl::~GXpmBtnTbl()
64 void GXpmBtnTbl::construct()
68 btns_.reset(new GXpmBtn[rows_ * cols_]);
73 for (row = 0; row < rows_; ++row)
74 for (col = 0; col < cols_; ++col) {
75 btn = &btns_[index(row, col)];
78 btn->signalClicked().connect(signalClicked_.slot());
80 attach(*btn, col, col + 1, row, row + 1);
85 void GXpmBtnTbl::setBtnXpm(XpmData xpms[])
88 for (row = 0; row < rows_; ++row)
89 for (col = 0; col < cols_; ++col)
90 btns_[index(row, col)].setXpm(xpms[index(row, col)]);
94 void GXpmBtnTbl::setBtnXpm(const XbmData& xbm)
96 Glib::RefPtr<Gdk::Bitmap> mask;
97 Glib::RefPtr<Gdk::Pixmap> pixmap;
98 Glib::RefPtr<Gdk::Colormap> clrmap = get_colormap();
99 Gdk::Color fg(const_cast<GdkColor *>(&xbm.fg_));
100 clrmap->alloc_color(fg);
101 Glib::RefPtr<Gdk::Window> window = get_window();
102 pixmap = Gdk::Pixmap::create_from_data(
104 reinterpret_cast<char const * const>(xbm.data_),
109 get_style()->get_bg(Gtk::STATE_NORMAL));
110 mask = Gdk::Bitmap::create(
112 reinterpret_cast<char const * const>(xbm.data_),
115 Glib::RefPtr<Gdk::Bitmap> maskBtn;
116 Glib::RefPtr<Gdk::Pixmap> pixmapBtn;
117 Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(mask);
119 int btnWidth = xbm.width_ / cols_;
120 int btnHeight = xbm.height_ / rows_;
121 for (row = 0; row < rows_; ++row)
122 for (col = 0; col < cols_; ++col) {
123 pixmapBtn = Gdk::Pixmap::create(
127 window->get_depth());
128 pixmapBtn->draw_drawable(get_style()->get_black_gc(),
136 maskBtn = Gdk::Bitmap::create(
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;
166 Glib::RefPtr<Gdk::Pixmap> pixmap;
167 Glib::RefPtr<Gdk::Colormap> clrmap = btn->get_colormap();
169 pixmap = Gdk::Pixmap::create_from_xpm(clrmap,
172 image = SigC::manage(new Gtk::Image(pixmap, mask));