llwindowmacosx-objc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @file llwindowmacosx-objc.h
  3. * @brief Prototypes for functions shared between llwindowmacosx.cpp
  4. * and llwindowmacosx-objc.mm.
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLWINDOWMACOSX_OBJC_H
  28. #define LL_LLWINDOWMACOSX_OBJC_H
  29. #include <map>
  30. #include <vector>
  31. // For CGSize
  32. #include <CoreGraphics/CGGeometry.h>
  33. typedef std::vector<std::pair<int, bool> > segment_t;
  34. typedef std::vector<int> segment_lengths;
  35. typedef std::vector<int> segment_standouts;
  36. struct attributedStringInfo {
  37. segment_lengths seg_lengths;
  38. segment_standouts seg_standouts;
  39. };
  40. // This will actually hold an NSCursor*, but that type is only available in objective C.
  41. typedef void* CursorRef;
  42. typedef void* NSWindowRef;
  43. typedef void* GLViewRef;
  44. struct NativeKeyEventData {
  45. enum EventType {
  46. KEYUNKNOWN,
  47. KEYUP,
  48. KEYDOWN,
  49. KEYCHAR
  50. };
  51. EventType mKeyEvent = KEYUNKNOWN;
  52. uint32_t mEventType = 0;
  53. uint32_t mEventModifiers = 0;
  54. uint32_t mEventKeyCode = 0;
  55. uint32_t mEventChars = 0;
  56. uint32_t mEventUnmodChars = 0;
  57. bool mEventRepeat = false;
  58. };
  59. typedef const NativeKeyEventData* NSKeyEventRef;
  60. // These are defined in llappviewermacosx.cpp.
  61. bool initViewer();
  62. void handleQuit();
  63. bool pumpMainLoop();
  64. void initMainLoop();
  65. void cleanupViewer();
  66. void handleUrl(const char* url);
  67. void dispatchUrl(std::string url);
  68. /* Defined in llwindowmacosx-objc.mm: */
  69. int createNSApp(int argc, const char** argv);
  70. void setupCocoa();
  71. bool pasteBoardAvailable();
  72. bool copyToPBoard(const unsigned short* str, unsigned int len);
  73. const unsigned short* copyFromPBoard();
  74. CursorRef createImageCursor(const char* fullpath, int hotspotX, int hotspotY);
  75. short releaseImageCursor(CursorRef ref);
  76. short setImageCursor(CursorRef ref);
  77. void setArrowCursor();
  78. void setIBeamCursor();
  79. void setPointingHandCursor();
  80. void setCopyCursor();
  81. void setCrossCursor();
  82. void setNotAllowedCursor();
  83. void hideNSCursor();
  84. void showNSCursor();
  85. bool isCGCursorVisible();
  86. void hideNSCursorTillMove(bool hide);
  87. void requestUserAttention();
  88. long showAlert(std::string title, std::string text, int type);
  89. NSWindowRef createNSWindow(int x, int y, int width, int height);
  90. #include <OpenGL/OpenGL.h>
  91. GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples,
  92. bool vsync, bool core_gl);
  93. void glSwapBuffers(void* context);
  94. CGLContextObj getCGLContextObj(GLViewRef view);
  95. unsigned long getVramSize(GLViewRef view);
  96. float getDeviceUnitSize(GLViewRef view);
  97. CGPoint getContentViewBoundsPosition(NSWindowRef window);
  98. CGSize getContentViewBoundsSize(NSWindowRef window);
  99. CGSize getDeviceContentViewSize(NSWindowRef window, GLViewRef view);
  100. void getWindowSize(NSWindowRef window, float* size);
  101. void setWindowSize(NSWindowRef window, int width, int height);
  102. void setWinTitle(NSWindowRef window, const std::string& title);
  103. void getCursorPos(NSWindowRef window, float* pos);
  104. void makeWindowOrderFront(NSWindowRef window);
  105. void convertScreenToWindow(NSWindowRef window, float* coord);
  106. void convertWindowToScreen(NSWindowRef window, float* coord);
  107. void convertScreenToView(NSWindowRef window, float* coord);
  108. void convertRectToScreen(NSWindowRef window, float* coord);
  109. void convertRectFromScreen(NSWindowRef window, float* coord);
  110. void setWindowPos(NSWindowRef window, float* pos);
  111. void closeWindow(NSWindowRef window);
  112. void removeGLView(GLViewRef view);
  113. void makeFirstResponder(NSWindowRef window, GLViewRef view);
  114. void setupInputWindow(NSWindowRef window, GLViewRef view);
  115. // These are all implemented in llwindowmacosx.cpp.
  116. // This is largely for easier interop between Obj-C and C++ (at least in the
  117. // viewer's case due to the BOOL vs. BOOL conflict)
  118. bool callKeyUp(NSKeyEventRef event, unsigned short key, unsigned int mask);
  119. bool callKeyDown(NSKeyEventRef event, unsigned short key, unsigned int mask);
  120. void callResetKeys();
  121. bool callUnicodeCallback(wchar_t character, unsigned int mask);
  122. void callRightMouseDown(float* pos, unsigned int mask);
  123. void callRightMouseUp(float* pos, unsigned int mask);
  124. void callLeftMouseDown(float* pos, unsigned int mask);
  125. void callLeftMouseUp(float* pos, unsigned int mask);
  126. void callDoubleClick(float* pos, unsigned int mask);
  127. void callResize(unsigned int width, unsigned int height);
  128. void callMouseMoved(float* pos, unsigned int mask);
  129. void callMouseDragged(float* pos, unsigned int mask);
  130. void callScrollMoved(float delta);
  131. void callMouseExit();
  132. void callWindowFocus();
  133. void callWindowUnfocus();
  134. void callWindowHide();
  135. void callWindowUnhide();
  136. void callWindowDidChangeScreen();
  137. void callDeltaUpdate(float* delta, unsigned int mask);
  138. void callMiddleMouseDown(float* pos, unsigned int mask);
  139. void callMiddleMouseUp(float* pos, unsigned int mask);
  140. void callFocus();
  141. void callFocusLost();
  142. void callModifier(unsigned int mask);
  143. void callQuitHandler();
  144. void commitCurrentPreedit(GLViewRef glView);
  145. #include <string>
  146. void callHandleDragEntered(std::string url);
  147. void callHandleDragExited(std::string url);
  148. void callHandleDragUpdated(std::string url);
  149. void callHandleDragDropped(std::string url);
  150. // LLPreeditor C bindings.
  151. std::basic_string<wchar_t> getPreeditString();
  152. void getPreeditSelectionRange(int* position, int* length);
  153. void getPreeditMarkedRange(int* position, int* length);
  154. bool handleUnicodeCharacter(wchar_t c);
  155. void updatePreeditor(unsigned short* str);
  156. void setPreeditMarkedRange(int position, int length);
  157. void resetPreedit();
  158. int wstring_length(const std::basic_string<wchar_t>& wstr, const int woffset, const int utf16_length, int* unaligned);
  159. void setMarkedText(unsigned short* text, unsigned int* selectedRange, unsigned int* replacementRange, long text_len, attributedStringInfo segments);
  160. void getPreeditLocation(float* location, unsigned int length);
  161. void allowDirectMarkedTextInput(bool allow, GLViewRef glView);
  162. NSWindowRef getMainAppWindow();
  163. unsigned int getModifiers();
  164. #endif // LL_LLWINDOWMACOSX_OBJC_H