* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB. If not,
- * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/* Color picker button for GNOME
*
#include "gtkbutton.h"
#include "gtkmain.h"
-#include "gtkalignment.h"
#include "gtkcolorchooser.h"
+#include "gtkcolorchooserprivate.h"
#include "gtkcolorchooserdialog.h"
#include "gtkdnd.h"
#include "gtkdrawingarea.h"
-#include "gtkframe.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#define CHECK_DARK (1.0 / 3.0)
#define CHECK_LIGHT (2.0 / 3.0)
+#define COLOR_SAMPLE_MARGIN 1
struct _GtkColorButtonPrivate
{
return button->priv->use_alpha && button->priv->rgba.alpha < 1;
}
-static cairo_pattern_t *
-gtk_color_button_get_checkered (void)
-{
- /* need to respect pixman's stride being a multiple of 4 */
- static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
- 0x00, 0xFF, 0x00, 0x00 };
- static cairo_surface_t *checkered = NULL;
- cairo_pattern_t *pattern;
-
- if (checkered == NULL)
- {
- checkered = cairo_image_surface_create_for_data (data,
- CAIRO_FORMAT_A8,
- 2, 2, 4);
- }
-
- pattern = cairo_pattern_create_for_surface (checkered);
- cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
- cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
-
- return pattern;
-}
-
/* Handle exposure events for the color picker's drawing area */
static gint
gtk_color_button_draw_cb (GtkWidget *widget,
cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
- checkered = gtk_color_button_get_checkered ();
+ checkered = _gtk_color_chooser_get_checkered_pattern ();
cairo_mask (cr, checkered);
cairo_pattern_destroy (checkered);
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
gdk_cairo_set_source_rgba (cr, &color);
- checkered = gtk_color_button_get_checkered ();
+ checkered = _gtk_color_chooser_get_checkered_pattern ();
cairo_mask (cr, checkered);
cairo_pattern_destroy (checkered);
}
static void
gtk_color_button_init (GtkColorButton *button)
{
- GtkWidget *alignment;
- GtkWidget *frame;
PangoLayout *layout;
PangoRectangle rect;
gtk_widget_push_composite_child ();
- alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
- gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
- gtk_container_add (GTK_CONTAINER (button), alignment);
- gtk_widget_show (alignment);
-
- frame = gtk_frame_new (NULL);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
- gtk_container_add (GTK_CONTAINER (alignment), frame);
- gtk_widget_show (frame);
-
- /* Just some widget we can hook to expose-event on */
- button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ button->priv->draw_area = gtk_drawing_area_new ();
+ g_object_set (button->priv->draw_area,
+ "margin-top", COLOR_SAMPLE_MARGIN,
+ "margin-bottom", COLOR_SAMPLE_MARGIN,
+ "margin-left", 16,
+ "margin-right", 16,
+ NULL);
layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
pango_layout_get_pixel_extents (layout, NULL, &rect);
g_object_unref (layout);
- gtk_widget_set_size_request (button->priv->draw_area, rect.width - 2, rect.height - 2);
+ gtk_widget_set_size_request (button->priv->draw_area,
+ rect.width, rect.height - 2 * COLOR_SAMPLE_MARGIN);
+
g_signal_connect (button->priv->draw_area, "draw",
G_CALLBACK (gtk_color_button_draw_cb), button);
- gtk_container_add (GTK_CONTAINER (frame), button->priv->draw_area);
+ gtk_container_add (GTK_CONTAINER (button), button->priv->draw_area);
gtk_widget_show (button->priv->draw_area);
button->priv->title = g_strdup (_("Pick a Color")); /* default title */