// Modified by:
// Created: 12.03.02
// RCS-ID: $Id$
-// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwindows.org>
+// Copyright: (c) 2002 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_PRIVATE_H_
#define _WX_GTK_PRIVATE_H_
-#include <gdk/gdk.h>
#include <gtk/gtk.h>
-#include "wx/event.h"
+#include "wx/gtk/private/string.h"
+#include "wx/gtk/private/gtk2-compat.h"
-// fail all version tests if the GTK+ version is so ancient that it doesn't
-// even have GTK_CHECK_VERSION
-#ifndef GTK_CHECK_VERSION
- #define GTK_CHECK_VERSION(a, b, c) 0
-#endif
+// pango_version_check symbol is quite recent ATM (4/2007)... so we
+// use our own wrapper which implements a smart trick.
+// Use this function as you'd use pango_version_check:
+//
+// if (!wx_pango_version_check(1,18,0))
+// ... call to a function available only in pango >= 1.18 ...
+//
+// and use it only to test for pango versions >= 1.16.0
+extern const gchar *wx_pango_version_check(int major, int minor, int micro);
-#ifdef __WXGTK20__
#if wxUSE_UNICODE
- #define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s)
- #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s)
+ #define wxGTK_CONV(s) (s).utf8_str()
+ #define wxGTK_CONV_ENC(s, enc) wxGTK_CONV((s))
+ #define wxGTK_CONV_FONT(s, font) wxGTK_CONV((s))
+ #define wxGTK_CONV_SYS(s) wxGTK_CONV((s))
+
+ #define wxGTK_CONV_BACK(s) wxString::FromUTF8Unchecked(s)
+ #define wxGTK_CONV_BACK_ENC(s, enc) wxGTK_CONV_BACK(s)
+ #define wxGTK_CONV_BACK_FONT(s, font) wxGTK_CONV_BACK(s)
+ #define wxGTK_CONV_BACK_SYS(s) wxGTK_CONV_BACK(s)
#else
- #define wxGTK_CONV(s) wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC(s) )
- #define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX( (wxConvUTF8.cMB2WC( s ) ) )
-#endif
-#else
- #define wxGTK_CONV(s) s.c_str()
- #define wxGTK_CONV_BACK(s) s
-#endif
+ #include "wx/font.h"
+ // convert the text between the given encoding and UTF-8 used by wxGTK
+ extern WXDLLIMPEXP_CORE wxCharBuffer
+ wxConvertToGTK(const wxString& s,
+ wxFontEncoding enc = wxFONTENCODING_SYSTEM);
-// GTK+ 2.0 compatibility define is broken when used from C++ as it
-// casts enum to int implicitly
-#ifdef __WXGTK20__
- #undef gtk_signal_disconnect_by_func
- #define gtk_signal_disconnect_by_func(object,func,data) \
- gtk_signal_compat_matched((object), (func), (data), \
- (GSignalMatchType)(G_SIGNAL_MATCH_FUNC | \
- G_SIGNAL_MATCH_DATA), 0)
-#endif
+ extern WXDLLIMPEXP_CORE wxCharBuffer
+ wxConvertFromGTK(const wxString& s,
+ wxFontEncoding enc = wxFONTENCODING_SYSTEM);
-// child is not a member of GTK_BUTTON() any more in GTK+ 2.0
-#ifdef __WXGTK20__
- #define BUTTON_CHILD(w) GTK_BIN((w))->child
-#else
- #define BUTTON_CHILD(w) GTK_BUTTON((w))->child
-#endif
+ // helper: use the encoding of the given font if it's valid
+ inline wxCharBuffer wxConvertToGTK(const wxString& s, const wxFont& font)
+ {
+ return wxConvertToGTK(s, font.IsOk() ? font.GetEncoding()
+ : wxFONTENCODING_SYSTEM);
+ }
-// event_window has disappeared from GtkToggleButton in GTK+ 2.0
-#ifdef __WXGTK20__
- #define TOGGLE_BUTTON_EVENT_WIN(w) GTK_BUTTON((w))->event_window
-#else
- #define TOGGLE_BUTTON_EVENT_WIN(w) GTK_TOGGLE_BUTTON((w))->event_window
-#endif
+ inline wxCharBuffer wxConvertFromGTK(const wxString& s, const wxFont& font)
+ {
+ return wxConvertFromGTK(s, font.IsOk() ? font.GetEncoding()
+ : wxFONTENCODING_SYSTEM);
+ }
-// gtk_editable_{copy|cut|paste}_clipboard() had an extra argument under
-// previous GTK+ versions but no more
-#if defined(__WXGTK20__) || (GTK_MINOR_VERSION > 0)
- #define DUMMY_CLIPBOARD_ARG
-#else
- #define DUMMY_CLIPBOARD_ARG ,0
-#endif
+ // more helpers: allow passing GTK+ strings directly
+ inline wxCharBuffer
+ wxConvertFromGTK(const wxGtkString& gs,
+ wxFontEncoding enc = wxFONTENCODING_SYSTEM)
+ {
+ return wxConvertFromGTK(gs.c_str(), enc);
+ }
-// _GtkEditable is now private
-#ifdef __WXGTK20__
- #define GET_EDITABLE_POS(w) gtk_editable_get_position(GTK_EDITABLE(w))
- #define SET_EDITABLE_POS(w, pos) \
- gtk_editable_set_position(GTK_EDITABLE(w), (pos))
-#else
- #define GET_EDITABLE_POS(w) GTK_EDITABLE((w))->current_pos
- #define SET_EDITABLE_POS(w, pos) \
- GTK_EDITABLE((w))->current_pos = (pos)
-#endif
+ inline wxCharBuffer
+ wxConvertFromGTK(const wxGtkString& gs, const wxFont& font)
+ {
+ return wxConvertFromGTK(gs.c_str(), font);
+ }
-// this GtkNotebook struct field has been renamed
-#ifdef __WXGTK20__
- #define NOTEBOOK_PANEL(nb) GTK_NOTEBOOK(nb)->event_window
-#else
- #define NOTEBOOK_PANEL(nb) GTK_NOTEBOOK(nb)->panel
+ #define wxGTK_CONV(s) wxGTK_CONV_FONT((s), m_font)
+ #define wxGTK_CONV_ENC(s, enc) wxConvertToGTK((s), (enc))
+ #define wxGTK_CONV_FONT(s, font) wxConvertToGTK((s), (font))
+ #define wxGTK_CONV_SYS(s) wxConvertToGTK((s))
+
+ #define wxGTK_CONV_BACK(s) wxConvertFromGTK((s), m_font)
+ #define wxGTK_CONV_BACK_ENC(s, enc) wxConvertFromGTK((s), (enc))
+ #define wxGTK_CONV_BACK_FONT(s, font) wxConvertFromGTK((s), (font))
+ #define wxGTK_CONV_BACK_SYS(s) wxConvertFromGTK((s))
#endif
-#ifdef __WXGTK20__
- #define SCROLLBAR_CBACK_ARG
- #define GET_SCROLL_TYPE(w) GTK_SCROLL_JUMP
+// Define a macro for converting wxString to char* in appropriate encoding for
+// the file names.
+#ifdef G_OS_WIN32
+ // Under MSW, UTF-8 file name encodings are always used.
+ #define wxGTK_CONV_FN(s) (s).utf8_str()
#else
- #define SCROLLBAR_CBACK_ARG
- #define GET_SCROLL_TYPE(w) GTK_RANGE((w))->scroll_type
+ // Under Unix use GLib file name encoding (which is also UTF-8 by default
+ // but may be different from it).
+ #define wxGTK_CONV_FN(s) (s).fn_str()
#endif
-// translate a GTK+ scroll type to a wxEventType
-inline wxEventType GtkScrollTypeToWx(guint scrollType)
-{
- wxEventType command;
- switch ( scrollType )
- {
- case GTK_SCROLL_STEP_BACKWARD:
- command = wxEVT_SCROLL_LINEUP;
- break;
-
- case GTK_SCROLL_STEP_FORWARD:
- command = wxEVT_SCROLL_LINEDOWN;
- break;
-
- case GTK_SCROLL_PAGE_BACKWARD:
- command = wxEVT_SCROLL_PAGEUP;
- break;
-
- case GTK_SCROLL_PAGE_FORWARD:
- command = wxEVT_SCROLL_PAGEDOWN;
- break;
-
- default:
- command = wxEVT_SCROLL_THUMBTRACK;
- }
+// ----------------------------------------------------------------------------
+// various private helper functions
+// ----------------------------------------------------------------------------
- return command;
-}
-
-inline wxEventType GtkScrollWinTypeToWx(guint scrollType)
+namespace wxGTKPrivate
{
- // GtkScrollTypeToWx() returns SCROLL_XXX, not SCROLLWIN_XXX as we need
- return GtkScrollTypeToWx(scrollType) +
- wxEVT_SCROLLWIN_TOP - wxEVT_SCROLL_TOP;
-}
-
-
-// In wxGTK2 the wxMessageDialog is not a real wxDialog, instead a
-// gtk_message_dialog is created, shown and destroyed inside the ShowModal()
-// call. Since its m_widget will always be NULL there would normally be lots
-// of wxCHECK asserts triggered by calling base class methods that are valid
-// calls (or just ignored) on other wx ports. Using these macros instead of
-// wxCHECK will silence those asserts if the window is a wxMessageDialog and
-// will let the method doing the check just be ignored in that case. If it's
-// not a wxMessageDialog then it behaves just like before.
+// these functions create the GTK widgets of the specified types which can then
+// used to retrieve their styles, pass them to drawing functions &c
//
-// NOTE: Once more native dialogs are used then this will need to be
-// generalized a bit, perhaps with a IsNativeGTKDialog method or
-// something...
-
-#if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
-#define wxCHECK_VALID_WIDGET(rc) \
- if (!(m_widget != NULL)) { \
- if (!wxIsKindOf(this, wxMessageDialog)) { wxFAIL_MSG(wxT("invalid window")); } \
- return rc; \
- }
-
-#define wxCHECK_VALID_WIDGET_RET() \
- if (!(m_widget != NULL)) { \
- if (!wxIsKindOf(this, wxMessageDialog)) { wxFAIL_MSG(wxT("invalid window")); } \
- return; \
- }
-
-#else // not wxGTK2, so just use wxCHECK
-#define wxCHECK_VALID_WIDGET(rc) wxCHECK_MSG( (m_widget != NULL), rc, wxT("invalid window") )
-#define wxCHECK_VALID_WIDGET_RET() wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
-#endif
-
+// the returned widgets shouldn't be destroyed, this is done automatically on
+// shutdown
+WXDLLIMPEXP_CORE GtkWidget *GetButtonWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetCheckButtonWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetComboBoxWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetEntryWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetHeaderButtonWidgetFirst();
+WXDLLIMPEXP_CORE GtkWidget *GetHeaderButtonWidgetLast();
+WXDLLIMPEXP_CORE GtkWidget *GetHeaderButtonWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetNotebookWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetRadioButtonWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetSplitterWidget(wxOrientation orient = wxHORIZONTAL);
+WXDLLIMPEXP_CORE GtkWidget *GetTextEntryWidget();
+WXDLLIMPEXP_CORE GtkWidget *GetTreeWidget();
+
+} // wxGTKPrivate
#endif // _WX_GTK_PRIVATE_H_
-