Theme engine using TQt for GTK+ 3.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tdegtk-engine.c 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* The TdeGtk Theming Engine for Gtk+.
  2. * Copyright (C) 2011 Canonical Ltd
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free
  16. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. *
  19. * Authored by Andrea Cimitan <andrea.cimitan@canonical.com>
  20. *
  21. */
  22. #include <cairo.h>
  23. #include <cairo-gobject.h>
  24. #include <gtk/gtk.h>
  25. #include "tdegtk.h"
  26. #include "tdegtk-cairo-support.h"
  27. #include "tdegtk-draw.h"
  28. #include "tdegtk-engine.h"
  29. #include "tdegtk-support.h"
  30. #include "tdegtk-types.h"
  31. #define TDEGTK_NAMESPACE "tdegtk"
  32. #define TDEGTK_CAIRO_INIT \
  33. cairo_set_line_width (cr, 1.0); \
  34. cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); \
  35. cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
  36. G_DEFINE_DYNAMIC_TYPE (TdeGtkEngine, tdegtk_engine, GTK_TYPE_THEMING_ENGINE)
  37. static void
  38. tdegtk_engine_render_activity (GtkThemingEngine *engine,
  39. cairo_t *cr,
  40. gdouble x,
  41. gdouble y,
  42. gdouble width,
  43. gdouble height)
  44. {
  45. TdeGtkStyleFunctions *style_functions;
  46. const GtkWidgetPath *path;
  47. TDEGTK_CAIRO_INIT
  48. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  49. path = gtk_theming_engine_get_path (engine);
  50. if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER)) {
  51. GTK_THEMING_ENGINE_CLASS (tdegtk_engine_parent_class)->render_activity (engine, cr, x, y, width, height);
  52. }
  53. else {
  54. style_functions->draw_activity (engine, cr, x, y, width, height);
  55. }
  56. }
  57. static void
  58. tdegtk_engine_render_arrow (GtkThemingEngine *engine,
  59. cairo_t *cr,
  60. gdouble angle,
  61. gdouble x,
  62. gdouble y,
  63. gdouble size)
  64. {
  65. TdeGtkStyleFunctions *style_functions;
  66. TDEGTK_CAIRO_INIT
  67. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  68. style_functions->draw_arrow (engine, cr, angle, x, y, size);
  69. }
  70. static void
  71. tdegtk_engine_render_background (GtkThemingEngine *engine,
  72. cairo_t *cr,
  73. gdouble x,
  74. gdouble y,
  75. gdouble width,
  76. gdouble height)
  77. {
  78. TdeGtkStyleFunctions *style_functions;
  79. const GtkWidgetPath *path;
  80. GtkRegionFlags flags;
  81. TDEGTK_CAIRO_INIT
  82. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  83. path = gtk_theming_engine_get_path (engine);
  84. if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_BUTTON) &&
  85. gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINBUTTON)
  86. ) {
  87. style_functions->draw_spinbutton_background (engine, cr, x, y, width, height);
  88. }
  89. else if (!gtk_widget_path_is_type (path, GTK_TYPE_ICON_VIEW) &&
  90. gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VIEW) &&
  91. gtk_theming_engine_has_region (engine, GTK_STYLE_REGION_COLUMN, &flags)
  92. ) {
  93. style_functions->draw_cell_background (engine, cr, x, y, width, height, flags);
  94. }
  95. else {
  96. style_functions->draw_common_background (engine, cr, x, y, width, height);
  97. }
  98. }
  99. static void
  100. tdegtk_engine_render_check (GtkThemingEngine *engine,
  101. cairo_t *cr,
  102. gdouble x,
  103. gdouble y,
  104. gdouble width,
  105. gdouble height)
  106. {
  107. TdeGtkStyleFunctions *style_functions;
  108. TDEGTK_CAIRO_INIT
  109. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  110. style_functions->draw_check (engine, cr, x, y, width, height);
  111. }
  112. static void
  113. tdegtk_engine_render_expander (GtkThemingEngine *engine,
  114. cairo_t *cr,
  115. gdouble x,
  116. gdouble y,
  117. gdouble width,
  118. gdouble height)
  119. {
  120. TdeGtkStyleFunctions *style_functions;
  121. TDEGTK_CAIRO_INIT
  122. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  123. style_functions->draw_expander (engine, cr, x, y, width, height);
  124. }
  125. static void
  126. tdegtk_engine_render_extension (GtkThemingEngine *engine,
  127. cairo_t *cr,
  128. gdouble x,
  129. gdouble y,
  130. gdouble width,
  131. gdouble height,
  132. GtkPositionType gap_side)
  133. {
  134. TdeGtkStyleFunctions *style_functions;
  135. TDEGTK_CAIRO_INIT
  136. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  137. style_functions->draw_extension (engine, cr, x, y, width, height, gap_side);
  138. }
  139. static void
  140. tdegtk_engine_render_focus (GtkThemingEngine *engine,
  141. cairo_t *cr,
  142. gdouble x,
  143. gdouble y,
  144. gdouble width,
  145. gdouble height)
  146. {
  147. TdeGtkStyleFunctions *style_functions;
  148. TDEGTK_CAIRO_INIT
  149. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  150. style_functions->draw_focus (engine, cr, x, y, width, height);
  151. }
  152. static void
  153. tdegtk_engine_render_frame (GtkThemingEngine *engine,
  154. cairo_t *cr,
  155. gdouble x,
  156. gdouble y,
  157. gdouble width,
  158. gdouble height)
  159. {
  160. TdeGtkStyleFunctions *style_functions;
  161. const GtkWidgetPath *path;
  162. GtkRegionFlags flags;
  163. TDEGTK_CAIRO_INIT
  164. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  165. path = gtk_theming_engine_get_path (engine);
  166. if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SEPARATOR)) {
  167. style_functions->draw_separator (engine, cr, x, y, width, height);
  168. }
  169. else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_BUTTON) &&
  170. gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINBUTTON)
  171. ) {
  172. style_functions->draw_spinbutton_frame (engine, cr, x, y, width, height);
  173. }
  174. else if (!gtk_widget_path_is_type (path, GTK_TYPE_ICON_VIEW) &&
  175. gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VIEW) &&
  176. gtk_theming_engine_has_region (engine, GTK_STYLE_REGION_COLUMN, &flags)
  177. ) {
  178. style_functions->draw_cell_frame (engine, cr, x, y, width, height, flags);
  179. }
  180. else {
  181. style_functions->draw_common_frame (engine, cr, x, y, width, height);
  182. }
  183. }
  184. static void
  185. tdegtk_engine_render_frame_gap (GtkThemingEngine *engine,
  186. cairo_t *cr,
  187. gdouble x,
  188. gdouble y,
  189. gdouble width,
  190. gdouble height,
  191. GtkPositionType gap_side,
  192. gdouble xy0_gap,
  193. gdouble xy1_gap)
  194. {
  195. TdeGtkStyleFunctions *style_functions;
  196. TDEGTK_CAIRO_INIT
  197. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  198. if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_NOTEBOOK)) {
  199. style_functions->draw_notebook (engine, cr, x, y, width, height, gap_side, xy0_gap, xy1_gap);
  200. }
  201. else {
  202. style_functions->draw_frame_gap (engine, cr, x, y, width, height, gap_side, xy0_gap, xy1_gap);
  203. }
  204. }
  205. static void
  206. tdegtk_engine_render_handle (GtkThemingEngine *engine,
  207. cairo_t *cr,
  208. gdouble x,
  209. gdouble y,
  210. gdouble width,
  211. gdouble height)
  212. {
  213. TdeGtkStyleFunctions *style_functions;
  214. TDEGTK_CAIRO_INIT
  215. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  216. if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP)) {
  217. style_functions->draw_grip (engine, cr, x, y, width, height);
  218. }
  219. else {
  220. style_functions->draw_handle (engine, cr, x, y, width, height);
  221. }
  222. }
  223. static void
  224. tdegtk_engine_render_line (GtkThemingEngine *engine,
  225. cairo_t *cr,
  226. gdouble x0,
  227. gdouble y0,
  228. gdouble x1,
  229. gdouble y1)
  230. {
  231. TdeGtkStyleFunctions *style_functions;
  232. TDEGTK_CAIRO_INIT
  233. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  234. style_functions->draw_line (engine, cr, x0, y0, x1, y1);
  235. }
  236. static void
  237. tdegtk_engine_render_option (GtkThemingEngine *engine,
  238. cairo_t *cr,
  239. gdouble x,
  240. gdouble y,
  241. gdouble width,
  242. gdouble height)
  243. {
  244. TdeGtkStyleFunctions *style_functions;
  245. TDEGTK_CAIRO_INIT
  246. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  247. style_functions->draw_radio (engine, cr, x, y, width, height);
  248. }
  249. static void
  250. tdegtk_engine_render_slider (GtkThemingEngine *engine,
  251. cairo_t *cr,
  252. gdouble x,
  253. gdouble y,
  254. gdouble width,
  255. gdouble height,
  256. GtkOrientation orientation)
  257. {
  258. TdeGtkStyleFunctions *style_functions;
  259. TDEGTK_CAIRO_INIT
  260. tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
  261. style_functions->draw_slider (engine, cr, x, y, width, height, orientation);
  262. }
  263. void
  264. tdegtk_engine_register_types (GTypeModule *module)
  265. {
  266. tdegtk_engine_register_type (module);
  267. }
  268. static void
  269. tdegtk_engine_init (TdeGtkEngine *engine)
  270. {
  271. tdegtk_register_style_default (&engine->style_functions[TDEGTK_STYLE_DEFAULT]);
  272. }
  273. static void
  274. tdegtk_engine_class_init (TdeGtkEngineClass *klass)
  275. {
  276. GtkThemingEngineClass *engine_class = GTK_THEMING_ENGINE_CLASS (klass);
  277. engine_class->render_activity = tdegtk_engine_render_activity;
  278. engine_class->render_arrow = tdegtk_engine_render_arrow;
  279. engine_class->render_background = tdegtk_engine_render_background;
  280. engine_class->render_check = tdegtk_engine_render_check;
  281. engine_class->render_expander = tdegtk_engine_render_expander;
  282. engine_class->render_extension = tdegtk_engine_render_extension;
  283. engine_class->render_focus = tdegtk_engine_render_focus;
  284. engine_class->render_frame = tdegtk_engine_render_frame;
  285. engine_class->render_frame_gap = tdegtk_engine_render_frame_gap;
  286. engine_class->render_handle = tdegtk_engine_render_handle;
  287. engine_class->render_line = tdegtk_engine_render_line;
  288. engine_class->render_option = tdegtk_engine_render_option;
  289. engine_class->render_slider = tdegtk_engine_render_slider;
  290. }
  291. static void
  292. tdegtk_engine_class_finalize (TdeGtkEngineClass *klass)
  293. {
  294. }