use the encoding of the font which is used to draw the text when convering it to...
[wxWidgets.git] / include / wx / gtk / private.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/private.h
3 // Purpose: wxGTK private macros, functions &c
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 12.03.02
7 // RCS-ID: $Id$
8 // Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTK_PRIVATE_H_
13 #define _WX_GTK_PRIVATE_H_
14
15 #include <gtk/gtk.h>
16
17 #include "wx/event.h"
18
19 // fail all version tests if the GTK+ version is so ancient that it doesn't
20 // even have GTK_CHECK_VERSION
21 #ifndef GTK_CHECK_VERSION
22 #define GTK_CHECK_VERSION(a, b, c) 0
23 #endif
24
25 #if wxUSE_UNICODE
26 #define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s)
27 #define wxGTK_CONV_SYS(s, enc) wxGTK_CONV(s)
28 #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s)
29 #else
30 // convert the text in given encoding to UTF-8 used by wxGTK
31 extern wxCharBuffer
32 wxConvertToGTK(const wxString& s,
33 wxFontEncoding enc = wxFONTENCODING_SYSTEM);
34
35 // helper: use the encoding of the given font if it's valid
36 inline wxCharBuffer wxConvertToGTK(const wxString& s, const wxFont& font)
37 {
38 return wxConvertToGTK(s, font.Ok() ? font.GetEncoding()
39 : wxFONTENCODING_SYSTEM);
40 }
41
42 #define wxGTK_CONV(s) wxConvertToGTK((s), m_font)
43 #define wxGTK_CONV_SYS(s) wxConvertToGTK(s)
44 #define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX( wxConvUTF8.cMB2WC((s)) )
45 #endif
46
47 // Some deprecated GTK+ prototypes we still use often
48 // FIXME: Don't use them if possible.
49 G_BEGIN_DECLS
50
51 // Should use gtk_image_new, but the mask seems to be handled different,
52 // and we need to migrate
53 GtkWidget* gtk_pixmap_new (GdkPixmap *pixmap,
54 GdkBitmap *mask);
55
56 // Deprecated since GTK+-1.3.7:
57 // Trivial wrapper around gtk_window_move, with some side effects we seem to rely on
58 void gtk_widget_set_uposition (GtkWidget *widget,
59 gint x,
60 gint y);
61
62 // We rely on the allow_shrink parameter in one place
63 void gtk_window_set_policy (GtkWindow *window,
64 gint allow_shrink,
65 gint allow_grow,
66 gint auto_shrink);
67
68 G_END_DECLS
69
70 //-----------------------------------------------------------------------------
71 // idle system
72 //-----------------------------------------------------------------------------
73
74 extern void wxapp_install_idle_handler();
75 extern bool g_isIdle;
76
77 //-----------------------------------------------------------------------------
78 // Convenience class for g_freeing a gchar* on scope exit automatically
79 //-----------------------------------------------------------------------------
80
81 class wxGtkString
82 {
83 public:
84 explicit wxGtkString(gchar *s) : m_str(s) { }
85 ~wxGtkString() { g_free(m_str); }
86
87 const gchar *c_str() const { return m_str; }
88
89 operator gchar *() const { return m_str; }
90
91 private:
92 gchar *m_str;
93
94 DECLARE_NO_COPY_CLASS(wxGtkString)
95 };
96
97 //-----------------------------------------------------------------------------
98 // GTK+ scroll types -> wxEventType
99 //-----------------------------------------------------------------------------
100
101 // translate a GTK+ scroll type to a wxEventType
102 inline wxEventType GtkScrollTypeToWx(guint scrollType)
103 {
104 wxEventType command;
105 switch ( scrollType )
106 {
107 case GTK_SCROLL_STEP_BACKWARD:
108 command = wxEVT_SCROLL_LINEUP;
109 break;
110
111 case GTK_SCROLL_STEP_FORWARD:
112 command = wxEVT_SCROLL_LINEDOWN;
113 break;
114
115 case GTK_SCROLL_PAGE_BACKWARD:
116 command = wxEVT_SCROLL_PAGEUP;
117 break;
118
119 case GTK_SCROLL_PAGE_FORWARD:
120 command = wxEVT_SCROLL_PAGEDOWN;
121 break;
122
123 default:
124 command = wxEVT_SCROLL_THUMBTRACK;
125 }
126
127 return command;
128 }
129
130 inline wxEventType GtkScrollWinTypeToWx(guint scrollType)
131 {
132 // GtkScrollTypeToWx() returns SCROLL_XXX, not SCROLLWIN_XXX as we need
133 return GtkScrollTypeToWx(scrollType) +
134 wxEVT_SCROLLWIN_TOP - wxEVT_SCROLL_TOP;
135 }
136
137
138 //-----------------------------------------------------------------------------
139 // Misc. functions
140 //-----------------------------------------------------------------------------
141
142 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
143 void wxAddGrab(wxWindow* window);
144 void wxRemoveGrab(wxWindow* window);
145
146 // Escapes string so that it is valid Pango markup XML string:
147 WXDLLIMPEXP_CORE wxString wxEscapeStringForPangoMarkup(const wxString& str);
148
149 // The declaration for gtk_icon_size_lookup was accidentally ifdefed out in
150 // GTK+ 2.1.0 which Sun seem to have shipped with some versions of JDS
151 // for Solaris 9 x86.
152 #ifdef NEED_GTK_ICON_SIZE_LOOKUP
153 extern "C" gboolean gtk_icon_size_lookup (GtkIconSize size,
154 gint *width,
155 gint *height);
156 #endif
157
158 #endif // _WX_GTK_PRIVATE_H_
159