Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
348

You've probably noticed our blogroll links in the right hand margin of this PowerBuilder blog. We've included those links whose content can advance you to being a more powerful developer. But just who are the people behind these resources? We're starting a series featuring each of these expert sources of developer knowledge...starting with Matt Balent, an engineer in the Paragon Development team at McKesson Provider Technologies and an organizer of the North Carolina PowerBuilder User Group who brings us a special DataWindow enhancement technique...

PowerBuilder – Treeview-Like Tooltips for DataWindows

The treeview control has a very neat piece of functionality built in called Tooltips. When this property is checked your application will automatically display all the text on a treeview item if it is cut off by the edge of the control when the mouse pointer goes over that row. If the row text is not cut off, no tip, if it is, a tip displays. The following is an implementation of this type of functionality for datawindows. Although it is geared more towards grid type datawindows it could be used on others as well. This code is done in PB11.5, which has a tooltip property on datawindow columns, but the basic ideas can be adapted to earlier versions without this.

The code is available here within an Archive File which also includes exports of the objects. Basically you will need to define the ‘mousemove’ event on your datawindow control (mapped to pbm_dwnmousemove) along with an string instance variable that tracks which row/column combination the mouse pointer is over. The instance variable is very important since it prevents the code from constantly being executed when the user keeps the pointer on the same row/column. Within the mouse move the position and width of the datawindow object column being pointed to is compared to the width of the datawindow control and the position of the horizontal scrollbar. Left and Right positioning of the column is also taken into consideration. If the text in the pointed at column is not completely within the control, it it placed into the Tooltip Text of the column. All columns have Tooltips enabled so once the Tip text has a value, the tip appears.

The code to derive the text and determine its length is encapsulated in an non visual object and uses a variety of API calls.

The sample application datawindow has columns of all Edit types as well as a couple of computed columns. One periodic issue is with dropdown datawindows and listboxed which have ‘Display all columns’ on. Another is with the ‘Always show arrow’ option which sometimes keeps the tooltip coming on even though all the text is visible.

Sample Screenshots:

This shows the bubblehelp for a Checkbox column. If the column has three states the text will show either ‘On’, ‘Off’, or ‘Other’.

This shows the right side of the datawindow control with no bubblehelp.

This shows the bubblehelp on a computed column.

At the bottom of the sample application are text boxes which display various position and size information which was useful in creating the checking logic. Since this is a grid datawindow you can re-order the columns as you wish. Also note the datawindow conrol can be resized which makes testing easier.

Code from mousemove event

// listview tooltips functionality for datawindow
//
// check to see if datawindow column text is cut off by either the size of the datawindow
// control or the position of the horizontal scrollbar
// if the text is cut off, put the text into the tooltip for the datawindow column so it
// will display.
Long    ll_hScrollPos, ll_width
Long    ll_colX, ll_colW, ll_colXW, ll_textwidth
datawindow ldw
string ls_mod, ls_value, ls_err, ls_checkname, ls_oldcolname, ls_alignment
s_dwbubble lstr_bubble
ldw = THIS
IF  row > 0 AND dwo.name <> 'datawindow' THEN
          ls_checkname = (dwo.Name  + '/' + string(row))
          // only do this if mouse moved to new row/column since last time
          IF(is_curcol <> ls_checkname) THEN
                   IF Len(is_curcol) > 0 THEN // blank out previous tip
                             ls_oldcolname = Left(is_curcol, Pos(is_curcol,'/') - 1)
                             ls_mod = ls_oldcolname + '.Tooltip.Tip = ""'
                             ls_err = this.modify(ls_mod)
                   END IF
                   ll_width = w_dwbubblehelp.dw_1.width
                   ll_hScrollPos = Long( THIS.Describe("DataWindow.HorizontalScrollPosition") )
                   ls_mod = dwo.name + '.x'
                   ll_colX = Long( THIS.Describe(ls_mod) )
                   ls_mod = dwo.name + '.width'
                   ll_colW = Long( this.Describe(ls_mod) )
                   ll_colXW = ll_colX + ll_colW
                   IF ll_colXW < ll_hScrollPos THEN
                              // "Not visible"
                   ELSE
                              IF ( ll_colX < ll_hScrollPos ) AND ( ll_colXW > ll_hScrollPos ) THEN
                                       // Partially Visible Left
                                       // get the text value and its length
                                      lstr_bubble = idw.uf_get_width_of_data(row, dwo.name, ldw, iw_parent)
                                      ll_textwidth = lstr_bubble.i_width
                                      ls_value = lstr_bubble.s_value
                                      ls_mod = dwo.name + '.Alignment'
                                      ls_alignment = this.describe(ls_mod)
                                      IF ls_alignment = '1' THEN // right alighment
                                                IF ll_textwidth > ll_colw THEN // text wider than column
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSEIF ll_colXW - ll_textwidth <  ll_hScrollPos THEN
                                                           // text cut off by datawindow control or scrollbar
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSE
                                                          ls_mod = dwo.name + '.Tooltip.Tip = ""'
                                                          ls_err = this.modify(ls_mod)
                                                END IF
                                      ELSE // other alignments
                                                IF ll_textwidth > ll_colw THEN
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSEIF ll_textwidth > (ll_colXW - (ll_width + ll_hScrollPos)) THEN
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSE
                                                          ls_mod = dwo.name + '.Tooltip.Tip = ""'
                                                          ls_err = this.modify(ls_mod)
                                                END IF
                                      END IF
                             ELSEIF (ll_colXW >  ll_hScrollPos) AND (ll_colXW > (ll_width + ll_hScrollPos) ) THEN
                                      // Partially Visible Right
                                      // get the text value and its length
                                      lstr_bubble = idw.uf_get_width_of_data(row, dwo.name, ldw, iw_parent)
                                      ll_textwidth = lstr_bubble.i_width
                                      ls_value = lstr_bubble.s_value
                                      ls_mod = dwo.name + '.Alignment'
                                      ls_alignment = this.describe(ls_mod)
                                      IF ls_alignment = '0' THEN // left alighment
                                                IF ll_textwidth > ll_colw THEN // text wider than column
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSEIF ll_width + ll_hScrollPos - ll_colX < ll_textwidth + Round((ll_textwidth / 10), 0) THEN
                                                          // text cut off by datawindow control or scrollbar
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSE
                                                          ls_mod = dwo.name + '.Tooltip.Tip = ""'
                                                          ls_err = this.modify(ls_mod)
                                                END IF
                                      ELSE
                                                IF ll_textwidth > ll_colw THEN // text wider than column width
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSEIF ll_textwidth > (ll_colW - (ll_width + ll_hScrollPos)) THEN
                                                          // text cut off by datawindow control or scrollbar
                                                          ls_mod = dwo.name + '.Tooltip.Tip = "' + ls_value + '"'
                                                          ls_err = this.modify(ls_mod)
                                                ELSE
                                                          ls_mod = dwo.name + '.Tooltip.Tip = ""'
                                                          ls_err = this.modify(ls_mod)
                                                END IF
                                      END IF
                              ELSE
                                      // "Visible"
                                      // this could be modifed for grid columns resized smaller than text value
                                      ls_mod = dwo.name + '.Tooltip.Tip = ""'
                                      ls_err = this.modify(ls_mod)
                              END IF
                   END IF
          END IF
          is_curcol = dwo.Name + '/' + string(row)
END IF

Thanks to Adam Simmonds for his assistance on this.