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

FXLabel.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                            L a b e l   W i d g e t                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXLabel.h,v 1.15 2002/01/18 22:42:53 jeroen Exp $                        *
00023 ********************************************************************************/
00024 #ifndef FXLABEL_H
00025 #define FXLABEL_H
00026 
00027 #ifndef FXFRAME_H
00028 #include "FXFrame.h"
00029 #endif
00030 
00031 
00032 
00033 /// Justification modes
00034 enum {
00035   JUSTIFY_NORMAL       = 0,           /// Default justification is centered text
00036   JUSTIFY_CENTER_X     = 0,           /// Text is centered horizontally
00037   JUSTIFY_LEFT         = 0x00008000,          /// Text is left-justified
00038   JUSTIFY_RIGHT        = 0x00010000,          /// Text is right-justified
00039   JUSTIFY_HZ_APART     = JUSTIFY_LEFT|JUSTIFY_RIGHT,  /// Combination of JUSTIFY_LEFT & JUSTIFY_RIGHT
00040   JUSTIFY_CENTER_Y     = 0,           /// Text is centered vertically
00041   JUSTIFY_TOP          = 0x00020000,          /// Text is aligned with label top
00042   JUSTIFY_BOTTOM       = 0x00040000,          /// Text is aligned with label bottom
00043   JUSTIFY_VT_APART     = JUSTIFY_TOP|JUSTIFY_BOTTOM   /// Combination of JUSTIFY_TOP & JUSTIFY_BOTTOM
00044   };
00045 
00046 
00047 
00048 /// Relationship options for icon-labels
00049 enum {
00050   ICON_UNDER_TEXT      = 0,           /// Icon appears under text
00051   ICON_AFTER_TEXT      = 0x00080000,          /// Icon appears after text (to its right)
00052   ICON_BEFORE_TEXT     = 0x00100000,          /// Icon appears before text (to its left)
00053   ICON_ABOVE_TEXT      = 0x00200000,          /// Icon appears above text
00054   ICON_BELOW_TEXT      = 0x00400000,          /// Icon appears below text
00055   TEXT_OVER_ICON       = ICON_UNDER_TEXT,       /// Same as ICON_UNDER_TEXT
00056   TEXT_AFTER_ICON      = ICON_BEFORE_TEXT,        /// Same as ICON_BEFORE_TEXT
00057   TEXT_BEFORE_ICON     = ICON_AFTER_TEXT,       /// Same as ICON_AFTER_TEXT
00058   TEXT_ABOVE_ICON      = ICON_BELOW_TEXT,       /// Same as ICON_BELOW_TEXT
00059   TEXT_BELOW_ICON      = ICON_ABOVE_TEXT        /// Same as ICON_ABOVE_TEXT
00060   };
00061 
00062 
00063 /// Normal way to show label
00064 enum {
00065   LABEL_NORMAL         = JUSTIFY_NORMAL|ICON_BEFORE_TEXT
00066   };
00067 
00068 
00069 class FXIcon;
00070 class FXFont;
00071 
00072 
00073 /**
00074 * A label widget can be used to place a text and/or icon for
00075 * explanation purposes.  The text label may have an optional tooltip
00076 * and/or help string.
00077 */
00078 class FXAPI FXLabel : public FXFrame {
00079   FXDECLARE(FXLabel)
00080 protected:
00081   FXString label;
00082   FXIcon*  icon;
00083   FXFont*  font;
00084   FXHotKey hotkey;
00085   FXint    hotoff;
00086   FXColor  textColor;
00087   FXString tip;
00088   FXString help;
00089 protected:
00090   FXLabel();
00091   FXint labelHeight(const FXString& text) const;
00092   FXint labelWidth(const FXString& text) const;
00093   void drawLabel(FXDCWindow& dc,const FXString& text,FXint hot,FXint tx,FXint ty,FXint tw,FXint th);
00094   void just_x(FXint& tx,FXint& ix,FXint tw,FXint iw);
00095   void just_y(FXint& ty,FXint& iy,FXint th,FXint ih);
00096 private:
00097   FXLabel(const FXLabel&);
00098   FXLabel &operator=(const FXLabel&);
00099 public:
00100   long onPaint(FXObject*,FXSelector,void*);
00101   long onHotKeyPress(FXObject*,FXSelector,void*);
00102   long onHotKeyRelease(FXObject*,FXSelector,void*);
00103   long onCmdGetStringValue(FXObject*,FXSelector,void*);
00104   long onCmdSetStringValue(FXObject*,FXSelector,void*);
00105   long onQueryHelp(FXObject*,FXSelector,void*);
00106   long onQueryTip(FXObject*,FXSelector,void*);
00107 public:
00108 
00109   /// Construct label with given text and icon
00110   FXLabel(FXComposite* p,const FXString& text,FXIcon* ic=0,FXuint opts=LABEL_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
00111 
00112   /// Create server-side resources
00113   virtual void create();
00114 
00115   /// Detach server-side resources
00116   virtual void detach();
00117 
00118   /// Enable the window
00119   virtual void enable();
00120 
00121   /// Disable the window
00122   virtual void disable();
00123 
00124   /// Return default width
00125   virtual FXint getDefaultWidth();
00126 
00127   /// Return default height
00128   virtual FXint getDefaultHeight();
00129 
00130   /// Set the text for this label
00131   void setText(const FXString& text);
00132 
00133   /// Get the text for this label
00134   FXString getText() const { return label; }
00135 
00136   /// Set the icon for this label
00137   void setIcon(FXIcon* ic);
00138 
00139   /// Get the icon for this label
00140   FXIcon* getIcon() const { return icon; }
00141 
00142   /// Set the text font
00143   void setFont(FXFont *fnt);
00144 
00145   /// Get the text font
00146   FXFont* getFont() const { return font; }
00147 
00148   /// Get the current text color
00149   FXColor getTextColor() const { return textColor; }
00150 
00151   /// Set the current text color
00152   void setTextColor(FXColor clr);
00153 
00154   /// Set the current text-justification mode.
00155   void setJustify(FXuint mode);
00156 
00157   /// Get the current text-justification mode.
00158   FXuint getJustify() const;
00159 
00160   /// Set the current icon position
00161   void setIconPosition(FXuint mode);
00162 
00163   /// Get the current icon position
00164   FXuint getIconPosition() const;
00165 
00166   /// Set the status line help text for this label
00167   void setHelpText(const FXString& text);
00168 
00169   /// Get the status line help text for this label
00170   FXString getHelpText() const { return help; }
00171 
00172   /// Set the tool tip message for this label
00173   void setTipText(const FXString&  text);
00174 
00175   /// Get the tool tip message for this label
00176   FXString getTipText() const { return tip; }
00177 
00178   /// Save label to a stream
00179   virtual void save(FXStream& store) const;
00180 
00181   /// Load label from a stream
00182   virtual void load(FXStream& store);
00183 
00184   /// Destructor
00185   virtual ~FXLabel();
00186   };
00187 
00188 
00189 
00190 #endif