Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000685.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
8    <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9    <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml" />
11
12    <title>Status for Andrew DeFaria: CreateWOR: Subclassing TextUndo</title>
13
14    <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15    <link rel="prev" href="http://defaria.com/blogs/Status/archives/000684.html" title="CreateWOR" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000686.html" title="cqtalk" />
17
18    <!--
19 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20          xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
21          xmlns:dc="http://purl.org/dc/elements/1.1/">
22 <rdf:Description
23     rdf:about="http://defaria.com/blogs/Status/archives/000685.html"
24     trackback:ping="http://defaria.com/mt/mt-tb.cgi/72"
25     dc:title="CreateWOR: Subclassing TextUndo"
26     dc:identifier="http://defaria.com/blogs/Status/archives/000685.html"
27     dc:subject="General Dynamics"
28     dc:description=" Added onChange like callbacks to CreateWOR&apos;s text field and text widget. This required subclassing the TextUndo class and properly handling the call back...."
29     dc:creator=""
30     dc:date="2007-10-03T11:17:48-06:00" />
31 </rdf:RDF>
32 -->
33
34
35    
36
37    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
38 </head>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
40    <div id="container">
41       <div id="container-inner" class="pkg">
42
43          <div id="banner">
44             <div id="banner-inner" class="pkg">
45                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
46                <h2 id="banner-description">Searchable status reports and work log</h2>
47             </div>
48          </div>
49
50          <div id="pagebody">
51             <div id="pagebody-inner" class="pkg">
52                <div id="alpha">
53                   <div id="alpha-inner" class="pkg">
54
55                      <p class="content-nav">
56                         <a href="http://defaria.com/blogs/Status/archives/000684.html">&laquo; CreateWOR</a> |
57                         <a href="http://defaria.com/blogs/Status/">Main</a>
58                         | <a href="http://defaria.com/blogs/Status/archives/000686.html">cqtalk &raquo;</a>
59                      </p>
60
61                      <a id="a000685"></a>
62                      <div class="entry" id="entry-685">
63                         <h3 class="entry-header">CreateWOR: Subclassing TextUndo</h3>
64                         <div class="entry-content">
65                            <div class="entry-body">
66                               <ul>
67   <li>Added onChange like callbacks to CreateWOR's text field and text widget. This required subclassing the TextUndo class and properly handling the call back.</li>
68 </ul>
69                            </div>
70                            <div id="more" class="entry-more">
71                               <h3>Subclassing TextUndo</h3>
72
73 <p>This is not working exactly as it should. I can't seem to store things like the onChange callback and a scalar representing the contents of the TextUndo widget in the new MyText object. I rely on overriding the methods InsertKeypress, insert, delete and replace in order to trap when modifications are made to the text, changing the $text member and to call the appropriate callback, but the object that's passed in is different than the object as it was in new and member variables for $text and $modified_CB are missing! So instead I use a package global but this means that only one, the same one, $modification_CB is used for all instantiations of MyText and the $text variable doesn't work at all. Instead one must call get_text in the &$modified_CB:</p>
74
75 <div class=code><pre>
76 # Subclass TextUndo widget to trap and call subroutine when text changes
77 package Tk::MyText;
78   use Tk::TextUndo;
79
80   use base qw/Tk::TextUndo/;
81
82   Construct Tk::Widget "MyText";
83
84   my $modified_CB;
85
86   sub new {
87     my $class   = shift;
88     my $self    = shift;
89     my %parms   = @_;
90
91     $modified_CB        = delete $parms{-modified}      if $parms{-modified};
92     $self->{text}       = delete $parms{-text}          if $parms{-text};
93
94     $class->SUPER::new ($self, %parms);
95   } # new
96
97   sub get_text {
98     my $self = shift;
99
100     return $self->{text};
101   } # get_text
102
103   sub InsertKeypress {
104     my $self = shift;
105
106     $self->SUPER::InsertKeypress (@_);
107     $self->{text} = $self->get ("1.0", "end");
108     &$modified_CB ($self) if $modified_CB;
109   } # InsertKeypress
110
111   sub insert {
112     my $self = shift;
113
114     $self->SUPER::insert (@_);
115     $self->{text} = $self->get ("1.0", "end");
116   } # insert
117
118   sub delete {
119     my $self = shift;
120
121     $self->SUPER::delete (@_);
122     $self->{text} = $self->get ("1.0", "end");
123     &$modified_CB ($self) if $modified_CB;
124   } # delete
125
126   sub replace {
127     my $self = shift;
128
129     $self->SUPER::replace (@_);
130     $self->{text} = $self->get ("1.0", "end");
131     &$modified_CB ($self) if $modified_CB;
132   } # replace
133
134 </pre></div> 
135                            </div>
136                         </div>
137                         <p class="entry-footer">
138                            <span class="post-footers">Posted by  on October  3, 2007 11:17 AM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000685.html">Permalink</a>
139                         </p>
140                      </div>
141
142                      
143                      <div class="trackbacks">
144                         <h3 id="trackback" class="trackbacks-header">TrackBack</h3>
145                         <div id="trackbacks-info">
146                            <p>TrackBack URL for this entry:<br />http://defaria.com/mt/mt-tb.cgi/72</p>
147                         </div>
148                         <div class="trackbacks-content">
149                            
150                         </div>
151                      </div>
152                      
153
154                      
155                   </div>
156                </div>
157             </div>
158          </div>
159       </div>
160    </div>
161 </body>
162 </html>