File: button.cpp

package info (click to toggle)
fox 1.0.52-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,788 kB
  • ctags: 13,384
  • sloc: cpp: 96,482; sh: 8,338; ansic: 1,935; makefile: 1,010; perl: 32
file content (368 lines) | stat: -rw-r--r-- 14,391 bytes parent folder | download | duplicates (2)
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/********************************************************************************
*                                                                               *
*                                 Button Test                                   *
*                                                                               *
*********************************************************************************
* Copyright (C) 1998 by Jeroen van der Zijp.   All Rights Reserved.             *
*********************************************************************************
* $Id: button.cpp,v 1.8 2000/08/29 05:56:48 jeroen Exp $                        *
********************************************************************************/
#include "fx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/*******************************************************************************/


// Mini application object
class ButtonWindow : public FXMainWindow {
  FXDECLARE(ButtonWindow)
protected:
  FXButton*          button;        // Object being tested
  FXStatusbar*       statusbar;     // Status line
  FXHorizontalFrame* contents;      // Container for button
  FXVerticalFrame*   controls;      // Switchs to set various modes
  FXGroupBox*        group1;
  FXGroupBox*        group2;
  FXGroupBox*        group3;
  FXGroupBox*        group4;
protected:
  ButtonWindow(){}
public:
  enum {
    ID_ICON_BEFORE_TEXT=FXMainWindow::ID_LAST,
    ID_ICON_AFTER_TEXT,
    ID_ICON_CENTER_HOR,
    ID_ICON_ABOVE_TEXT,
    ID_ICON_BELOW_TEXT,
    ID_ICON_CENTER_VER,
    ID_JUST_CENTER_X,
    ID_JUST_LEFT,
    ID_JUST_RIGHT,
    ID_JUST_HOR_APART,
    ID_JUST_CENTER_Y,
    ID_JUST_TOP,
    ID_JUST_BOTTOM,
    ID_JUST_VER_APART,
    ID_TOOLBAR_STYLE,
    ID_QUIT,
    ID_DEBUG
    };
public:
  long onCmdIconBeforeText(FXObject*,FXSelector,void*);
  long onCmdIconAfterText(FXObject*,FXSelector,void*);
  long onCmdIconCenterHor(FXObject*,FXSelector,void*);
  long onCmdIconAboveText(FXObject*,FXSelector,void*);
  long onCmdIconBelowText(FXObject*,FXSelector,void*);
  long onCmdIconCenterVer(FXObject*,FXSelector,void*);
  long onCmdJustCenterX(FXObject*,FXSelector,void*);
  long onCmdJustLeft(FXObject*,FXSelector,void*);
  long onCmdJustRight(FXObject*,FXSelector,void*);
  long onCmdJustHorApart(FXObject*,FXSelector,void*);
  long onCmdJustCenterY(FXObject*,FXSelector,void*);
  long onCmdJustTop(FXObject*,FXSelector,void*);
  long onCmdJustBottom(FXObject*,FXSelector,void*);
  long onCmdJustVerApart(FXObject*,FXSelector,void*);
  long onCmdToolbarStyle(FXObject*,FXSelector,void*);
  long onCmdQuit(FXObject*,FXSelector,void*);
public:
  ButtonWindow(FXApp* a);
  void create();
  };

  
/*******************************************************************************/

