Page 2 of 2

Re: combobox color

PostPosted: Mon Apr 29, 2024 6:22 am
by nageswaragunupudi
Silvio.Falconi wrote:I have a combobox
@ 10, 120 COMBOBOX aget[1] VAR cCategoria Items ArrTranspose(aCategorie )[ 2] size 200,90 PIXEL OF oDlg
...
I wish change color and font of text only on these two items


Please test this sample and use your own font and colors for these items
Code: Select all  Expand view
#include "fivewin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oCbx, aItems[7], cItem, oFont

   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-16
   DEFINE WINDOW oWnd
   oWnd:SetFont( oFont )

   AEval( aItems, { |c,i | aItems[ i ] := NTOCDOW( i ) } )
   cItem    := aItems[ 1 ]

   @ 80,40 COMBOBOX oCbx VAR cItem ITEMS aItems SIZE 150,300 PIXEL OF oWnd ;
      OWNERDRAW OwnerDrawItem( Self, nIdCtl, oItemStruct )

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

function OwnerDrawItem( Self, nIdCtl, oItem )

   local oFont, nClrText, nClrBack
   local hDC      := oItem:hDC

   if oItem:itemID >= 0
      if oItem:itemID == 0 .or. oItem:itemID == ( Len( ::aItems ) - 1 )
         oFont    := ::oFont:Bold()
         nClrBack    := If( lAnd( oItem:itemState, 1 ), CLR_HGREEN, CLR_YELLOW )
         nClrText    := If( lAnd( oItem:itemState, 1 ), CLR_HRED, CLR_HRED )
      else
         nClrBack    := If( lAnd( oItem:itemState, 1 ), CLR_HGRAY, CLR_WHITE )
         nClrText    := If( lAnd( oItem:itemState, 1 ), CLR_BLACK, CLR_BLACK )
      endif

      FW_SayText( hDC, oItem:itemData, oItem:aRect,"L", IfNil( oFont, ::oFont ), ;
         nClrText, nARGB( 255, nClrBack ) )

      RELEASE FONT oFont
   endif

return 1


Image

Re: combobox color

PostPosted: Mon Apr 29, 2024 7:16 am
by Jimmy
hi,
thx for The Solution, it is much simple than my Solution

Re: combobox color

PostPosted: Mon Apr 29, 2024 10:17 am
by Otto
Dear Mr. Rao,

This is a very good solution.

However, it seems inappropriate that we should be restricted from discussing solutions involving WebView and Mod Harbour, as Mr. Silvio suggests.

We urgently need effective solutions for the web, and it's essential to accelerate our learning curve.
Providing samples that address specific questions, such as how things can be accomplished using the WebView interface, would be beneficial.

Thanks to FIVETECH, we have the necessary tools; now we just need to utilize them.

Best regards,
Otto

Re: combobox color

PostPosted: Mon Apr 29, 2024 4:32 pm
by Silvio.Falconi
nageswaragunupudi wrote:
Silvio.Falconi wrote:I have a combobox
@ 10, 120 COMBOBOX aget[1] VAR cCategoria Items ArrTranspose(aCategorie )[ 2] size 200,90 PIXEL OF oDlg
...
I wish change color and font of text only on these two items


Please test this sample and use your own font and colors for these items
Code: Select all  Expand view
#include "fivewin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oCbx, aItems[7], cItem, oFont

   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-16
   DEFINE WINDOW oWnd
   oWnd:SetFont( oFont )

   AEval( aItems, { |c,i | aItems[ i ] := NTOCDOW( i ) } )
   cItem    := aItems[ 1 ]

   @ 80,40 COMBOBOX oCbx VAR cItem ITEMS aItems SIZE 150,300 PIXEL OF oWnd ;
      OWNERDRAW OwnerDrawItem( Self, nIdCtl, oItemStruct )

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

