… | |
… | |
61 | //TODO: use magic |
61 | //TODO: use magic |
62 | static SV * |
62 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
63 | newSVptr (void *ptr, const char *klass) |
64 | { |
64 | { |
65 | HV *hv = newHV (); |
65 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
66 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
68 | } |
|
|
69 | |
|
|
70 | static void |
|
|
71 | clearSVptr (SV *sv) |
|
|
72 | { |
|
|
73 | if (SvROK (sv)) |
|
|
74 | sv = SvRV (sv); |
|
|
75 | |
|
|
76 | hv_clear ((HV *)sv); |
|
|
77 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
78 | } |
69 | |
79 | |
70 | static long |
80 | static long |
71 | SvPTR (SV *sv, const char *klass) |
81 | SvPTR (SV *sv, const char *klass) |
72 | { |
82 | { |
73 | if (!sv_derived_from (sv, klass)) |
83 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
84 | croak ("object of type %s expected", klass); |
75 | |
85 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
86 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
87 | |
78 | if (!iv) |
88 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
89 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
90 | |
81 | return (long)iv; |
91 | return (long)mg->mg_ptr; |
82 | } |
92 | } |
83 | |
93 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
94 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
95 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
96 | |
… | |
… | |
185 | text_t **text; |
195 | text_t **text; |
186 | rend_t **rend; |
196 | rend_t **rend; |
187 | |
197 | |
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
198 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 | ~overlay (); |
199 | ~overlay (); |
|
|
200 | |
|
|
201 | void show (); |
|
|
202 | void hide (); |
190 | |
203 | |
191 | void swap (); |
204 | void swap (); |
192 | |
205 | |
193 | void set (int x, int y, SV *str, SV *rend); |
206 | void set (int x, int y, SV *str, SV *rend); |
194 | }; |
207 | }; |
… | |
… | |
240 | *tp++ = 0x0020; |
253 | *tp++ = 0x0020; |
241 | *rp++ = r; |
254 | *rp++ = r; |
242 | } |
255 | } |
243 | } |
256 | } |
244 | |
257 | |
|
|
258 | show (); |
245 | THIS->want_refresh = 1; |
259 | THIS->want_refresh = 1; |
246 | } |
260 | } |
247 | |
261 | |
248 | overlay::~overlay () |
262 | overlay::~overlay () |
249 | { |
263 | { |
|
|
264 | hide (); |
|
|
265 | |
250 | for (int y = h; y--; ) |
266 | for (int y = h; y--; ) |
251 | { |
267 | { |
252 | delete [] text[y]; |
268 | delete [] text[y]; |
253 | delete [] rend[y]; |
269 | delete [] rend[y]; |
254 | } |
270 | } |
255 | |
271 | |
256 | delete [] text; |
272 | delete [] text; |
257 | delete [] rend; |
273 | delete [] rend; |
258 | |
274 | |
259 | THIS->want_refresh = 1; |
275 | THIS->want_refresh = 1; |
|
|
276 | } |
|
|
277 | |
|
|
278 | void |
|
|
279 | overlay::show () |
|
|
280 | { |
|
|
281 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
282 | |
|
|
283 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
284 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
285 | } |
|
|
286 | |
|
|
287 | void |
|
|
288 | overlay::hide () |
|
|
289 | { |
|
|
290 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
|
|
291 | |
|
|
292 | if (ovs) |
|
|
293 | { |
|
|
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
295 | |
|
|
296 | HV *hv = (HV *)SvRV (*ovs); |
|
|
297 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
298 | } |
260 | } |
299 | } |
261 | |
300 | |
262 | void overlay::swap () |
301 | void overlay::swap () |
263 | { |
302 | { |
264 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
303 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
… | |
… | |
282 | } |
321 | } |
283 | } |
322 | } |
284 | |
323 | |
285 | } |
324 | } |
286 | |
325 | |
287 | void overlay::set (int x, int y, SV *str, SV *rend) |
326 | void overlay::set (int x, int y, SV *text, SV *rend) |
288 | { |
327 | { |
289 | x += border; |
328 | x += border; |
290 | y += border; |
329 | y += border; |
291 | |
330 | |
292 | if (!IN_RANGE_EXC (y, 0, h - border)) |
331 | if (!IN_RANGE_EXC (y, 0, h - border)) |
293 | return; |
332 | return; |
294 | |
333 | |
295 | wchar_t *wstr = sv2wcs (str); |
334 | wchar_t *wtext = sv2wcs (text); |
296 | |
335 | |
297 | for (int col = min (wcslen (wstr), w - x - border); col--; ) |
336 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 | text [y][x + col] = wstr [col]; |
337 | this->text [y][x + col] = wtext [col]; |
299 | |
338 | |
300 | free (wstr); |
339 | free (wtext); |
|
|
340 | |
|
|
341 | if (rend) |
|
|
342 | { |
|
|
343 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
|
|
344 | croak ("rend must be arrayref"); |
|
|
345 | |
|
|
346 | AV *av = (AV *)SvRV (rend); |
|
|
347 | |
|
|
348 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
|
|
349 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
|
|
350 | } |
301 | |
351 | |
302 | THIS->want_refresh = 1; |
352 | THIS->want_refresh = 1; |
303 | } |
353 | } |
304 | |
354 | |
305 | |
355 | |
… | |
… | |
356 | if (htype == HOOK_INIT) // first hook ever called |
406 | if (htype == HOOK_INIT) // first hook ever called |
357 | { |
407 | { |
358 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
408 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
359 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
409 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
360 | } |
410 | } |
|
|
411 | else if (!term->self) |
|
|
412 | return false; // perl not initialized for this instance |
361 | else if (htype == HOOK_DESTROY) |
413 | else if (htype == HOOK_DESTROY) |
362 | { |
414 | { |
363 | // handled later |
415 | // handled later |
364 | } |
416 | } |
365 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
417 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
… | |
… | |
428 | if (SvTRUE (ERRSV)) |
480 | if (SvTRUE (ERRSV)) |
429 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
481 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
430 | |
482 | |
431 | if (htype == HOOK_DESTROY) |
483 | if (htype == HOOK_DESTROY) |
432 | { |
484 | { |
433 | // TODO: clear magic |
|
|
434 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
485 | clearSVptr ((SV *)term->self); |
435 | SvREFCNT_dec ((SV *)term->self); |
486 | SvREFCNT_dec ((SV *)term->self); |
436 | } |
487 | } |
437 | |
488 | |
438 | return count; |
489 | return count; |
439 | } |
490 | } |
… | |
… | |
831 | THIS->want_refresh = 1; |
882 | THIS->want_refresh = 1; |
832 | } |
883 | } |
833 | } |
884 | } |
834 | |
885 | |
835 | int |
886 | int |
836 | rxvt_term::selection_grab (int eventtime) |
887 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
837 | |
888 | |
838 | void |
889 | void |
839 | rxvt_term::selection (SV *newtext = 0) |
890 | rxvt_term::selection (SV *newtext = 0) |
840 | PPCODE: |
891 | PPCODE: |
841 | { |
892 | { |
… | |
… | |
870 | CODE: |
921 | CODE: |
871 | { |
922 | { |
872 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
923 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
873 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
924 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
874 | o->self = (HV *)SvRV (RETVAL); |
925 | o->self = (HV *)SvRV (RETVAL); |
875 | |
|
|
876 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
877 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
878 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
879 | } |
926 | } |
880 | OUTPUT: |
927 | OUTPUT: |
881 | RETVAL |
928 | RETVAL |
882 | |
929 | |
883 | MODULE = urxvt PACKAGE = urxvt::overlay |
930 | MODULE = urxvt PACKAGE = urxvt::overlay |
884 | |
931 | |
885 | void |
932 | void |
886 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
933 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
887 | |
934 | |
888 | void |
935 | void |
|
|
936 | overlay::show () |
|
|
937 | |
|
|
938 | void |
|
|
939 | overlay::hide () |
|
|
940 | |
|
|
941 | void |
889 | overlay::DESTROY () |
942 | overlay::DESTROY () |
890 | CODE: |
|
|
891 | { |
|
|
892 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
893 | if (ovs) |
|
|
894 | { |
|
|
895 | HV *hv = (HV *)SvRV (*ovs); |
|
|
896 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
897 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
898 | } |
|
|
899 | |
|
|
900 | delete THIS; |
|
|
901 | } |
|
|
902 | |
943 | |
903 | MODULE = urxvt PACKAGE = urxvt::timer |
944 | MODULE = urxvt PACKAGE = urxvt::timer |
904 | |
945 | |
905 | SV * |
946 | SV * |
906 | timer::new () |
947 | timer::new () |