1 /***************************************************************************
2  *   Copyright (C) 2008 by Vadim Lopatin                                   *
3  *   vadim.lopatin@coolreader.org                                          *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef CR_SKIN_INCLUDED
21 #define CR_SKIN_INCLUDED
22 
23 #include "lvtypes.h"
24 #include "lvptrvec.h"
25 #include "lvref.h"
26 #include "lvstring.h"
27 #include "crlog.h"
28 #include "lvfntman.h"
29 #include "lvdrawbuf.h"
30 #include "lvtinydom.h"
31 
32 
33 // Vertical alignment flags
34 #define SKIN_VALIGN_MASK    0x0003
35 #define SKIN_VALIGN_TOP     0x0001
36 #define SKIN_VALIGN_CENTER  0x0000
37 #define SKIN_VALIGN_BOTTOM  0x0002
38 
39 // Horizontal alignment flags
40 #define SKIN_HALIGN_MASK    0x0030
41 #define SKIN_HALIGN_LEFT    0x0000
42 #define SKIN_HALIGN_CENTER  0x0010
43 #define SKIN_HALIGN_RIGHT   0x0020
44 
45 #define SKIN_EXTEND_TAB     0x0040
46 
47 #define SKIN_WORD_WRAP      0x0080
48 
49 #define SKIN_COORD_PERCENT_FLAG 0x10000000
50 
51 /// encodes percent value*100 (0..10000), to store in skin
toSkinPercent(int x)52 inline int toSkinPercent( int x )
53 {
54     return ((x)|SKIN_COORD_PERCENT_FLAG);
55 }
56 
57 /// encodes percent value*100 (0..10000), to store in skin, from string like "75%" or "10"
58 int toSkinPercent( const lString32 & value, int defValue, bool * res );
59 
60 /// decodes skin percent to pixels (fullx is value corresponding to 100%)
61 int fromSkinPercent( int x, int fullx );
62 
63 /// decodes skin percent point to pixels (fullx is value corresponding to 100%)
64 lvPoint fromSkinPercent( lvPoint pt, lvPoint fullpt );
65 
66 /// resizable/autoplaceable icon for using in skins
67 class CRIconSkin
68 {
69 protected:
70     LVImageSourceRef _image; /// image to draw
71     lUInt32 _bgcolor; /// color to fill area if image is not found
72     ImageTransform _hTransform;
73     ImageTransform _vTransform;
74     lvPoint _splitPoint;
75     lvPoint _pos;
76     lvPoint _size;
77     int _align;
78 public:
79     /// image to draw
getImage()80     LVImageSourceRef getImage() { return _image; }
81     /// color to fill area if image is not found
getBgColor()82     lUInt32 getBgColor() { return _bgcolor; }
83     /// horizontal image transform
getHTransform()84     ImageTransform getHTransform() { return _hTransform; }
85     /// vertical image transform
getVTransform()86     ImageTransform getVTransform() { return _vTransform; }
87     /// splitting point of image for split transform
getSplitPoint()88     lvPoint getSplitPoint() { return _splitPoint; }
89     /// position of image inside destination rectangle
getPos()90     lvPoint getPos() { return _pos; }
91     /// size of image (percents are relative to destination rectangle)
getSize()92     lvPoint getSize() { return _size; }
93     /// set image to draw
setImage(LVImageSourceRef img)94     void setImage( LVImageSourceRef img ) { _image = img; }
95     /// color to fill area if image is not found
setBgColor(lUInt32 cl)96     void setBgColor(lUInt32 cl) { _bgcolor = cl; }
97     /// horizontal image transform
setHTransform(ImageTransform t)98     void setHTransform( ImageTransform t) { _hTransform = t; }
99     /// vertical image transform
setVTransform(ImageTransform t)100     void setVTransform( ImageTransform t) { _vTransform = t; }
101     /// splitting point of image for split transform
setSplitPoint(lvPoint p)102     void setSplitPoint(lvPoint p) { _splitPoint = p ; }
103     /// position of image inside destination rectangle
setPos(lvPoint p)104     void setPos(lvPoint p) { _pos = p; }
105     /// size of image (percents are relative to destination rectangle)
setSize(lvPoint sz)106     void setSize( lvPoint sz) { _size = sz; }
getAlign()107     virtual int getAlign() { return _align; }
getVAlign()108     virtual int getVAlign() { return _align & SKIN_VALIGN_MASK; }
getHAlign()109     virtual int getHAlign() { return _align & SKIN_HALIGN_MASK; }
setAlign(int align)110     virtual void setAlign( int align ) { _align = align; }
setVAlign(int align)111     virtual void setVAlign( int align ) { _align = (_align & ~SKIN_VALIGN_MASK ) | (align & SKIN_VALIGN_MASK); }
setHAlign(int align)112     virtual void setHAlign( int align ) { _align = (_align & ~SKIN_HALIGN_MASK ) | (align & SKIN_HALIGN_MASK); }
113     virtual void draw( LVDrawBuf & buf, const lvRect & rc );
114     CRIconSkin();
~CRIconSkin()115     virtual ~CRIconSkin() { }
116 };
117 typedef LVRef<CRIconSkin> CRIconSkinRef;
118 
119 /// list of icons
120 class CRIconList
121 {
122 protected:
123     LVRefVec<CRIconSkin> _list;
124 public:
add(CRIconSkinRef icon)125     void add( CRIconSkinRef icon ) { _list.add( icon ); }
add(CRIconList & list)126     void add( CRIconList & list ) { _list.add( list._list ); }
first()127     CRIconSkinRef first() { return _list.length()>0 ? _list[0] : CRIconSkinRef(); }
getBgColor()128     lUInt32 getBgColor() { CRIconSkinRef r = first(); return r.isNull() ? 0xFFFFFF : r->getBgColor(); }
length()129     int length() { return _list.length(); }
130     virtual void draw( LVDrawBuf & buf, const lvRect & rc );
CRIconList()131     CRIconList() { }
~CRIconList()132     virtual ~CRIconList() { }
133 };
134 typedef LVRef<CRIconList> CRIconListRef;
135 
136 /// base skinned item class
137 class CRSkinnedItem : public LVRefCounter
138 {
139 protected:
140     lUInt32 _textcolor;
141     CRIconListRef _bgicons;
142     //lUInt32 _bgcolor;
143     //LVImageSourceRef _bgimage;
144     //lvPoint _bgimagesplit;
145     lString32 _fontFace;
146     int _fontSize;
147     bool _fontBold;
148     bool _fontItalic;
149     LVFontRef _font;
150     int _textAlign;
151 public:
152     CRSkinnedItem();
getBackgroundColor()153     virtual lUInt32 getBackgroundColor() { return _bgicons.isNull() ? 0xFFFFFF : _bgicons->getBgColor(); }
154     // set icons to single image, with splitting
setBackgroundImage(LVImageSourceRef img)155     virtual void setBackgroundImage( LVImageSourceRef img )
156     {
157         CRIconListRef icons( new CRIconList() );
158         CRIconSkinRef icon( new CRIconSkin() );
159         icon->setImage( img );
160         icons->add( icon );
161         _bgicons = icons;
162     }
getBgIcons()163     virtual CRIconListRef getBgIcons() { return _bgicons; }
setBgIcons(CRIconListRef list)164     virtual void setBgIcons( CRIconListRef list ) { _bgicons = list; }
getTextAlign()165     virtual int getTextAlign() { return _textAlign; }
getTextVAlign()166     virtual int getTextVAlign() { return _textAlign & SKIN_VALIGN_MASK; }
getTextHAlign()167     virtual int getTextHAlign() { return _textAlign & SKIN_HALIGN_MASK; }
setTextAlign(int align)168     virtual void setTextAlign( int align ) { _textAlign = align; }
setTextVAlign(int align)169     virtual void setTextVAlign( int align ) { _textAlign = (_textAlign & ~SKIN_VALIGN_MASK ) | (align & SKIN_VALIGN_MASK); }
setTextHAlign(int align)170     virtual void setTextHAlign( int align ) { _textAlign = (_textAlign & ~SKIN_HALIGN_MASK ) | (align & SKIN_HALIGN_MASK); }
setWordWrap(bool v)171     virtual void setWordWrap( bool v ) { _textAlign = v ? (_textAlign | SKIN_WORD_WRAP ) : (_textAlign & ~SKIN_WORD_WRAP ); }
getWordWrap()172     virtual bool getWordWrap() { return (_textAlign & SKIN_WORD_WRAP) ? true : false; }
getTextColor()173     virtual lUInt32 getTextColor() { return _textcolor; }
174     //virtual lUInt32 getBackgroundColor() { return _bgcolor; }
175     //virtual LVImageSourceRef getBackgroundImage() { return _bgimage; }
176     //virtual lvPoint getBackgroundImageSplit() { return _bgimagesplit; }
getFontFace()177     virtual lString32 getFontFace() { return _fontFace; }
getFontSize()178     virtual int getFontSize() { return _fontSize; }
getFontBold()179     virtual bool getFontBold() { return _fontBold; }
getFontItalic()180     virtual bool getFontItalic() { return _fontItalic; }
181     virtual void setFontFace( lString32 face );
182     virtual void setFontSize( int size );
183     virtual void setFontBold( bool bold );
184     virtual void setFontItalic( bool italic );
185     virtual LVFontRef getFont();
setTextColor(lUInt32 color)186     virtual void setTextColor( lUInt32 color ) { _textcolor = color; }
187     //virtual void setBackgroundColor( lUInt32 color ) { _bgcolor = color; }
188     //virtual void setBackgroundImage( LVImageSourceRef img ) { _bgimage = img; }
189     //virtual void setBackgroundImageSplit( lvPoint pt ) { _bgimagesplit = pt; }
setFont(LVFontRef fnt)190     virtual void setFont( LVFontRef fnt ) { _font = fnt; }
191     virtual void draw( LVDrawBuf & buf, const lvRect & rc );
192     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text, LVFontRef font, lUInt32 textColor, lUInt32 bgColor, int flags );
drawText(LVDrawBuf & buf,const lvRect & rc,lString32 text,LVFontRef font)193     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text, LVFontRef font )
194     {
195         drawText(  buf, rc, text, font, getTextColor(), getBackgroundColor(), getTextAlign() );
196     }
drawText(LVDrawBuf & buf,const lvRect & rc,lString32 text)197     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text )
198     {
199         drawText(  buf, rc, text, LVFontRef(), getTextColor(), getBackgroundColor(), getTextAlign() );
200     }
drawText(LVDrawBuf & buf,const lvRect & rc,lString32 text,lUInt32 color)201     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text, lUInt32 color )
202     {
203         drawText(  buf, rc, text, LVFontRef(), color, getBackgroundColor(), getTextAlign() );
204     }
205     /// measures text string using current font
206     virtual lvPoint measureText( lString32 text );
~CRSkinnedItem()207     virtual ~CRSkinnedItem() { }
208 };
209 
210 class CRRectSkin : public CRSkinnedItem
211 {
212 protected:
213     lvRect _margins;
214     lvPoint _minsize;
215     lvPoint _maxsize;
216     lvPoint _size;
217     lvPoint _pos;
218     int _align;
219 public:
220     /// same as measureText, but with added margins and minSize applied
221     virtual lvPoint measureTextItem( lString32 text );
222     CRRectSkin();
~CRRectSkin()223     virtual ~CRRectSkin() { }
224     /// returns rect based on pos and size
225     virtual bool getRect( lvRect & rc, const lvRect & baseRect );
getSize()226     virtual lvPoint getSize() { return _size; }
getPos()227     virtual lvPoint getPos() { return _pos; }
setSize(lvPoint sz)228     virtual void setSize( lvPoint sz ) { _size = sz; }
setPos(lvPoint pos)229     virtual void setPos( lvPoint pos ) { _pos = pos; }
getAlign()230     virtual int getAlign() { return _align; }
getVAlign()231     virtual int getVAlign() { return _align & SKIN_VALIGN_MASK; }
getHAlign()232     virtual int getHAlign() { return _align & SKIN_HALIGN_MASK; }
setAlign(int align)233     virtual void setAlign( int align ) { _align = align; }
setVAlign(int align)234     virtual void setVAlign( int align ) { _align = (_align & ~SKIN_VALIGN_MASK ) | (align & SKIN_VALIGN_MASK); }
setHAlign(int align)235     virtual void setHAlign( int align ) { _align = (_align & ~SKIN_HALIGN_MASK ) | (align & SKIN_HALIGN_MASK); }
getMinSize()236     virtual lvPoint getMinSize() { return _minsize; }
getMaxSize()237     virtual lvPoint getMaxSize() { return _maxsize; }
setMinSize(lvPoint sz)238     virtual void setMinSize( lvPoint sz ) { _minsize = sz; }
setMaxSize(lvPoint sz)239     virtual void setMaxSize( lvPoint sz ) { _maxsize = sz; }
setBorderWidths(const lvRect & rc)240     virtual void setBorderWidths( const lvRect & rc) { _margins = rc; }
getBorderWidths()241     virtual lvRect getBorderWidths() { return _margins; }
242     virtual lvRect getClientRect( const lvRect &windowRect );
243     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text );
244     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text, LVFontRef font );
drawText(LVDrawBuf & buf,const lvRect & rc,lString32 text,LVFontRef font,lUInt32 textColor,lUInt32 bgColor,int flags)245     virtual void drawText( LVDrawBuf & buf, const lvRect & rc, lString32 text, LVFontRef font, lUInt32 textColor, lUInt32 bgColor, int flags )
246     {
247         CRSkinnedItem::drawText( buf, rc, text, font, textColor, bgColor, flags );
248     }
249 };
250 typedef LVFastRef<CRRectSkin> CRRectSkinRef;
251 
252 
253 enum page_skin_type_t {
254     PAGE_SKIN_SCROLL,
255     PAGE_SKIN_LEFT_PAGE,
256     PAGE_SKIN_RIGHT_PAGE,
257     PAGE_SKIN_SINGLE_PAGE
258 };
259 
260 class CRPageSkin : public CRSkinnedItem
261 {
262     CRRectSkinRef _scrollSkin;
263     CRRectSkinRef _leftPageSkin;
264     CRRectSkinRef _rightPageSkin;
265     CRRectSkinRef _singlePageSkin;
266     lString32     _name;
267 public:
getName()268     const lString32 & getName() { return _name; }
setName(const lString32 & newName)269     void setName( const lString32 & newName ) { _name = newName; }
270     CRPageSkin();
271     CRRectSkinRef getSkin( page_skin_type_t type );
272 };
273 typedef LVFastRef<CRPageSkin> CRPageSkinRef;
274 
275 class CRPageSkinList : public LVArray<CRPageSkinRef>
276 {
277 public:
278     CRPageSkinRef findByName( const lString32 & name );
279 };
280 typedef LVRef<CRPageSkinList> CRPageSkinListRef;
281 
282 class CRButtonSkin : public CRRectSkin
283 {
284 protected:
285     LVImageSourceRef _normalimage;
286     LVImageSourceRef _disabledimage;
287     LVImageSourceRef _pressedimage;
288     LVImageSourceRef _selectedimage;
289 public:
290     enum {
291         ENABLED = 1,
292         PRESSED = 2,
293         SELECTED = 4
294     };
getNormalImage()295     LVImageSourceRef getNormalImage() { return _normalimage; }
getDisabledImage()296     LVImageSourceRef getDisabledImage() { return _disabledimage; }
getPressedImage()297     LVImageSourceRef getPressedImage() { return _pressedimage; }
getSelectedImage()298     LVImageSourceRef getSelectedImage() { return _selectedimage; }
setNormalImage(LVImageSourceRef img)299     void setNormalImage( LVImageSourceRef img ) { _normalimage = img; }
setDisabledImage(LVImageSourceRef img)300     void setDisabledImage( LVImageSourceRef img ) { _disabledimage = img; }
setPressedImage(LVImageSourceRef img)301     void setPressedImage( LVImageSourceRef img ) { _pressedimage = img; }
setSelectedImage(LVImageSourceRef img)302     void setSelectedImage( LVImageSourceRef img ) { _selectedimage = img; }
303     virtual void drawButton( LVDrawBuf & buf, const lvRect & rc, int flags = ENABLED );
304     LVImageSourceRef getImage(int flags = ENABLED);
305     CRButtonSkin();
~CRButtonSkin()306     virtual ~CRButtonSkin() {
307 		CRLog::trace("~CRButtonSkin()");
308 	}
309 };
310 typedef LVFastRef<CRButtonSkin> CRButtonSkinRef;
311 
312 
313 class CRScrollSkin : public CRRectSkin
314 {
315 public:
316     enum Location {
317         Title,
318         Status
319     };
320 
321 protected:
322     CRButtonSkinRef _upButton;
323     CRButtonSkinRef _downButton;
324     CRButtonSkinRef _leftButton;
325     CRButtonSkinRef _rightButton;
326     LVImageSourceRef _hBody;
327     LVImageSourceRef _hSlider;
328     LVImageSourceRef _vBody;
329     LVImageSourceRef _vSlider;
330     CRRectSkinRef _bottomTabSkin;
331     CRRectSkinRef _bottomActiveTabSkin;
332     CRRectSkinRef _bottomPageBoundSkin;
333 
334     bool _autohide;
335     bool _showPageNumbers;
336     Location _location;
337 
338 public:
339 
340 
getLocation()341     Location getLocation() { return _location; }
setLocation(Location location)342     void setLocation( Location location ) { _location = location; }
getBottomTabSkin()343     CRRectSkinRef getBottomTabSkin() { return _bottomTabSkin; }
getBottomActiveTabSkin()344     CRRectSkinRef getBottomActiveTabSkin() { return _bottomActiveTabSkin; }
getBottomPageBoundSkin()345     CRRectSkinRef getBottomPageBoundSkin() { return _bottomPageBoundSkin; }
setBottomTabSkin(CRRectSkinRef skin)346     void setBottomTabSkin( CRRectSkinRef skin ) { _bottomTabSkin = skin; }
setBottomActiveTabSkin(CRRectSkinRef skin)347     void setBottomActiveTabSkin( CRRectSkinRef skin ) { _bottomActiveTabSkin = skin; }
setBottomPageBoundSkin(CRRectSkinRef skin)348     void setBottomPageBoundSkin( CRRectSkinRef skin ) { _bottomPageBoundSkin = skin; }
getUpButton()349     CRButtonSkinRef getUpButton() { return _upButton; }
getDownButton()350     CRButtonSkinRef getDownButton() { return _downButton; }
getLeftButton()351     CRButtonSkinRef getLeftButton() { return _leftButton; }
getRightButton()352     CRButtonSkinRef getRightButton() { return _rightButton; }
setUpButton(CRButtonSkinRef btn)353     void setUpButton( CRButtonSkinRef btn ) { _upButton = btn; }
setDownButton(CRButtonSkinRef btn)354     void setDownButton( CRButtonSkinRef btn ) { _downButton = btn; }
setLeftButton(CRButtonSkinRef btn)355     void setLeftButton( CRButtonSkinRef btn ) { _leftButton = btn; }
setRightButton(CRButtonSkinRef btn)356     void setRightButton( CRButtonSkinRef btn ) { _rightButton = btn; }
getHBody()357     LVImageSourceRef getHBody() { return _hBody; }
getHSlider()358     LVImageSourceRef getHSlider() { return _hSlider; }
getVBody()359     LVImageSourceRef getVBody() { return _vBody; }
getVSlider()360     LVImageSourceRef getVSlider() { return _vSlider; }
setHBody(LVImageSourceRef img)361     void setHBody( LVImageSourceRef img ) { _hBody = img; }
setHSlider(LVImageSourceRef img)362     void setHSlider( LVImageSourceRef img ) { _hSlider = img; }
setVBody(LVImageSourceRef img)363     void setVBody( LVImageSourceRef img ) { _vBody = img; }
setVSlider(LVImageSourceRef img)364     void setVSlider( LVImageSourceRef img ) { _vSlider = img; }
getAutohide()365     bool getAutohide() { return _autohide; }
setAutohide(bool flgAutoHide)366     void setAutohide( bool flgAutoHide ) { _autohide = flgAutoHide; }
getShowPageNumbers()367     bool getShowPageNumbers() { return _showPageNumbers; }
setShowPageNumbers(bool flg)368     void setShowPageNumbers( bool flg ) { _showPageNumbers = flg; }
369     virtual void drawScroll( LVDrawBuf & buf, const lvRect & rc, bool vertical, int pos, int maxpos, int pagesize );
370     virtual void drawGauge( LVDrawBuf & buf, const lvRect & rc, int percent );
371     CRScrollSkin();
~CRScrollSkin()372     virtual ~CRScrollSkin() { }
373 };
374 typedef LVFastRef<CRScrollSkin> CRScrollSkinRef;
375 
376 class CRButtonList
377 {
378 protected:
379     LVRefVec<CRButtonSkin> _list;
380 public:
add(LVRef<CRButtonSkin> button)381     void add( LVRef<CRButtonSkin> button ) { _list.add( button ); }
add(CRButtonList & list)382     void add( CRButtonList & list ) { _list.add( list._list ); }
length()383     int length() { return _list.length(); }
get(int index)384     LVRef<CRButtonSkin> get(int index) { return (index >= 0 && index < _list.length()) ? _list[index] : LVRef<CRButtonSkin>(); }
CRButtonList()385     CRButtonList() { }
~CRButtonList()386     virtual ~CRButtonList() {
387 		CRLog::trace("~CRButtonList();");
388 	}
389 };
390 typedef LVRef<CRButtonList> CRButtonListRef;
391 
392 class CRToolBarSkin : public CRRectSkin
393 {
394 protected:
395     CRButtonListRef _buttons;
396 public:
CRToolBarSkin()397     CRToolBarSkin() { }
~CRToolBarSkin()398     virtual ~CRToolBarSkin() {
399 		CRLog::trace("~CRToolBarSkin();");
400 	}
401 
getButtons()402     CRButtonListRef getButtons() { return _buttons; }
setButtons(CRButtonListRef list)403     void setButtons(CRButtonListRef list) { _buttons = list; }
404     virtual void drawToolBar( LVDrawBuf & buf, const lvRect & rc, bool enabled, int selectedButton );
405     virtual void drawButton(LVDrawBuf & buf, const lvRect & rc, int index, int flags);
406 };
407 typedef LVFastRef<CRToolBarSkin> CRToolBarSkinRef;
408 
409 class CRWindowSkin : public CRRectSkin
410 {
411 protected:
412     //lvPoint _titleSize;
413     CRRectSkinRef _titleSkin;
414     CRRectSkinRef _clientSkin;
415     CRRectSkinRef _statusSkin;
416     CRRectSkinRef _inputSkin;
417     CRScrollSkinRef _scrollSkin;
418     bool _fullscreen;
419 public:
getFullScreen()420     bool getFullScreen() { return _fullscreen; }
setFullScreen(bool fs)421     void setFullScreen( bool fs ) { _fullscreen = fs; }
422     CRWindowSkin();
~CRWindowSkin()423     virtual ~CRWindowSkin() { }
424     /// returns necessary window size for specified client size
getScrollSkin()425     CRScrollSkinRef getScrollSkin() { return _scrollSkin; }
setScrollSkin(CRScrollSkinRef v)426     void setScrollSkin( CRScrollSkinRef v ) { _scrollSkin = v; }
427     virtual lvPoint getWindowSize( const lvPoint & clientSize );
428     virtual lvPoint getTitleSize();
429     //virtual void setTitleSize( lvPoint sz ) { _titleSize = sz; }
430     virtual lvRect getTitleRect( const lvRect &windowRect );
431     virtual lvRect getClientRect( const lvRect &windowRect );
getTitleSkin()432     virtual CRRectSkinRef getTitleSkin() { return _titleSkin; }
setTitleSkin(CRRectSkinRef skin)433     virtual void setTitleSkin( CRRectSkinRef skin ) { _titleSkin = skin; }
getClientSkin()434     virtual CRRectSkinRef getClientSkin() { return _clientSkin; }
setClientSkin(CRRectSkinRef skin)435     virtual void setClientSkin( CRRectSkinRef skin ) { _clientSkin = skin; }
getStatusSkin()436     virtual CRRectSkinRef getStatusSkin() { return _statusSkin; }
setStatusSkin(CRRectSkinRef skin)437     virtual void setStatusSkin( CRRectSkinRef skin ) { _statusSkin = skin; }
getInputSkin()438     virtual CRRectSkinRef getInputSkin() { return _inputSkin; }
setInputSkin(CRRectSkinRef skin)439     virtual void setInputSkin( CRRectSkinRef skin ) { _inputSkin = skin; }
440 };
441 typedef LVFastRef<CRWindowSkin> CRWindowSkinRef;
442 
443 class CRMenuSkin : public CRWindowSkin
444 {
445 protected:
446     CRRectSkinRef _separatorSkin;
447     CRRectSkinRef _valueSkin;
448     CRRectSkinRef _itemSkin;
449     CRRectSkinRef _itemShortcutSkin;
450     CRRectSkinRef _evenItemSkin;
451     CRRectSkinRef _evenItemShortcutSkin;
452     CRRectSkinRef _selItemSkin;
453     CRRectSkinRef _selItemShortcutSkin;
454     CRRectSkinRef _evenSelItemSkin;
455     CRRectSkinRef _evenSelItemShortcutSkin;
456     int _minItemCount;
457     int _maxItemCount;
458     bool _showShortcuts;
459 public:
460     CRMenuSkin();
~CRMenuSkin()461     virtual ~CRMenuSkin() { }
getValueSkin()462     virtual CRRectSkinRef getValueSkin() { return _valueSkin; }
setValueSkin(CRRectSkinRef skin)463     virtual void setValueSkin( CRRectSkinRef skin ) { _valueSkin = skin; }
getItemSkin()464     virtual CRRectSkinRef getItemSkin() { return _itemSkin; }
setItemSkin(CRRectSkinRef skin)465     virtual void setItemSkin( CRRectSkinRef skin ) { _itemSkin = skin; }
getSeparatorSkin()466     virtual CRRectSkinRef getSeparatorSkin() { return _separatorSkin; }
setSeparatorSkin(CRRectSkinRef skin)467     virtual void setSeparatorSkin( CRRectSkinRef skin ) { _separatorSkin = skin; }
getEvenItemSkin()468     virtual CRRectSkinRef getEvenItemSkin() { return _evenItemSkin; }
setEvenItemSkin(CRRectSkinRef skin)469     virtual void setEvenItemSkin( CRRectSkinRef skin ) { _evenItemSkin = skin; }
getItemShortcutSkin()470     virtual CRRectSkinRef getItemShortcutSkin() { return _itemShortcutSkin; }
setItemShortcutSkin(CRRectSkinRef skin)471     virtual void setItemShortcutSkin( CRRectSkinRef skin ) { _itemShortcutSkin = skin; }
getEvenItemShortcutSkin()472     virtual CRRectSkinRef getEvenItemShortcutSkin() { return _evenItemShortcutSkin; }
setEvenItemShortcutSkin(CRRectSkinRef skin)473     virtual void setEvenItemShortcutSkin( CRRectSkinRef skin ) { _evenItemShortcutSkin = skin; }
getSelItemSkin()474     virtual CRRectSkinRef getSelItemSkin() { return _selItemSkin; }
setSelItemSkin(CRRectSkinRef skin)475     virtual void setSelItemSkin( CRRectSkinRef skin ) { _selItemSkin = skin; }
getEvenSelItemSkin()476     virtual CRRectSkinRef getEvenSelItemSkin() { return _evenSelItemSkin; }
setEvenSelItemSkin(CRRectSkinRef skin)477     virtual void setEvenSelItemSkin( CRRectSkinRef skin ) { _evenSelItemSkin = skin; }
getSelItemShortcutSkin()478     virtual CRRectSkinRef getSelItemShortcutSkin() { return _selItemShortcutSkin; }
setSelItemShortcutSkin(CRRectSkinRef skin)479     virtual void setSelItemShortcutSkin( CRRectSkinRef skin ) { _selItemShortcutSkin = skin; }
getEvenSelItemShortcutSkin()480     virtual CRRectSkinRef getEvenSelItemShortcutSkin() { return _evenSelItemShortcutSkin; }
setEvenSelItemShortcutSkin(CRRectSkinRef skin)481     virtual void setEvenSelItemShortcutSkin( CRRectSkinRef skin ) { _evenSelItemShortcutSkin = skin; }
getMinItemCount()482     int getMinItemCount() { return _minItemCount; }
getMaxItemCount()483     int getMaxItemCount() { return _maxItemCount; }
setMinItemCount(int v)484     void setMinItemCount( int v ) { _minItemCount = v; }
setMaxItemCount(int v)485     void setMaxItemCount( int v ) { _maxItemCount = v; }
getShowShortcuts()486     bool getShowShortcuts() { return _showShortcuts; }
setShowShortcuts(bool flgShowShortcuts)487     void setShowShortcuts( bool flgShowShortcuts ) { _showShortcuts = flgShowShortcuts; }
488 };
489 typedef LVFastRef<CRMenuSkin> CRMenuSkinRef;
490 
491 
492 
493 /// Base skin class
494 class CRSkinContainer : public LVRefCounter
495 {
496 protected:
497     virtual bool readRectSkin(  const lChar32 * path, CRRectSkin * res );
498     virtual bool readIconSkin(  const lChar32 * path, CRIconSkin * res );
499     virtual bool readButtonSkin(  const lChar32 * path, CRButtonSkin * res );
500     virtual bool readScrollSkin(  const lChar32 * path, CRScrollSkin * res );
501     virtual bool readWindowSkin(  const lChar32 * path, CRWindowSkin * res );
502     virtual bool readPageSkin(  const lChar32 * path, CRPageSkin * res );
503     virtual bool readMenuSkin(  const lChar32 * path, CRMenuSkin * res );
504     virtual bool readToolBarSkin( const lChar32 * path, CRToolBarSkin *res );
505 public:
506     /// retuns path to base definition, if attribute base="#nodeid" is specified for element of path
507     virtual lString32 getBasePath( const lChar32 * path );
508     /// find path by id
509     virtual lString32 pathById( const lChar32 * id ) = 0;
510     /// gets image from container
511     virtual LVImageSourceRef getImage( const lChar32 * filename ) = 0;
512     /// gets image from container
getImage(const lString32 & filename)513     virtual LVImageSourceRef getImage( const lString32 & filename ) { return getImage( filename.c_str() ); }
514     /// gets doc pointer by path
515     virtual ldomXPointer getXPointer( const lString32 & xPointerStr ) = 0;
516     /// gets doc pointer by path
getXPointer(const lChar32 * xPointerStr)517     virtual ldomXPointer getXPointer( const lChar32 * xPointerStr ) { return getXPointer( lString32(xPointerStr) ); }
518     /// reads int value from attrname attribute of element specified by path, returns defValue if not found
519     virtual int readInt( const lChar32 * path, const lChar32 * attrname, int defValue, bool * res=NULL );
520     /// reads boolean value from attrname attribute of element specified by path, returns defValue if not found
521     virtual bool readBool( const lChar32 * path, const lChar32 * attrname, bool defValue, bool * res=NULL );
522     /// reads image transform value from attrname attribute of element specified by path, returns defValue if not found
523     ImageTransform readTransform( const lChar32 * path, const lChar32 * attrname, ImageTransform defValue, bool * res );
524     /// reads h align value from attrname attribute of element specified by path, returns defValue if not found
525     virtual int readHAlign( const lChar32 * path, const lChar32 * attrname, int defValue, bool * res=NULL );
526     /// reads h align value from attrname attribute of element specified by path, returns defValue if not found
527     virtual int readVAlign( const lChar32 * path, const lChar32 * attrname, int defValue, bool * res=NULL );
528     /// reads string value from attrname attribute of element specified by path, returns empty string if not found
529     virtual lString32 readString( const lChar32 * path, const lChar32 * attrname, bool * res=NULL );
530     /// reads string value from attrname attribute of element specified by path, returns defValue if not found
531     virtual lString32 readString( const lChar32 * path, const lChar32 * attrname, const lString32 & defValue, bool * res=NULL );
532     /// reads color value from attrname attribute of element specified by path, returns defValue if not found
533     virtual lUInt32 readColor( const lChar32 * path, const lChar32 * attrname, lUInt32 defValue, bool * res=NULL );
534     /// reads rect value from attrname attribute of element specified by path, returns defValue if not found
535     virtual lvRect readRect( const lChar32 * path, const lChar32 * attrname, lvRect defValue, bool * res=NULL );
536     /// reads point(size) value from attrname attribute of element specified by path, returns defValue if not found
537     virtual lvPoint readSize( const lChar32 * path, const lChar32 * attrname, lvPoint defValue, bool * res=NULL );
538     /// reads rect value from attrname attribute of element specified by path, returns null ref if not found
539     virtual LVImageSourceRef readImage( const lChar32 * path, const lChar32 * attrname, bool * res=NULL );
540     /// reads list of icons
541     virtual CRIconListRef readIcons( const lChar32 * path, bool * res=NULL );
542 	/// reads list of buttons
543     virtual CRButtonListRef readButtons( const lChar32 * path, bool * res=NULL );
544     /// returns rect skin by path or #id
545     virtual CRRectSkinRef getRectSkin( const lChar32 * path ) = 0;
546     /// returns scroll skin by path or #id
547     virtual CRScrollSkinRef getScrollSkin( const lChar32 * path ) = 0;
548     /// returns window skin by path or #id
549     virtual CRWindowSkinRef getWindowSkin( const lChar32 * path ) = 0;
550     /// returns menu skin by path or #id
551     virtual CRMenuSkinRef getMenuSkin( const lChar32 * path ) = 0;
552     /// returns book page skin by path or #id
553     virtual CRPageSkinRef getPageSkin( const lChar32 * path ) = 0;
554     /// returns book page skin list
555     virtual CRPageSkinListRef getPageSkinList() = 0;
556     /// returns toolbar skin by path or #id
557     virtual CRToolBarSkinRef getToolBarSkin( const lChar32 * path ) = 0;
558 
559     /// garbage collection
gc()560     virtual void gc() { }
561 
562     /// destructor
~CRSkinContainer()563     virtual ~CRSkinContainer() { }
564 };
565 
566 /// skin reference
567 typedef LVFastRef<CRSkinContainer> CRSkinRef;
568 
569 class CRSkinListItem
570 {
571     lString32 _name;
572     lString32 _baseDir;
573     lString32 _fileName;
574     lString32Collection _pageSkinList;
CRSkinListItem()575     CRSkinListItem() { }
576 public:
getName()577     lString32 getName() { return _name; }
getFileName()578     lString32 getFileName() { return _fileName; }
getDirName()579     lString32 getDirName() { return _baseDir; }
getPageSkinList()580     lString32Collection & getPageSkinList() { return _pageSkinList; }
581     static CRSkinListItem * init( lString32 baseDir, lString32 fileName );
582     CRSkinRef getSkin();
~CRSkinListItem()583     virtual ~CRSkinListItem() { }
584 };
585 class CRSkinList : public LVPtrVector<CRSkinListItem>
586 {
587 public:
588     CRSkinListItem * findByName(const lString32 & name);
589 };
590 
591 
592 /// opens skin from directory or .zip file
593 CRSkinRef LVOpenSkin( const lString32 & pathname );
594 /// open simple skin, without image files, from string
595 CRSkinRef LVOpenSimpleSkin( const lString8 & xml );
596 
597 
598 
599 #endif// CR_SKIN_INCLUDED
600