1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
/*
* Author: William Chia-Wei Cheng (bill.cheng@acm.org)
*
* Copyright (C) 2001-2009, William Chia-Wei Cheng.
*
* This file may be distributed under the terms of the Q Public License
* as defined by Trolltech AS of Norway and appearing in the file
* LICENSE.QPL included in the packaging of this file.
*
* THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* @(#)$Header: /mm2/home/cvs/bc-src/tgif/tdgtmsg.c,v 1.9 2011/05/16 16:22:00 william Exp $
*/
#define _INCLUDE_FROM_TDGTMSG_C_
#include "tgifdefs.h"
#include "patchlvl.h"
#include "tidget.h"
#include "choose.e"
#include "cursor.e"
#include "font.e"
#include "menu.e"
#include "msg.e"
#include "raster.e"
#include "rect.e"
#include "setup.e"
#include "tdgtmsg.e"
#include "text.e"
#include "tidget.e"
#include "util.e"
static void RedrawTdgtMsg ARGS_DECL((TidgetInfo *pti));
static int TdgtMsgEventHandler ARGS_DECL((TidgetInfo *pti, XEvent *input,
TidgetInfo *handling_pti));
static int IsTdgtMsgEvent ARGS_DECL((TidgetInfo *pti, XEvent *input,
TidgetInfo **ppti_handler_tidget_return));
static void DestroyTdgtMsg ARGS_DECL((TidgetInfo *pti));
static void MapTdgtMsg ARGS_DECL((TidgetInfo *pti));
static void TdgtMsgMoveResize ARGS_DECL((TidgetInfo *pti, int x, int y,
int w, int h));
static int TdgtMsgSendCmd ARGS_DECL((TidgetInfo *pti, int cmd_type,
int cmd_arg, void *pv_cmd_userdata));
/* --------------------- RedrawTdgtMsg() --------------------- */
static void TdgtMsgDrawCaption(TdgtMsg *pTdgtMsg)
{
int x=windowPadding+pTdgtMsg->pti->tci.h_pad;
int y=windowPadding+pTdgtMsg->pti->tci.v_pad;
int just=pTdgtMsg->just;
int win_w=pTdgtMsg->pti->tci.win_info.w;
char *psz=NULL, *psz_cur=TdgtMsgGetText(pTdgtMsg);
if (boldMsgFontSet != NULL || boldMsgFontPtr != NULL) {
if (boldMsgFontPtr != NULL) {
XSetFont(mainDisplay, gTidgetManager.gc, boldMsgFontPtr->fid);
}
y += boldMsgFontAsc;
} else if (msgFontSet != NULL || msgFontPtr != NULL) {
XSetFont(mainDisplay, gTidgetManager.gc, msgFontPtr->fid);
y += msgFontAsc;
} else {
y += defaultFontAsc;
}
switch (just) {
case JUST_L: break;
case JUST_C: x = (win_w>>1); break;
case JUST_R: x = win_w-windowPadding-pTdgtMsg->pti->tci.h_pad; break;
}
do {
int line_w=0;
psz = strchr(psz_cur, '\n');
if (psz != NULL) *psz = '\0';
switch (just) {
case JUST_L:
DrawBoldMsgString(mainDisplay, pTdgtMsg->pti->tci.win,
gTidgetManager.gc, x, y, psz_cur, strlen(psz_cur));
break;
case JUST_C:
line_w = BoldMsgTextWidth(boldMsgFontPtr, psz_cur, strlen(psz_cur));
DrawBoldMsgString(mainDisplay, pTdgtMsg->pti->tci.win,
gTidgetManager.gc, x-(line_w>>1), y, psz_cur, strlen(psz_cur));
break;
case JUST_R:
line_w = BoldMsgTextWidth(boldMsgFontPtr, psz_cur, strlen(psz_cur));
DrawBoldMsgString(mainDisplay, pTdgtMsg->pti->tci.win,
gTidgetManager.gc, x-line_w, y, psz_cur, strlen(psz_cur));
break;
}
if (boldMsgFontSet != NULL || boldMsgFontPtr != NULL) {
y += boldMsgFontHeight;
} else if (msgFontSet != NULL || msgFontPtr != NULL) {
y += msgFontHeight;
} else {
y += defaultFontHeight;
}
if (psz != NULL) {
*psz++ = '\n';
psz_cur = psz;
} else {
psz_cur = NULL;
}
} while (psz != NULL);
TidgetManagerResetGC();
}
static void RedrawTdgtMsg(TidgetInfo *pti)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
XClearWindow(mainDisplay, pTdgtMsg->pti->tci.win);
if (threeDLook) {
struct BBRec bbox;
SetBBRec(&bbox, 0, 0, pTdgtMsg->pti->tci.win_info.w,
pTdgtMsg->pti->tci.win_info.h);
switch (pTdgtMsg->pti->tci.state) {
case TGBS_NORMAL: break;
default:
TgDrawThreeDButton(mainDisplay, pTdgtMsg->pti->tci.win,
gTidgetManager.gc, &bbox, pTdgtMsg->pti->tci.state, 2, TRUE);
TidgetManagerResetGC();
break;
}
} else {
/*
* XDrawRectangle(mainDisplay, pTdgtMsg->pti->tci.win, gTidgetManager.gc,
* 0, 0, pTdgtMsg->pti->tci.win_info.w,
* pTdgtMsg->pti->tci.win_info.h);
*/
}
TdgtMsgDrawCaption(pTdgtMsg);
}
/* --------------------- TdgtMsgEventHandler() --------------------- */
static int TdgtMsgEventHandler(TidgetInfo *pti, XEvent *input, TidgetInfo *handling_pti)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
if (pti != handling_pti) return FALSE;
if (input->type == Expose) {
XEvent ev;
RedrawTdgtMsg(pTdgtMsg->pti);
while (XCheckWindowEvent(mainDisplay, pTdgtMsg->pti->tci.win,
ExposureMask, &ev)) ;
}
return FALSE;
}
/* --------------------- IsTdgtMsgEvent() --------------------- */
static int IsTdgtMsgEvent(TidgetInfo *pti, XEvent *input, TidgetInfo **ppti_handler_tidget_return)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
if (input->xany.window == pTdgtMsg->pti->tci.win) {
*ppti_handler_tidget_return = pti;
return TRUE;
}
return FALSE;
}
/* --------------------- DestroyTdgtMsg() --------------------- */
static void DestroyTdgtMsg(TidgetInfo *pti)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
TdgtMsgReset(pTdgtMsg);
free(pTdgtMsg);
}
/* --------------------- MapTdgtMsg() --------------------- */
static void MapTdgtMsg(TidgetInfo *pti)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
#ifdef MAPBEFORESELECT
XMapWindow(mainDisplay, pTdgtMsg->pti->tci.win);
XSelectInput(mainDisplay, pTdgtMsg->pti->tci.win,
ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
EnterWindowMask | LeaveWindowMask);
#else
XSelectInput(mainDisplay, pTdgtMsg->pti->tci.win,
ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
EnterWindowMask | LeaveWindowMask);
XMapWindow(mainDisplay, pTdgtMsg->pti->tci.win);
#endif
}
/* --------------------- TdgtMsgMoveResize() --------------------- */
static void TdgtMsgMoveResize(TidgetInfo *pti, int x, int y, int w, int h)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
/* there should be no need to resize a button */
pTdgtMsg->pti->tci.win_info.x = x;
pTdgtMsg->pti->tci.win_info.y = y;
pTdgtMsg->pti->tci.win_info.w = w;
pTdgtMsg->pti->tci.win_info.h = h;
XMoveResizeWindow(mainDisplay, pTdgtMsg->pti->tci.win, x, y, w, h);
}
/* --------------------- TdgtMsgSendCmd() --------------------- */
static int TdgtMsgSendCmd(TidgetInfo *pti, int cmd_type, int cmd_arg, void *pv_cmd_userdata)
{
TdgtMsg *pTdgtMsg=(TdgtMsg*)(pti->tidget);
if (pTdgtMsg != NULL) {
}
return FALSE;
}
/* --------------------- TdgtMsgReset() --------------------- */
void TdgtMsgReset(TdgtMsg *pTdgtMsg)
{
FreeDynStrBuf(&pTdgtMsg->pti->tci.dyn_str);
}
/* --------------------- CreateTdgtMsg() --------------------- */
static void TdgtMsgCalcGeom(char *caption, int *pn_w, int *pn_h)
{
int w=0, h=0;
char *psz=NULL, *psz_cur=NULL, *dup_caption=UtilStrDup(caption);
if (dup_caption == NULL) FailAllocMessage();
psz_cur = dup_caption;
do {
int line_w=0;
psz = strchr(psz_cur, '\n');
if (psz != NULL) *psz = '\0';
line_w = BoldMsgTextWidth(boldMsgFontPtr, psz_cur, strlen(psz_cur));
if (line_w > w) w = line_w;
if (boldMsgFontSet != NULL || boldMsgFontPtr != NULL) {
h += boldMsgFontHeight;
} else if (msgFontSet != NULL || msgFontPtr != NULL) {
h += msgFontHeight;
} else {
h += defaultFontHeight;
}
if (psz != NULL) {
*psz++ = '\n';
psz_cur = psz;
} else {
psz_cur = NULL;
}
} while (psz != NULL);
UtilFree(dup_caption);
if (pn_w != NULL) *pn_w = w;
if (pn_h != NULL) *pn_h = h;
}
TdgtMsg *CreateTdgtMsg(Window parent_win, TidgetInfo *parent_tidgetinfo, int ctl_id, int x, int y, int h_pad, int v_pad, int state, char *caption, int just)
{
int bg_pixel=(threeDLook ? myLtGryPixel : myBgPixel), w=0, h=0;
TdgtMsg *pTdgtMsg=NULL;
if (caption != NULL) {
int msg_w=0, msg_h=0;
TdgtMsgCalcGeom(caption, &msg_w, &msg_h);
w = msg_w + (windowPadding<<1) + (h_pad<<1);
h = msg_h + (windowPadding<<1) + (v_pad<<1);
}
pTdgtMsg = (TdgtMsg*)malloc(sizeof(TdgtMsg));
if (pTdgtMsg == NULL) FailAllocMessage();
memset(pTdgtMsg, 0, sizeof(TdgtMsg));
pTdgtMsg->pti = NewTidgetInfo(parent_tidgetinfo, TIDGET_TYPE_MSG, pTdgtMsg,
ctl_id, NULL);
if ((pTdgtMsg->pti->tci.win=XCreateSimpleWindow(mainDisplay, parent_win,
x, y, w, h, brdrW, myBorderPixel, bg_pixel)) == 0) {
FailToCreateWindowMessage("CreateTdgtMsg()", NULL, TRUE);
return NULL;
}
XSelectInput(mainDisplay, pTdgtMsg->pti->tci.win,
ButtonReleaseMask | ButtonPressMask | KeyPressMask | ExposureMask |
EnterWindowMask | LeaveWindowMask);
SetTidgetInfoBasic(pTdgtMsg->pti, TIDGET_TYPE_MSG, pTdgtMsg, parent_win,
x, y, w, h, h_pad, v_pad, state, caption);
TidgetSetCallbacks(pTdgtMsg->pti,
RedrawTdgtMsg, TdgtMsgEventHandler, IsTdgtMsgEvent, DestroyTdgtMsg,
MapTdgtMsg, TdgtMsgMoveResize, TdgtMsgSendCmd);
pTdgtMsg->just = just;
return pTdgtMsg;
}
/* --------------------- TdgtMsgSetText() --------------------- */
int TdgtMsgSetText(TdgtMsg *pTdgtMsg, char *str)
{
RedrawTdgtMsg(pTdgtMsg->pti);
if (str != NULL) {
FreeDynStrBuf(&(pTdgtMsg->pti->tci.dyn_str));
DynStrSet(&(pTdgtMsg->pti->tci.dyn_str), str);
}
return TRUE;
}
/* --------------------- TdgtMsgGetText() --------------------- */
char *TdgtMsgGetText(TdgtMsg *pTdgtMsg)
{
return pTdgtMsg->pti->tci.dyn_str.s;
}
/* --------------------- TdgtMsgSetState() --------------------- */
int TdgtMsgSetState(TdgtMsg *pTdgtMsg, int new_state)
{
int need_to_redraw=(pTdgtMsg->pti->tci.state != new_state);
pTdgtMsg->pti->tci.state = new_state;
if (need_to_redraw) {
RedrawTdgtMsg(pTdgtMsg->pti);
}
return TRUE;
}
/* --------------------- TdgtMsgGetState() --------------------- */
int TdgtMsgGetState(TdgtMsg *pTdgtMsg)
{
return pTdgtMsg->pti->tci.state;
}
/* --------------------- Init & Clean Up --------------------- */
int InitTdgtMsg(void)
{
return TRUE;
}
void CleanUpTdgtMsg(void)
{
}
|