1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* Screem: colourWizard.c,
* A GTK colour selector dialog to insert colours
*
* Copyright (C) 1999 David A Knight
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For contact information with the author of this source code please see
* the AUTHORS file. If there is no AUTHORS file present then check the
* about box under the help menu for a contact address
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <gmodule.h>
#include <gnome.h>
#include "site.h"
#include "page.h"
#include "editor.h"
extern GtkWidget *app;
extern Site *current_site;
extern Page *current_page;
static GtkWidget* create_dialog ();
void colourWizard();
static void closed( GtkWidget *widget, GdkEvent *event, gpointer data );
static void clicked( GtkWidget *widget, gint button, GtkColorSelection *cs );
/*********************************************************************/
G_MODULE_EXPORT const gchar*
g_module_check_init( GModule *module )
{
g_print("colourWizard: check-init\n");
return NULL;
}
/*********************************************************************/
G_MODULE_EXPORT void
g_module_unload( GModule *module )
{
g_print( "colourWizard: unloaded\n" );
}
/*********************************************************************/
G_MODULE_EXPORT void
init()
{
GtkWidget *toolbar;
GtkWidget *button;
GnomeUIInfo menuinfo[] = {
{
GNOME_APP_UI_ITEM, N_( "Colour..." ),
N_( "Insert a colour" ),
colourWizard, NULL, NULL,
GNOME_APP_PIXMAP_STOCK,
GNOME_STOCK_MENU_BLANK,
0,
GDK_CONTROL_MASK, NULL
},
GNOMEUIINFO_END
};
toolbar = gtk_object_get_data( GTK_OBJECT( app ), "wizardbar" );
/* place menu item after image under insert */
gnome_app_insert_menus( GNOME_APP( app ),
_("_Insert/"), menuinfo);
/* place a button on the wizards toolbar */
button = gnome_stock_new_with_icon( GNOME_STOCK_PIXMAP_COLORSELECTOR );
gtk_toolbar_append_item( GTK_TOOLBAR( toolbar ), "",
_("Colour Browser"), "", button ,
colourWizard, 0 );
g_print( "colourWizard: initialised\n" );
}
/*********************************************************************/
void colourWizard()
{
static GtkWidget *dialog = NULL;
Page *page;
if( current_site )
page = screem_site_get_current_page( current_site );
else
page = current_page;
g_return_if_fail( page != NULL );
if( dialog ) {
gdk_window_raise( dialog->window );
gdk_window_show( dialog->window );
return;
}
dialog = create_dialog();
gtk_object_set_data( GTK_OBJECT( dialog ), "dialog", &dialog );
gtk_widget_show_all( dialog );
}
/*********************************************************************/
static void closed( GtkWidget *widget, GdkEvent *event, gpointer data )
{
GtkWidget **dialog;
dialog = gtk_object_get_data( GTK_OBJECT( widget ), "dialog" );
*dialog = NULL;
}
/*********************************************************************/
static void clicked( GtkWidget *widget, gint button, GtkColorSelection *cs )
{
GtkWidget **dialog;
gint r, g, b;
gchar *text;
gint16 pos;
dialog = gtk_object_get_data( GTK_OBJECT( widget ), "dialog" );
if( button < 2 ) {
r = (cs->values[ 3 ] * 256) - 1; /* why do I need to -1 ? */
g = (cs->values[ 4 ] * 256);
b = (cs->values[ 5 ] * 256);
text = g_strdup_printf( "\"#%.2x%.2x%.2x\"", r, g, b );
pos = screem_editor_get_pos();
screem_editor_insert( pos, text );
g_free( text );
}
if( button == 1 ) /* apply */
return;
*dialog = NULL;
gtk_widget_destroy( widget );
}
/*********************************************************************/
static GtkWidget*
create_dialog ()
{
GtkWidget *dialog;
GtkWidget *colourSel;
dialog = gnome_dialog_new (_("Insert a colour"),
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_APPLY,
GNOME_STOCK_BUTTON_CLOSE,
NULL );
colourSel = gtk_color_selection_new();
gtk_box_pack_start( GTK_BOX( GNOME_DIALOG( dialog )->vbox ), colourSel,
TRUE, TRUE, GNOME_PAD );
gtk_signal_connect( GTK_OBJECT( dialog ), "clicked", clicked,
colourSel );
gtk_signal_connect(GTK_OBJECT( dialog ), "delete_event", closed, NULL);
return dialog;
}
|