home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / src / wx_event.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  5.7 KB  |  268 lines

  1. /*
  2.  * File:     wx_event.cc
  3.  * Purpose:  wxEvent class definition
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-3-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #include <windows.h>
  30. #include <iostream.h>
  31.  
  32. #include "common.h"
  33. #include "wx_frame.h"
  34. #include "wx_dc.h"
  35. #include "wx_canvs.h"
  36.  
  37. wxEvent::wxEvent()
  38. {
  39. #ifdef wx_motif
  40.   event_handle = NULL;
  41. #endif
  42. #ifdef wx_xview
  43.   event_handle = NULL;
  44. #endif
  45. #ifdef wx_msw
  46.   event = 0;
  47.   flags = 0;
  48.   x = 0.0;
  49.   y = 0.0;
  50. #endif
  51.   index = 0;
  52.   string = NULL;
  53.   client_data = NULL;
  54. }
  55.  
  56. #ifdef wx_xview
  57. wxEvent::wxEvent(Event *x_event)
  58. {
  59.   event_handle = x_event;
  60.   if (x_event)
  61.   {
  62.     x = (float)event_x(event_handle);
  63.     y = (float)event_y(event_handle);
  64.   }
  65.   index = 0;
  66.   string = NULL;
  67.   client_data = NULL;
  68. }
  69. #endif
  70.  
  71. Bool wxEvent::ControlDown(void)
  72. {
  73. #ifdef wx_motif
  74.   return event_handle->state & ControlMask;
  75. #endif
  76. #ifdef wx_xview
  77.   return event_ctrl_is_down(event_handle);
  78. #endif
  79. #ifdef wx_msw
  80.   return (flags & MK_CONTROL);
  81. #endif
  82. }
  83.  
  84. Bool wxEvent::ShiftDown(void)
  85. {
  86. #ifdef wx_motif
  87.   return event_handle->state & ShiftMask;
  88. #endif
  89. #ifdef wx_xview
  90.   return event_shift_is_down(event_handle);
  91. #endif
  92. #ifdef wx_msw
  93.   return (flags & MK_SHIFT);
  94. #endif
  95. }
  96.  
  97. // Is a button event (*doesn't* mean: is any button *down*?)
  98. Bool wxEvent::IsButton(void)
  99. {
  100. #ifdef wx_motif
  101.   return TRUE;
  102. #endif
  103. #ifdef wx_xview
  104.   return event_is_button(event_handle);
  105. #endif
  106. #ifdef wx_msw
  107.   return (event == wxLEFTUP || event == wxLEFTDOWN ||
  108.           event == wxRIGHTUP || event == wxRIGHTDOWN ||
  109.           event == wxMIDDLEUP || event == wxMIDDLEDOWN);
  110. #endif
  111. }
  112.  
  113. // Any button is down
  114. Bool wxEvent::ButtonDown(void)
  115. {
  116.   return (Button(1) || Button(2) || Button(3));
  117. }
  118.  
  119. // True if button down (1 = left, 2 = middle, 3 = right)
  120. Bool wxEvent::Button(int but)
  121. {
  122. #ifdef wx_motif
  123.   switch (but)
  124.   {
  125.     case 1:
  126.       return button1Pressed;
  127.       break;
  128.     case 2:
  129.       return button2Pressed;
  130.       break;
  131.     case 3:
  132.       return button3Pressed;
  133.       break;
  134.   }
  135.   return FALSE;
  136. #endif
  137. #ifdef wx_xview
  138.   return event_id(event_handle) == BUT(but);
  139. #endif
  140. #ifdef wx_msw
  141.   return ((but == 1 && (flags & MK_LBUTTON)) ||
  142.           (but == 2 && (flags & MK_MBUTTON)) ||
  143.           (but == 3 && (flags & MK_RBUTTON)));
  144. #endif
  145. }
  146.  
  147. Bool wxEvent::LeftDown(void)
  148. {
  149. #ifdef wx_motif
  150.   return (event_handle->type == ButtonPress && (event_handle->button == Button1));
  151. #endif
  152. #ifdef wx_xview
  153.   return (event_is_down(event_handle) && event_id(event_handle) == BUT(1));
  154. #endif
  155. #ifdef wx_msw
  156.   return (event == wxLEFTDOWN);
  157. #endif
  158. }
  159.  
  160. Bool wxEvent::MiddleDown(void)
  161. {
  162. #ifdef wx_motif
  163.   return (event_handle->type == ButtonPress && (event_handle->button == Button2));
  164. #endif
  165. #ifdef wx_xview
  166.   return (event_is_down(event_handle) && event_id(event_handle) == BUT(2));
  167. #endif
  168. #ifdef wx_msw
  169.   return (event == wxMIDDLEDOWN);
  170. #endif
  171. }
  172.  
  173. Bool wxEvent::RightDown(void)
  174. {
  175. #ifdef wx_motif
  176.   return (event_handle->type == ButtonPress && (event_handle->button == Button3));
  177. #endif
  178. #ifdef wx_xview
  179.   return (event_is_down(event_handle) && event_id(event_handle) == BUT(3));
  180. #endif
  181. #ifdef wx_msw
  182.   return (event == wxRIGHTDOWN);
  183. #endif
  184. }
  185.  
  186. Bool wxEvent::LeftUp(void)
  187. {
  188. #ifdef wx_motif
  189.   return (event_handle->type == ButtonRelease && (event_handle->button == Button1));
  190. #endif
  191. #ifdef wx_xview
  192.   return (event_is_button(event_handle) && event_id(event_handle) == BUT(1) && 
  193.           event_is_up(event_handle));
  194. #endif
  195. #ifdef wx_msw
  196.   return (event == wxLEFTUP);
  197. #endif
  198. }
  199.  
  200. Bool wxEvent::MiddleUp(void)
  201. {
  202. #ifdef wx_motif
  203.   return (event_handle->type == ButtonRelease && (event_handle->button == Button2));
  204. #endif
  205. #ifdef wx_xview
  206.   return (event_is_button(event_handle) && event_id(event_handle) == BUT(2) &&
  207.           event_is_up(event_handle));
  208. #endif
  209. #ifdef wx_msw
  210.   return (event == wxMIDDLEUP);
  211. #endif
  212. }
  213.  
  214. Bool wxEvent::RightUp(void)
  215. {
  216. #ifdef wx_motif
  217.   return (event_handle->type == ButtonRelease && (event_handle->button == Button3));
  218. #endif
  219. #ifdef wx_xview
  220.   return (event_is_button(event_handle) && event_id(event_handle) == BUT(3) &&
  221.           event_is_up(event_handle));
  222. #endif
  223. #ifdef wx_msw
  224.   return (event == wxRIGHTUP);
  225. #endif
  226. }
  227.  
  228. Bool wxEvent::Dragging(void)
  229. {
  230. #ifdef wx_motif
  231.   return ((event_handle->type == MotionNotify) && ButtonDown());
  232.   return FALSE;
  233. #endif
  234. #ifdef wx_xview
  235.   return (event_id(event_handle) == LOC_DRAG);
  236. #endif
  237. #ifdef wx_msw
  238.   return ((event == wxMOVE) && ButtonDown());
  239. #endif
  240. }
  241.  
  242. void wxEvent::Position(float *xpos, float *ypos)
  243. {
  244. #ifdef wx_motif
  245.   *xpos = x;
  246.   *ypos = y;
  247. #endif
  248. #ifdef wx_xview
  249.   *xpos = x;
  250.   *ypos = y;
  251. #endif
  252. #ifdef wx_msw
  253.   *xpos = x;
  254.   *ypos = y;
  255. #endif
  256. }
  257.  
  258. int wxEvent::Index(void)
  259. {
  260.   return index;
  261. }
  262.  
  263. char *wxEvent::String(void)
  264. {
  265.   return string;
  266. }
  267.  
  268.