📄 archetype.n
字号:
'\"'\" Copyright (c) 1993-1998 Lucent Technologies, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\"'\" RCS: $Id: Archetype.n,v 1.1 2003/02/05 10:53:58 mdejong Exp $'\".so man.macros.TH Archetype n 3.0 itk "[incr\ Tk]".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEArchetype \- base class for all [incr\ Tk] mega-widgets.SH "INHERITANCE"none.ta 4c 8c 12c.SH "WIDGET-SPECIFIC OPTIONS".LP.nfName: \fBclientData\fRClass: \fBClientData\fRCommand-Line Switch: \fB-clientdata\fR.fi.IPThis does not affect the widget operation in any way. It issimply a hook that clients can use to store a bit of data witheach widget. This can come in handy when using widgets tobuild applications..BE.SH DESCRIPTION.PPThe \fBArchetype\fR class is the basis for all \fB[incr\ Tk]\fRmega-widgets. It keeps track of component widgets and providesmethods like "configure" and "cget" that are used to accessthe composite configuration options. Each component widgetmust be registered with the \fBArchetype\fR base class usingthe "\fBitk_component add\fR" method. When the componentis registered, its configuration options are integrated intothe composite option list. Configuring a composite optionlike "-background" causes all of the internal componentsto change their background color..PPIt is not used as a widget by itself, but is used as a baseclass for more specialized widgets. The \fBWidget\fR base classinherits from \fBArchetype\fR, and adds a Tk frame which acts asthe "hull" for the mega-widget. The \fBToplevel\fR base classinherits from \fBArchetype\fR, but adds a Tk toplevel which actsas the "hull"..PP\fIEach derived class must invoke the \fBitk_initialize\fP methodwithin its constructor\fR, so that all options are properlyintegrated and initialized in the composite list..SH "PUBLIC METHODS".PPThe following methods are provided to support the publicinterface of the mega-widget..TP\fIpathName \fBcget\fR \fIoption\fRReturns the current value of the configuration option givenby \fIoption\fR..spIn this case, \fIoption\fR refers to a composite configurationoption for the mega-widget. Individual components integratetheir own configuration options onto the composite list whenthey are registered by the "\fBitk_component add\fR" method..TP\fIpathName\fR \fBcomponent\fR ?\fIname\fR? ?\fIcommand arg arg ...\fR?Used to query or access component widgets within a mega-widget.With no arguments, this returns a list of symbolic names forcomponent widgets that are accessible in the current scope.The symbolic name for a component is established when it isregistered by the "\fBitk_component add\fR" method. Note thatcomponent widgets obey any public/protected/private accessrestriction that is in force when the component is created..spIf a symbolic \fIname\fR is specified, this method returns thewindow path name for that component..spOtherwise, the \fIcommand\fR and any remaining \fIarg\fR argumentsare invoked as a method on the component with the symbolicname \fIname\fR. This provides a well-defined way of accessinginternal components without relying on specific window pathnames, which are really details of the implementation..TP\fIpathName\fR \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?Query or modify the configuration options of the widget.If no \fIoption\fR is specified, returns a list describing all ofthe available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR forinformation on the format of this list). If \fIoption\fR is specifiedwith no \fIvalue\fR, then the command returns a list describing theone named option (this list will be identical to the correspondingsublist of the value returned if no \fIoption\fR is specified). Ifone or more \fIoption\-value\fR pairs are specified, then the commandmodifies the given widget option(s) to have the given value(s); inthis case the command returns an empty string..spIn this case, the \fIoptions\fR refer to composite configurationoptions for the mega-widget. Individual components integrate theirown configuration options onto the composite list when they areregistered by the "\fBitk_component add\fR" method..SH "PROTECTED METHODS".PPThe following methods are used in derived classes as part ofthe implementation for a mega-widget..TP\fBitk_component add\fR ?\fB-protected\fR? ?\fB-private\fR? ?\fB--\fR? \fIname createCmds\fR ?\fIoptionCmds\fR?Creates a component widget by executing the \fIcreateCmds\fRargument and registers the new component with the symbolicname \fIname\fR. The \fB-protected\fR and \fB-private\fR optionscan be used to keep the component hidden from the outside world.These options have a similar effect on component visibility asthey have on class members..spThe \fIcreateCmds\fR code can contain anynumber of commands, but it must return the window path namefor the new component widget..spThe \fIoptionCmds\fR script contains commands that describehow the configuration options for the new component shouldbe integrated into the composite list for the mega-widget.It can contain any of the following commands:.RS.TP\fBignore \fIoption\fR ?\fIoption option ...\fR?Removes one or more configuration \fIoptions\fR from thecomposite list. All options are ignored by default,so the \fBignore\fR command is only used to negate theeffect of a previous \fBkeep\fR or \fBrename\fR command.This is useful, for example, when the some of the optionsadded by the \fBusual\fR command should not apply toa particular component, and need to be ignored..TP\fBkeep \fIoption\fR ?\fIoption option ...\fR?Integrates one or more configuration \fIoptions\fR into thecomposite list, keeping the name the same. Whenever themega-widget option is configured, the new value is alsoapplied to the current component. Options like "-background"and "-cursor" are commonly found on the \fBkeep\fR list..TP\fBrename \fIoption switchName resourceName resourceClass\fRIntegrates the configuration \fIoption\fR into the compositelist with a different name. The option will be called\fIswitchName\fR on the composite list. It will also bemodified by setting values for \fIresourceName\fR and \fIresourceClass\fRin the X11 resource database. The "-highlightbackground"option is commonly renamed to "-background", so that whenthe mega-widget background changes, the background of thefocus ring will change as well..TP\fBusual ?\fItag\fR?Finds the usual option-handling commands for the specified\fItag\fR name and executes them. If the \fItag\fR isnot specified, then the widget class name is used as the\fItag\fR name. The "usual" option-handling commandsare registered via the \fBusual\fR command..RE.spIf the \fIoptionCmds\fR script is not specified, the usualoption-handling commands associated with the class of thecomponent widget are used by default..TP\fBitk_component delete\fR \fIname\fR ?\fIname name ...\fR?Removes the component widget with the symbolic name \fIname\fRfrom the mega-widget. The component widget will still exist,but it will no longer be accessible as a component of themega-widget. Also, any options associated with the componentare removed from the composite option list..spNote that you can destroy a component using the \fBdestroy\fRcommand, just as you would destroy any Tk widget. Componentsautomatically detach themselves from their mega-widget parentwhen destroyed, so "\fBitk_component delete\fR" is rarely used..TP\fBitk_initialize ?\fIoption value option value...\fR?\fIThis method must be invoked within the constructor foreach class in a mega-widget hierarchy.\fR It makes surethat all options are properly integrated into the compositeoption list, and synchronizes all components to the initialoption values. It is usually invoked near the bottom ofthe constructor, after all component widgets have beenadded..spIf any \fIoption\fR/\fIvalue\fR pairs are specified, theyoverride settings determined from the X11 resource database.The arguments to the constructor are usually passed alongto this method as follows:.CSclass MyWidget { inherit Widget constructor {args} { . . . eval itk_initialize $args }}.CE.TP\fBitk_option add\fR \fIoptName\fR ?\fIoptName optName ...\fR?Adds one or more options to the composite option list fora mega-widget. Here, \fIoptName\fR can have one of thefollowing forms:.RS.TP\fIcomponent\fR.\fIoption\fRAccesses an \fIoption\fR belonging to a component with thesymbolic name \fIcomponent\fR. The \fIoption\fR name isspecified without a leading "\fB-\fR" sign..TP\fIclassName\fR::\fIoption\fRAccesses an \fIoption\fR defined by the "\fBitk_option define\fR"command in class \fIclassName\fR. The \fIoption\fR name isspecified without a leading "\fB-\fR" sign..RE.PPOptions are normally integrated into the composite option listwhen a component widget is first created. This method can beused to add options at a later time. For example, the \fBWidget\fRand \fBToplevel\fR base classes keep only the bare minimum optionsfor their "hull" component: -background and -cursor. A derivedclass can override this decision, and add options that controlthe border of the "hull" component as well:.CSclass MyWidget { inherit Widget constructor {args} { itk_option add hull.borderwidth hull.relief itk_component add label { label $itk_interior.l1 -text "Hello World!" } pack $itk_component(label) eval itk_initialize $args }}.CE.TP\fBitk_option define\fR \fIswitchName resourceName resourceClass init\fR ?\fIconfig\fR?This command is used at the level of the class definition todefine a synthetic mega-widget option. Within the \fBconfigure\fRand \fBcget\fR methods, this option is referenced by \fIswitchName\fR,which must start with a "\fB-\fR" sign. It can also bemodified by setting values for \fIresourceName\fR and \fIresourceClass\fRin the X11 resource database. The \fIinit\fR value string is usedas a last resort to initialize the option if no other value canbe used from an existing option, or queried from the X11 resourcedatabase. If any \fIconfig\fR code is specified, it is executedwhenever the option is modified via the \fBconfigure\fR method.The \fIconfig\fR code can also be specified outside of the classdefinition via the \fBconfigbody\fR command..spIn the following example, a synthetic "-background" option isadded to the class, so that whenever the background changes, thenew value is reported to standard output. Note that this syntheticoption is integrated with the rest of the "-background" optionsthat have been kept from component widgets:.CSclass MyWidget { inherit Widget constructor {args} { itk_component add label { label $itk_interior.l1 -text "Hello World!" } pack $itk_component(label) eval itk_initialize $args } itk_option define -background background Background #d9d9d9 { puts "new background: $itk_option(-background)" }}.CE.TP\fBitk_option remove\fR \fIoptName\fR ?\fIoptName optName ...\fR?Removes one or more options from the composite option list fora mega-widget. Here, \fIoptName\fR can have one of the formsdescribed above for the "\fBitk_option add\fR" command..spOptions are normally integrated into the composite option listwhen a component widget is first created. This method can beused to remove options at a later time. For example, a derivedclass can override an option defined in a base class by removingand redefining the option:.CSclass Base { inherit Widget constructor {args} { eval itk_initialize $args } itk_option define -foo foo Foo "" { puts "Base: $itk_option(-foo)" }}class Derived { inherit Base constructor {args} { itk_option remove Base::foo eval itk_initialize $args } itk_option define -foo foo Foo "" { puts "Derived: $itk_option(-foo)" }}.CEWithout the "\fBitk_option remove\fR" command, the code fragmentsfor both of the "-foo" options would be executed each time thecomposite "-foo" option is configured. In the example above,the \fCBase::foo\fR option is suppressed in all Derived classwidgets, so only the \fCDerived::foo\fR option remains..SH "PROTECTED VARIABLES"Derived classes can find useful information in the followingprotected variables..TPitk_component(\fIname\fR)The "itk_component" array returns the real window path namefor a component widget with the symbolic name \fIname\fR.The same information can be queried using the \fBcomponent\fRmethod, but accessing this array is faster and more convenient..TPitk_interiorThis variable contains the name of the window that acts asa parent for internal components. It is initialized to thename of the "hull" component provided by the \fBWidget\fRand \fBToplevel\fR classes. Derived classes can overridethe initial setting to point to another interior windowto be used for further-derived classes..TPitk_option(\fIoption\fR)The "itk_option" array returns the current option valuefor the composite widget option named \fIoption\fR. Here,the \fIoption\fR name should include a leading "\fB-\fR" sign.The same information can be queried using the \fBcget\fRmethod, but accessing this array is faster and more convenient..SH KEYWORDSitk, Widget, Toplevel, mega-widget
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -