]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GXpmBtnTbl.h
WS changes
[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 public:
20         typedef char const ** XpmData;
21         typedef SigC::Signal2<void, int, int> SigType;
22
23         struct XbmData {
24                 unsigned char const* data_;
25                 int width_;
26                 int height_;
27                 GdkColor fg_;
28         };
29
30         class GXpmBtn : public Gtk::Button {
31         public:
32                 GXpmBtn() : row_(-1), col_(-1)
33                 {
34                         signal_clicked().connect(
35                                 SigC::slot(*this,
36                                            &GXpmBtn::onButtonClicked));
37                 }
38                 void setRow(int row) { row_ = row; }
39                 void setCol(int col) { col_ = col; }
40                 int getRow() { return row_; }
41                 int getCol() { return col_; }
42                 void setXpm(XpmData xpm);
43                 void setXpm(Glib::RefPtr<Gdk::Pixmap> pixmap,
44                             Glib::RefPtr<Gdk::Bitmap> mask);
45                 Glib::RefPtr<Gdk::Pixmap> getPixmap() { return pixmap_; }
46                 Glib::RefPtr<Gdk::Bitmap> getMask() { return mask_; }
47                 SigType signalClicked() { return signalClicked_; }
48
49                 void onButtonClicked()
50                 {
51                         signalClicked_.emit(row_, col_);
52                 }
53         private:
54                 int row_;
55                 int col_;
56                 Glib::RefPtr<Gdk::Pixmap> pixmap_;
57                 Glib::RefPtr<Gdk::Bitmap> mask_;
58                 SigType signalClicked_;
59         };
60
61         GXpmBtnTbl(int rows, int cols, XpmData xpms[]);
62         //GXpmBtnTbl(int rows, int cols, XpmData xpm);
63         GXpmBtnTbl(int rows, int cols, XbmData const & xbm);
64         ~GXpmBtnTbl();
65
66         GXpmBtn * getBtn(int row, int col)
67         {
68                 return &btns_[index(row, col)];
69         }
70
71         SigType signalClicked() { return signalClicked_; }
72 private:
73         int index(int row, int col) { return row * cols_ + col; }
74         void on_realize();
75         void construct();
76         void setBtnXpm(XpmData xpms[]);
77         void setBtnXpm(XbmData const & xbm);
78
79         int rows_;
80         int cols_;
81         boost::scoped_array<GXpmBtn> btns_;
82         const XbmData * xbm_;
83         SigType signalClicked_;
84 };
85
86
87 void buttonSetXpm(Gtk::Button * btn, char const ** xpm);
88
89
90 #endif