File: widgetproxy.h

package info (click to toggle)
eboard 1.1.1-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,548 kB
  • ctags: 2,803
  • sloc: cpp: 24,724; perl: 1,012; sh: 866; makefile: 66
file content (241 lines) | stat: -rw-r--r-- 5,664 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* $Id: widgetproxy.h,v 1.28 2007/02/05 19:37:56 bergo Exp $ */

/*

    eboard - chess client
    http://eboard.sourceforge.net
    Copyright (C) 2000-2007 Felipe Paulo Guazzi Bergo
    bergo@seul.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#ifndef WIDGET_PROXY_H
#define WIDGET_PROXY_H

#include <gtk/gtk.h>
#include "eboard.h"
#include "stl.h"

class WindowGeometry;

class WidgetProxy {
 public:
  WidgetProxy();

  virtual void show();
  virtual void hide();
  virtual void repaint();

  void setIcon(char **xpmdata,const char *text);
  void restorePosition(WindowGeometry *wg);

  GtkWidget * PixButton(char **xpmicon, char *caption);

  GtkWidget * scrollBox(GtkWidget *child);

  GtkWidget *widget;
};

class BoxedLabel : public WidgetProxy {
 public:
  BoxedLabel(char *text);
  void setText(char *msg);
 private:
  GtkWidget *label;
};

class ModalDialog : public WidgetProxy {
 public:
  ModalDialog(char *title);
  virtual ~ModalDialog();
  virtual void show();

  void setDismiss(GtkObject *obj,char *sig);
  void setCloseable(bool v);

  void release();
  virtual void releaseWithoutDelete();

  GtkWidget *focused_widget;

  friend void modal_release(GtkWidget *w,gpointer data);
  friend gint modal_closereq(GtkWidget * widget, 
			     GdkEvent * event, gpointer data);

 private:
  bool closeable;
};

void modal_release(GtkWidget *w,gpointer data);
gint modal_closereq(GtkWidget * widget, 
		    GdkEvent * event, gpointer data);

class NonModalDialog : public ModalDialog {
 public:
  NonModalDialog(char *title);
  ~NonModalDialog();
  virtual void show();

  virtual void releaseWithoutDelete();
};

class UnboundedProgressWindow : public WidgetProxy {
 public:
  UnboundedProgressWindow(const char *_templ);
  virtual ~UnboundedProgressWindow();
  void setProgress(int v);  
 private:
  const char *templ;
  GtkWidget *label;
};

class UpdateNotify {
 public:
  virtual void update()=0;
};

class ColorButton : public WidgetProxy {
 public:
  ColorButton(char *caption, int value);
  void hookNotify(UpdateNotify *listen);
  void setColor(int value);
  int  getColor();
 private:
  void updateButtonFace();
  friend void colorb_click(GtkWidget *b,gpointer data);
  friend void colorb_csok(GtkWidget *b,gpointer data);

  int ColorValue;
  GtkWidget *colordlg, *label;
  UpdateNotify * notified;
};

void colorb_click(GtkWidget *b,gpointer data);
void colorb_csok(GtkWidget *b,gpointer data);

class TextPreview : public WidgetProxy, public UpdateNotify {
 public:
  TextPreview(GdkWindow *wnd, ColorButton *_bg);
  virtual ~TextPreview();
  void attach(ColorButton *cb, const char *sample);
  void freeze();
  void thaw();
  void update();
 private:
  ColorButton *bg;
  GdkPixmap *pixmap;
  bool frozen, pending;
  vector<ColorButton *> colors;
  vector<string> examples;
  PangoLayout *pl;
  PangoFontDescription *pfd;

  friend gboolean preview_expose(GtkWidget *widget,GdkEventExpose *ee,
				 gpointer data);
};

gboolean preview_expose(GtkWidget *widget,GdkEventExpose *ee,
			gpointer data);

class FileDialog : public WidgetProxy {

 public:
  FileDialog(char *title);
  virtual ~FileDialog();

  bool run();

  char FileName[128];

 private:
  bool gotresult;
  bool destroyed;

  friend void filedlg_ok (GtkWidget * w, gpointer data);
  friend void filedlg_destroy (GtkWidget * w, gpointer data);

};

void filedlg_ok (GtkWidget * w, gpointer data);
void filedlg_destroy (GtkWidget * w, gpointer data);

class LayoutBox {
 public:
  LayoutBox();
  virtual ~LayoutBox();

  void prepare(GtkWidget *w, GdkPixmap *t, GdkGC *gc, int a, int b, int c,int d);
  void setFont(int i,const char *fontname);

  void setColor(int c);
  void drawRect(int x,int y,int w,int h,bool fill);
  void drawLine(int x,int y,int w,int h);
  void drawEllipse(int x,int y,int w,int h,bool fill);
  void drawString(int x,int y, int f, const char *s);
  void drawString(int x,int y, int f, string &s);
  void drawSubstring(int x,int y, int f, const char *s,int len);
  int  drawButton(int x,int y,int w,int h, char *s,int font,
		  int fg,int bg);

  int  stringWidth(int f,const char *s);
  int  substringWidth(int f,const char *s,int len);
  int  fontHeight(int f);

  bool drawBoxedString(int x,int y,int w,int h,int f,char *s,char *sep);
  bool prepared();

  void consumeTop(int v);
  void consumeBottom(int v);

  int X,Y,W,H;
  GdkPixmap * Target;
  GdkGC     * GC;

 private:
  PangoFontDescription *pfd[5];
  PangoLayout *pl;
};

class DropBox : public WidgetProxy {
 public:
  DropBox(char *option, ...);
  virtual ~DropBox();

  int  getSelection();
  void setSelection(int i);
  void setUpdateListener(UpdateInterface *ui);

 private:
  int selection;
  vector<GtkWidget *> options;
  UpdateInterface *listener;

  friend void dropbox_select(GtkWidget *w, gpointer data);
};

void dropbox_select(GtkWidget *w, gpointer data);

/* some gtk helpers */

namespace Gtk {

  // call gtk_widget_show for a bunch of widgets
  void show(GtkWidget *w, ...);

}

#endif