function OwnerDrawItem( Self, nIdCtl, oItem )

   local oFont, nClrText, nClrBack
   local hDC      := oItem:hDC

   if oItem:itemID >= 0
      if oItem:itemID == 0 .or. oItem:itemID == ( Len( ::aItems ) - 1 )
         oFont    := ::oFont:Bold()
         nClrBack    := If( lAnd( oItem:itemState, 1 ), CLR_HGREEN, CLR_YELLOW )
         nClrText    := If( lAnd( oItem:itemState, 1 ), CLR_HRED, CLR_HRED )
      else
         nClrBack    := If( lAnd( oItem:itemState, 1 ), CLR_HGRAY, CLR_WHITE )
         nClrText    := If( lAnd( oItem:itemState, 1 ), CLR_BLACK, CLR_BLACK )
      endif

      FW_SayText( hDC, oItem:itemData, oItem:aRect,"L", IfNil( oFont, ::oFont ), ;
         nClrText, nARGB( 255, nClrBack ) )

      RELEASE FONT oFont
   endif

return 1


Image



thanks rao run ok

Re: combobox color

PostPosted: Tue Apr 30, 2024 1:39 am
by Cgallegoa
Hi,

The "oItem:itemData" attribute of COMBOBOX returns incorrect data with FWH 23.10. Works perfect with FWH-20.07. When reviewing the class I see many changes between the two versions. How and where do I correct it ?

FWH-23.10 - INCORRECT
Image

FWH-20.07 - OK
Image

Thanks and regards,

Re: combobox color

PostPosted: Wed May 01, 2024 1:39 pm
by karinha
Carlos, you need to update yourself.

Carlos, necesitas actualizarte.

Code: Select all  Expand view

 xHarbour 1.3.1 Intl. (SimpLex) (Build 20240404), , Borland C++7.70
 


Regards, saludos.

Re: combobox color

PostPosted: Wed May 01, 2024 3:25 pm
by Enrico Maria Giordano
These are the latest builds, please update with them:

https://github.com/FiveTechSoft/harbour_and_xharbour_builds

Re: combobox color

PostPosted: Wed May 01, 2024 8:10 pm
by Silvio.Falconi
Otto wrote:Dear Jimmy,
nevertheless, I think that the future for the frontend will be HTML (WEBVIEW2)

Best regards,
Otto



Image


Code: Select all  Expand view



    #include "FiveWin.ch"

    function Main()

       local oWebView := TWebView():New()

       oWebView:SetHtml( Html() )
       oWebView:SetTitle( "WebView2 - combobox sample" )

       oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
       oWebView:Bind( "SendToFWH" )
       oWebView:bOnBind = { | cJson, cCalls | Login( cJson, cCalls, oWebView ) }
       sleep( 300 )
       oWebView:Run()
       oWebView:Destroy()

    return nil

    function Login( cJson, cCalls, oWebView )

       local hData

       hb_jsonDecode( cJson, @hData )

       if hData[ 1 ][ "username" ] != "Antonio" .or. hData[ 1 ][ "password" ] != "1234"
          oWebView:Return( cCalls, 0, "{ 'result': 'incorrect values' }" )
       else
          oWebView:Return( cCalls, 0, "{ 'result': 'correct!' }" )
      endif

    return nil  

    function Html()

       local cHtml

       TEXT INTO cHtml
     
     <!DOCTYPE html>
        <!DOCTYPE html>
        <!DOCTYPE html>
            <html lang="en">
            <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Mehrwertsteuer-Auswahl</title>
            <style>
              .special-color {
                color: red;
              }
              .taxable-10-percent {
                background-color: orange;
                color: white;
                font-weight: bold;
                font-size: larger;
              }
            </style>
            </head>
            <body>
           
            <form action="/submit-form-url" method="post">
              <label for="vatRate">Aliquota Iva:</label>
              <select name="vatRate" id="vatRate">
                <option value="none" class="special-color">nessuna</option>
                <option value="exempt_art_10">Esente art. 10</option>
                <option value="exempt_art_15">Esente art. 15</option>
                <option value="outside_scope_vat">Fuori campo IVA</option>
                <option value="taxable_4_percent">Imponibile 4%</option>
                <option value="taxable_10_percent" class="taxable-10-percent">Imponibile 10%</option>
                <option value="taxable_22_percent">Imponibile 22%</option>
                <option value="not_taxable_art_7">Non imponibile art. 7</option>
                <option value="not_taxable_art_8">Non imponibile art. 8</option>
                <option value="excluded_art_15">Esclusa art. 15</option>
                <option value="add" class="special-color">aggiungi</option>
              </select>
           
              <input type="submit" value="Hinzufügen">
            </form>
           
            </body>
            </html>
   

       ENDTEXT

    return cHtml
   

 


I prefer that what I use in my images or examples are not used for your entertainment