home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / TextEdit.pm < prev    next >
Text File  |  1998-04-05  |  8KB  |  462 lines

  1. =head1 NAME
  2.  
  3. Mac::TextEdit - Macintosh Toolbox Interface to TextEdit
  4.  
  5. =head1 SYNOPSIS
  6.  
  7.  
  8. =head1 DESCRIPTION
  9.  
  10. Access to Inside Macintosh is essential for proper use of these functions.
  11. Explanations of terms, processes and procedures are provided there.
  12. Any attempt to use these functions without guidance can cause severe errors in 
  13. your machine, including corruption of data. B<You have been warned.>
  14.  
  15. =cut
  16.  
  17. use strict;
  18.  
  19. package Mac::TextEdit;
  20.  
  21. BEGIN {
  22.     use Exporter   ();
  23.     use DynaLoader ();
  24.     
  25.     use vars qw(@ISA @EXPORT);
  26.     
  27.     @ISA = qw(Exporter DynaLoader);
  28.     @EXPORT = qw(
  29.         TEScrapHandle
  30.         TEGetScrapLength
  31.         TENew
  32.         TEDispose
  33.         TESetText
  34.         TEGetText
  35.         TEIdle
  36.         TESetSelect
  37.         TEActivate
  38.         TEDeactivate
  39.         TEKey
  40.         TECut
  41.         TECopy
  42.         TEPaste
  43.         TEDelete
  44.         TEInsert
  45.         TESetAlignment
  46.         TEUpdate
  47.         TETextBox
  48.         TEScroll
  49.         TESelView
  50.         TEPinScroll
  51.         TEAutoView
  52.         TECalText
  53.         TEGetOffset
  54.         TEGetPoint
  55.         TEClick
  56.         TEStyleNew
  57.         TESetStyleHandle
  58.         TEGetStyleHandle
  59.         TEGetStyle
  60.         TEStylePaste
  61.         TESetStyle
  62.         TEReplaceStyle
  63.         TEGetStyleScrapHandle
  64.         TEStyleInsert
  65.         TEGetHeight
  66.         TEContinuousStyle
  67.         TEUseStyleScrap
  68.         TENumStyles
  69.         TEFeatureFlag
  70.         TESetScrapLength
  71.         TEFromScrap
  72.         TEToScrap
  73.  
  74.         teFlushDefault
  75.         teCenter
  76.         teFlushRight
  77.         teFlushLeft
  78.         doFont
  79.         doFace
  80.         doSize
  81.         doColor
  82.         doAll
  83.         addSize
  84.         doToggle
  85.         teFAutoScroll
  86.         teFTextBuffering
  87.         teFOutlineHilite
  88.         teFInlineInput
  89.         teFUseInlineInput
  90.         teFInlineInputAutoScroll
  91.         teBitClear
  92.         teBitSet
  93.         teBitTest
  94.         teWordSelect
  95.         teWordDrag
  96.         teFromFind
  97.         teFromRecal
  98.         teFind
  99.         teHighlight
  100.         teDraw
  101.         teCaret
  102.         teFUseTextServices
  103.     );
  104. }
  105.  
  106. bootstrap Mac::TextEdit;
  107.  
  108. =head2 Constants
  109.  
  110. =over 4
  111.  
  112. =item teFlushDefault
  113.  
  114. =item teCenter
  115.  
  116. =item teFlushRight
  117.  
  118. =item teFlushLeft
  119.  
  120. Text alignment constants.
  121.  
  122. =cut
  123. sub teFlushDefault ()              {          0; }
  124. sub teCenter ()                    {          1; }
  125. sub teFlushRight ()                {         -1; }
  126. sub teFlushLeft ()                 {         -2; }
  127.  
  128. =item doFont
  129.  
  130. =item doFace
  131.  
  132. =item doSize
  133.  
  134. =item doColor
  135.  
  136. =item doAll
  137.  
  138. =item addSize
  139.  
  140. =item doToggle
  141.  
  142. Constants for C<TEContinuousStyle>.
  143.  
  144. =cut
  145. sub doFont ()                      {          1; }
  146. sub doFace ()                      {          2; }
  147. sub doSize ()                      {          4; }
  148. sub doColor ()                     {          8; }
  149. sub doAll ()                       {         15; }
  150. sub addSize ()                     {         16; }
  151. sub doToggle ()                    {         32; }
  152.  
  153. =item teFAutoScroll
  154.  
  155. =item teFTextBuffering
  156.  
  157. =item teFOutlineHilite
  158.  
  159. =item teFInlineInput
  160.  
  161. =item teFUseTextServices
  162.  
  163. =item teFUseInlineInput
  164.  
  165. =item teFInlineInputAutoScroll
  166.  
  167. =item teBitClear
  168.  
  169. =item teBitSet
  170.  
  171. =item teBitTest
  172.  
  173. Features.
  174.  
  175. =cut
  176. sub teFAutoScroll ()               {          0; }
  177. sub teFTextBuffering ()            {          1; }
  178. sub teFOutlineHilite ()            {          2; }
  179. sub teFInlineInput ()              {          3; }
  180. sub teFUseTextServices ()          {          4; }
  181. sub teFUseInlineInput ()           {          5; }
  182. sub teFInlineInputAutoScroll ()    {          6; }
  183. sub teBitClear ()                  {          0; }
  184. sub teBitSet ()                    {          1; }
  185. sub teBitTest ()                   {         -1; }
  186.  
  187. sub teWordSelect ()                {          4; }
  188. sub teWordDrag ()                  {          8; }
  189. sub teFromFind ()                  {         12; }
  190. sub teFromRecal ()                 {         16; }
  191. sub teFind ()                      {          0; }
  192. sub teHighlight ()                 {          1; }
  193. sub teDraw ()                      {         -1; }
  194. sub teCaret ()                     {         -2; }
  195.  
  196. =include TextEdit.xs
  197.  
  198. =head2 Extension to MacWindow
  199.  
  200. =over 4
  201.  
  202. =cut
  203. package MacWindow;
  204.  
  205. BEGIN {
  206.     use Carp;
  207.     use Mac::QuickDraw qw(SetPort);
  208.     import Mac::TextEdit;
  209. }
  210.  
  211. =item new_textedit [CLASS, ] HTE
  212.  
  213. =item new_textedit [CLASS, ] DESTRECT, VIEWRECT
  214.  
  215. Create a new text editing field, attach it to the window, and return it. In the 
  216. first form,  registers an existing text editing field. In the second form, calls  
  217. C<TENew>.
  218.  
  219. =cut
  220. sub new_textedit {
  221.     my($my) = shift @_;
  222.     my($type) = @_;
  223.     my($class,$edit);
  224.  
  225.     if (ref($type)) {
  226.         $class = "MacTextEdit"
  227.     } else {
  228.         $class = shift @_;
  229.         $type  = $_[0];
  230.     }
  231.     if (ref($type) eq "TEHandle") {
  232.         $edit = $type;
  233.     } else {
  234.         SetPort($my->{port});
  235.         $edit = TENew(@_) or croak "TENew failed";
  236.     } 
  237.     $class->new($my, $edit);
  238. }
  239.  
  240. =item new_textedit_style [CLASS, ] DESTRECT, VIEWRECT
  241.  
  242. Create a new styled text editing field, attach it to the window, and return it.
  243.  
  244. =cut
  245. sub new_textedit_style {
  246.     my($my) = shift @_;
  247.     my($type) = @_;
  248.     my($class,$edit);
  249.  
  250.     if (ref($type)) {
  251.         $class = "MacTextEdit"
  252.     } else {
  253.         $class = shift @_;
  254.         $type  = $_[0];
  255.     }
  256.     if (ref($type) eq "TEHandle") {
  257.         $edit = $type;
  258.     } else {
  259.         SetPort($my->{port});
  260.         $edit = TEStyleNew(@_) or croak "TEStyleNew failed";
  261.     } 
  262.     $class->new($my, $edit);
  263. }
  264.  
  265. =back
  266.  
  267. =head2 MacTextEdit - The object interface to a text editing field
  268.  
  269. MacTextEdit is a TextEdit field embedded into a pane.
  270.  
  271. =cut
  272. package MacTextEdit;
  273.  
  274. BEGIN {
  275.     use Mac::Hooks ();
  276.     use Mac::QuickDraw;
  277.     use Mac::Pane;
  278.     use Mac::Events;
  279.     use Mac::Windows();
  280.     import Mac::TextEdit;
  281.  
  282.     use vars qw(@ISA);
  283.     
  284.     @ISA = qw(Mac::Pane Mac::Hooks);
  285. }
  286.  
  287. =item new WINDOW, CONTROL
  288.  
  289. Initialize a C<MacTextEdit> (which is always created with 
  290. C<MacWindow::new_textedit>).
  291.  
  292. =cut
  293. sub new {
  294.     my($class, $window, $edit) = @_;
  295.  
  296.     my(%vars) = (window => $window, edit => $edit);
  297.     
  298.     my $me = bless \%vars, $class;
  299.     
  300.     $window->add_pane($me);
  301.     $window->add_focusable($me);
  302.     $window->add_idle($me, 1);
  303.     
  304.     $me;
  305. }
  306.  
  307. =item dispose
  308.  
  309. Dispose of the toolbox edit.
  310.  
  311. =cut
  312. sub dispose {
  313.     my($my) = @_;
  314.     TEDispose($my->{edit}) if $my->{edit};
  315.     delete $my->{edit};
  316. }
  317.  
  318. =item DESTROY
  319.  
  320. Destroys the C<MacList>.
  321.  
  322. =cut
  323. sub DESTROY {
  324.     dispose(@_);
  325. }
  326.  
  327. =item edit
  328.  
  329. Get the toolbox TextEdit handle.
  330.  
  331. =cut
  332. sub edit {
  333.     my($my) = @_;
  334.     
  335.     $my->{edit};
  336. }
  337.  
  338. =item attach(WINDOW)
  339.  
  340. Called by MacWindow to indicate that the pane has just been attached.
  341.  
  342. =cut
  343. sub attach {
  344.     my($my, $window) = @_;
  345.     
  346.     $window->{edits}->{${$my->{edit}}} = $my;
  347. }
  348.  
  349. =item detach(WINDOW)
  350.  
  351. Called by MacWindow to indicate that the pane has just been detached.
  352.  
  353. =cut
  354. sub detach {
  355.     my($my, $window) = @_;
  356.     
  357.     delete $window->{edits}->{${$my->{edit}}};
  358.     dispose(@_);
  359. }
  360.  
  361. =item focus(WINDOW, FOCUS)
  362.  
  363. Called by MacWindow to indicate that the edit has acquired (1) or lost (0) the 
  364. focus.
  365.  
  366. =cut
  367. sub focus {
  368.     my($my, $window, $focus) = @_;
  369.     my $edit = $my->{edit};
  370.     
  371.     if ($focus) {
  372.         TEActivate($edit);
  373.     } else {
  374.         TEDeactivate($edit);
  375.     }
  376.     
  377.     $my->callhook("focus", @_) and return;
  378. }
  379.  
  380. =item redraw(WINDOW)
  381.  
  382. Redraw the contents of the pane.
  383.  
  384. =cut
  385. sub redraw {
  386.     my($my, $window) = @_;
  387.     my $edit = $my->{edit};
  388.     
  389.     TEUpdate($window->window->visRgn->rgnBBox, $edit);
  390.  
  391.     my $r    = InsetRect $edit->viewRect, -1, -1;
  392.     FrameRect($r);
  393. }
  394.  
  395. =item key(WINDOW, KEY)
  396.  
  397. Handle a key stroke. 
  398.  
  399. =cut
  400. sub key {
  401.     my($my, $window, $key) = @_;
  402.     
  403.     $my->callhook("key", @_) and return;
  404.     
  405.     my $edit = $my->{edit};
  406.     
  407.     TEKey(chr($key), $edit);
  408. }
  409.  
  410. =item click(WINDOW, PT)
  411.  
  412. Handle a click.
  413.  
  414. =cut
  415. sub click {
  416.     my($my, $window, $pt) = @_;
  417.     my($res);
  418.     
  419.     ($res = $my->callhook("click", @_)) and return $res;
  420.  
  421.     my $edit = $my->{edit};
  422.     my $extend = ($Mac::Events::CurrentEvent->modifiers & shiftKey) != 0;
  423.     
  424.     if (TEClick($pt, $extend, $edit)) {
  425.         $my->hit($window);
  426.     }
  427.     return PtInRect($pt, $edit->viewRect);
  428. }
  429.  
  430. =item hit(WINDOW)
  431.  
  432. Handle a double click.
  433.  
  434. =cut
  435. sub hit {
  436.     defined($_[0]->callhook("hit", @_)) and return;
  437. }
  438.  
  439. =item idle 
  440.  
  441. Handle idle events. 
  442.  
  443. =cut
  444. sub idle {
  445.     my($my) = @_;
  446.     TEIdle($my->{edit});
  447. }
  448.  
  449. =head1 BUGS/LIMITATIONS
  450.  
  451. =head1 FILES
  452.  
  453. =head1 AUTHOR(S)
  454.  
  455. Matthias Ulrich Neeracher <neeri@iis.ee.ethz.ch> 
  456.  
  457. =cut
  458.  
  459. 1;
  460.  
  461. __END__
  462.