// Icon data
const unsigned char bigpenguin[]={
  0x47,0x49,0x46,0x38,0x37,0x61,0x30,0x00,0x39,0x00,0xf3,0x00,0x00,0xb2,0xc0,0xdc,
  0x5a,0x52,0x41,0x0e,0x0b,0x0b,0x47,0x3b,0x26,0x71,0x6e,0x67,0xb7,0xb5,0xb0,0xd4,
  0xd2,0xce,0xf9,0xf7,0xf7,0x99,0x8d,0x77,0xa3,0x77,0x1b,0xee,0xba,0x12,0xbe,0xa2,
  0x14,0x8b,0x5e,0x07,0xb3,0x8b,0x27,0xee,0xc7,0x1c,0xd2,0x98,0x0f,0x2c,0x00,0x00,
  0x00,0x00,0x30,0x00,0x39,0x00,0x00,0x04,0xfe,0x10,0xc8,0x49,0xab,0x0d,0x22,0x8b,
  0x61,0xbb,0xff,0x20,0xa6,0x8d,0x1c,0x68,0x9e,0xd3,0x30,0xae,0x19,0x81,0xbe,0x9d,
  0xca,0x66,0x81,0xe8,0xc2,0x38,0x31,0x6b,0x84,0x28,0xe0,0x38,0xd9,0x6e,0x15,0x00,
  0xbe,0x84,0xc3,0x91,0x11,0x95,0x9c,0xdd,0x96,0x9f,0xe1,0x20,0x30,0x40,0x16,0xa1,
  0x51,0x01,0xa1,0xe0,0x1b,0x14,0x0a,0x06,0x9d,0xe6,0x8a,0xed,0x6c,0x0c,0x85,0x83,
  0xcc,0x70,0x40,0x18,0x0c,0xa4,0xb2,0x67,0x5a,0x2d,0x00,0x32,0x07,0x4c,0x40,0xad,
  0x29,0xc9,0x2b,0x74,0x5a,0x77,0x02,0x06,0x6b,0x5d,0x7f,0x16,0x2a,0x05,0x02,0x09,
  0x0a,0x0a,0x0b,0x0b,0x0c,0x1b,0x7c,0x19,0x7e,0x88,0x12,0x2a,0x08,0x0d,0x0a,0x0e,
  0x9d,0x9d,0x0a,0x12,0x2b,0x97,0x14,0x18,0x09,0x0f,0x9c,0x9e,0xa9,0xa2,0xa3,0x12,
  0x54,0x9b,0xa8,0x9e,0x0a,0x0f,0x0f,0x2b,0x4f,0x97,0x18,0x0c,0x8e,0xb1,0x0d,0xb3,
  0xb4,0x1b,0x34,0xac,0x00,0x18,0x08,0x0c,0x0f,0x90,0x09,0xa6,0xc6,0x00,0x2a,0x45,
  0x19,0xc1,0x3a,0x05,0x08,0xc9,0x0f,0x0d,0x0d,0x60,0x68,0x2d,0x95,0xac,0x19,0x6f,
  0xd2,0xc8,0x0d,0x00,0x6c,0x07,0x94,0x3c,0xb7,0x93,0x68,0x5f,0x5f,0xe2,0xe3,0x8b,
  0x71,0x88,0xdc,0xec,0xea,0xe3,0xf3,0xe3,0x48,0x82,0x72,0x2d,0xf4,0xeb,0xf4,0xec,
  0x2c,0x72,0x32,0xfc,0x02,0xf2,0x63,0x61,0x09,0x88,0x88,0x3d,0x02,0x13,0xda,0xdb,
  0xb0,0x44,0xcc,0x8f,0x7d,0x01,0xdf,0x48,0x44,0xe0,0xc4,0x88,0x10,0x30,0x09,0xe7,
  0x49,0x4c,0xb3,0xf0,0x07,0x90,0x3e,0xfe,0x10,0x33,0x1e,0xe8,0x56,0x11,0x86,0x8f,
  0x34,0x22,0x05,0xc2,0x99,0x81,0x63,0x4c,0xca,0x8c,0x77,0xec,0xd9,0x02,0xe1,0x30,
  0xe4,0xcb,0x71,0x2b,0x7f,0x69,0x43,0x21,0x03,0xe1,0x4d,0x81,0x3b,0x5e,0x68,0x40,
  0xf9,0x33,0x60,0xc7,0x99,0x1d,0x1c,0x16,0x55,0x38,0x83,0x4c,0x16,0x3c,0x4b,0x03,
  0x3a,0x74,0xf7,0x41,0xc8,0x80,0xa8,0x52,0x83,0x82,0xe8,0x73,0x15,0x2b,0xbd,0x41,
  0xfe,0xb6,0x56,0xf2,0xe9,0xf5,0xc0,0xd4,0x3e,0x26,0x04,0x30,0x48,0xa0,0xa5,0xec,
  0x3c,0x1f,0x95,0x18,0x82,0x38,0xe5,0x48,0x00,0xd1,0xa8,0x9d,0xe0,0xfe,0x72,0x6a,
  0x81,0x97,0x23,0x59,0x02,0x10,0x60,0x35,0xc0,0xa9,0x01,0x8b,0x04,0x0b,0x3e,0x20,
  0x98,0xf5,0x57,0x01,0xdb,0xae,0x45,0x09,0x2b,0x90,0x34,0x82,0x41,0xa7,0x0e,0xd2,
  0xfc,0x7e,0xe2,0xa4,0x02,0xf2,0x4d,0x00,0x8e,0x12,0x08,0xc9,0xe5,0x88,0x82,0xa6,
  0x5e,0x8d,0x1b,0x2f,0xa8,0xf4,0xd3,0x00,0xe8,0x59,0xc8,0xd6,0xd2,0x55,0x80,0x60,
  0x82,0xdf,0xd4,0x8d,0x3b,0xb1,0xcd,0x70,0x37,0xa1,0xeb,0x53,0xbd,0x18,0x73,0x72,
  0x54,0x1b,0x00,0x02,0x5d,0xa9,0x1d,0xa4,0x76,0xf9,0xb2,0xc0,0x2b,0x47,0xb3,0x1b,
  0x4b,0x58,0x3c,0x3c,0x77,0xee,0xdd,0x64,0x33,0x32,0x78,0x8e,0xbb,0x31,0x02,0xea,
  0xdd,0xab,0x73,0x4a,0xd0,0x5b,0xe5,0x86,0xe8,0x7f,0x95,0xa7,0x06,0x8f,0x5b,0x7d,
  0x63,0x9b,0xf4,0xda,0x05,0xa0,0xeb,0xde,0xba,0x72,0xf6,0xe1,0xab,0x27,0x10,0xe9,
  0xb0,0x58,0xfa,0xff,0x8d,0xf1,0x67,0x82,0x1e,0x72,0xb8,0x89,0x16,0xce,0x1b,0xd1,
  0x10,0x60,0x8f,0x7f,0xf9,0xc9,0x52,0x5b,0x70,0xe1,0xb9,0xf7,0x80,0x68,0x4d,0x64,
  0xc0,0x60,0x7d,0x8e,0x34,0x50,0x9c,0x71,0xdf,0x04,0x27,0x5c,0x63,0x13,0xea,0xb5,
  0xc3,0x76,0xe8,0x51,0x83,0x94,0x04,0x04,0x10,0x80,0xcc,0x8a,0x02,0xce,0xd2,0x40,
  0x02,0x0c,0x58,0x55,0xc5,0x8c,0x55,0xd0,0x90,0x40,0x8b,0xd4,0x30,0x70,0xa2,0x05,
  0x29,0x32,0xb0,0xd6,0x8a,0x3e,0x56,0xb1,0x23,0x05,0x03,0xfc,0x08,0xe4,0x86,0x2f,
  0xf4,0xe0,0x63,0x90,0x7c,0x7d,0x40,0xc5,0x92,0x0c,0x34,0x39,0x41,0x04,0x00,0x3b
  };

