ui_signal_dissect_view.c 3.86 KB
Newer Older
1
2
3
4
5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

Cedric Roux's avatar
 
Cedric Roux committed
22
23
#include <string.h>

24
25
#define G_LOG_DOMAIN ("UI")

Cedric Roux's avatar
 
Cedric Roux committed
26
27
#include <gtk/gtk.h>

28
#include "rc.h"
Cedric Roux's avatar
 
Cedric Roux committed
29
30
31
32
33

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

Cedric Roux's avatar
Cedric Roux committed
34
ui_text_view_t *ui_signal_dissect_new(GtkWidget *hbox)
Cedric Roux's avatar
 
Cedric Roux committed
35
36
{
    GtkWidget *scrolled_window;
Cedric Roux's avatar
Cedric Roux committed
37
    ui_text_view_t *new_text_view;
Cedric Roux's avatar
 
Cedric Roux committed
38

Cedric Roux's avatar
Cedric Roux committed
39
40
41
    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
42
43
44
45
46
    scrolled_window = gtk_scrolled_window_new(NULL, NULL);

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

47
48
49
50
51
52
53
54
55
56
57
58
    /* 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
59
    /* Disable editable attribute */
Cedric Roux's avatar
Cedric Roux committed
60
    gtk_text_view_set_editable(GTK_TEXT_VIEW(new_text_view->text_view), FALSE);
Cedric Roux's avatar
 
Cedric Roux committed
61

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

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

Cedric Roux's avatar
Cedric Roux committed
66
    return new_text_view;
Cedric Roux's avatar
 
Cedric Roux committed
67
68
}

Cedric Roux's avatar
Cedric Roux committed
69
int ui_signal_dissect_clear_view(ui_text_view_t *text_view)
Cedric Roux's avatar
 
Cedric Roux committed
70
{
Cedric Roux's avatar
Cedric Roux committed
71
    GtkTextBuffer *text_buffer;
Cedric Roux's avatar
 
Cedric Roux committed
72

Cedric Roux's avatar
Cedric Roux committed
73
    g_assert(text_view != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
74

75
76
    if (text_view->text_view != NULL)
    {
winckel's avatar
winckel committed
77
78
79
        /* Create an empty text buffer */
        text_buffer = gtk_text_buffer_new(NULL);
        gtk_text_buffer_set_text(text_buffer, "", 0);
80

winckel's avatar
winckel committed
81
        gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_view->text_view), text_buffer);
Cedric Roux's avatar
 
Cedric Roux committed
82
    }
Cedric Roux's avatar
Cedric Roux committed
83

Cedric Roux's avatar
 
Cedric Roux committed
84
85
86
    return RC_OK;
}

Cedric Roux's avatar
Cedric Roux committed
87
gboolean ui_signal_set_text(gpointer user_data, gchar *text, gint length)
Cedric Roux's avatar
 
Cedric Roux committed
88
{
Cedric Roux's avatar
Cedric Roux committed
89
90
    GtkTextBuffer  *text_buffer;
    ui_text_view_t *text_view;
Cedric Roux's avatar
 
Cedric Roux committed
91
92

    if (length < 0)
Cedric Roux's avatar
Cedric Roux committed
93
        return FALSE;
Cedric Roux's avatar
 
Cedric Roux committed
94

Cedric Roux's avatar
Cedric Roux committed
95
    text_view = (ui_text_view_t *)user_data;
Cedric Roux's avatar
 
Cedric Roux committed
96

Cedric Roux's avatar
Cedric Roux committed
97
98
99
    g_assert(text != NULL);
    g_assert(text_view != NULL);
    g_assert(text_view->text_view != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
100

Cedric Roux's avatar
Cedric Roux committed
101
    g_assert(GTK_IS_TEXT_VIEW(GTK_TEXT_VIEW(text_view->text_view)));
Cedric Roux's avatar
 
Cedric Roux committed
102

Cedric Roux's avatar
Cedric Roux committed
103
104
105
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view->text_view));

    if (text_buffer) {
Cedric Roux's avatar
 
Cedric Roux committed
106
        /* We already have a text buffer, use it */
Cedric Roux's avatar
Cedric Roux committed
107
        gtk_text_buffer_insert_at_cursor(text_buffer, text, length);
Cedric Roux's avatar
 
Cedric Roux committed
108
109
    } else {
        /* No buffer currently in use, create a new one */
Cedric Roux's avatar
Cedric Roux committed
110
111
112
113
        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
114
115
    }

Cedric Roux's avatar
Cedric Roux committed
116
    return TRUE;
Cedric Roux's avatar
 
Cedric Roux committed
117
}