1 /*
2  * Author:      William Chia-Wei Cheng (bill.cheng@acm.org)
3  *
4  * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5  *
6  * This file may be distributed under the terms of the Q Public License
7  * as defined by Trolltech AS of Norway and appearing in the file
8  * LICENSE.QPL included in the packaging of this file.
9  *
10  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11  * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12  * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * @(#)$Header: /mm2/home/cvs/bc-src/tgif/tidget.h,v 1.6 2011/05/16 16:22:00 william Exp $
19  */
20 
21 #ifndef _TIDGET_H_
22 #define _TIDGET_H_
23 
24 #include "list.e"
25 
26 #define TIDGET_TYPE_BASE  0
27 #define TIDGET_TYPE_LIST  1
28 #define TIDGET_TYPE_BTN   2
29 #define TIDGET_TYPE_EDIT  3
30 #define TIDGET_TYPE_DRAW  4
31 #define TIDGET_TYPE_MSG   5
32 #define TIDGET_TYPE_BROW  6
33 #define TIDGET_TYPE_BMPL  7
34 #define TIDGET_TYPE_SEDT  8
35 
36 /* --------------------- Notifications --------------------- */
37 
38 /*
39  * TDGTNF_* are tidget notifications generated by a control.
40  * nf_type is one of TDGTNF_*.
41  * nf_arg and nf_arg2 are arguments to the notification event.
42  */
43 #define TDGTNF_NO_NOTIFY 0
44 
45 /* list control events */
46 #define TDGTNF_LIST_CLICKED 10 /* nf_arg is the item index,
47 		nf_arg2 is which mouse button was used when clicking */
48 #define TDGTNF_LIST_DBL_CLICKED 11 /* nf_arg is the item index */
49 
50 /* button control events */
51 #define TDGTNF_BTN_CLICKED 20 /* nf_arg is 0 */
52 #define TDGTNF_MULTI_BTN_CLICKED 21 /* nf_arg is Button[1-3],
53 		nf_arg2 is color_index */
54 
55 /* edit control events */
56 #define TDGTNF_EDIT_ENTERED 30 /* nf_arg is 0 */
57 
58 /* --------------------- Commands --------------------- */
59 
60 /*
61  * TDGTCMD_* are tidget commands that can be send to a control.
62  * cmd_type is one of TDGTCMD_*.
63  * cmd_arg is an argument to the command.
64  */
65 #define TDGTCMD_NO_CMD 200
66 
67 /* bitmap list control commands */
68 #define TDGTCMD_LIST_RESETCONTENT 210 /* cmd_arg is 0 */
69 #define TDGTCMD_LIST_SEL_NEXT     211 /* cmd_arg is one of TDGTARG_MOVE_* */
70 #define     TDGTARG_MOVE_UP    0
71 #define     TDGTARG_MOVE_DOWN  1
72 #define     TDGTARG_MOVE_RIGHT 2
73 #define     TDGTARG_MOVE_LEFT  3
74 #define TDGTCMD_LIST_GETCURSEL    212 /* get marked_index,
75 		pv_cmd_userdata is of type (int*) */
76 #define TDGTCMD_LIST_GETITEM      213 /* cmd_arg is an index,
77 		if tidget is TdgtBmpList, pv_cmd_userdata is of type
78 		(BmpListItemInfo**), if tidget is TdgtList, pv_cmd_userdata
79 		is of type (ListItemInfo**) */
80 
81 /* draw control commands */
82 #define TDGTCMD_DRAW_USER 240 /* cmd_arg is user defined */
83 
84 /* --------------------- Structures --------------------- */
85 
86 struct tagTidgetInfo;
87 
88 typedef void (TidgetRedrawCallbackFunc)ARGS_DECL((struct tagTidgetInfo *));
89 typedef int (TidgetEvHandlerCallbackFunc)ARGS_DECL((struct tagTidgetInfo *,
90 		XEvent*, struct tagTidgetInfo *));
91 typedef int (TidgetIsEventCallbackFunc)ARGS_DECL((struct tagTidgetInfo *,
92 		XEvent*, struct tagTidgetInfo **));
93 typedef void (TidgetDestroyCallbackFunc)ARGS_DECL((struct tagTidgetInfo *));
94 typedef void (TidgetMapCallbackFunc)ARGS_DECL((struct tagTidgetInfo *));
95 typedef void (TidgetMoveResizeCallbackFunc)ARGS_DECL((struct tagTidgetInfo *,
96 		int x, int y, int w, int h));
97 typedef int (TidgetSendCmdCallbackFunc)ARGS_DECL((struct tagTidgetInfo *,
98 		int cmd_type, int cmd_arg, void *pv_cmd_userdata));
99 
100 typedef struct tagTidgetCommonInfo {
101    /*
102     * If parent_tidgetinfo is NULL, the parent is not a tidget (just some sort
103     *         of a window -- for an example, see "chat.c" and "tgtwb5dl.c").
104     * The parent window is stored in parent_win.
105     */
106    struct tagTidgetInfo *parent_tidgetinfo;
107    Window parent_win;
108 
109    Window win;
110    SimpleWinInfo win_info;
111 
112    int state; /* TGBS_NORMAL, TGBS_GRAYED, TGBS_RAISED, or TGBS_LOWRED */
113    int mapped;
114    int redraw_disabled;
115    int dirty; /* to be used with redraw_disabled */
116 
117    int h_pad, v_pad; /* horizontal and vertical padding */
118 
119    /*
120     * content_w is usually win_info.w-(windowPadding<<1)-(h_pad<<1)
121     * content_h is usually win_info.h-(windowPadding<<1)-(v_pad<<1)
122     */
123    int content_w, content_h;
124 
125    struct DynStrRec dyn_str; /* caption, msg, btn name, etc. */
126 
127    int ctl_id; /* so that objects can be named */
128 
129    int can_have_children; /* TRUE if a tidget can have child tidgets */
130    CVList clist; /* list of (TIdgetInfo*) which are children tidgets */
131 
132    /* call back functions */
133    TidgetRedrawCallbackFunc *pf_redraw_callback;
134    TidgetEvHandlerCallbackFunc *pf_ev_handler_callback;
135    TidgetIsEventCallbackFunc *pf_is_event_callback;
136    TidgetDestroyCallbackFunc *pf_destroy_callback;
137    TidgetMapCallbackFunc *pf_map_callback;
138    TidgetMoveResizeCallbackFunc *pf_moveresize_callback;
139    TidgetSendCmdCallbackFunc *pf_sendcmd_callback;
140 } TidgetCommonInfo;
141 
142 typedef struct tagTidgetInfo {
143    /*
144     * type is one of TIDGET_TYPE_*
145     * It is used to typecast the tidget field below to one of the
146     *         known types.
147     */
148    int type;
149    void *tidget; /* points to the actual tidget */
150 
151    TidgetCommonInfo tci;
152 
153    /* additional userdata */
154    void *userdata;
155 } TidgetInfo;
156 
157 typedef struct tagTdgtCmd {
158    int cmd_type;
159    int cmd_arg;
160    void *cmd_userdata;
161 } TdgtCmd;
162 
163 typedef struct tagTdgtNtfy {
164    int ctl_id;
165    int nf_type;
166    int nf_arg;
167    int nf_arg2;
168 } TdgtNtfy;
169 
170 #endif /*_TIDGET_H_*/
171