home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>CallingTk - what is Perl Tk interface doing when you call Tk functions.</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> CallingTk - what is Perl Tk interface doing when you call Tk functions.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>CallingTk - what is Perl Tk interface doing when you call Tk functions.</P>
- <P>This information is worse than useless for <CODE>perlTk</CODE> users, but can of
- some help for people interested in using modified Tk source with
- <CODE>perlTk</CODE>.</P>
- <P><EM>This document is under construction. The information is believed to
- be pertinent to the version of</EM> <CODE>portableTk</CODE> <EM>available when it was
- created. All the details are subject to change.</EM></P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <DL>
- <DT><STRONG><A NAME="item_PreCompiling">PreCompiling</A></STRONG><BR>
- <DD>
- Before the actual compilation stage a script scans the source
- and extracts the subcommands of different commands. This information
- resides in the file <CODE>pTk/Methods.def</CODE>.
- <P></P>
- <DT><STRONG><A NAME="item_Compilation">Compilation</A></STRONG><BR>
- <DD>
- During compilation the above file is included in the source of booting
- routine of dynamic (or static) library. More precisely, the booting
- code of module <CODE>Tk</CODE> calls the subroutine <CODE>Boot_Glue()</CODE> from the module
- <CODE>tkGlue.c</CODE>, and this subroutine includes the file (with appropriate
- macro definitions).
- <P></P>
- <DT><STRONG><A NAME="item_Inside_use_Tk%3B">Inside <CODE>use Tk;</CODE></A></STRONG><BR>
- <DD>
- The module bootstraps the C code, then loads the Perl libraries. The
- heart of the Perl code is contained in the <CODE>Tk::Widget</CODE> library, all the
- widgets inherit from this module. Code for toplevels is loaded from
- <CODE>Tk::MainWindow</CODE>.
- <P>During bootstrap of the C glue code the <CODE>Xevent::?</CODE> codes and a
- handful of <CODE>Tk::Widget</CODE> and <CODE>Tk::Image</CODE> routines are defined. (Much
- more XSUBs are created from <CODE>Tk.xs</CODE> code.) The widget subcommands are
- glued to Perl basing on the list included from <CODE>pTk/Methods.def</CODE>. In
- fact all the subcommands are glued to XSUBs that are related to the
- same C subroutine XStoWidget(), but have different data parts.</P>
- <P>During the Perl code bootstrap the method <CODE>Tk::Widget::import</CODE> is
- called. This call requires all the code from particular widget
- packages.</P>
- <P>Code from the widget packages calls an obscure command like</P>
- <PRE>
- (bless \"Text")->WidgetClass;</PRE>
- <P>This command (actually Tk::Widget::WidgetClass()) creates three
- routines: Tk::Widget::Text(), Tk::Widget::isText(), and
- Tk::Text::isText(). The first one is basically <A HREF="#item_new"><CODE>new</CODE></A> of <CODE>Tk::Text</CODE>,
- the other two return constants. It also puts the class into
- depository.</P>
- <P></P>
- <DT><STRONG><A NAME="item_new">Inside <CODE>$top = MainWindow->new;</CODE></A></STRONG><BR>
- <DD>
- This is quite intuitive. This call goes direct to
- <CODE>Tk::MainWindow::new</CODE>, that calls XSUB
- <CODE>Tk::MainWindow::CreateMainWindow</CODE>, that calls C subroutine
- Tk_CreateMainWindow(). It is a <CODE>Tk</CODE> subroutine, so here black magic
- ends (almost).
- <P>The only remaining black magic is that the <CODE>Tk</CODE> initialization
- routine creates a lot of commands, but the subroutine for creation is
- usurped by <STRONG>portableTk</STRONG> and the commands are created in the package
- <CODE>Tk</CODE>. They are associated to XSUBs that are related to one of three C
- subroutines XStoSubCmd(), XStoBind(), or XStoTk(), but have different
- data parts.</P>
- <P>The result of the call is blessed into <CODE>Tk::MainWindow</CODE>, as it should.</P>
- <P></P>
- <DT><STRONG><A NAME="item_title">Inside <CODE>$top->title('Text demo');</CODE></A></STRONG><BR>
- <DD>
- The package <CODE>Tk::Toplevel</CODE> defines a lot of subroutines on the fly on
- some list. All the commands from the list are converted to the
- corresponding subcommands of <CODE>wm</CODE> method of the widget. Here
- subcommand is a command with some particular second argument (in this
- case <CODE>"title"</CODE>). Recall that the first argument is $self.
- <P>Now <CODE>Tk::Toplevel</CODE> @ISA <CODE>Tk::Widget</CODE>, that in turn @ISA <CODE>Tk</CODE>. So a
- call to <CODE>$top->wm('title','Text demo')</CODE> calls <CODE>Tk::wm</CODE>, that is
- defined during call to Tk_CreateMainWindow(). As it is described
- above, the XSUB associated to <CODE>XStoSubCmd()</CODE> is called.</P>
- <P>This C routine is defined in <CODE>tkGlue.c</CODE>. It gets the data part of
- XSUB, creates a <A HREF="../../../lib/Pod/perlguts.html#item_SV"><CODE>SV</CODE></A> with the name of the command, and calls
- <CODE>Call_Tk()</CODE> with the XSUB data as the first argument, and with the name
- of XSUB stuffed into the Perl stack in the place there <CODE>tk</CODE> expects
- it. (In fact it can also reorder the arguments if it thinks it is
- what you want).</P>
- <P>The latter procedure extracts name of <CODE>tk</CODE> procedure and
- <CODE>clientData</CODE> from the first argument and makes a call, using Perl
- stack as <CODE>argv</CODE> for the procedure. A lot of black magic is performed
- afterwards to convert result of the procedure to a Perl array return.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Text">Inside <CODE>$text = $top->Text(background => $txtBg);</CODE></A></STRONG><BR>
- <DD>
- Above we discussed how the command <CODE>Tk::Widget::Text</CODE> is created. The
- above command calls it via inheritance. It is translated to
- <PRE>
- Tk::Text::new($top, background => $txtBg);</PRE>
- <P>The package <CODE>Tk::Text</CODE> has no method <A HREF="#item_new"><CODE>new</CODE></A>, so the
- <CODE>Tk::Widget::new</CODE> is called. In turn it calls
- <CODE>Tk::Text->DoInit($top)</CODE>, that is
- <CODE>Tk::Widget::DoInit(Tk::Text,$top)</CODE>, that initializes the bindings if
- necessary. Then it creates the name for the widget of the form
- <CODE>.text0</CODE>, and calls <CODE>Tk::text('.text0', background => $txtBg)</CODE>
- (note lowercase). The result of the call is blessed into <CODE>Tk::Text</CODE>,
- and the method <CODE>bindtags</CODE> for this object is called.</P>
- <P>Now the only thing to discuss is who defines the methods <CODE>text</CODE> and
- <CODE>bindtags</CODE>. The answer is that they are defined in <CODE>tkWindow.c</CODE>,
- and these commands are created in the package <CODE>Tk</CODE> in the same sweep
- that created the command <CODE>Tk::wm</CODE> discussed above.</P>
- <P>So the the same C code that corresponds to the processing of
- corresponding TCL commands is called here as well (this time via
- <CODE>XStoTk</CODE> interface).</P>
- <P></P>
- <DT><STRONG><A NAME="item_insert">Inside <CODE>$text->insert('insert','Hello, world!');</CODE></A></STRONG><BR>
- <DD>
- As we discussed above, the subcommands of widget procedures correspond
- to XSUB <CODE>XStoWidget</CODE>. This XSUB substitutes the first argument $text
- (that is a hash reference) to an appropriate value from this hash,
- adds the additional argument after the first one that contains the
- name of the subcommand extracted from the data part of XSUB, and calls
- the corresponding Tk C subroutine via <CODE>Call_Tk</CODE>.
- <P></P></DL>
- <P>Ilya Zakharevich <<A HREF="mailto:ilya@math.ohio-state.edu">ilya@math.ohio-state.edu</A>></P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> CallingTk - what is Perl Tk interface doing when you call Tk functions.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-