Back to index

lightning-sunbird  0.9+nobinonly
nsFormControlHelper.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsFormControlHelper_h___
00039 #define nsFormControlHelper_h___
00040 
00041 #include "nsIFormControlFrame.h"
00042 #include "nsISupports.h"
00043 #include "nsIWidget.h"
00044 #include "nsLeafFrame.h"
00045 #include "nsCoord.h"
00046 #include "nsHTMLAtoms.h"
00047 #include "nsINameSpaceManager.h"
00048 
00049 class nsIView;
00050 class nsPresContext;
00051 class nsStyleCoord;
00052 class nsStyleContext;
00053 
00054 #define CSS_NOTSET -1
00055 #define ATTR_NOTSET -1
00056 
00057 #define NS_STRING_TRUE   NS_LITERAL_STRING("1")
00058 #define NS_STRING_FALSE  NS_LITERAL_STRING("0")
00059 
00063 enum nsMouseState {
00064   eMouseNone,
00065   eMouseEnter,
00066   eMouseExit,
00067   eMouseDown,
00068   eMouseUp
00069 };
00070 
00071 
00077 class nsFormControlHelper 
00078 {
00079 
00080 public:
00081   
00082   // returns the an addref'ed FontMetrics for the default font for the frame
00083   static nsresult GetFrameFontFM(nsIFrame* aFrame,
00084                                  nsIFontMetrics** aFontMet);
00085 
00086   // Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
00087   static void PlatformToDOMLineBreaks(nsString &aString);
00088 
00094   static PRBool GetDisabled(nsIContent* aContent) {
00095     return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled);
00096   };
00106   static nsresult GetName(nsIContent* aContent, nsAString* aResult);
00116   static PRInt32 GetType(nsIContent* aContent);
00126   static nsresult GetValueAttr(nsIContent* aContent, nsAString* aResult);
00132   static nsresult Reset(nsIFrame* aFrame, nsPresContext* aPresContext);
00133 
00139   static PRBool GetBool(const nsAString& aValue);
00140 
00147   static void  GetBoolString(const PRBool aValue, nsAString& aResult);
00148 
00149   static void GetRepChars(char& char1, char& char2) {
00150     char1 = 'W';
00151     char2 = 'w';
00152   }
00153 
00154   // wrap can be one of these three values.  
00155   typedef enum {
00156     eHTMLTextWrap_Off     = 1,    // the default
00157     eHTMLTextWrap_Hard    = 2,    // "hard" or "physical"
00158     eHTMLTextWrap_Soft    = 3     // "soft" or "virtual"
00159   } nsHTMLTextWrap;
00160 
00164   static nsresult GetWrapProperty(nsIContent * aContent, nsString &aOutValue);
00165 
00166   static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp);
00167 
00168 //
00169 //-------------------------------------------------------------------------------------
00170 //  Utility methods for managing checkboxes and radiobuttons
00171 //-------------------------------------------------------------------------------------
00172 //   
00180   //nsresult GetCurrentCheckState(PRBool* aState);
00181  
00189   nsresult SetCurrentCheckState(PRBool aState);
00190 
00198   nsresult GetDefaultCheckState(PRBool* aState);
00199 
00200 
00201 //
00202 //-------------------------------------------------------------------------------------
00203 // Utility methods for rendering Form Elements using GFX
00204 //-------------------------------------------------------------------------------------
00205 //
00206 // XXX: The following location for the paint code is TEMPORARY. 
00207 // It is being used to get printing working
00208 // under windows. Later it will be used to GFX-render the controls to the display. 
00209 // Expect this code to repackaged and moved to a new location in the future.
00210 
00214    enum nsArrowDirection {
00215     eArrowDirection_Left,
00216     eArrowDirection_Right,
00217     eArrowDirection_Up,
00218     eArrowDirection_Down
00219    };
00220 
00233    static void SetupPoints(PRUint32 aNumberOfPoints, nscoord* aPoints, 
00234      nsPoint* aPolygon, nscoord aScaleFactor, nscoord aX, nscoord aY,
00235      nscoord aCenterX, nscoord aCenterY);
00236 
00250   static void PaintLine(nsIRenderingContext& aRenderingContext, 
00251                  nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY, 
00252                  PRBool aHorz, nscoord aWidth, nscoord aOnePixel);
00253 
00261   static void PaintFixedSizeCheckMark(nsIRenderingContext& aRenderingContext, 
00262                                      float aPixelsToTwips);
00263                        
00273   static void PaintCheckMark(nsIRenderingContext& aRenderingContext,
00274                              float aPixelsToTwips, const nsRect & aRect);
00275 
00284   static void PaintFixedSizeCheckMarkBorder(nsIRenderingContext& aRenderingContext,
00285                          float aPixelsToTwips, const nsStyleColor& aBackgroundColor);
00286 
00301   static void PaintRectangularButton(nsPresContext* aPresContext,
00302                             nsIRenderingContext& aRenderingContext,
00303                             const nsRect& aDirtyRect, const nsRect& aRect, 
00304                             PRBool aShift, PRBool aShowFocus, PRBool aDisabled,
00305                                                                PRBool aDrawOutline,
00306                                                                nsStyleContext* aOutlineStyle,
00307                                                                nsStyleContext* aFocusStyle,
00308                             nsStyleContext* aStyleContext, nsString& aLabel, 
00309                             nsIFrame* aForFrame);
00310 
00311   static void StyleChangeReflow(nsPresContext* aPresContext,
00312                                 nsIFrame* aFrame);
00313 
00314 protected:
00315   nsFormControlHelper();
00316   virtual ~nsFormControlHelper();
00317 
00318 };
00319 
00320 #endif
00321