WNGZWZSC0110(2  OO84#0You must have a sheet open to use this function.? 9??>7v9/)#%Cannot insert; no Cell Range selected96#2Cannot insert; the first range is not a Cell Range?@9?@97 O N NO   ???.+??.+???p Insert Block/OK@Cancel@ @@  H!BINSERT.scz:ok_button = TRUE() INSERT.scz:insert_dir = CTVALUE(3,0)+Right Down@g Shift Cells@J9 9?*?<*?   rowcol last_row last_col act_rows act_cols ok_button insert_dirpresent_sheet new_sheet RIGHT InsertBlock{ InsertBlock() This script was developed by Informix to demonstrate how to design a dialog box and work with the clipboard. This script designs a dialog with a two radio buttons. There is only one function in this file; InsertBlock. Conventions: HyperScript keywords and functions are in all capital letters, user functions are in proper case, and variables are in lower case. Some variables are used as constants (i.e. they are defined and initialized, but are never changed), these always appear in all capital letters. TO USE THIS SCRIPT: To add this function to a menu, add the following to a Startup script: SELECT MENU "~Sheet"; ADD MENUITEM "Insert Block..." COMMAND "GET SCRIPT ""/usr/lpp/Wingz/Examples/Insert.scz""; CALL Insert.scz:InsertBlock(); REMOVE SCRIPT ""Insert.scz"";"; You can then access the function just by going to the "Sheet" menu and selecting the command from the menu. NOTE: Before calling this function or choosing it from the menu, you must select a range of cells to convert. } { Variable List } DEFINE row, col { hold the upper-left corner of the } { selected area } DEFINE last_row, last_col { save the lower-right corner of the } { selected area } DEFINE act_rows, act_cols { save the size of the active sheet by } { saving the number of active rows and } { columns } DEFINE ok_button { a flag that holds the status of the } { OK button on the dialog box } DEFINE insert_dir { a flag that hold the direction the } { new area will be inserted } { 0 will indicate shift down } { 1 will indicate shift to the right } DEFINE present_sheet { save the current sheet name } DEFINE new_sheet { this sheet is used as a temporary } { storage area for the clipboard } { Variables used as Constants } DEFINE RIGHT { constant used to indicate the } { direction the area should be shifted. } CALL InsertBlock() { InsertBlock() This function will insert a blank area into the middle of a sheet. The cells in a marked area are shifted either to the right or down. Any cells in the direction of the shift are also shifted to create the new empty space in the sheet. The user must first select an area and then call this function. This function will then display a dialog box which allows the user to select which direction to shift the marked block to create the new empty space. } FUNCTION InsertBlock() { Check if there is a sheet open. } IF (ISERR(NAME())) MESSAGE "You must have a sheet open to use this function." EXIT SCRIPT END IF RIGHT = 1 { Initialize constants to use with } { the insert_dir flag. } { Determine if a range has been } { selected, and if the first range } { selected is a cell range. } { If not print an appropriate message } { and exit the script. } IF ((NRSELECTIONS() = 0) OR (SELECTIONTYPE(1) <> 1)) { Something failed, } { Determine which condition failed. } IF (NRSELECTIONS() = 0) MESSAGE ("Cannot insert; no Cell Range selected") ELSE MESSAGE ("Cannot insert; the first range is not a Cell Range") END IF EXIT FUNCTION END IF { END IF the check for a valid area } { Check to see if the user has an } { entire row or column selected. } IF ((COLS(SELECTION(1)) = 32768) OR (ROWS(SELECTION(1)) = 32768)) INSERT { Do the system insert and exit } EXIT FUNCTION END IF present_sheet = NAME() { Save the name of the current sheet } { Create a new sheet to use a place } { to store the current clipboard. } NEW WORKSHEET "" LOCATION (20000,20000) (0,0) new_sheet = NAME() { Save the name of the new sheet and } PASTE { put the contents of the clipboard } { into the new sheet. } INVALIDATE ON { Because we turned INVALIDATE ON, any } { changes will not be updated on the } { sheet. When we use the INVALIDATE ON } { command, Wingz will save a list of } { any parts of the screen that SHOULD } { HAVE BEEN repainted but not do the } { actual repainting until the } { INVALIDATE OFF command is encountered.} GO TO WINDOW present_sheet { Go back to the original sheet } row = ROWOF(SELECTION(1)) { Save the coordinates of the } col = COLOF(SELECTION(1)) { selected area. } last_row = row+ROWS(SELECTION(1))-1 last_col = col+COLS(SELECTION(1))-1 SELECT ACTIVE CELLS { Select all cells being used and } act_rows = ROWS(SELECTION(1)) { save the size of the active sheet. } act_cols = COLS(SELECTION(1)) { Reselect the original area. } SELECT RANGE MAKERANGE(col,row,last_col,last_row) { Define the dialog box here. } { Define a dialog box of the specified } { height and width that is centered on } { the screen. } { The (-1,-1) means center this box on } { the screen. The second set of coord- } { inates specify the size of the box. } NEW MODAL DIALOG BOX AT (-1,-1) (2.5inch,1.5inch) NAME DIALOG BOX "Insert Block" { Add the two buttons, the OK and } { CANCEL buttons in the specified } { rectangle. These will be controls } { one and two. } { CONTROLS 1 and 2 } ADD PUSH BUTTON "OK@","Cancel@" AT (0.2inch,1inch) (2.3inch,1.4inch) DIALOG CANCEL PUSH BUTTON { Specify an action for the CANCEL } { button, which is the current control } { because it was the last one added. } SELECT CONTROL 1 { Select the OK button. It was the } { first control added so it is } { has the control number of 1. } DIALOG DEFAULT PUSH BUTTON { Make the OK button the default } { control, which means it will have a } { wider border. } { Specify what should happen when the } { OK button is pressed: } { -set the OK flag. } { -save the current value of the } { the radio button control. } SCRIPT "INSERT.scz:ok_button = TRUE() "& "INSERT.scz:insert_dir = CTVALUE(3,0)" { CONTROL 3 } { Add two radio buttons so the user can } { choose which direction to insert the } { new area. } ADD RADIO BUTTON "Right ","Down" AT (0.1inch,0.1inch) (2.4inch,0.8inch) SHOW CONTROL NAME "Shift Cells@" OUTLINE 2 BORDER USE DIALOG BOX { Display the box. } IF (ok_button = TRUE()) { If the user pressed the OK button } { process the insert, otherwise skip it.} IF (insert_dir = RIGHT) { Shift cells to the right. } { Select the first range. } { It is the area to the right of the } { selected area that goes to the last } { active column of the sheet and down } { as far as the selected range's lowest } { row. } SELECT RANGE MAKERANGE(col,row,act_cols,last_row) CUT { Cut the first area out } { Create the cell to paste the area } { into that was cut from the the first } { range. } SELECT RANGE MAKECELL(last_col+1,row) PASTE { Put the cut part of the sheet here. } ELSE { Shift the cells down. } { Select the first range. } { It is the area below the selected } { area that goes to the last active row } { of the sheet and to the right as far } { as the selected range's rightmost } { column. } SELECT RANGE MAKERANGE(col,row,last_col,act_rows) CUT { Cut the first area out of the sheet. } { Create the range to paste the area } { into that was cut from the the first } { range. } SELECT RANGE MAKECELL(col,last_row+1) PASTE { Put the cut part of the sheet here. } END IF { END IF insert_dir = RIGHT } END IF { END IF ok_button = TRUE() } { At this point, regardless of whether } { the user CANCELED the insert from the } { dialog box or not, we need to restore } { the original clipboard from the sheet } { which we created at the beginning. } GO TO WINDOW NEW_SHEET { Move to the temporary sheet. } COPY { Copy it to the clipboard. } CLOSE NOW { Close the temporary sheet. } SELECT RANGE MAKERANGE(col,row,last_col,last_row) INVALIDATE OFF { Set the INVALIDATE flag off. This } { will cause Wingz to repaint the } { objects which have changed since } { INVALIDATE was turned on. } END FUNCTION