Alert() function colors

120 views
Skip to first unread message

to...@personamedical.com

unread,
Mar 5, 2013, 3:52:04 PM3/5/13
to harbou...@googlegroups.com
When a color string is provided for the 3rd parameter of Alert(), Harbour's handling of the colors is not consistent with Clipper.  It appears that Harbour is attempting to reverse the colors provided but it doesn't work correctly with a color string with standard and enhanced colors are specified, and regardless is not what Clipper does.

In Clipper, when only the standard color string is supplied to Alert(), Clipper uses the current SetColor()'s enhanced color setting.

For example, if SetColor() returns "W/N,N/W,N/N,N/N,N/W", and you call Alert("Test",{"One","Two"},"GR+/B"), the items (One and Two) would be drawn using the "N/W" color string. However, if the color string, "GR+/B,W+/R" is used, the items are drawn using "W+/R".

So, to make the Alert function work as it does in Clipper, Harbour's \harbour\src\rtl\alert.prg needs to be changed similar to the highlighted portion below:

FUNCTION Alert( cMessage, aOptions, cColorNorm )

   LOCAL cColorHigh
   LOCAL aOptionsOK
   LOCAL cOption

#ifdef HB_CLP_UNDOC

   IF s_lNoAlert == NIL
      s_lNoAlert := hb_argCheck( "NOALERT" )
   ENDIF

   IF s_lNoAlert
      RETURN NIL
   ENDIF

#endif

   IF ! HB_ISSTRING( cMessage )
      RETURN NIL
   ENDIF

   cMessage := StrTran( cMessage, ";", Chr( 10 ) )

   hb_default( @aOptions, {} )

   IF ! HB_ISSTRING( cColorNorm ) .OR. Empty( cColorNorm )
      cColorNorm := "W+/R" // first pair color (Box line and Text)
      cColorHigh := "W+/B" // second pair color (Options buttons)
   ELSE
      cColorHigh := HB_TOKENGET( cColorNorm, 2, ",")
      IF Empty( cColorHigh )
        cColorHigh := HB_TOKENGET( SetColor(), 2, ",")
      ENDIF

   ENDIF

   aOptionsOK := {}
   FOR EACH cOption IN aOptions
      IF HB_ISSTRING( cOption ) .AND. ! Empty( cOption )
         AAdd( aOptionsOK, cOption )
      ENDIF
   NEXT

   IF Len( aOptionsOK ) == 0
      aOptionsOK := { "Ok" }
#ifdef HB_CLP_STRICT
   ELSEIF Len( aOptionsOK ) > 4 /* NOTE: Clipper allows only four options [vszakats] */
      ASize( aOptionsOK, 4 )
#endif
   ENDIF

   RETURN hb_gtAlert( cMessage, aOptionsOK, cColorNorm, cColorHigh )


BTW, I'm working with Harbour 3.2.0dev (Rev. 18896) in Windows 7 Pro 32 bit..

Regards,
tq

Viktor Szakáts

unread,
Mar 5, 2013, 5:02:58 PM3/5/13
to harbou...@googlegroups.com
Can you modify the patch to use hb_colorindex()? Thanks.
--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Viktor

to...@personamedical.com

unread,
Mar 5, 2013, 5:14:52 PM3/5/13
to harbou...@googlegroups.com
I hadn't noticed that function. Here you go:

FUNCTION Alert( cMessage, aOptions, cColorNorm )

   LOCAL cColorHigh
   LOCAL aOptionsOK
   LOCAL cOption

#ifdef HB_CLP_UNDOC

   IF s_lNoAlert == NIL
      s_lNoAlert := hb_argCheck( "NOALERT" )
   ENDIF

   IF s_lNoAlert
      RETURN NIL
   ENDIF

#endif

   IF ! HB_ISSTRING( cMessage )
      RETURN NIL
   ENDIF

   cMessage := StrTran( cMessage, ";", Chr( 10 ) )

   hb_default( @aOptions, {} )

   IF ! HB_ISSTRING( cColorNorm ) .OR. Empty( cColorNorm )
      cColorNorm := "W+/R" // first pair color (Box line and Text)
      cColorHigh := "W+/B" // second pair color (Options buttons)
   ELSE
      cColorHigh := HB_COLORINDEX( cColorNorm, 1)
      IF Empty( cColorHigh )
        cColorHigh := HB_COLORINDEX( SetColor(), 1)
      ENDIF
   ENDIF

   aOptionsOK := {}
   FOR EACH cOption IN aOptions
      IF HB_ISSTRING( cOption ) .AND. ! Empty( cOption )
         AAdd( aOptionsOK, cOption )
      ENDIF
   NEXT

   IF Len( aOptionsOK ) == 0
      aOptionsOK := { "Ok" }
#ifdef HB_CLP_STRICT
   ELSEIF Len( aOptionsOK ) > 4 /* NOTE: Clipper allows only four options [vszakats] */
      ASize( aOptionsOK, 4 )
#endif
   ENDIF

Better?

Regards,

tq
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-devel+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Viktor

vszakats

unread,
Mar 5, 2013, 7:37:04 PM3/5/13
to harbou...@googlegroups.com
Yes, thanks. I replaced 1 with CLR_ENHANCED and applied the 
same to HB_ALERT(), too. Though when testing against Clipper, 
the modification gave different results, so I'll commit a different, 
simpler patch.

-- Viktor
Reply all
Reply to author
Forward
0 new messages