third_party_content:sprezz_blog:15534.4694444444

EditTable Cookbook - Row selection without focus

Published 12 JUL 2010 at 11:16:00AM by Captain C

Following on from our recent post on how to remove the row-selection from an EditTable we came across a related issue last week that we think you might like to know about.

Basically we designed a form with several EditTables, all row-select enabled, but during testing it became difficult to know where the actual input focus was as so many controls had a selection highlighted. We could have used the technique in the aforementioned blog post to clear the row-selection during the LOSTFOCUS event, but in this case we still needed to see which row was selected even though the focus was on another control.

The solution we used was to change the highlight color of the EditTable during the LOSTFOCUS event, toning it down to a lighter shade than normal. We then reset it during the GOTFOCUS event. This is actually quite easy to achieve with the COLOR_BY_POS message, the only real challenge is to devise an algorithm to fade the highlight color.

As usual we've saved you the trouble - here's small function that you can use as a starting point for your own application should you wish to use a similar technique:

0001  subroutine edt_FadeSelection( edtID, bFade ) 0002  /* 0003     Author   : Darth C, Sprezzatura Actual 0004     Date     : 12 Jul 2010 0005     Purpose  : Function to adjust the row selection color of an edit table 0006      0007     Parameters 0008     

0009      0010       edtID    → Fully qualified name of the edit table  0011        0012       bFade    → If TRUE then fade the selection color, otherwise 0013                   reset it to normal  0014                    0015     Requirements 0016     ============                  0017        0018  */ 0019     declare function rgb 0020     $insert winAPI_EditTable_Equates 0021     $insert winAPI_SysColor_Equates 0022     $insert logical 0023      0024     if assigned( edtID ) else edtID = "" 0025     if assigned( bFade ) else bFade = FALSE$ 0026      0027     if len( edtID ) then 0028        if ( bFade ) then 0029           goSub fadeSelectionColor 0030        end else 0031           goSub resetSelectionColor 0032        end 0033     end 0034      0035  return 0036   0037  /////////////////////////////////////////////////////////////////////////////// 0038  /////////////////////////////////////////////////////////////////////////////// 0039   0040  fadeSelectionColor: 0041   0042     origColor =        winAPI_GetSysColor( SYSCOLOR_HIGHLIGHT$ ) 0043         0044     origColor = fmt( oconv( origColor, "MB" ), "R(0)#32" ) 0045     bleach    = 185 ; * // this is how much white we want to add…(0..255) 0046              0047     selColor =        iconv( origColor[25,8], "MB" ) 0048     selColor := @fm : iconv( origColor[17,8], "MB" ) 0049     selColor := @fm : iconv( origColor[9,8], "MB" ) 0050         0051     * // Now add the bleach to each component 0052     for x = 1 to 3 0053        pct = ( 1 - ( selColor<x>/255 ) ) 0054        selColor<x> = selColor<x> + int( pct * bleach ) 0055     next 0056         0057     selColor = rgb( selColor<1>, selColor<2>, selColor<3> ) 0058     txtColor = winAPI_GetSysColor( SYSCOLOR_WINDOWTEXT$ ) 0059     if txtColor else 0060        * // 0 (BLACK) means "default color" in COLOR_BY_POS processing!!! 0061        txtColor += 1 0062     end 0063         0064     dtcs =       DT_DEFAULTCOLOR$                                           | 0065          : @fm : DT_DEFAULTCOLOR$                                           | 0066          : @fm : selColor                                                   | 0067          : @fm : txtColor 0068              0069     call send_Message( edtID, "COLOR_BY_POS", 0, 0, dtcs ) 0070   0071  return 0072   0073  /////////////////////////////////////////////////////////////////////////////// 0074   0075  resetSelectionColor: 0076   0077     dtcs =       DT_DEFAULTCOLOR$                                           | 0078          : @fm : DT_DEFAULTCOLOR$                                           |  0079          : @fm : DT_DEFAULTCOLOR$                                           | 0080          : @fm : DT_DEFAULTCOLOR$ 0081              0082     call send_Message( edtID, "COLOR_BY_POS", 0, 0, dtcs ) 0083   0084  return 0085   0086  /////////////////////////////////////////////////////////////////////////////// 0087  ///////////////////////////////////////////////////////////////////////////////

In your EditTable LOSTFOCUS event you call this:

    call edt_FadeSelection( @window : ".TABLE_1", TRUE$ )

And to reset the colors in your EditTable GOTFOCUS event you call this:

    call edt_FadeSelection( @window : ".TABLE_1", FALSE$ )

(You'll notice that the function uses two "WinAPI" $insert records, both of which can be found the WinAPI Library that we recently posted.)

You can download a text version of edt_FadeSelection here.

Disclaimer

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Comments

Original ID: post-8583498247302902760
  • third_party_content/sprezz_blog/15534.4694444444.txt
  • Last modified: 2024/01/17 19:45
  • by 127.0.0.1