private.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/motif/private.h
  3. // Purpose: Private declarations for wxMotif port
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 17/09/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_PRIVATE_H_
  11. #define _WX_PRIVATE_H_
  12. #include "wx/defs.h"
  13. #include <X11/Xlib.h>
  14. #include <Xm/Xm.h>
  15. #include "wx/evtloop.h"
  16. class WXDLLIMPEXP_FWD_CORE wxFont;
  17. class WXDLLIMPEXP_FWD_CORE wxWindow;
  18. class WXDLLIMPEXP_FWD_CORE wxSize;
  19. class WXDLLIMPEXP_FWD_CORE wxBitmap;
  20. class WXDLLIMPEXP_FWD_CORE wxColour;
  21. #include "wx/x11/privx.h"
  22. // Put any private declarations here: native Motif types may be used because
  23. // this header is included after Xm/Xm.h
  24. // ----------------------------------------------------------------------------
  25. // convenience macros
  26. // ----------------------------------------------------------------------------
  27. #define wxCHECK_MOTIF_VERSION( major, minor ) \
  28. ( XmVersion >= (major) * 1000 + (minor) )
  29. #define wxCHECK_LESSTIF_VERSION( major, minor ) \
  30. ( LesstifVersion >= (major) * 1000 + (minor) )
  31. #define wxCHECK_LESSTIF() ( __WXLESSTIF__ )
  32. // some compilers (e.g. Sun CC) give warnings when treating string literals as
  33. // (non const) "char *" but many Motif functions take "char *" parameters which
  34. // are really "const char *" so use this macro to suppress the warnings when we
  35. // know it's ok
  36. #define wxMOTIF_STR(x) const_cast<char *>(x)
  37. // ----------------------------------------------------------------------------
  38. // Miscellaneous functions
  39. // ----------------------------------------------------------------------------
  40. WXWidget wxCreateBorderWidget( WXWidget parent, long style );
  41. // ----------------------------------------------------------------------------
  42. // common callbacks
  43. // ----------------------------------------------------------------------------
  44. // All widgets should have this as their resize proc.
  45. extern void wxWidgetResizeProc(Widget w, XConfigureEvent *event,
  46. String args[], int *num_args);
  47. // For repainting arbitrary windows
  48. void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data),
  49. XEvent *event, char *);
  50. // ----------------------------------------------------------------------------
  51. // we maintain a hash table which contains the mapping from Widget to wxWindow
  52. // corresponding to the window for this widget
  53. // ----------------------------------------------------------------------------
  54. extern void wxDeleteWindowFromTable(Widget w);
  55. extern wxWindow *wxGetWindowFromTable(Widget w);
  56. extern bool wxAddWindowToTable(Widget w, wxWindow *win);
  57. // ----------------------------------------------------------------------------
  58. // wxBitmap related functions
  59. // ----------------------------------------------------------------------------
  60. // Creates a bitmap with transparent areas drawn in the given colour.
  61. wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, const wxColour& colour);
  62. // ----------------------------------------------------------------------------
  63. // key events related functions
  64. // ----------------------------------------------------------------------------
  65. extern char wxFindMnemonic(const char* s);
  66. extern char * wxFindAccelerator (const char *s);
  67. extern XmString wxFindAcceleratorText (const char *s);
  68. // ----------------------------------------------------------------------------
  69. // TranslateXXXEvent() functions - translate Motif event to wxWindow one
  70. // ----------------------------------------------------------------------------
  71. extern bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
  72. Widget widget, const XEvent *xevent);
  73. extern bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win,
  74. Widget widget, const XEvent *xevent);
  75. extern void wxDoChangeForegroundColour(WXWidget widget,
  76. wxColour& foregroundColour);
  77. extern void wxDoChangeBackgroundColour(WXWidget widget,
  78. const wxColour& backgroundColour,
  79. bool changeArmColour = false);
  80. extern void wxDoChangeFont(WXWidget widget, const wxFont& font);
  81. extern void wxGetTextExtent(WXDisplay* display, const wxFont& font,
  82. double scale,
  83. const wxString& string, int* width, int* height,
  84. int* ascent, int* descent);
  85. extern void wxGetTextExtent(const wxWindow* window, const wxString& str,
  86. int* width, int* height,
  87. int* ascent, int* descent);
  88. #define wxNO_COLORS 0x00
  89. #define wxBACK_COLORS 0x01
  90. #define wxFORE_COLORS 0x02
  91. extern XColor itemColors[5] ;
  92. #define wxBACK_INDEX 0
  93. #define wxFORE_INDEX 1
  94. #define wxSELE_INDEX 2
  95. #define wxTOPS_INDEX 3
  96. #define wxBOTS_INDEX 4
  97. // ----------------------------------------------------------------------------
  98. // XmString/wxString conversion utilities
  99. // ----------------------------------------------------------------------------
  100. wxString wxXmStringToString( const XmString& xmString );
  101. XmString wxStringToXmString( const char* string );
  102. inline XmString wxStringToXmString( const wxScopedCharBuffer& string )
  103. { return wxStringToXmString(string.data()); }
  104. inline XmString wxStringToXmString( const wxString& string )
  105. { return wxStringToXmString((const char*)string.mb_str()); }
  106. // XmString made easy to use in wxWidgets (and has an added benefit of
  107. // cleaning up automatically)
  108. class wxXmString
  109. {
  110. void Init(const char *str)
  111. {
  112. m_string = XmStringCreateLtoR
  113. (
  114. const_cast<char *>(str),
  115. const_cast<char *>(XmSTRING_DEFAULT_CHARSET)
  116. );
  117. }
  118. public:
  119. wxXmString(const char* str)
  120. {
  121. Init(str);
  122. }
  123. wxXmString(const wchar_t* str)
  124. {
  125. Init(wxConvLibc.cWC2MB(str));
  126. }
  127. wxXmString(const wxString& str)
  128. {
  129. Init(str.mb_str());
  130. }
  131. wxXmString(const wxCStrData& str)
  132. {
  133. Init(str);
  134. }
  135. // just to avoid calling XmStringFree()
  136. wxXmString(const XmString& string) { m_string = string; }
  137. ~wxXmString() { XmStringFree(m_string); }
  138. // semi-implicit conversion to XmString (shouldn't rely on implicit
  139. // conversion because many of Motif functions are macros)
  140. XmString operator()() const { return m_string; }
  141. private:
  142. XmString m_string;
  143. };
  144. // ----------------------------------------------------------------------------
  145. // Routines used in both wxTextCtrl/wxListBox and nativa wxComboBox
  146. // (defined in src/motif/listbox.cpp or src/motif/textctrl.cpp
  147. // ----------------------------------------------------------------------------
  148. int wxDoFindStringInList( Widget listWidget, const wxString& str );
  149. int wxDoGetSelectionInList( Widget listWidget );
  150. wxString wxDoGetStringInList( Widget listWidget, int n );
  151. wxSize wxDoGetListBoxBestSize( Widget listWidget, const wxWindow* window );
  152. wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
  153. const wxWindow* window );
  154. // ----------------------------------------------------------------------------
  155. // event-related functions
  156. // ----------------------------------------------------------------------------
  157. // executes one main loop iteration (implemented in src/motif/evtloop.cpp)
  158. // returns true if the loop should be exited
  159. bool wxDoEventLoopIteration( wxGUIEventLoop& evtLoop );
  160. // Consume all events until no more left
  161. void wxFlushEvents(WXDisplay* display);
  162. // ----------------------------------------------------------------------------
  163. // macros to avoid casting WXFOO to Foo all the time
  164. // ----------------------------------------------------------------------------
  165. // argument is of type "wxWindow *"
  166. #define GetWidget(w) ((Widget)(w)->GetHandle())
  167. // ----------------------------------------------------------------------------
  168. // accessors for C modules
  169. // ----------------------------------------------------------------------------
  170. extern "C" XtAppContext wxGetAppContext();
  171. #endif
  172. // _WX_PRIVATE_H_