|
Formatting |
Top Previous Next |
|
Version 1.08 adds Numeric Display Formatting and Format Override so formatting can be accomplished at the cell level in addition to the previous column and row formatting.
A) Numeric Display Formatting
The row and column formatting of previous versions has been expanded to include enhanced display formatting of numeric fields using the Powerbasic FORMAT$ function. There are slots for 20 mask in MLG with the first 5 being predefined (though they can be written over if necessary. The predefined masks are as follows:
'Number Format Overriding predefined masks %MLG_NOFORMAT = 1 '"" %MLG_NODECIMAL = 2 '"#," %MLG_COMMAS = 3 '"#," %MLG_CURRENCY = 4 '"$* #,.00" %MLG_PERCENT = 5 '"0.0%
As explained in the Structure and Equates page, the programmers simply use the %MLG_SETNUMFORMATSTR and assign a mask to a slot such as:
SendMessage hGrid, %MLG_SETNUMFORMATSTR ,6,"0000.00"
and then assign 6 to the PrintUsing field of the of the RowColDataType structure. Using the %MLG_SETROWFORMAT message will then assign the mask to the desire row or column and MLG will display the formatted number IF this same row or column if the FormatNumber field is non zero.
Display Mask Definitions (much as per the Powerbasic help file) 1)Empty string [null string] No formatting takes place. 2) 0 [zero] Digit placeholder. MLG will insert a digit or 0 in that position. If there is a digit in num_expression in the position where the 0 appears in the format string, return that digit. Otherwise, return "0". If the number being formatted has fewer digits than there are zeros (on either side of the decimal point) in the format expression, leading or trailing zeros are added. If the number has more digits to the right of the decimal point than there are zeros to the right of the decimal point in the format expression, the number is rounded to as many decimal places as there are zeros in the mask. If the number has more digits to the left of the decimal point than there are zeros to the left of the decimal point in the format expression, the extra digits are displayed without truncation. If the numeric value is negative, the negation symbol will be treated as a decimal digit. Therefore, care should be exercised when displaying negative values with this placeholder style. In such cases, it is recommended that multiple masks be used. ' Numeric padded with leading zero characters MASK = "00000000" OUTPUT = 00000999 (if 999 is in the cell) 3) # [Number symbol] Digit placeholder. If there is a digit for this position, MLG replaces this placeholder with a digit, nothing, or a user-specified character. Unlike the 0 digit placeholder, if the numeric value has the fewer digits than there are # characters on either side of the decimal placeholder, MLG will either: a) Omit this character position from the final formatted string; or Substitute a user-specified replacement character if one has been defined (see the asterisk (*) character for more information). To specify leading spaces, prefix the mask with "* " (asterisk and a space character). For example: ' No leading spaces and trailing spaces MASK = "####.###" OUTPUT = 0.75 (cell has .75) MLG may also return a string that is larger than the number of characters in the mask: MASK = "#.#" OUTPUT = 999999.9 (cell has 9999.999) 4) . [period] Decimal placeholder. Determines the position of the decimal point. If any numeric field is specified to the left of the decimal point, at least one digit will always result, even if only a zero. The zero is not considered to be a "leading" zero if it is the only digit to the left of the decimal. Placing more than one period character in the fmt$ string will produce undefined results. 5) %[percent] Percentage placeholder. Multiplies cell by 100, and adds % MASK = "0.0%" OUTPUT = 20.0% (cell has .2 in it) 6) , [comma] Thousand separator. Used to separate thousands from hundreds within a number that has four or more digits to the left of the decimal point. In order to be recognized as a format character, the comma must be placed immediately after a digit placeholder character (also see Restrictions below). MASK = "#," OUTPUT = 1,234,567 (if cell has 1234567) MASK = "#,.00" OUTPUT = 12,345.00 (if cell has 12345) MASK = "$00,000.00" OUTPUT = $01,212.46 (if cell has 1212.46) 7) *x [asterisk] Digit placeholder and fill-character. Instructs PowerBASIC to insert a digit or character "x" in that position. If there is a digit in num_expression at the position where the * appears in the format string, that digit is used; otherwise, the "x" character is used (where "x" represents your own choice of character). The *x specifier acts as two digit (#) fields. MASK = "$**####,.00" OUTPUT = $**9,999.90 (if cell has 9999.9) MASK = "$*=###0,.00#" OUTPUT = $=====0.00= (if cell has 0) MASK = "$* ####0,.00" OUTPUT = $ 0.00 (if cell has 0) 8) E- e- E+ e+ [e] Scientific format. MLG will use scientific notation in the formatted output. Use E- or e- to place a minus sign in front of negative exponents. Use E+ or e+ to place a minus sign in front of negative exponents and a plus sign in front of non-negative exponents. In order to be recognized as a format sequence, the E-, e-, E+, or e+ must be placed between two digit placeholder characters. For example: MASK = "0.0E-##" OUTPUT = 1.0E2 (if cell has 99.999) 9) " [double-quote] Quoted string. PowerBASIC treats all characters up to the next quotation mark as-is, without interpreting them as digit placeholders or format characters. Also see backslash. For example: MASK = """Total ""#" OUTPUT = Total 999 (if cell has 999 in it) 10) \x [backslash] Escaped character prefix. MLG treats the character "x" immediately following the backslash (\) as a literal character rather than a digit placeholder or a formatting character. Many characters in a mask have a special meaning and cannot be used as literal characters unless they are preceded by a backslash. The backslash itself is not copied. To display a backslash, use two backslashes (\\). To display a literal double-quote, use two double-quote characters. To simplify the mask string for common numeric formats, MLG permits the dollar symbol, the left and right parenthesis symbols, the plus and minus symbols, and the space character ("$()+- ") to pass through from the mask string into the formatted output string, without requiring an escape (\) prefix character. MASK = "(* 0\%)" OUTPUT = (23%) (if 23 is in the cell) MASK = "#\#" OUTPUT = 99999# (if 99999 is in the cell)
B) Date Formatting (Improved in Version 2.06)
There has been a change in how MLG handles dates. In versions previous to this version, if a column had a date format specified, then upon typing a date into the cell (within the date column) MLG would force the typed characters into a legal date of the format specified. The date would then be displayed on the screen exactly as stored in the element of the string array.
In 2.06 cell that are formatted as date type now also set the legal date typed with the %MLG_TYPE_USING to one of the Date Formats below such as :
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX ,MAKLNG(14,3),MAKLNG(%MLG_TYPE_CELLTYPE,%MLG_TYPE_DATE) SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX ,MAKLNG(14,3),MAKLNG(%MLG_TYPE_USING,1)
'Date Formats %MMDDYYYY = 1 %MMDDYYYYH = 2 'Dot instead of a slash %MMDDYYYYL = 3 'Line instead of a slash %DDMMYYYY = 4 %DDMMYYYYH = 5 'Dot instead of a slash %DDMMYYYYL = 6 'Line instead of a slash %MMYYYY = 7 %MMYYYYH = 8 'Dot instead of a slash %MMYYYYL = 9 'Line instead of a slash %YYYYMMDD = 10 %YYYYMMDDH = 11 'Dot instead of a slash %YYYYMMDDL = 12 'Line instead of a slash %YYYYMM = 13 %YYYYMMH = 14 'Dot instead of a slash %YYYYMML = 15 'Line instead of a slash
In MLG version 2.06 can now associate an output format for each date format listed above with the message MLG_SETDATEFORMATSTR. This is at the cell formatting level only. The example below associates an output format with Date Format #1
zBuf = "ddd',' MMM dd yy" 'Wed, Aug 31 94 SendMessage hGrid1 ,%MLG_SETDATEFORMATSTR ,1,VARPTR(zBuf)
MLG uses the Window API GetDateFormat to do the output formatting. In the above example the cell actually contains 08/31/1994 but Wed, Aug 31 94 is displayed.
GetDateFormat() Value Description D Day of month as digits with no leading zero for single-digit days. Dd Day of month as digits with leading zero for single-digit days. Ddd Day of week as a three-letter abbreviation. The function uses the LOCALE_SABBREVDAYNAME value associated with the specified locale. Dddd Day of week as its full name. The function uses the LOCALE_SDAYNAME value associated with the specified locale. M Month as digits with no leading zero for single-digit months. MM Month as digits with leading zero for single-digit months. 'MMM Month as a three-letter abbreviation. The function uses the LOCALE_SABBREVMONTHNAME value associated with the specified locale. MMMM Month as its full name. The function uses the LOCALE_SMONTHNAME value associated with the specified locale. y Year as last two digits, with a leading zero for years less than 10. The same format as "yy." yy Year as last two digits, with a leading zero for years less than 10. yyyy Year represented by full four digits. gg Period/era string. The function uses the CAL_SERASTRING value associated with the specified locale. This element is ignored if the date to be formatted does not have an associated era or period string.
'For example, to get the date string '"Wed, Aug 31 94" 'use the following picture string: '"ddd',' MMM dd yy"
C) Merged Cells (New in Version 2.06)
MLG 2.06 allows the creation of Merged Cells which can be used as labels or informational text boxes. The merged cells implementation is crude in this version of MLG and hopefully will be improved in later versions of MLG. The below example merges cells A1 thru C1 (in Excel speak) and the merged group take on the attributes of A1. Since merged cells are used a labels, number and date cell formatting are not supported.
SendMessage hGrid, %MLG_SETMERGECELLS, MAKLNG(1,1),MAKLNG(1,3)
To cancel the merged effect, repeat the first cell for both parameters.
SendMessage hGrid, %MLG_SETMERGECELLS, MAKLNG(1,1),MAKLNG(1,1)
All the cells in the merged group are locked and can not be selected. The Merged Cells are the first of MLG Objects and actually floats above the grid. Other objects may be added in the future.
D) Format Overriding (Improved in Version 2.06)
MLG now allows the programming to assign an additional array (of 32 bit values) over the existing string array (which holds the cell's contents). By creating a Format Override Array, any cell within that array can be defined to have its individual Font display (normal,bold, or italics), RGB Colors, Border (top,line,bottom, or right heavy lines), and Number and Date formatting,Comboboxes , Checkboxes and User Buttons The maximum size of the override array is the currently sized sheet (up to 65,000 rows). Only one Format Override Array can be defined per sheet and will be resized dynamically upon changes in the dimension of the sheet.
New to version 2.06 is the ability to set a row or column header array element with default cell formatting for that column or row. Such as the following for column 3.
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX ,MAKLNG(0,3),MAKLNG(%MLG_TYPE_USING,1)
Use the z1 switch when creating the grid or use the message SendMessage hGrid ,%MLG_CREATEFORMATOVERRIDE,0,0
The sheet has to be current (selected) while the creating a an format override array.
TYPE FormatOverRide CellFont AS BYTE '16 fonts in 2.06 bits 5,6,7,8 are now flags CellType AS BYTE 'bits 1 2 3 is cell type 'bit 4 is writelock 'bits 5 6 7 8 list pointers 1 to 15 'Cell Type 0 automatic (text) = Justify Case 'Cell Type 1 text with wordwrap = Justify Case DT_WORDBREAK 'Cell Type 2 checkbox = not used 'Cell Type 3 combo static = 1 to 15 lists 'Cell Type 4 combo edit = 1 to 15 lists 'Cell Type 5 user button = not used 'Cell Type 6 date = 1 to 15 date formats 'Cell Type 7 number = 1 to 15 number formats CellFormatExtra AS BYTE 'bit 1 2 3 4 border bit 5 6 case bit 7 8 justify CellColor AS BYTE '16 Background colors, 16 text colors END TYPE
For information, internally the cell formatting info is retrieve as follow:
CellFont = (fo(myrow,mycol).CellFont AND &B00001111) 'Changed in 2.06 CellFlags = (fo(myrow,mycol).CellFont AND &B11110000)\16 'Changed in 2.06
CellCT = (fo(myrow,mycol).CellType AND &B11100000)\32 CellWriteLock = (fo(myrow,mycol).CellType AND &B00010000)\16 CellUsing = (fo(myrow,mycol).CellType AND &B00001111)
CellCase = (fo(myrow,mycol).CellFormatExtra AND &B00001100)\4 CellJust = (fo(myrow,mycol).CellFormatExtra AND &B00000011) CellBorder = (fo(myrow,mycol).CellFormatExtra AND &B11110000)\16
CellBkGndColor = (fo(myrow,mycol).CellColor AND &B00001111) CellForeGndColor = (fo(myrow,mycol).CellColor AND &B11110000)\16
Format Override Items %MLG_TYPE_CELLTYPE = 0 %MLG_TYPE_WRITELOCK = 1 %MLG_TYPE_USING = 2 %MLG_TYPE_FONT = 3 %MLG_TYPE_BKGCOLOR = 4 %MLG_TYPE_FGCOLOR = 5 %MLG_TYPE_BORDER = 6 %MLG_TYPE_CASE = 7 %MLG_TYPE_JUST = 8
FONTS (Changed in 2.06)
The number of fonts available in MLG has been reduced from 256 to 16 in version 2.06 to make room for bit information in the 32 bit cell format array element. Fonts are now made with a new message %MLG_MAKENEWFONT and the older message %MLG_SETUSERCELLFONT (which also created fonts) has been deprecated.
The %MLG_MAKENEWFONT message comes in 2 forms 1) fonts in font slot 7 to 15 and 2) MLG system fonts in slots 0 to 6.
To make a font in slot 7 to 15, generate a font using the Windows API and set that desired font slot to the font just created as shown below. As a note, all the MLG system fonts use the 0-fontheight format.
LOCAL MyFont AS LONG LOCAL zStr AS ASCIIZ * 64
Myfont = CreateFont(0 - 24, 0, 0, 0, %FW_NORMAL, 0, 0, 0, _ %ANSI_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _ %DEFAULT_QUALITY, 0, "Arial")
SendMessage hGrid1 ,%MLG_MAKENEWFONT ,7,MyFont SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX, MAKLNG(6,3),MAKLNG(%MLG_TYPE_FONT,7)
'--------------------------------------------------------- To change the system font, use the second form of the %MLG_MAKENEWFONT message. The lParam is the face name of the font. The wParam has a lot of info packed into it. The low word should be set to zero (for 0 slot), the high word should have the font height in the low byte and font family in the high byte. The below example sets the MLG system font to Tahoma 12.
zStr = "Tahoma" SendMessage hGrid1 ,%MLG_MAKENEWFONT ,MAK(LONG,0,MAK(WORD,12,0)),VARPTR(zstr) SendMessage hGrid1,%MLG_REFRESH,0,0
As a note, the Tab Fonts are not altered by the %MLG_MAKENEWFONT message.
MLG System Fonts in Slots 0 to 6 %MLGSYSFONTNORM = 0 %MLGSYSFONTBOLD = 1 %MLGSYSFONTITAL = 2 %MLGSYSFONTTABNORM = 3 %MLGSYSFONTTABBOLD = 4 %MLGSYSFONTNORMVERT = 5 %MLGSYSFONTBOLDVERT = 6
CELL TYPES Depending on the cell type, MLG will display cell data differently. Below are the 8 cell types and an example of set cell row 6 column 6 to a drawing cell (ie put a bitmap in the cell)
'Cell Types %MLG_TYPE_EDIT = 0 'Cell,Row,Col DEFAULT %MLG_TYPE_DRAW = 1 'Cell Only %MLG_TYPE_CHECKBOX = 2 'Cell,Row,Col %MLG_TYPE_COMBOSTATIC = 3 'Cell,Row,Col %MLG_TYPE_COMBOEDIT = 4 'Cell,Row,Col %MLG_TYPE_USERBUTTON = 5 'Cell Only %MLG_TYPE_DATE = 6 'Cell Only %MLG_TYPE_NUMBER = 7 'Cell Only
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX ,MAKLNG(6,5),MAKLNG _ (%MLG_TYPE_CELLTYPE,%MLG_TYPE_DRAW)
WRITELOCK
Write protects a given cell.
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX ,MAKLNG(6,5),MAKLNG _ (%MLG_TYPE_WRITELOCK,1)
CELLUSING Depending on the cell type, the CellUsing field is extra info for that cell type
CellType %MLG_TYPE_EDIT Currently only used to display a vertical font in a cell.
%MLGSYSFONTNORMVERT = 5 %MLGSYSFONTBOLDVERT = 6
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(6,1),MAKLNG(%MLG_TYPE_USING,%MLGSYSFONTNORMVERT) SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(6,2),MAKLNG(%MLG_TYPE_USING,%MLGSYSFONTBOLDVERT)
CellType %MLG_TYPE_DRAW The purpose is to hold a bitmap in one of 15 slots and then assign a cell that slot for automatically displaying the bitmap
SendMessage hGrid1 ,%MLG_REGISTERBITMAP ,1,LoadBitmap(GetModuleHandle(BYVAL %NULL), "BM1") SendMessage hGrid1 ,%MLG_ASSIGNCELLBITMAP ,MAKLNG(7,3),1
Use a Drawing Callback if more than 15 bitmaps are needed.
CellType %MLG_TYPE_COMBOSTATIC, %MLG_TYPE_COMBOEDIT The purpose is to hold a comma delimited string to fill a combobox in one of 15 slots and then assign a cell that slot for displaying that data for a combo
Use a Listbox Callback if more than 15 lists are needed.
CellType %MLG_TYPE_DATE
Dates are displayed in one of the following formats. These 15 formats are hardwired.
'Date Formats %MMDDYYYY = 1 %MMDDYYYYH = 2 'Dot instead of a slash %MMDDYYYYL = 3 'Line instead of a slash %DDMMYYYY = 4 %DDMMYYYYH = 5 'Dot instead of a slash %DDMMYYYYL = 6 'Line instead of a slash %MMYYYY = 7 %MMYYYYH = 8 'Dot instead of a slash %MMYYYYL = 9 'Line instead of a slash %YYYYMMDD = 10 %YYYYMMDDH = 11 'Dot instead of a slash %YYYYMMDDL = 12 'Line instead of a slash %YYYYMM = 13 %YYYYMMH = 14 'Dot instead of a slash %YYYYMML = 15 'Line instead of a slash
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(6,1),MAKLNG(%MLG_TYPE_USING,11)
In MLG version 2.06 can now associate an output format for each date format listed above with the message MLG_SETDATEFORMATSTR. This is at the cell formatting level only. The example below associates an output format with Date Format #1
zBuf = "ddd',' MMM dd yy" 'Wed, Aug 31 94 SendMessage hGrid1 ,%MLG_SETDATEFORMATSTR ,1,VARPTR(zBuf)
MLG uses the Window API GetDateFormat to do the output formatting. In the above example the cell actually contains 08/31/1994 but Wed, Aug 31 94 is displayed
Use a Date Callback if the 15 built in formats are not adequate.
CellType %MLG_TYPE_NUMBER Determined how a number will be displayed using. The first 5 formats are hardwired but the programmer is free to set the next 10 PrintUsing mask with the message:
%MLG_SETNUMFORMATSTR
'Built in Number Formats NumberFormatString(1)="" NumberFormatString(2)="#" NumberFormatString(3)="#," NumberFormatString(4)="$* #,.00" NumberFormatString(5)="0.0%"
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(6,1),MAKLNG(%MLG_TYPE_USING,4) 'For $* #,.00 format
Use a Number Callback if more than 15 number are needed.
CELLCASE
Control the displayed case of the cell string's content
'Case Formats %MLG_NOCASE = 0 %MLG_UCASE = 1 %MLG_LCASE = 2 %MLG_MCASE = 3
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(6,1),MAKLNG(%MLG_TYPE_CASE,%MLG_UCASE)
CELLJUST Control the displayed justifcation of the cell string's content
'Justification formats %MLG_JUST_LEFT = 0 %MLG_JUST_RIGHT = 1 %MLG_JUST_CENTER = 2 %MLG_JUST_WORDWRAP = 3
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(7,5),MAKLNG(%MLG_TYPE_JUST,%MLG_JUST_WORDWRAP)
CELLBORDER Control the display of a border around a cell by OR'ing the sides of the cell if desired
'Format Override Borders %MLG_TOP = 8 %MLG_LEFT = 4 %MLG_BOTTOM = 2 %MLG_RIGHT = 1
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(7,5),MAKLNG(%MLG_TYPE_BORDER,%MLG_TOP OR %MLG_BOTTOM)
The message %MLG_SETMULTICELLBORDER is useful in enclosing a group of cells in a border
CELLBKGNDCOLOR Set the background color of a cell. The 16 slots are prefilled with the following colors
'CellColors %CELLCOLORDEFAULTTEXTBLACK = 0 %CELLCOLORDEFAULTBKGNDWHITE = 0 'Colors for the background only - when setting text colors black and white are reversed. %CELLCOLORWHITE = 0 %CELLCOLORBLACK = 1 'Same for Text and Background %CELLCOLORRED = 2 %CELLCOLORSALMON = 3 %CELLCOLORGREEN = 4 %CELLCOLORLIGHTGREEN = 5 %CELLCOLORBLUE = 6 %CELLCOLORLIGHTBLUE = 7 %CELLCOLORMAGENTA = 8 %CELLCOLORDARKMAGENTA = 9 %CELLCOLORCYAN = 10 %CELLCOLORAQUAMARINE = 11 %CELLCOLORKHAKI = 12 %CELLCOLORBROWN = 13 %CELLCOLORYELLOW = 14 %CELLCOLORORANGE = 15
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(8,2),MAKLNG(%MLG_TYPE_BKGCOLOR,%CELLCOLORYELLOW)
A slot can have another RGB color assigned using the message %MLG_SETBKGNDCELLCOLOR. Slot zero is reserved and is the default.
CELLFOREGNDCOLOR
Mirrors the CellBkGndColor above for the text color except that the default color is set to the color black.
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX _ ,MAKLNG(8,2),MAKLNG(%MLG_TYPE_FGCOLOR,%CELLCOLORRED)
A slot can have another RGB color assigned using the message %MLG_SETTEXTCELLCOLOR. Slot zero is reserved and is the default.
FORMATTING MENU (New in 2.06)
The formatting dialog box has been deprecated and replaced with a formatting menu. To activate the ability of the user to this menu you need to toggle the showformatmenu attribute. Once activated, by HOLDING DOWN THE CONTROL KEY and right clicking the menu, the below context menu drops drop and a submenu item can be chosen. The selection will be applied to the single selected cell or the selected cell block.
SendMessage hGrid1 ,%MLG_ALTERATTRIBUTE ,%MLG_SHOWFORMATMENU,1 'RClickFormatMenu activate
The CellType submenu can be altered with the %MLG_SETFOMATMENUDATENUMITEMS message. The wParam of the message expect a zero terminated string the describes the five number formats (1 to 15 for each of the 5 number slots) and four date formats (1 to 15 for each of the 4 date slots). In this example the date output format string is also set for the first date slot.
szBuffer = "ddd MM/dd/yyyy" SendMessage hGrid1, %MLG_SETDATEFORMATSTR,1, VARPTR(szBuffer) szBuffer = "1,2,3,4,5,1,2,3,4" SendMessage hGrid1, %MLG_SETFOMATMENUDATENUMITEMS,VARPTR(szBuffer),0 SendMessage hGrid1 ,%MLG_ALTERATTRIBUTE ,%MLG_SHOWFORMATMENU,1 'RClickFormatMenu
D) Formatting Callbacks (New in Version 2.00)
Overview New to MLG version 2.00 are callbacks which the programmer can control what is written back to the grid if the grid was set up with the z1 switch upon creation or the format override was subsequently setup. The callbacks do not disturb the string data stored in cell but only what is displayed on the screen.
Drawing Callback
If an individual cell is set to a %MLG_TYPE_DRAW then the programmer has the ability to take over drawing into a cell and displaying bitmaps into that cell. That is accomplished with the following message which sets cell row=6 and column = 3 as a draw type cell:
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX,MAKLNG(6,3) _ ,MAKLNG(%MLG_TYPE_CELLTYPE,%MLG_TYPE_DRAW)
The programmer must set register a drawing callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_DRAWCALLBACK,CODEPTR(DrawCallback)
Note that a standard Windows API callback is used as a callback template
CELLTYPE = %MLG_TYPE_DRAW CBMSG = Pointer to a string buffer that can be written back to the cell if desired CBWPARAM = The rectangle of the cell to be drawn to CBLPARAM = Row and Column of the cell to be drawn to.
CALLBACK FUNCTION DrawCallBack() LOCAL MyRow,MyCol,MySize,CurrentSheet AS LONG LOCAL DrawRect AS RECT LOCAL hDC,RecPtr AS DWORD
MyRow=LOWRD(CBLPARAM) MyCol=HIWRD(CBLPARAM) hDC=SendMessage(CBHNDL,%MLG_GETGRIDDC,0,0)
RectPtr=VARPTR(DrawRect) MySize=SIZEOF(DrawRect) CopyMemory RectPtr,CBWPARAM,MySize
CurrentSheet = SendMessage(CBHNDL,%MLG_GETSHEETINFO,%MLG_SHEET_GETCURRENT,0)
'Do Drawing in the cell here IF MyRow = 6 AND MyCol=3 AND CurrentSheet = 1 THEN
Drawing Commands using hDC and the DrawRect as a bounding box
'Write something back to the cell MyStr = "SAMPLE" MyStrPtr = VARPTR(MyStr) CopyMemory CBMSG,MyStrPtr,%MLG_MAXCELLLEN
END IF
END FUNCTION
Formula Callback This gives the programmer the ability for the end user to run pre set macro by entering in first an equal sign then a macro are formula that the programmer can interpret.
The programmer must set register a drawing callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_FORMULACALLBACK,CODEPTR(MacroCallback)
Note that a standard Windows API callback is used as a callback template
CBMSG = Not used CBWPARAM = Pointer to a string buffer that can be written back to and get data from CBLPARAM = Row and Column of the cell to be drawn to.
CALLBACK FUNCTION MacroCallBack() LOCAL MyRow,MyCol AS LONG LOCAL MyStr AS STRING * %MLG_MAXCELLLEN LOCAL MyStrPtr,a,DimRows,DimCols AS LONG LOCAL InputString as string
MyStrPtr = VARPTR(MyStr) CopyMemory MyStrPtr,CBWPARAM,%MLG_MAXCELLLEN InputString = MID$(TRIM$(MyStr),2) 'get past the equal siqn
MyRow=LOWRD(CBLPARAM) 'May be handy to know MyCol=HIWRD(CBLPARAM) 'May be handy to know
a=SendMessage(CBHNDL,%MLG_GETARRAYPTR,VARPTR(DimRows),VARPTR(DimCols)) DIM GridData(DimRows,DimCols) AS STRING AT a
IF InputString = "PostAnnualSales" THEN 'Perhaps use a parser here and get fancy MyStr = STR$(VAL(GridData(1,1) + VAL(GridData(2,1)) CopyMemory CBWPARAM,MyStrPtr,%MLG_MAXCELLLEN END IF
END FUNCTION
Number Callback If an individual cell is set to a %MLG_TYPE_NUMBER then the programmer has the ability to take over drawing into a cell and displaying numbers as they wish or if the 15 slots of formatting is not enough. That is accomplished with the following message which sets cell row=6 and column = 3 as a number type cell:
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX,MAKLNG(6,3) _ ,MAKLNG(%MLG_TYPE_CELLTYPE,%MLG_TYPE_NUMBER)
The programmer must set register a drawing callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_NUMBERCALLBACK,CODEPTR(NumberCallback)
Note that a standard Windows API callback is used as a callback template
CELLTYPE = %MLG_TYPE_NUMBER CBMSG = Not used CBWPARAM = Pointer to a string buffer that can be written back to and get data from CBLPARAM = Row and Column of the cell to be drawn to.
CALLBACK FUNCTION NumberCallBack() LOCAL MyRow,MyCol AS LONG LOCAL MyStr AS STRING * %MLG_MAXCELLLEN LOCAL MyStrPtr, CurrentSheet AS LONG LOCAL InputString as string
MyStrPtr = VARPTR(MyStr) CopyMemory MyStrPtr,CBWPARAM,%MLG_MAXCELLLEN InputString = TRIM$(MyStr)
MyRow=LOWRD(CBLPARAM) MyCol=HIWRD(CBLPARAM)
CurrentSheet = SendMessage(CBHNDL,%MLG_GETSHEETINFO,%MLG_SHEET_GETCURRENT,0)
'Do Drawing in the cell here IF MyRow = 6 AND MyCol=3 AND CurrentSheet = 1 THEN
MyStr = Some type of formatting with InputString CopyMemory CBWPARAM,MyStrPtr,%MLG_MAXCELLLEN
END IF
END FUNCTION
Listbox Callback If an individual cell is set to a %MLG_TYPE_COMBOSTATIC or %MLG_TYPE_COMBOEDIT then the programmer has the ability to insert options into a combo as desired or if the 15 slots of formatting is not enough. That is accomplished with the following message which sets cell row=6 and column = 3 as a number type cell:
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX,MAKLNG(6,3) _ ,MAKLNG(%MLG_TYPE_CELLTYPE,%MLG_TYPE_COMBOSTATIC)
The programmer must set register a listbox callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_LISTBOXCALLBACK,CODEPTR(ListboxCallback)
Note that a standard Windows API callback is used as a callback template
CELLTYPE = %MLG_TYPE_COMBOSTATIC or %MLG_TYPE_COMBOEDIT CBMSG =Not used CBWPARAM = Date Slot 1 to 15 'May be useful CBLPARAM = Row and Column of the cell with the listbox.
****************************************** It is up to the programmer to set grid element 0,0 to the desired comma delimited string. This is where the listbox will be looking to get it data to fill itself. ******************************************
CALLBACK FUNCTION ListboxCallBack() LOCAL MyRow,MyCol,DimCols,DimRows,a AS LONG LOCAL CurrentSheet ,MySlot AS LONG
MyRow=LOWRD(CBLPARAM) MyCol=HIWRD(CBLPARAM)
CurrentSheet = SendMessage(CBHNDL,%MLG_GETSHEETINFO,%MLG_SHEET_GETCURRENT,0)
MySlot = CBWPARAM 'May be useful
a=SendMessage(CBHNDL,%MLG_GETARRAYPTR,VARPTR(DimRows),VARPTR(DimCols)) DIM GridData(DimRows,DimCols) AS STRING AT a
'Insert the list string IF MyRow = 6 AND MyCol=3 AND CurrentSheet = 1 THEN
GridData(0,0)= "First Option,Second Option"
END IF
END FUNCTION
Date Callback If an individual cell is set to a %MLG_TYPE_DATE then the programmer has the ability to take over drawing into a cell and displaying numbers as they wish or if the 15 slots of formatting is not enough. That is accomplished with the following message which sets cell row=6 and column = 3 as a number type cell:
SendMessage hGrid1 ,%MLG_SETFORMATOVERRIDEEX,MAKLNG(6,3) _ ,MAKLNG(%MLG_TYPE_CELLTYPE,%MLG_TYPE_DATE)
The programmer must set register a drawing callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_DATECALLBACK,CODEPTR(DateCallback)
Note that a standard Windows API callback is used as a callback template
CELLTYPE = %MLG_TYPE_DATE CBMSG = Date Slot 1 to 15 'May be useful CBWPARAM = Pointer to a string buffer that can be written back to and get data from CBLPARAM = Row and Column of the cell to be drawn to.
CALLBACK FUNCTION DateCallBack() LOCAL MyRow,MyCol AS LONG LOCAL MyStr AS STRING * %MLG_MAXCELLLEN LOCAL MyStrPtr, CurrentSheet ,MySlot AS LONG LOCAL InputString as string
MyStrPtr = VARPTR(MyStr) CopyMemory MyStrPtr,CBWPARAM,%MLG_MAXCELLLEN InputString = TRIM$(MyStr)
MyRow=LOWRD(CBLPARAM) MyCol=HIWRD(CBLPARAM)
CurrentSheet = SendMessage(CBHNDL,%MLG_GETSHEETINFO,%MLG_SHEET_GETCURRENT,0)
MySlot = CBMSG
'Do Date Formatting in the cell here IFMyRow = 6 AND MyCol=3 AND CurrentSheet = 1 THEN
IF MySlot = 5 THEN Something MyStr = Some type of formatting with Date InputString (is in default format) CopyMemory CBWPARAM,MyStrPtr,%MLG_MAXCELLLEN
END IF
END FUNCTION
Sheet Type Callback
This option is extreme. It give the programmer full control of drawing on to a sheet. Perhaps it could be useful to generate a chart on the data in a different sheet. I will leave this option to the programmer's imagination. The sheet type of a sheet must be set to a positive number to identify the sheet.
SendMessage hGrid1 ,%MLG_ALTERATTRIBUTE ,%MLG_SETMYSHEETTYPE,3 'SheetType
The programmer must set register a sheettype callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_SHEETTYPECALLBACK,CODEPTR(SheetCallback)
Note that a standard Windows API callback is used as a callback template
Probably advisable to hide the headers SendMessage hGrid1 ,%MLG_SETCOLWIDTH ,0,0 SendMessage hGrid1 ,%MLG_SETROWHEIGHT ,0,0
And hide the splitters SendMessage hGrid1 ,%MLG_ALTERATTRIBUTE ,%MLG_SHOWTHESPLITTERS,1 'No Splitters
It may be nice to keep the scrollbars you can scroll around so the chart (or whatever). Dimension the sheet to maybe 100,100 and then be polling scroll changes and getting TOPROW and LEFTCOL values you can move your picture or chart around.
CBMSG = Not used CBWPARAM = SheetType CBLPARAM = Not Used
CALLBACK FUNCTION SheetCallBack() LOCAL hDC,CurrentSheet,SheetType AS LONG LOCAL rc AS RECT LOCAL TopRow,LeftCol AS LONG
SheetType = CBWPARAM hDC=SendMessage(CBHNDL,%MLG_GETGRIDDC,0,0) CurrentSheet = SendMessage(CBHNDL,%MLG_GETSHEETINFO,%MLG_SHEET_GETCURRENT,0) 'Check the scrollbars TopRow=SendMessage(CBHNDL,%MLG_GETTOPROW,0,0) LeftCol=SendMessage(CBHNDL,%MLG_GETLEFTCOL,0,0)
IF SheetType = 3 THEN 'Fill with desired background brush SelectObject(hDC, GetStockObject(%WHITE_BRUSH)) SelectObject(hDC, GetStockObject(%BLACK_PEN)) CALL GetClientRect(CBHNDL, rc) PatBlt hDC,rc.nLeft,rc.nTop, rc.nRight, rc.nBottom,%PATCOPY MoveTo(hDC,70,70) LineTo(hDC,70,400) LineTo(hDC,400,400) END IF
InfoBar Callback New to MLG 3.00 This is used to paste information in an area on top of the grid. Could be useful for having a running cell count, sum etc. like is available on Excel.
The programmer must set register a drawing callback by pointing to the desired function as follows: SendMessage hGrid1 ,%MLG_SETCALLBACK,%MLG_INFOBARCALLBACK,CODEPTR(InfoBarCallback)
Note that a standard Windows API callback is used as a callback template
CBMSG = LOWRD is SelelectedRowStart HIWRD is SelectedRowEnd CBWPARAM = LOWRD is SelelectedColStart HIWRD is SelectedColEnd CBLPARAM = Pointer to the ASCIIZ string that will be pasted in the infobar
CALLBACK FUNCTION InfoBarCallBack() LOCAL MyStr AS ASCIIZ * 256 LOCAL MyStrPtr AS LONG LOCAL rc,pa,prc AS RECT LOCAL NonBlankCount,x,y,a,DimRows,DimCols AS LONG LOCAL MySum,MyAve AS DOUBLE
MyStrPtr = VARPTR(MyStr)
SendMessage (CBHNDL,%MLG_GETMULTICELLSELECTION,VARPTR(rc),0) SendMessage (CBHNDL,%MLG_GETPRINTAREA,VARPTR(pa),VARPTR(prc))
FOR x=Rc.nLeft TO Rc.nRight FOR y=Rc.nTop TO rc.nBottom IF LEN(MLG_GET(CBHNDL,y,x)) > 0 THEN INCR NonBlankCount MySum = MySum + VAL(MLG_GET(CBHNDL,y,x)) IF NonBlankCount > 0 THEN MyAve = MySum/NonBlankCount NEXT y NEXT x MyStr = "Print Area = " + STR$(pa.nTop) + STR$(pa.nLeft) + STR$(pa.nBottom) + STR$(pa.nRight) + " Repeat RowsCols = " + STR$(prc.nTop) + STR$(prc.nLeft) + STR$(prc.nBottom) + STR$(prc.nRight) MyStr = MyStr + " Count = " + STR$(NonBlankCount) + " Sum = " + FORMAT$(MySum,"0.00") + " Average = " + FORMAT$(MyAve,"0.000") MyStrPtr = VARPTR(MyStr) CopyMemory CBLPARAM,MyStrPtr,256 END FUNCTION |