Convert crlf->lf line endings.
[mesa.git] / src / glut / os2 / glut_cursor.cpp
index 9784e9b62260e4ee7600f18abaa703a21cdb4e7d..0db0aa64a427c275dbba5bebcfba53beb135d254 100644 (file)
-\r
-/* Copyright (c) Mark J. Kilgard, 1995, 1998. */\r
-\r
-/* This program is freely distributable without licensing fees\r
-   and is provided without guarantee or warrantee expressed or\r
-   implied. This program is -not- in the public domain. */\r
-\r
-#include "glutint.h"\r
-\r
-#if !defined(_WIN32) && !defined(__OS2PM__)\r
-#include <X11/Xatom.h>  /* For XA_CURSOR */\r
-#include <X11/cursorfont.h>\r
-#endif\r
-\r
-typedef struct _CursorTable {\r
-#if defined(_WIN32)\r
-  char* glyph;\r
-#else\r
-  int glyph;\r
-#endif\r
-  Cursor cursor;\r
-} CursorTable;\r
-/* *INDENT-OFF* */\r
-\r
-static CursorTable cursorTable[] = {\r
-  {XC_arrow, None},              /* GLUT_CURSOR_RIGHT_ARROW */\r
-  {XC_top_left_arrow, None},     /* GLUT_CURSOR_LEFT_ARROW */\r
-  {XC_hand1, None},              /* GLUT_CURSOR_INFO */\r
-  {XC_pirate, None},             /* GLUT_CURSOR_DESTROY */\r
-  {XC_question_arrow, None},     /* GLUT_CURSOR_HELP */\r
-  {XC_exchange, None},           /* GLUT_CURSOR_CYCLE */\r
-  {XC_spraycan, None},           /* GLUT_CURSOR_SPRAY */\r
-  {XC_watch, None},              /* GLUT_CURSOR_WAIT */\r
-  {XC_xterm, None},              /* GLUT_CURSOR_TEXT */\r
-  {XC_crosshair, None},                  /* GLUT_CURSOR_CROSSHAIR */\r
-  {XC_sb_v_double_arrow, None},          /* GLUT_CURSOR_UP_DOWN */\r
-  {XC_sb_h_double_arrow, None},          /* GLUT_CURSOR_LEFT_RIGHT */\r
-  {XC_top_side, None},           /* GLUT_CURSOR_TOP_SIDE */\r
-  {XC_bottom_side, None},        /* GLUT_CURSOR_BOTTOM_SIDE */\r
-  {XC_left_side, None},                  /* GLUT_CURSOR_LEFT_SIDE */\r
-  {XC_right_side, None},         /* GLUT_CURSOR_RIGHT_SIDE */\r
-  {XC_top_left_corner, None},    /* GLUT_CURSOR_TOP_LEFT_CORNER */\r
-  {XC_top_right_corner, None},   /* GLUT_CURSOR_TOP_RIGHT_CORNER */\r
-  {XC_bottom_right_corner, None}, /* GLUT_CURSOR_BOTTOM_RIGHT_CORNER */\r
-  {XC_bottom_left_corner, None},  /* GLUT_CURSOR_BOTTOM_LEFT_CORNER */\r
-};\r
-/* *INDENT-ON* */\r
-\r
-#if !defined(_WIN32) && !defined(__OS2PM__)\r
-static Cursor blankCursor = None;\r
-static Cursor fullCrosshairCusor = None;\r
-\r
-/* SGI X server's support a special property called the\r
-   _SGI_CROSSHAIR_CURSOR that when installed as a window's\r
-   cursor, becomes a full screen crosshair cursor.  SGI\r
-   has special cursor generation hardware for this case. */\r
-static Cursor\r
-getFullCrosshairCursor(void)\r
-{\r
-  Cursor cursor;\r
-  Atom crosshairAtom, actualType;\r
-  int rc, actualFormat;\r
-  unsigned long n, left;\r
-  unsigned long *value;\r
-\r
-  if (fullCrosshairCusor == None) {\r
-    crosshairAtom = XInternAtom(__glutDisplay,\r
-      "_SGI_CROSSHAIR_CURSOR", True);\r
-    if (crosshairAtom != None) {\r
-      value = 0;        /* Make compiler happy. */\r
-      rc = XGetWindowProperty(__glutDisplay, __glutRoot,\r
-        crosshairAtom, 0, 1, False, XA_CURSOR, &actualType,\r
-        &actualFormat, &n, &left, (unsigned char **) &value);\r
-      if (rc == Success && actualFormat == 32 && n >= 1) {\r
-        cursor = value[0];\r
-        XFree(value);\r
-        return cursor;\r
-      }\r
-    }\r
-  }\r
-  return XCreateFontCursor(__glutDisplay, XC_crosshair);\r
-}\r
-\r
-/* X11 forces you to create a blank cursor if you want\r
-   to disable the cursor. */\r
-static Cursor\r
-makeBlankCursor(void)\r
-{\r
-  static char data[1] =\r
-  {0};\r
-  Cursor cursor;\r
-  Pixmap blank;\r
-  XColor dummy;\r
-\r
-  blank = XCreateBitmapFromData(__glutDisplay, __glutRoot,\r
-    data, 1, 1);\r
-  if (blank == None)\r
-    __glutFatalError("out of memory.");\r
-  cursor = XCreatePixmapCursor(__glutDisplay, blank, blank,\r
-    &dummy, &dummy, 0, 0);\r
-  XFreePixmap(__glutDisplay, blank);\r
-\r
-  return cursor;\r
-}\r
-#endif /* !_WIN32 && !__OS2PM__*/\r
-\r
-/* Win32 and X11 use this same function to accomplish\r
-   fairly different tasks.  X11 lets you just define the\r
-   cursor for a window and the window system takes care\r
-   of making sure that the window's cursor is installed\r
-   when the mouse is in the window.  Win32 requires the\r
-   application to handle a WM_SETCURSOR message to install\r
-   the right cursor when windows are entered.  Think of\r
-   the Win32 __glutSetCursor (called from __glutWindowProc)\r
-   as "install cursor".  Think of the X11 __glutSetCursor\r
-   (called from glutSetCursor) as "define cursor". */\r
-void\r
-__glutSetCursor(GLUTwindow *window)\r
-{\r
-  int cursor = window->cursor;\r
-  Cursor xcursor = 0;\r
-\r
-  if (cursor >= 0 &&\r
-    cursor < sizeof(cursorTable) / sizeof(cursorTable[0])) {\r
-    if (cursorTable[cursor].cursor == None) {\r
-      cursorTable[cursor].cursor = XCreateFontCursor(__glutDisplay,\r
-        cursorTable[cursor].glyph);\r
-    }\r
-    xcursor = cursorTable[cursor].cursor;\r
-  } else {\r
-    /* Special cases. */\r
-    switch (cursor) {\r
-    case GLUT_CURSOR_INHERIT:\r
-#if defined(_WIN32)\r
-      while (window->parent) {\r
-        window = window->parent;\r
-        if (window->cursor != GLUT_CURSOR_INHERIT) {\r
-          __glutSetCursor(window);\r
-          return;\r
-        }\r
-      }\r
-      /* XXX Default to an arrow cursor.  Is this\r
-         right or should we be letting the default\r
-         window proc be installing some system cursor? */\r
-      xcursor = cursorTable[0].cursor;\r
-      if (xcursor == NULL) {\r
-        xcursor =\r
-          cursorTable[0].cursor =\r
-          LoadCursor(NULL, cursorTable[0].glyph);\r
-      }\r
-\r
-#elif defined(__OS2PM__)\r
-//todo\r
-      xcursor = None;\r
-\r
-#else\r
-      xcursor = None;\r
-#endif\r
-      break;\r
-    case GLUT_CURSOR_NONE:\r
-#if defined(_WIN32) || defined(__OS2PM__)\r
-      xcursor = NULL;\r
-#else\r
-      if (blankCursor == None) {\r
-        blankCursor = makeBlankCursor();\r
-      }\r
-      xcursor = blankCursor;\r
-#endif\r
-      break;\r
-    case GLUT_CURSOR_FULL_CROSSHAIR:\r
-#if defined(_WIN32)\r
-      xcursor = (HICON) IDC_CROSS;\r
-#elif defined(__OS2PM__)\r
-//todo\r
-#else\r
-      if (fullCrosshairCusor == None) {\r
-        fullCrosshairCusor = getFullCrosshairCursor();\r
-      }\r
-      xcursor = fullCrosshairCusor;\r
-#endif\r
-      break;\r
-    }\r
-  }\r
-  XDefineCursor(__glutDisplay,\r
-    window->win, xcursor);\r
-  XFlush(__glutDisplay);\r
-}\r
-\r
-/* CENTRY */\r
-void GLUTAPIENTRY\r
-glutSetCursor(int cursor)\r
-{\r
-#ifdef _WIN32\r
-  POINT point;\r
-\r
-  __glutCurrentWindow->cursor = cursor;\r
-  /* Are we in the window right now?  If so,\r
-     install the cursor. */\r
-  GetCursorPos(&point);\r
-  if (__glutCurrentWindow->win == WindowFromPoint(point)) {\r
-    __glutSetCursor(__glutCurrentWindow);\r
-  }\r
-#elif defined(__OS2PM__)\r
-//todo\r
-#else\r
-  __glutCurrentWindow->cursor = cursor;\r
-  __glutSetCursor(__glutCurrentWindow);\r
-#endif\r
-}\r
-/* ENDCENTRY */\r
+
+/* Copyright (c) Mark J. Kilgard, 1995, 1998. */
+
+/* This program is freely distributable without licensing fees
+   and is provided without guarantee or warrantee expressed or
+   implied. This program is -not- in the public domain. */
+
+#include "glutint.h"
+
+#if !defined(_WIN32) && !defined(__OS2PM__)
+#include <X11/Xatom.h>  /* For XA_CURSOR */
+#include <X11/cursorfont.h>
+#endif
+
+typedef struct _CursorTable {
+#if defined(_WIN32)
+  char* glyph;
+#else
+  int glyph;
+#endif
+  Cursor cursor;
+} CursorTable;
+/* *INDENT-OFF* */
+
+static CursorTable cursorTable[] = {
+  {XC_arrow, None},              /* GLUT_CURSOR_RIGHT_ARROW */
+  {XC_top_left_arrow, None},     /* GLUT_CURSOR_LEFT_ARROW */
+  {XC_hand1, None},              /* GLUT_CURSOR_INFO */
+  {XC_pirate, None},             /* GLUT_CURSOR_DESTROY */
+  {XC_question_arrow, None},     /* GLUT_CURSOR_HELP */
+  {XC_exchange, None},           /* GLUT_CURSOR_CYCLE */
+  {XC_spraycan, None},           /* GLUT_CURSOR_SPRAY */
+  {XC_watch, None},              /* GLUT_CURSOR_WAIT */
+  {XC_xterm, None},              /* GLUT_CURSOR_TEXT */
+  {XC_crosshair, None},                  /* GLUT_CURSOR_CROSSHAIR */
+  {XC_sb_v_double_arrow, None},          /* GLUT_CURSOR_UP_DOWN */
+  {XC_sb_h_double_arrow, None},          /* GLUT_CURSOR_LEFT_RIGHT */
+  {XC_top_side, None},           /* GLUT_CURSOR_TOP_SIDE */
+  {XC_bottom_side, None},        /* GLUT_CURSOR_BOTTOM_SIDE */
+  {XC_left_side, None},                  /* GLUT_CURSOR_LEFT_SIDE */
+  {XC_right_side, None},         /* GLUT_CURSOR_RIGHT_SIDE */
+  {XC_top_left_corner, None},    /* GLUT_CURSOR_TOP_LEFT_CORNER */
+  {XC_top_right_corner, None},   /* GLUT_CURSOR_TOP_RIGHT_CORNER */
+  {XC_bottom_right_corner, None}, /* GLUT_CURSOR_BOTTOM_RIGHT_CORNER */
+  {XC_bottom_left_corner, None},  /* GLUT_CURSOR_BOTTOM_LEFT_CORNER */
+};
+/* *INDENT-ON* */
+
+#if !defined(_WIN32) && !defined(__OS2PM__)
+static Cursor blankCursor = None;
+static Cursor fullCrosshairCusor = None;
+
+/* SGI X server's support a special property called the
+   _SGI_CROSSHAIR_CURSOR that when installed as a window's
+   cursor, becomes a full screen crosshair cursor.  SGI
+   has special cursor generation hardware for this case. */
+static Cursor
+getFullCrosshairCursor(void)
+{
+  Cursor cursor;
+  Atom crosshairAtom, actualType;
+  int rc, actualFormat;
+  unsigned long n, left;
+  unsigned long *value;
+
+  if (fullCrosshairCusor == None) {
+    crosshairAtom = XInternAtom(__glutDisplay,
+      "_SGI_CROSSHAIR_CURSOR", True);
+    if (crosshairAtom != None) {
+      value = 0;        /* Make compiler happy. */
+      rc = XGetWindowProperty(__glutDisplay, __glutRoot,
+        crosshairAtom, 0, 1, False, XA_CURSOR, &actualType,
+        &actualFormat, &n, &left, (unsigned char **) &value);
+      if (rc == Success && actualFormat == 32 && n >= 1) {
+        cursor = value[0];
+        XFree(value);
+        return cursor;
+      }
+    }
+  }
+  return XCreateFontCursor(__glutDisplay, XC_crosshair);
+}
+
+/* X11 forces you to create a blank cursor if you want
+   to disable the cursor. */
+static Cursor
+makeBlankCursor(void)
+{
+  static char data[1] =
+  {0};
+  Cursor cursor;
+  Pixmap blank;
+  XColor dummy;
+
+  blank = XCreateBitmapFromData(__glutDisplay, __glutRoot,
+    data, 1, 1);
+  if (blank == None)
+    __glutFatalError("out of memory.");
+  cursor = XCreatePixmapCursor(__glutDisplay, blank, blank,
+    &dummy, &dummy, 0, 0);
+  XFreePixmap(__glutDisplay, blank);
+
+  return cursor;
+}
+#endif /* !_WIN32 && !__OS2PM__*/
+
+/* Win32 and X11 use this same function to accomplish
+   fairly different tasks.  X11 lets you just define the
+   cursor for a window and the window system takes care
+   of making sure that the window's cursor is installed
+   when the mouse is in the window.  Win32 requires the
+   application to handle a WM_SETCURSOR message to install
+   the right cursor when windows are entered.  Think of
+   the Win32 __glutSetCursor (called from __glutWindowProc)
+   as "install cursor".  Think of the X11 __glutSetCursor
+   (called from glutSetCursor) as "define cursor". */
+void
+__glutSetCursor(GLUTwindow *window)
+{
+  int cursor = window->cursor;
+  Cursor xcursor = 0;
+
+  if (cursor >= 0 &&
+    cursor < sizeof(cursorTable) / sizeof(cursorTable[0])) {
+    if (cursorTable[cursor].cursor == None) {
+      cursorTable[cursor].cursor = XCreateFontCursor(__glutDisplay,
+        cursorTable[cursor].glyph);
+    }
+    xcursor = cursorTable[cursor].cursor;
+  } else {
+    /* Special cases. */
+    switch (cursor) {
+    case GLUT_CURSOR_INHERIT:
+#if defined(_WIN32)
+      while (window->parent) {
+        window = window->parent;
+        if (window->cursor != GLUT_CURSOR_INHERIT) {
+          __glutSetCursor(window);
+          return;
+        }
+      }
+      /* XXX Default to an arrow cursor.  Is this
+         right or should we be letting the default
+         window proc be installing some system cursor? */
+      xcursor = cursorTable[0].cursor;
+      if (xcursor == NULL) {
+        xcursor =
+          cursorTable[0].cursor =
+          LoadCursor(NULL, cursorTable[0].glyph);
+      }
+
+#elif defined(__OS2PM__)
+//todo
+      xcursor = None;
+
+#else
+      xcursor = None;
+#endif
+      break;
+    case GLUT_CURSOR_NONE:
+#if defined(_WIN32) || defined(__OS2PM__)
+      xcursor = NULL;
+#else
+      if (blankCursor == None) {
+        blankCursor = makeBlankCursor();
+      }
+      xcursor = blankCursor;
+#endif
+      break;
+    case GLUT_CURSOR_FULL_CROSSHAIR:
+#if defined(_WIN32)
+      xcursor = (HICON) IDC_CROSS;
+#elif defined(__OS2PM__)
+//todo
+#else
+      if (fullCrosshairCusor == None) {
+        fullCrosshairCusor = getFullCrosshairCursor();
+      }
+      xcursor = fullCrosshairCusor;
+#endif
+      break;
+    }
+  }
+  XDefineCursor(__glutDisplay,
+    window->win, xcursor);
+  XFlush(__glutDisplay);
+}
+
+/* CENTRY */
+void GLUTAPIENTRY
+glutSetCursor(int cursor)
+{
+#ifdef _WIN32
+  POINT point;
+
+  __glutCurrentWindow->cursor = cursor;
+  /* Are we in the window right now?  If so,
+     install the cursor. */
+  GetCursorPos(&point);
+  if (__glutCurrentWindow->win == WindowFromPoint(point)) {
+    __glutSetCursor(__glutCurrentWindow);
+  }
+#elif defined(__OS2PM__)
+//todo
+#else
+  __glutCurrentWindow->cursor = cursor;
+  __glutSetCursor(__glutCurrentWindow);
+#endif
+}
+/* ENDCENTRY */