Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to allow user to edit tooltips?
Message
From
25/05/2008 20:40:45
 
 
To
19/05/2008 12:33:36
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01318188
Message ID:
01319447
Views:
22
To everybody who contributed to this thread:

Thanks! I thought I'd review my (almost) final results:

(1) Original statement:
I have a request to allow a user (responsible for creating user documentation) to create and edit tooltips for all my forms.

What I can see clearly is how and where to store the tooltips. Clearly, the user will not be modifying my forms directly, so I would want to store the tooltips in a table ... somewhere. Where?

Then, how do I get the tooltips INTO the forms? Constantly reading the table on each MouseEnter? At the Init for the form (for all controls on the form)? Something else?


Clearly, the tooltips need to live in some table that the user updates, so the essential problem here became how to associate controls on my forms with records in that user table.

The most common suggestion was to have a table where the key was the full name of the object. However, I was unhappy with this suggestion, for a number of reasons: the tooltip would get lost if the object were renamed, copied, or moved to a different container or page. Furthermore, I wanted to provide for the case where objects in a class could keep their tooltips, if desired, instead of requiring a new definition for each use of that class.

The solution then was to assign a unique ID to each control that could have a tooltip.

It turns out that this is much easier to do than thought. A number of people suggested the use of ASELOBJ -- that is, when a form (or class) is open in Forms Designer, the objects in the form can be modified by using ASELOBJ.

The most appropriate solution, below, comes from Tamar. It cycles through all controls in the form (or class), assigning the unique ID, SYS(2015) where appropriate. See below.

A couple of comments:

(1) The only code here that's mine is the Proc at the end (AssignUniqueID)

(2) Forms Designer only allows you to create new properties for the form (or class), but not the controls within the form or class. Thus, you must first create, in your base classes that have tooltips, an empty property for the unique ID.

(3) For my own convenience, I have an On Key Label assignment to invoke this Proc for me when I have a form open.

(4) The remaining problem is to assign the unique IDs for all existing forms is quite easy as well. The following, also from Tamar, almost does the trick:
* With the project open
FOR EACH oFile IN _VFP.ActiveProject.Files
  IF oFile.Type="K" && form
     * Open the form either in the Form Designer
     MODIFY FORM (oFile) NOWAIT
     AssignUniqueControlIDs()
     Keyboard '{Ctrl-W}'
  ENDIF
ENDFOR
Unfortunately, the Ctrl+W doesn't work, so the form does not save.

(5) I have not included of code for editing the tooltips; that's not necessary here.

(6) Nor have I included any code for assigning the tooltips at runtime. The suggestion was to assign them all in the form's INIT; however, since I don't use VFP's native tooltips, but my own variant, I decided to do it differently (at the first MouseEnter for each object) -- the code would be essentially the same as Tamar's DrillControls below.


Here's the code to assign all unique IDs:
Procedure AssignUniqueControlIDs
* Assigns Unique IDs to all objects on this form
* (Used as a builder, called when Form is open in Form Designer)

Local loForm

loForm = GetTarget()
If "O" = Vartype (loForm)
	DrillControls (loForm)
Endif

Return


* Following programs from Tamar Granor
* Modified by Jim Nelson 05/20/2008

*==============================================================================
* Program:				ControlRenamer.PRG
* Purpose:				Main class for Control Renamer Builder
* Copyright:			(c) 2005 Tamar E. Granor, Ph.D.
* Last revision:		05/02/05
* Notes:				You may freely distribute this builder
*                       as long as this header is retained.
* Contact:				tamar@thegranors.com
*==============================================================================

Procedure GetTarget
	* Grab a reference to the top-level control/form
	Local aSelected[1], oTarget, oLast

	If Aselobj(aSelected) = 0
		If Aselobj(aSelected, 1) = 0
			oTarget = .Null.
		Endif
	Endif

	If Vartype(aSelected[1]) = "O"
		oTarget = aSelected[1]
		Do While Upper(oTarget.Parent.BaseClass)<>"FORMSET"
			oLast = oTarget
			oTarget = oTarget.Parent
		Enddo

		* Form class/form or something else? If not a form class
		* need to go back down one level
		If Not Pemstatus(oTarget, "BufferMode", 5)
			* It's not a real form; it's the pseudo-form
			* represented by the Class Designer
			oTarget = oLast
		Endif
	Else
		oTarget = .Null.
	Endif

	Return oTarget

Endproc


Procedure DrillControls(oContainer)
	* Assign property C_UniqueID (unless already assigned for all children)
	* and then repeat for all THEIR children.

	Local Array aControls[1]
	Local nControls, oObject, nControl

	nControls = Amembers(aControls, oContainer, 2)

	For nControl = 1 To nControls

		oObject = Evaluate("oContainer." + aControls[nControl])

		AssignUniqueID (oObject)

		* Drill down
		If Pemstatus(oObject, "Objects", 5)
			DrillControls(oObject)
		Endif

	Endfor

	Return nControls

Endproc


Procedure AssignUniqueID (oObject)
	* assign C_UniqueID unless already assigned
	If Pemstatus (oObject, "h_UniqueID", 5) And Empty (oObject.h_UniqueID)
		oObject.AddProperty( "h_UniqueID", Sys(2015))
	Endif
Endproc
Jim Nelson
Newbury Park, CA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform