00001
00020 #include "mfcpch.h"
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #ifdef __UNIX__
00024 #include <signal.h>
00025 #endif
00026 #include "grphics.h"
00027
00028
00029 #include "grphshm.h"
00030 #include "evntlst.h"
00031
00032 #define XSIZE_INCREMENT 8
00033 #define YSIZE_INCREMENT 30
00034
00035 void def_overlap_picture_ops(BOOL8 update);
00036
00037 WINCREATEFUNC create_func = WINFD::create;
00038 void (*overlap_func) (BOOL8) = def_overlap_picture_ops;
00039
00068 WINDOW WINFD::create(
00069 const char *name,
00070 INT8 window_type,
00071 INT16 xpos,
00072 INT16 ypos,
00073 INT16 xsize,
00074 INT16 ysize,
00075 float xmin,
00076 float xmax,
00077 float ymin,
00078 float ymax,
00079 BOOL8 downon,
00080 BOOL8 moveon,
00081 BOOL8 upon,
00082 BOOL8 keyon) {
00083 INT16 fd;
00084 CREATEOP *newop;
00085 WINDOW win;
00086
00087 #ifdef NO_X_WINDOWS
00088 return NO_WINDOW;
00089 #endif
00090
00091 if (xmin == xmax || ymin == ymax)
00092 return NO_WINDOW;
00093 if (maxsbfd == 0) {
00094 maxsbfd = 1;
00095 start_sbdaemon();
00096 }
00097
00098
00099 for (fd = 1; fd < maxsbfd && sbfds[fd].used; fd++);
00100 if (fd == maxsbfd) {
00101 if (maxsbfd == MAXWINDOWS)
00102 return NO_WINDOW;
00103 maxsbfd++;
00104 }
00105 win = &sbfds[fd];
00106 win->fd = fd;
00107 win->used = TRUE;
00108 win->downevent = downon;
00109 win->moveevent = moveon;
00110 win->upevent = upon;
00111 win->keyevent = keyon;
00112 win->click_handler = NULL;
00113 win->selection_handler = NULL;
00114 win->key_handler = NULL;
00115 win->destroy_handler = NULL;
00116 win->events = NULL;
00117 win->lastevent = NULL;
00118
00119 newop = (CREATEOP *) getshm (sizeof (CREATEOP));
00120 if (newop != NULL) {
00121 newop->header.fd = fd;
00122 newop->type = CREATE;
00123 newop->window_type = window_type;
00124
00125 strncpy (newop->name, name, MAXWINDOWNAME - 1);
00126 newop->name[MAXWINDOWNAME - 1] = '\0';
00127 newop->xpos = xpos;
00128 newop->ypos = ypos;
00129 newop->xsize = xsize;
00130 newop->ysize = ysize;
00131 newop->xmin = xmin;
00132 newop->xmax = xmax;
00133 newop->ymin = ymin;
00134 newop->ymax = ymax;
00135 newop->downon = downon;
00136 newop->moveon = moveon;
00137 newop->upon = upon;
00138 newop->keyon = keyon;
00139 }
00140 return win;
00141 }
00142
00150 void WINFD::Line_color_index(
00151 COLOUR index
00152 ) {
00153 ONEOP *newop;
00154
00155
00156 newop = (ONEOP *) getshm (sizeof (ONEOP));
00157 if (newop != NULL) {
00158 newop->header.fd = fd;
00159 newop->type = LINECOLOUR;
00160 newop->param.p.i = index;
00161 }
00162 }
00163
00164
00170 void WINFD::Perimeter_color_index(
00171 COLOUR index
00172 ) {
00173 ONEOP *newop;
00174
00175
00176 newop = (ONEOP *) getshm (sizeof (ONEOP));
00177 if (newop != NULL) {
00178 newop->header.fd = fd;
00179
00180 newop->type = PERIMETERCOLOUR;
00181 newop->param.p.i = index;
00182 }
00183 }
00184
00185
00191 void WINFD::Fill_color_index(
00192 COLOUR index
00193 ) {
00194 ONEOP *newop;
00195
00196
00197 newop = (ONEOP *) getshm (sizeof (ONEOP));
00198 if (newop != NULL) {
00199 newop->header.fd = fd;
00200 newop->type = FILLCOLOUR;
00201 newop->param.p.i = index;
00202 }
00203 }
00204
00205
00211 void WINFD::Fill_color(
00212 UINT8 red,
00213 UINT8 green,
00214 UINT8 blue) {
00215 ONEOP *newop;
00216 UINT32 packed_colour;
00217
00218 packed_colour = (blue << 24) + (green << 16) + (red << 8);
00219
00220 newop = (ONEOP *) getshm (sizeof (ONEOP));
00221 if (newop != NULL) {
00222 newop->header.fd = fd;
00223 newop->type = FILLCOLOUR;
00224
00225 newop->param.p.i = (INT32) packed_colour;
00226 }
00227 }
00228
00229
00235 void WINFD::Marker_color_index(
00236 COLOUR index
00237 ) {
00238 ONEOP *newop;
00239
00240
00241 newop = (ONEOP *) getshm (sizeof (ONEOP));
00242 if (newop != NULL) {
00243 newop->header.fd = fd;
00244 newop->type = MARKERCOLOUR;
00245 newop->param.p.i = index;
00246 }
00247 }
00248
00249
00255 void WINFD::Text_color_index(
00256 COLOUR index
00257 ) {
00258 ONEOP *newop;
00259
00260
00261 newop = (ONEOP *) getshm (sizeof (ONEOP));
00262 if (newop != NULL) {
00263 newop->header.fd = fd;
00264 newop->type = TEXTCOLOUR;
00265 newop->param.p.i = index;
00266 }
00267 }
00268
00269
00275 void WINFD::Text_font_index(
00276 INT16 index
00277 ) {
00278 ONEOP *newop;
00279
00280
00281 newop = (ONEOP *) getshm (sizeof (ONEOP));
00282 if (newop != NULL) {
00283 newop->header.fd = fd;
00284 newop->type = TEXTFONT;
00285 newop->param.p.i = index;
00286 }
00287 }
00288
00289
00295 void WINFD::Character_height(
00296 float height
00297 ) {
00298 ONEOP *newop;
00299
00300
00301 newop = (ONEOP *) getshm (sizeof (ONEOP));
00302 if (newop != NULL) {
00303 newop->header.fd = fd;
00304 newop->type = CHARHEIGHT;
00305 newop->param.p.f = height;
00306 }
00307 }
00308
00309
00315 void WINFD::Line_type(
00316 INT16 style
00317 ) {
00318 ONEOP *newop;
00319
00320
00321 newop = (ONEOP *) getshm (sizeof (ONEOP));
00322 if (newop != NULL) {
00323 newop->header.fd = fd;
00324 newop->type = LINETYPE;
00325 newop->param.p.i = style;
00326 }
00327 }
00328
00329
00335 void WINFD::Marker_type(
00336 INT16 type
00337 ) {
00338 ONEOP *newop;
00339
00340
00341 newop = (ONEOP *) getshm (sizeof (ONEOP));
00342 if (newop != NULL) {
00343 newop->header.fd = fd;
00344 newop->type = MARKERTYPE;
00345 newop->param.p.i = type;
00346 }
00347 }
00348
00349
00355 void WINFD::Interior_style(
00356 INT16 style,
00357 INT16 edged
00358 ) {
00359 TWOOP *newop;
00360
00361
00362 newop = (TWOOP *) getshm (sizeof (TWOOP));
00363 if (newop != NULL) {
00364 newop->header.fd = fd;
00365 newop->type = INTERIORSTYLE;
00366 newop->param.p[0].i = style;
00367 newop->param.p[1].i = edged;
00368 }
00369 }
00370
00371
00377 void WINFD::Marker_size(
00378 float size
00379 ) {
00380 TWOOP *newop;
00381
00382
00383 newop = (TWOOP *) getshm (sizeof (TWOOP));
00384 if (newop != NULL) {
00385 newop->header.fd = fd;
00386 newop->type = MARKERSIZE;
00387 newop->param.p[0].f = size;
00388 newop->param.p[1].i = FALSE;
00389 }
00390 }
00391
00392
00398 void WINFD::Move2d(
00399 float x,
00400 float y
00401 ) {
00402 TWOOP *newop;
00403
00404
00405 newop = (TWOOP *) getshm (sizeof (TWOOP));
00406 if (newop != NULL) {
00407 newop->header.fd = fd;
00408 newop->type = MOVE2D;
00409 newop->param.p[0].f = x;
00410 newop->param.p[1].f = y;
00411 }
00412 }
00413
00414
00420 void WINFD::Draw2d(
00421 float x,
00422 float y
00423 ) {
00424 TWOOP *newop;
00425
00426
00427 newop = (TWOOP *) getshm (sizeof (TWOOP));
00428 if (newop != NULL) {
00429 newop->header.fd = fd;
00430 newop->type = DRAW2D;
00431 newop->param.p[0].f = x;
00432 newop->param.p[1].f = y;
00433 }
00434 }
00435
00436
00442 void WINFD::Rectangle(
00443 float x1,
00444 float y1,
00445 float x2,
00446 float y2
00447 ) {
00448 FOUROP *newop;
00449
00450
00451 newop = (FOUROP *) getshm (sizeof (FOUROP));
00452 if (newop != NULL) {
00453 newop->header.fd = fd;
00454 newop->type = RECTANGLE;
00455 newop->param.p[0].f = x1;
00456 newop->param.p[1].f = y1;
00457 newop->param.p[2].f = x2;
00458 newop->param.p[3].f = y2;
00459 }
00460 }
00461
00462
00468 void WINFD::Text_alignment(
00469 INT32 h_select,
00470 INT32 v_select,
00471 float horiz,
00472 float vert
00473 ) {
00474 #ifndef WXSBSERVANT
00475 FOUROP *newop;
00476
00477
00478 newop = (FOUROP *) getshm (sizeof (FOUROP));
00479 if (newop != NULL) {
00480 newop->header.fd = fd;
00481 newop->type = TEXT_ALIGNMENT;
00482 newop->param.p[0].i = h_select;
00483 newop->param.p[1].i = v_select;
00484 newop->param.p[2].f = horiz;
00485 newop->param.p[3].f = vert;
00486 }
00487 #else // WXSBSERVANT
00488 #endif //WXSBSERVANT
00489 }
00490
00491
00497 void
00498 WINFD::Polyline2d (
00499 float clist[],
00500 INT16 numpts,
00501 INT16 flags
00502 ) {
00503 POLYOP *newop;
00504 INT32 floatcount;
00505
00506 floatcount = flags ? numpts * 3
00507 : numpts * 2;
00508
00509 newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1));
00510 if (newop != NULL) {
00511 newop->header.fd = fd;
00512 newop->type = POLYLINE2D;
00513
00514 newop->param.clist = newop->clist;
00515 newop->param.numpts = numpts;
00516 newop->param.flags = flags;
00517 memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float));
00518 }
00519 }
00520
00521
00527 void
00528 WINFD::Polygon2d (
00529 float clist[],
00530 INT16 numpts,
00531 INT16 flags
00532 ) {
00533 POLYOP *newop;
00534 INT32 floatcount;
00535
00536 floatcount = flags ? numpts * 3
00537 : numpts * 2;
00538
00539 newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1));
00540 if (newop != NULL) {
00541 newop->header.fd = fd;
00542 newop->type = POLYGON2D;
00543
00544 newop->param.clist = newop->clist;
00545 newop->param.numpts = numpts;
00546 newop->param.flags = flags;
00547 memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float));
00548 }
00549 }
00550
00551
00557 void
00558 WINFD::Polymarker2d (
00559 float clist[],
00560 INT16 numpts,
00561 INT16 flags
00562 ) {
00563 POLYOP *newop;
00564 INT32 floatcount;
00565
00566 floatcount = flags ? numpts * 3
00567 : numpts * 2;
00568
00569 newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1));
00570 if (newop != NULL) {
00571 newop->header.fd = fd;
00572 newop->type = POLYMARKER2D;
00573
00574 newop->param.clist = newop->clist;
00575 newop->param.numpts = numpts;
00576 newop->param.flags = flags;
00577 memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float));
00578 }
00579 }
00580
00581
00587 void WINFD::Text2d(
00588 float x,
00589 float y,
00590 const char *string,
00591 INT16 xform,
00592 INT16 more
00593 ) {
00594 TEXTOP *newop;
00595 INT16 length;
00596
00597 length = strlen (string) + 1;
00598 length += 3;
00599 length &= ~3;
00600
00601 newop = (TEXTOP *) getshm (sizeof (TEXTOP) + length - 4);
00602 if (newop != NULL) {
00603 newop->header.fd = fd;
00604 newop->type = TEXT2D;
00605 newop->param.x = x;
00606 newop->param.y = y;
00607 newop->param.string = newop->chars;
00608 newop->param.xform = xform;
00609 newop->param.more = more;
00610
00611 strcpy (newop->chars, string);
00612 }
00613 }
00614
00615
00621 void WINFD::Append_text(
00622 const char *string,
00623 INT16 xform,
00624 INT16 more
00625 ) {
00626 APPENDOP *newop;
00627 INT16 length;
00628
00629 length = strlen (string) + 1;
00630 length += 3;
00631 length &= ~3;
00632
00633 newop = (APPENDOP *) getshm (sizeof (APPENDOP) + length - 4);
00634 if (newop != NULL) {
00635 newop->header.fd = fd;
00636 newop->type = APPENDTEXT;
00637 newop->param.string = newop->chars;
00638 newop->param.xform = xform;
00639 newop->param.more = more;
00640
00641 strcpy (newop->chars, string);
00642 }
00643 }
00644
00645
00651 void WINFD::Ellipse(
00652 float x_radius,
00653 float y_radius,
00654 float x_center,
00655 float y_center,
00656 float rotation
00657 ) {
00658 EIGHTOP *newop;
00659
00660
00661 newop = (EIGHTOP *) getshm (sizeof (EIGHTOP));
00662 if (newop != NULL) {
00663 newop->header.fd = fd;
00664 newop->type = ELLIPSE;
00665
00666 newop->param.p[0].f = x_radius;
00667 newop->param.p[1].f = y_radius;
00668 newop->param.p[2].f = x_center;
00669 newop->param.p[3].f = y_center;
00670 newop->param.p[4].f = rotation;
00671 }
00672 }
00673
00674
00680 void WINFD::Arc(
00681 float x_radius,
00682 float y_radius,
00683 float x_center,
00684 float y_center,
00685 float start,
00686 float stop,
00687 float rotation,
00688 INT16 close_type
00689 ) {
00690 EIGHTOP *newop;
00691
00692
00693 newop = (EIGHTOP *) getshm (sizeof (EIGHTOP));
00694 if (newop != NULL) {
00695 newop->header.fd = fd;
00696 newop->type = ARC;
00697
00698 newop->param.p[0].f = x_radius;
00699 newop->param.p[1].f = y_radius;
00700 newop->param.p[2].f = x_center;
00701 newop->param.p[3].f = y_center;
00702 newop->param.p[4].f = start;
00703 newop->param.p[5].f = stop;
00704 newop->param.p[6].f = rotation;
00705 newop->param.p[7].i = close_type;
00706 }
00707 }
00708
00709
00713 WINFD::WINFD() {
00714 fd = -1;
00715 used = FALSE;
00716 downevent = FALSE;
00717 moveevent = FALSE;
00718 upevent = FALSE;
00719 keyevent = FALSE;
00720 click_handler = NULL;
00721 selection_handler = NULL;
00722 key_handler = NULL;
00723 destroy_handler = NULL;
00724 events = NULL;
00725 lastevent = NULL;
00726 }
00727
00728
00729 WINFD::~WINFD () {
00730 }
00731
00732
00738 void WINFD::Destroy_window() {
00739 ONEOP *newop;
00740
00741 if (fd < 1 || fd > maxsbfd || sbfds[fd].used == FALSE) {
00742 return;
00743 }
00744 else {
00745 Clear_event_queue();
00746 sbfds[fd].used = FALSE;
00747 sbfds[fd].click_handler = NULL;
00748
00749 newop = (ONEOP *) getshm (sizeof (ONEOP));
00750 if (newop != NULL) {
00751 newop->header.fd = fd;
00752 newop->type = DESTROY;
00753 }
00754 }
00755 }
00756
00757
00763 void WINFD::Clear_event_queue() {
00764 INT16 fd;
00765 GRAPHICS_EVENT *event;
00766 GRAPHICS_EVENT *nextevent;
00767
00768 if (this == NULL) {
00769 for (fd = 1; fd < maxsbfd; fd++) {
00770 if (sbfds[fd].used) {
00771 sbfds[fd].Clear_event_queue ();
00772 }
00773 }
00774 }
00775 else {
00776 for (event = events; event != NULL; event = nextevent) {
00777 nextevent = event->next;
00778 delete event;
00779 }
00780 events = NULL;
00781 }
00782 }
00783
00784
00790 void WINFD::Clear_view_surface() {
00791 ONEOP *newop;
00792
00793
00794 newop = (ONEOP *) getshm (sizeof (ONEOP));
00795 if (newop != NULL) {
00796 newop->header.fd = fd;
00797 newop->type = CLEAR;
00798 }
00799 }
00800
00801
00807 void WINFD::Re_compute_colourmap() {
00808 ONEOP *newop;
00809
00810
00811 newop = (ONEOP *) getshm (sizeof (ONEOP));
00812 if (newop != NULL) {
00813 newop->header.fd = fd;
00814 newop->type = RE_COMP_COLMAP;
00815 }
00816
00817
00818
00819
00820
00821
00822
00823 }
00824
00825
00831 void WINFD::Vdc_extent(
00832 float Xmin,
00833 float Ymin,
00834 float Xmax,
00835 float Ymax
00836 ) {
00837 EIGHTOP *newop;
00838
00839
00840 newop = (EIGHTOP *) getshm (sizeof (EIGHTOP));
00841 if (newop != NULL) {
00842 newop->header.fd = fd;
00843 newop->type = VDCEXTENT;
00844 newop->param.p[0].f = Xmin;
00845 newop->param.p[1].f = Ymin;
00846 newop->param.p[2].f = 0.0f;
00847 newop->param.p[3].f = Xmax;
00848 newop->param.p[4].f = Ymax;
00849 newop->param.p[5].f = 0.0f;
00850 }
00851 }
00852
00853
00859 void WINFD::Set_echo(
00860 ECHO_TYPE echo_type,
00861 float xorig,
00862 float yorig
00863 ) {
00864 FOUROP *newop;
00865
00866
00867 newop = (FOUROP *) getshm (sizeof (FOUROP));
00868 if (newop != NULL) {
00869 newop->header.fd = fd;
00870 newop->type = SETECHO;
00871 newop->param.p[0].i = echo_type;
00872 newop->param.p[1].f = xorig;
00873 newop->param.p[2].f = yorig;
00874 }
00875 }
00876
00877
00886 DLLSYM void def_overlap_picture_ops(
00887 BOOL8 update
00888 ) {
00889 ONEOP *newop;
00890 INT16 fd;
00891
00892 if (update) {
00893 for (fd = 1; fd < maxsbfd; fd++) {
00894 if (sbfds[fd].used) {
00895
00896 newop = (ONEOP *) getshm (sizeof (ONEOP));
00897 if (newop != NULL) {
00898 newop->header.fd = fd;
00899
00900 newop->type = MAKECURRENT;
00901 }
00902 }
00903 }
00904 }
00905 kick_daemon(FLUSH_OUT);
00906 }
00907
00908
00916 void WINFD::Make_picture_current() {
00917 ONEOP *newop;
00918
00919 if (this == NULL || fd <= 0) {
00920 overlap_picture_ops(TRUE);
00921 }
00922 else {
00923
00924 newop = (ONEOP *) getshm (sizeof (ONEOP));
00925 if (newop != NULL) {
00926 newop->header.fd = fd;
00927 newop->type = MAKECURRENT;
00928 kick_daemon(FLUSH_IN);
00929 }
00930 }
00931 }
00932
00933
00939 void WINFD::Synchronize_windows(
00940 WINDOW fd2
00941 ) {
00942 ONEOP *newop;
00943
00944
00945 newop = (ONEOP *) getshm (sizeof (ONEOP));
00946 if (newop != NULL) {
00947 newop->header.fd = fd;
00948 newop->type = SYNCWIN;
00949 newop->param.p.i = fd2->fd;
00950 }
00951 }
00952
00953
00961 void WINFD::Set_click_handler(
00962 EVENT_HANDLER handler
00963 ) {
00964 click_handler = handler;
00965 }
00966
00967
00975 void WINFD::Set_selection_handler(
00976 EVENT_HANDLER handler
00977 ) {
00978 selection_handler = handler;
00979 }
00980
00981
00989 void WINFD::Set_key_handler(
00990 EVENT_HANDLER handler
00991 ) {
00992 key_handler = handler;
00993 }
00994
00995
01003 void WINFD::Set_destroy_handler(
01004 EVENT_HANDLER handler
01005 ) {
01006 destroy_handler = handler;
01007 }
01008
01009 #ifdef WXSBSERVANT
01010
01011 #endif //WXSBSERVANT