File: header.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 (247 lines) | stat: -rw-r--r-- 8,275 bytes parent folder | download
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
/********************************************************************************
*                                                                               *
*                          Test Header Controls                                 *
*                                                                               *
*********************************************************************************
* Copyright (C) 1997 by Jeroen van der Zijp.   All Rights Reserved.             *
*********************************************************************************
* $Id: header.cpp,v 1.16.4.1 2003/06/20 19:02:07 fox Exp $                       *
********************************************************************************/
#include "fx.h"
#include <stdio.h>
#include <stdlib.h>




/* Generated by reswrap from file minidoc.gif */
const unsigned char minidoc[]={
  0x47,0x49,0x46,0x38,0x37,0x61,0x10,0x00,0x10,0x00,0xf2,0x00,0x00,0xbf,0xbf,0xbf,
  0x80,0x80,0x80,0xff,0xff,0xff,0xc0,0xc0,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x03,
  0x36,0x08,0x10,0xdc,0xae,0x70,0x89,0x49,0xe7,0x08,0x51,0x56,0x3a,0x04,0x86,0xc1,
  0x46,0x11,0x24,0x01,0x8a,0xd5,0x60,0x2a,0x21,0x6a,0xad,0x9a,0xab,0x9e,0xae,0x30,
  0xb3,0xb5,0x0d,0xb7,0xf2,0x9e,0xdf,0x31,0x14,0x90,0x27,0xf4,0xd5,0x86,0x83,0xa4,
  0x72,0x09,0x2c,0x39,0x9f,0xa6,0x04,0x00,0x3b
  };



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


// Header Window
class HeaderWindow : public FXMainWindow {
  FXDECLARE(HeaderWindow)
protected:
  HeaderWindow(){}
public:
  long onQuit(FXObject*,FXSelector,void*);
  long onCmdAbout(FXObject*,FXSelector,void*);
  long onCmdHeader(FXObject*,FXSelector,void*);
  long onCmdHeaderButton(FXObject*,FXSelector,void*);
  long onCmdContinuous(FXObject*,FXSelector,void*);
public:
  enum {
    ID_ABOUT=FXMainWindow::ID_LAST,
    ID_HEADER,
    ID_TRACKING,
    ID_LAST
    };
protected:
  FXMenubar*         menubar;
  FXMenuPane*        filemenu;
  FXMenuPane*        helpmenu;
  FXVerticalFrame*   contents;
  FXHorizontalFrame* panes;
  FXHeader*          header1;
  FXHeader*          header2;
  FXList*            list[4];
  FXGIFIcon*         doc;
  FXCheckButton*     check;
public:
  HeaderWindow(FXApp* a);
  virtual void create();
  virtual ~HeaderWindow();
  };



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

// Map
FXDEFMAP(HeaderWindow) HeaderWindowMap[]={
  FXMAPFUNC(SEL_COMMAND,  HeaderWindow::ID_ABOUT,      HeaderWindow::onCmdAbout),
  FXMAPFUNC(SEL_CHANGED,  HeaderWindow::ID_HEADER,     HeaderWindow::onCmdHeader),
  FXMAPFUNC(SEL_COMMAND,  HeaderWindow::ID_HEADER,     HeaderWindow::onCmdHeaderButton),
  FXMAPFUNC(SEL_COMMAND,  HeaderWindow::ID_TRACKING,   HeaderWindow::onCmdContinuous),
  };


// Object implementation
FXIMPLEMENT(HeaderWindow,FXMainWindow,HeaderWindowMap,ARRAYNUMBER(HeaderWindowMap))


