SAS/AF Subclassing the Textpad Control
This information was originally posted to comp.soft-sys.sas on 11 April 2002.
Robert Matthews wrote:
Richard,
I have an AF screen (Windows 2000/ SAS 8.2) with an external file viewer control that displays text information for a user to review. It works fine, but now the user wants to be able to cut and paste information from the EFV window into another Windows application (e.g. MS Word).
I can't find any way to do this, is it possible to do this? If so, how? I have spent some time this morning looking into writing the same data into a 'text pad control' widget, which seems to have a lot more functionality than the EFV, but I still can't find a simple way for the user to be able to highlight some text and paste it into another application.
This seems like a simple problem, but the solution isn't very apparent. Any thoughts would be greatly appreciated!
Thanks,
Robert...
The following sample code subclasses the Text Pad Control. A new attribute filename is added, as is an override of the _popup() method.
Set the filename to read the contents of a file into the text pad.
The _popup() captures the right click event and presents a menu for copying selected text to the clipboard. Once in the clipboard the text can be pasted somewhere else.
This SCL is not 'complete', you have to add to it to implement the full cut/copy/paste/select all mouse experience. [Note: Ctrl + X, C, V, A work defacto in Windows.]
The same code can be used to extend any af control from which one would want to copy to paste buffer (text entry, combos, etc...). I have other sample code for copying selected cells of a Table Viewer.
Create the following SCL entry and SAVECLASS;SAVE it to create example.subclass.textpadex_c.class. You can then drag
example.subclass.textpadex_c.class from a SAS Explorer window onto a frame at build-time. Set the .filename attribute and TESTAF the frame.
( If you want to use the class over and over, place it in the component palette (by right clicking on the Components window and selecting Add Classes...)
example.subclass.textpadex_cclass.scl
class example.subclass.textpadex_c.class extends sashelp.classes.textpad_c.class; Public Char fileName / (InitialValue="", Editor="Sashelp.Classes.Fileentryeditor.Scl", SetCAM="setcamFileName", Category="Data", Description="Sets the file name to view.") ; setcamFileName: Protected Method attributeValue:Update:Char Return=Num / ( Label="setcamFileName", Description="Invoked when the fileName attribute is changed", ArgDesc1="contains the attribute value", ReturnDesc="returns 0 if successful, >0 if error, <0 if warning") ; declare num rc; * in Text Pad Control, text attribute is an SCL list; rc = clearlist (text); rc = fillist ('file', attributeValue, text); endmethod; _onPopUp: Public Method / ( State = 'O' ) ; declare list menu = { 'Copy', 'Copy All' }; declare num choice rc; declare num startRow startCol endRow endCol i; declare string line; choice = popMenu (menu); if choice ^= 0 then do; if choice = 1 then do; _getMark (startRow, startCol, endRow, endCol); endcol = endcol - 1; end; if choice = 2 then do; startRow = 1; startCol = 1; endRow = listlen (text); endCol = length (getItemC (text,endRow)); end; declare sashelp.classes.pastebuffer_c pb = _new_ sashelp.classes.pastebuffer_c(); declare list selectedText = {}; if startRow = endRow then do; line = getItemC (text, startRow); rc = insertc ( selectedText , substr (line, startCol, endCol-startCol+1) ); end; else do; line = getItemC (text, startRow); rc = insertc ( selectedText , substr (line, startCol) ); do i = startRow+1 to endRow-1; line = getItemC (text, i); rc = insertc (selectedText, line, -1); end; line = getItemC (text, endRow); rc = insertc (selectedText, substr (line, 1, endCol), -1); end; * Assigning .text runs the paste buffer setcamText which places the text in the system clipboard, thus the paste buffer can be _terminated ; pb.text = selectedText; pb._term(); rc = dellist (selectedText); end; rc = dellist (menu); endmethod; endclass;Copyright 2003 Richard A. DeVenezia This page was last updated 14 August 2003.