Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXHeader.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * H e a d e r W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXHeader.h,v 1.70.2.2 2006/11/17 16:02:31 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXHEADER_H
25 #define FXHEADER_H
26 
27 #ifndef FXFRAME_H
28 #include "FXFrame.h"
29 #endif
30 
31 namespace FX {
32 
33 class FXIcon;
34 class FXFont;
35 class FXHeader;
36 
37 
38 /// Header style options
39 enum {
40  HEADER_BUTTON = 0x00008000, /// Button style can be clicked
41  HEADER_HORIZONTAL = 0, /// Horizontal header control (default)
42  HEADER_VERTICAL = 0x00010000, /// Vertical header control
43  HEADER_TRACKING = 0x00020000, /// Tracks continuously while moving
44  HEADER_RESIZE = 0x00040000, /// Allow resizing sections
46  };
47 
48 
49 /// Header item
50 class FXAPI FXHeaderItem : public FXObject {
52  friend class FXHeader;
53 protected:
54  FXString label; // Text of item
55  FXIcon *icon; // Icon of item
56  void *data; // Item user data pointer
57  FXint size; // Item size
58  FXint pos; // Item position
59  FXuint state; // Item state flags
60 private:
61  FXHeaderItem(const FXHeaderItem&);
62  FXHeaderItem& operator=(const FXHeaderItem&);
63 protected:
65  virtual void draw(const FXHeader* header,FXDC& dc,FXint x,FXint y,FXint w,FXint h);
66 public:
67  enum{
68  ARROW_NONE = 0, /// No arrow
69  ARROW_UP = 1, /// Arrow pointing up
70  ARROW_DOWN = 2, /// Arrow pointing down
71  PRESSED = 4, /// Pressed down
72  RIGHT = 8, /// Align on right
73  LEFT = 16, /// Align on left
74  CENTER_X = 0, /// Aling centered horizontally (default)
75  TOP = 32, /// Align on top
76  BOTTOM = 64, /// Align on bottom
77  CENTER_Y = 0, /// Aling centered vertically (default)
78  BEFORE = 128, /// Icon before the text
79  AFTER = 256, /// Icon after the text
80  ABOVE = 512, /// Icon above the text
81  BELOW = 1024 /// Icon below the text
82  };
83 public:
84 
85  /// Construct new item with given text, icon, size, and user-data
86  FXHeaderItem(const FXString& text,FXIcon* ic=NULL,FXint s=0,void* ptr=NULL):label(text),icon(ic),data(ptr),size(s),pos(0),state(LEFT|BEFORE){}
87 
88  /// Change item's text label
89  virtual void setText(const FXString& txt);
90 
91  /// Return item's text label
92  const FXString& getText() const { return label; }
93 
94  /// Change item's icon
95  virtual void setIcon(FXIcon* icn);
96 
97  /// Return item's icon
98  FXIcon* getIcon() const { return icon; }
99 
100  /// Change item's user data
101  void setData(void* ptr){ data=ptr; }
103  /// Get item's user data
104  void* getData() const { return data; }
106  /// Change size
107  void setSize(FXint s){ size=s; }
109  /// Obtain current size
110  FXint getSize() const { return size; }
112  /// Change position
113  void setPos(FXint p){ pos=p; }
114 
115  /// Obtain current position
116  FXint getPos() const { return pos; }
117 
118  /// Change sort direction (FALSE, TRUE, MAYBE)
119  void setArrowDir(FXbool dir=MAYBE);
120 
121  /// Return sort direction (FALSE, TRUE, MAYBE)
122  FXbool getArrowDir() const;
124  /// Change content justification
125  void setJustify(FXuint justify=LEFT|CENTER_Y);
126 
127  /// Return content justification
128  FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); }
130  /// Change icon position
131  void setIconPosition(FXuint mode=BEFORE);
132 
133  /// Return icon position
134  FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); }
136  /// Change state to pressed
137  void setPressed(FXbool pressed);
138 
139  /// Return pressed state
140  FXbool isPressed() const { return (state&PRESSED)!=0; }
141 
142  /// Return the item's content width in the header
143  virtual FXint getWidth(const FXHeader* header) const;
144 
145  /// Return the item's content height in the header
146  virtual FXint getHeight(const FXHeader* header) const;
147 
148  /// Create server-side resources
149  virtual void create();
150 
151  /// Detach from server-side resources
152  virtual void detach();
153 
154  /// Destroy server-side resources
155  virtual void destroy();
156 
157  /// Stream serialization
158  virtual void save(FXStream& store) const;
159  virtual void load(FXStream& store);
160 
161  /// Destructor
162  virtual ~FXHeaderItem(){}
163  };
164 
165 
166 /// List of FXHeaderItem's
167 typedef FXObjectListOf<FXHeaderItem> FXHeaderItemList;
168 
169 
170 /**
171 * Header control may be placed over a table or list to provide a resizable
172 * captions above a number of columns.
173 * Each caption comprises a label and an optional icon; in addition, an arrow
174 * may be shown to indicate whether the items in that column are sorted, and
175 * if so, whether they are sorted in increasing or decreasing order.
176 * Each caption can be interactively resized. During the resizing, if the
177 * HEADER_TRACKING was specified, the header control sends a SEL_CHANGED message
178 * to its target, with the message data set to the caption number being resized,
179 * of the type FXint.
180 * If the HEADER_TRACKING was not specified the SEL_CHANGED message is sent at
181 * the end of the resizing operation.
182 * Clicking on a caption causes a message of type SEL_COMMAND to be sent to the
183 * target, with the message data set to the caption number being clicked.
184 * A single click on a split causes a message of type SEL_CLICKED to be sent to the
185 * target; a typical response to this message would be to adjust the size of
186 * the split to fit the contents displayed underneath it.
187 * The contents may be scrolled by calling setPosition().
188 */
189 class FXAPI FXHeader : public FXFrame {
191 protected:
192  FXHeaderItemList items; // Item list
193  FXColor textColor; // Text color
194  FXFont *font; // Text font
195  FXString help; // Help text
196  FXint pos; // Scroll position
197  FXint active; // Active button
198  FXint activepos; // Position of active item
199  FXint activesize; // Size of active item
200  FXint offset; // Offset where split grabbed
201 protected:
202  FXHeader();
203  void drawSplit(FXint pos);
204  virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr);
205 private:
206  FXHeader(const FXHeader&);
207  FXHeader &operator=(const FXHeader&);
208 public:
209  long onPaint(FXObject*,FXSelector,void*);
210  long onLeftBtnPress(FXObject*,FXSelector,void*);
211  long onLeftBtnRelease(FXObject*,FXSelector,void*);
212  long onUngrabbed(FXObject*,FXSelector,void*);
213  long onMotion(FXObject*,FXSelector,void*);
214  long onTipTimer(FXObject*,FXSelector,void*);
215  long onQueryTip(FXObject*,FXSelector,void*);
216  long onQueryHelp(FXObject*,FXSelector,void*);
217 public:
218 
219  /// Construct new header control
221 
222  /// Create server-side resources
223  virtual void create();
224 
225  /// Detach server-side resources
226  virtual void detach();
227 
228  /// Perform layout
229  virtual void layout();
230 
231  /// Return number of items
232  FXint getNumItems() const { return items.no(); }
233 
234  /// Return total size of all items
235  FXint getTotalSize() const;
236 
237  /// Return default width
238  virtual FXint getDefaultWidth();
239 
240  /// Return default height
241  virtual FXint getDefaultHeight();
242 
243  /// Set the current position
244  void setPosition(FXint pos);
245 
246  /// Return the current position
247  FXint getPosition() const { return pos; }
248 
249  /**
250  * Return item-index given coordinate offset, or -1 if coordinate
251  * is before first item in header, or nitems if coordinate is after
252  * last item in header.
253  */
254  FXint getItemAt(FXint coord) const;
255 
256  /// Return item at given index
257  FXHeaderItem *getItem(FXint index) const;
258 
259  /// Replace the item with a [possibly subclassed] item
260  FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
261 
262  /// Replace items text, icon, and user-data pointer
263  FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
264 
265  /// Fill header by appending items from array of strings
266  FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
267 
268  /// Fill header by appending items from newline separated strings
269  FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
270 
271  /// Insert a new [possibly subclassed] item at the give index
272  FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
273 
274  /// Insert item at index with given text, icon, and user-data pointer
275  FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
276 
277  /// Append a [possibly subclassed] item to the list
278  FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE);
279 
280  /// Append new item with given text and optional icon, and user-data pointer
281  FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
282 
283  /// Prepend a [possibly subclassed] item to the list
284  FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE);
285 
286  /// Prepend new item with given text and optional icon, and user-data pointer
287  FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
288 
289  /// Extract item from list
290  FXHeaderItem* extractItem(FXint index,FXbool notify=FALSE);
291 
292  /// Remove item at index
293  void removeItem(FXint index,FXbool notify=FALSE);
294 
295  /// Remove all items
296  void clearItems(FXbool notify=FALSE);
297 
298  /// Change text label for item at index
299  void setItemText(FXint index,const FXString& text);
300 
301  /// Get text of item at index
302  FXString getItemText(FXint index) const;
303 
304  /// Change icon of item at index
305  void setItemIcon(FXint index,FXIcon* icon);
306 
307  /// Return icon of item at index
308  FXIcon* getItemIcon(FXint index) const;
309 
310  /// Change size of item at index
311  void setItemSize(FXint index,FXint size);
312 
313  /// Return size of item at index
314  FXint getItemSize(FXint index) const;
315 
316  /// Compute offset from the left side of item at index
317  FXint getItemOffset(FXint index) const;
318 
319  /// Change data of item at index
320  void setItemData(FXint index,void* ptr);
321 
322  /// Return data of item at index
323  void* getItemData(FXint index) const;
324 
325  /// Change sort direction (FALSE, TRUE, MAYBE)
326  void setArrowDir(FXint index,FXbool dir=MAYBE);
327 
328  /// Return sort direction (FALSE, TRUE, MAYBE)
329  FXbool getArrowDir(FXint index) const;
330 
331  /**
332  * Change item justification. Horizontal justification is controlled by passing
333  * FXHeaderItem::RIGHT, FXHeaderItem::LEFT, or FXHeaderItem::CENTER_X.
334  * Vertical justification is controlled by FXHeaderItem::TOP, FXHeaderItem::BOTTOM,
335  * or FXHeaderItem::CENTER_Y.
336  * The default is a combination of FXHeaderItem::LEFT and FXHeaderItem::CENTER_Y.
337  */
338  void setItemJustify(FXint index,FXuint justify);
339 
340  /// Return item justification
341  FXuint getItemJustify(FXint index) const;
342 
343  /**
344  * Change relative position of icon and text of item.
345  * Passing FXHeaderItem::BEFORE or FXHeaderItem::AFTER places the icon
346  * before or after the text, and passing FXHeaderItem::ABOVE or
347  * FXHeaderItem::BELOW places it above or below the text, respectively.
348  * The default of FXHeaderItem::BEFORE places the icon in front of the text.
349  */
350  void setItemIconPosition(FXint index,FXuint mode);
351 
352  /// Return relative icon and text position
353  FXuint getItemIconPosition(FXint index) const;
354 
355  /// Changed button item's pressed state
356  void setItemPressed(FXint index,FXbool pressed=TRUE);
357 
358  /// Return TRUE if button item is pressed in
359  FXbool isItemPressed(FXint index) const;
360 
361  /// Scroll to make given item visible
362  void makeItemVisible(FXint index);
363 
364  /// Repaint header at index
365  void updateItem(FXint index) const;
366 
367  /// Change text font
368  void setFont(FXFont* fnt);
369 
370  /// return text font
371  FXFont* getFont() const { return font; }
372 
373  /// Return text color
374  FXColor getTextColor() const { return textColor; }
375 
376  /// Change text color
377  void setTextColor(FXColor clr);
378 
379  /// Set header style options
380  void setHeaderStyle(FXuint style);
381 
382  /// Get header style options
383  FXuint getHeaderStyle() const;
384 
385  /// Set the status line help text for this header
386  void setHelpText(const FXString& text);
387 
388  /// Get the status line help text for this header
389  const FXString& getHelpText() const { return help; }
390 
391  /// Save header to a stream
392  virtual void save(FXStream& store) const;
393 
394  /// Load header from a stream
395  virtual void load(FXStream& store);
396 
397  /// Destructor
398  virtual ~FXHeader();
399  };
400 
401 }
402 
403 #endif
Allow resizing sections.
Definition: FXHeader.h:47
Definition: FXHeader.h:48
char FXchar
Definition: fxdefs.h:380
Arrow points down.
Definition: FXArrowButton.h:41
Horizontal header control (default)
Definition: FXHeader.h:44
#define TRUE
Definition: fxdefs.h:32
FXint no() const
Return number of objects.
Definition: FXObjectList.h:53
The Frame widget provides borders around some contents.
Definition: FXFrame.h:73
unsigned int FXuint
Definition: fxdefs.h:389
Definition: FXFrame.h:56
FXuint FXSelector
Association key.
Definition: FXObject.h:53
Vertical header control.
Definition: FXHeader.h:45
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:386
Base composite.
Definition: FXComposite.h:35
Header control may be placed over a table or list to provide a resizable captions above a number of c...
Definition: FXHeader.h:187
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:447
Arrow points up.
Definition: FXArrowButton.h:40
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
Abstract Device Context.
Definition: FXDC.h:191
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
Button style can be clicked.
Definition: FXHeader.h:43
Header item.
Definition: FXHeader.h:58
#define FALSE
Definition: fxdefs.h:35
Regular raised/thick border.
Definition: FXWindow.h:82
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
No arrow.
Definition: FXArrowButton.h:39
FXObjectListOf< FXHeaderItem > FXHeaderItemList
List of FXHeaderItem's.
Definition: FXHeader.h:162
Font class.
Definition: FXFont.h:142
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Tracks continuously while moving.
Definition: FXHeader.h:46
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33
#define MAYBE
Definition: fxdefs.h:38

Copyright © 1997-2005 Jeroen van der Zijp