gtkcompat.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Header file to make compatibility with older GTK versions less
  3. * painful, by #defining various things that are pure spelling changes
  4. * between GTK1 and GTK2, or between 2 and 3.
  5. */
  6. #if !GTK_CHECK_VERSION(2,0,0)
  7. #include <ctype.h>
  8. #include <X11/X.h>
  9. /* Helper macro used in definitions below. Note that although it
  10. * *expands* w and flag twice, it does not *evaluate* them twice
  11. * because the evaluations are in exclusive branches of ?:. So it's
  12. * a side-effect-safe macro. */
  13. #define gtk1_widget_set_unset_flag(w, flag, b) \
  14. ((b) ? GTK_WIDGET_SET_FLAGS(w, flag) : GTK_WIDGET_UNSET_FLAGS(w, flag))
  15. #define GType GtkType
  16. #define GObject GtkObject
  17. #define G_CALLBACK(x) GTK_SIGNAL_FUNC(x)
  18. #define G_OBJECT(x) GTK_OBJECT(x)
  19. #define G_TYPE_CHECK_INSTANCE_TYPE GTK_CHECK_TYPE
  20. #define G_TYPE_CHECK_INSTANCE_CAST GTK_CHECK_CAST
  21. #define G_TYPE_CHECK_CLASS_TYPE GTK_CHECK_CLASS_TYPE
  22. #define G_TYPE_CHECK_CLASS_CAST GTK_CHECK_CLASS_CAST
  23. #define g_ascii_isspace(x) (isspace((unsigned char)(x)))
  24. #define g_signal_connect gtk_signal_connect
  25. #define g_signal_connect_swapped gtk_signal_connect_object
  26. #define g_signal_stop_emission_by_name gtk_signal_emit_stop_by_name
  27. #define g_signal_emit_by_name gtk_signal_emit_by_name
  28. #define g_signal_handler_disconnect gtk_signal_disconnect
  29. #define g_object_get_data gtk_object_get_data
  30. #define g_object_set_data gtk_object_set_data
  31. #define g_object_set_data_full gtk_object_set_data_full
  32. #define g_object_ref_sink(x) do { \
  33. gtk_object_ref(x); \
  34. gtk_object_sink(x); \
  35. } while (0)
  36. #define GDK_GRAB_SUCCESS GrabSuccess
  37. #define GDK_WINDOW_XID GDK_WINDOW_XWINDOW
  38. #define gtk_widget_set_size_request gtk_widget_set_usize
  39. #define gtk_radio_button_get_group gtk_radio_button_group
  40. #define gtk_notebook_set_current_page gtk_notebook_set_page
  41. #define gtk_color_selection_set_has_opacity_control \
  42. gtk_color_selection_set_opacity
  43. #define gtk_dialog_get_content_area(dlg) ((dlg)->vbox)
  44. #define gtk_dialog_get_action_area(dlg) ((dlg)->action_area)
  45. #define gtk_dialog_set_can_default(dlg) ((dlg)->action_area)
  46. #define gtk_widget_get_window(w) ((w)->window)
  47. #define gtk_widget_get_parent(w) ((w)->parent)
  48. #define gtk_widget_set_allocation(w, a) ((w)->allocation = *(a))
  49. #define gtk_container_get_border_width(c) ((c)->border_width)
  50. #define gtk_container_get_focus_child(c) ((c)->focus_child)
  51. #define gtk_bin_get_child(b) ((b)->child)
  52. #define gtk_color_selection_dialog_get_color_selection(cs) ((cs)->colorsel)
  53. #define gtk_selection_data_get_target(sd) ((sd)->target)
  54. #define gtk_selection_data_get_data_type(sd) ((sd)->type)
  55. #define gtk_selection_data_get_data(sd) ((sd)->data)
  56. #define gtk_selection_data_get_length(sd) ((sd)->length)
  57. #define gtk_selection_data_get_format(sd) ((sd)->format)
  58. #define gtk_adjustment_set_lower(a, val) ((a)->lower = (val))
  59. #define gtk_adjustment_set_upper(a, val) ((a)->upper = (val))
  60. #define gtk_adjustment_set_page_size(a, val) ((a)->page_size = (val))
  61. #define gtk_adjustment_set_page_increment(a, val) ((a)->page_increment = (val))
  62. #define gtk_adjustment_set_step_increment(a, val) ((a)->step_increment = (val))
  63. #define gtk_adjustment_get_value(a) ((a)->value)
  64. #define gtk_selection_data_get_selection(a) ((a)->selection)
  65. #define gdk_display_beep(disp) gdk_beep()
  66. #define gtk_widget_set_has_window(w, b) \
  67. gtk1_widget_set_unset_flag(w, GTK_NO_WINDOW, !(b))
  68. #define gtk_widget_set_mapped(w, b) \
  69. gtk1_widget_set_unset_flag(w, GTK_MAPPED, (b))
  70. #define gtk_widget_set_can_default(w, b) \
  71. gtk1_widget_set_unset_flag(w, GTK_CAN_DEFAULT, (b))
  72. #define gtk_widget_get_visible(w) GTK_WIDGET_VISIBLE(w)
  73. #define gtk_widget_get_mapped(w) GTK_WIDGET_MAPPED(w)
  74. #define gtk_widget_get_realized(w) GTK_WIDGET_REALIZED(w)
  75. #define gtk_widget_get_state(w) GTK_WIDGET_STATE(w)
  76. #define gtk_widget_get_can_focus(w) GTK_WIDGET_CAN_FOCUS(w)
  77. #define gtk_widget_is_drawable(w) GTK_WIDGET_DRAWABLE(w)
  78. #define gtk_widget_is_sensitive(w) GTK_WIDGET_IS_SENSITIVE(w)
  79. #define gtk_widget_has_focus(w) GTK_WIDGET_HAS_FOCUS(w)
  80. /* This is a bit of a bodge because it relies on us only calling this
  81. * macro as GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), so under
  82. * GTK1 it makes sense to omit the contained function call and just
  83. * return the GDK default display. */
  84. #define GDK_DISPLAY_XDISPLAY(x) GDK_DISPLAY()
  85. #define GDK_KEY_C ('C')
  86. #define GDK_KEY_V ('V')
  87. #define GDK_KEY_c ('c')
  88. #define GDK_KEY_v ('v')
  89. #endif /* 2.0 */
  90. #if !GTK_CHECK_VERSION(2,22,0)
  91. #define gdk_visual_get_depth(v) ((v)->depth)
  92. #endif /* 2.22 */
  93. #if !GTK_CHECK_VERSION(2,24,0)
  94. #define GDK_KEY_Alt_L GDK_Alt_L
  95. #define GDK_KEY_Alt_R GDK_Alt_R
  96. #define GDK_KEY_BackSpace GDK_BackSpace
  97. #define GDK_KEY_Begin GDK_Begin
  98. #define GDK_KEY_Break GDK_Break
  99. #define GDK_KEY_Delete GDK_Delete
  100. #define GDK_KEY_Down GDK_Down
  101. #define GDK_KEY_End GDK_End
  102. #define GDK_KEY_Escape GDK_Escape
  103. #define GDK_KEY_F10 GDK_F10
  104. #define GDK_KEY_F11 GDK_F11
  105. #define GDK_KEY_F12 GDK_F12
  106. #define GDK_KEY_F13 GDK_F13
  107. #define GDK_KEY_F14 GDK_F14
  108. #define GDK_KEY_F15 GDK_F15
  109. #define GDK_KEY_F16 GDK_F16
  110. #define GDK_KEY_F17 GDK_F17
  111. #define GDK_KEY_F18 GDK_F18
  112. #define GDK_KEY_F19 GDK_F19
  113. #define GDK_KEY_F1 GDK_F1
  114. #define GDK_KEY_F20 GDK_F20
  115. #define GDK_KEY_F2 GDK_F2
  116. #define GDK_KEY_F3 GDK_F3
  117. #define GDK_KEY_F4 GDK_F4
  118. #define GDK_KEY_F5 GDK_F5
  119. #define GDK_KEY_F6 GDK_F6
  120. #define GDK_KEY_F7 GDK_F7
  121. #define GDK_KEY_F8 GDK_F8
  122. #define GDK_KEY_F9 GDK_F9
  123. #define GDK_KEY_Home GDK_Home
  124. #define GDK_KEY_Insert GDK_Insert
  125. #define GDK_KEY_ISO_Left_Tab GDK_ISO_Left_Tab
  126. #define GDK_KEY_KP_0 GDK_KP_0
  127. #define GDK_KEY_KP_1 GDK_KP_1
  128. #define GDK_KEY_KP_2 GDK_KP_2
  129. #define GDK_KEY_KP_3 GDK_KP_3
  130. #define GDK_KEY_KP_4 GDK_KP_4
  131. #define GDK_KEY_KP_5 GDK_KP_5
  132. #define GDK_KEY_KP_6 GDK_KP_6
  133. #define GDK_KEY_KP_7 GDK_KP_7
  134. #define GDK_KEY_KP_8 GDK_KP_8
  135. #define GDK_KEY_KP_9 GDK_KP_9
  136. #define GDK_KEY_KP_Add GDK_KP_Add
  137. #define GDK_KEY_KP_Begin GDK_KP_Begin
  138. #define GDK_KEY_KP_Decimal GDK_KP_Decimal
  139. #define GDK_KEY_KP_Delete GDK_KP_Delete
  140. #define GDK_KEY_KP_Divide GDK_KP_Divide
  141. #define GDK_KEY_KP_Down GDK_KP_Down
  142. #define GDK_KEY_KP_End GDK_KP_End
  143. #define GDK_KEY_KP_Enter GDK_KP_Enter
  144. #define GDK_KEY_KP_Home GDK_KP_Home
  145. #define GDK_KEY_KP_Insert GDK_KP_Insert
  146. #define GDK_KEY_KP_Left GDK_KP_Left
  147. #define GDK_KEY_KP_Multiply GDK_KP_Multiply
  148. #define GDK_KEY_KP_Page_Down GDK_KP_Page_Down
  149. #define GDK_KEY_KP_Page_Up GDK_KP_Page_Up
  150. #define GDK_KEY_KP_Right GDK_KP_Right
  151. #define GDK_KEY_KP_Subtract GDK_KP_Subtract
  152. #define GDK_KEY_KP_Up GDK_KP_Up
  153. #define GDK_KEY_Left GDK_Left
  154. #define GDK_KEY_Meta_L GDK_Meta_L
  155. #define GDK_KEY_Meta_R GDK_Meta_R
  156. #define GDK_KEY_Num_Lock GDK_Num_Lock
  157. #define GDK_KEY_Page_Down GDK_Page_Down
  158. #define GDK_KEY_Page_Up GDK_Page_Up
  159. #define GDK_KEY_Return GDK_Return
  160. #define GDK_KEY_Right GDK_Right
  161. #define GDK_KEY_Tab GDK_Tab
  162. #define GDK_KEY_Up GDK_Up
  163. #define GDK_KEY_greater GDK_greater
  164. #define GDK_KEY_less GDK_less
  165. #define gdk_window_get_screen(w) gdk_drawable_get_screen(w)
  166. #define gtk_combo_box_new_with_model_and_entry(t) gtk_combo_box_entry_new_with_model(t, 1)
  167. #endif /* 2.24 */
  168. #if !GTK_CHECK_VERSION(3,0,0)
  169. #define GDK_IS_X11_WINDOW(window) (1)
  170. #endif
  171. #if GTK_CHECK_VERSION(3,0,0)
  172. #define STANDARD_OK_LABEL "_OK"
  173. #define STANDARD_OPEN_LABEL "_Open"
  174. #define STANDARD_CANCEL_LABEL "_Cancel"
  175. #else
  176. #define STANDARD_OK_LABEL GTK_STOCK_OK
  177. #define STANDARD_OPEN_LABEL GTK_STOCK_OPEN
  178. #define STANDARD_CANCEL_LABEL GTK_STOCK_CANCEL
  179. #endif
  180. #if GTK_CHECK_VERSION(3,0,0)
  181. #define gtk_hseparator_new() gtk_separator_new(GTK_ORIENTATION_HORIZONTAL)
  182. /* Fortunately, my hboxes and vboxes never actually set homogeneous to
  183. * true, so I can just wrap these deprecated constructors with a macro
  184. * without also having to arrange a call to gtk_box_set_homogeneous. */
  185. #define gtk_hbox_new(homogeneous, spacing) \
  186. gtk_box_new(GTK_ORIENTATION_HORIZONTAL, spacing)
  187. #define gtk_vbox_new(homogeneous, spacing) \
  188. gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing)
  189. #define gtk_vscrollbar_new(adjust) \
  190. gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, adjust)
  191. #define gdk_get_display() gdk_display_get_name(gdk_display_get_default())
  192. #define gdk_cursor_new(cur) \
  193. gdk_cursor_new_for_display(gdk_display_get_default(), cur)
  194. #endif /* 3.0 */
  195. #if !HAVE_G_APPLICATION_DEFAULT_FLAGS
  196. #define G_APPLICATION_DEFAULT_FLAGS G_APPLICATION_FLAGS_NONE
  197. #endif