ui_signal_dissect_view.c 2.79 KB
Newer Older
Cedric Roux's avatar
   
Cedric Roux committed
1
2
3
4
#include <string.h>

#include <gtk/gtk.h>

5
#include "rc.h"
Cedric Roux's avatar
   
Cedric Roux committed
6
7
8
9
10

#include "ui_main_screen.h"
#include "ui_menu_bar.h"
#include "ui_signal_dissect_view.h"

Cedric Roux's avatar
Cedric Roux committed
11
ui_text_view_t *ui_signal_dissect_new(GtkWidget *hbox)
Cedric Roux's avatar
   
Cedric Roux committed
12
13
{
    GtkWidget *scrolled_window;
Cedric Roux's avatar
Cedric Roux committed
14
    ui_text_view_t *new_text_view;
Cedric Roux's avatar
   
Cedric Roux committed
15

Cedric Roux's avatar
Cedric Roux committed
16
17
18
    new_text_view = malloc(sizeof(ui_text_view_t));

    new_text_view->text_view = gtk_text_view_new();
Cedric Roux's avatar
   
Cedric Roux committed
19
20
21
22
23
    scrolled_window = gtk_scrolled_window_new(NULL, NULL);

    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);

24
25
26
27
28
29
30
31
32
33
34
35
    /* Change the font of the widget */
    new_text_view->text_view_font = pango_font_description_new();

    g_debug("Default family is: %s\n", pango_font_description_get_family(new_text_view->text_view_font));

    pango_font_description_set_family(new_text_view->text_view_font, "Monospace");
    pango_font_description_set_absolute_size(new_text_view->text_view_font, 10 * PANGO_SCALE);

    g_debug("Font family has been set to: %s\n", pango_font_description_get_family(new_text_view->text_view_font));

    gtk_widget_override_font(new_text_view->text_view, new_text_view->text_view_font);

Cedric Roux's avatar
   
Cedric Roux committed
36
    /* Disable editable attribute */
Cedric Roux's avatar
Cedric Roux committed
37
    gtk_text_view_set_editable(GTK_TEXT_VIEW(new_text_view->text_view), FALSE);
Cedric Roux's avatar
   
Cedric Roux committed
38

39
    gtk_container_add(GTK_CONTAINER(scrolled_window), new_text_view->text_view);
Cedric Roux's avatar
   
Cedric Roux committed
40

41
    gtk_paned_pack2 (GTK_PANED (hbox), scrolled_window, TRUE, FALSE);
Cedric Roux's avatar
   
Cedric Roux committed
42

Cedric Roux's avatar
Cedric Roux committed
43
    return new_text_view;
Cedric Roux's avatar
   
Cedric Roux committed
44
45
}

Cedric Roux's avatar
Cedric Roux committed
46
int ui_signal_dissect_clear_view(ui_text_view_t *text_view)
Cedric Roux's avatar
   
Cedric Roux committed
47
{
Cedric Roux's avatar
Cedric Roux committed
48
    GtkTextBuffer *text_buffer;
Cedric Roux's avatar
   
Cedric Roux committed
49

Cedric Roux's avatar
Cedric Roux committed
50
    g_assert(text_view != NULL);
Cedric Roux's avatar
   
Cedric Roux committed
51

Cedric Roux's avatar
Cedric Roux committed
52
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view->text_view));
Cedric Roux's avatar
   
Cedric Roux committed
53
54

    /* If a text buffer is present for the textview remove it */
Cedric Roux's avatar
Cedric Roux committed
55
56
    if (text_buffer != NULL) {
        gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_view->text_view), NULL);
Cedric Roux's avatar
   
Cedric Roux committed
57
    }
Cedric Roux's avatar
Cedric Roux committed
58

Cedric Roux's avatar
   
Cedric Roux committed
59
60
61
    return RC_OK;
}

Cedric Roux's avatar
Cedric Roux committed
62
gboolean ui_signal_set_text(gpointer user_data, gchar *text, gint length)
Cedric Roux's avatar
   
Cedric Roux committed
63
{
Cedric Roux's avatar
Cedric Roux committed
64
65
    GtkTextBuffer  *text_buffer;
    ui_text_view_t *text_view;
Cedric Roux's avatar
   
Cedric Roux committed
66
67

    if (length < 0)
Cedric Roux's avatar
Cedric Roux committed
68
        return FALSE;
Cedric Roux's avatar
   
Cedric Roux committed
69

Cedric Roux's avatar
Cedric Roux committed
70
    text_view = (ui_text_view_t *)user_data;
Cedric Roux's avatar
   
Cedric Roux committed
71

Cedric Roux's avatar
Cedric Roux committed
72
73
74
    g_assert(text != NULL);
    g_assert(text_view != NULL);
    g_assert(text_view->text_view != NULL);
Cedric Roux's avatar
   
Cedric Roux committed
75

Cedric Roux's avatar
Cedric Roux committed
76
    g_assert(GTK_IS_TEXT_VIEW(GTK_TEXT_VIEW(text_view->text_view)));
Cedric Roux's avatar
   
Cedric Roux committed
77

Cedric Roux's avatar
Cedric Roux committed
78
79
80
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view->text_view));

    if (text_buffer) {
Cedric Roux's avatar
   
Cedric Roux committed
81
        /* We already have a text buffer, use it */
Cedric Roux's avatar
Cedric Roux committed
82
        gtk_text_buffer_insert_at_cursor(text_buffer, text, length);
Cedric Roux's avatar
   
Cedric Roux committed
83
84
    } else {
        /* No buffer currently in use, create a new one */
Cedric Roux's avatar
Cedric Roux committed
85
86
87
88
        text_buffer = gtk_text_buffer_new(NULL);
        gtk_text_buffer_set_text(text_buffer, text, length);
        gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_view->text_view),
                                 text_buffer);
Cedric Roux's avatar
   
Cedric Roux committed
89
90
    }

Cedric Roux's avatar
Cedric Roux committed
91
    return TRUE;
Cedric Roux's avatar
   
Cedric Roux committed
92
}