/*******************************************************************************/
  

// Map
FXDEFMAP(ButtonWindow) ButtonWindowMap[]={
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_BEFORE_TEXT,ButtonWindow::onCmdIconBeforeText),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_AFTER_TEXT,ButtonWindow::onCmdIconAfterText),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_CENTER_HOR,ButtonWindow::onCmdIconCenterHor),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_ABOVE_TEXT,ButtonWindow::onCmdIconAboveText),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_BELOW_TEXT,ButtonWindow::onCmdIconBelowText),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_ICON_CENTER_VER,ButtonWindow::onCmdIconCenterVer),
    
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_CENTER_X,ButtonWindow::onCmdJustCenterX),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_LEFT,ButtonWindow::onCmdJustLeft),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_RIGHT,ButtonWindow::onCmdJustRight),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_HOR_APART,ButtonWindow::onCmdJustHorApart),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_CENTER_Y,ButtonWindow::onCmdJustCenterY),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_TOP,ButtonWindow::onCmdJustTop),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_BOTTOM,ButtonWindow::onCmdJustBottom),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_JUST_VER_APART,ButtonWindow::onCmdJustVerApart),
  
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_TOOLBAR_STYLE,ButtonWindow::onCmdToolbarStyle),
  FXMAPFUNC(SEL_COMMAND,ButtonWindow::ID_QUIT,ButtonWindow::onCmdQuit),
  };


// ButtonApp implementation
FXIMPLEMENT(ButtonWindow,FXMainWindow,ButtonWindowMap,ARRAYNUMBER(ButtonWindowMap))

  
  
