gui.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include <assert.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "gui.h"
  14. #include <glade/glade.h>
  15. #include <gdk/gdkkeysyms.h>
  16. #include <gdk/gdk.h>
  17. #include "viewport.h"
  18. #include <cgraph/strview.h>
  19. #include <util/alloc.h>
  20. GladeXML *xml; //global libglade vars
  21. void Color_Widget_bg(char *colorstring, GtkWidget * widget)
  22. {
  23. GdkColor color;
  24. gdk_color_parse(colorstring, &color);
  25. gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
  26. gtk_widget_modify_base(widget, GTK_STATE_NORMAL, &color);
  27. }
  28. void load_graph_properties(void) {
  29. //dlgOpenGraph , GtkDialog
  30. gtk_entry_set_text((GtkEntry *)
  31. glade_xml_get_widget(xml, "entryGraphFileName"),
  32. view->Topview->Graphdata.GraphFileName);
  33. }
  34. void show_gui_warning(char *str)
  35. {
  36. GtkMessageDialog *Dlg = (GtkMessageDialog *)gtk_message_dialog_new(NULL,
  37. GTK_DIALOG_MODAL,
  38. GTK_MESSAGE_WARNING,
  39. GTK_BUTTONS_OK, "%s", str);
  40. gtk_dialog_run((GtkDialog *) Dlg);
  41. gtk_object_destroy((GtkObject *) Dlg);
  42. }
  43. /*
  44. Generic Open File dialog, if a file is selected and return value is 1, else 0
  45. file name is copied to char* filename,which should be allocated before using the function
  46. */
  47. int openfiledlg(char **filename) {
  48. assert(filename != NULL);
  49. GtkWidget *dialog;
  50. int rv;
  51. dialog = gtk_file_chooser_dialog_new("Open File",
  52. NULL,
  53. GTK_FILE_CHOOSER_ACTION_OPEN,
  54. GTK_STOCK_CANCEL,
  55. GTK_RESPONSE_CANCEL,
  56. GTK_STOCK_OPEN,
  57. GTK_RESPONSE_ACCEPT, NULL);
  58. if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
  59. *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  60. rv = 1;
  61. } else
  62. rv = 0;
  63. gtk_widget_destroy(dialog);
  64. return rv;
  65. }
  66. int savefiledlg(char **filename) {
  67. assert(filename != NULL);
  68. GtkWidget *dialog;
  69. int rv;
  70. dialog = gtk_file_chooser_dialog_new("Save File",
  71. NULL,
  72. GTK_FILE_CHOOSER_ACTION_OPEN,
  73. GTK_STOCK_CANCEL,
  74. GTK_RESPONSE_CANCEL,
  75. GTK_STOCK_OPEN,
  76. GTK_RESPONSE_ACCEPT, NULL);
  77. if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
  78. *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  79. rv = 1;
  80. } else
  81. rv = 0;
  82. gtk_widget_destroy(dialog);
  83. return rv;
  84. }
  85. void append_textview(GtkTextView * textv, const char *s, size_t bytes)
  86. {
  87. GtkTextIter endit;
  88. GtkTextBuffer *gtkbuf;
  89. /*get text view buffer */
  90. gtkbuf = gtk_text_view_get_buffer(textv);
  91. /*set iterator to the end of the buffer */
  92. gtk_text_buffer_get_end_iter(gtkbuf, &endit);
  93. /* insert buf to the end */
  94. gtk_text_buffer_insert(gtkbuf, &endit, s, (int)bytes);
  95. }