… | |
… | |
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)); |
… | |
… | |
441 | if (SvTRUE (ERRSV)) |
480 | if (SvTRUE (ERRSV)) |
442 | 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)); |
443 | |
482 | |
444 | if (htype == HOOK_DESTROY) |
483 | if (htype == HOOK_DESTROY) |
445 | { |
484 | { |
446 | // TODO: clear magic |
|
|
447 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
485 | clearSVptr ((SV *)term->self); |
448 | SvREFCNT_dec ((SV *)term->self); |
486 | SvREFCNT_dec ((SV *)term->self); |
449 | } |
487 | } |
450 | |
488 | |
451 | return count; |
489 | return count; |
452 | } |
490 | } |
… | |
… | |
666 | void |
704 | void |
667 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
705 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
668 | PPCODE: |
706 | PPCODE: |
669 | { |
707 | { |
670 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
708 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
671 | croak ("row_number number of out range"); |
709 | XSRETURN_EMPTY; |
672 | |
710 | |
673 | line_t &l = ROW(row_number); |
711 | line_t &l = ROW(row_number); |
674 | |
712 | |
675 | if (GIMME_V != G_VOID) |
713 | if (GIMME_V != G_VOID) |
676 | { |
714 | { |
… | |
… | |
713 | void |
751 | void |
714 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
752 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
715 | PPCODE: |
753 | PPCODE: |
716 | { |
754 | { |
717 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
755 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
718 | croak ("row_number number of out range"); |
756 | XSRETURN_EMPTY; |
719 | |
757 | |
720 | line_t &l = ROW(row_number); |
758 | line_t &l = ROW(row_number); |
721 | |
759 | |
722 | if (GIMME_V != G_VOID) |
760 | if (GIMME_V != G_VOID) |
723 | { |
761 | { |
… | |
… | |
753 | int |
791 | int |
754 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
792 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
755 | CODE: |
793 | CODE: |
756 | { |
794 | { |
757 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
795 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
758 | croak ("row_number number of out range"); |
796 | XSRETURN_EMPTY; |
759 | |
797 | |
760 | line_t &l = ROW(row_number); |
798 | line_t &l = ROW(row_number); |
761 | RETVAL = l.l; |
799 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
762 | |
800 | |
763 | if (new_length >= -1) |
801 | if (new_length >= -1) |
764 | l.l = new_length; |
802 | l.l = new_length; |
|
|
803 | } |
|
|
804 | OUTPUT: |
|
|
805 | RETVAL |
|
|
806 | |
|
|
807 | bool |
|
|
808 | rxvt_term::ROW_is_longer (int row_number) |
|
|
809 | CODE: |
|
|
810 | { |
|
|
811 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
812 | XSRETURN_EMPTY; |
|
|
813 | |
|
|
814 | line_t &l = ROW(row_number); |
|
|
815 | RETVAL = l.l < 0; |
765 | } |
816 | } |
766 | OUTPUT: |
817 | OUTPUT: |
767 | RETVAL |
818 | RETVAL |
768 | |
819 | |
769 | SV * |
820 | SV * |
… | |
… | |
883 | CODE: |
934 | CODE: |
884 | { |
935 | { |
885 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
936 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
886 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
937 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
887 | o->self = (HV *)SvRV (RETVAL); |
938 | o->self = (HV *)SvRV (RETVAL); |
888 | |
|
|
889 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
890 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
891 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
892 | } |
939 | } |
893 | OUTPUT: |
940 | OUTPUT: |
894 | RETVAL |
941 | RETVAL |
895 | |
942 | |
896 | MODULE = urxvt PACKAGE = urxvt::overlay |
943 | MODULE = urxvt PACKAGE = urxvt::overlay |
897 | |
944 | |
898 | void |
945 | void |
899 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
946 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
900 | |
947 | |
901 | void |
948 | void |
|
|
949 | overlay::show () |
|
|
950 | |
|
|
951 | void |
|
|
952 | overlay::hide () |
|
|
953 | |
|
|
954 | void |
902 | overlay::DESTROY () |
955 | overlay::DESTROY () |
903 | CODE: |
|
|
904 | { |
|
|
905 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
906 | if (ovs) |
|
|
907 | { |
|
|
908 | HV *hv = (HV *)SvRV (*ovs); |
|
|
909 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
910 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
911 | } |
|
|
912 | |
|
|
913 | delete THIS; |
|
|
914 | } |
|
|
915 | |
956 | |
916 | MODULE = urxvt PACKAGE = urxvt::timer |
957 | MODULE = urxvt PACKAGE = urxvt::timer |
917 | |
958 | |
918 | SV * |
959 | SV * |
919 | timer::new () |
960 | timer::new () |