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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
|
/****************************************************************************
* NCSA Mosaic for the X Window System *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* mosaic@ncsa.uiuc.edu *
* *
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
* *
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
* copyrighted by The Board of Trustees of the University of Illinois *
* (UI), and ownership remains with the UI. *
* *
* The UI grants you (hereafter, Licensee) a license to use the Software *
* for academic, research and internal business purposes only, without a *
* fee. Licensee may distribute the binary and source code (if released) *
* to third parties provided that the copyright notice and this statement *
* appears on all copies and that no charge is associated with such *
* copies. *
* *
* Licensee may make derivative works. However, if Licensee distributes *
* any derivative work based on or derived from the Software, then *
* Licensee will (1) notify NCSA regarding its distribution of the *
* derivative work, and (2) clearly notify users that such derivative *
* work is a modified version and not the original NCSA Mosaic *
* distributed by the UI. *
* *
* Any Licensee wishing to make commercial use of the Software should *
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
* commercial use. Commercial use includes (1) integration of all or *
* part of the source code into a product for sale or license by or on *
* behalf of Licensee to third parties, or (2) distribution of the binary *
* code or source code to third parties that need it to utilize a *
* commercial product sold or licensed by or on behalf of Licensee. *
* *
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
* USERS OF THIS SOFTWARE. *
* *
* By using or copying this Software, Licensee agrees to abide by the *
* copyright law and all other applicable laws of the U.S. including, but *
* not limited to, export control laws, and the terms of this license. *
* UI shall have the right to terminate this license immediately by *
* written notice upon Licensee's breach of, or non-compliance with, any *
* of its terms. Licensee may be held legally responsible for any *
* copyright infringement that is caused or encouraged by Licensee's *
* failure to abide by the terms of this license. *
* *
* Comments and questions are welcome and can be sent to *
* mosaic-x@ncsa.uiuc.edu. *
****************************************************************************/
#ifdef MOTIF
#include <stdio.h>
#include "inkstore.h"
#include "HTMLP.h"
#include <sys/types.h>
#include <netinet/in.h>
typedef struct stroke_rec {
Boolean draw;
int x, y;
struct stroke_rec *next;
} Stroke;
typedef struct jot_rec {
Widget w;
int width, height;
Pixmap pix;
Boolean drawing;
int last_x, last_y;
int min_x, min_y;
int max_x, max_y;
int stroke_cnt;
Stroke *strokes;
Stroke *last_stroke;
struct jot_rec *next;
} JotInfo;
static JotInfo *JotList = NULL;
static JotInfo *JotCurrent = NULL;
void
NewJot(w, width, height)
Widget w;
int width, height;
{
if (JotCurrent == NULL)
{
JotList = (JotInfo *)malloc(sizeof(JotInfo));
JotCurrent = JotList;
JotCurrent->w = w;
JotCurrent->width = width;
JotCurrent->height = height;
JotCurrent->pix = (Pixmap)NULL;
JotCurrent->drawing = False;
JotCurrent->strokes = NULL;
JotCurrent->last_stroke = NULL;
JotCurrent->stroke_cnt = 0;
JotCurrent->min_x = width;
JotCurrent->max_x = 0;
JotCurrent->min_y = height;
JotCurrent->max_y = 0;
JotCurrent->next = NULL;
}
else
{
JotCurrent->next = (JotInfo *)malloc(sizeof(JotInfo));
JotCurrent = JotCurrent->next;
JotCurrent->w = w;
JotCurrent->width = width;
JotCurrent->height = height;
JotCurrent->pix = (Pixmap)NULL;
JotCurrent->drawing = False;
JotCurrent->strokes = NULL;
JotCurrent->last_stroke = NULL;
JotCurrent->stroke_cnt = 0;
JotCurrent->min_x = width;
JotCurrent->max_x = 0;
JotCurrent->min_y = height;
JotCurrent->max_y = 0;
JotCurrent->next = NULL;
}
}
JotInfo *
GetJot(w)
Widget w;
{
JotInfo *jptr;
jptr = JotList;
while (jptr != NULL)
{
if (jptr->w == w)
{
break;
}
jptr = jptr->next;
}
return(jptr);
}
void
FreeStrokes(sptr)
Stroke *sptr;
{
Stroke *tptr;
while (sptr != NULL)
{
tptr = sptr;
sptr = sptr->next;
tptr->next = NULL;
free((char *)tptr);
}
}
void
ClearJot(hw, w, width, height)
HTMLWidget hw;
Widget w;
int width, height;
{
JotInfo *jptr;
XClearArea(XtDisplay(w), XtWindow(w),
0, 0, width, height, False);
jptr = GetJot(w);
if (jptr == NULL)
{
return;
}
if (jptr->pix != (Pixmap)NULL)
{
XSetForeground(XtDisplay(w), hw->html.drawGC,
hw->core.background_pixel);
XFillRectangle(XtDisplay(w), jptr->pix,
hw->html.drawGC,
0, 0, jptr->width, jptr->height);
}
FreeStrokes(jptr->strokes);
jptr->strokes = NULL;
jptr->last_stroke = NULL;
jptr->stroke_cnt = 0;
jptr->drawing = False;
jptr->min_x = width;
jptr->max_x = 0;
jptr->min_y = height;
jptr->max_y = 0;
}
void
AddStroke(jptr, sptr, drawing)
JotInfo *jptr;
Stroke *sptr;
Boolean drawing;
{
if (jptr->strokes == NULL)
{
jptr->strokes = sptr;
jptr->last_stroke = jptr->strokes;
jptr->last_stroke->next = NULL;
}
else
{
jptr->last_stroke->next = sptr;
jptr->last_stroke = jptr->last_stroke->next;
jptr->last_stroke->next = NULL;
}
jptr->last_x = sptr->x;
jptr->last_y = sptr->y;
jptr->drawing = drawing;
if (sptr->x < jptr->min_x)
{
jptr->min_x = sptr->x;
}
if (sptr->x > jptr->max_x)
{
jptr->max_x = sptr->x;
}
if (sptr->y < jptr->min_y)
{
jptr->min_y = sptr->y;
}
if (sptr->y > jptr->max_y)
{
jptr->max_y = sptr->y;
}
jptr->stroke_cnt++;
}
void
EVJotExpose(w, data, event)
Widget w;
XtPointer data;
XEvent *event;
{
XExposeEvent *ExEvent = (XExposeEvent *)event;
HTMLWidget hw = (HTMLWidget)data;
JotInfo *jptr;
jptr = GetJot(w);
if (jptr == NULL)
{
return;
}
if (jptr->pix == (Pixmap)NULL)
{
jptr->pix = XCreatePixmap(XtDisplay(w), XtWindow(w),
jptr->width, jptr->height,
XDefaultDepth(XtDisplay(w), XDefaultScreen(XtDisplay(w))));
if (jptr->pix == (Pixmap)NULL)
{
return;
}
XSetForeground(XtDisplay(w), hw->html.drawGC,
hw->core.background_pixel);
XFillRectangle(XtDisplay(w), jptr->pix,
hw->html.drawGC,
0, 0, jptr->width, jptr->height);
}
XCopyArea(XtDisplay(w), jptr->pix, XtWindow(w),
hw->html.drawGC,
ExEvent->x, ExEvent->y,
ExEvent->width, ExEvent->height,
ExEvent->x, ExEvent->y);
}
void
EVJotPress(w, data, event)
Widget w;
XtPointer data;
XEvent *event;
{
XButtonPressedEvent *BuEvent = (XButtonPressedEvent *)event;
HTMLWidget hw = (HTMLWidget)data;
JotInfo *jptr;
Stroke *sptr;
jptr = GetJot(w);
if (jptr == NULL)
{
return;
}
sptr = (Stroke *)malloc(sizeof(Stroke));
if (sptr == NULL)
{
return;
}
sptr->x = BuEvent->x;
sptr->y = BuEvent->y;
sptr->draw = False;
sptr->next = NULL;
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
XSetForeground(XtDisplay(w), hw->html.drawGC,
#ifdef MOTIF
hw->manager.foreground);
#else
hw->html.foreground);
#endif /* MOTIF */
XDrawPoint(XtDisplay(w), XtWindow(w),
hw->html.drawGC, sptr->x, sptr->y);
if (jptr->pix != (Pixmap)NULL)
{
XDrawPoint(XtDisplay(w), jptr->pix,
hw->html.drawGC, sptr->x, sptr->y);
}
AddStroke(jptr, sptr, True);
}
void
EVJotMove(w, data, event)
Widget w;
XtPointer data;
XEvent *event;
{
XPointerMovedEvent *MoEvent = (XPointerMovedEvent *)event;
HTMLWidget hw = (HTMLWidget)data;
JotInfo *jptr;
Stroke *sptr;
jptr = GetJot(w);
if (jptr == NULL)
{
return;
}
if (jptr->drawing == False)
{
return;
}
sptr = (Stroke *)malloc(sizeof(Stroke));
if (sptr == NULL)
{
return;
}
sptr->x = MoEvent->x;
sptr->y = MoEvent->y;
sptr->draw = True;
sptr->next = NULL;
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
XSetForeground(XtDisplay(w), hw->html.drawGC,
#ifdef MOTIF
hw->manager.foreground);
#else
hw->html.foreground);
#endif /* MOTIF */
XDrawLine(XtDisplay(w), XtWindow(w), hw->html.drawGC,
jptr->last_x, jptr->last_y, sptr->x, sptr->y);
if (jptr->pix != (Pixmap)NULL)
{
XDrawLine(XtDisplay(w), jptr->pix, hw->html.drawGC,
jptr->last_x, jptr->last_y, sptr->x, sptr->y);
}
AddStroke(jptr, sptr, True);
}
void
EVJotRelease(w, data, event)
Widget w;
XtPointer data;
XEvent *event;
{
XButtonReleasedEvent *BuEvent = (XButtonReleasedEvent *)event;
HTMLWidget hw = (HTMLWidget)data;
JotInfo *jptr;
Stroke *sptr;
jptr = GetJot(w);
if (jptr == NULL)
{
return;
}
if (jptr->drawing == False)
{
return;
}
sptr = (Stroke *)malloc(sizeof(Stroke));
if (sptr == NULL)
{
return;
}
sptr->x = BuEvent->x;
sptr->y = BuEvent->y;
sptr->draw = True;
sptr->next = NULL;
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
XSetForeground(XtDisplay(w), hw->html.drawGC,
#ifdef MOTIF
hw->manager.foreground);
#else
hw->html.foreground);
#endif /* MOTIF */
XDrawLine(XtDisplay(w), XtWindow(w), hw->html.drawGC,
jptr->last_x, jptr->last_y, sptr->x, sptr->y);
if (jptr->pix != (Pixmap)NULL)
{
XDrawLine(XtDisplay(w), jptr->pix, hw->html.drawGC,
jptr->last_x, jptr->last_y, sptr->x, sptr->y);
}
AddStroke(jptr, sptr, True);
}
char *
EJB_JOTfromJot(w)
Widget w;
{
int i, cnt;
int dlen, total;
u_long val;
unsigned char uchar;
JotInfo *jptr;
Stroke *sptr;
unsigned char *data;
unsigned char *dptr;
unsigned char *buffer;
unsigned char *bptr;
jptr = GetJot(w);
if (jptr == NULL)
{
return(NULL);
}
dlen = (2 * sizeof(u_long) + sizeof(char)) * jptr->stroke_cnt;
data = (unsigned char *)malloc(dlen);
cnt = 0;
sptr = jptr->strokes;
dptr = data;
while ((sptr != NULL)&&(cnt < jptr->stroke_cnt))
{
val = htonl((u_long)sptr->x);
bcopy((char *)&val, (char *)dptr, sizeof(u_long));
dptr = dptr + sizeof(u_long);
val = htonl((u_long)sptr->y);
bcopy((char *)&val, (char *)dptr, sizeof(u_long));
dptr = dptr + sizeof(u_long);
if (sptr->draw == False)
{
uchar = 0;
}
else
{
uchar = 1;
}
*dptr++ = uchar;
cnt++;
sptr = sptr->next;
}
for (i=cnt; i<jptr->stroke_cnt; i++)
{
val = 0;
bcopy((char *)&val, (char *)dptr, sizeof(u_long));
dptr = dptr + sizeof(u_long);
val = 0;
bcopy((char *)&val, (char *)dptr, sizeof(u_long));
dptr = dptr + sizeof(u_long);
uchar = 0;
*dptr++ = uchar;
}
fprintf(stderr, "Packaging up %d points\n", jptr->stroke_cnt);
cnt = 0;
dptr = data;
for (i=0; i<dlen; i++)
{
if ((*dptr == 0)||(*dptr == 1))
{
cnt++;
}
dptr++;
}
total = dlen + cnt + 1;
buffer = (unsigned char *)malloc(total);
bptr = buffer;
dptr = data;
for (i=0; i<dlen; i++)
{
if (*dptr == 0)
{
*bptr++ = (unsigned char)'o';
*bptr++ = (unsigned char)'O';
}
else if (*dptr == 'o')
{
*bptr++ = (unsigned char)'o';
*bptr++ = (unsigned char)'o';
}
else
{
*bptr++ = *dptr;
}
dptr++;
}
*bptr = (unsigned char)'\0';
free((char *)data);
return((char *)buffer);
}
typedef struct my_INK_POINT {
XY32 position;
INK_BUTTONS buttons;
} MY_INK_POINT;
unsigned char *
JOTfromJot(w, buffer_len)
Widget w;
int *buffer_len;
{
int i, cnt;
int dlen, total;
JotInfo *jptr;
Stroke *sptr;
MY_INK_POINT *dataArray;
INK_BUNDLE_RECORD *iptr;
INK_PENDATA_RECORD *pptr;
INK_END_RECORD *eptr;
unsigned char *buffer;
jptr = GetJot(w);
if (jptr == NULL)
{
return(NULL);
}
dlen = sizeof(MY_INK_POINT) * jptr->stroke_cnt;
dataArray = (MY_INK_POINT *)malloc(dlen);
cnt = 0;
sptr = jptr->strokes;
while ((sptr != NULL)&&(cnt < jptr->stroke_cnt));
{
dataArray[cnt].position.x = sptr->x;
dataArray[cnt].position.y = sptr->y;
dataArray[cnt].buttons = inkPointDefaultButtons;
dataArray[cnt].buttons |= flag0;
if ((sptr->next != NULL)&&(sptr->next->draw == False))
{
}
else
{
dataArray[cnt].buttons |= flag1;
}
cnt++;
sptr = sptr->next;
}
for (i=cnt; i<jptr->stroke_cnt; i++)
{
dataArray[i].position.x = 0;
dataArray[i].position.y = 0;
dataArray[i].buttons = inkPointDefaultButtons;
}
iptr = (INK_BUNDLE_RECORD *)malloc(inkRecordBundleSize);
iptr->header.recordType = inkRecordBundle;
iptr->header.recordLength = inkRecordBundleSize;
iptr->version = inkPointDefaultVersion;
iptr->compactionType = inkNoCompression;
iptr->flags = (inkPointDefaultBundleFlags | inkButtonDataPresent);
iptr->penUnitsPerX = inkPointDefaultPenUnitsPerX;
iptr->penUnitsPerY = inkPointDefaultPenUnitsPerY;
pptr = (INK_PENDATA_RECORD *)malloc(inkRecordPenDataSize(dlen));
pptr->header.recordType = inkRecordPenData;
pptr->header.recordLength = inkRecordPenDataSize(dlen);
pptr->bounds.origin.x = jptr->min_x;
pptr->bounds.origin.y = jptr->min_y;
pptr->bounds.size.w = jptr->max_x - jptr->min_x + 1;
pptr->bounds.size.h = jptr->max_y - jptr->min_y + 1;
bcopy((char *)dataArray, (char *)pptr->inkData, dlen);
free((char *)dataArray);
/*
pptr->inkData = dataArray;
*/
eptr = (INK_END_RECORD *)malloc(inkRecordEndSize);
eptr->header.recordType = inkRecordEnd;
total = inkRecordBundleSize + inkRecordPenDataSize(dlen) +
inkRecordEndSize;
buffer = (unsigned char *)malloc(total);
bcopy((char *)iptr, buffer, inkRecordBundleSize);
bcopy((char *)pptr, (char *)(buffer + inkRecordBundleSize),
inkRecordPenDataSize(dlen));
bcopy((char *)eptr, (char *)(buffer + inkRecordBundleSize +
inkRecordPenDataSize(dlen)), inkRecordEndSize);
free((char *)iptr);
free((char *)pptr);
free((char *)eptr);
*buffer_len = total;
return(buffer);
}
#endif /* MOTIF */
|