[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Antiright-devel] antiright configure xshell/arguments.c xshell/a...
From: |
Jeffrey Bedard |
Subject: |
[Antiright-devel] antiright configure xshell/arguments.c xshell/a... |
Date: |
Fri, 20 Jul 2007 00:57:21 +0000 |
CVSROOT: /sources/antiright
Module name: antiright
Changes by: Jeffrey Bedard <jefbed> 07/07/20 00:57:21
Modified files:
. : configure
Added files:
xshell : arguments.c arguments.h decoration.c
decoration.h events.c events.h layout.c
layout.h shell.c shell.h text.c text.h
Log message:
Added xshell code.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/configure?cvsroot=antiright&r1=1.104&r2=1.105
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/arguments.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/arguments.h?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/decoration.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/decoration.h?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/events.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/events.h?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/layout.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/layout.h?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/shell.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/shell.h?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/text.c?cvsroot=antiright&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/antiright/xshell/text.h?cvsroot=antiright&rev=1.1
Patches:
Index: configure
===================================================================
RCS file: /sources/antiright/antiright/configure,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -b -r1.104 -r1.105
--- configure 11 Jun 2007 21:32:36 -0000 1.104
+++ configure 20 Jul 2007 00:57:20 -0000 1.105
@@ -28,6 +28,7 @@
USE_DISTCC=NO
USE_CCACHE=NO
+# Must be enabled.
USE_GTK=YES
for ARG in $@; do
Index: xshell/arguments.c
===================================================================
RCS file: xshell/arguments.c
diff -N xshell/arguments.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/arguments.c 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,115 @@
+
+#include "xshell.h"
+
+
+static void
+handle_options(XShell * xsh, int argc, char ** argv, unsigned int * counter)
+{
+ switch(argv[*counter][1])
+ {
+ case 'a': /* Add options. */
+ {
+ switch(argv[*counter][2])
+ {
+ case 'l': /* Label. */
+ xshell_button_new(xsh, xsh->gui.widgets,
+ argv[*counter]);
+ xsh->gui.last_widget->events.button_press
+ =xsh->gui.last_widget
+ ->events.button_press
+ =NULL;
+ break;
+ case 'r': /* Add a column. */
+ xsh->gui.layout.column_count++;
+ xsh->gui.layout.row_count=0;
+ break;
+ case 't': /* Field. */
+ xshell_text_new(xsh, xsh->gui.widgets, 0,
+ (*counter)*16, "TEXT");
+ break;
+ case 'T': /* Text Area. */
+ xshell_text_new(xsh, xsh->gui.widgets, 0,
+ (*counter)*16, "TEXT");
+ break;
+ }
+ }
+ break;
+ case 'o':
+ {
+ switch(argv[*counter][2])
+ {
+ case 'g':
+ {
+ unsigned int plus_ind=0;
+ size_t len;
+ char * x;
+ char * y;
+
+ (*counter)++;
+ len=strlen(argv[*counter]);
+ while(argv[*counter][plus_ind++]!='+'
+ && (plus_ind<len));
+ x=argv[*counter];
+ x[plus_ind-1]='\0';
+ y=&(x[plus_ind]);
+ xsh->gui.widgets->geometry.x=atoi(x);
+ xsh->gui.widgets->geometry.y=atoi(y);
+#ifdef DEBUG
+ printf("x:%s,y:%s\n", x, y);
+#endif /* DEBUG */
+ }
+ break;
+ case 'n':
+ /*xsh->gui.widgets
+ ->geometry.override_redirect
+ =True;*/
+ {
+ XSetWindowAttributes attr;
+ attr.override_redirect=True;
+ XUnmapWindow(xsh->gui.display,
+ xsh->gui.widgets->window);
+ XChangeWindowAttributes(
+ xsh->gui.display,
+ xsh->gui.widgets->window,
+ CWOverrideRedirect,
+ &attr);
+ XMapRaised(xsh->gui.display,
+ xsh->gui.widgets->window);
+ }
+ break;
+ case 'r':
+ (*counter)++;
+ xsh->gui.layout.max_row_count=
+ atoi(argv[*counter]);
+ printf("%d\n",
xsh->gui.layout.max_row_count);
+ break;
+ }
+ }
+ break;
+ case 't': /* test area */
+ {
+ }
+ break;
+ }
+}
+
+static void
+handle_argument(XShell * xsh, int argc, char ** argv, unsigned int * counter)
+{
+ if(argv[*counter][0]=='-')
+ handle_options(xsh, argc, argv, counter);
+ else
+ xshell_button_new(xsh, xsh->gui.widgets, argv[*counter]);
+}
+
+void
+xsh_parse_arguments(XShell * xsh, int argc, char ** argv)
+{
+ unsigned int counter;
+
+ for(counter=1; counter<(unsigned int)argc; counter++)
+ {
+ handle_argument(xsh, argc, argv, &counter);
+ }
+}
+
Index: xshell/arguments.h
===================================================================
RCS file: xshell/arguments.h
diff -N xshell/arguments.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/arguments.h 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,5 @@
+#ifndef XSH_ARGS_H
+#define XSH_ARGS_H
+void
+xsh_parse_arguments(XShell * xsh, int argc, char ** argv);
+#endif
Index: xshell/decoration.c
===================================================================
RCS file: xshell/decoration.c
diff -N xshell/decoration.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/decoration.c 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,145 @@
+#ifdef XSH_DECORATE
+#include "xshell.h"
+
+#define GRADIENT_DELTA 16
+
+
+static GC
+setup_gc(Display * display, Window window)
+{
+ return XCreateGC(display, window, 0, NULL);
+}
+
+static unsigned long
+get_color(Display * display,
+ unsigned short r, unsigned short g, unsigned short b)
+{
+ XColor color;
+
+ color.red=r*256;
+ color.green=g*256;
+ color.blue=b*256;
+ color.flags=DoRed|DoGreen|DoBlue;
+ XAllocColor(display, DefaultColormap(display, DefaultScreen(display)),
+ &color);
+
+ return color.pixel;
+}
+
+static void
+set_foreground(Display * display, GC gc, unsigned long color)
+{
+ XGCValues values;
+
+ /* Set up GC. */
+ values.foreground=color;
+ XChangeGC(display, gc, GCForeground, &values);
+}
+
+#define SET_COLOR(dpy, gc, r, g, b)\
+ set_foreground(dpy, gc, get_color(dpy, r, g, b))
+
+static void
+cleanup(Display * display, GC gc)
+{
+ XFreeGC(display, gc);
+}
+
+static void
+draw_frame(Display * dpy, Window win, GC gc, Bool outset,
+ XWindowAttributes geometry)
+{
+ short val;
+
+ val=outset?255:0;
+ SET_COLOR(dpy, gc, val, val, val);
+ /* top */
+ XDrawLine(dpy, win, gc, 0, 0, geometry.width, 0);
+ /* left */
+ XDrawLine(dpy, win, gc, 0, 0, 0, geometry.height);
+
+ val=!outset?255:0;
+ SET_COLOR(dpy, gc, val, val, val);
+ /* bottom */
+ XDrawLine(dpy, win, gc, 0, geometry.height-1,
+ geometry.width, geometry.height-1);
+ /* right */
+ XDrawLine(dpy, win, gc, geometry.width-1, 0,
+ geometry.width-1, geometry.height);
+
+ SET_COLOR(dpy, gc, 0xae, 0xff, 0xc3);
+ XFillArc(dpy, win, gc, geometry.width-8,
+ geometry.height/5, 4, 8, 0, 360*64);
+ SET_COLOR(dpy, gc, (0xae)/2, (0xb2)/2, (0xc3)/2);
+ XDrawArc(dpy, win, gc, geometry.width-8,
+ geometry.height/5, 4, 8, 0, 360*64);
+ SET_COLOR(dpy, gc, (0xae)/3, (0xb2)/3, (0xc3)/3);
+ XDrawArc(dpy, win, gc, geometry.width-8,
+ geometry.height/5, 5, 9, 0, 360*64);
+
+}
+
+#ifdef XSH_USE_GRADIENT
+static void
+draw_gradient(Display * display, Window window, GC gc,
+ XWindowAttributes * geometry, int order)
+{
+ unsigned int counter;
+
+ for(counter = 0; counter++<(unsigned int)geometry->height;)
+ {
+ unsigned int delta;
+ int y;
+
+ delta=-order*counter*4;
+ SET_COLOR(display, gc,
+ (0xae)+delta*(order),
+ (0xb2)+delta*(order),
+ (0xc3)+delta*(order));
+ /* Sunken or raised determined by Y start. */
+ y=(order >= 0) ? counter : geometry->height-counter;
+ /* Draw gradient portion. */
+ XDrawLine(display, window, gc,
+ 0, y, geometry->width, y);
+ }
+}
+
+void
+xsh_setup_gradients(XShell * xsh)
+{
+}
+
+#endif /* XSH_USE_GRADIENT */
+
+void
+xsh_decorate(XWidget * widget, int order)
+{
+ GC gc;
+ XShell * xsh;
+ Display * display;
+ Window window;
+
+ xsh=xsh_get_XShell_for_widget(widget);
+ gc=setup_gc(display=xsh->gui.display, window=widget->window);
+/* XClearWindow(display, window); */
+
+ /* Draw decoration */
+ {
+ XWindowAttributes geometry;
+
+ XGetWindowAttributes(display, window, &geometry);
+#ifdef XSH_USE_GRADIENT
+ draw_gradient(display, window, gc, &geometry, -order);
+#else /* not XSH_USE_GRADIENT */
+ SET_COLOR(display, gc, (0xae)+4*-order, (0xb2)+4*-order,
(0xc3)+4*-order);
+ XFillRectangle(display, window, gc,
+ 0, 0, geometry.width, geometry.height);
+#endif /* XSH_USE_GRADIENT */
+ draw_frame(display, window, gc, order!=1, geometry);
+ }
+ /* Free GC data. */
+ cleanup(display, gc);
+}
+
+#endif /* XSH_DECORATE */
+
Index: xshell/decoration.h
===================================================================
RCS file: xshell/decoration.h
diff -N xshell/decoration.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/decoration.h 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,17 @@
+#ifdef XSH_DECORATE
+
+#ifndef XSH_DECOR_H
+#define XSH_DECOR_H
+
+#define XSH_DECOR_IN 1
+#define XSH_DECOR_OUT -1
+
+void
+xsh_decorate(XWidget * widget, int order);
+
+void
+xsh_setup_gradients(XShell * xsh);
+
+#endif /* XSH_DECOR_H */
+
+#endif /* XSH_DECORATE */
Index: xshell/events.c
===================================================================
RCS file: xshell/events.c
diff -N xshell/events.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/events.c 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,123 @@
+
+#include "xshell.h"
+
+#ifndef DEBUG_EVENTS
+#undef XMSG
+#define XMSG
+#endif /* not DEBUG_EVENTS */
+
+#define XSH_EVENT(iter, event)\
+{\
+ if(iter->events.event)\
+ (iter->events.event)(iter);\
+}
+
+#ifdef DEBUG_EVENTS
+unsigned int xsh_expose_count=0;
+unsigned int xsh_configure_count=0;
+#endif /* DEBUG_EVENTS */
+
+static void
+select_event(XWidget * iter, XEvent * event)
+{
+#ifdef DEBUG_EVENTS
+ XMSG("select event");
+#endif
+ iter->event=event;
+ switch(event->type)
+ {
+ case Expose:
+ if(event->xexpose.count<1)
+ {
+#ifdef DEBUG_EVENTS
+ fprintf(stderr, "xsh_expose_count: %d\n",
+ ++xsh_expose_count);
+#endif /* DEBUG_EVENTS */
+ XSH_EVENT(iter, expose);
+ }
+ break;
+ case KeyPress:
+ XSH_EVENT(iter, key_press);
+ break;
+ case ButtonPress:
+ XSH_EVENT(iter, button_press);
+ break;
+ case ButtonRelease:
+ XSH_EVENT(iter, button_release);
+ break;
+ case ConfigureRequest:
+#ifdef DEBUG_EVENTS
+ fprintf(stderr, "xsh_configure_count: %d\n", ++xsh_configure_count);
+#endif /* DEBUG_EVENTS */
+ /* Unreachable. */
+/* XSH_EVENT(iter, configure);*/
+ break;
+ };
+
+}
+
+static void
+xshell_foreach_XWidget(XWidget * head, XEvent * event)
+{
+ XWidget * iter;
+
+ XMSG("xshell_foreach_XWidget()");
+ iter=head;
+ while(iter)
+ {
+ XMSG("event received");
+#ifdef DEBUG
+ assert(iter);
+#endif /* DEBUG */
+ /* Only process event if it occurs on a particular window. */
+ if(event->xany.window!=iter->window)
+ {
+ iter=iter->next;
+ continue;
+ }
+ select_event(iter, event);
+ iter=iter->next;
+ }
+ XMSG("end xshell_foreach_XWidget()");
+}
+
+void
+xsh_nullify_widget_events(XWidget * widget)
+{
+ widget->events.expose=NULL;
+ widget->events.key_press=NULL;
+ widget->events.button_press=NULL;
+ widget->events.button_release=NULL;
+ widget->events.configure=NULL;
+}
+
+void
+xsh_event_loop(XShell * xsh)
+{
+ XEvent event;
+ Display *dpy;
+
+ for(dpy=xsh->gui.display;;XNextEvent(dpy, &event))
+ {
+ if(event.type==ConfigureNotify)
+ {
+#ifdef DEBUG_EVENTS
+ XMSG("ConfigureNotify");
+#endif /* DEBUG_EVENTS */
+ /* puts("resize"); */
+ xsh->gui.widgets->geometry.width
+ =event.xconfigure.width;
+ if(event.xany.window == xsh->gui.widgets->window)
+ xsh->gui.widgets->geometry.height
+ =event.xconfigure.height;
+ // if(event.xexpose.count < 1)
+ xsh_layout_widgets(xsh);
+ XFlush(dpy);
+ }
+ else
+ xshell_foreach_XWidget(xsh->gui.widgets, &event);
+
+ XFlush(dpy);
+ }
+}
+
Index: xshell/events.h
===================================================================
RCS file: xshell/events.h
diff -N xshell/events.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/events.h 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,9 @@
+
+#ifndef XSH_EVENTS_H
+#define XSH_EVENTS_H
+void
+xsh_nullify_widget_events(XWidget * widget);
+void
+xsh_event_loop(XShell * xsh);
+#endif
+
Index: xshell/layout.c
===================================================================
RCS file: xshell/layout.c
diff -N xshell/layout.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/layout.c 20 Jul 2007 00:57:20 -0000 1.1
@@ -0,0 +1,13 @@
+
+#include "xshell.h"
+
+void
+xsh_layout_widgets(XShell * xsh)
+{
+ XResizeWindow(xsh->gui.display, xsh->gui.widgets->window,
+ XSH_WIDGET_WIDTH*(xsh->gui.layout.column_count+1),
+ XSH_WIDGET_HEIGHT*(xsh->gui.layout.column_count>0
+ ? xsh->gui.layout.max_row_count
+ : xsh->gui.layout.row_count));
+}
+
Index: xshell/layout.h
===================================================================
RCS file: xshell/layout.h
diff -N xshell/layout.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/layout.h 20 Jul 2007 00:57:21 -0000 1.1
@@ -0,0 +1,10 @@
+#ifndef XSH_LAYOUT_H
+#define XSH_LAYOUT_H
+
+#define XSH_ROWS_PER_COLUMN 8
+#define XSH_WIDGET_WIDTH 84
+#define XSH_WIDGET_HEIGHT 16
+
+void
+xsh_layout_widgets(XShell * xsh);
+#endif /* XSH_LAYOUT_H */
Index: xshell/shell.c
===================================================================
RCS file: xshell/shell.c
diff -N xshell/shell.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/shell.c 20 Jul 2007 00:57:21 -0000 1.1
@@ -0,0 +1,75 @@
+#include "xshell.h"
+
+static void
+draw_label(XWidget * shell)
+{
+ XShell * xsh;
+ const char * label = shell->data;
+
+ xsh=(XShell *)shell->xsh;
+ XDrawString(xsh->gui.display, shell->window, xsh->gui.gc,
+ 3, 12, label, strlen(label));
+}
+
+static void
+expose(XWidget * button)
+{
+ draw_label(button);
+}
+
+static void
+button_press(XWidget * button)
+{
+ XSHButtonData * data;
+
+ XMSG("PRESSED");
+ data=(XSHButtonData *)button->data;
+ system(data->command);
+}
+
+static void
+key_press(XWidget * button)
+{
+ button_press(button);
+}
+
+static void
+configure(XWidget * button)
+{
+ expose(button);
+}
+
+static void
+setup_events(XWidget * button)
+{
+ button->events.expose=&expose;
+ button->events.configure=&configure;
+ button->events.key_press=&key_press;
+ button->events.button_press=&button_press;
+}
+
+void
+xshell_shell_new(XShell * xsh, XWidget * parent, int x, int y,
+ const char * command)
+{
+ XWidget * button;
+ XSHButtonData * data;
+ char * label;
+
+ xshell_XWidget_new(xsh, parent, x, y, 100, 16);
+ button=xsh->gui.last_widget;
+ data=malloc(sizeof(XSHButtonData));
+ data->command=(char *)command;
+ label=strchr(command, '#');
+ if(label)
+ {
+ data->label=label+1;
+ }
+ else
+ {
+ data->label=(char *)command;
+ }
+ button->data=data;
+ setup_events(button);
+}
+
Index: xshell/shell.h
===================================================================
RCS file: xshell/shell.h
diff -N xshell/shell.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/shell.h 20 Jul 2007 00:57:21 -0000 1.1
@@ -0,0 +1,12 @@
+
+#ifndef XSH_SHELL_H
+#define XSH_SHELL_H
+
+typedef struct XSHShellData XSHShellData;
+
+void
+xshell_shell_new(XShell * xsh, XWidget * parent, int x, int y,
+ const char * command);
+
+#endif /* XSH_SHELL_H */
+
Index: xshell/text.c
===================================================================
RCS file: xshell/text.c
diff -N xshell/text.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/text.c 20 Jul 2007 00:57:21 -0000 1.1
@@ -0,0 +1,78 @@
+#include "xshell.h"
+
+static void
+draw_label(XShell * xsh, XWidget * text)
+{
+ XSHTextData * data;
+ char * label;
+
+ data=(XSHTextData *)text->data;
+ label=data->label;
+
+ XDrawString(xsh->gui.display, text->window, xsh->gui.gc,
+ 5, 12, label, strlen(label));
+}
+
+static void
+expose(XWidget * text)
+{
+ draw_label((XShell *)(text->xsh), text);
+}
+
+static void
+button_press(XWidget * text)
+{
+ XSHTextData * data;
+
+ XMSG("PRESSED");
+ data=(XSHTextData *)text->data;
+ draw_label((XShell *)(text->xsh), text);
+ system(data->command);
+}
+
+static void
+button_release(XWidget * text)
+{
+ expose(text);
+}
+
+static void
+key_press(XWidget * text)
+{
+ button_press(text);
+}
+
+static void
+configure(XWidget * text)
+{
+ expose(text);
+}
+
+static void
+setup_events(XWidget * text)
+{
+ text->events.expose=&expose;
+ text->events.configure=&configure;
+ text->events.key_press=&key_press;
+ text->events.button_press=&button_press;
+ text->events.button_release=&button_release;
+}
+
+void
+xshell_text_new(XShell * xsh, XWidget * parent, int x, int y,
+ const char * command)
+{
+ XWidget * text;
+ XSHTextData * data;
+ char * label;
+
+ xshell_XWidget_new(xsh, parent, x, y, 100, 16);
+ text=xsh->gui.last_widget;
+ data=malloc(sizeof(XSHTextData));
+ data->command=(char *)command;
+ label=strchr(command, '#');
+ data->label= label ? label+1 : (char *) command;
+ text->data=data;
+ setup_events(text);
+}
+
Index: xshell/text.h
===================================================================
RCS file: xshell/text.h
diff -N xshell/text.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ xshell/text.h 20 Jul 2007 00:57:21 -0000 1.1
@@ -0,0 +1,18 @@
+
+#ifndef XSH_TEXT_H
+#define XSH_TEXT_H
+
+struct XSHTextData
+{
+ char * command;
+ char * label;
+};
+
+typedef struct XSHTextData XSHTextData;
+
+void
+xshell_text_new(XShell * xsh, XWidget * parent, int x, int y,
+ const char * command);
+
+#endif /* XSH_TEXT_H */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Antiright-devel] antiright configure xshell/arguments.c xshell/a...,
Jeffrey Bedard <=