File: gui.c

package info (click to toggle)
sc-im 0.8.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,972 kB
  • sloc: lisp: 32,533; ansic: 19,618; yacc: 1,489; xml: 518; sh: 410; makefile: 307; sed: 4
file content (185 lines) | stat: -rw-r--r-- 4,119 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* gtk ui */
#include <unistd.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <wchar.h>

#include "main.h"
#include "conf.h"
#include "input.h"
#include "tui.h"
#include "range.h"
#include "sc.h"
#include "cmds.h"
#include "cmds_visual.h"
#include "conf.h"
#include "version.h"
#include "file.h"
#include "format.h"
#include "utils/string.h"


#define NB_ENABLE 0
#define NB_DISABLE 1

static wint_t buf[1000];

static void on_key_press(GtkWidget *widget, GdkEventKey * event, gpointer data) {
    if (event->hardware_keycode == 0 ||
        event->hardware_keycode == 50 ||
        event->hardware_keycode == 66 ||
        event->hardware_keycode == 62 ||
        event->hardware_keycode == 105 ||
        event->hardware_keycode == 37 ||
        event->hardware_keycode == 64) return;
    buf[0] = event->keyval;
    g_print("key pressed: %d %c\n", event->hardware_keycode, event->keyval);
    return;
}

/* this function asks user for input from stdin.
 * should be non blocking and should
 * return -1 when no key was press
 * return 0 when key was press.
 * it receives * wint_t as a parameter.
 * when a valid key is press, its value its then updated in that wint_t variable.
 */
int ui_getch(wint_t * wd) {
    gtk_main_iteration();
    *wd = buf[0];

    if (buf[0] == GDK_KEY_Return) {
        *wd = 10;
    } else if (buf[0] == GDK_KEY_Escape)
        *wd = OKEY_ESC;

    //printf("char: %d\n", *wd);
    buf[0]=0;
    return 0;
}
void ui_start_screen() {
    buf[0]=0;
    GtkWidget *window;
    GtkWidget *t;

    gtk_init(0, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    t = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(t), 0);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(t, "key_press_event", G_CALLBACK(on_key_press), NULL);

    gtk_container_add(GTK_CONTAINER (window), t);
    gtk_widget_show(t);
    gtk_widget_show(window);
    printf("started screen\n");
}

void ui_stop_screen() {
    gtk_main_quit();
    printf("stopped screen\n");
}


/* this function asks user for input from stdin.
 * should be blocking and should
 * return -1 when ESC was pressed
 * return 0 otherwise.
 * it receives * wint_t as a parameter.
 * when a valid key is press, its value its then updated in that wint_t variable.
 */
int ui_getch_b(wint_t * wd) {
    printf("calling uigetch_b\n");
    return -1;
}

// sc_msg - used for sc_info, sc_error and sc_debug macros
void ui_sc_msg(char * s, int type, ...) {
    char t[BUFFERSIZE];
    va_list args;
    va_start(args, type);
    vsprintf (t, s, args);
    printf("%s\n", t);
    va_end(args);
    return;
}

// Welcome screen
void ui_do_welcome() {
    printf("welcome screen\n");
    return;
}

// function that refreshes grid of screen
// if header flag is set, the first column of screen gets refreshed
void ui_update(int header) {
    printf("update\n");
    printf("value of current cell: %d %d %f\n", currow, curcol, lookat(currow, curcol)->v);
    return;
}

// Enable cursor and echo depending on the current mode
void ui_handle_cursor() {
}

// Print multiplier and pending operator on the status bar
void ui_print_mult_pend() {
    return;
}

void ui_show_header() {
    return;
}

void ui_clr_header(int i) {
    return;
}

void ui_print_mode() {
    return;
}

// Draw cell content detail in header
void ui_show_celldetails() {
    return;
}

// error routine for yacc (gram.y)
void yyerror(char * err) {
    printf("%s: %.*s<=%s\n", err, linelim, line, line + linelim);
    return;
}

int ui_get_formated_value(struct ent ** p, int col, char * value) {
    return -1;
}

void ui_show_text(char * val) {
    printf("%s", val);
    return;
}

void winchg() {
    return;
}

#ifdef XLUA
/* function to print errors of lua scripts */
void ui_bail(lua_State *L, char * msg) {
    return;
}
#endif

/* function to read text from stdin */
char * ui_query(char * initial_msg) {
    return NULL;
}

void ui_start_colors() {
    return;
}