Dillo
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
dw
style.hh
Go to the documentation of this file.
1
#ifndef __DW_STYLE_HH__
2
#define __DW_STYLE_HH__
3
4
#include <stdint.h>
5
6
#ifndef __INCLUDED_FROM_DW_CORE_HH__
7
# error Do not include this file directly, use "core.hh" instead.
8
#endif
9
10
namespace
dw {
11
namespace
core {
12
193
namespace
style {
194
195
enum
Cursor
{
196
CURSOR_CROSSHAIR
,
197
CURSOR_DEFAULT
,
198
CURSOR_POINTER
,
199
CURSOR_MOVE
,
200
CURSOR_E_RESIZE
,
201
CURSOR_NE_RESIZE
,
202
CURSOR_NW_RESIZE
,
203
CURSOR_N_RESIZE
,
204
CURSOR_SE_RESIZE
,
205
CURSOR_SW_RESIZE
,
206
CURSOR_S_RESIZE
,
207
CURSOR_W_RESIZE
,
208
CURSOR_TEXT
,
209
CURSOR_WAIT
,
210
CURSOR_HELP
211
};
212
213
enum
BorderCollapse
{
214
BORDER_MODEL_SEPARATE
,
215
BORDER_MODEL_COLLAPSE
216
};
217
218
enum
BorderStyle
{
219
BORDER_NONE
,
220
BORDER_HIDDEN
,
221
BORDER_DOTTED
,
222
BORDER_DASHED
,
223
BORDER_SOLID
,
224
BORDER_DOUBLE
,
225
BORDER_GROOVE
,
226
BORDER_RIDGE
,
227
BORDER_INSET
,
228
BORDER_OUTSET
229
};
230
231
enum
TextAlignType
{
232
TEXT_ALIGN_LEFT
,
233
TEXT_ALIGN_RIGHT
,
234
TEXT_ALIGN_CENTER
,
235
TEXT_ALIGN_JUSTIFY
,
236
TEXT_ALIGN_STRING
237
};
238
239
enum
VAlignType
{
240
VALIGN_TOP
,
241
VALIGN_BOTTOM
,
242
VALIGN_MIDDLE
,
243
VALIGN_BASELINE
,
244
VALIGN_SUB
,
245
VALIGN_SUPER
,
246
VALIGN_TEXT_TOP
,
247
VALIGN_TEXT_BOTTOM
,
248
};
249
250
enum
TextTransform
{
251
TEXT_TRANSFORM_NONE
,
252
TEXT_TRANSFORM_CAPITALIZE
,
253
TEXT_TRANSFORM_UPPERCASE
,
254
TEXT_TRANSFORM_LOWERCASE
,
255
};
256
260
enum
DisplayType
{
261
DISPLAY_BLOCK
,
262
DISPLAY_INLINE
,
263
DISPLAY_INLINE_BLOCK
,
264
DISPLAY_LIST_ITEM
,
265
DISPLAY_NONE
,
266
DISPLAY_TABLE
,
267
DISPLAY_TABLE_ROW_GROUP
,
268
DISPLAY_TABLE_HEADER_GROUP
,
269
DISPLAY_TABLE_FOOTER_GROUP
,
270
DISPLAY_TABLE_ROW
,
271
DISPLAY_TABLE_CELL
272
};
273
274
enum
LineType
{
275
LINE_NORMAL
,
276
LINE_DOTTED
,
277
LINE_DASHED
278
};
279
280
enum
ListStylePosition
{
281
LIST_STYLE_POSITION_INSIDE
,
282
LIST_STYLE_POSITION_OUTSIDE
283
};
284
285
enum
ListStyleType
{
286
LIST_STYLE_TYPE_DISC
,
287
LIST_STYLE_TYPE_CIRCLE
,
288
LIST_STYLE_TYPE_SQUARE
,
289
LIST_STYLE_TYPE_DECIMAL
,
290
LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO
,
291
LIST_STYLE_TYPE_LOWER_ROMAN
,
292
LIST_STYLE_TYPE_UPPER_ROMAN
,
293
LIST_STYLE_TYPE_LOWER_GREEK
,
294
LIST_STYLE_TYPE_LOWER_ALPHA
,
295
LIST_STYLE_TYPE_LOWER_LATIN
,
296
LIST_STYLE_TYPE_UPPER_ALPHA
,
297
LIST_STYLE_TYPE_UPPER_LATIN
,
298
LIST_STYLE_TYPE_HEBREW
,
299
LIST_STYLE_TYPE_ARMENIAN
,
300
LIST_STYLE_TYPE_GEORGIAN
,
301
LIST_STYLE_TYPE_CJK_IDEOGRAPHIC
,
302
LIST_STYLE_TYPE_HIRAGANA
,
303
LIST_STYLE_TYPE_KATAKANA
,
304
LIST_STYLE_TYPE_HIRAGANA_IROHA
,
305
LIST_STYLE_TYPE_KATAKANA_IROHA
,
306
LIST_STYLE_TYPE_NONE
307
};
308
309
enum
FontStyle
{
310
FONT_STYLE_NORMAL
,
311
FONT_STYLE_ITALIC
,
312
FONT_STYLE_OBLIQUE
313
};
314
315
enum
FontVariant
{
316
FONT_VARIANT_NORMAL
,
317
FONT_VARIANT_SMALL_CAPS
318
};
319
320
enum
TextDecoration
{
321
TEXT_DECORATION_NONE
= 0,
322
TEXT_DECORATION_UNDERLINE
= 1 << 0,
323
TEXT_DECORATION_OVERLINE
= 1 << 1,
324
TEXT_DECORATION_LINE_THROUGH
= 1 << 2,
325
TEXT_DECORATION_BLINK
= 1 << 3
326
};
327
328
enum
WhiteSpace
{
329
WHITE_SPACE_NORMAL
,
330
WHITE_SPACE_PRE
,
331
WHITE_SPACE_NOWRAP
,
332
WHITE_SPACE_PRE_WRAP
,
333
WHITE_SPACE_PRE_LINE
,
334
};
335
374
typedef
int
Length
;
375
377
inline
Length
createAbsLength
(
int
n) {
return
(n << 2) | 1; }
378
380
inline
Length
createPerLength
(
double
v) {
381
return
((
int
)(v * (1 << 18)) & ~3) | 2; }
382
384
inline
Length
createRelLength
(
double
v) {
385
return
((
int
)(v * (1 << 18)) & ~3) | 3; }
386
388
inline
bool
isAbsLength
(
Length
l) {
return
(l & 3) == 1; }
389
391
inline
bool
isPerLength
(
Length
l) {
return
(l & 3) == 2; }
392
394
inline
bool
isRelLength
(
Length
l) {
return
(l & 3) == 3; }
395
397
inline
int
absLengthVal
(
Length
l) {
return
l >> 2; }
398
400
inline
double
perLengthVal
(
Length
l) {
return
(
double
)(l & ~3) / (1 << 18); }
401
403
inline
double
relLengthVal
(
Length
l) {
return
(
double
)(l & ~3) / (1 << 18); }
404
405
enum
{
407
LENGTH_AUTO
= 0
408
};
409
416
class
Box
417
{
418
public
:
419
/* in future also percentages */
420
int
top
,
right
,
bottom
,
left
;
421
422
inline
void
setVal
(
int
val) {
top
=
right
=
bottom
=
left
= val; }
423
inline
bool
equals
(
Box
*other) {
424
return
top
== other->
top
&&
425
right
== other->
right
&&
426
bottom
== other->
bottom
&&
427
left
== other->
left
;
428
}
429
inline
int
hashValue
() {
430
return
top
+
right
+
bottom
+
left
;
431
}
432
};
433
434
class
Font;
435
class
Color;
436
class
Tooltip;
437
441
class
StyleAttrs
:
public
lout::object::Object
442
{
443
public
:
444
Font
*
font
;
445
int
textDecoration
;
/* No TextDecoration because of problems converting
446
* TextDecoration <-> int */
447
Color
*
color
, *
backgroundColor
;
448
449
TextAlignType
textAlign
;
450
VAlignType
valign
;
451
char
textAlignChar
;
/* In future, strings will be supported. */
452
TextTransform
textTransform
;
453
454
int
hBorderSpacing
,
vBorderSpacing
,
wordSpacing
;
455
Length
width
,
height
,
lineHeight
,
textIndent
;
456
457
Box
margin
,
borderWidth
,
padding
;
458
BorderCollapse
borderCollapse
;
459
struct
{
Color
*
top
, *
right
, *
bottom
, *
left
; }
borderColor
;
460
struct
{
BorderStyle
top
,
right
,
bottom
,
left
; }
borderStyle
;
461
462
DisplayType
display
;
463
WhiteSpace
whiteSpace
;
464
ListStylePosition
listStylePosition
;
465
ListStyleType
listStyleType
;
466
Cursor
cursor
;
467
468
int
x_link
;
469
int
x_img
;
470
Tooltip
*
x_tooltip
;
471
char
x_lang
[2];
/* Either x_lang[0] == x_lang[1] == 0 (no language
472
set), or x_lang contains the RFC 1766 country
473
code in lower case letters. (Only two letters
474
allowed, currently.) */
475
476
void
initValues
();
477
void
resetValues
();
478
479
bool
sizeDiffs
(
StyleAttrs
*otherStyleAttrs);
480
481
inline
void
setBorderColor
(
Color
*val) {
482
borderColor
.top =
borderColor
.right =
borderColor
.bottom
483
=
borderColor
.left = val; }
484
inline
void
setBorderStyle
(
BorderStyle
val) {
485
borderStyle
.top =
borderStyle
.right =
borderStyle
.bottom
486
=
borderStyle
.left = val; }
487
488
inline
int
boxOffsetX
()
489
{
490
return
margin
.
left
+
borderWidth
.
left
+
padding
.
left
;
491
}
492
inline
int
boxRestWidth
()
493
{
494
return
margin
.
right
+
borderWidth
.
right
+
padding
.
right
;
495
}
496
inline
int
boxDiffWidth
() {
return
boxOffsetX
() +
boxRestWidth
(); }
497
inline
int
boxOffsetY
()
498
{
499
return
margin
.
top
+
borderWidth
.
top
+
padding
.
top
;
500
}
501
inline
int
boxRestHeight
()
502
{
503
return
margin
.
bottom
+
borderWidth
.
bottom
+
padding
.
bottom
;
504
}
505
inline
int
boxDiffHeight
() {
return
boxOffsetY
() +
boxRestHeight
(); }
506
507
inline
bool
hasBackground
() {
return
backgroundColor
!= NULL; }
508
509
bool
equals
(
lout::object::Object
*other);
510
int
hashValue
();
511
};
512
513
517
class
Style
:
public
StyleAttrs
518
{
519
private
:
520
static
int
totalRef
;
521
int
refCount
;
522
static
lout::container::typed::HashTable <StyleAttrs, Style>
*
styleTable
;
523
524
Style
(
StyleAttrs
*attrs);
525
526
protected
:
527
~Style
();
528
529
void
copyAttrs
(
StyleAttrs
*attrs);
530
531
public
:
532
inline
static
Style
*
create
(
Layout
*layout,
StyleAttrs
*attrs)
533
{
534
Style
*style =
styleTable
->
get
(attrs);
535
if
(style) {
536
style->
ref
();
537
}
else
{
538
style =
new
Style
(attrs);
539
styleTable
->
put
(style, style);
540
}
541
return
style;
542
}
543
544
inline
void
ref
() {
refCount
++; }
545
inline
void
unref
() {
if
(--
refCount
== 0)
delete
this
; }
546
};
547
548
552
class
TooltipAttrs
:
public
lout::object::String
553
{
554
public
:
555
TooltipAttrs
(
const
char
*text): lout::object::
String
(text) { }
556
};
557
561
class
Tooltip
:
public
TooltipAttrs
562
{
563
private
:
564
int
refCount
;
565
566
protected
:
567
Tooltip
(
const
char
*text):
TooltipAttrs
(text) {
refCount
= 0; }
568
569
public
:
570
static
Tooltip
*
create
(
dw::core::Layout
*layout,
const
char
*text);
571
inline
void
ref
() {
refCount
++; }
572
inline
void
unref
()
573
{
if
(--
refCount
== 0)
delete
this
; }
574
575
inline
virtual
void
onEnter
() { }
576
inline
virtual
void
onLeave
() { }
577
inline
virtual
void
onMotion
() { }
578
};
579
580
584
class
FontAttrs
:
public
lout::object::Object
585
{
586
public
:
587
const
char
*
name
;
588
int
size
;
589
int
weight
;
590
int
letterSpacing
;
591
FontVariant
fontVariant
;
592
FontStyle
style
;
593
594
bool
equals
(
lout::object::Object
*other);
595
int
hashValue
();
596
};
597
598
602
class
Font
:
public
FontAttrs
603
{
604
private
:
605
int
refCount
;
606
607
static
Font
*
create0
(
Layout
*layout,
FontAttrs
*attrs,
bool
tryEverything);
608
609
protected
:
610
inline
Font
() {
refCount
= 0; }
611
virtual
~Font
();
612
613
void
copyAttrs
(
FontAttrs
*attrs);
614
615
public
:
616
int
ascent
,
descent
;
617
int
spaceWidth
;
618
int
xHeight
;
619
620
static
Font
*
create
(
Layout
*layout,
FontAttrs
*attrs);
621
static
bool
exists
(
Layout
*layout,
const
char
*
name
);
622
623
inline
void
ref
() {
refCount
++; }
624
inline
void
unref
() {
if
(--
refCount
== 0)
delete
this
; }
625
};
626
627
631
class
ColorAttrs
:
public
lout::object::Object
632
{
633
protected
:
634
int
color
;
635
636
public
:
637
inline
ColorAttrs
(
int
color
)
638
{
639
this->color =
color
;
640
}
641
642
inline
int
getColor
() {
return
color
; }
643
644
bool
equals
(
lout::object::Object
*other);
645
int
hashValue
();
646
};
647
648
652
class
Color
:
public
ColorAttrs
653
{
654
private
:
655
int
refCount
;
656
657
void
remove
(
dw::core::Layout
*layout);
658
int
shadeColor
(
int
color
,
int
d);
659
660
protected
:
661
inline
Color
(
int
color
):
ColorAttrs
(color) {
662
refCount
= 0; }
663
virtual
~Color
();
664
665
public
:
666
enum
Shading
{
SHADING_NORMAL
,
SHADING_INVERSE
,
SHADING_DARK
,
SHADING_LIGHT
,
667
SHADING_NUM
};
668
669
protected
:
670
int
shadeColor
(
int
color
,
Shading
shading);
671
672
public
:
673
static
Color
*
create
(
Layout
*layout,
int
color
);
674
675
inline
void
ref
() {
refCount
++; }
676
inline
void
unref
()
677
{
if
(--
refCount
== 0)
delete
this
; }
678
};
679
680
void
drawBorder
(
View
*view,
Rectangle
*area,
681
int
x,
int
y,
int
width,
int
height,
682
Style *style,
bool
inverse);
683
void
drawBackground
(
View
*view,
Rectangle
*area,
684
int
x,
int
y,
int
width,
int
height,
685
Style *style,
bool
inverse);
686
void
numtostr
(
int
num,
char
*buf,
int
buflen,
ListStyleType
listStyleType);
687
688
}
// namespace style
689
}
// namespace dw
690
}
// namespace core
691
692
#endif // __DW_STYLE_HH__
693
Generated on Mon Nov 5 2012 02:16:32 for Dillo by
1.8.2