53 #include "contiki-net.h"
55 #include "ctk/vnc-server.h"
56 #include "ctk/vnc-out.h"
58 #include "ctk/ctk-vncfont.h"
59 #include "ctk/ctk-vncserver.h"
62 static unsigned char sizex, sizey;
64 #define CH_ULCORNER 0x00
65 #define CH_TITLEBAR 0x01
66 #define CH_URCORNER 0x02
67 #define CH_WINDOWRBORDER 0x03
68 #define CH_LRCORNER 0x04
69 #define CH_WINDOWLOWERBORDER 0x05
70 #define CH_LLCORNER 0x06
71 #define CH_WINDOWLBORDER 0x07
73 #define CH_DIALOG_ULCORNER 0x12
74 #define CH_DIALOGUPPERBORDER 0x09
75 #define CH_DIALOG_URCORNER 0x0a
76 #define CH_DIALOGRBORDER 0x0b
77 #define CH_DIALOG_LRCORNER 0x0c
78 #define CH_DIALOGLOWERBORDER 0x0d
79 #define CH_DIALOG_LLCORNER 0x0e
80 #define CH_DIALOGLBORDER 0x0f
82 #define CH_BUTTONLEFT 0x10
83 #define CH_BUTTONRIGHT 0x11
85 #define CH_SEPARATOR 0x13
87 #include "lib/libconio.h"
93 #define WIDGETCOLOR_FWIN 3
94 #define WIDGETCOLOR_FOCUS 4
95 #define WIDGETCOLOR_DIALOG 5
96 #define WIDGETCOLOR_HLINK 6
97 #define WIDGETCOLOR_HLINK_FOCUS 7
100 #define WINDOWCOLOR_FOCUS 9
102 #define WINDOWBORDER 10
103 #define WINDOWBORDER_FOCUS 11
105 #define DIALOGCOLOR 12
107 #define OPENMENUCOLOR 13
109 #define ACTIVEMENUITEMCOLOR 14
114 PROCESS(ctk_vncserver_process,
"CTK VNC server");
116 static struct vnc_server_state conns[CTK_VNCSERVER_CONF_NUMCONNS];
122 unsigned char ctk_draw_windowborder_height = 1;
123 unsigned char ctk_draw_windowborder_width = 1;
124 unsigned char ctk_draw_windowtitle_height = 1;
140 struct vnc_server_update *a)
143 a->next = vs->updates_pending;
144 vs->updates_pending = a;
158 struct vnc_server_update *
161 struct vnc_server_update *a;
163 a = vs->updates_free;
167 vs->updates_free = a->next;
184 struct vnc_server_update *a)
186 a->next = vs->updates_free;
187 vs->updates_free = a;
200 struct vnc_server_update *
203 struct vnc_server_update *a;
205 a = vs->updates_pending;
209 vs->updates_pending = a->next;
223 struct vnc_server_update *a)
225 struct vnc_server_update *b, *c;
227 if(a == vs->updates_pending) {
228 vs->updates_pending = a->next;
230 b = vs->updates_pending;
231 for(c = vs->updates_pending; c != a; b = c, c = c->next);
243 update_area(u8_t x, u8_t y, u8_t w, u8_t h)
247 if(h == 0 || w == 0) {
252 for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) {
253 if(conns[i].state != VNC_DEALLOCATED) {
254 vnc_out_update_area(&conns[i],
266 static struct vnc_server_state *
270 for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) {
271 if(conns[i].state == VNC_DEALLOCATED) {
277 for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) {
278 conns[i].state = VNC_DEALLOCATED;
289 dealloc_state(
struct vnc_server_state *s)
291 s->state = VNC_DEALLOCATED;
295 cputsn(
char *str,
unsigned char len)
318 bgcolor(SCREENCOLOR);
319 bordercolor(BORDERCOLOR);
320 screensize(&sizex, &sizey);
326 unsigned char x,
unsigned char y,
329 unsigned char clipy1,
unsigned char clipy2,
332 unsigned char xpos, ypos, xscroll;
334 unsigned char iconnum;
358 textcolor(VNC_OUT_SEPARATORCOLOR + focus);
359 if(ypos >= clipy1 && ypos < clipy2) {
362 for(i = 0; i < w->
w; ++i) {
368 textcolor(VNC_OUT_LABELCOLOR + focus);
369 text = w->
widget.label.text;
370 for(i = 0; i < w->
h; ++i) {
371 if(ypos >= clipy1 && ypos < clipy2) {
374 if(w->
w - (wherex() - xpos) > 0) {
375 cclear(w->
w - (wherex() - xpos));
383 textcolor(VNC_OUT_BUTTONCOLOR + focus);
384 if(ypos >= clipy1 && ypos < clipy2) {
390 cputcxy(xpos, ypos, CH_BUTTONLEFT);
392 cputc(CH_BUTTONRIGHT);
397 textcolor(VNC_OUT_HYPERLINKCOLOR + focus);
398 if(ypos >= clipy1 && ypos < clipy2) {
412 textcolor(VNC_OUT_TEXTENTRYCOLOR + focus);
413 text = w->
widget.textentry.text;
415 if(w->
widget.textentry.xpos >= w->
w - 1) {
416 xscroll = w->
widget.textentry.xpos - w->
w + 1;
418 for(j = 0; j < w->
h; ++j) {
419 if(ypos >= clipy1 && ypos < clipy2) {
420 if(w->
widget.textentry.state == CTK_TEXTENTRY_EDIT &&
421 w->
widget.textentry.ypos == j) {
423 cputcxy(xpos, ypos,
'>');
425 for(i = 0; i < w->
w; ++i) {
427 c = text[i + xscroll];
429 if(i == w->
widget.textentry.xpos - xscroll) {
430 textcolor(VNC_OUT_TEXTENTRYCOLOR + (focus ^ 0x01));
441 textcolor(VNC_OUT_TEXTENTRYCOLOR + focus);
450 cvlinexy(xpos, ypos, 1);
451 gotoxy(xpos + 1, ypos);
454 if(i - xpos - 1 < w->
w) {
455 cclear(w->
w - (i - xpos) + 1);
461 text += w->
widget.textentry.len + 1;
467 if(ypos >= clipy1 && ypos < clipy2) {
468 textcolor(VNC_OUT_ICONCOLOR + focus);
476 len = strlen(w->
widget.icon.title);
477 if(x + len >= sizex) {
482 if(ypos >= clipy1 && ypos < clipy2) {
483 cputs(w->
widget.icon.title);
486 #if CTK_CONF_ICON_BITMAPS
488 iconnum = vnc_out_add_icon((
struct ctk_icon *)w);
489 textcolor(iconnum | (focus << 6));
543 unsigned char clipy1,
544 unsigned char clipy2)
547 struct ctk_icon *icon;
548 unsigned char posx, posy, x, len;
557 draw_widget(w, posx, posy,
564 update_area(posx + w->
x,
565 posy + w->
y, w->
w + 2, w->
h);
567 icon = (
struct ctk_icon *)w;
569 len = strlen(icon->title);
571 if(x + len >= sizex) {
575 update_area(x, posy + w->
y, len > 4? len: 4, w->
h);
578 #ifdef CTK_CONIO_CONF_UPDATE
579 CTK_CONIO_CONF_UPDATE();
595 unsigned char clipy1,
596 unsigned char clipy2)
606 textcolor(VNC_OUT_WINDOWCOLOR + focus);
608 h = window->y + 2 + window->
h;
610 for(i = window->y + 2; i < h; ++i) {
611 if(i >= clipy1 && i < clipy2) {
612 cclearxy(window->x + 1, i, window->
w);
616 update_area(window->x + 1, window->y + 2, window->
w, window->
h);
620 draw_window_contents(
struct ctk_window *window,
unsigned char focus,
621 unsigned char clipy1,
unsigned char clipy2,
622 unsigned char x1,
unsigned char x2,
623 unsigned char y1,
unsigned char y2)
626 unsigned char wfocus;
630 draw_widget(w, x1, y1, x2, y2,
642 draw_widget(w, x1, y1, x2, y2,
647 #ifdef CTK_CONIO_CONF_UPDATE
648 CTK_CONIO_CONF_UPDATE();
665 unsigned char clipy1,
unsigned char clipy2,
666 unsigned char draw_borders)
670 unsigned char x1, y1, x2, y2;
674 if(window->y + 1 >= clipy2) {
688 textcolor(VNC_OUT_WINDOWCOLOR + focus);
696 cputcxy(x, y, CH_ULCORNER);
697 for(i = wherex() + window->
titlelen + CTK_CONF_WINDOWMOVE * 2; i < x2; ++i) {
698 cputcxy(i, y, CH_TITLEBAR);
700 cputcxy(x2, y, CH_URCORNER);
706 if(clipy1 - y1 < h) {
714 if(clipy2 < y1 + h) {
722 for(i = y1; i < y1 +
h; ++i) {
723 cputcxy(x, i, CH_WINDOWLBORDER);
724 cputcxy(x2, i, CH_WINDOWRBORDER);
730 if(y + window->
h >= clipy1 &&
731 y + window->
h < clipy2) {
732 cputcxy(x, y2, CH_LLCORNER);
733 for(i = x1; i < x2; ++i) {
734 cputcxy(i, y2, CH_WINDOWLOWERBORDER);
737 cputcxy(x2, y2, CH_LRCORNER);
741 draw_window_contents(window, focus, clipy1, clipy2,
744 update_area(window->x, window->y, window->
w + 2, window->
h + 2);
758 unsigned char x1, y1, x2, y2;
775 for(i = y1; i < y1 + dialog->
h; ++i) {
776 cputcxy(x, i, CH_DIALOGLBORDER);
777 cputcxy(x2, i, CH_DIALOGRBORDER);
785 for(i = x1; i < x2; ++i) {
786 cputcxy(i, y, CH_DIALOGUPPERBORDER);
787 cputcxy(i, y2, CH_DIALOGLOWERBORDER);
794 cputcxy(x, y, CH_DIALOG_ULCORNER);
795 cputcxy(x, y2, CH_DIALOG_LLCORNER);
796 cputcxy(x2, y, CH_DIALOG_URCORNER);
797 cputcxy(x2, y2, CH_DIALOG_LRCORNER);
801 for(i = y1; i < y2; ++i) {
802 cclearxy(x1, i, dialog->
w);
808 update_area(dialog->x, dialog->y, dialog->
w + 4, dialog->
h + 4);
823 textcolor(VNC_OUT_BACKGROUNDCOLOR);
824 for(i = y1; i < y2; ++i) {
825 cclearxy(0, i, sizex);
828 update_area(0, y1, sizex, y2 - y1);
840 unsigned char x, x2,
y;
842 textcolor(VNC_OUT_MENUCOLOR);
847 if(x + CTK_CONF_MENUWIDTH > sizex) {
848 x = sizex - CTK_CONF_MENUWIDTH;
852 for(y = 0; y < m->
nitems; ++
y) {
854 textcolor(VNC_OUT_ACTIVEMENUCOLOR);
857 textcolor(VNC_OUT_MENUCOLOR);
861 chline(CTK_CONF_MENUWIDTH);
865 if(x + CTK_CONF_MENUWIDTH > wherex()) {
866 cclear(x + CTK_CONF_MENUWIDTH - wherex());
872 textcolor(VNC_OUT_MENUCOLOR);
874 update_area(x, 0, CTK_CONF_MENUWIDTH, m->
nitems + 1);
890 textcolor(VNC_OUT_MENUCOLOR);
895 if(m != menus->
open) {
896 update_area(wherex(), 0, strlen(m->
title) + 1, 1);
908 cclear(sizex - wherex() -
910 update_area(wherex(), 0, sizex - wherex() -
936 ctk_draw_height(
void)
954 ctk_mouse_xtoc(
unsigned short x)
956 return x / CTK_VNCFONT_WIDTH;
960 ctk_mouse_ytoc(
unsigned short y)
962 return y / CTK_VNCFONT_HEIGHT;
970 ascii2screen(
unsigned char c)
978 if(c > 0x20 && c < 0x40) {
981 if(c >= 0x40 && c < 0x60) {
984 if(c >= 0x60 && c < 0x80) {
1008 unsigned char reversedflag,
1009 unsigned char color)
1012 vnc_out_update_screen(xpos, ypos, ascii2screen(c),
1029 return vnc_out_keyavail();
1042 return vnc_out_getkey() & 0x7f;
1050 ctk_vncserver_appcall(
void *state)
1052 static struct vnc_server_state *vs;
1054 vs = (
struct vnc_server_state *)(state);
1068 tcp_markconn(
uip_conn, (
void *)vs);
1076 vnc_server_appcall(vs);
1087 for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) {
1088 conns[i].state = VNC_DEALLOCATED;
1093 ctk_vncserver_appcall(data);