File: mc_space.c

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (94 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download
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
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */

#include "mc_space.h"

#include <pobl/bl_str.h>
#include <pobl/bl_mem.h> /* free */
#include <pobl/bl_debug.h>
#include <pobl/bl_util.h> /* BL_ARRAY_SIZE */
#include <glib.h>
#include <c_intl.h>

#include "mc_combo.h"
#include "mc_io.h"

#if 0
#define __DEBUG
#endif

#define MAX_VALUE_LEN 2

/* --- static variables --- */

static char new_values[MC_SPACES][MAX_VALUE_LEN + 1]; /* -9...99 */
static char old_values[MC_SPACES][MAX_VALUE_LEN + 1]; /* -9...99 */
static int is_changed[MC_SPACES];

static char *config_keys[MC_SPACES] = {
  "line_space", "letter_space", "baseline_offset", "underline_offset",
};

static char *labels[MC_SPACES] = {
  N_("Line space (pixels)"), N_("Letter space (pixels)"), N_("Baseline position (pixels)"),
  N_("Underline position (pixels)"),
};

/* --- static functions --- */

static void space_selected(GtkWidget *widget, gpointer data) {
  gchar *text;

  text = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
  if (strlen(text) <= MAX_VALUE_LEN) {
    strcpy(data, text);
  }
  g_free(text);

#ifdef __DEBUG
  bl_debug_printf(BL_DEBUG_TAG " %s space is selected.\n", text);
#endif
}

/* --- global functions --- */

GtkWidget *mc_space_config_widget_new(int id) {
  char *value;
  GtkWidget *combo;
  GtkWidget *entry;
  char *spaces[] = {
    "3", "2", "1", "0", "-1", "-2",
  };
  char *spaces2[] = {
    "5", "4", "3", "2", "1", "0",
  };

  value = mc_get_str_value(config_keys[id]);
  if (strlen(value) <= MAX_VALUE_LEN) {
    strcpy(new_values[id], value);
    strcpy(old_values[id], value);
  }
  free(value);

  if (id == MC_SPACE_LETTER) {
    combo = mc_combo_new_with_width(_(labels[id]), spaces2, BL_ARRAY_SIZE(spaces2),
                                    new_values[id], 0, 20, &entry);
  } else {
    combo = mc_combo_new_with_width(_(labels[id]), spaces, BL_ARRAY_SIZE(spaces),
                                    new_values[id], 0, 20, &entry);
  }

  g_signal_connect(entry, "changed", G_CALLBACK(space_selected), &new_values[id]);

  return combo;
}

void mc_update_space(int id) {
  if (strcmp(new_values[id], old_values[id])) {
    is_changed[id] = 1;
  }

  if (is_changed[id]) {
    mc_set_str_value(config_keys[id], new_values[id]);
    strcpy(old_values[id], new_values[id]);
  }
}