Clarion allows us to change the colors of browse lists and this can be a handy way of highlighting individual cells, or rows within an application. However it can be tedious to apply a set of colors across an entire application.

So, I created a simple Clarion ABC template that sets the color of browse lists globally - GWBChangeBrowseRowColors

The Global Template

I want to define the browse colors globally and apply the colors to all the browses in the application, this is done as follows…

#TEMPLATE (GWBChangeBrowseRowColorsTemplate, 'GWB Change Browse Row Colors - Template'),FAMILY('ABC')

#EXTENSION (GWBChangeBrowseRowColors_Global, 'GWB Change Browse Row Colors - Global Level'), APPLICATION(GWBChangeBrowseRowColors_ProcedureCode GWBChangeBrowseRowColorsTemplate)), LAST

The colors of the browselist can be specified at runtime by 4 PROPLIST:colors…

-PROPLIST:BackColor -PROPLIST:TextColor -PROPLIST:BackSelected -PROPLIST:TextSelected

I’ve defined variables for these colors in the template user interface for the developer…

#SHEET,HSCROLL
  #TAB ('GWB Change Browse Row Colors Globally')
    #DISPLAY('Change browse row colors')
    #PROMPT('Unselected Background',COLOR),%GWBUBColor,AT(100),DEFAULT(color:white)
    #PROMPT('Unselected Foreground',COLOR),%GWBUFColor,AT(100),DEFAULT(color:Navy)
    #PROMPT('Selected Background',COLOR),%GWBSBColor,AT(100),DEFAULT(color:Navy)
    #PROMPT('Selected Foreground',COLOR),%GWBSFColor,AT(100),DEFAULT(color:Yellow)
    #DISPLAY()
  #ENDTAB
#ENDSHEET

Using a COLOR prompt lets the developer choose the color using the Clarion Color Picker…

COLOR picker in a template

How the Procedure template colors the browse list.

I created a PROCEDURE level template to add code to each procedure…

#EXTENSION (GWBChangeBrowseRowColors_ProcedureCode,'GWBChangeBrowseRowColors - Procedure Level'),PROCEDURE

In this Extension template I want to give the developer the option to disable the effects of the Global template…

#SHEET
  #TAB('Properties')
    #BOXED('Change Browse Row Colors in this procedure')
      #DISPLAY
      #DISPLAY('Uncheck the box if you DO NOT want')
      #DISPLAY('to change the browse colors')
      #DISPLAY('in this procedure' )
      #DISPLAY
      #PROMPT('Change Browse Colors?',CHECK),%GWBBrowseColorsEnabled,AT(10),DEFAULT(1)
    #ENDBOXED
  #ENDTAB
#ENDSHEET

This results in the following dialog for the template in each procedure…

Disabling the template for a procedure

Now, I only want to add the Procedure level code if the procedure is a WINDOW procedure, so it doesn’t get added to SOURCE or REPORT procedures, for example. The easiest way to do this is to #RESTRICT this template code so it only gets added to WINDOW procedures….

#RESTRICT
  #IF(UPPER(%ProcedureTemplate) = 'WINDOW')
    #ACCEPT
  #ENDIF
  #REJECT
#ENDRESTRICT

Next, I need to insert some code into the procedure, to actually set the colors for our browse lists…

I’ll be inserting this code into ThisWindow.Init at priority 8450, that is, near the end of the init process.

Since there might be multiple browse lists in the procedure I loop through each of them and apply the code. The code in this template colors all the browses in the procedure, I haven’t allowed for the option to conditionally color individual browses within a procedure.

Colors for a browse list are set on a column by column basis. Using the standard Clarion list formatter to do this would be a very time consuming task. With a template however I can simply loop through them with some code.

#AT(%WindowManagerMethodCodeSection,'Init','(),BYTE'),PRIORITY(8450),WHERE(%GWBBrowseColorsEnabled)
#DECLARE(%FieldEquate)
    #FOR(%Control),WHERE(%ControlType = 'LIST')
        #SET(%FieldEquate,(EXTRACT(%ControlStatement,'USE',1)))

        #! Based on Clarion help example for PropList
        LOOP X# = 1 TO 255  
            IF %FieldEquate{PROPLIST:Exists,X#} = 1  
                IF %FieldEquate{PROPLIST:BackColor,X#} = -1 |
                AND %FieldEquate{PROPLIST:TextColor,X#} = -1 |
                AND %FieldEquate{PROPLIST:BackSelected,X#} = -1 |
                AND %FieldEquate{PROPLIST:TextSelected,X#} = -1
                    %FieldEquate{PROPLIST:BackColor,X#} = %GWBUBColor   
                    %FieldEquate{PROPLIST:TextColor,X#} = %GWBUFColor
                    %FieldEquate{PROPLIST:BackSelected,X#} = %GWBSBColor
                    %FieldEquate{PROPLIST:TextSelected,X#} = %GWBSFColor
                END    
            ELSE
                BREAK
            END
        END   

    #ENDFOR
#ENDAT    

The template allows for up to 255 columns and loops through them. It checks to see if the user has specified local colors for the column. -1 is the default color for the PROPLIST:colors, so if any of these colors is not -1 it means the developer has set a specific color for this column and the template should not override that color. Otherwise, set the colors specified in the global template.

This browse has colors set for the first column by formatting the browse colors in the Clarion Browse formatter, and also conditional colors for First Names beginning with a “J”…

Local colors are respected by our template

…and the template respects those colors.

The template and example app are available for download.

Get the File

A valid email address is required

Please agree to these terms

  • Template is provided "as is"
  • No warranty is expressed or implied
  • No liability will be accepted for any damage, or loss, caused by the use of this template.
  • The file and code is the copyright of Comformark Pty Ltd
  • The file is not to be distributed to any other party
You must agree to our terms*