2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "libs/fvwmlib.h"
20 #include "libs/ColorUtils.h"
21 #include "libs/Graphics.h"
24 /* left, center and right offsets */
25 #define ITEM_DRAW_LCR_OFFSETS 1,0,1
28 * Fonction pour ItemDraw / functions for ItemDraw
30 void InitItemDraw(struct XObj
*xobj
)
33 XSetWindowAttributes Attr
;
34 int minHeight
,minWidth
;
36 /* Enregistrement des couleurs et de la police */
37 if (xobj
->colorset
>= 0) {
38 xobj
->TabColor
[fore
] = Colorset
[xobj
->colorset
].fg
;
39 xobj
->TabColor
[back
] = Colorset
[xobj
->colorset
].bg
;
40 xobj
->TabColor
[hili
] = Colorset
[xobj
->colorset
].hilite
;
41 xobj
->TabColor
[shad
] = Colorset
[xobj
->colorset
].shadow
;
43 xobj
->TabColor
[fore
] = GetColor(xobj
->forecolor
);
44 xobj
->TabColor
[back
] = GetColor(xobj
->backcolor
);
45 xobj
->TabColor
[hili
] = GetColor(xobj
->hilicolor
);
46 xobj
->TabColor
[shad
] = GetColor(xobj
->shadcolor
);
49 Attr
.background_pixel
= xobj
->TabColor
[back
];
52 xobj
->win
= XCreateWindow(dpy
, *xobj
->ParentWin
,
53 xobj
->x
, xobj
->y
, xobj
->width
, xobj
->height
, 0,
54 CopyFromParent
, InputOutput
, CopyFromParent
,
56 xobj
->gc
= fvwmlib_XCreateGC(dpy
, xobj
->win
, 0, NULL
);
57 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
59 if ((xobj
->Ffont
= FlocaleLoadFont(dpy
, xobj
->font
, ScriptName
)) == NULL
)
61 fprintf(stderr
, "%s: Couldn't load font. Exiting!\n", ScriptName
);
64 if (xobj
->Ffont
->font
!= NULL
)
65 XSetFont(dpy
, xobj
->gc
, xobj
->Ffont
->font
->fid
);
67 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
69 /* Redimensionnement du widget */
71 if (xobj
->icon
== NULL
)
73 if (strlen(xobj
->title
) != 0)
75 /* title but no icon */
76 minHeight
= xobj
->Ffont
->height
+ 2;
77 minWidth
= FlocaleTextWidth(xobj
->Ffont
, xobj
->title
, strlen(xobj
->title
))
79 if (xobj
->height
< minHeight
)
80 xobj
->height
= minHeight
;
81 if (xobj
->width
< minWidth
)
82 xobj
->width
= minWidth
;
85 else if (strlen(xobj
->title
)==0)
87 /* icon but no title */
88 if (xobj
->height
<xobj
->icon_h
)
89 xobj
->height
= xobj
->icon_h
;
90 if (xobj
->width
<xobj
->icon_w
)
91 xobj
->width
= xobj
->icon_w
;
97 FlocaleTextWidth(xobj
->Ffont
, xobj
->title
, strlen(xobj
->title
))+2)
99 /* icon is wider than the title */
100 if (xobj
->width
<xobj
->icon_w
)
101 xobj
->width
= xobj
->icon_w
;
105 /* title is wider than icon */
107 FlocaleTextWidth(xobj
->Ffont
, xobj
->title
, strlen(xobj
->title
)) + 2)
109 FlocaleTextWidth(xobj
->Ffont
, xobj
->title
, strlen(xobj
->title
)) + 2;
111 xobj
->height
= xobj
->icon_h
+ xobj
->Ffont
->height
+ 2;
113 XResizeWindow(dpy
, xobj
->win
, xobj
->width
, xobj
->height
);
114 if (xobj
->colorset
>= 0)
115 SetWindowBackground(dpy
, xobj
->win
, xobj
->width
, xobj
->height
,
116 &Colorset
[xobj
->colorset
], Pdepth
,
118 XSelectInput(dpy
, xobj
->win
, ExposureMask
);
119 /* x and y value of a clic */
124 void DestroyItemDraw(struct XObj
*xobj
)
126 FlocaleUnloadFont(dpy
,xobj
->Ffont
);
127 XFreeGC(dpy
,xobj
->gc
);
128 XDestroyWindow(dpy
,xobj
->win
);
131 void DrawItemDraw(struct XObj
*xobj
, XEvent
*evp
)
137 dpy
,xobj
->win
, evp
->xexpose
.x
, evp
->xexpose
.y
,
138 evp
->xexpose
.width
, evp
->xexpose
.height
, False
);
142 XClearArea(dpy
,xobj
->win
,0,0,xobj
->width
,xobj
->height
,False
);
144 DrawIconStr(0,xobj
,False
,ITEM_DRAW_LCR_OFFSETS
, NULL
, NULL
, evp
);
147 void EvtMouseItemDraw(struct XObj
*xobj
,XButtonEvent
*EvtButton
)
153 FQueryPointer(dpy
, *xobj
->ParentWin
, &Win1
, &Win2
, &x1
, &y1
, &x2
, &y2
, &modif
);
154 xobj
->value2
= x2
-xobj
->x
;
155 xobj
->value3
= y2
-xobj
->y
;
156 SendMsg(xobj
,SingleClic
);
159 void EvtKeyItemDraw(struct XObj
*xobj
, XKeyEvent
*EvtKey
)
162 unsigned char buf
[10];
167 FQueryPointer(dpy
, *xobj
->ParentWin
, &Win1
, &Win2
, &x1
, &y1
, &x2
, &y2
, &modif
);
168 xobj
->value2
= x2
-xobj
->x
;
169 xobj
->value3
= y2
-xobj
->y
;
170 XLookupString(EvtKey
, (char *)buf
, sizeof(buf
), &ks
, NULL
);
171 if (ks
== XK_Left
&& xobj
->value2
> 0) {
172 FWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, -1, 0);
174 else if (ks
== XK_Right
&& xobj
->value2
< xobj
->width
- 1) {
175 FWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, 1, 0);
177 else if (ks
== XK_Up
&& xobj
->value3
> 0) {
178 FWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, 0, -1);
180 else if (ks
== XK_Down
&& xobj
->value3
< xobj
->height
- 1) {
181 FWarpPointer(dpy
, None
, None
, 0, 0, 0, 0, 0, 1);
183 else if (ks
== XK_Return
) {
184 EvtMouseItemDraw(xobj
, NULL
);
188 void ProcessMsgItemDraw(struct XObj
*xobj
,unsigned long type
,unsigned long *body
)