Tech Tip: Get cursor position to set Write Area Pro attributes
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: March 30, 2017
In the 4D Write Pro Area, attributes can be set where the mouse cursor is located while using the contextual click to access the menu below:
To set attributes with WP SET ATTRIBUTES requires a range or the Write Pro Area. The following method utility will extract the cursor mouse position. This can later set the attributes at that cursor position with WP get range and WP SET ATTRIBUTES:
// -------------------------------------------------------------------------------- // Name: WP_GET_RANGE_CURSOR_POSITION // Description: Method will get the mouse cursor position in the Write Pro Area. // This can be used in with with WP Get range and WP SET ATTRIBUTES. // // Input: // $1 (POINTER) - Pointer to Write Pro Area // Output: // $0 (LONGINT) - Returning the mouse cursor position // -------------------------------------------------------------------------------- C_POINTER($1;$wrAreaPtr) C_LONGINT($0;$CursorPostion) C_OBJECT($range) $wrAreaPtr:=$1 $range:=WP Get selection($wrAreaPtr->) WP GET ATTRIBUTES($range;"rangeStart";$CursorPostion) //Get actual cursor position $0:=$CursorPostion |
The following example will change the text color from default to red from the mouse cursor position. Here is text before the mouse cursor position:
Putting the following code in a button will get the mouse position and set the attribute to red:
C_LONGINT($CursorPostion) C_OBJECT($objRange) $CursorPostion:=WP_GET_RANGE_CURSOR_POSITION (->WriteProArea) // Setting the attribute to red $objRange:=WP Get range(WriteProArea;$CursorPostion;$CursorPostion) WP SET ATTRIBUTES($objRange;wk text color;"#FF0000") //Red |
Here is the text color attribute set and text has been typed:
See Also: