| 1 |
#define PERL_NO_GET_CONTEXT |
| 2 |
#include <EXTERN.h> |
| 3 |
#include <perl.h> |
| 4 |
#include <XSUB.h> |
| 5 |
#include "tkGlue.def" |
| 6 |
|
| 7 |
#include "pTk/tkPort.h" |
| 8 |
#include "pTk/tkInt.h" |
| 9 |
#include "tkGlue.h" |
| 10 |
#include "tkGlue.m" |
| 11 |
#include "pTk/tkVMacro.h" |
| 12 |
|
| 13 |
DECLARE_VTABLES; |
| 14 |
|
| 15 |
/* A few sample routines to get at Xlib via perl |
| 16 |
Will eventaually be extended to the point where |
| 17 |
simple pTk widgets can be *implemented* in perl |
| 18 |
|
| 19 |
Main stumbling block is a clean way of filling in |
| 20 |
a GC. |
| 21 |
|
| 22 |
The XDraw*() functions may be a bit messy, but |
| 23 |
should be okay via CODE: bodies and variable number |
| 24 |
of args and/or passing in array refs |
| 25 |
*/ |
| 26 |
|
| 27 |
/* Now we have some sneakyness for Benefit of Win32. |
| 28 |
* As we have tkVMacro.h above any function which exists |
| 29 |
* should be #define'd so we can test for existance. |
| 30 |
*/ |
| 31 |
|
| 32 |
#ifndef XLoadFont |
| 33 |
#define XLoadFont(dpy,name) None |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef XDrawString |
| 37 |
#define XDrawString(dpy,win,gc,x,y,string,len) |
| 38 |
#endif |
| 39 |
|
| 40 |
static IV |
| 41 |
SvGCIVOBJ(pTHX_ char *class,SV *sv) |
| 42 |
{ |
| 43 |
if (sv_isa(sv, class)) |
| 44 |
return SvIV((SV*)SvRV(sv)); |
| 45 |
else |
| 46 |
croak("Not of type %s",class); |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
#define SvGCint(x) SvIV(x) |
| 51 |
#define SvGCBool(x) SvIV(x) |
| 52 |
#define SvGCunsigned_long(x) SvIV(x) |
| 53 |
#define SvGCPixmap(x) (Pixmap) SvGCIVOBJ(aTHX_ "Pixmap",x) |
| 54 |
#define SvGCFont(x) (Font) SvGCIVOBJ(aTHX_ "Font",x) |
| 55 |
|
| 56 |
#define GCField(name,bit,field,func) \ |
| 57 |
if (!strcmp(key,name)) { \ |
| 58 |
values->field = func(value); \ |
| 59 |
valuemask |= bit; \ |
| 60 |
} else |
| 61 |
|
| 62 |
unsigned long |
| 63 |
GCSetValue(pTHX_ unsigned long valuemask, |
| 64 |
XGCValues *values,char *key,SV *value) |
| 65 |
{ |
| 66 |
#include "GC.def" |
| 67 |
croak("Setting GC %s not implemented",key); |
| 68 |
return valuemask; |
| 69 |
} |
| 70 |
|
| 71 |
static void |
| 72 |
tmpLine(tkwin,x1,y1,x2,y2,flags) |
| 73 |
Tk_Window tkwin; |
| 74 |
int x1,y1,x2,y2; |
| 75 |
int flags; |
| 76 |
{ |
| 77 |
GC gc = None; |
| 78 |
XGCValues values; |
| 79 |
Window root = Tk_WindowId(tkwin); |
| 80 |
unsigned long valuemask = GCForeground | GCBackground |
| 81 |
| GCSubwindowMode | GCFunction |
| 82 |
#if 0 |
| 83 |
| GCLineStyle |
| 84 |
#endif |
| 85 |
; |
| 86 |
values.line_style = LineDoubleDash; |
| 87 |
|
| 88 |
if (flags & 4) |
| 89 |
{ |
| 90 |
Window child; |
| 91 |
root = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin)); |
| 92 |
XTranslateCoordinates(Tk_Display(tkwin),Tk_WindowId(tkwin),root, |
| 93 |
x1, y1, &x1, &y1, &child); |
| 94 |
XTranslateCoordinates(Tk_Display(tkwin),Tk_WindowId(tkwin),root, |
| 95 |
x2, y2, &x2, &y2, &child); |
| 96 |
values.subwindow_mode = IncludeInferiors; |
| 97 |
} |
| 98 |
else |
| 99 |
{ |
| 100 |
values.subwindow_mode = ClipByChildren; |
| 101 |
} |
| 102 |
|
| 103 |
if (flags & 2) |
| 104 |
{ |
| 105 |
values.background = 0x0a; |
| 106 |
values.foreground = 0x05; |
| 107 |
values.function = GXxor; |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
values.function = GXcopy; |
| 112 |
if (flags & 1) |
| 113 |
{ |
| 114 |
values.foreground = BlackPixelOfScreen(Tk_Screen(tkwin)); |
| 115 |
values.background = WhitePixelOfScreen(Tk_Screen(tkwin)); |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
values.background = BlackPixelOfScreen(Tk_Screen(tkwin)); |
| 120 |
values.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); |
| 121 |
} |
| 122 |
} |
| 123 |
gc = Tk_GetGC(tkwin, valuemask, &values); |
| 124 |
if (gc != None) |
| 125 |
{ |
| 126 |
XDrawLine(Tk_Display(tkwin), root, gc, x1, y1, x2, y2); |
| 127 |
Tk_FreeGC(Tk_Display(tkwin),gc); |
| 128 |
} |
| 129 |
else |
| 130 |
croak("Cannot get graphic context"); |
| 131 |
} |
| 132 |
|
| 133 |
#if defined(WIN32) || defined(__WIN32__) || defined(__PM__) |
| 134 |
/* wrap the naive macro versions of these ... */ |
| 135 |
static int |
| 136 |
pTk_XSync(Display *dpy, int flush) |
| 137 |
{ |
| 138 |
XSync(dpy,flush); |
| 139 |
return 0; |
| 140 |
} |
| 141 |
|
| 142 |
static int |
| 143 |
pTk_XFlush(Display *dpy) |
| 144 |
{ |
| 145 |
XFlush(dpy); |
| 146 |
return 0; |
| 147 |
} |
| 148 |
#else |
| 149 |
#define pTk_XSync XSync |
| 150 |
#define pTk_XFlush XFlush |
| 151 |
#endif /* WIN32 or friends */ |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
MODULE = Tk::Xlib PACKAGE = Tk::Widget |
| 156 |
|
| 157 |
void |
| 158 |
tmpLine(win,x1,y1,x2,y2,onroot = 0) |
| 159 |
Tk_Window win |
| 160 |
int x1 |
| 161 |
int y1 |
| 162 |
int x2 |
| 163 |
int y2 |
| 164 |
int onroot |
| 165 |
|
| 166 |
|
| 167 |
MODULE = Tk::Xlib PACKAGE = ScreenPtr |
| 168 |
|
| 169 |
PROTOTYPES: DISABLE |
| 170 |
|
| 171 |
int |
| 172 |
WidthOfScreen(s) |
| 173 |
Screen * s |
| 174 |
|
| 175 |
int |
| 176 |
WidthMMOfScreen(s) |
| 177 |
Screen * s |
| 178 |
|
| 179 |
int |
| 180 |
HeightOfScreen(s) |
| 181 |
Screen * s |
| 182 |
|
| 183 |
int |
| 184 |
HeightMMOfScreen(s) |
| 185 |
Screen * s |
| 186 |
|
| 187 |
GC |
| 188 |
DefaultGCOfScreen(s) |
| 189 |
Screen * s |
| 190 |
|
| 191 |
unsigned long |
| 192 |
BlackPixelOfScreen(s) |
| 193 |
Screen * s |
| 194 |
|
| 195 |
unsigned long |
| 196 |
WhitePixelOfScreen(s) |
| 197 |
Screen * s |
| 198 |
|
| 199 |
MODULE = Tk::Xlib PACKAGE = DisplayPtr PREFIX = pTk_ |
| 200 |
|
| 201 |
int |
| 202 |
pTk_XSync(dpy,discard = False) |
| 203 |
Display * dpy |
| 204 |
int discard |
| 205 |
|
| 206 |
int |
| 207 |
pTk_XFlush(dpy) |
| 208 |
Display * dpy |
| 209 |
|
| 210 |
int |
| 211 |
ConnectionNumber(dpy) |
| 212 |
Display * dpy |
| 213 |
|
| 214 |
Font |
| 215 |
XLoadFont(dpy,name) |
| 216 |
Display * dpy |
| 217 |
char * name |
| 218 |
|
| 219 |
void |
| 220 |
XListFonts(dpy,pattern,max) |
| 221 |
Display * dpy |
| 222 |
char * pattern |
| 223 |
int max |
| 224 |
PPCODE: |
| 225 |
{ |
| 226 |
int count = 0; |
| 227 |
#if !defined(__WIN32__) && !defined(__PM__) |
| 228 |
char **list = XListFonts(dpy, pattern, max, &count); |
| 229 |
int i; |
| 230 |
EXTEND(sp, count); |
| 231 |
for (i=0; i < count; i++) |
| 232 |
{ |
| 233 |
PUSHs(sv_2mortal(newSVpv(list[i],0))); |
| 234 |
} |
| 235 |
XFreeFontNames(list); |
| 236 |
#endif |
| 237 |
XSRETURN(count); |
| 238 |
} |
| 239 |
|
| 240 |
void |
| 241 |
XDrawLine(dpy,win,gc,x1,y1,x2,y2) |
| 242 |
Display * dpy |
| 243 |
Window win |
| 244 |
GC gc |
| 245 |
int x1 |
| 246 |
int y1 |
| 247 |
int x2 |
| 248 |
int y2 |
| 249 |
|
| 250 |
void |
| 251 |
XDrawRectangle(dpy,win,gc,x,y,width,height) |
| 252 |
Display * dpy |
| 253 |
Window win |
| 254 |
GC gc |
| 255 |
int x |
| 256 |
int y |
| 257 |
int width |
| 258 |
int height |
| 259 |
|
| 260 |
void |
| 261 |
XDrawString(dpy,win,gc,x,y,string) |
| 262 |
Display * dpy |
| 263 |
Window win |
| 264 |
GC gc |
| 265 |
int x |
| 266 |
int y |
| 267 |
SV * string |
| 268 |
CODE: |
| 269 |
{ |
| 270 |
if (SvOK(string)) |
| 271 |
{STRLEN len; |
| 272 |
char *s = SvPV(string,len); |
| 273 |
if (s && len) |
| 274 |
{ |
| 275 |
XDrawString(dpy,win,gc,x,y,s,len); |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
Window |
| 281 |
RootWindow(dpy,scr = DefaultScreen(dpy)) |
| 282 |
Display * dpy |
| 283 |
int scr |
| 284 |
|
| 285 |
char * |
| 286 |
DisplayString(dpy) |
| 287 |
Display * dpy |
| 288 |
|
| 289 |
int |
| 290 |
DefaultScreen(dpy) |
| 291 |
Display * dpy |
| 292 |
|
| 293 |
Screen * |
| 294 |
ScreenOfDisplay(dpy,scr = DefaultScreen(dpy)) |
| 295 |
Display * dpy |
| 296 |
int scr |
| 297 |
|
| 298 |
GC |
| 299 |
DefaultGC(dpy,scr) |
| 300 |
Display * dpy |
| 301 |
int scr |
| 302 |
|
| 303 |
void |
| 304 |
XQueryTree(dpy,w,root = NULL,parent = NULL) |
| 305 |
Display * dpy |
| 306 |
Window w |
| 307 |
SV * root |
| 308 |
SV * parent |
| 309 |
PPCODE: |
| 310 |
{Window *children = NULL; |
| 311 |
unsigned int count = 0; |
| 312 |
Window pw = None; |
| 313 |
Window rw = None; |
| 314 |
if (XQueryTree(dpy, w, &rw, &pw, &children, &count)) |
| 315 |
{ |
| 316 |
unsigned int i; |
| 317 |
for (i=0; i < count; i++) |
| 318 |
{ |
| 319 |
SV *sv = sv_newmortal(); |
| 320 |
sv_setref_iv(sv, "Window", (IV) (children[i])); |
| 321 |
XPUSHs(sv); |
| 322 |
} |
| 323 |
XFree((char *) children); |
| 324 |
} |
| 325 |
else |
| 326 |
{ |
| 327 |
count = 0; |
| 328 |
XSRETURN(0); |
| 329 |
} |
| 330 |
if (parent) |
| 331 |
{ |
| 332 |
if (pw == None) |
| 333 |
sv_setsv(parent,&PL_sv_undef); |
| 334 |
else |
| 335 |
sv_setref_iv(parent, "Window", (IV) (pw)); |
| 336 |
} |
| 337 |
if (root) |
| 338 |
{ |
| 339 |
if (rw == None) |
| 340 |
sv_setsv(root,&PL_sv_undef); |
| 341 |
else |
| 342 |
sv_setref_iv(root, "Window", (IV) (rw)); |
| 343 |
} |
| 344 |
XSRETURN(count); |
| 345 |
} |
| 346 |
|
| 347 |
MODULE = Tk::Xlib PACKAGE = GC PREFIX = XSet |
| 348 |
|
| 349 |
static GC |
| 350 |
GC::new(dpy,win,...) |
| 351 |
Display * dpy |
| 352 |
Window win |
| 353 |
CODE: |
| 354 |
{unsigned long valuemask = 0; |
| 355 |
XGCValues values; |
| 356 |
STRLEN na; |
| 357 |
int i; |
| 358 |
for (i=3; i < items; i += 2) |
| 359 |
{char *key = SvPV(ST(i),na); |
| 360 |
if (i+1 < items) |
| 361 |
valuemask = GCSetValue(aTHX_ valuemask,&values,key,ST(i+1)); |
| 362 |
else |
| 363 |
croak("No value for %s",key); |
| 364 |
} |
| 365 |
RETVAL = XCreateGC(dpy,win,valuemask,&values); |
| 366 |
} |
| 367 |
OUTPUT: |
| 368 |
RETVAL |
| 369 |
|
| 370 |
void |
| 371 |
XSetForeground(dpy,gc,val) |
| 372 |
Display * dpy |
| 373 |
GC gc |
| 374 |
unsigned long val |
| 375 |
|
| 376 |
BOOT: |
| 377 |
{ |
| 378 |
IMPORT_VTABLES; |
| 379 |
} |
| 380 |
|