ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.24 by root, Wed Jan 4 21:37:55 2006 UTC vs.
Revision 1.41 by root, Sun Jan 8 03:07:05 2006 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtperl.xs 2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28 28
29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef>
31#include <cstdarg> 32#include <cstdarg>
32 33
33#include "rxvt.h" 34#include "rxvt.h"
34#include "iom.h" 35#include "iom.h"
35#include "rxvtutil.h" 36#include "rxvtutil.h"
36#include "rxvtperl.h" 37#include "rxvtperl.h"
37 38
38#include "perlxsi.c" 39#include "perlxsi.c"
39 40
41#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
42# define GRAB_CURSOR THIS->leftptr_cursor
43#else
44# define GRAB_CURSOR None
45#endif
46
40#undef LINENO 47#undef LINENO
41#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42#undef ROW 49#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
44 51
51 char *str = SvPVutf8 (sv, len); 58 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 59 return rxvt_utf8towcs (str, len);
53} 60}
54 61
55static SV * 62static SV *
63wcs2sv (wchar_t *wstr, int len = -1)
64{
65 char *str = rxvt_wcstoutf8 (wstr, len);
66
67 SV *sv = newSVpv (str, 0);
68 SvUTF8_on (sv);
69 free (str);
70
71 return sv;
72}
73
74static SV *
56new_ref (HV *hv, const char *klass) 75new_ref (HV *hv, const char *klass)
57{ 76{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 77 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 78}
60 79
89 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 108 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
90 109
91 return (long)mg->mg_ptr; 110 return (long)mg->mg_ptr;
92} 111}
93 112
94#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 113#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
95#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 114#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96 115
97///////////////////////////////////////////////////////////////////////////// 116/////////////////////////////////////////////////////////////////////////////
98 117
99struct perl_watcher 118struct perl_watcher
278void 297void
279overlay::show () 298overlay::show ()
280{ 299{
281 char key[33]; sprintf (key, "%32lx", (long)this); 300 char key[33]; sprintf (key, "%32lx", (long)this);
282 301
283 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); 302 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
284 hv_store (hv, key, 32, newSViv ((long)this), 0); 303 hv_store (hv, key, 32, newSViv ((long)this), 0);
285} 304}
286 305
287void 306void
288overlay::hide () 307overlay::hide ()
289{ 308{
290 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); 309 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
291 310
292 if (ovs) 311 if (ovs)
293 { 312 {
294 char key[33]; sprintf (key, "%32lx", (long)this); 313 char key[33]; sprintf (key, "%32lx", (long)this);
295 314
403 if (!perl) 422 if (!perl)
404 return false; 423 return false;
405 424
406 if (htype == HOOK_INIT) // first hook ever called 425 if (htype == HOOK_INIT) // first hook ever called
407 { 426 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 427 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
409 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 428 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
410 } 429 }
411 else if (!term->self) 430 else if (!term->perl.self)
412 return false; // perl not initialized for this instance 431 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY) 432 else if (htype == HOOK_DESTROY)
414 { 433 {
415 // handled later 434 // handled later
416 } 435 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 436 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
418 { 437 {
419 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 438 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
420 439
421 if (HvKEYS (hv)) 440 if (HvKEYS (hv))
422 { 441 {
423 hv_iterinit (hv); 442 hv_iterinit (hv);
424 443
453 472
454 case DT_LONG: 473 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 474 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break; 475 break;
457 476
458 case DT_STRING: 477 case DT_STR:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 478 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
479 break;
480
481 case DT_STR_LEN:
482 {
483 char *str = va_arg (ap, char *);
484 int len = va_arg (ap, int);
485
486 XPUSHs (sv_2mortal (newSVpvn (str, len)));
487 }
488 break;
489
490 case DT_WCS_LEN:
491 {
492 wchar_t *wstr = va_arg (ap, wchar_t *);
493 int wlen = va_arg (ap, int);
494
495 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
496 }
497 break;
498
499 case DT_XEVENT:
500 {
501 XEvent *xe = va_arg (ap, XEvent *);
502 HV *hv = newHV ();
503
504# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
505# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
506# undef set
507
508 setiv (type, xe->type);
509 setiv (send_event, xe->xany.send_event);
510 setiv (serial, xe->xany.serial);
511
512 switch (xe->type)
513 {
514 case KeyPress:
515 case KeyRelease:
516 case ButtonPress:
517 case ButtonRelease:
518 case MotionNotify:
519 setiv (time, xe->xmotion.time);
520 setiv (x, xe->xmotion.x);
521 setiv (y, xe->xmotion.y);
522 setiv (row, xe->xmotion.y / term->fheight);
523 setiv (col, xe->xmotion.x / term->fwidth);
524 setiv (x_root, xe->xmotion.x_root);
525 setiv (y_root, xe->xmotion.y_root);
526 setiv (state, xe->xmotion.state);
527 break;
528 }
529
530 switch (xe->type)
531 {
532 case KeyPress:
533 case KeyRelease:
534 setiv (keycode, xe->xkey.keycode);
535 break;
536
537 case ButtonPress:
538 case ButtonRelease:
539 setiv (button, xe->xbutton.button);
540 break;
541
542 case MotionNotify:
543 setiv (is_hint, xe->xmotion.is_hint);
544 break;
545 }
546
547 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
548 }
460 break; 549 break;
461 550
462 case DT_END: 551 case DT_END:
463 { 552 {
464 va_end (ap); 553 va_end (ap);
480 if (SvTRUE (ERRSV)) 569 if (SvTRUE (ERRSV))
481 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 570 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
482 571
483 if (htype == HOOK_DESTROY) 572 if (htype == HOOK_DESTROY)
484 { 573 {
485 clearSVptr ((SV *)term->self); 574 clearSVptr ((SV *)term->perl.self);
486 SvREFCNT_dec ((SV *)term->self); 575 SvREFCNT_dec ((SV *)term->perl.self);
487 } 576 }
488 577
489 return count; 578 return count;
490 } 579 }
491 580
501 590
502PROTOTYPES: ENABLE 591PROTOTYPES: ENABLE
503 592
504BOOT: 593BOOT:
505{ 594{
506# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 595 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
596
507 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 597 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
508# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 598# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
509# include "hookinc.h" 599# include "hookinc.h"
510# undef def 600# undef def
511 601
602 HV *option = get_hv ("urxvt::OPTION", 1);
603# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
604# define nodef(name)
605# include "optinc.h"
606# undef nodef
607# undef def
608
609 HV *stash = gv_stashpv ("urxvt", 1);
610# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
512 export_const (DEFAULT_RSTYLE); 611 export_const_iv (DEFAULT_RSTYLE);
513 export_const (OVERLAY_RSTYLE); 612 export_const_iv (OVERLAY_RSTYLE);
514 export_const (RS_Bold); 613 export_const_iv (RS_Bold);
515 export_const (RS_Italic); 614 export_const_iv (RS_Italic);
516 export_const (RS_Blink); 615 export_const_iv (RS_Blink);
517 export_const (RS_RVid); 616 export_const_iv (RS_RVid);
518 export_const (RS_Uline); 617 export_const_iv (RS_Uline);
519 618
520 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 619 export_const_iv (CurrentTime);
620 export_const_iv (ShiftMask);
621 export_const_iv (LockMask);
622 export_const_iv (ControlMask);
623 export_const_iv (Mod1Mask);
624 export_const_iv (Mod2Mask);
625 export_const_iv (Mod3Mask);
626 export_const_iv (Mod4Mask);
627 export_const_iv (Mod5Mask);
628 export_const_iv (Button1Mask);
629 export_const_iv (Button2Mask);
630 export_const_iv (Button3Mask);
631 export_const_iv (Button4Mask);
632 export_const_iv (Button5Mask);
633 export_const_iv (AnyModifier);
521} 634}
635
636SV *
637new (...)
638 CODE:
639{
640 stringvec *argv = new stringvec;
641 bool success;
642
643 for (int i = 0; i < items ;i++)
644 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
645
646 rxvt_term *term = new rxvt_term;
647
648 term->argv = argv;
649
650 try
651 {
652 if (!term->init (argv->size (), argv->begin ()))
653 term = 0;
654 }
655 catch (const class rxvt_failure_exception &e)
656 {
657 term->destroy ();
658 croak ("exception caught while initializing new terminal instance");
659 }
660
661 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
662}
663 OUTPUT:
664 RETVAL
522 665
523void 666void
524set_should_invoke (int htype, int value) 667set_should_invoke (int htype, int value)
525 CODE: 668 CODE:
526 rxvt_perl.should_invoke [htype] = value; 669 rxvt_perl.should_invoke [htype] = value;
589} 732}
590 OUTPUT: 733 OUTPUT:
591 RETVAL 734 RETVAL
592 735
593MODULE = urxvt PACKAGE = urxvt::term 736MODULE = urxvt PACKAGE = urxvt::term
737
738void
739rxvt_term::destroy ()
740
741void
742rxvt_term::grab_button (int button, U32 modifiers)
743 CODE:
744 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
745 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
746 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
747
748bool
749rxvt_term::grab (U32 eventtime, int sync = 0)
750 CODE:
751{
752 int mode = sync ? GrabModeSync : GrabModeAsync;
753
754 THIS->perl.grabtime = 0;
755
756 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
757 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
758 mode, mode, None, GRAB_CURSOR, eventtime))
759 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
760 THIS->perl.grabtime = eventtime;
761 else
762 XUngrabPointer (THIS->display->display, eventtime);
763
764 RETVAL = !!THIS->perl.grabtime;
765}
766 OUTPUT:
767 RETVAL
768
769void
770rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
771 CODE:
772 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
773
774void
775rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
776 CODE:
777 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
778
779void
780rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
781 CODE:
782 XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
783 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
784
785void
786rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
787 CODE:
788 THIS->perl.grabtime = 0;
789 XUngrabKeyboard (THIS->display->display, eventtime);
790 XUngrabPointer (THIS->display->display, eventtime);
594 791
595int 792int
596rxvt_term::strwidth (SV *str) 793rxvt_term::strwidth (SV *str)
597 CODE: 794 CODE:
598{ 795{
634 831
635 rxvt_push_locale (THIS->locale); 832 rxvt_push_locale (THIS->locale);
636 wchar_t *wstr = rxvt_mbstowcs (data, len); 833 wchar_t *wstr = rxvt_mbstowcs (data, len);
637 rxvt_pop_locale (); 834 rxvt_pop_locale ();
638 835
639 char *str = rxvt_wcstoutf8 (wstr); 836 RETVAL = wcs2sv (wstr);
640 free (wstr); 837 free (wstr);
641
642 RETVAL = newSVpv (str, 0);
643 SvUTF8_on (RETVAL);
644 free (str);
645} 838}
646 OUTPUT: 839 OUTPUT:
647 RETVAL 840 RETVAL
648 841
649# very portable, especially on objects as opposed to pods 842#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
650#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
651 843
652#define TERM_OFFSET_width TERM_OFFSET(width) 844#define TERM_OFFSET_width TERM_OFFSET(width)
653#define TERM_OFFSET_height TERM_OFFSET(height) 845#define TERM_OFFSET_height TERM_OFFSET(height)
654#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 846#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
655#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 847#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
680 CODE: 872 CODE:
681 RETVAL = *(int *)((char *)THIS + ix); 873 RETVAL = *(int *)((char *)THIS + ix);
682 OUTPUT: 874 OUTPUT:
683 RETVAL 875 RETVAL
684 876
877unsigned int
878rxvt_term::ModLevel3Mask ()
879 ALIAS:
880 ModLevel3Mask = 0
881 ModMetaMask = 1
882 ModNumLockMask = 2
883 CODE:
884 switch (ix)
885 {
886 case 0: RETVAL = THIS->ModLevel3Mask; break;
887 case 1: RETVAL = THIS->ModMetaMask; break;
888 case 2: RETVAL = THIS->ModNumLockMask; break;
889 }
890 OUTPUT:
891 RETVAL
892
685U32 893U32
894rxvt_term::parent ()
895 CODE:
896 RETVAL = (U32)THIS->parent [0];
897 OUTPUT:
898 RETVAL
899
900U32
901rxvt_term::vt ()
902 CODE:
903 RETVAL = (U32)THIS->vt;
904 OUTPUT:
905 RETVAL
906
907U32
686rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) 908rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
687 CODE: 909 CODE:
688{ 910{
689 RETVAL = THIS->screen.s_rstyle; 911 RETVAL = THIS->rstyle;
690 THIS->screen.s_rstyle = new_rstyle; 912 THIS->rstyle = new_rstyle;
691} 913}
692 OUTPUT: 914 OUTPUT:
693 RETVAL 915 RETVAL
694 916
695int 917int
711rxvt_term::want_refresh () 933rxvt_term::want_refresh ()
712 CODE: 934 CODE:
713 THIS->want_refresh = 1; 935 THIS->want_refresh = 1;
714 936
715void 937void
716rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 938rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
717 PPCODE: 939 PPCODE:
718{ 940{
719 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 941 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
720 XSRETURN_EMPTY; 942 XSRETURN_EMPTY;
721 943
723 945
724 if (GIMME_V != G_VOID) 946 if (GIMME_V != G_VOID)
725 { 947 {
726 wchar_t *wstr = new wchar_t [THIS->ncol]; 948 wchar_t *wstr = new wchar_t [THIS->ncol];
727 949
728 for (int col = 0; col <THIS->ncol; col++) 950 for (int col = 0; col < THIS->ncol; col++)
729 wstr [col] = l.t [col]; 951 wstr [col] = l.t [col];
730 952
731 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol);
732 free (wstr);
733
734 SV *sv = newSVpv (str, 0);
735 SvUTF8_on (sv);
736 XPUSHs (sv_2mortal (sv)); 953 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
737 free (str); 954
955 delete [] wstr;
738 } 956 }
739 957
740 if (new_text) 958 if (new_text)
741 { 959 {
742 wchar_t *wstr = sv2wcs (new_text); 960 wchar_t *wstr = sv2wcs (new_text);
743 961
744 int len = wcslen (wstr); 962 int len = min (wcslen (wstr) - start_ofs, max_len);
745 963
746 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 964 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
747 { 965 {
748 free (wstr); 966 free (wstr);
749 croak ("new_text extends beyond horizontal margins"); 967 croak ("new_text extends beyond horizontal margins");
750 } 968 }
751 969
752 for (int col = start_col; col < start_col + len; col++) 970 for (int col = start_col; col < start_col + len; col++)
753 { 971 {
754 l.t [col] = wstr [col - start_col]; 972 l.t [col] = wstr [start_ofs + col - start_col];
755 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 973 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
756 } 974 }
757 975
758 free (wstr); 976 free (wstr);
759 } 977 }
760} 978}
761 979
762void 980void
763rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 981rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
764 PPCODE: 982 PPCODE:
765{ 983{
766 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 984 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
767 XSRETURN_EMPTY; 985 XSRETURN_EMPTY;
768 986
783 { 1001 {
784 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1002 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
785 croak ("new_rend must be arrayref"); 1003 croak ("new_rend must be arrayref");
786 1004
787 AV *av = (AV *)SvRV (new_rend); 1005 AV *av = (AV *)SvRV (new_rend);
788 int len = av_len (av) + 1; 1006 int len = min (av_len (av) + 1 - start_ofs, max_len);
789 1007
790 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1008 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
791 croak ("new_rend array extends beyond horizontal margins"); 1009 croak ("new_rend array extends beyond horizontal margins");
792 1010
793 for (int col = start_col; col < start_col + len; col++) 1011 for (int col = start_col; col < start_col + len; col++)
794 { 1012 {
795 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1013 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
796 1014
797 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1015 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
798 } 1016 }
799 } 1017 }
800} 1018}
801 1019
802int 1020int
803rxvt_term::ROW_l (int row_number, int new_length = -2) 1021rxvt_term::ROW_l (int row_number, int new_length = -1)
804 CODE: 1022 CODE:
805{ 1023{
806 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1024 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
807 XSRETURN_EMPTY; 1025 XSRETURN_EMPTY;
808 1026
809 line_t &l = ROW(row_number); 1027 line_t &l = ROW(row_number);
810 RETVAL = l.l < 0 ? THIS->ncol : l.l; 1028 RETVAL = l.l;
811 1029
812 if (new_length >= -1) 1030 if (new_length >= 0)
813 l.l = new_length; 1031 l.l = new_length;
814} 1032}
815 OUTPUT: 1033 OUTPUT:
816 RETVAL 1034 RETVAL
817 1035
818bool 1036bool
819rxvt_term::ROW_is_longer (int row_number) 1037rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
820 CODE: 1038 CODE:
821{ 1039{
822 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1040 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
823 XSRETURN_EMPTY; 1041 XSRETURN_EMPTY;
824 1042
825 line_t &l = ROW(row_number); 1043 line_t &l = ROW(row_number);
826 RETVAL = l.l < 0; 1044 RETVAL = l.is_longer ();
1045
1046 if (new_is_longer >= 0)
1047 l.is_longer (new_is_longer);
827} 1048}
828 OUTPUT: 1049 OUTPUT:
829 RETVAL 1050 RETVAL
830 1051
831SV * 1052SV *
832rxvt_term::special_encode (SV *str) 1053rxvt_term::special_encode (SV *string)
833 CODE: 1054 CODE:
834 abort ();//TODO 1055{
1056 wchar_t *wstr = sv2wcs (string);
1057 int wlen = wcslen (wstr);
1058 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1059
1060 rxvt_push_locale (THIS->locale);
1061
1062 wchar_t *r = rstr;
1063 for (wchar_t *s = wstr; *s; s++)
1064 if (wcwidth (*s) == 0)
1065 {
1066 if (r == rstr)
1067 croak ("leading combining character unencodable");
1068
1069 unicode_t n = rxvt_compose (r[-1], *s);
1070 if (n == NOCHAR)
1071 n = rxvt_composite.compose (r[-1], *s);
1072
1073 r[-1] = n;
1074 }
1075#if !UNICODE_3
1076 else if (*s >= 0x10000)
1077 *r++ = rxvt_composite.compose (*s);
1078#endif
1079 else
1080 *r++ = *s;
1081
1082 rxvt_pop_locale ();
1083
1084 RETVAL = wcs2sv (rstr, r - rstr);
1085
1086 delete [] rstr;
1087}
1088 OUTPUT:
1089 RETVAL
835 1090
836SV * 1091SV *
837rxvt_term::special_decode (SV *str) 1092rxvt_term::special_decode (SV *text)
838 CODE: 1093 CODE:
839 abort ();//TODO 1094{
1095 wchar_t *wstr = sv2wcs (text);
1096 int wlen = wcslen (wstr);
1097 int dlen = 0;
1098
1099 // find length
1100 for (wchar_t *s = wstr; *s; s++)
1101 if (*s == NOCHAR)
1102 ;
1103 else if (IS_COMPOSE (*s))
1104 dlen += rxvt_composite.expand (*s, 0);
1105 else
1106 dlen++;
1107
1108 wchar_t *rstr = new wchar_t [dlen];
1109
1110 // decode
1111 wchar_t *r = rstr;
1112 for (wchar_t *s = wstr; *s; s++)
1113 if (*s == NOCHAR)
1114 ;
1115 else if (IS_COMPOSE (*s))
1116 r += rxvt_composite.expand (*s, r);
1117 else
1118 *r++ = *s;
1119
1120 RETVAL = wcs2sv (rstr, r - rstr);
1121
1122 delete [] rstr;
1123}
1124 OUTPUT:
1125 RETVAL
840 1126
841void 1127void
842rxvt_term::_resource (char *name, int index, SV *newval = 0) 1128rxvt_term::_resource (char *name, int index, SV *newval = 0)
843 PPCODE: 1129 PPCODE:
844{ 1130{
876 else 1162 else
877 THIS->rs [index] = 0; 1163 THIS->rs [index] = 0;
878 } 1164 }
879} 1165}
880 1166
1167bool
1168rxvt_term::option (U32 optval, int set = -1)
1169 CODE:
1170{
1171 RETVAL = THIS->options & optval;
1172
1173 if (set >= 0)
1174 {
1175 if (set)
1176 THIS->options |= optval;
1177 else
1178 THIS->options &= ~optval;
1179
1180 switch (optval)
1181 {
1182 case Opt_skipBuiltinGlyphs:
1183 THIS->set_fonts ();
1184 THIS->scr_remap_chars ();
1185 THIS->scr_touch (true);
1186 THIS->want_refresh = 1;
1187 break;
1188
1189 case Opt_cursorUnderline:
1190 THIS->want_refresh = 1;
1191 break;
1192
1193# case Opt_scrollBar_floating:
1194# case Opt_scrollBar_right:
1195# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1196# break;
1197 }
1198 }
1199}
1200 OUTPUT:
1201 RETVAL
1202
881void 1203void
882rxvt_term::cur (...) 1204rxvt_term::cur (...)
883 PROTOTYPE: $;$$ 1205 PROTOTYPE: $;$$
884 ALIAS: 1206 ALIAS:
885 screen_cur = 0 1207 screen_cur = 0
909 THIS->want_refresh = 1; 1231 THIS->want_refresh = 1;
910 } 1232 }
911} 1233}
912 1234
913int 1235int
914rxvt_term::selection_grab (int eventtime = CurrentTime) 1236rxvt_term::selection_grab (U32 eventtime)
915 1237
916void 1238void
917rxvt_term::selection (SV *newtext = 0) 1239rxvt_term::selection (SV *newtext = 0)
918 PPCODE: 1240 PPCODE:
919{ 1241{
920 if (GIMME_V != G_VOID) 1242 if (GIMME_V != G_VOID)
921 { 1243 XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)));
922 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len);
923 SV *sv = newSVpv (sel, 0);
924 SvUTF8_on (sv);
925 free (sel);
926 XPUSHs (sv_2mortal (sv));
927 }
928 1244
929 if (newtext) 1245 if (newtext)
930 { 1246 {
931 free (THIS->selection.text); 1247 free (THIS->selection.text);
932 1248
933 THIS->selection.text = sv2wcs (newtext); 1249 THIS->selection.text = sv2wcs (newtext);
934 THIS->selection.len = wcslen (THIS->selection.text); 1250 THIS->selection.len = wcslen (THIS->selection.text);
935 } 1251 }
1252}
1253
1254void
1255rxvt_term::scr_add_lines (SV *string)
1256 CODE:
1257{
1258 wchar_t *wstr = sv2wcs (string);
1259 THIS->scr_add_lines (wstr, wcslen (wstr));
1260 free (wstr);
936} 1261}
937 1262
938void 1263void
939rxvt_term::tt_write (SV *octets) 1264rxvt_term::tt_write (SV *octets)
940 INIT: 1265 INIT:
941 STRLEN len; 1266 STRLEN len;
942 char *str = SvPVbyte (octets, len); 1267 char *str = SvPVbyte (octets, len);
943 C_ARGS: 1268 C_ARGS:
944 str, len 1269 str, len
945 1270
1271void
1272rxvt_term::cmd_parse (SV *octets)
1273 CODE:
1274{
1275 STRLEN len;
1276 char *str = SvPVbyte (octets, len);
1277
1278 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1279 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1280
1281 THIS->cmdbuf_ptr = str;
1282 THIS->cmdbuf_endp = str + len;
1283
1284 rxvt_push_locale (THIS->locale);
1285 THIS->cmd_parse ();
1286 rxvt_pop_locale ();
1287
1288 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1289 THIS->cmdbuf_endp = old_cmdbuf_endp;
1290}
1291
946SV * 1292SV *
947rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1293rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
948 CODE: 1294 CODE:
949{ 1295{
950 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1296 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines