File: editor_view.cc

package info (click to toggle)
drgeo 1.0.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,944 kB
  • ctags: 2,451
  • sloc: cpp: 22,604; sh: 8,353; lisp: 1,043; makefile: 430; ansic: 343
file content (100 lines) | stat: -rw-r--r-- 2,475 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Dr Genius an interactive geometry software
 * (C) Copyright Hilaire Fernandes  2003
 * hilaire@ofset.org 
 * 
 *
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public Licences as by published
 * by the Free Software Foundation; either version 2; or (at your option)
 * any later version
 *
 * This program is distributed in the hope that it will entertaining,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Publis License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <string.h>
#include <libintl.h>

#include "editor_view.h"
#include "drgeo_gtkhelpers.h"

#define  _(x)  gettext (x)
#define N_(x)  x

editorView::editorView (xmlNodePtr editorXml):
  drgeniusView (EDITOR_CHILD, true)
{
  static gint counter = 1;

  createWidgetView ();
  
  if (editorXml == NULL)
    {
      /* create a new name */
      p_name = g_strdup_printf (_("Text %d"), 
				counter++);
      gtk_text_view_clear (GTK_TEXT_VIEW (p_textView));
    }
  else
    {
      /* get the name from the XML Tree */		    
      p_name = (gchar *) (xmlGetProp (editorXml, BAD_CAST "name"));
      gtk_text_view_set_text (GTK_TEXT_VIEW (p_textView),
			      (gchar *) xmlNodeGetContent (editorXml));
    }  
}

editorView::
~editorView ()
{
  // FIXME: it should not be necessary
  gtk_widget_destroy (p_view);
}

gboolean
editorView::saveNode (xmlNodePtr tree)
{
  gchar *text;
  xmlNodePtr textNode;

  text = gtk_text_view_get_text (GTK_TEXT_VIEW (p_textView));
  if (strlen (text) != 0) {
    textNode = xmlNewChild (tree, NULL, BAD_CAST "text", BAD_CAST text);
    xmlSetProp (textNode, BAD_CAST "name", BAD_CAST p_name);
    g_free (text);
    return true;
  }	    
  else {
    g_free (text);
    return false;
  }
}

gpointer
editorView::createWidgetView ()
{
  p_view = gtk_scrolled_window_new (NULL, NULL);
  p_textView = gtk_text_view_new ();
  gtk_text_view_set_editable(GTK_TEXT_VIEW (p_textView),
			     TRUE);
  gtk_container_add (GTK_CONTAINER(p_view), p_textView);

  gtk_widget_show_all (p_view);

  /* No WidgetView class is created, only plain GtkWidget */
  return NULL;
}

GtkWidget *
editorView::widgetView ()
{
  return p_view;
}