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
|
#include "userbut.h"
#include "color.h"
#include "ggets.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "kbs.h"
#define USERBUTCOLOR 24
#define USERBUTMAX 20
int nuserbut=0;
USERBUT userbut[USERBUTMAX];
extern int MyAddedButtonColor;
extern Display *display;
extern Window main_win;
Window make_fancy_window();
extern int DCURYs,DCURXs,CURY_OFFs;
extern GC small_gc;
void user_button_events(XEvent report)
{
switch(report.type){
case Expose:
case MapNotify:
user_button_draw(report.xany.window);
break;
case EnterNotify:
user_button_cross(report.xcrossing.window,2);
break;
case LeaveNotify:
user_button_cross(report.xcrossing.window,1);
break;
case ButtonPress:
user_button_press(report.xbutton.window);
break;
}
}
void user_button_press(Window w)
{
int i;
for(i=0;i<nuserbut;i++)
{
if(w==userbut[i].w)
{
run_the_commands(userbut[i].com);
}
}
}
void draw_all_user_buttons()
{
int i=0;
for(i=0;i<nuserbut;i++){
user_button_draw(userbut[i].w);
}
}
void user_button_draw(Window w)
{
int i;
for(i=0;i<nuserbut;i++){
if(w==userbut[i].w)
{
XDrawString(display,w,small_gc,5,CURY_OFFs,
userbut[i].bname,strlen(userbut[i].bname));
}
}
}
void user_button_cross(Window w,int b)
{
int i;
for(i=0;i<nuserbut;i++)
if(w==userbut[i].w){
XSetWindowBorderWidth(display,w,b);
return;
}
}
int get_button_info(char *s,char *bname,char *sc)
{
int i=0,j=0,f=0,n=strlen(s);
char c;
if(n==0)return(-1);
bname[0]=0;
sc[0]=0;
while(1){
if(i==n)break;
c=s[i];
if(c==':'){
f=1;
bname[j]=0;
j=0;
i++;
}
else {
if(f==0){
bname[j]=c;
j++;
}
else {
sc[j]=c;
j++;
}
i++;
}
}
sc[j]=0;
return(1);
}
int find_kbs(char *sc)
{
int i=0;
while(1){
if(strcmp(sc,kbs[i].seq)==0)
return kbs[i].com;
i++;
if(kbs[i].com==0)return (-1);
}
}
void add_user_button(char *s)
{
char bname[10],sc[10];
int z;
if(nuserbut>=USERBUTMAX)return;
if(strlen(s)==0)return;
get_button_info(s,bname,sc);
if(strlen(bname)==0||strlen(sc)==0)return;
z=find_kbs(sc);
if(z==-1){
plintf("%s - not implemented\n",sc);
return;
}
/*Don't add buttons with same functionality twice*/
int i;
for (i=0;i<nuserbut;i++)
{
if (userbut[i].com == z)
{
/* plintf("But=%s:%s already implemented as button '%s'\n",bname,sc,userbut[i].bname); */
return;
}
}
userbut[nuserbut].com=z;
strcpy(userbut[nuserbut].bname,bname);
plintf(" added button(%d) -- %s %d\n",
nuserbut,userbut[nuserbut].bname,userbut[nuserbut].com);
nuserbut++;
}
void create_user_buttons(int x0,int y0, Window base)
{
int i;
int x=x0;
int l;
if(nuserbut==0)return;
for(i=0;i<nuserbut;i++){
l=DCURXs*(strlen(userbut[i].bname)+2);
userbut[i].w=make_fancy_window(base,x,y0,l,DCURYs,
1,ColorMap(20),ColorMap(USERBUTCOLOR));
x=x+l+DCURXs;
}
draw_all_user_buttons();
}
|