PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/windows/checkbox.c

https://github.com/jff/mathspad
C | 154 lines | 95 code | 18 blank | 41 comment | 12 complexity | 2695e112c819e725e76e5a863b6af7ab MD5 | raw file
  1. /*****************************************************************
  2. **
  3. ** MathSpad 0.60
  4. **
  5. ** Copyright 1996, Eindhoven University of Technology (EUT)
  6. **
  7. ** Permission to use, copy, modify and distribute this software
  8. ** and its documentation for any purpose is hereby granted
  9. ** without fee, provided that the above copyright notice appear
  10. ** in all copies and that both that copyright notice and this
  11. ** permission notice appear in supporting documentation, and
  12. ** that the name of EUT not be used in advertising or publicity
  13. ** pertaining to distribution of the software without specific,
  14. ** written prior permission. EUT makes no representations about
  15. ** the suitability of this software for any purpose. It is provided
  16. ** "as is" without express or implied warranty.
  17. **
  18. ** EUT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  19. ** SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  20. ** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL EUT
  21. ** BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  22. ** DAMAGES OR ANY DAMAGE WHATSOEVER RESULTING FROM
  23. ** LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  24. ** CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  25. ** OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  26. ** OF THIS SOFTWARE.
  27. **
  28. **
  29. ** Roland Backhouse & Richard Verhoeven.
  30. ** Department of Mathematics and Computing Science.
  31. ** Eindhoven University of Technology.
  32. **
  33. ********************************************************************/
  34. #include "mathpad.h"
  35. #include "system.h"
  36. #include "funcs.h"
  37. #include "sources.h"
  38. #include "checkbox.h"
  39. #include "message.h"
  40. typedef struct CHECKBOXINFO CHECKBOXINFO;
  41. struct CHECKBOXINFO {
  42. Window win_id;
  43. Bool check;
  44. CHECKBOXINFO *next,*prev;
  45. } ;
  46. static unsigned long checkbox_mask;
  47. static XSetWindowAttributes checkbox_attr;
  48. static void checkbox_draw(void *data)
  49. {
  50. CHECKBOXINFO *cbinfo = (CHECKBOXINFO *) data;
  51. if (cbinfo->check) {
  52. XDrawLine(display, cbinfo->win_id, get_GC(Normal, 0,0),
  53. 0, 0, CHECKBOXSIZE-1, CHECKBOXSIZE-1);
  54. XDrawLine(display, cbinfo->win_id, get_GC(Normal, 0,0),
  55. 0, CHECKBOXSIZE-1, CHECKBOXSIZE-1, 0);
  56. } else {
  57. XClearWindow(display, cbinfo->win_id);
  58. }
  59. }
  60. /*
  61. static void checkbox_press(void *data, XButtonEvent *event)
  62. {
  63. CHECKBOXINFO *cbinfo = (CHECKBOXINFO *) data;
  64. checkbox_draw(cdata);
  65. }
  66. */
  67. static void checkbox_release(void *data, XButtonEvent *event __attribute__((unused)))
  68. {
  69. CHECKBOXINFO *cbinfo = (CHECKBOXINFO *) data;
  70. if (aig(cbinfo->check = (!cbinfo->check))) {
  71. CHECKBOXINFO *h= cbinfo->next;
  72. while (h != cbinfo) {
  73. if (h->check) { h->check=MP_False; checkbox_draw((void*) h); }
  74. h=h->next;
  75. }
  76. }
  77. checkbox_draw(data);
  78. }
  79. FUNCTIONS checkboxfuncs = {
  80. NULL, checkbox_draw, NULL, NULL, checkbox_release };
  81. void checkbox_init(void)
  82. {
  83. checkbox_mask =
  84. (CWBackPixel | CWBorderPixel | CWWinGravity |
  85. CWEventMask | CWColormap );
  86. checkbox_attr.background_pixel = white_pixel;
  87. checkbox_attr.border_pixel = black_pixel;
  88. checkbox_attr.win_gravity = NorthWestGravity;
  89. checkbox_attr.colormap = colormap;
  90. checkbox_attr.event_mask = (ExposureMask | ButtonPressMask |
  91. ButtonReleaseMask | StructureNotifyMask |
  92. VisibilityChangeMask);
  93. }
  94. void checkbox_set(void *data, Bool on)
  95. {
  96. CHECKBOXINFO *cbinfo = (CHECKBOXINFO*) data;
  97. if (cbinfo->check != on) checkbox_release(data, NULL);
  98. }
  99. Bool checkbox_value(void *data)
  100. {
  101. return ((CHECKBOXINFO*)data)->check;
  102. }
  103. void checkbox_connect(void *box, void *other_box)
  104. {
  105. CHECKBOXINFO *cb1 = (CHECKBOXINFO*)box;
  106. CHECKBOXINFO *cb2 = (CHECKBOXINFO*)other_box;
  107. CHECKBOXINFO *h;
  108. cb1->next->prev = cb2;
  109. cb2->next->prev = cb1;
  110. h=cb1->next;
  111. cb1->next=cb2->next;
  112. cb2->next=h;
  113. }
  114. void *checkbox_make(Window parent, int xpos, int ypos, int value __attribute__((unused)))
  115. {
  116. CHECKBOXINFO *cbinfo;
  117. if ( (cbinfo = (CHECKBOXINFO *) malloc( sizeof(CHECKBOXINFO) )) == NULL) {
  118. message(MP_ERROR, translate("Out of memory in checkbox."));
  119. return NULL;
  120. } else {
  121. cbinfo->check = MP_False;
  122. cbinfo->prev = cbinfo->next = cbinfo;
  123. cbinfo->win_id = XCreateWindow(display, parent, xpos, ypos,
  124. CHECKBOXSIZE,CHECKBOXSIZE, 1,
  125. CopyFromParent, InputOutput,
  126. visual,
  127. checkbox_mask, &checkbox_attr);
  128. if (add_window(cbinfo->win_id, CHECKBOXWINDOW, parent,
  129. (void *)cbinfo, NULL))
  130. return ((void *) cbinfo);
  131. XDestroyWindow(display, cbinfo->win_id);
  132. free(cbinfo);
  133. return NULL;
  134. }
  135. }