9 #include <ScintillaWidget.h>
12 static int IntFromHexDigit(int ch
) {
13 if ((ch
>= '0') && (ch
<= '9')) {
15 } else if (ch
>= 'A' && ch
<= 'F') {
17 } else if (ch
>= 'a' && ch
<= 'f') {
24 static int IntFromHexByte(const char *hexByte
) {
25 return IntFromHexDigit(hexByte
[0]) * 16 + IntFromHexDigit(hexByte
[1]);
29 Colour
ColourRGB(unsigned int red
, unsigned int green
, unsigned int blue
)
31 return red
| (green
<< 8) | (blue
<< 16);
34 static Colour
ColourFromString(const char *s
) {
35 if ((s
!= NULL
) && (*s
!= '\0')) {
36 int r
= IntFromHexByte(s
+ 1);
37 int g
= IntFromHexByte(s
+ 3);
38 int b
= IntFromHexByte(s
+ 5);
39 return ColourRGB(r
, g
, b
);
45 void SetOneStyle(GtkWidget
*sci
, int style
, const char *s
) {
46 char *val
= strdup(s
);
49 char *cpComma
= strchr(opt
, ',');
52 char *colon
= strchr(opt
, ':');
55 if (0 == strcmp(opt
, "italics"))
56 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETITALIC
, style
, 1);
57 if (0 == strcmp(opt
, "notitalics"))
58 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETITALIC
, style
, 0);
59 if (0 == strcmp(opt
, "bold"))
60 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETBOLD
, style
, 1);
61 if (0 == strcmp(opt
, "notbold"))
62 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETBOLD
, style
, 0);
63 if (0 == strcmp(opt
, "font"))
64 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETFONT
, style
, reinterpret_cast<long>(colon
));
65 if (0 == strcmp(opt
, "fore"))
66 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETFORE
, style
, ColourFromString(colon
));
67 if (0 == strcmp(opt
, "back"))
68 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETBACK
, style
, ColourFromString(colon
));
69 if (0 == strcmp(opt
, "size"))
70 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETSIZE
, style
, atoi(colon
));
71 if (0 == strcmp(opt
, "eolfilled"))
72 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETEOLFILLED
, style
, 1);
73 if (0 == strcmp(opt
, "noteolfilled"))
74 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETEOLFILLED
, style
, 0);
75 if (0 == strcmp(opt
, "underlined"))
76 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETUNDERLINE
, style
, 1);
77 if (0 == strcmp(opt
, "notunderlined"))
78 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETUNDERLINE
, style
, 0);
79 if (0 == strcmp(opt
, "case")) {
81 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETCASE
, style
, SC_CASE_UPPER
);
82 } else if (*colon
== 'l') {
83 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETCASE
, style
, SC_CASE_LOWER
);
85 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETCASE
, style
, SC_CASE_MIXED
);
88 if (0 == strcmp(opt
, "visible"))
89 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETVISIBLE
, style
, 1);
90 if (0 == strcmp(opt
, "notvisible"))
91 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETVISIBLE
, style
, 0);
92 if (0 == strcmp(opt
, "changeable"))
93 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETCHANGEABLE
, style
, 1);
94 if (0 == strcmp(opt
, "notchangeable"))
95 scintilla_send_message(SCINTILLA(sci
), SCI_STYLESETCHANGEABLE
, style
, 0);
103 // scintilla_send_message(SCINTILLA(sci), SCI_STYLESETCHARACTERSET, style, characterSet);
106 int main(int argc
, char **argv
)
111 size_t read_bytes
= 0;
114 gtk_init (&argc
, &argv
);
117 printf ("Usage: test-scintilla filename\n");
120 win
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
121 sci
= scintilla_new();
122 SetOneStyle (sci
, STYLE_DEFAULT
,
123 "font:bitstream vera sans mono,size:10,back:#EFEFEF");
124 scintilla_send_message(SCINTILLA(sci
), SCI_SETWRAPMODE
, SC_WRAP_WORD
, 0);
125 scintilla_send_message(SCINTILLA(sci
), SCI_SETHSCROLLBAR
, 0, 0);
126 scintilla_send_message(SCINTILLA(sci
), SCI_SETCODEPAGE
, SC_CP_UTF8
, 0);
127 scintilla_send_message(SCINTILLA(sci
), SCI_SETMARGINWIDTHN
, 0, 40);
128 scintilla_set_id(SCINTILLA(sci
), 0);
129 gtk_container_add (GTK_CONTAINER(win
), sci
);
130 g_signal_connect (G_OBJECT (win
), "delete-event",
131 G_CALLBACK (gtk_main_quit
), NULL
);
132 gtk_widget_set_size_request (GTK_WIDGET (win
), 500, 600);
133 gtk_window_set_default_size (GTK_WINDOW (win
), 500, 600);
134 gtk_widget_show (sci
);
135 gtk_widget_show (win
);
136 fp
= fopen (argv
[1], "r");
139 perror ("Unable to open file\n");
142 while ((read_bytes
= fread (buffer
, 1, 1024, fp
)) > 0)
144 buffer
[read_bytes
] = '\0';
145 scintilla_send_message(SCINTILLA(sci
), SCI_APPENDTEXT
, read_bytes
, reinterpret_cast<long>(buffer
));