{***************************************************************************

	NoMan Custom Control Library			$Version$
	Flags Module Unit
	$Author$		$Date$

        Copyright 1991 Anthony M. Vitabile

	Unit Description

	This Turbo Pascal for Windows unit contains a routine that
	creates control style strings.	This routine is common to all
	controls in the DLL.  It also implements one exported routine
	for each type of control which calls the common routine.  This
	minimizes the duplication of code in the unit.

	The library uses straight Windows calls and does NOT use Object-
	Windows.  This is to allow the control to be used by ANY Windows
	program.

	This code is adapted from the code that appeared in the July,
	1990 issue of Microsoft Systems Journal article, "Extending the
	Windows 3.0 Interface with Installable Custom Controls" by Kevin
	P. Welch.  The code has been extended to support the multiple
	control DLL format defined by Borland for use with their
	Resource Workshop resource editor.

***************************************************************************}

{$C DemandLoad Discardable}
Unit CtrlFlags;
Interface
  Uses WinTypes, CustCntl;

  function PercentCtrlFlags(Style :  longint;
			    Txt   :  PChar;
			    MaxStr:  word
			   ):  word; export;

Implementation
  Uses CtrlCommonDefs, Strings, WinProcs;

  type
    FlagsArray	= array [1 .. 16] of PChar;
    StylesArray = array [1 .. 16] of longint;

  var
    PctFlags :	FlagsArray;
    PctStyles:	StylesArray;

  function BuildFlags(Style :  longint;
		      Txt   :  PChar;
		      MaxStr,
		      NStyle:  word;
		  var Styles:  StylesArray;
		  var Flags :  FlagsArray
		     ):  word;
    var
      i   :  integer;
      len :  word;

    begin	{ BuildFlags }
      i      := 1;
      len    := 0;
      Txt[0] := #0;
      while (len < MaxStr) and (i <= NStyle) do
	begin
	  if (Style and Styles[i]) <> 0
	   then
	    begin
	     if len > 0
	      then
	       begin
		StrCat(Txt, ' | ');
		len := len + 3
	       end;
	     StrCat(Txt, Flags[i]);
	     len := len + StrLen(Flags[i])
	    end;
	  inc(i)
	end;
      BuildFlags := len
    end 	{ BuildFlags };

  function PercentCtrlFlags(Style :  longint;
			    Txt   :  PChar;
			    MaxStr:  word
			   ):  word;
    begin	{ PercentCtrlFlags }
      PercentCtrlFlags := BuildFlags(Style, Txt, MaxStr, PctNoStyles, PctStyles, PctFlags)
    end 	{ PercentCtrlFlags };

  begin
    PctFlags [1] := 'Pct_Decades';
    PctFlags [2] := 'Pct_Quarters';
    PctFlags [3] := 'Pct_Halves';
    PctFlags [4] := 'Pct_Axis';
    PctFlags [5] := 'Pct_Digits';

    PctStyles[1] := Pct_Decades;
    PctStyles[2] := Pct_Quarters;
    PctStyles[3] := Pct_Halves;
    PctStyles[4] := Pct_Axis;
    PctStyles[5] := Pct_Digits;
  end.
