/** * \file GXpmBtnTbl.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Huang Ying * * Full author contact details are available in file CREDITS. */ #include // Too hard to make concept checks work with this file #ifdef _GLIBCPP_CONCEPT_CHECKS #undef _GLIBCPP_CONCEPT_CHECKS #endif #include "GXpmBtnTbl.h" #include #include void GXpmBtnTbl::GXpmBtn::setXpm(XpmData xpm) { Glib::RefPtr clrmap = get_colormap(); pixmap_ = Gdk::Pixmap::create_from_xpm(clrmap, mask_, xpm); Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap_, mask_)); image->show(); add(*image); } void GXpmBtnTbl::GXpmBtn::setXpm(Glib::RefPtr pixmap, Glib::RefPtr mask) { pixmap_ = pixmap; mask_ = mask; Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap_, mask_)); image->show(); add(*image); } GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XpmData xpms[]) : Gtk::Table(rows, cols, true), rows_(rows), cols_(cols), xbm_(0) { construct(); setBtnXpm(xpms); } GXpmBtnTbl::GXpmBtnTbl(int rows, int cols, XbmData const & xbm) : Gtk::Table(rows, cols, true), rows_(rows), cols_(cols), xbm_(&xbm) { construct(); } GXpmBtnTbl::~GXpmBtnTbl() { } void GXpmBtnTbl::construct() { BOOST_ASSERT(rows_); BOOST_ASSERT(cols_); btns_.reset(new GXpmBtn[rows_ * cols_]); BOOST_ASSERT(btns_.get()); for (int row = 0; row < rows_; ++row) for (int col = 0; col < cols_; ++col) { GXpmBtn * btn = &btns_[index(row, col)]; btn->setRow(row); btn->setCol(col); btn->signalClicked().connect(signalClicked_); btn->show(); attach(*btn, col, col + 1, row, row + 1); } } void GXpmBtnTbl::setBtnXpm(XpmData xpms[]) { for (int row = 0; row < rows_; ++row) for (int col = 0; col < cols_; ++col) btns_[index(row, col)].setXpm(xpms[index(row, col)]); } void GXpmBtnTbl::setBtnXpm(XbmData const & xbm) { Glib::RefPtr clrmap = get_colormap(); Gdk::Color fg(const_cast(&xbm.fg_)); clrmap->alloc_color(fg); Glib::RefPtr window = get_window(); Glib::RefPtr pixmap = Gdk::Pixmap::create_from_data( window, reinterpret_cast(xbm.data_), xbm.width_, xbm.height_, window->get_depth(), fg, get_style()->get_bg(Gtk::STATE_NORMAL)); Glib::RefPtr mask = Gdk::Bitmap::create( window, reinterpret_cast(xbm.data_), xbm.width_, xbm.height_); Glib::RefPtr gc = Gdk::GC::create(mask); int const btnWidth = xbm.width_ / cols_; int const btnHeight = xbm.height_ / rows_; for (int row = 0; row < rows_; ++row) for (int col = 0; col < cols_; ++col) { Glib::RefPtr pixmapBtn = Gdk::Pixmap::create( window, btnWidth, btnHeight, window->get_depth()); pixmapBtn->draw_drawable(get_style()->get_black_gc(), pixmap, col * btnWidth, row * btnHeight, 0, 0, btnWidth, btnHeight); Glib::RefPtr maskBtn = Gdk::Bitmap::create( window, reinterpret_cast(xbm.data_), btnWidth, btnHeight); maskBtn->draw_drawable(gc, mask, col * btnWidth, row * btnHeight, 0, 0, btnWidth, btnHeight); btns_[index(row, col)].setXpm(pixmapBtn, maskBtn); } } void GXpmBtnTbl::on_realize() { Gtk::Table::on_realize(); if (!xbm_) return; setBtnXpm(*xbm_); } void buttonSetXpm(Gtk::Button * btn, char const ** xpm) { Glib::RefPtr clrmap = btn->get_colormap(); Glib::RefPtr mask; Glib::RefPtr pixmap = Gdk::Pixmap::create_from_xpm(clrmap, mask, xpm); Gtk::Image * image = Gtk::manage(new Gtk::Image(pixmap, mask)); image->show(); btn->add(*image); }