Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsColorPicker_h__
7 : #define nsColorPicker_h__
8 :
9 : #include <gtk/gtk.h>
10 :
11 : #include "nsCOMPtr.h"
12 : #include "nsIColorPicker.h"
13 : #include "nsString.h"
14 :
15 : // Don't activate the GTK3 color picker for now, because it is missing a few
16 : // things, mainly the ability to let the user select a color on the screen.
17 : // See bug 1198256.
18 : #undef ACTIVATE_GTK3_COLOR_PICKER
19 :
20 : class nsIWidget;
21 :
22 : class nsColorPicker final : public nsIColorPicker
23 : {
24 : public:
25 : NS_DECL_ISUPPORTS
26 : NS_DECL_NSICOLORPICKER
27 :
28 0 : nsColorPicker() {};
29 :
30 : private:
31 0 : ~nsColorPicker() {};
32 :
33 : static nsString ToHexString(int n);
34 :
35 : static void OnResponse(GtkWidget* dialog, gint response_id,
36 : gpointer user_data);
37 : static void OnDestroy(GtkWidget* dialog, gpointer user_data);
38 :
39 : #if defined(ACTIVATE_GTK3_COLOR_PICKER) && GTK_CHECK_VERSION(3,4,0)
40 : static void OnColorChanged(GtkColorChooser* color_chooser, GdkRGBA* color,
41 : gpointer user_data);
42 :
43 : static int convertGdkRgbaComponent(gdouble color_component);
44 : static gdouble convertToGdkRgbaComponent(int color_component);
45 : static GdkRGBA convertToRgbaColor(nscolor color);
46 :
47 : void Update(GdkRGBA* color);
48 : void SetColor(const GdkRGBA* color);
49 : #else
50 : static void OnColorChanged(GtkColorSelection* colorselection,
51 : gpointer user_data);
52 :
53 : // Conversion functions for color
54 : static int convertGdkColorComponent(guint16 color_component);
55 : static guint16 convertToGdkColorComponent(int color_component);
56 : static GdkColor convertToGdkColor(nscolor color);
57 :
58 : static GtkColorSelection* WidgetGetColorSelection(GtkWidget* widget);
59 :
60 : void Update(GtkColorSelection* colorselection);
61 : void ReadValueFromColorSelection(GtkColorSelection* colorselection);
62 : #endif
63 :
64 : void Done(GtkWidget* dialog, gint response_id);
65 :
66 : nsCOMPtr<nsIWidget> mParentWidget;
67 : nsCOMPtr<nsIColorPickerShownCallback> mCallback;
68 : nsString mTitle;
69 : nsString mColor;
70 : nsString mInitialColor;
71 : };
72 :
73 : #endif // nsColorPicker_h__
|