// Make some windows
HeaderWindow::HeaderWindow(FXApp* a):FXMainWindow(a,"Header Control Test",NULL,NULL,DECOR_ALL,0,0,800,600){

  // Make menu bar
  menubar=new FXMenubar(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X);

  new FXStatusbar(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);

  filemenu=new FXMenuPane(this);
  new FXMenuCommand(filemenu,"&Quit\tCtl-Q\tQuit the application",NULL,getApp(),FXApp::ID_QUIT);
  new FXMenuTitle(menubar,"&File",NULL,filemenu);
  helpmenu=new FXMenuPane(this);
  new FXMenuCommand(helpmenu,"&About Header...",NULL,this,ID_ABOUT,0);
  new FXMenuTitle(menubar,"&Help",NULL,helpmenu,LAYOUT_RIGHT);

  // Make Main Window contents
  contents=new FXVerticalFrame(this,FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);

  // Make header control
  header1=new FXHeader(contents,this,ID_HEADER,HEADER_BUTTON|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X);

  // Document icon
  doc=new FXGIFIcon(getApp(),minidoc);

  header1->appendItem("Name",doc,150);
  header1->appendItem("Type",NULL,120);
  header1->appendItem("Layout Option",doc,230);
  header1->appendItem("Attributes",NULL,80);

  // Below header
  panes=new FXHorizontalFrame(contents,FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);

  // Make 4 lists
  list[0]=new FXList(panes,1,NULL,0,LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LIST_BROWSESELECT,0,0,150,0);
  list[1]=new FXList(panes,1,NULL,0,LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LIST_SINGLESELECT,0,0,120,0);
  list[2]=new FXList(panes,1,NULL,0,LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LIST_MULTIPLESELECT,0,0,230,0);
  list[3]=new FXList(panes,1,NULL,0,LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LIST_EXTENDEDSELECT,0,0,80,0);
  list[0]->setBackColor(FXRGB(255,240,240));
  list[1]->setBackColor(FXRGB(240,255,240));
  list[2]->setBackColor(FXRGB(240,240,255));
  list[3]->setBackColor(FXRGB(255,255,240));

  // Add some contents
  list[0]->appendItem("Jeroen van der Zijp");
  list[0]->appendItem("Lyle Johnson");
  list[0]->appendItem("Freddy Golos");
  list[0]->appendItem("Charles Warren");
  list[0]->appendItem("Jonathan Bush");
  list[0]->appendItem("Guoqing Tian");

  list[1]->appendItem("Incorrigible Hacker");
  list[1]->appendItem("Windows Hacker");
  list[1]->appendItem("Russian Hacker");
  list[1]->appendItem("Shutter Widget");
  list[1]->appendItem("Progress Bar");
  list[1]->appendItem("Dial Widget");

  list[2]->appendItem("LAYOUT_FILL_X|LAYOUT_FILL_Y");
  list[2]->appendItem("LAYOUT_FILL_Y");
  list[2]->appendItem("LAYOUT_NORMAL");
  list[2]->appendItem("LAYOUT_NORMAL");
  list[2]->appendItem("LAYOUT_NORMAL");
  list[2]->appendItem("LAYOUT_NORMAL");

  list[3]->appendItem("A");
  list[3]->appendItem("B");
  list[3]->appendItem("C");
  list[3]->appendItem("D");
  list[3]->appendItem("E");
  list[3]->appendItem("F");

  header2=new FXHeader(panes,NULL,0,HEADER_VERTICAL|HEADER_BUTTON|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y);
  header2->appendItem("Example",NULL,30);
  header2->appendItem("Of",NULL,30);
  header2->appendItem("Vertical",NULL,30);
  header2->appendItem("Header",NULL,30);

  // Group box with some controls
  FXGroupBox *groupie=new FXGroupBox(panes,"Controls",GROUPBOX_TITLE_CENTER|LAYOUT_FILL_X|LAYOUT_FILL_Y);
  check=new FXCheckButton(groupie,"Continuous Tracking\tContinuous\tTrack Header continuously",this,ID_TRACKING,ICON_BEFORE_TEXT|LAYOUT_SIDE_TOP);

  // Whip out a tooltip control, jeez, that's hard
  new FXTooltip(getApp());
  }


HeaderWindow::~HeaderWindow(){
  delete filemenu;
  delete helpmenu;
  }


// About
long HeaderWindow::onCmdAbout(FXObject*,FXSelector,void*){
  FXMessageBox::information(this,MBOX_OK,"About Header",
    "An example of how to work with the header control\n\n\nAnd some attributes of the developers!"
    );
  return 1;
  }


// Changed the header control
long HeaderWindow::onCmdHeader(FXObject*,FXSelector,void* ptr){
  FXint which=(FXint)(FXival)ptr;
  FXASSERT(0<=which && which<4);
  FXTRACE((1,"Width of item %d = %d\n",which,header1->getItemSize(which)));
  list[which]->setWidth(header1->getItemSize(which));
  return 1;
  }


// Clicked a header button:- we highlight all in the list
long HeaderWindow::onCmdHeaderButton(FXObject*,FXSelector,void* ptr){
  FXint which=(FXint)(FXival)ptr;
  FXint i;
  FXASSERT(0<=which && which<4);
  for(i=0; i<list[which]->getNumItems(); i++){
    list[which]->selectItem(i);
    }
  return 1;
  }


// Tracking continuously
long HeaderWindow::onCmdContinuous(FXObject*,FXSelector,void*){
  header1->setHeaderStyle(HEADER_TRACKING^header1->getHeaderStyle());
  header2->setHeaderStyle(HEADER_TRACKING^header2->getHeaderStyle());
  return 1;
  }


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


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


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

  // Make application
  FXApp application("Header","FoxTest");

  // Initialize application and open display;
  // FOX will parse some parameters, and leave the remaining
  // ones for the main application.
  application.init(argc,argv);

  // Make window
  new HeaderWindow(&application);

  // Create all the windows.
  application.create();

  // Run the application
  return application.run();
  }