1 /***************************************************************************
2  *   Copyright (C) 2009-2010 by t3swing                                    *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
18  ***************************************************************************/
19 /**
20  * @file   skin.h
21  * @author t3swing  t3swing@sina.com
22  *
23  * @date   2009-10-9
24  *
25  *  皮肤设置相关定义及初始化加载工作
26  *
27  *
28  */
29 
30 #ifndef _SKIN_H
31 #define _SKIN_H
32 
33 #define SIZEX 800
34 #define SIZEY 200
35 #include "fcitx-utils/uthash.h"
36 #include <cairo.h>
37 #include "fcitx-config/fcitx-config.h"
38 #include "fcitx/ui.h"
39 
40 struct _XlibMenu;
41 struct _InputWindow;
42 struct _Messages;
43 struct _FcitxClassicUI;
44 
45 typedef enum _FillRule {
46     F_COPY = 0,
47     F_RESIZE = 1
48 } FillRule;
49 
50 typedef enum _MouseE {
51     RELEASE,//鼠标释放状态
52     PRESS,//鼠标按下
53     MOTION//鼠标停留
54 } MouseE;
55 
56 typedef enum _OverlayDock {
57     OD_TopLeft = 0,
58     OD_TopCenter = 1,
59     OD_TopRight = 2,
60     OD_CenterLeft = 3,
61     OD_Center = 4,
62     OD_CenterRight = 5,
63     OD_BottomLeft = 6,
64     OD_BottomCenter = 7,
65     OD_BottomRight = 8,
66 } OverlayDock;
67 
68 typedef struct _FcitxWindowBackground {
69     char* background;
70 
71     char* overlay;
72     OverlayDock dock;
73     int overlayOffsetX;
74     int overlayOffsetY;
75 
76     int marginTop;
77     int marginBottom;
78     int marginLeft;
79     int marginRight;
80 
81     int clickMarginTop;
82     int clickMarginBottom;
83     int clickMarginLeft;
84     int clickMarginRight;
85 
86     FillRule fillV;
87     FillRule fillH;
88 } FcitxWindowBackground;
89 
90 typedef struct _SkinImage {
91     char *name;
92     cairo_surface_t *image;
93     boolean textIcon;
94     UT_hash_handle hh;
95 } SkinImage;
96 
97 typedef struct _SkinInfo {
98     char *skinName;
99     char *skinVersion;
100     char *skinAuthor;
101     char *skinDesc;
102 } SkinInfo;
103 
104 typedef struct _SkinFont {
105     boolean respectDPI;
106     int fontSize;
107     int menuFontSize;
108     FcitxConfigColor fontColor[7];
109     FcitxConfigColor menuFontColor[2];
110 } SkinFont;
111 
112 typedef struct _SkinMenu {
113     FcitxWindowBackground background;
114     FcitxConfigColor activeColor;
115     FcitxConfigColor lineColor;
116 } SkinMenu;
117 
118 /**
119  * The Main Window Skin description
120  **/
121 typedef struct _SkinMainBar {
122     char* logo;
123     char* eng;
124     char* active;
125 
126     FcitxWindowBackground background;
127 
128     char *placement;
129     UT_array skinPlacement;
130     boolean bUseCustomTextIconColor;
131     FcitxConfigColor textIconColor[2];
132 } SkinMainBar;
133 
134 typedef struct _SkinInputBar {
135     FcitxConfigColor cursorColor;
136 
137     FcitxWindowBackground background;
138 
139     char* backArrow;
140     char* forwardArrow;
141     int iBackArrowX;
142     int iBackArrowY;
143     int iForwardArrowX;
144     int iForwardArrowY;
145     int iInputPos;
146     int iOutputPos;
147 } SkinInputBar;
148 
149 typedef struct _SkinPlacement {
150     char *name;;
151     int x;
152     int y;
153     UT_hash_handle hh;
154 } SkinPlacement;
155 
156 /**
157  * Tray Icon Image
158  **/
159 typedef struct _SkinTrayIcon {
160     /**
161      * Active Tray Icon Image
162      **/
163     char* active;
164 
165     /**
166      * Inactive Tray Icon Image
167      **/
168     char* inactive;
169 } SkinTrayIcon;
170 
171 typedef struct _SkinKeyboard {
172     char* backImg;
173     FcitxConfigColor keyColor;
174 } SkinKeyboard;
175 
176 /**
177 * 配置文件结构,方便处理,结构固定
178 */
179 typedef struct _FcitxSkin {
180     FcitxGenericConfig config;
181     SkinInfo skinInfo;
182     SkinFont skinFont;
183     SkinMainBar skinMainBar;
184     SkinInputBar skinInputBar;
185     SkinTrayIcon skinTrayIcon;
186     SkinMenu skinMenu;
187     SkinKeyboard skinKeyboard;
188 
189     char** skinType;
190 
191     SkinImage* imageTable;
192     SkinImage* trayImageTable;
193 } FcitxSkin;
194 
195 FcitxConfigFileDesc* GetSkinDesc();
196 int LoadSkinConfig(FcitxSkin* sc, char** skinType);
197 void DrawImage(cairo_t* c, cairo_surface_t* png, int x, int y, MouseE mouse);
198 void DrawInputBar(struct _InputWindow* inputWindow, boolean vertical, int iCursorPos);
199 SkinImage* LoadImage(FcitxSkin* sc, const char* name, int fallback);
200 SkinImage* LoadImageWithText(struct _FcitxClassicUI *classicui, FcitxSkin* sc, const char* name, const char* text, int w, int h, boolean active);
201 void InitSkinMenu(struct _FcitxClassicUI* classicui);
202 void DisplaySkin(struct _FcitxClassicUI* classicui, char * skinname);
203 void ParsePlacement(UT_array* sps, char* placment);
204 SkinImage* GetIMIcon(struct _FcitxClassicUI* classicui, FcitxSkin* sc, const char* fallbackIcon, int flag, boolean fallbackToDefault);
205 void DrawResizableBackground(cairo_t *c,
206                              cairo_surface_t *background,
207                              int width,
208                              int height,
209                              int marginLeft,
210                              int marginTop,
211                              int marginRight,
212                              int marginBottom,
213                              FillRule fillV,
214                              FillRule fillH
215                             );
216 #define fcitx_cairo_set_color(c, color) cairo_set_source_rgb((c), (color)->r, (color)->g, (color)->b)
217 
218 CONFIG_BINDING_DECLARE(FcitxSkin);
219 #endif
220 
221 
222 
223 // kate: indent-mode cstyle; space-indent on; indent-width 0;
224