2
0

gtkglue.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright (c) 2006-2020 Bruce A Henderson
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "gtk/gtk.h"
  20. #include "gdk/gdk.h"
  21. #include "brl.mod/blitz.mod/blitz.h"
  22. int bmx_gtk3_gtkdesktop_gethertz() {
  23. #if GTK_MINOR_VERSION >= 22
  24. GdkMonitor * monitor = gdk_display_get_primary_monitor(gdk_display_get_default());
  25. int rate = gdk_monitor_get_refresh_rate(monitor);
  26. return rate / 1000;
  27. #else
  28. return 60;
  29. #endif
  30. }
  31. GValue * bmx_gtk3_gvalue_new(int type) {
  32. GValue * val = (GValue*)calloc(1, sizeof(GValue));
  33. return g_value_init(val, type);
  34. }
  35. void bmx_gtk3_gvalue_free(GValue * val) {
  36. free(val);
  37. }
  38. GtkTreeIter * bmx_gtk3_gtktreeiter_new() {
  39. return (GtkTreeIter*)calloc(1, sizeof(GtkTreeIter));
  40. }
  41. void bmx_gtk3_gtktreeiter_free(GtkTreeIter * iter) {
  42. free(iter);
  43. }
  44. PangoFontDescription * bmx_gtk3_stylecontext_get_fontdesc(GtkStyleContext *context) {
  45. return gtk_style_context_get_font(context, GTK_STATE_FLAG_NORMAL);
  46. }
  47. GtkTextIter * bmx_gtk3_gtktextiter_new() {
  48. return (GtkTextIter*)calloc(1, sizeof(GtkTextIter));
  49. }
  50. void bmx_gtk3_gtktextiter_free(GtkTextIter * iter) {
  51. free(iter);
  52. }
  53. GtkTextTag * bmx_gtk3_set_text_tag_style(GtkTextBuffer *buffer, const gchar *tag, GdkRGBA * color, int _style, int _weight, int _under, int _strike) {
  54. return gtk_text_buffer_create_tag(buffer, tag, "foreground-rgba", color, "style", _style, "weight", _weight, "underline", _under, "strikethrough", _strike, 0);
  55. }
  56. GtkTextTag * bmx_gtk3_set_text_bg_tag(GtkTextBuffer *buffer, const gchar *tag, GdkRGBA * color) {
  57. return gtk_text_buffer_create_tag(buffer, tag, "background-rgba", color, 0);
  58. }
  59. BBArray * bmx_gtk3_selection_data_get_uris(GtkSelectionData * data) {
  60. gchar ** uris = gtk_selection_data_get_uris(data);
  61. if (uris == NULL) {
  62. return &bbEmptyString;
  63. }
  64. int count = 0;
  65. while (uris[count] && count < 128) {
  66. count++;
  67. }
  68. BBArray *p=bbArrayNew1D( "$",count );
  69. BBString **s=(BBString**)BBARRAYDATA( p,p->dims );
  70. for( int i=0;i<count;++i ){
  71. s[i]=bbStringFromUTF8String( uris[i] );
  72. }
  73. g_strfreev(uris);
  74. return p;
  75. }