ucss.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  ucss.hpp
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2005 Eric Lecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 *
00008 * ***********************************************************************
00009 * COPYRIGHT NOTICE :
00010 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
00011 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00012 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
00013 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
00014 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016 * ***********************************************************************
00017 * ==================================================== [(c)Elc] ======= *
00018 * ==================================================== ======== ======= */
00019 
00020 #ifndef _ucss_hpp_
00021 #define _ucss_hpp_
00022 //pragma ident  "@(#)ucss.hpp   ubit:05.05.00"
00023 #include <map>
00024 #include <ubit/ubit.hpp>
00025 #include <ubit/ustyle.hpp>
00026 #include <ubit/ustyleparser.hpp>
00027 #include <ubit/udom.hpp>
00028 namespace ubit {
00029 
00030 /* ==================================================== ======== ======= */
00034 class UCssParser : public UStyleParser {
00035 public:
00036   int parse(const UStr& buffer, class UXmlDoc*);
00037   int parseAttr(const UStr& buffer, class UXmlDoc*, UProps*);
00038 };
00039 
00040 /* ==================================================== ======== ======= */
00044 class UStyleProps {
00045 public:
00046   typedef UProp* (*PropCreator)(UXmlDoc*, const UStr&);
00047   ~UStyleProps();
00048   
00049   PropCreator findProp(const UStr& prop_name);
00050   void defProp(const char* prop_name, PropCreator);
00051   void defProp(const UStr& prop_name, PropCreator);
00052 
00053   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00054   // useful fcts.
00055 
00056   static bool isEq(const UStr& s1, const char* s2);
00057   static bool isEq(const UStr* s1, const char* s2);
00058   static bool parseUrl(const UStr&, UStr& url, UStr& remain);
00059   static bool parseNum(const UStr&, double& val, UStr& unit);
00060   static bool parseNum(const UStr*, double& val, UStr& unit);
00061   static int  roundNum(double x);
00062   static void setFontFamily(UFont&, const UStr& _val);
00063   
00064 private:
00065   struct Comp {
00066     bool operator()(const UStr*s1, const UStr*s2) const {return s1->compare(*s2)<0;}
00067   };
00068   typedef std::map<const UStr*, PropCreator, Comp> PropMap;
00069   PropMap prop_map;
00070 };
00071 
00072 /* ==================================================== ======== ======= */
00076 class UCssProps : public UStyleProps {
00077 public:
00078   UCssProps();
00079 
00080   static UProp* create_font_family(UXmlDoc*, const UStr& v);
00081   static UProp* create_font_size(UXmlDoc*, const UStr& v);
00082   static UProp* create_font_weight(UXmlDoc*, const UStr& v);
00083   static UProp* create_font_style(UXmlDoc*, const UStr& v);
00084 
00085   static UProp* create_color(UXmlDoc*, const UStr& v);
00086   static UProp* create_background_color(UXmlDoc*, const UStr& v);
00087   static UProp* create_background_image(UXmlDoc*, const UStr& v);
00088   static UProp* create_background(UXmlDoc*, const UStr& v);
00089 
00090   static UProp* create_width(UXmlDoc*, const UStr& v);
00091   static UProp* create_height(UXmlDoc*, const UStr& v);
00092   static UProp* create_text_align(UXmlDoc*, const UStr& v);
00093   static UProp* create_vertical_align(UXmlDoc*, const UStr& v);
00094 
00095   static UProp* create_margin_top(UXmlDoc*, const UStr& v);
00096   static UProp* create_margin_bottom(UXmlDoc*, const UStr& v);
00097   static UProp* create_margin_left(UXmlDoc*, const UStr& v);
00098   static UProp* create_margin_right(UXmlDoc*, const UStr& v);
00099 
00100   static UProp* create_padding_top(UXmlDoc*, const UStr& v);
00101   static UProp* create_padding_bottom(UXmlDoc*, const UStr& v);
00102   static UProp* create_padding_left(UXmlDoc*, const UStr& v);
00103   static UProp* create_padding_right(UXmlDoc*, const UStr& v);
00104 
00105   static UProp* create_border(UXmlDoc*, const UStr& v);
00106 };
00107 
00108 /* ==================================================== ======== ======= */
00112 class UCssStyles {
00113 public:
00114   static UStyle* create_body_style();
00115   static UStyle* create_div_style();
00116   static UStyle* create_p_style();
00117 
00118   static UStyle* create_ul_style();
00119   static UStyle* create_ol_style();
00120   static UStyle* create_li_style();
00121 
00122   static UStyle* create_pre_style();
00123   static UStyle* create_blockquote_style();
00124   static UStyle* create_center_style();
00125     
00126   static UStyle* create_h1_style();
00127   static UStyle* create_h2_style();
00128   static UStyle* create_h3_style();
00129   static UStyle* create_h4_style();
00130   static UStyle* create_h5_style();
00131   static UStyle* create_h6_style();
00132 
00133   static UStyle* create_table_style();
00134   static UStyle* create_tr_style();
00135   static UStyle* create_td_style();
00136   static UStyle* create_th_style();
00137   
00138   static UStyle* create_span_style();
00139   static UStyle* create_b_style();
00140   static UStyle* create_i_style();
00141   static UStyle* create_em_style();
00142   static UStyle* create_u_style();
00143   static UStyle* create_font_style();
00144   
00145   static UStyle* create_a_style();
00146   static UStyle* create_img_style();
00147   static UStyle* create_br_style();
00148 };
00149 
00150 }
00151 #endif
00152 /* ==================================================== [TheEnd] ======= */
00153 
00154 
00155 

Generated on Mon Jan 29 00:20:37 2007 for Ubit by  doxygen 1.4.7