// Make some windows
ButtonWindow::ButtonWindow(FXApp* a):FXMainWindow(a,"Button Test",NULL,NULL,DECOR_ALL,100,100,0,0){
  
  // Tooltip
  new FXTooltip(getApp());
  
  // Status bar
  statusbar=new FXStatusbar(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER);
  
  // Controls on right
  controls=new FXVerticalFrame(this,LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH);

  // Separator
  new FXVerticalSeparator(this,LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y|SEPARATOR_GROOVE);
  
  // Contents
  contents=new FXHorizontalFrame(this,LAYOUT_SIDE_LEFT|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH,0,0,0,0,20,20,20,20);
  
  // The button
  button=new FXButton(contents,
                      "&This is a multi-line label on\na button to show off the full\ncapabilities of the button object\tIt also has a tooltip\n[which by the way can be multi-line also]\tAnd some helpful message for the status line.",
                      new FXGIFIcon(getApp(),bigpenguin),
                      NULL,0,
                      FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_X|LAYOUT_CENTER_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,
                      0,0,300,200);
    
  new FXCheckButton(controls,"Toolbar Style\tCool ``poppy'' style buttons",this,ID_TOOLBAR_STYLE);
  
  group1=new FXGroupBox(controls,"Horizontal Placement",GROUPBOX_TITLE_CENTER|FRAME_RIDGE);
  new FXRadioButton(group1,"Before Text",this,ID_ICON_BEFORE_TEXT);
  new FXRadioButton(group1,"After Text",this,ID_ICON_AFTER_TEXT);
  new FXRadioButton(group1,"Centered",this,ID_ICON_CENTER_HOR);
  
  group2=new FXGroupBox(controls,"Vertical Placement",GROUPBOX_TITLE_CENTER|FRAME_RIDGE);
  new FXRadioButton(group2,"Above Text",this,ID_ICON_ABOVE_TEXT);
  new FXRadioButton(group2,"Below Text",this,ID_ICON_BELOW_TEXT);
  new FXRadioButton(group2,"Centered",this,ID_ICON_CENTER_VER);
  
  group3=new FXGroupBox(controls,"Horizontal Justify",GROUPBOX_TITLE_CENTER|FRAME_RIDGE);
  new FXRadioButton(group3,"Center",this,ID_JUST_CENTER_X);
  new FXRadioButton(group3,"Left",this,ID_JUST_LEFT);
  new FXRadioButton(group3,"Right",this,ID_JUST_RIGHT);
  new FXRadioButton(group3,"Apart",this,ID_JUST_HOR_APART);
  
  group4=new FXGroupBox(controls,"Vertical Justify",GROUPBOX_TITLE_CENTER|FRAME_RIDGE);
  new FXRadioButton(group4,"Center",this,ID_JUST_CENTER_Y);
  new FXRadioButton(group4,"Top",this,ID_JUST_TOP);
  new FXRadioButton(group4,"Bottom",this,ID_JUST_BOTTOM);
  new FXRadioButton(group4,"Apart",this,ID_JUST_VER_APART);
  
  new FXButton(controls,"&Quit",NULL,this,ID_QUIT,FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X);
  }


// Start
void ButtonWindow::create(){
  FXMainWindow::create();
  show(PLACEMENT_SCREEN);
  }


long ButtonWindow::onCmdIconBeforeText(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style|=ICON_BEFORE_TEXT;
  style&=~ICON_AFTER_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdIconAfterText(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style|=ICON_AFTER_TEXT;
  style&=~ICON_BEFORE_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdIconCenterHor(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style&=~ICON_AFTER_TEXT;
  style&=~ICON_BEFORE_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdIconAboveText(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style|=ICON_ABOVE_TEXT;
  style&=~ICON_BELOW_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdIconBelowText(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style|=ICON_BELOW_TEXT;
  style&=~ICON_ABOVE_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdIconCenterVer(FXObject*,FXSelector,void*){
  FXuint style=button->getIconPosition();
  style&=~ICON_ABOVE_TEXT;
  style&=~ICON_BELOW_TEXT;
  button->setIconPosition(style);
  return 1;
  }

long ButtonWindow::onCmdJustCenterX(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_HZ_APART;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustLeft(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_HZ_APART;
  style|=JUSTIFY_LEFT;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustRight(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_HZ_APART;
  style|=JUSTIFY_RIGHT;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustHorApart(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style|=JUSTIFY_HZ_APART;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustCenterY(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_VT_APART;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustTop(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_VT_APART;
  style|=JUSTIFY_TOP;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustBottom(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style&=~JUSTIFY_VT_APART;
  style|=JUSTIFY_BOTTOM;
  button->setJustify(style);
  return 1;
  }

long ButtonWindow::onCmdJustVerApart(FXObject*,FXSelector,void*){
  FXuint style=button->getJustify();
  style|=JUSTIFY_VT_APART;
  button->setJustify(style);
  return 1;
  }


long ButtonWindow::onCmdToolbarStyle(FXObject*,FXSelector,void* ptr){
  FXuint style=button->getButtonStyle();
  if(ptr){
    style|=BUTTON_TOOLBAR;
    button->setFrameStyle(FRAME_RAISED);
    }
  else{
    style&=~BUTTON_TOOLBAR;
    button->setFrameStyle(FRAME_RAISED|FRAME_THICK);
    }
  button->setButtonStyle(style);
  return 1;
  }


long ButtonWindow::onCmdQuit(FXObject*,FXSelector,void*){
  getApp()->exit(0);
  return 1;
  }

/*******************************************************************************/


// Start the whole thing
int main(int argc,char *argv[]){

  // Make application
  FXApp application("Button","FoxTest");
  
  // Open display
  application.init(argc,argv);
  
  // Main window
  new ButtonWindow(&application);
  
  // Create app
  application.create();
  
  // Run
  return application.run();
  }