gtk2: colorDialog changes

- fix wrong argument type of SetColorDialogColor
  - set previous color = current color of the ColorDialog: user can see what colors was when dialog was opened and can return to it at any moment
  - add method SetColorDialogPalette which tells to GtkColorSelectionDialog to show palette frame and sets custom colors to palette

git-svn-id: trunk@17343 -
This commit is contained in:
paul 2008-11-11 15:14:50 +00:00
parent ab459c3829
commit 42b8e648ce

View File

@ -41,8 +41,8 @@ type
TGtk2WSCommonDialog = class(TWSCommonDialog) TGtk2WSCommonDialog = class(TWSCommonDialog)
private private
class procedure SetColorDialogColor(ColorSelection: PGtkColorSelection; class procedure SetColorDialogColor(ColorSelection: PGtkColorSelectionDialog; Color: TColor);
Color: TColor); class procedure SetColorDialogPalette(ColorSelection: PGtkColorSelectionDialog; Palette: TStrings);
protected protected
public public
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual; class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
@ -1084,25 +1084,62 @@ end;
Set the color of the color selection dialog Set the color of the color selection dialog
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class procedure TGtk2WSCommonDialog.SetColorDialogColor(ColorSelection: PGtkColorSelection; class procedure TGtk2WSCommonDialog.SetColorDialogColor(ColorSelection: PGtkColorSelectionDialog;
Color: TColor); Color: TColor);
var var
SelectionColor: TGDKColor; SelectionColor: TGDKColor;
colorSel : PGTKCOLORSELECTION; colorSel: PGtkColorSelection;
begin begin
{$IFDEF VerboseColorDialog} Color := ColorToRGB(Color);
DebugLn('TGtkWidgetSet.SetColorDialogColor Start Color=',DbgS(Color)); SelectionColor := TColortoTGDKColor(Color);
{$ENDIF} colorSel := PGtkColorSelection(ColorSelection^.colorsel);
Color:=ColorToRGB(Color); gtk_color_selection_set_current_color(colorSel, @SelectionColor);
{$IFDEF VerboseColorDialog} gtk_color_selection_set_previous_color(colorSel, @SelectionColor);
DebugLn('TGtkWidgetSet.SetColorDialogColor Converted Color=',DbgS(Color)); end;
{$ENDIF}
SelectionColor.Pixel := 0; class procedure TGtk2WSCommonDialog.SetColorDialogPalette(
SelectionColor.Red := Red(Color) shl 8; ColorSelection: PGtkColorSelectionDialog; Palette: TStrings);
SelectionColor.Green:= Green(Color) shl 8; const
SelectionColor.Blue:= Blue(Color) shl 8; PaletteSetting = 'gtk-color-palette';
colorSel := PGTKCOLORSELECTION((PGTKCOLORSELECTIONDIALOG(ColorSelection))^.colorsel); var
gtk_color_selection_set_current_color(colorSel,@SelectionColor); colorSel: PGtkColorSelection;
settings: PGtkSettings;
new_palette: Pgchar;
colors: PGdkColor;
colors_len: gint;
procedure FillCustomColors;
var
i, AIndex: integer;
AColor: TColor;
begin
for i := 0 to Palette.Count - 1 do
if ExtractColorIndexAndColor(Palette, i, AIndex, AColor) then
if AIndex < colors_len then
colors[AIndex] := TColortoTGDKColor(AColor);
end;
begin
colorSel := PGtkColorSelection(ColorSelection^.colorsel);
// show palette
gtk_color_selection_set_has_palette(colorSel, True);
// replace palette. it is stored in 'gtk-color-palette' settings
// 1. get original palette => we will know colors and replace only part of it
settings := gtk_widget_get_settings(PGtkWidget(colorSel));
new_palette := nil;
g_object_get(settings, PaletteSetting, [@new_palette, nil]);
gtk_color_selection_palette_from_string(new_palette, colors, @colors_len);
g_free(new_palette);
// 2. fill original palette with our custom colors
FillCustomColors;
// 3. set new palette back to settings
new_palette := gtk_color_selection_palette_to_string(colors, colors_len);
g_free(colors);
gtk_settings_set_string_property(settings, PaletteSetting, new_palette, 'gtk_color_selection_palette_to_string');
g_free(new_palette);
end; end;
class procedure TGtk2WSCommonDialog.SetCallbacks(const AGtkWidget: PGtkWidget; class procedure TGtk2WSCommonDialog.SetCallbacks(const AGtkWidget: PGtkWidget;
@ -1151,8 +1188,12 @@ begin
GtkWindow:=PGtkWindow(ACommonDialog.Handle); GtkWindow:=PGtkWindow(ACommonDialog.Handle);
gtk_window_set_title(GtkWindow,PChar(ACommonDialog.Title)); gtk_window_set_title(GtkWindow,PChar(ACommonDialog.Title));
if ACommonDialog is TColorDialog then if ACommonDialog is TColorDialog then
SetColorDialogColor(PGtkColorSelection(GtkWindow), begin
SetColorDialogColor(PGtkColorSelectionDialog(GtkWindow),
TColorDialog(ACommonDialog).Color); TColorDialog(ACommonDialog).Color);
SetColorDialogPalette(PGtkColorSelectionDialog(GtkWindow),
TColorDialog(ACommonDialog).CustomColors);
end;
gtk_window_set_position(GtkWindow, GTK_WIN_POS_CENTER); gtk_window_set_position(GtkWindow, GTK_WIN_POS_CENTER);
GtkWindowShowModal(GtkWindow); GtkWindowShowModal(GtkWindow);
@ -1184,6 +1225,7 @@ var
WidgetInfo: PWidgetInfo; WidgetInfo: PWidgetInfo;
begin begin
Widget := gtk_color_selection_dialog_new(PChar(ACommonDialog.Title)); Widget := gtk_color_selection_dialog_new(PChar(ACommonDialog.Title));
Result := THandle(PtrUInt(Widget)); Result := THandle(PtrUInt(Widget));
WidgetInfo := CreateWidgetInfo(Widget); WidgetInfo := CreateWidgetInfo(Widget);
WidgetInfo^.LCLObject := ACommonDialog; WidgetInfo^.LCLObject := ACommonDialog;