]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GXpmBtnTbl.h
gtk-patch_2004_2_9.new
[lyx.git] / src / frontends / gtk / GXpmBtnTbl.h
1 // -*- C++ -*-
2 /**
3  * \file GXpmBtnTbl.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Huang Ying
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef XPM_BTN_TBL_H
13 #define XPM_BTN_TBL_H
14
15 #include <boost/scoped_array.hpp>
16
17
18 class GXpmBtnTbl : public Gtk::Table
19 {
20 public:
21         typedef char const ** XpmData;
22         typedef SigC::Signal2<void, int, int> SigType;
23         struct XbmData
24         {
25                 unsigned char const* data_;
26                 int width_;
27                 int height_;
28                 GdkColor fg_;
29         };
30         class GXpmBtn : public Gtk::Button
31         {
32         public:
33                 GXpmBtn() : row_(-1), col_(-1)
34                 {
35                         signal_clicked().connect(
36                                 SigC::slot(*this,
37                                            &GXpmBtn::onButtonClicked));
38                 }
39                 void setRow(int row) { row_ = row; }
40                 void setCol(int col) { col_ = col; }
41                 int getRow() { return row_; }
42                 int getCol() { return col_; }
43                 void setXpm(XpmData xpm);
44                 void setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
45                             Glib::RefPtr<Gdk::Bitmap> mask);
46                 Glib::RefPtr<Gdk::Pixmap> getPixmap() { return pixmap_; }
47                 Glib::RefPtr<Gdk::Bitmap> getMask() { return mask_; }
48                 SigType signalClicked() { return signalClicked_; }
49                 void onButtonClicked()
50                         { signalClicked_.emit(row_, col_); }
51         private:
52                 int row_;
53                 int col_;
54                 Glib::RefPtr<Gdk::Pixmap> pixmap_;
55                 Glib::RefPtr<Gdk::Bitmap> mask_;
56                 SigType signalClicked_;
57         };
58         GXpmBtnTbl(int rows, int cols, XpmData xpms[]);
59         //GXpmBtnTbl(int rows, int cols, XpmData xpm);
60         GXpmBtnTbl(int rows, int cols, const XbmData& xbm);
61         ~GXpmBtnTbl();
62         GXpmBtn* getBtn(int row, int col)
63                 { return &btns_[index(row, col)]; }
64         SigType signalClicked() { return signalClicked_; }
65 private:
66         int index(int row, int col) { return row * cols_ + col; }
67         void on_realize();
68         void construct();
69         void setBtnXpm(XpmData xpms[]);
70         void setBtnXpm(const XbmData& xbm);
71
72         int rows_;
73         int cols_;
74         boost::scoped_array<GXpmBtn> btns_;
75         const XbmData * xbm_;
76         SigType signalClicked_;
77 };
78
79
80 void buttonSetXpm(Gtk::Button * btn, char const **xpm);
81
82
83 #endif