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

  1. =head1 NAME
  2.  
  3. Mac::.Controls - Macintosh Toolbox Interface to Control Manager
  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::Controls;
  20.  
  21. BEGIN {
  22.     use Exporter   ();
  23.     use DynaLoader ();
  24.     
  25.     use vars qw(@ISA @EXPORT @EXPORT_OK $gControlManager);
  26.     
  27.     @ISA = qw(Exporter DynaLoader);
  28.     @EXPORT = qw(
  29.         NewControl
  30.         GetNewControl
  31.         DisposeControl
  32.         KillControls
  33.         ShowControl
  34.         HideControl
  35.         DrawControls
  36.         Draw1Control
  37.         UpdateControls
  38.         HiliteControl
  39.         TrackControl
  40.         DragControl
  41.         TestControl
  42.         FindControl
  43.         MoveControl
  44.         SizeControl
  45.         SetControlTitle
  46.         GetControlTitle
  47.         GetControlValue
  48.         SetControlValue
  49.         GetControlMinimum
  50.         SetControlMinimum
  51.         GetControlMaximum
  52.         SetControlMaximum
  53.         GetControlVariant
  54.         SetControlReference
  55.         GetControlReference
  56.     
  57.         pushButProc
  58.         checkBoxProc
  59.         radioButProc
  60.         scrollBarProc
  61.         popupMenuProc
  62.         kControlUsesOwningWindowsFontVariant
  63.         kControlNoPart
  64.         kControlLabelPart
  65.         kControlMenuPart
  66.         kControlTrianglePart
  67.         kControlButtonPart
  68.         kControlCheckBoxPart
  69.         kControlRadioButtonPart
  70.         kControlUpButtonPart
  71.         kControlDownButtonPart
  72.         kControlPageUpPart
  73.         kControlPageDownPart
  74.         kControlIndicatorPart
  75.         kControlDisabledPart
  76.         kControlInactivePart
  77.         kControlCheckboxUncheckedValue
  78.         kControlCheckboxCheckedValue
  79.         kControlCheckboxMixedValue
  80.         kControlRadioButtonUncheckedValue
  81.         kControlRadioButtonCheckedValue
  82.         kControlRadioButtonMixedValue
  83.         popupFixedWidth
  84.         popupVariableWidth
  85.         popupUseAddResMenu
  86.         popupUseWFont
  87.         popupTitleBold
  88.         popupTitleItalic
  89.         popupTitleUnderline
  90.         popupTitleOutline
  91.         popupTitleShadow
  92.         popupTitleCondense
  93.         popupTitleExtend
  94.         popupTitleNoStyle
  95.         popupTitleLeftJust
  96.         popupTitleCenterJust
  97.         popupTitleRightJust
  98.         noConstraint
  99.         hAxisOnly
  100.         vAxisOnly
  101.         cFrameColor
  102.         cBodyColor
  103.         cTextColor
  104.         cThumbColor
  105.         kNoHiliteControlPart
  106.         kInLabelControlPart
  107.         kInMenuControlPart
  108.         kInTriangleControlPart
  109.         kInButtonControlPart
  110.         kInCheckBoxControlPart
  111.         kInUpButtonControlPart
  112.         kInDownButtonControlPart
  113.         kInPageUpControlPart
  114.         kInPageDownControlPart
  115.         kInIndicatorControlPart
  116.         kReservedControlPart
  117.         kControlInactiveControlPart
  118.     );
  119.     @EXPORT_OK = qw(
  120.         $gControlManager
  121.     );
  122. }
  123.  
  124. =head2 Constants
  125.  
  126. =over 4
  127.  
  128. =item pushButProc
  129.  
  130. =item checkBoxProc
  131.  
  132. =item radioButProc
  133.  
  134. =item scrollBarProc
  135.  
  136. =item popupMenuProc
  137.  
  138. =item kControlUsesOwningWindowsFontVariant
  139.  
  140. Standard control definition procedures and a variant to make them use the window
  141. font instead of the system font.
  142.  
  143. =cut
  144. sub pushButProc ()                 {          0; }
  145. sub checkBoxProc ()                {          1; }
  146. sub radioButProc ()                {          2; }
  147. sub scrollBarProc ()               {         16; }
  148. sub popupMenuProc ()               {       1008; }
  149. sub kControlUsesOwningWindowsFontVariant () {     1 << 3; }
  150.  
  151.  
  152. =item kControlNoPart
  153.  
  154. =item kControlLabelPart
  155.  
  156. =item kControlMenuPart
  157.  
  158. =item kControlTrianglePart
  159.  
  160. =item kControlButtonPart
  161.  
  162. =item kControlCheckBoxPart
  163.  
  164. =item kControlRadioButtonPart
  165.  
  166. =item kControlUpButtonPart
  167.  
  168. =item kControlDownButtonPart
  169.  
  170. =item kControlPageUpPart
  171.  
  172. =item kControlPageDownPart
  173.  
  174. =item kControlIndicatorPart
  175.  
  176. =item kControlDisabledPart
  177.  
  178. =item kControlInactivePart
  179.  
  180. Standard control parts.
  181.  
  182. =cut
  183. sub kControlNoPart ()              {          0; }
  184. sub kControlLabelPart ()           {          1; }
  185. sub kControlMenuPart ()            {          2; }
  186. sub kControlTrianglePart ()        {          4; }
  187. sub kControlButtonPart ()          {         10; }
  188. sub kControlCheckBoxPart ()        {         11; }
  189. sub kControlRadioButtonPart ()     {         11; }
  190. sub kControlUpButtonPart ()        {         20; }
  191. sub kControlDownButtonPart ()      {         21; }
  192. sub kControlPageUpPart ()          {         22; }
  193. sub kControlPageDownPart ()        {         23; }
  194. sub kControlIndicatorPart ()       {        129; }
  195. sub kControlDisabledPart ()        {        254; }
  196. sub kControlInactivePart ()        {        255; }
  197.  
  198.  
  199. =item kControlCheckboxUncheckedValue
  200.  
  201. =item kControlCheckboxCheckedValue
  202.  
  203. =item kControlCheckboxMixedValue
  204.  
  205. =item kControlRadioButtonUncheckedValue
  206.  
  207. =item kControlRadioButtonCheckedValue
  208.  
  209. =item kControlRadioButtonMixedValue
  210.  
  211. Standard control values.
  212.  
  213. =cut
  214. sub kControlCheckboxUncheckedValue () {          0; }
  215. sub kControlCheckboxCheckedValue () {          1; }
  216. sub kControlCheckboxMixedValue ()  {          2; }
  217. sub kControlRadioButtonUncheckedValue () {          0; }
  218. sub kControlRadioButtonCheckedValue () {          1; }
  219. sub kControlRadioButtonMixedValue () {          2; }
  220.  
  221.  
  222. =item popupFixedWidth
  223.  
  224. =item popupVariableWidth
  225.  
  226. =item popupUseAddResMenu
  227.  
  228. =item popupUseWFont
  229.  
  230. =item popupTitleBold
  231.  
  232. =item popupTitleItalic
  233.  
  234. =item popupTitleUnderline
  235.  
  236. =item popupTitleOutline
  237.  
  238. =item popupTitleShadow
  239.  
  240. =item popupTitleCondense
  241.  
  242. =item popupTitleExtend
  243.  
  244. =item popupTitleNoStyle
  245.  
  246. =item popupTitleLeftJust
  247.  
  248. =item popupTitleCenterJust
  249.  
  250. =item popupTitleRightJust
  251.  
  252. Popup menu options, for use in the C<value> parameter of the control creation.
  253.  
  254. =cut
  255. sub popupFixedWidth ()             {     1 << 0; }
  256. sub popupVariableWidth ()          {     1 << 1; }
  257. sub popupUseAddResMenu ()          {     1 << 2; }
  258. sub popupUseWFont ()               {     1 << 3; }
  259. sub popupTitleBold ()              {     1 << 8; }
  260. sub popupTitleItalic ()            {     1 << 9; }
  261. sub popupTitleUnderline ()         {    1 << 10; }
  262. sub popupTitleOutline ()           {    1 << 11; }
  263. sub popupTitleShadow ()            {    1 << 12; }
  264. sub popupTitleCondense ()          {    1 << 13; }
  265. sub popupTitleExtend ()            {    1 << 14; }
  266. sub popupTitleNoStyle ()           {    1 << 15; }
  267. sub popupTitleLeftJust ()          { 0x00000000; }
  268. sub popupTitleCenterJust ()        { 0x00000001; }
  269. sub popupTitleRightJust ()         { 0x000000FF; }
  270.  
  271.  
  272. =item noConstraint
  273.  
  274. =item hAxisOnly
  275.  
  276. =item vAxisOnly
  277.  
  278. Drag axis.
  279.  
  280. =cut
  281. sub noConstraint ()                {          0; }
  282. sub hAxisOnly ()                   {          1; }
  283. sub vAxisOnly ()                   {          2; }
  284.  
  285.  
  286. =item cFrameColor
  287.  
  288. =item cBodyColor
  289.  
  290. =item cTextColor
  291.  
  292. =item cThumbColor
  293.  
  294. Color specification parts for control colors.
  295.  
  296. =cut
  297. sub cFrameColor ()                 {          0; }
  298. sub cBodyColor ()                  {          1; }
  299. sub cTextColor ()                  {          2; }
  300. sub cThumbColor ()                 {          3; }
  301.  
  302.  
  303. =item kNoHiliteControlPart
  304.  
  305. =item kInLabelControlPart
  306.  
  307. =item kInMenuControlPart
  308.  
  309. =item kInTriangleControlPart
  310.  
  311. =item kInButtonControlPart
  312.  
  313. =item kInCheckBoxControlPart
  314.  
  315. =item kInUpButtonControlPart
  316.  
  317. =item kInDownButtonControlPart
  318.  
  319. =item kInPageUpControlPart
  320.  
  321. =item kInPageDownControlPart
  322.  
  323. =item kInIndicatorControlPart
  324.  
  325. =item kReservedControlPart
  326.  
  327. =item kControlInactiveControlPart
  328.  
  329. Part codes for controls.
  330.  
  331. =cut
  332. sub kNoHiliteControlPart ()        {          0; }
  333. sub kInLabelControlPart ()         {          1; }
  334. sub kInMenuControlPart ()          {          2; }
  335. sub kInTriangleControlPart ()      {          4; }
  336. sub kInButtonControlPart ()        {         10; }
  337. sub kInCheckBoxControlPart ()      {         11; }
  338. sub kInUpButtonControlPart ()      {         20; }
  339. sub kInDownButtonControlPart ()    {         21; }
  340. sub kInPageUpControlPart ()        {         22; }
  341. sub kInPageDownControlPart ()      {         23; }
  342. sub kInIndicatorControlPart ()     {        129; }
  343. sub kReservedControlPart ()        {        254; }
  344. sub kControlInactiveControlPart () {        255; }
  345.  
  346. =back
  347.  
  348. =cut
  349.  
  350. bootstrap Mac::Controls;
  351.  
  352. =include Controls.xs
  353.  
  354. =head2 Variables
  355.  
  356. =over 4
  357.  
  358. =item $gControlManager
  359.  
  360. A pane to handle all controls in a window. The default control manager should
  361. usually do what you want.
  362.  
  363. =back
  364.  
  365. =cut
  366. $gControlManager = undef;
  367.  
  368. =head2 MacControlWindow - The Object Interface
  369.  
  370. The C<MacControlWindow> class used to be necessary to manage a window with 
  371. controls, but is now obsolete.
  372.  
  373. =cut
  374. package MacControlWindow;
  375.  
  376. BEGIN {
  377.     use Carp;
  378.  
  379.     use vars qw(@ISA);
  380.     
  381.     @ISA = qw(MacWindow);
  382. }
  383.  
  384. sub new {
  385.     carp("MacControlWindow is obsolete, simply use MacWindow") if $^W;
  386.     
  387.     &MacWindow::new;
  388. }
  389.  
  390. # Name dropping so new MacControlManager below works
  391.  
  392. package MacControlManager;
  393.  
  394. package MacWindow;
  395.  
  396. BEGIN {
  397.     use Carp;
  398.     use Mac::Windows ();
  399.     import Mac::Controls;
  400. }
  401.  
  402. =item new_control [CLASS, ] CONTROL
  403.  
  404. =item new_control [CLASS, ] BOUNDS, TITLE, VISIBLE, VAL, MIN, MAX, PROC [, REFCON]
  405.  
  406. Register a new control for the window. In the first form, registers an existing 
  407. control. In the second form, calls  C<NewControl>.
  408.  
  409. =cut
  410. sub new_control {
  411.     my($my) = shift @_;
  412.     my($type) = @_;
  413.     my($class,$control,$popup,$c);
  414.     
  415.     unless ($my->{controlmanager}) {
  416.         $my->{controlmanager} = new MacControlManager;
  417.         $my->add_pane($my->{controlmanager});
  418.     }
  419.     if (ref($type)) {
  420.         $class = "MacControl"
  421.     } else {
  422.         $class = shift @_;
  423.         $type  = $_[0];
  424.     }
  425.     if (ref($type) eq "ControlHandle") {
  426.         $control = $type;
  427.     } else {
  428.         $control = NewControl($my->{port}, @_) or croak "NewControl failed";
  429.         $popup   = ($_[6] & ~0x0F) == popupMenuProc;
  430.     } 
  431.     $c = $class->new($my, $control);
  432.     if ($popup) {
  433.         $c->{action} = -1;
  434.     }
  435.     $my->{controls}->{$$control} = $c;
  436. }
  437.  
  438. =head2 MacControlManager - Managing the controls in a window
  439.  
  440. The C<MacControlManager> pane handles all controls in a window. This class is
  441. implemented as a flyweight, so only one instance is needed for the entire program.
  442.  
  443. =cut
  444. package MacControlManager;
  445.  
  446. BEGIN {
  447.     use Mac::Pane;
  448.     import Mac::Controls;
  449.  
  450.     use vars qw(@ISA);
  451.     
  452.     @ISA = qw(Mac::Pane);
  453. }
  454.  
  455. sub new {
  456.     my($class) = @_;
  457.     
  458.     $Mac::Controls::gControlManager ||= bless {}, $class;
  459. }
  460.  
  461. sub redraw {
  462.     my($my,$win) = @_;
  463.     UpdateControls($win->window);
  464. }
  465.  
  466. sub click {
  467.     my($my, $win, $pt) = @_;
  468.     
  469.     my($part,$control) = FindControl($pt, $win->window);
  470.     return 0 unless $control;
  471.     
  472.     my($ctrl) = $win->{controls}->{$$control};
  473.     return 0 unless $ctrl;
  474.  
  475.     $ctrl->track($win, $pt);
  476.     
  477.     1;
  478. }
  479.  
  480. =head2 MacControl - The Object Interface
  481.  
  482. The C<MacControlWindow> class manages a single control in a window.
  483.  
  484. =over 4
  485.  
  486. =cut
  487. package MacControl;
  488.  
  489. BEGIN {
  490.     use Mac::Hooks ();
  491.     import Mac::Controls;
  492.  
  493.     use vars qw(@ISA);
  494.     
  495.     @ISA = qw(Mac::Hooks);
  496. }
  497.  
  498. =item new WINDOW, CONTROL
  499.  
  500. Initialize a C<MacControl> (which is always created with 
  501. C<MacWindow::new_control>).
  502.  
  503. =cut
  504. sub new {
  505.     my($class, $window, $control) = @_;
  506.  
  507.     my(%vars) = (window => $window, control => $control);
  508.     
  509.     bless \%vars, $class;
  510. }
  511.  
  512. =item DESTROY
  513.  
  514. Destroys the C<MacControl>.
  515.  
  516. =cut
  517. sub DESTROY {
  518.     my($my) = @_;
  519.     DisposeControl($my->{control});
  520. }
  521.  
  522. =item track WINDOW, PT
  523.  
  524. Track a mouse click in the control.
  525.  
  526. =cut
  527. sub track {
  528.     defined($_[0]->callhook("track", @_)) and return;
  529.     my($my, $window, $pt) = @_;
  530.     my($part);
  531.     if ($my->{action}) {
  532.         $part = TrackControl($my->{control}, $pt, $my->{action});
  533.     } else {
  534.         $part = TrackControl($my->{control}, $pt);
  535.     }
  536.     $part && $my->hit($part);
  537. }
  538.  
  539. =item hit WINDOW, PART
  540.  
  541. Handle user action in a part. 
  542.  
  543. =cut
  544. sub hit {
  545.     defined($_[0]->callhook("hit", @_)) and return;
  546. }
  547.  
  548. =back
  549.  
  550. =head1 BUGS/LIMITATIONS
  551.  
  552. =head1 FILES
  553.  
  554. =head1 AUTHOR(S)
  555.  
  556. Matthias Ulrich Neeracher <neeri@iis.ee.ethz.ch> 
  557.  
  558. =cut
  559.  
  560. 1;
  561.  
  562. __END__
  563.