aboutsummaryrefslogtreecommitdiff
path: root/dw/style.hh
diff options
context:
space:
mode:
Diffstat (limited to 'dw/style.hh')
-rw-r--r--dw/style.hh191
1 files changed, 92 insertions, 99 deletions
diff --git a/dw/style.hh b/dw/style.hh
index a96a3471..81d47930 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -14,100 +14,100 @@ namespace core {
* \brief Anything related to Dillo %Widget styles is defined here.
*
* <h3>Overview</h3>
- *
+ *
* dw::core::style::Style provides some resources and attributes for
* drawing widgets, as well as for parts of a widget (e.g., dw::Textblock
* uses styles for its words). Creating a style is done by filling a
* dw::core::style::StyleAttrs with the attributes and calling
* dw::core::style::Style::create:
- *
+ *
* \code
* dw::core::style::Style styleAttrs;
* dw::core::style::Style *style;
* dw::core::Layout *layout;
- *
+ *
* // ...
- *
+ *
* styleAttrs.foo = bar;
* // etc.
* style = dw::core::style::Style::create (&styleAttrs, layout);
* // do something with style
* \endcode
- *
+ *
* After this, the attributes of a dw::core::style::Style should not be
* changed anymore, since styles are often shared between different
* widgets etc. (see below). Most times, you simply copy the attributes
* of another style (possible, since dw::core::style::Style is a sub
* class of dw::core::style::StyleAttrs), modify them and create a new
* style:
- *
+ *
* \code
* styleAttrs = *anotherStyle;
* styleAttrs.foo = baz;
* style = dw::core::style::Style::create (&styleAttrs, layout);
* \endcode
- *
+ *
* The dw::core::style::Font structure can be created by
* dw::core::style::Font::create, in a similar, with
* dw::core::style::FontAttrs, and colors by
* dw::core::style::Color::create, passing 0xrrggbb as an
* argument. Furthermore, there is dw::core::style::Tooltip, created by
* dw::core::style::Tooltip::create.
- *
+ *
* Notice that fonts, colors and tooltips are only intended to be used in
* conjunction with dw::core::style::Style.
- *
- *
+ *
+ *
* <h3>Naming</h3>
- *
+ *
* dw::core::style::Style will become important for CSS, each CSS
* attribute, which is supported by dillo, will refer to an attribute in
* dw::core::style::Style. For this reason, the attributes in
* dw::core::style::Style get the names from the CSS attributes, with
* "camelCase" instead of hythens (e.g. "background-color" becomes
* "backgroundColor").
- *
+ *
* However, dw::core::style::Style will be extended by some more
* attributes, which are not defined by CSS. To distinguish them, they
* get the prefix "x_", e.g. dw::core::style::Style::x_link.
- *
- *
+ *
+ *
* <h3>Lengths and Percentages</h3>
- *
+ *
* dw::core::style::Length is a simple data type for lengths and
* percentages:
- *
+ *
* <ul>
* <li> A length refers to an absolute measurement. It is used to
* represent the HTML type %Pixels; and the CSS type \<length\>.
- *
- * For CSS lenghts, there are two units: (i) pixels and absolute
+ *
+ * For CSS lengths, there are two units: (i) pixels and absolute
* units, which have to be converted to pixels (a pixel is, unlike
* in the CSS specification, treated as absolute unit), and (ii) the
* relative units "em" and "ex" (see below).
- *
+ *
* <li> A percentage refers to a value relative to another value. It is
* used for the HTML type %Length; (except %Pixels;), and the CSS
* type \<percentage\>.
- *
+ *
* <li> A relative length can be used in lists of HTML MultiLengths.
* </ul>
- *
+ *
* Since many values in CSS may be either lengths or percentages, a
* single type is very useful.
- *
+ *
* <h4>Useful Functions</h4>
- *
+ *
* Creating lengths:
- *
+ *
* <ul>
* <li> dw::core::style::createAbsLength
* <li> dw::core::style::createPerLength
* <li> dw::core::style::createRelLength
* </ul>
- *
+ *
* Examine lengths:
- *
+ *
* <ul>
* <li> dw::core::style::isAbsLength
* <li> dw::core::style::isPerLength
@@ -116,61 +116,61 @@ namespace core {
* <li> dw::core::style::perLengthVal
* <li> dw::core::style::relLengthVal
* </ul>
- *
- *
+ *
+ *
* <h3>Boxes</h3>
- *
+ *
* <h4>The CSS %Box Model</h4>
- *
+ *
* For borders, margins etc., the box model defined by CSS2 is
* used. dw::core::style::Style contains some members defining these
* attributes. A dw::core::Widget must use these values for any
* calculation of sizes. There are some helper functions (see
* dw/style.hh). A dw::core::style::Style box looks quite similar to a
* CSS box:
- *
+ *
* \image html dw-style-box-model.png
- *
+ *
* <h4>Background colors</h4>
- *
+ *
* The background color is stored in
* dw::core::style::Style::backgroundColor, which may be NULL (the
* background color of the parent widget is shining through).
- *
+ *
* For toplevel widgets, this color is set as the background color of the
* views (dw::core::View::setBgColor), for other widgets, a filled
* rectangle is drawn, covering the content and padding. (This is
* compliant with CSS2, the background color of the toplevel element
* covers the whole canvas.)
- *
+ *
* <h4>Drawing</h4>
- *
+ *
* The following methods may be useful:
- *
+ *
* <ul>
* <li> dw::core::Widget::drawWidgetBox for drawing the box of a widget
* (typically at the beginning of the implementation of
* dw::core::Widget::draw), and
- *
+ *
* <li> dw::core::Widget::drawBox, for drawing parts of a widget (e.g.
* dw::Textblock::Word, which has its own dw::Textblock::Word::style).
* </ul>
- *
- *
+ *
+ *
* <h3>Notes on Memory Management</h3>
- *
+ *
* Memory management is done by reference counting,
* dw::core::style::Style::create returns a pointer to
* dw::core::style::Style with an increased reference counter, so you
* should care about calling dw::core::style::Style::unref if it is not
* used anymore. You do \em not need to care about the reference counters
* of fonts and styles.
- *
+ *
* In detail:
- *
+ *
* <ul>
* <li> dw::core::style::Style::ref is called in
- *
+ *
* <ul>
* <li> dw::core::Widget::setStyle to assign a style to a widget,
* <li> dw::Textblock::addText, dw::Textblock::addWidget,
@@ -179,9 +179,9 @@ namespace core {
* to assign a style to a dw::Textblock::Word, and
* <li> by the HTML parser, when pushing an element on the stack.
* </ul>
- *
+ *
* <li> dw::core::style::Style::unref is called in
- *
+ *
* <ul>
* <li> dw::core::Widget::~Widget, dw::Textblock::~Textblock, by the
* HTML parser, when popping an element fom the stack, and
@@ -237,7 +237,9 @@ enum VAlignType {
VALIGN_MIDDLE,
VALIGN_BASELINE,
VALIGN_SUB,
- VALIGN_SUPER
+ VALIGN_SUPER,
+ VALIGN_TEXT_TOP,
+ VALIGN_TEXT_BOTTOM,
};
/**
@@ -247,15 +249,19 @@ enum DisplayType {
DISPLAY_BLOCK,
DISPLAY_INLINE,
DISPLAY_LIST_ITEM,
+ DISPLAY_NONE,
DISPLAY_TABLE,
DISPLAY_TABLE_ROW_GROUP,
DISPLAY_TABLE_HEADER_GROUP,
DISPLAY_TABLE_FOOTER_GROUP,
DISPLAY_TABLE_ROW,
- DISPLAY_TABLE_CELL,
- DISPLAY_LAST
+ DISPLAY_TABLE_CELL
};
+enum ListStylePosition {
+ LIST_STYLE_POSITION_INSIDE,
+ LIST_STYLE_POSITION_OUTSIDE
+};
enum ListStyleType {
LIST_STYLE_TYPE_DISC,
LIST_STYLE_TYPE_CIRCLE,
@@ -297,7 +303,9 @@ enum TextDecoration {
enum WhiteSpace {
WHITE_SPACE_NORMAL,
WHITE_SPACE_PRE,
- WHITE_SPACE_NOWRAP
+ WHITE_SPACE_NOWRAP,
+ WHITE_SPACE_PRE_WRAP,
+ WHITE_SPACE_PRE_LINE,
};
enum FloatType {
@@ -331,15 +339,15 @@ enum ClearType {
* This is an implementation detail, use one of the following functions:
*
* Creating lengths:
- *
+ *
* <ul>
* <li> dw::core::style::createAbsLength
* <li> dw::core::style::createPerLength
* <li> dw::core::style::createRelLength
* </ul>
- *
+ *
* Examine lengths:
- *
+ *
* <ul>
* <li> dw::core::style::isAbsLength
* <li> dw::core::style::isPerLength
@@ -349,7 +357,7 @@ enum ClearType {
* <li> dw::core::style::relLengthVal
* </ul>
*
- * "auto" lenghths are represented as dw::core::style::LENGTH_AUTO.
+ * "auto" lengths are represented as dw::core::style::LENGTH_AUTO.
*/
typedef int Length;
@@ -358,11 +366,11 @@ inline Length createAbsLength(int n) { return (n << 2) | 1; }
/** \brief Returns a percentage, \em v is relative to 1, not to 100. */
inline Length createPerLength(double v) {
- return (int)(v * (1 << 18)) & ~3 | 2; }
+ return ((int)(v * (1 << 18)) & ~3) | 2; }
/** \brief Returns a relative length. */
inline Length createRelLength(double v) {
- return (int)(v * (1 << 18)) & ~3 | 3; }
+ return ((int)(v * (1 << 18)) & ~3) | 3; }
/** \brief Returns true if \em l is an absolute length. */
inline bool isAbsLength(Length l) { return (l & 3) == 1; }
@@ -418,7 +426,7 @@ class Tooltip;
/**
* \sa dw::core::style
*/
-class StyleAttrs : public object::Object
+class StyleAttrs : public lout::object::Object
{
public:
Font *font;
@@ -433,8 +441,8 @@ public:
FloatType vloat; /* "float" is a keyword. */
ClearType clear;
- int hBorderSpacing, vBorderSpacing;
- Length width, height;
+ int hBorderSpacing, vBorderSpacing, wordSpacing;
+ Length width, height, lineHeight;
Box margin, borderWidth, padding;
struct { Color *top, *right, *bottom, *left; } borderColor;
@@ -442,13 +450,14 @@ public:
DisplayType display;
WhiteSpace whiteSpace;
+ ListStylePosition listStylePosition;
ListStyleType listStyleType;
Cursor cursor;
int x_link;
int x_img;
Tooltip *x_tooltip;
-
+
void initValues ();
void resetValues ();
@@ -482,7 +491,7 @@ public:
inline bool hasBackground () { return backgroundColor != NULL; }
- bool equals (object::Object *other);
+ bool equals (lout::object::Object *other);
int hashValue ();
};
@@ -495,7 +504,7 @@ class Style: public StyleAttrs
private:
static int totalRef;
int refCount;
- static container::typed::HashTable <StyleAttrs, Style> *styleTable;
+ static lout::container::typed::HashTable <StyleAttrs, Style> *styleTable;
Style (StyleAttrs *attrs);
@@ -518,17 +527,17 @@ public:
}
inline void ref () { refCount++; }
- inline void unref () { if(--refCount == 0) delete this; }
+ inline void unref () { if (--refCount == 0) delete this; }
};
/**
* \sa dw::core::style
*/
-class TooltipAttrs: public object::String
+class TooltipAttrs: public lout::object::String
{
public:
- TooltipAttrs(const char *text): object::String(text) { }
+ TooltipAttrs(const char *text): lout::object::String(text) { }
};
/**
@@ -539,34 +548,34 @@ class Tooltip: public TooltipAttrs
private:
int refCount;
+protected:
Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; }
public:
- inline Tooltip *create (Layout *layout, const char *text)
- { return new Tooltip (text); }
-
+ static Tooltip *create (dw::core::Layout *layout, const char *text);
inline void ref () { refCount++; }
inline void unref ()
- { if(--refCount == 0) delete this; }
+ { if (--refCount == 0) delete this; }
- inline void onEnter () { }
- inline void onLeave () { }
- inline void onMotion () { }
+ inline virtual void onEnter () { }
+ inline virtual void onLeave () { }
+ inline virtual void onMotion () { }
};
/**
* \sa dw::core::style
*/
-class FontAttrs: public object::Object
+class FontAttrs: public lout::object::Object
{
public:
const char *name;
int size;
int weight;
+ int letterSpacing;
FontStyle style;
- bool equals(object::Object *other);
+ bool equals(lout::object::Object *other);
int hashValue();
};
@@ -593,37 +602,30 @@ public:
int xHeight;
static Font *create (Layout *layout, FontAttrs *attrs);
- static Font *createFromList (Layout *layout, FontAttrs *attrs,
- char *defaultFamily);
+ static bool exists (Layout *layout, const char *name);
inline void ref () { refCount++; }
- inline void unref () { if(--refCount == 0) delete this; }
+ inline void unref () { if (--refCount == 0) delete this; }
};
/**
* \sa dw::core::style
*/
-class ColorAttrs: public object::Object
+class ColorAttrs: public lout::object::Object
{
-public:
- enum Type { TYPE_SIMPLE, TYPE_SHADED };
-
protected:
int color;
- Type type;
public:
- inline ColorAttrs(int color, Type type)
+ inline ColorAttrs(int color)
{
this->color = color;
- this->type = type;
}
inline int getColor () { return color; }
- inline Type getType () { return type; }
- bool equals(object::Object *other);
+ bool equals(lout::object::Object *other);
int hashValue();
};
@@ -636,12 +638,11 @@ class Color: public ColorAttrs
private:
int refCount;
- static Color *create (Layout *layout, int color, Type type);
void remove(dw::core::Layout *layout);
- int shadeColor (int color, int d);
+ int shadeColor (int color, int d);
protected:
- inline Color (int color, Type type): ColorAttrs (color, type) {
+ inline Color (int color): ColorAttrs (color) {
refCount = 0; }
virtual ~Color ();
@@ -653,19 +654,11 @@ protected:
int shadeColor (int color, Shading shading);
public:
- inline static Color *createSimple (Layout *layout, int color)
- {
- return create (layout, color, TYPE_SIMPLE);
- }
-
- inline static Color *createShaded (Layout *layout, int color)
- {
- return create (layout, color, TYPE_SHADED);
- }
+ static Color *create (Layout *layout, int color);
inline void ref () { refCount++; }
inline void unref ()
- { if(--refCount == 0) delete this; }
+ { if (--refCount == 0) delete this; }
};
void drawBorder (View *view, Rectangle *area,