From: André S. <asn...@us...> - 2004-07-07 00:04:20
|
Update of /cvsroot/jvcl/dev/JVCL3/design In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2816/JVCL3/design Modified Files: JvColorEditor.pas Log Message: clx update: added TJvColorProperty.Edit ( stores/retrieves custom colors) Index: JvColorEditor.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/design/JvColorEditor.pas,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** JvColorEditor.pas 15 Jun 2004 05:24:00 -0000 1.13 --- JvColorEditor.pas 7 Jul 2004 00:04:09 -0000 1.14 *************** *** 31,62 **** uses SysUtils, Classes, - {$IFDEF VCL} Windows, Graphics, - {$ENDIF VCL} - {$IFDEF VisualCLX} - QGraphics, Types, - {$ENDIF VisualCLX} {$IFDEF COMPILER6_UP} RTLConsts, DesignIntf, DesignEditors, - {$IFDEF VCL} VCLEditors, - {$ENDIF VCL} - {$IFDEF VisualCLX} - ClxEditors, - {$ENDIF VisualCLX} {$ELSE} DsgnIntf, {$ENDIF COMPILER6_UP} JvConsts, JvJVCLUtils; type TJvColorProperty = class(TColorProperty) public function GetValue: string; override; procedure GetValues(Proc: TGetStrProc); override; procedure SetValue(const Value: string); override; procedure ListDrawValue(const Value: string; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); {$IFDEF COMPILER5} override {$ELSE} virtual {$ENDIF}; end; --- 31,75 ---- uses SysUtils, Classes, Windows, Graphics, {$IFDEF COMPILER6_UP} RTLConsts, DesignIntf, DesignEditors, VCLEditors, {$ELSE} DsgnIntf, {$ENDIF COMPILER6_UP} + {$IFDEF VisualCLX} + QDialogs, + {$IFDEF MSWINDOWS} + Registry, + {$ENDIF MSWINDOWS} + {$IFDEF LINUX} + JvQRegistryIniFile, + {$ENDIF LINUX} + {$ENDIF VisualCLX} JvConsts, JvJVCLUtils; + {$IFDEF VisualCLX} + const + SCustomColors = 'JVCLX Custom Colors'; + {$ENDIF VisualCLX} + type TJvColorProperty = class(TColorProperty) + {$IFDEF VisualCLX} + protected + function GetRegKey: string; dynamic; + {$ENDIF VisualCLX} public function GetValue: string; override; procedure GetValues(Proc: TGetStrProc); override; procedure SetValue(const Value: string); override; + {$IFDEF VCL} procedure ListDrawValue(const Value: string; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); {$IFDEF COMPILER5} override {$ELSE} virtual {$ENDIF}; + {$ENDIF VCL} + {$IFDEF VisualCLX} + procedure Edit; override; + {$ENDIF VisualCLX} end; *************** *** 179,182 **** --- 192,196 ---- end; + {$IFDEF VCL} procedure TJvColorProperty.ListDrawValue(const Value: string; ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); *************** *** 202,205 **** --- 216,310 ---- end; end; + {$ENDIF VCL} + + {$IFDEF VisualCLX} + // + // Edit uses TColorDialog, but that does not store the + // customcolors. For design time non volatile customcolors are + // implemented stored in the Registry under windows and in + // Linux in an IniFile. + // + function TJvColorProperty.GetRegKey: String; + begin + Result := SDelphiKey + PathDelim + SCustomColors; + end; + + procedure TJvColorProperty.Edit; + var + ColorDialog: TColorDialog; + + procedure GetCustomColors; + var + KeyName: string; + KeyValue: string; + Suffix: Char; + begin + with TRegistry.Create do + try + LazyWrite := False; + if OpenKey(GetRegKey, True) then + try + with ColorDialog.CustomColors do + begin + Clear; + for Suffix := 'A' to 'P' do + begin + KeyName := 'Color' + Suffix; + KeyValue := ReadString(KeyName); + Add(KeyName + '=' + KeyValue); + end; + end; + finally + CloseKey; + end; + finally + Free; + end; + end; + + procedure SaveCustomColors; + var + I: Integer; + KeyName: string; + KeyValue: string; + Suffix: Char; + begin + with TRegistry.Create do + try + LazyWrite := False; + if OpenKey(GetRegKey, True) then + try + I := 0; + with ColorDialog.CustomColors do + for Suffix := 'A' to 'P' do + begin + KeyName := 'Color' + Suffix; + KeyValue := StringReplace(Strings[I], Keyname + '=', '', []); + WriteString(KeyName, KeyValue); + inc(I); + end; + finally + CloseKey; + end; + finally + Free; + end; + end; + + begin + ColorDialog := TColorDialog.Create(nil); + try + ColorDialog.Color := ColorFromColormap(GetOrdValue); + GetCustomColors; + if ColorDialog.Execute then + begin + SetOrdValue(ColorDialog.Color); + SaveCustomColors; + end; + finally + ColorDialog.Free; + end; + {$ENDIF VisualCLX} + end. |