Added new files, the UI independant part of new image dialog.

Wed Aug 25 02:40:39 CDT 1999 Shawn T. Amundson <amundson@gimp.org>

        * app/image_new.[ch]: Added new files, the UI independant part of
          new image dialog.

        * app/file_new_dialog.[ch]: uses image_new stuff now.  Alot
          changed.  No UI changed.  Different behavior is a bug, as
          this is only for UI separation.

        * app/gimpimage.[ch]: Added gimp_image_get_width () and
          gimp_image_get_height ().

        * app/global_edit.c: Call a function in image_new instead of
          file_new_dialog for updating the status of the cut buffe.
This commit is contained in:
CDT 1999 Shawn T. Amundson 1999-08-26 04:39:21 +00:00 committed by Shawn Amundson
parent d418d18a97
commit c6eec63232
30 changed files with 1181 additions and 1159 deletions

View file

@ -1,3 +1,18 @@
Wed Aug 25 02:40:39 CDT 1999 Shawn T. Amundson <amundson@gimp.org>
* app/image_new.[ch]: Added new files, the UI independant part of
new image dialog.
* app/file_new_dialog.[ch]: uses image_new stuff now. Alot
changed. No UI changed. Different behavior is a bug, as
this is only for UI separation.
* app/gimpimage.[ch]: Added gimp_image_get_width () and
gimp_image_get_height ().
* app/global_edit.c: Call a function in image_new instead of
file_new_dialog for updating the status of the cut buffe.
Wed Aug 25 17:27:40 PDT 1999 Manish Singh <yosh@gimp.org> Wed Aug 25 17:27:40 PDT 1999 Manish Singh <yosh@gimp.org>
* Makefile.am * Makefile.am

View file

@ -234,6 +234,8 @@ gimp_SOURCES = \
hue_saturation.h \ hue_saturation.h \
image_map.c \ image_map.c \
image_map.h \ image_map.h \
image_new.c \
image_new.h \
image_render.c \ image_render.c \
image_render.h \ image_render.h \
indicator_area.c \ indicator_area.c \

View file

@ -19,7 +19,7 @@
#include "appenv.h" #include "appenv.h"
#include "actionarea.h" #include "actionarea.h"
#include "drawable.h" #include "drawable.h"
#include "file_new_dialog.h" #include "image_new.h"
#include "floating_sel.h" #include "floating_sel.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "gimage.h" #include "gimage.h"
@ -206,7 +206,7 @@ edit_cut (GImage *gimage,
cropped_cut = NULL; cropped_cut = NULL;
if (cut) if (cut)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer ();
/* end the group undo */ /* end the group undo */
@ -257,7 +257,7 @@ edit_copy (GImage *gimage,
cropped_copy = NULL; cropped_copy = NULL;
if(copy) if(copy)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer();
if (cropped_copy) if (cropped_copy)

View file

@ -19,7 +19,7 @@
#include "appenv.h" #include "appenv.h"
#include "actionarea.h" #include "actionarea.h"
#include "drawable.h" #include "drawable.h"
#include "file_new_dialog.h" #include "image_new.h"
#include "floating_sel.h" #include "floating_sel.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "gimage.h" #include "gimage.h"
@ -206,7 +206,7 @@ edit_cut (GImage *gimage,
cropped_cut = NULL; cropped_cut = NULL;
if (cut) if (cut)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer ();
/* end the group undo */ /* end the group undo */
@ -257,7 +257,7 @@ edit_copy (GImage *gimage,
cropped_copy = NULL; cropped_copy = NULL;
if(copy) if(copy)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer();
if (cropped_copy) if (cropped_copy)

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -15,17 +15,11 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "appenv.h"
#include "actionarea.h"
#include "file_new_dialog.h" #include "file_new_dialog.h"
#include "gimage.h"
#include "gimpcontext.h" #include "actionarea.h"
#include "gimprc.h" #include "gimprc.h"
#include "global_edit.h"
#include "interface.h"
#include "lc_dialog.h"
#include "plug_in.h"
#include "tile_manager_pvt.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "libgimp/gimpchainbutton.h" #include "libgimp/gimpchainbutton.h"
@ -33,8 +27,7 @@
#include "libgimp/gimpsizeentry.h" #include "libgimp/gimpsizeentry.h"
#include "libgimp/gimpintl.h" #include "libgimp/gimpintl.h"
typedef struct typedef struct {
{
GtkWidget *dlg; GtkWidget *dlg;
GtkWidget *confirm_dlg; GtkWidget *confirm_dlg;
@ -44,27 +37,16 @@ typedef struct
GtkWidget *resolution_se; GtkWidget *resolution_se;
GtkWidget *couple_resolutions; GtkWidget *couple_resolutions;
/* this should be a list */
GtkWidget *type_w[2]; GtkWidget *type_w[2];
GtkWidget *fill_type_w[4]; GtkWidget *fill_type_w[4];
gint width; GimpImageNewValues *values;
gint height; gdouble size;
GUnit unit; } NewImageInfo;
gdouble xresolution;
gdouble yresolution;
GUnit res_unit;
gdouble size; /* in bytes */
GimpImageBaseType type;
GimpFillType fill_type;
} NewImageValues;
/* new image local functions */ /* new image local functions */
static void file_new_create_image (NewImageValues *); static void file_new_confirm_dialog (NewImageInfo *);
static void file_new_confirm_dialog (NewImageValues *);
static gchar * file_new_print_size (gdouble);
static void file_new_ok_callback (GtkWidget *, gpointer); static void file_new_ok_callback (GtkWidget *, gpointer);
static void file_new_reset_callback (GtkWidget *, gpointer); static void file_new_reset_callback (GtkWidget *, gpointer);
@ -74,119 +56,43 @@ static void file_new_toggle_callback (GtkWidget *, gpointer);
static void file_new_resolution_callback (GtkWidget *, gpointer); static void file_new_resolution_callback (GtkWidget *, gpointer);
static void file_new_image_size_callback (GtkWidget *, gpointer); static void file_new_image_size_callback (GtkWidget *, gpointer);
/* static variables */
static gint last_width = 256;
static gint last_height = 256;
static GUnit last_unit = UNIT_INCH;
static gdouble last_xresolution = 72.0;
static gdouble last_yresolution = 72.0;
static GUnit last_res_unit = UNIT_INCH;
static GimpImageBaseType last_type = RGB;
static GimpFillType last_fill_type = BACKGROUND_FILL;
static gboolean last_new_image = FALSE;
static gboolean new_dialog_run = FALSE;
extern TileManager *global_buf;
/* functions */
static void
file_new_create_image (NewImageValues *vals)
{
GImage *gimage;
GDisplay *gdisplay;
Layer *layer;
GimpImageType type;
last_width = vals->width;
last_height = vals->height;
last_type = vals->type;
last_fill_type = vals->fill_type;
last_xresolution = vals->xresolution;
last_yresolution = vals->yresolution;
last_unit = vals->unit;
last_res_unit = vals->res_unit;
last_new_image = TRUE;
switch (vals->fill_type)
{
case BACKGROUND_FILL:
case FOREGROUND_FILL:
case WHITE_FILL:
type = (vals->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (vals->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_IMAGE;
break;
}
gimage = gimage_new (vals->width, vals->height, vals->type);
gimp_image_set_resolution (gimage, vals->xresolution, vals->yresolution);
gimp_image_set_unit (gimage, vals->unit);
/* Make the background (or first) layer */
layer = layer_new (gimage, gimage->width, gimage->height,
type, _("Background"), OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
/* add the new layer to the gimage */
gimage_disable_undo (gimage);
gimage_add_layer (gimage, layer, 0);
gimage_enable_undo (gimage);
drawable_fill (GIMP_DRAWABLE(layer), vals->fill_type);
gimage_clean_all (gimage);
gdisplay = gdisplay_new (gimage, 0x0101);
gimp_context_set_display (gimp_context_get_user (), gdisplay);
}
g_free (vals);
}
static void static void
file_new_ok_callback (GtkWidget *widget, file_new_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
GimpImageNewValues *values;
vals = data; info = (NewImageInfo*) data;
values = info->values;
/* get the image size in pixels */ /* get the image size in pixels */
vals->width = (int) values->width = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
vals->height = (int) values->height = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
/* get the resolution in dpi */ /* get the resolution in dpi */
vals->xresolution = values->xresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 0); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0);
vals->yresolution = values->yresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 1); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1);
/* get the units */ /* get the units */
vals->unit = values->unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->size_se));
vals->res_unit = values->res_unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->resolution_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->resolution_se));
if (vals->size > max_new_image_size) if (info->size > max_new_image_size)
{ {
file_new_confirm_dialog (vals); file_new_confirm_dialog (info);
} }
else else
{ {
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
file_new_create_image (vals); image_new_create_image (values);
image_new_values_free (values);
} }
} }
@ -194,40 +100,40 @@ static void
file_new_reset_callback (GtkWidget *widget, file_new_reset_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_signal_handler_block_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_block_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION); ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, default_xresolution); 0, default_xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, default_yresolution); 1, default_yresolution);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->resolution_se),
default_resolution_units); default_resolution_units);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_unblock_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
0, default_xresolution, TRUE); 0, default_xresolution, TRUE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
1, default_yresolution, TRUE); 1, default_yresolution, TRUE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
0, default_width); 0, default_width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
1, default_height); 1, default_height);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->size_se),
default_units); default_units);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vals->type_w[default_type]), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->type_w[default_type]),
TRUE); TRUE);
gtk_toggle_button_set_active gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (vals->fill_type_w[BACKGROUND_FILL]), TRUE); (GTK_TOGGLE_BUTTON (info->fill_type_w[BACKGROUND_FILL]), TRUE);
} }
static gint static gint
@ -243,44 +149,53 @@ static void
file_new_cancel_callback (GtkWidget *widget, file_new_cancel_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
g_free (vals); image_new_values_free(info->values);
g_free (info);
} }
/* local callbacks of file_new_confirm_dialog() */ /* local callbacks of file_new_confirm_dialog() */
static void static void
file_new_confirm_dialog_ok_callback (GtkWidget *widget, file_new_confirm_dialog_ok_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
gtk_widget_destroy (vals->dlg);
file_new_create_image (vals); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
gtk_widget_destroy (info->dlg);
image_new_create_image (info->values);
} }
static void static void
file_new_confirm_dialog_cancel_callback (GtkWidget *widget, file_new_confirm_dialog_cancel_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
vals->confirm_dlg = NULL;
gtk_widget_set_sensitive (vals->dlg, TRUE); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
info->confirm_dlg = NULL;
gtk_widget_set_sensitive (info->dlg, TRUE);
} }
static gint static gint
file_new_confirm_dialog_delete_callback (GtkWidget *widget, file_new_confirm_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
NewImageValues *vals) gpointer data)
{ {
file_new_confirm_dialog_cancel_callback (widget, vals); file_new_confirm_dialog_cancel_callback (widget, data);
return TRUE; return TRUE;
} }
static void static void
file_new_confirm_dialog (NewImageValues *vals) file_new_confirm_dialog (NewImageInfo *info)
{ {
GtkWidget *label; GtkWidget *label;
gchar *size; gchar *size;
@ -295,24 +210,27 @@ file_new_confirm_dialog (NewImageValues *vals)
(ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL } (ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL }
}; };
gtk_widget_set_sensitive (vals->dlg, FALSE); gtk_widget_set_sensitive (info->dlg, FALSE);
vals->confirm_dlg = gtk_dialog_new (); info->confirm_dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->confirm_dlg), gtk_window_set_wmclass (GTK_WINDOW (info->confirm_dlg),
"confirm_size", "Gimp"); "confirm_size", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->confirm_dlg), _("Confirm Image Size")); gtk_window_set_title (GTK_WINDOW (info->confirm_dlg), _("Confirm Image Size"));
gtk_window_set_policy (GTK_WINDOW (vals->confirm_dlg), FALSE, FALSE, FALSE); gtk_window_set_policy (GTK_WINDOW (info->confirm_dlg), FALSE, FALSE, FALSE);
gtk_window_position (GTK_WINDOW (vals->confirm_dlg), GTK_WIN_POS_MOUSE); gtk_window_position (GTK_WINDOW (info->confirm_dlg), GTK_WIN_POS_MOUSE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->confirm_dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->confirm_dlg), "delete_event",
(GtkSignalFunc) file_new_confirm_dialog_delete_callback, (GtkSignalFunc) file_new_confirm_dialog_delete_callback,
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
build_action_area (GTK_DIALOG (vals->confirm_dlg), action_items, 2, 0); build_action_area (GTK_DIALOG (info->confirm_dlg), action_items, 2, 0);
size = image_new_get_size_string (info->size);
max_size = image_new_get_size_string (max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image which\n" text = g_strdup_printf (_("You are trying to create an image which\n"
"has an initial size of %s.\n\n" "has an initial size of %s.\n\n"
@ -323,11 +241,10 @@ file_new_confirm_dialog (NewImageValues *vals)
"increase the \"Maximum Image Size\"\n" "increase the \"Maximum Image Size\"\n"
"setting (currently %s) in the\n" "setting (currently %s) in the\n"
"preferences dialog."), "preferences dialog."),
size = file_new_print_size (vals->size), size, max_size);
max_size = file_new_print_size (max_new_image_size));
label = gtk_label_new (text); label = gtk_label_new (text);
gtk_misc_set_padding (GTK_MISC (label), 6, 6); gtk_misc_set_padding (GTK_MISC (label), 6, 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->confirm_dlg)->vbox), label, gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->confirm_dlg)->vbox), label,
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_widget_show (label); gtk_widget_show (label);
@ -335,7 +252,7 @@ file_new_confirm_dialog (NewImageValues *vals)
g_free (max_size); g_free (max_size);
g_free (size); g_free (size);
gtk_widget_show (vals->confirm_dlg); gtk_widget_show (info->confirm_dlg);
} }
static void static void
@ -355,23 +272,23 @@ static void
file_new_resolution_callback (GtkWidget *widget, file_new_resolution_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
static gdouble xres = 0.0; static gdouble xres = 0.0;
static gdouble yres = 0.0; static gdouble yres = 0.0;
gdouble new_xres; gdouble new_xres;
gdouble new_yres; gdouble new_yres;
vals = data; info = (NewImageInfo*) data;
new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0); new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1); new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);
if (gimp_chain_button_get_active if (gimp_chain_button_get_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions))) (GIMP_CHAIN_BUTTON (info->couple_resolutions)))
{ {
gtk_signal_handler_block_by_data gtk_signal_handler_block_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
if (new_xres != xres) if (new_xres != xres)
{ {
@ -386,7 +303,7 @@ file_new_resolution_callback (GtkWidget *widget,
} }
gtk_signal_handler_unblock_by_data gtk_signal_handler_unblock_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
} }
else else
{ {
@ -396,61 +313,38 @@ file_new_resolution_callback (GtkWidget *widget,
yres = new_yres; yres = new_yres;
} }
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
xres, FALSE); xres, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
yres, FALSE); yres, FALSE);
file_new_image_size_callback (widget, data); file_new_image_size_callback (widget, data);
} }
static gchar *
file_new_print_size (gdouble size)
{
if (size < 4096)
return g_strdup_printf (_("%d Bytes"), (gint) size);
else if (size < 1024 * 10)
return g_strdup_printf (_("%.2f KB"), size / 1024);
else if (size < 1024 * 100)
return g_strdup_printf (_("%.1f KB"), size / 1024);
else if (size < 1024 * 1024)
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
else if (size < 1024 * 1024 * 10)
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
else
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
}
static void static void
file_new_image_size_callback (GtkWidget *widget, file_new_image_size_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
gdouble width, height;
gdouble width, height, size;
gchar *text; gchar *text;
gchar *label; gchar *label;
vals = data; info = (NewImageInfo*) data;
width = (gdouble) (gint) width = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
height = (gdouble) (gint) height = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
size = info->size = image_new_calculate_size (info->values);
width * height *
((vals->type == RGB ? 3 : 1) + /* bytes per pixel */
(vals->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
label = g_strdup_printf (_("Image Size: %s"), label = g_strdup_printf (_("Image Size: %s"),
text = file_new_print_size (size)); text = image_new_get_size_string (info->size));
gtk_frame_set_label (GTK_FRAME (vals->size_frame), label); gtk_frame_set_label (GTK_FRAME (info->size_frame), label);
g_free (label); g_free (label);
g_free (text); g_free (text);
vals->size = size;
} }
void void
@ -459,7 +353,27 @@ file_new_cmd_callback (GtkWidget *widget,
guint callback_action) guint callback_action)
{ {
GDisplay *gdisp; GDisplay *gdisp;
NewImageValues *vals; GimpImage *image = NULL;
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
{
gdisp = gdisplay_active ();
if (gdisp)
image = gdisp->gimage;
}
image_new_create_window (NULL, image);
}
void
ui_new_image_window_create (const GimpImageNewValues *values_orig)
{
NewImageInfo *info;
GimpImageNewValues *values;
GtkWidget *top_vbox; GtkWidget *top_vbox;
GtkWidget *hbox; GtkWidget *hbox;
@ -475,7 +389,7 @@ file_new_cmd_callback (GtkWidget *widget,
GtkWidget *spinbutton2; GtkWidget *spinbutton2;
GtkWidget *radio_box; GtkWidget *radio_box;
GSList *group; GSList *group;
gint i; GList *list;
static ActionAreaItem action_items[] = static ActionAreaItem action_items[] =
{ {
@ -484,121 +398,44 @@ file_new_cmd_callback (GtkWidget *widget,
{ N_("Cancel"), file_new_cancel_callback, NULL, NULL } { N_("Cancel"), file_new_cancel_callback, NULL, NULL }
}; };
static gchar *type_names[] = info = g_new (NewImageInfo, 1);
{ info->values = values = image_new_values_new (values_orig);
N_("RGB"),
N_("Grayscale")
};
static gint ntypes = sizeof (type_names) / sizeof (type_names[0]);
static gchar *fill_type_names[] = info->confirm_dlg = NULL;
{ info->size = 0.0;
N_("Foreground"),
N_("Background"),
N_("White"),
N_("Transparent")
};
static gint nfill_types =
sizeof (fill_type_names) / sizeof (fill_type_names[0]);
if(!new_dialog_run) info->dlg = gtk_dialog_new ();
{ gtk_window_set_wmclass (GTK_WINDOW (info->dlg), "new_image", "Gimp");
/* all from gimprc */ gtk_window_set_title (GTK_WINDOW (info->dlg), _("New Image"));
last_width = default_width; gtk_window_set_position (GTK_WINDOW (info->dlg), GTK_WIN_POS_MOUSE);
last_height = default_height; gtk_window_set_policy(GTK_WINDOW (info->dlg), FALSE, FALSE, TRUE);
last_unit = default_units;
last_xresolution = default_xresolution;
last_yresolution = default_yresolution;
last_res_unit = default_resolution_units;
last_type = default_type;
new_dialog_run = TRUE;
}
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
gdisp = gdisplay_active ();
else
gdisp = NULL;
vals = g_malloc (sizeof (NewImageValues));
vals->confirm_dlg = NULL;
vals->size = 0.0;
vals->res_unit = last_res_unit;
vals->fill_type = last_fill_type;
if (gdisp)
{
vals->width = gdisp->gimage->width;
vals->height = gdisp->gimage->height;
vals->unit = gdisp->gimage->unit;
vals->xresolution = gdisp->gimage->xresolution;
vals->yresolution = gdisp->gimage->yresolution;
vals->type = gimage_base_type (gdisp->gimage);
}
else
{
vals->width = last_width;
vals->height = last_height;
vals->unit = last_unit;
vals->xresolution = last_xresolution;
vals->yresolution = last_yresolution;
vals->type = last_type;
}
if (vals->type == INDEXED)
vals->type = RGB; /* no indexed images */
/* If a cut buffer exists, default to using its size for the new image
* also check to see if a new_image has been opened
*/
if(global_buf && !last_new_image)
{
vals->width = global_buf->width;
vals->height = global_buf->height;
}
vals->dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->dlg), "new_image", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->dlg), _("New Image"));
gtk_window_set_position (GTK_WINDOW (vals->dlg), GTK_WIN_POS_MOUSE);
gtk_window_set_policy(GTK_WINDOW (vals->dlg), FALSE, FALSE, TRUE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->dlg), "delete_event",
GTK_SIGNAL_FUNC (file_new_delete_callback), GTK_SIGNAL_FUNC (file_new_delete_callback),
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
action_items[2].user_data = vals; action_items[2].user_data = info;
build_action_area (GTK_DIALOG (vals->dlg), action_items, 3, 2); build_action_area (GTK_DIALOG (info->dlg), action_items, 3, 2);
/* vbox holding the rest of the dialog */ /* vbox holding the rest of the dialog */
top_vbox = gtk_vbox_new (FALSE, 2); top_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4); gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->dlg)->vbox), gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->dlg)->vbox),
top_vbox, TRUE, TRUE, 0); top_vbox, TRUE, TRUE, 0);
gtk_widget_show (top_vbox); gtk_widget_show (top_vbox);
/* Image size frame */ /* Image size frame */
vals->size_frame = gtk_frame_new (NULL); info->size_frame = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (top_vbox), vals->size_frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (top_vbox), info->size_frame, FALSE, FALSE, 0);
gtk_widget_show (vals->size_frame); gtk_widget_show (info->size_frame);
vbox = gtk_vbox_new (FALSE, 0); vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (vals->size_frame), vbox); gtk_container_add (GTK_CONTAINER (info->size_frame), vbox);
gtk_widget_show (vbox); gtk_widget_show (vbox);
table = gtk_table_new (7, 2, FALSE); table = gtk_table_new (7, 2, FALSE);
@ -644,12 +481,12 @@ file_new_cmd_callback (GtkWidget *widget,
/* create the sizeentry which keeps it all together */ /* create the sizeentry which keeps it all together */
abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0); abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5); gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5);
vals->size_se = info->size_se =
gimp_size_entry_new (0, vals->unit, "%a", FALSE, FALSE, TRUE, 75, gimp_size_entry_new (0, values->unit, "%a", FALSE, FALSE, TRUE, 75,
GIMP_SIZE_ENTRY_UPDATE_SIZE); GIMP_SIZE_ENTRY_UPDATE_SIZE);
gtk_table_set_col_spacing (GTK_TABLE (vals->size_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->size_se), 1, 2);
gtk_container_add (GTK_CONTAINER (abox), vals->size_se); gtk_container_add (GTK_CONTAINER (abox), info->size_se);
gtk_widget_show (vals->size_se); gtk_widget_show (info->size_se);
gtk_widget_show (abox); gtk_widget_show (abox);
/* height in units */ /* height in units */
@ -660,7 +497,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "height in units" spinbutton to the sizeentry */ /* add the "height in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 2, 3); 0, 1, 2, 3);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -684,7 +521,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (hbox); gtk_widget_show (hbox);
/* register the height spinbuttons with the sizeentry */ /* register the height spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
@ -696,7 +533,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "width in units" spinbutton to the sizeentry */ /* add the "width in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 1, 2); 0, 1, 1, 2);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -715,33 +552,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (abox); gtk_widget_show (abox);
/* register the width spinbuttons with the sizeentry */ /* register the width spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
/* initialize the sizeentry */ /* initialize the sizeentry */
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
vals->xresolution, FALSE); values->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
vals->yresolution, FALSE); values->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 0,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 1,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 0, vals->width); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 0, values->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 1, vals->height); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 1, values->height);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "refval_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "refval_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "value_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
/* initialize the size label */ /* initialize the size label */
file_new_image_size_callback (vals->size_se, vals); file_new_image_size_callback (info->size_se, info);
/* the resolution labels */ /* the resolution labels */
label = gtk_label_new (_("Resolution X:")); label = gtk_label_new (_("Resolution X:"));
@ -764,44 +601,44 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
vals->resolution_se = info->resolution_se =
gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"), gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"),
FALSE, FALSE, FALSE, 75, FALSE, FALSE, FALSE, 75,
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION); GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 1, 2);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 2, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 2, 2);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->resolution_se),
GTK_SPIN_BUTTON (spinbutton), NULL); GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->resolution_se), spinbutton,
1, 2, 0, 1); 1, 2, 0, 1);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
gtk_table_attach (GTK_TABLE (table), vals->resolution_se, 1, 2, 5, 7, gtk_table_attach (GTK_TABLE (table), info->resolution_se, 1, 2, 5, 7,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (vals->resolution_se); gtk_widget_show (info->resolution_se);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
0, GIMP_MIN_RESOLUTION, 0, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
1, GIMP_MIN_RESOLUTION, 1, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, vals->xresolution); 0, values->xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, vals->yresolution); 1, values->yresolution);
gtk_signal_connect (GTK_OBJECT (vals->resolution_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->resolution_se), "value_changed",
(GtkSignalFunc) file_new_resolution_callback, vals); (GtkSignalFunc) file_new_resolution_callback, info);
/* the resolution chainbutton */ /* the resolution chainbutton */
vals->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT); info->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (vals->xresolution - vals->yresolution) < GIMP_MIN_RESOLUTION); ABS (values->xresolution - values->yresolution) < GIMP_MIN_RESOLUTION);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), gtk_table_attach_defaults (GTK_TABLE (info->resolution_se),
vals->couple_resolutions, 2, 3, 0, 2); info->couple_resolutions, 2, 3, 0, 2);
gtk_widget_show (vals->couple_resolutions); gtk_widget_show (info->couple_resolutions);
/* hbox containing the Image type and fill type frames */ /* hbox containing the Image type and fill type frames */
hbox = gtk_hbox_new (FALSE, 2); hbox = gtk_hbox_new (FALSE, 2);
@ -820,22 +657,29 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < ntypes; i++) list = g_list_first (image_new_get_image_base_type_names ());
while (list)
{ {
button = gtk_radio_button_new_with_label (group, gettext (type_names[i])); GimpImageBaseTypeName *name_info;
name_info = (GimpImageBaseTypeName*) list->data;
button = gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->type); &values->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->type == i) if (values->type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->type_w[i] = button; info->type_w[name_info->type] = button;
list = g_list_next (list);
} }
/* frame for Fill Type */ /* frame for Fill Type */
@ -849,34 +693,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < nfill_types; i++) list = g_list_first (image_new_get_fill_type_names ());
while (list)
{ {
GimpFillTypeName *name_info;
name_info = (GimpFillTypeName*) list->data;
button = button =
gtk_radio_button_new_with_label (group, gettext (fill_type_names[i])); gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->fill_type); &values->fill_type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->fill_type == i) if (values->fill_type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->fill_type_w[i] = button; info->fill_type_w[name_info->type] = button;
list = g_list_next (list);
} }
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (info->size_se));
gtk_widget_show (vals->dlg); gtk_widget_show (info->dlg);
}
void
file_new_reset_current_cut_buffer ()
{
/* this function just changes the status of last_image_new
so i can if theres been a cut/copy since the last file new */
last_new_image = FALSE;
} }

View file

@ -3,10 +3,12 @@
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "image_new.h"
void file_new_cmd_callback (GtkWidget *widget, void file_new_cmd_callback (GtkWidget *widget,
gpointer callback_data, gpointer callback_data,
guint callback_action); guint callback_action);
void file_new_reset_current_cut_buffer (); void ui_new_image_window_create (const GimpImageNewValues *values);
#endif /* __FILE_NEW_DIALOG_H_H__ */ #endif /* __FILE_NEW_DIALOG_H_H__ */

View file

@ -15,17 +15,11 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "appenv.h"
#include "actionarea.h"
#include "file_new_dialog.h" #include "file_new_dialog.h"
#include "gimage.h"
#include "gimpcontext.h" #include "actionarea.h"
#include "gimprc.h" #include "gimprc.h"
#include "global_edit.h"
#include "interface.h"
#include "lc_dialog.h"
#include "plug_in.h"
#include "tile_manager_pvt.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "libgimp/gimpchainbutton.h" #include "libgimp/gimpchainbutton.h"
@ -33,8 +27,7 @@
#include "libgimp/gimpsizeentry.h" #include "libgimp/gimpsizeentry.h"
#include "libgimp/gimpintl.h" #include "libgimp/gimpintl.h"
typedef struct typedef struct {
{
GtkWidget *dlg; GtkWidget *dlg;
GtkWidget *confirm_dlg; GtkWidget *confirm_dlg;
@ -44,27 +37,16 @@ typedef struct
GtkWidget *resolution_se; GtkWidget *resolution_se;
GtkWidget *couple_resolutions; GtkWidget *couple_resolutions;
/* this should be a list */
GtkWidget *type_w[2]; GtkWidget *type_w[2];
GtkWidget *fill_type_w[4]; GtkWidget *fill_type_w[4];
gint width; GimpImageNewValues *values;
gint height; gdouble size;
GUnit unit; } NewImageInfo;
gdouble xresolution;
gdouble yresolution;
GUnit res_unit;
gdouble size; /* in bytes */
GimpImageBaseType type;
GimpFillType fill_type;
} NewImageValues;
/* new image local functions */ /* new image local functions */
static void file_new_create_image (NewImageValues *); static void file_new_confirm_dialog (NewImageInfo *);
static void file_new_confirm_dialog (NewImageValues *);
static gchar * file_new_print_size (gdouble);
static void file_new_ok_callback (GtkWidget *, gpointer); static void file_new_ok_callback (GtkWidget *, gpointer);
static void file_new_reset_callback (GtkWidget *, gpointer); static void file_new_reset_callback (GtkWidget *, gpointer);
@ -74,119 +56,43 @@ static void file_new_toggle_callback (GtkWidget *, gpointer);
static void file_new_resolution_callback (GtkWidget *, gpointer); static void file_new_resolution_callback (GtkWidget *, gpointer);
static void file_new_image_size_callback (GtkWidget *, gpointer); static void file_new_image_size_callback (GtkWidget *, gpointer);
/* static variables */
static gint last_width = 256;
static gint last_height = 256;
static GUnit last_unit = UNIT_INCH;
static gdouble last_xresolution = 72.0;
static gdouble last_yresolution = 72.0;
static GUnit last_res_unit = UNIT_INCH;
static GimpImageBaseType last_type = RGB;
static GimpFillType last_fill_type = BACKGROUND_FILL;
static gboolean last_new_image = FALSE;
static gboolean new_dialog_run = FALSE;
extern TileManager *global_buf;
/* functions */
static void
file_new_create_image (NewImageValues *vals)
{
GImage *gimage;
GDisplay *gdisplay;
Layer *layer;
GimpImageType type;
last_width = vals->width;
last_height = vals->height;
last_type = vals->type;
last_fill_type = vals->fill_type;
last_xresolution = vals->xresolution;
last_yresolution = vals->yresolution;
last_unit = vals->unit;
last_res_unit = vals->res_unit;
last_new_image = TRUE;
switch (vals->fill_type)
{
case BACKGROUND_FILL:
case FOREGROUND_FILL:
case WHITE_FILL:
type = (vals->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (vals->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_IMAGE;
break;
}
gimage = gimage_new (vals->width, vals->height, vals->type);
gimp_image_set_resolution (gimage, vals->xresolution, vals->yresolution);
gimp_image_set_unit (gimage, vals->unit);
/* Make the background (or first) layer */
layer = layer_new (gimage, gimage->width, gimage->height,
type, _("Background"), OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
/* add the new layer to the gimage */
gimage_disable_undo (gimage);
gimage_add_layer (gimage, layer, 0);
gimage_enable_undo (gimage);
drawable_fill (GIMP_DRAWABLE(layer), vals->fill_type);
gimage_clean_all (gimage);
gdisplay = gdisplay_new (gimage, 0x0101);
gimp_context_set_display (gimp_context_get_user (), gdisplay);
}
g_free (vals);
}
static void static void
file_new_ok_callback (GtkWidget *widget, file_new_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
GimpImageNewValues *values;
vals = data; info = (NewImageInfo*) data;
values = info->values;
/* get the image size in pixels */ /* get the image size in pixels */
vals->width = (int) values->width = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
vals->height = (int) values->height = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
/* get the resolution in dpi */ /* get the resolution in dpi */
vals->xresolution = values->xresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 0); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0);
vals->yresolution = values->yresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 1); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1);
/* get the units */ /* get the units */
vals->unit = values->unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->size_se));
vals->res_unit = values->res_unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->resolution_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->resolution_se));
if (vals->size > max_new_image_size) if (info->size > max_new_image_size)
{ {
file_new_confirm_dialog (vals); file_new_confirm_dialog (info);
} }
else else
{ {
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
file_new_create_image (vals); image_new_create_image (values);
image_new_values_free (values);
} }
} }
@ -194,40 +100,40 @@ static void
file_new_reset_callback (GtkWidget *widget, file_new_reset_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_signal_handler_block_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_block_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION); ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, default_xresolution); 0, default_xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, default_yresolution); 1, default_yresolution);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->resolution_se),
default_resolution_units); default_resolution_units);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_unblock_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
0, default_xresolution, TRUE); 0, default_xresolution, TRUE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
1, default_yresolution, TRUE); 1, default_yresolution, TRUE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
0, default_width); 0, default_width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
1, default_height); 1, default_height);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->size_se),
default_units); default_units);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vals->type_w[default_type]), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->type_w[default_type]),
TRUE); TRUE);
gtk_toggle_button_set_active gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (vals->fill_type_w[BACKGROUND_FILL]), TRUE); (GTK_TOGGLE_BUTTON (info->fill_type_w[BACKGROUND_FILL]), TRUE);
} }
static gint static gint
@ -243,44 +149,53 @@ static void
file_new_cancel_callback (GtkWidget *widget, file_new_cancel_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
g_free (vals); image_new_values_free(info->values);
g_free (info);
} }
/* local callbacks of file_new_confirm_dialog() */ /* local callbacks of file_new_confirm_dialog() */
static void static void
file_new_confirm_dialog_ok_callback (GtkWidget *widget, file_new_confirm_dialog_ok_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
gtk_widget_destroy (vals->dlg);
file_new_create_image (vals); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
gtk_widget_destroy (info->dlg);
image_new_create_image (info->values);
} }
static void static void
file_new_confirm_dialog_cancel_callback (GtkWidget *widget, file_new_confirm_dialog_cancel_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
vals->confirm_dlg = NULL;
gtk_widget_set_sensitive (vals->dlg, TRUE); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
info->confirm_dlg = NULL;
gtk_widget_set_sensitive (info->dlg, TRUE);
} }
static gint static gint
file_new_confirm_dialog_delete_callback (GtkWidget *widget, file_new_confirm_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
NewImageValues *vals) gpointer data)
{ {
file_new_confirm_dialog_cancel_callback (widget, vals); file_new_confirm_dialog_cancel_callback (widget, data);
return TRUE; return TRUE;
} }
static void static void
file_new_confirm_dialog (NewImageValues *vals) file_new_confirm_dialog (NewImageInfo *info)
{ {
GtkWidget *label; GtkWidget *label;
gchar *size; gchar *size;
@ -295,24 +210,27 @@ file_new_confirm_dialog (NewImageValues *vals)
(ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL } (ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL }
}; };
gtk_widget_set_sensitive (vals->dlg, FALSE); gtk_widget_set_sensitive (info->dlg, FALSE);
vals->confirm_dlg = gtk_dialog_new (); info->confirm_dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->confirm_dlg), gtk_window_set_wmclass (GTK_WINDOW (info->confirm_dlg),
"confirm_size", "Gimp"); "confirm_size", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->confirm_dlg), _("Confirm Image Size")); gtk_window_set_title (GTK_WINDOW (info->confirm_dlg), _("Confirm Image Size"));
gtk_window_set_policy (GTK_WINDOW (vals->confirm_dlg), FALSE, FALSE, FALSE); gtk_window_set_policy (GTK_WINDOW (info->confirm_dlg), FALSE, FALSE, FALSE);
gtk_window_position (GTK_WINDOW (vals->confirm_dlg), GTK_WIN_POS_MOUSE); gtk_window_position (GTK_WINDOW (info->confirm_dlg), GTK_WIN_POS_MOUSE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->confirm_dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->confirm_dlg), "delete_event",
(GtkSignalFunc) file_new_confirm_dialog_delete_callback, (GtkSignalFunc) file_new_confirm_dialog_delete_callback,
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
build_action_area (GTK_DIALOG (vals->confirm_dlg), action_items, 2, 0); build_action_area (GTK_DIALOG (info->confirm_dlg), action_items, 2, 0);
size = image_new_get_size_string (info->size);
max_size = image_new_get_size_string (max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image which\n" text = g_strdup_printf (_("You are trying to create an image which\n"
"has an initial size of %s.\n\n" "has an initial size of %s.\n\n"
@ -323,11 +241,10 @@ file_new_confirm_dialog (NewImageValues *vals)
"increase the \"Maximum Image Size\"\n" "increase the \"Maximum Image Size\"\n"
"setting (currently %s) in the\n" "setting (currently %s) in the\n"
"preferences dialog."), "preferences dialog."),
size = file_new_print_size (vals->size), size, max_size);
max_size = file_new_print_size (max_new_image_size));
label = gtk_label_new (text); label = gtk_label_new (text);
gtk_misc_set_padding (GTK_MISC (label), 6, 6); gtk_misc_set_padding (GTK_MISC (label), 6, 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->confirm_dlg)->vbox), label, gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->confirm_dlg)->vbox), label,
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_widget_show (label); gtk_widget_show (label);
@ -335,7 +252,7 @@ file_new_confirm_dialog (NewImageValues *vals)
g_free (max_size); g_free (max_size);
g_free (size); g_free (size);
gtk_widget_show (vals->confirm_dlg); gtk_widget_show (info->confirm_dlg);
} }
static void static void
@ -355,23 +272,23 @@ static void
file_new_resolution_callback (GtkWidget *widget, file_new_resolution_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
static gdouble xres = 0.0; static gdouble xres = 0.0;
static gdouble yres = 0.0; static gdouble yres = 0.0;
gdouble new_xres; gdouble new_xres;
gdouble new_yres; gdouble new_yres;
vals = data; info = (NewImageInfo*) data;
new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0); new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1); new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);
if (gimp_chain_button_get_active if (gimp_chain_button_get_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions))) (GIMP_CHAIN_BUTTON (info->couple_resolutions)))
{ {
gtk_signal_handler_block_by_data gtk_signal_handler_block_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
if (new_xres != xres) if (new_xres != xres)
{ {
@ -386,7 +303,7 @@ file_new_resolution_callback (GtkWidget *widget,
} }
gtk_signal_handler_unblock_by_data gtk_signal_handler_unblock_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
} }
else else
{ {
@ -396,61 +313,38 @@ file_new_resolution_callback (GtkWidget *widget,
yres = new_yres; yres = new_yres;
} }
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
xres, FALSE); xres, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
yres, FALSE); yres, FALSE);
file_new_image_size_callback (widget, data); file_new_image_size_callback (widget, data);
} }
static gchar *
file_new_print_size (gdouble size)
{
if (size < 4096)
return g_strdup_printf (_("%d Bytes"), (gint) size);
else if (size < 1024 * 10)
return g_strdup_printf (_("%.2f KB"), size / 1024);
else if (size < 1024 * 100)
return g_strdup_printf (_("%.1f KB"), size / 1024);
else if (size < 1024 * 1024)
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
else if (size < 1024 * 1024 * 10)
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
else
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
}
static void static void
file_new_image_size_callback (GtkWidget *widget, file_new_image_size_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
gdouble width, height;
gdouble width, height, size;
gchar *text; gchar *text;
gchar *label; gchar *label;
vals = data; info = (NewImageInfo*) data;
width = (gdouble) (gint) width = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
height = (gdouble) (gint) height = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
size = info->size = image_new_calculate_size (info->values);
width * height *
((vals->type == RGB ? 3 : 1) + /* bytes per pixel */
(vals->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
label = g_strdup_printf (_("Image Size: %s"), label = g_strdup_printf (_("Image Size: %s"),
text = file_new_print_size (size)); text = image_new_get_size_string (info->size));
gtk_frame_set_label (GTK_FRAME (vals->size_frame), label); gtk_frame_set_label (GTK_FRAME (info->size_frame), label);
g_free (label); g_free (label);
g_free (text); g_free (text);
vals->size = size;
} }
void void
@ -459,7 +353,27 @@ file_new_cmd_callback (GtkWidget *widget,
guint callback_action) guint callback_action)
{ {
GDisplay *gdisp; GDisplay *gdisp;
NewImageValues *vals; GimpImage *image = NULL;
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
{
gdisp = gdisplay_active ();
if (gdisp)
image = gdisp->gimage;
}
image_new_create_window (NULL, image);
}
void
ui_new_image_window_create (const GimpImageNewValues *values_orig)
{
NewImageInfo *info;
GimpImageNewValues *values;
GtkWidget *top_vbox; GtkWidget *top_vbox;
GtkWidget *hbox; GtkWidget *hbox;
@ -475,7 +389,7 @@ file_new_cmd_callback (GtkWidget *widget,
GtkWidget *spinbutton2; GtkWidget *spinbutton2;
GtkWidget *radio_box; GtkWidget *radio_box;
GSList *group; GSList *group;
gint i; GList *list;
static ActionAreaItem action_items[] = static ActionAreaItem action_items[] =
{ {
@ -484,121 +398,44 @@ file_new_cmd_callback (GtkWidget *widget,
{ N_("Cancel"), file_new_cancel_callback, NULL, NULL } { N_("Cancel"), file_new_cancel_callback, NULL, NULL }
}; };
static gchar *type_names[] = info = g_new (NewImageInfo, 1);
{ info->values = values = image_new_values_new (values_orig);
N_("RGB"),
N_("Grayscale")
};
static gint ntypes = sizeof (type_names) / sizeof (type_names[0]);
static gchar *fill_type_names[] = info->confirm_dlg = NULL;
{ info->size = 0.0;
N_("Foreground"),
N_("Background"),
N_("White"),
N_("Transparent")
};
static gint nfill_types =
sizeof (fill_type_names) / sizeof (fill_type_names[0]);
if(!new_dialog_run) info->dlg = gtk_dialog_new ();
{ gtk_window_set_wmclass (GTK_WINDOW (info->dlg), "new_image", "Gimp");
/* all from gimprc */ gtk_window_set_title (GTK_WINDOW (info->dlg), _("New Image"));
last_width = default_width; gtk_window_set_position (GTK_WINDOW (info->dlg), GTK_WIN_POS_MOUSE);
last_height = default_height; gtk_window_set_policy(GTK_WINDOW (info->dlg), FALSE, FALSE, TRUE);
last_unit = default_units;
last_xresolution = default_xresolution;
last_yresolution = default_yresolution;
last_res_unit = default_resolution_units;
last_type = default_type;
new_dialog_run = TRUE;
}
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
gdisp = gdisplay_active ();
else
gdisp = NULL;
vals = g_malloc (sizeof (NewImageValues));
vals->confirm_dlg = NULL;
vals->size = 0.0;
vals->res_unit = last_res_unit;
vals->fill_type = last_fill_type;
if (gdisp)
{
vals->width = gdisp->gimage->width;
vals->height = gdisp->gimage->height;
vals->unit = gdisp->gimage->unit;
vals->xresolution = gdisp->gimage->xresolution;
vals->yresolution = gdisp->gimage->yresolution;
vals->type = gimage_base_type (gdisp->gimage);
}
else
{
vals->width = last_width;
vals->height = last_height;
vals->unit = last_unit;
vals->xresolution = last_xresolution;
vals->yresolution = last_yresolution;
vals->type = last_type;
}
if (vals->type == INDEXED)
vals->type = RGB; /* no indexed images */
/* If a cut buffer exists, default to using its size for the new image
* also check to see if a new_image has been opened
*/
if(global_buf && !last_new_image)
{
vals->width = global_buf->width;
vals->height = global_buf->height;
}
vals->dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->dlg), "new_image", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->dlg), _("New Image"));
gtk_window_set_position (GTK_WINDOW (vals->dlg), GTK_WIN_POS_MOUSE);
gtk_window_set_policy(GTK_WINDOW (vals->dlg), FALSE, FALSE, TRUE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->dlg), "delete_event",
GTK_SIGNAL_FUNC (file_new_delete_callback), GTK_SIGNAL_FUNC (file_new_delete_callback),
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
action_items[2].user_data = vals; action_items[2].user_data = info;
build_action_area (GTK_DIALOG (vals->dlg), action_items, 3, 2); build_action_area (GTK_DIALOG (info->dlg), action_items, 3, 2);
/* vbox holding the rest of the dialog */ /* vbox holding the rest of the dialog */
top_vbox = gtk_vbox_new (FALSE, 2); top_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4); gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->dlg)->vbox), gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->dlg)->vbox),
top_vbox, TRUE, TRUE, 0); top_vbox, TRUE, TRUE, 0);
gtk_widget_show (top_vbox); gtk_widget_show (top_vbox);
/* Image size frame */ /* Image size frame */
vals->size_frame = gtk_frame_new (NULL); info->size_frame = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (top_vbox), vals->size_frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (top_vbox), info->size_frame, FALSE, FALSE, 0);
gtk_widget_show (vals->size_frame); gtk_widget_show (info->size_frame);
vbox = gtk_vbox_new (FALSE, 0); vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (vals->size_frame), vbox); gtk_container_add (GTK_CONTAINER (info->size_frame), vbox);
gtk_widget_show (vbox); gtk_widget_show (vbox);
table = gtk_table_new (7, 2, FALSE); table = gtk_table_new (7, 2, FALSE);
@ -644,12 +481,12 @@ file_new_cmd_callback (GtkWidget *widget,
/* create the sizeentry which keeps it all together */ /* create the sizeentry which keeps it all together */
abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0); abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5); gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5);
vals->size_se = info->size_se =
gimp_size_entry_new (0, vals->unit, "%a", FALSE, FALSE, TRUE, 75, gimp_size_entry_new (0, values->unit, "%a", FALSE, FALSE, TRUE, 75,
GIMP_SIZE_ENTRY_UPDATE_SIZE); GIMP_SIZE_ENTRY_UPDATE_SIZE);
gtk_table_set_col_spacing (GTK_TABLE (vals->size_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->size_se), 1, 2);
gtk_container_add (GTK_CONTAINER (abox), vals->size_se); gtk_container_add (GTK_CONTAINER (abox), info->size_se);
gtk_widget_show (vals->size_se); gtk_widget_show (info->size_se);
gtk_widget_show (abox); gtk_widget_show (abox);
/* height in units */ /* height in units */
@ -660,7 +497,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "height in units" spinbutton to the sizeentry */ /* add the "height in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 2, 3); 0, 1, 2, 3);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -684,7 +521,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (hbox); gtk_widget_show (hbox);
/* register the height spinbuttons with the sizeentry */ /* register the height spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
@ -696,7 +533,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "width in units" spinbutton to the sizeentry */ /* add the "width in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 1, 2); 0, 1, 1, 2);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -715,33 +552,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (abox); gtk_widget_show (abox);
/* register the width spinbuttons with the sizeentry */ /* register the width spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
/* initialize the sizeentry */ /* initialize the sizeentry */
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
vals->xresolution, FALSE); values->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
vals->yresolution, FALSE); values->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 0,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 1,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 0, vals->width); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 0, values->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 1, vals->height); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 1, values->height);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "refval_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "refval_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "value_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
/* initialize the size label */ /* initialize the size label */
file_new_image_size_callback (vals->size_se, vals); file_new_image_size_callback (info->size_se, info);
/* the resolution labels */ /* the resolution labels */
label = gtk_label_new (_("Resolution X:")); label = gtk_label_new (_("Resolution X:"));
@ -764,44 +601,44 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
vals->resolution_se = info->resolution_se =
gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"), gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"),
FALSE, FALSE, FALSE, 75, FALSE, FALSE, FALSE, 75,
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION); GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 1, 2);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 2, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 2, 2);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->resolution_se),
GTK_SPIN_BUTTON (spinbutton), NULL); GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->resolution_se), spinbutton,
1, 2, 0, 1); 1, 2, 0, 1);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
gtk_table_attach (GTK_TABLE (table), vals->resolution_se, 1, 2, 5, 7, gtk_table_attach (GTK_TABLE (table), info->resolution_se, 1, 2, 5, 7,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (vals->resolution_se); gtk_widget_show (info->resolution_se);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
0, GIMP_MIN_RESOLUTION, 0, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
1, GIMP_MIN_RESOLUTION, 1, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, vals->xresolution); 0, values->xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, vals->yresolution); 1, values->yresolution);
gtk_signal_connect (GTK_OBJECT (vals->resolution_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->resolution_se), "value_changed",
(GtkSignalFunc) file_new_resolution_callback, vals); (GtkSignalFunc) file_new_resolution_callback, info);
/* the resolution chainbutton */ /* the resolution chainbutton */
vals->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT); info->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (vals->xresolution - vals->yresolution) < GIMP_MIN_RESOLUTION); ABS (values->xresolution - values->yresolution) < GIMP_MIN_RESOLUTION);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), gtk_table_attach_defaults (GTK_TABLE (info->resolution_se),
vals->couple_resolutions, 2, 3, 0, 2); info->couple_resolutions, 2, 3, 0, 2);
gtk_widget_show (vals->couple_resolutions); gtk_widget_show (info->couple_resolutions);
/* hbox containing the Image type and fill type frames */ /* hbox containing the Image type and fill type frames */
hbox = gtk_hbox_new (FALSE, 2); hbox = gtk_hbox_new (FALSE, 2);
@ -820,22 +657,29 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < ntypes; i++) list = g_list_first (image_new_get_image_base_type_names ());
while (list)
{ {
button = gtk_radio_button_new_with_label (group, gettext (type_names[i])); GimpImageBaseTypeName *name_info;
name_info = (GimpImageBaseTypeName*) list->data;
button = gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->type); &values->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->type == i) if (values->type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->type_w[i] = button; info->type_w[name_info->type] = button;
list = g_list_next (list);
} }
/* frame for Fill Type */ /* frame for Fill Type */
@ -849,34 +693,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < nfill_types; i++) list = g_list_first (image_new_get_fill_type_names ());
while (list)
{ {
GimpFillTypeName *name_info;
name_info = (GimpFillTypeName*) list->data;
button = button =
gtk_radio_button_new_with_label (group, gettext (fill_type_names[i])); gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->fill_type); &values->fill_type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->fill_type == i) if (values->fill_type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->fill_type_w[i] = button; info->fill_type_w[name_info->type] = button;
list = g_list_next (list);
} }
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (info->size_se));
gtk_widget_show (vals->dlg); gtk_widget_show (info->dlg);
}
void
file_new_reset_current_cut_buffer ()
{
/* this function just changes the status of last_image_new
so i can if theres been a cut/copy since the last file new */
last_new_image = FALSE;
} }

View file

@ -3,10 +3,12 @@
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "image_new.h"
void file_new_cmd_callback (GtkWidget *widget, void file_new_cmd_callback (GtkWidget *widget,
gpointer callback_data, gpointer callback_data,
guint callback_action); guint callback_action);
void file_new_reset_current_cut_buffer (); void ui_new_image_window_create (const GimpImageNewValues *values);
#endif /* __FILE_NEW_DIALOG_H_H__ */ #endif /* __FILE_NEW_DIALOG_H_H__ */

View file

@ -475,6 +475,18 @@ gimp_image_resize (GimpImage *gimage,
gimp_remove_busy_cursors (NULL); gimp_remove_busy_cursors (NULL);
} }
gint
gimp_image_get_width (const GimpImage *gimage)
{
return gimage->width;
}
gint
gimp_image_get_height (const GimpImage *gimage)
{
return gimage->height;
}
void void
gimp_image_scale (GimpImage *gimage, gimp_image_scale (GimpImage *gimage,
gint new_width, gint new_width,

View file

@ -119,6 +119,8 @@ GUnit gimp_image_get_unit (GimpImage *);
void gimp_image_set_save_proc (GimpImage *, void gimp_image_set_save_proc (GimpImage *,
PlugInProcDef *); PlugInProcDef *);
PlugInProcDef * gimp_image_get_save_proc (GimpImage *); PlugInProcDef * gimp_image_get_save_proc (GimpImage *);
gint gimp_image_get_width (const GimpImage *);
gint gimp_image_get_height (const GimpImage *);
void gimp_image_resize (GimpImage *, void gimp_image_resize (GimpImage *,
gint, gint, gint, gint); gint, gint, gint, gint);
void gimp_image_scale (GimpImage *, gint, gint); void gimp_image_scale (GimpImage *, gint, gint);

View file

@ -19,7 +19,7 @@
#include "appenv.h" #include "appenv.h"
#include "actionarea.h" #include "actionarea.h"
#include "drawable.h" #include "drawable.h"
#include "file_new_dialog.h" #include "image_new.h"
#include "floating_sel.h" #include "floating_sel.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "gimage.h" #include "gimage.h"
@ -206,7 +206,7 @@ edit_cut (GImage *gimage,
cropped_cut = NULL; cropped_cut = NULL;
if (cut) if (cut)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer ();
/* end the group undo */ /* end the group undo */
@ -257,7 +257,7 @@ edit_copy (GImage *gimage,
cropped_copy = NULL; cropped_copy = NULL;
if(copy) if(copy)
file_new_reset_current_cut_buffer(); image_new_reset_current_cut_buffer();
if (cropped_copy) if (cropped_copy)

View file

@ -15,17 +15,11 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "appenv.h"
#include "actionarea.h"
#include "file_new_dialog.h" #include "file_new_dialog.h"
#include "gimage.h"
#include "gimpcontext.h" #include "actionarea.h"
#include "gimprc.h" #include "gimprc.h"
#include "global_edit.h"
#include "interface.h"
#include "lc_dialog.h"
#include "plug_in.h"
#include "tile_manager_pvt.h"
#include "gdisplay.h" #include "gdisplay.h"
#include "libgimp/gimpchainbutton.h" #include "libgimp/gimpchainbutton.h"
@ -33,8 +27,7 @@
#include "libgimp/gimpsizeentry.h" #include "libgimp/gimpsizeentry.h"
#include "libgimp/gimpintl.h" #include "libgimp/gimpintl.h"
typedef struct typedef struct {
{
GtkWidget *dlg; GtkWidget *dlg;
GtkWidget *confirm_dlg; GtkWidget *confirm_dlg;
@ -44,27 +37,16 @@ typedef struct
GtkWidget *resolution_se; GtkWidget *resolution_se;
GtkWidget *couple_resolutions; GtkWidget *couple_resolutions;
/* this should be a list */
GtkWidget *type_w[2]; GtkWidget *type_w[2];
GtkWidget *fill_type_w[4]; GtkWidget *fill_type_w[4];
gint width; GimpImageNewValues *values;
gint height; gdouble size;
GUnit unit; } NewImageInfo;
gdouble xresolution;
gdouble yresolution;
GUnit res_unit;
gdouble size; /* in bytes */
GimpImageBaseType type;
GimpFillType fill_type;
} NewImageValues;
/* new image local functions */ /* new image local functions */
static void file_new_create_image (NewImageValues *); static void file_new_confirm_dialog (NewImageInfo *);
static void file_new_confirm_dialog (NewImageValues *);
static gchar * file_new_print_size (gdouble);
static void file_new_ok_callback (GtkWidget *, gpointer); static void file_new_ok_callback (GtkWidget *, gpointer);
static void file_new_reset_callback (GtkWidget *, gpointer); static void file_new_reset_callback (GtkWidget *, gpointer);
@ -74,119 +56,43 @@ static void file_new_toggle_callback (GtkWidget *, gpointer);
static void file_new_resolution_callback (GtkWidget *, gpointer); static void file_new_resolution_callback (GtkWidget *, gpointer);
static void file_new_image_size_callback (GtkWidget *, gpointer); static void file_new_image_size_callback (GtkWidget *, gpointer);
/* static variables */
static gint last_width = 256;
static gint last_height = 256;
static GUnit last_unit = UNIT_INCH;
static gdouble last_xresolution = 72.0;
static gdouble last_yresolution = 72.0;
static GUnit last_res_unit = UNIT_INCH;
static GimpImageBaseType last_type = RGB;
static GimpFillType last_fill_type = BACKGROUND_FILL;
static gboolean last_new_image = FALSE;
static gboolean new_dialog_run = FALSE;
extern TileManager *global_buf;
/* functions */
static void
file_new_create_image (NewImageValues *vals)
{
GImage *gimage;
GDisplay *gdisplay;
Layer *layer;
GimpImageType type;
last_width = vals->width;
last_height = vals->height;
last_type = vals->type;
last_fill_type = vals->fill_type;
last_xresolution = vals->xresolution;
last_yresolution = vals->yresolution;
last_unit = vals->unit;
last_res_unit = vals->res_unit;
last_new_image = TRUE;
switch (vals->fill_type)
{
case BACKGROUND_FILL:
case FOREGROUND_FILL:
case WHITE_FILL:
type = (vals->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (vals->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_IMAGE;
break;
}
gimage = gimage_new (vals->width, vals->height, vals->type);
gimp_image_set_resolution (gimage, vals->xresolution, vals->yresolution);
gimp_image_set_unit (gimage, vals->unit);
/* Make the background (or first) layer */
layer = layer_new (gimage, gimage->width, gimage->height,
type, _("Background"), OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
/* add the new layer to the gimage */
gimage_disable_undo (gimage);
gimage_add_layer (gimage, layer, 0);
gimage_enable_undo (gimage);
drawable_fill (GIMP_DRAWABLE(layer), vals->fill_type);
gimage_clean_all (gimage);
gdisplay = gdisplay_new (gimage, 0x0101);
gimp_context_set_display (gimp_context_get_user (), gdisplay);
}
g_free (vals);
}
static void static void
file_new_ok_callback (GtkWidget *widget, file_new_ok_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
GimpImageNewValues *values;
vals = data; info = (NewImageInfo*) data;
values = info->values;
/* get the image size in pixels */ /* get the image size in pixels */
vals->width = (int) values->width = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
vals->height = (int) values->height = (int)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
/* get the resolution in dpi */ /* get the resolution in dpi */
vals->xresolution = values->xresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 0); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 0);
vals->yresolution = values->yresolution =
gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->resolution_se), 1); gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->resolution_se), 1);
/* get the units */ /* get the units */
vals->unit = values->unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->size_se));
vals->res_unit = values->res_unit =
gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (vals->resolution_se)); gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (info->resolution_se));
if (vals->size > max_new_image_size) if (info->size > max_new_image_size)
{ {
file_new_confirm_dialog (vals); file_new_confirm_dialog (info);
} }
else else
{ {
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
file_new_create_image (vals); image_new_create_image (values);
image_new_values_free (values);
} }
} }
@ -194,40 +100,40 @@ static void
file_new_reset_callback (GtkWidget *widget, file_new_reset_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_signal_handler_block_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_block_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION); ABS (default_xresolution - default_yresolution) < GIMP_MIN_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, default_xresolution); 0, default_xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, default_yresolution); 1, default_yresolution);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->resolution_se),
default_resolution_units); default_resolution_units);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (vals->resolution_se), vals); gtk_signal_handler_unblock_by_data (GTK_OBJECT (info->resolution_se), info);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
0, default_xresolution, TRUE); 0, default_xresolution, TRUE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se),
1, default_yresolution, TRUE); 1, default_yresolution, TRUE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
0, default_width); 0, default_width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se),
1, default_height); 1, default_height);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (info->size_se),
default_units); default_units);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vals->type_w[default_type]), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->type_w[default_type]),
TRUE); TRUE);
gtk_toggle_button_set_active gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (vals->fill_type_w[BACKGROUND_FILL]), TRUE); (GTK_TOGGLE_BUTTON (info->fill_type_w[BACKGROUND_FILL]), TRUE);
} }
static gint static gint
@ -243,44 +149,53 @@ static void
file_new_cancel_callback (GtkWidget *widget, file_new_cancel_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
vals = data; info = (NewImageInfo*) data;
gtk_widget_destroy (vals->dlg); gtk_widget_destroy (info->dlg);
g_free (vals); image_new_values_free(info->values);
g_free (info);
} }
/* local callbacks of file_new_confirm_dialog() */ /* local callbacks of file_new_confirm_dialog() */
static void static void
file_new_confirm_dialog_ok_callback (GtkWidget *widget, file_new_confirm_dialog_ok_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
gtk_widget_destroy (vals->dlg);
file_new_create_image (vals); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
gtk_widget_destroy (info->dlg);
image_new_create_image (info->values);
} }
static void static void
file_new_confirm_dialog_cancel_callback (GtkWidget *widget, file_new_confirm_dialog_cancel_callback (GtkWidget *widget,
NewImageValues *vals) gpointer data)
{ {
gtk_widget_destroy (vals->confirm_dlg); NewImageInfo *info;
vals->confirm_dlg = NULL;
gtk_widget_set_sensitive (vals->dlg, TRUE); info = (NewImageInfo*) data;
gtk_widget_destroy (info->confirm_dlg);
info->confirm_dlg = NULL;
gtk_widget_set_sensitive (info->dlg, TRUE);
} }
static gint static gint
file_new_confirm_dialog_delete_callback (GtkWidget *widget, file_new_confirm_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
NewImageValues *vals) gpointer data)
{ {
file_new_confirm_dialog_cancel_callback (widget, vals); file_new_confirm_dialog_cancel_callback (widget, data);
return TRUE; return TRUE;
} }
static void static void
file_new_confirm_dialog (NewImageValues *vals) file_new_confirm_dialog (NewImageInfo *info)
{ {
GtkWidget *label; GtkWidget *label;
gchar *size; gchar *size;
@ -295,24 +210,27 @@ file_new_confirm_dialog (NewImageValues *vals)
(ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL } (ActionCallback) file_new_confirm_dialog_cancel_callback, NULL, NULL }
}; };
gtk_widget_set_sensitive (vals->dlg, FALSE); gtk_widget_set_sensitive (info->dlg, FALSE);
vals->confirm_dlg = gtk_dialog_new (); info->confirm_dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->confirm_dlg), gtk_window_set_wmclass (GTK_WINDOW (info->confirm_dlg),
"confirm_size", "Gimp"); "confirm_size", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->confirm_dlg), _("Confirm Image Size")); gtk_window_set_title (GTK_WINDOW (info->confirm_dlg), _("Confirm Image Size"));
gtk_window_set_policy (GTK_WINDOW (vals->confirm_dlg), FALSE, FALSE, FALSE); gtk_window_set_policy (GTK_WINDOW (info->confirm_dlg), FALSE, FALSE, FALSE);
gtk_window_position (GTK_WINDOW (vals->confirm_dlg), GTK_WIN_POS_MOUSE); gtk_window_position (GTK_WINDOW (info->confirm_dlg), GTK_WIN_POS_MOUSE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->confirm_dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->confirm_dlg), "delete_event",
(GtkSignalFunc) file_new_confirm_dialog_delete_callback, (GtkSignalFunc) file_new_confirm_dialog_delete_callback,
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
build_action_area (GTK_DIALOG (vals->confirm_dlg), action_items, 2, 0); build_action_area (GTK_DIALOG (info->confirm_dlg), action_items, 2, 0);
size = image_new_get_size_string (info->size);
max_size = image_new_get_size_string (max_new_image_size);
text = g_strdup_printf (_("You are trying to create an image which\n" text = g_strdup_printf (_("You are trying to create an image which\n"
"has an initial size of %s.\n\n" "has an initial size of %s.\n\n"
@ -323,11 +241,10 @@ file_new_confirm_dialog (NewImageValues *vals)
"increase the \"Maximum Image Size\"\n" "increase the \"Maximum Image Size\"\n"
"setting (currently %s) in the\n" "setting (currently %s) in the\n"
"preferences dialog."), "preferences dialog."),
size = file_new_print_size (vals->size), size, max_size);
max_size = file_new_print_size (max_new_image_size));
label = gtk_label_new (text); label = gtk_label_new (text);
gtk_misc_set_padding (GTK_MISC (label), 6, 6); gtk_misc_set_padding (GTK_MISC (label), 6, 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->confirm_dlg)->vbox), label, gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->confirm_dlg)->vbox), label,
TRUE, TRUE, 0); TRUE, TRUE, 0);
gtk_widget_show (label); gtk_widget_show (label);
@ -335,7 +252,7 @@ file_new_confirm_dialog (NewImageValues *vals)
g_free (max_size); g_free (max_size);
g_free (size); g_free (size);
gtk_widget_show (vals->confirm_dlg); gtk_widget_show (info->confirm_dlg);
} }
static void static void
@ -355,23 +272,23 @@ static void
file_new_resolution_callback (GtkWidget *widget, file_new_resolution_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
static gdouble xres = 0.0; static gdouble xres = 0.0;
static gdouble yres = 0.0; static gdouble yres = 0.0;
gdouble new_xres; gdouble new_xres;
gdouble new_yres; gdouble new_yres;
vals = data; info = (NewImageInfo*) data;
new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0); new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1); new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);
if (gimp_chain_button_get_active if (gimp_chain_button_get_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions))) (GIMP_CHAIN_BUTTON (info->couple_resolutions)))
{ {
gtk_signal_handler_block_by_data gtk_signal_handler_block_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
if (new_xres != xres) if (new_xres != xres)
{ {
@ -386,7 +303,7 @@ file_new_resolution_callback (GtkWidget *widget,
} }
gtk_signal_handler_unblock_by_data gtk_signal_handler_unblock_by_data
(GTK_OBJECT (vals->resolution_se), vals); (GTK_OBJECT (info->resolution_se), info);
} }
else else
{ {
@ -396,61 +313,38 @@ file_new_resolution_callback (GtkWidget *widget,
yres = new_yres; yres = new_yres;
} }
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
xres, FALSE); xres, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
yres, FALSE); yres, FALSE);
file_new_image_size_callback (widget, data); file_new_image_size_callback (widget, data);
} }
static gchar *
file_new_print_size (gdouble size)
{
if (size < 4096)
return g_strdup_printf (_("%d Bytes"), (gint) size);
else if (size < 1024 * 10)
return g_strdup_printf (_("%.2f KB"), size / 1024);
else if (size < 1024 * 100)
return g_strdup_printf (_("%.1f KB"), size / 1024);
else if (size < 1024 * 1024)
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
else if (size < 1024 * 1024 * 10)
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
else
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
}
static void static void
file_new_image_size_callback (GtkWidget *widget, file_new_image_size_callback (GtkWidget *widget,
gpointer data) gpointer data)
{ {
NewImageValues *vals; NewImageInfo *info;
gdouble width, height;
gdouble width, height, size;
gchar *text; gchar *text;
gchar *label; gchar *label;
vals = data; info = (NewImageInfo*) data;
width = (gdouble) (gint) width = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 0) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 0) + 0.5);
height = (gdouble) (gint) height = (gdouble) (gint)
(gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (vals->size_se), 1) + 0.5); (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (info->size_se), 1) + 0.5);
size = info->size = image_new_calculate_size (info->values);
width * height *
((vals->type == RGB ? 3 : 1) + /* bytes per pixel */
(vals->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
label = g_strdup_printf (_("Image Size: %s"), label = g_strdup_printf (_("Image Size: %s"),
text = file_new_print_size (size)); text = image_new_get_size_string (info->size));
gtk_frame_set_label (GTK_FRAME (vals->size_frame), label); gtk_frame_set_label (GTK_FRAME (info->size_frame), label);
g_free (label); g_free (label);
g_free (text); g_free (text);
vals->size = size;
} }
void void
@ -459,7 +353,27 @@ file_new_cmd_callback (GtkWidget *widget,
guint callback_action) guint callback_action)
{ {
GDisplay *gdisp; GDisplay *gdisp;
NewImageValues *vals; GimpImage *image = NULL;
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
{
gdisp = gdisplay_active ();
if (gdisp)
image = gdisp->gimage;
}
image_new_create_window (NULL, image);
}
void
ui_new_image_window_create (const GimpImageNewValues *values_orig)
{
NewImageInfo *info;
GimpImageNewValues *values;
GtkWidget *top_vbox; GtkWidget *top_vbox;
GtkWidget *hbox; GtkWidget *hbox;
@ -475,7 +389,7 @@ file_new_cmd_callback (GtkWidget *widget,
GtkWidget *spinbutton2; GtkWidget *spinbutton2;
GtkWidget *radio_box; GtkWidget *radio_box;
GSList *group; GSList *group;
gint i; GList *list;
static ActionAreaItem action_items[] = static ActionAreaItem action_items[] =
{ {
@ -484,121 +398,44 @@ file_new_cmd_callback (GtkWidget *widget,
{ N_("Cancel"), file_new_cancel_callback, NULL, NULL } { N_("Cancel"), file_new_cancel_callback, NULL, NULL }
}; };
static gchar *type_names[] = info = g_new (NewImageInfo, 1);
{ info->values = values = image_new_values_new (values_orig);
N_("RGB"),
N_("Grayscale")
};
static gint ntypes = sizeof (type_names) / sizeof (type_names[0]);
static gchar *fill_type_names[] = info->confirm_dlg = NULL;
{ info->size = 0.0;
N_("Foreground"),
N_("Background"),
N_("White"),
N_("Transparent")
};
static gint nfill_types =
sizeof (fill_type_names) / sizeof (fill_type_names[0]);
if(!new_dialog_run) info->dlg = gtk_dialog_new ();
{ gtk_window_set_wmclass (GTK_WINDOW (info->dlg), "new_image", "Gimp");
/* all from gimprc */ gtk_window_set_title (GTK_WINDOW (info->dlg), _("New Image"));
last_width = default_width; gtk_window_set_position (GTK_WINDOW (info->dlg), GTK_WIN_POS_MOUSE);
last_height = default_height; gtk_window_set_policy(GTK_WINDOW (info->dlg), FALSE, FALSE, TRUE);
last_unit = default_units;
last_xresolution = default_xresolution;
last_yresolution = default_yresolution;
last_res_unit = default_resolution_units;
last_type = default_type;
new_dialog_run = TRUE;
}
/* Before we try to determine the responsible gdisplay,
* make sure this wasn't called from the toolbox
*/
if (callback_action)
gdisp = gdisplay_active ();
else
gdisp = NULL;
vals = g_malloc (sizeof (NewImageValues));
vals->confirm_dlg = NULL;
vals->size = 0.0;
vals->res_unit = last_res_unit;
vals->fill_type = last_fill_type;
if (gdisp)
{
vals->width = gdisp->gimage->width;
vals->height = gdisp->gimage->height;
vals->unit = gdisp->gimage->unit;
vals->xresolution = gdisp->gimage->xresolution;
vals->yresolution = gdisp->gimage->yresolution;
vals->type = gimage_base_type (gdisp->gimage);
}
else
{
vals->width = last_width;
vals->height = last_height;
vals->unit = last_unit;
vals->xresolution = last_xresolution;
vals->yresolution = last_yresolution;
vals->type = last_type;
}
if (vals->type == INDEXED)
vals->type = RGB; /* no indexed images */
/* If a cut buffer exists, default to using its size for the new image
* also check to see if a new_image has been opened
*/
if(global_buf && !last_new_image)
{
vals->width = global_buf->width;
vals->height = global_buf->height;
}
vals->dlg = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (vals->dlg), "new_image", "Gimp");
gtk_window_set_title (GTK_WINDOW (vals->dlg), _("New Image"));
gtk_window_set_position (GTK_WINDOW (vals->dlg), GTK_WIN_POS_MOUSE);
gtk_window_set_policy(GTK_WINDOW (vals->dlg), FALSE, FALSE, TRUE);
/* Handle the wm close signal */ /* Handle the wm close signal */
gtk_signal_connect (GTK_OBJECT (vals->dlg), "delete_event", gtk_signal_connect (GTK_OBJECT (info->dlg), "delete_event",
GTK_SIGNAL_FUNC (file_new_delete_callback), GTK_SIGNAL_FUNC (file_new_delete_callback),
vals); info);
/* The action area */ /* The action area */
action_items[0].user_data = vals; action_items[0].user_data = info;
action_items[1].user_data = vals; action_items[1].user_data = info;
action_items[2].user_data = vals; action_items[2].user_data = info;
build_action_area (GTK_DIALOG (vals->dlg), action_items, 3, 2); build_action_area (GTK_DIALOG (info->dlg), action_items, 3, 2);
/* vbox holding the rest of the dialog */ /* vbox holding the rest of the dialog */
top_vbox = gtk_vbox_new (FALSE, 2); top_vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4); gtk_container_set_border_width (GTK_CONTAINER (top_vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (vals->dlg)->vbox), gtk_box_pack_start (GTK_BOX (GTK_DIALOG (info->dlg)->vbox),
top_vbox, TRUE, TRUE, 0); top_vbox, TRUE, TRUE, 0);
gtk_widget_show (top_vbox); gtk_widget_show (top_vbox);
/* Image size frame */ /* Image size frame */
vals->size_frame = gtk_frame_new (NULL); info->size_frame = gtk_frame_new (NULL);
gtk_box_pack_start (GTK_BOX (top_vbox), vals->size_frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (top_vbox), info->size_frame, FALSE, FALSE, 0);
gtk_widget_show (vals->size_frame); gtk_widget_show (info->size_frame);
vbox = gtk_vbox_new (FALSE, 0); vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (vals->size_frame), vbox); gtk_container_add (GTK_CONTAINER (info->size_frame), vbox);
gtk_widget_show (vbox); gtk_widget_show (vbox);
table = gtk_table_new (7, 2, FALSE); table = gtk_table_new (7, 2, FALSE);
@ -644,12 +481,12 @@ file_new_cmd_callback (GtkWidget *widget,
/* create the sizeentry which keeps it all together */ /* create the sizeentry which keeps it all together */
abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0); abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5); gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 5);
vals->size_se = info->size_se =
gimp_size_entry_new (0, vals->unit, "%a", FALSE, FALSE, TRUE, 75, gimp_size_entry_new (0, values->unit, "%a", FALSE, FALSE, TRUE, 75,
GIMP_SIZE_ENTRY_UPDATE_SIZE); GIMP_SIZE_ENTRY_UPDATE_SIZE);
gtk_table_set_col_spacing (GTK_TABLE (vals->size_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->size_se), 1, 2);
gtk_container_add (GTK_CONTAINER (abox), vals->size_se); gtk_container_add (GTK_CONTAINER (abox), info->size_se);
gtk_widget_show (vals->size_se); gtk_widget_show (info->size_se);
gtk_widget_show (abox); gtk_widget_show (abox);
/* height in units */ /* height in units */
@ -660,7 +497,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "height in units" spinbutton to the sizeentry */ /* add the "height in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 2, 3); 0, 1, 2, 3);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -684,7 +521,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (hbox); gtk_widget_show (hbox);
/* register the height spinbuttons with the sizeentry */ /* register the height spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
@ -696,7 +533,7 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
/* add the "width in units" spinbutton to the sizeentry */ /* add the "width in units" spinbutton to the sizeentry */
gtk_table_attach_defaults (GTK_TABLE (vals->size_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->size_se), spinbutton,
0, 1, 1, 2); 0, 1, 1, 2);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
@ -715,33 +552,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (abox); gtk_widget_show (abox);
/* register the width spinbuttons with the sizeentry */ /* register the width spinbuttons with the sizeentry */
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->size_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->size_se),
GTK_SPIN_BUTTON (spinbutton), GTK_SPIN_BUTTON (spinbutton),
GTK_SPIN_BUTTON (spinbutton2)); GTK_SPIN_BUTTON (spinbutton2));
/* initialize the sizeentry */ /* initialize the sizeentry */
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 0,
vals->xresolution, FALSE); values->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (info->size_se), 1,
vals->yresolution, FALSE); values->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 0, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 0,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->size_se), 1, gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->size_se), 1,
GIMP_MIN_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE); GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 0, vals->width); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 0, values->width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->size_se), 1, vals->height); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->size_se), 1, values->height);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "refval_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "refval_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
gtk_signal_connect (GTK_OBJECT (vals->size_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->size_se), "value_changed",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
/* initialize the size label */ /* initialize the size label */
file_new_image_size_callback (vals->size_se, vals); file_new_image_size_callback (info->size_se, info);
/* the resolution labels */ /* the resolution labels */
label = gtk_label_new (_("Resolution X:")); label = gtk_label_new (_("Resolution X:"));
@ -764,44 +601,44 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_widget_set_usize (spinbutton, 75, 0); gtk_widget_set_usize (spinbutton, 75, 0);
vals->resolution_se = info->resolution_se =
gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"), gimp_size_entry_new (1, default_resolution_units, _("pixels/%a"),
FALSE, FALSE, FALSE, 75, FALSE, FALSE, FALSE, 75,
GIMP_SIZE_ENTRY_UPDATE_RESOLUTION); GIMP_SIZE_ENTRY_UPDATE_RESOLUTION);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 1, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 1, 2);
gtk_table_set_col_spacing (GTK_TABLE (vals->resolution_se), 2, 2); gtk_table_set_col_spacing (GTK_TABLE (info->resolution_se), 2, 2);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_add_field (GIMP_SIZE_ENTRY (info->resolution_se),
GTK_SPIN_BUTTON (spinbutton), NULL); GTK_SPIN_BUTTON (spinbutton), NULL);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), spinbutton, gtk_table_attach_defaults (GTK_TABLE (info->resolution_se), spinbutton,
1, 2, 0, 1); 1, 2, 0, 1);
gtk_widget_show (spinbutton); gtk_widget_show (spinbutton);
gtk_table_attach (GTK_TABLE (table), vals->resolution_se, 1, 2, 5, 7, gtk_table_attach (GTK_TABLE (table), info->resolution_se, 1, 2, 5, 7,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (vals->resolution_se); gtk_widget_show (info->resolution_se);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
0, GIMP_MIN_RESOLUTION, 0, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (info->resolution_se),
1, GIMP_MIN_RESOLUTION, 1, GIMP_MIN_RESOLUTION,
GIMP_MAX_RESOLUTION); GIMP_MAX_RESOLUTION);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
0, vals->xresolution); 0, values->xresolution);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (vals->resolution_se), gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (info->resolution_se),
1, vals->yresolution); 1, values->yresolution);
gtk_signal_connect (GTK_OBJECT (vals->resolution_se), "value_changed", gtk_signal_connect (GTK_OBJECT (info->resolution_se), "value_changed",
(GtkSignalFunc) file_new_resolution_callback, vals); (GtkSignalFunc) file_new_resolution_callback, info);
/* the resolution chainbutton */ /* the resolution chainbutton */
vals->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT); info->couple_resolutions = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
gimp_chain_button_set_active gimp_chain_button_set_active
(GIMP_CHAIN_BUTTON (vals->couple_resolutions), (GIMP_CHAIN_BUTTON (info->couple_resolutions),
ABS (vals->xresolution - vals->yresolution) < GIMP_MIN_RESOLUTION); ABS (values->xresolution - values->yresolution) < GIMP_MIN_RESOLUTION);
gtk_table_attach_defaults (GTK_TABLE (vals->resolution_se), gtk_table_attach_defaults (GTK_TABLE (info->resolution_se),
vals->couple_resolutions, 2, 3, 0, 2); info->couple_resolutions, 2, 3, 0, 2);
gtk_widget_show (vals->couple_resolutions); gtk_widget_show (info->couple_resolutions);
/* hbox containing the Image type and fill type frames */ /* hbox containing the Image type and fill type frames */
hbox = gtk_hbox_new (FALSE, 2); hbox = gtk_hbox_new (FALSE, 2);
@ -820,22 +657,29 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < ntypes; i++) list = g_list_first (image_new_get_image_base_type_names ());
while (list)
{ {
button = gtk_radio_button_new_with_label (group, gettext (type_names[i])); GimpImageBaseTypeName *name_info;
name_info = (GimpImageBaseTypeName*) list->data;
button = gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, FALSE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->type); &values->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->type == i) if (values->type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->type_w[i] = button; info->type_w[name_info->type] = button;
list = g_list_next (list);
} }
/* frame for Fill Type */ /* frame for Fill Type */
@ -849,34 +693,33 @@ file_new_cmd_callback (GtkWidget *widget,
gtk_widget_show (radio_box); gtk_widget_show (radio_box);
group = NULL; group = NULL;
for (i = 0; i < nfill_types; i++) list = g_list_first (image_new_get_fill_type_names ());
while (list)
{ {
GimpFillTypeName *name_info;
name_info = (GimpFillTypeName*) list->data;
button = button =
gtk_radio_button_new_with_label (group, gettext (fill_type_names[i])); gtk_radio_button_new_with_label (group, name_info->name);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (radio_box), button, TRUE, TRUE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) i); gtk_object_set_user_data (GTK_OBJECT (button), (gpointer) name_info->type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_toggle_callback, (GtkSignalFunc) file_new_toggle_callback,
&vals->fill_type); &values->fill_type);
gtk_signal_connect (GTK_OBJECT (button), "toggled", gtk_signal_connect (GTK_OBJECT (button), "toggled",
(GtkSignalFunc) file_new_image_size_callback, vals); (GtkSignalFunc) file_new_image_size_callback, info);
if (vals->fill_type == i) if (values->fill_type == name_info->type)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_widget_show (button); gtk_widget_show (button);
vals->fill_type_w[i] = button; info->fill_type_w[name_info->type] = button;
list = g_list_next (list);
} }
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (vals->size_se)); gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (info->size_se));
gtk_widget_show (vals->dlg); gtk_widget_show (info->dlg);
}
void
file_new_reset_current_cut_buffer ()
{
/* this function just changes the status of last_image_new
so i can if theres been a cut/copy since the last file new */
last_new_image = FALSE;
} }

View file

@ -3,10 +3,12 @@
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "image_new.h"
void file_new_cmd_callback (GtkWidget *widget, void file_new_cmd_callback (GtkWidget *widget,
gpointer callback_data, gpointer callback_data,
guint callback_action); guint callback_action);
void file_new_reset_current_cut_buffer (); void ui_new_image_window_create (const GimpImageNewValues *values);
#endif /* __FILE_NEW_DIALOG_H_H__ */ #endif /* __FILE_NEW_DIALOG_H_H__ */

282
app/image_new.c Normal file
View file

@ -0,0 +1,282 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* 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.
*/
#include "image_new.h"
#include "gimprc.h"
#include "file_new_dialog.h"
#include "tile_manager_pvt.h"
#include "gdisplay.h"
#include "gimpcontext.h"
#include "gimage.h"
#include "libgimp/gimpintl.h"
static GList *image_base_type_names = NULL;
static GList *fill_type_names = NULL;
static GimpImageNewValues last_values;
static gboolean current_cut_buffer = FALSE;
extern TileManager *global_buf;
static void
image_new_init ()
{
static gboolean image_new_inited = 0;
GimpImageBaseTypeName *new_type;
GimpFillTypeName *new_fill_type;
if (image_new_inited)
return;
else
image_new_inited = 1;
/* Available Image Base Types */
new_type = g_new (GimpImageBaseTypeName, 1);
new_type->type = RGB;
new_type->name = _("RGB");
image_base_type_names = g_list_append (image_base_type_names, new_type);
new_type = g_new (GimpImageBaseTypeName, 1);
new_type->type = GRAY;
new_type->name = _("Grayscale");
image_base_type_names = g_list_append (image_base_type_names, new_type);
/* Available Fill Types */
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = FOREGROUND_FILL;
new_fill_type->name = _("Foreground");
fill_type_names = g_list_append (fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = BACKGROUND_FILL;
new_fill_type->name = _("Background");
fill_type_names = g_list_append (fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = WHITE_FILL;
new_fill_type->name = _("White");
fill_type_names = g_list_append (fill_type_names, new_fill_type);
new_fill_type = g_new (GimpFillTypeName, 1);
new_fill_type->type = TRANSPARENT_FILL;
new_fill_type->name = _("Transparent");
fill_type_names = g_list_append (fill_type_names, new_fill_type);
/* Set the last values used to default values. */
last_values.width = default_width;
last_values.height = default_height;
last_values.unit = default_units;
last_values.xresolution = default_xresolution;
last_values.yresolution = default_yresolution;
last_values.res_unit = default_resolution_units;
last_values.type = default_type;
last_values.fill_type = BACKGROUND_FILL;
}
GList*
image_new_get_image_base_type_names ()
{
image_new_init ();
return image_base_type_names;
}
GList*
image_new_get_fill_type_names ()
{
image_new_init ();
return fill_type_names;
}
void
image_new_create_window (const GimpImageNewValues *create_values,
const GimpImage *image)
{
GimpImageNewValues *values;
image_new_init ();
values = image_new_values_new (create_values);
if (image)
{
values->width = gimp_image_get_width (image);
values->height = gimp_image_get_height (image);
values->unit = gimp_image_get_unit (image);
gimp_image_get_resolution(image,
&values->xresolution,
&values->yresolution);
values->type = gimp_image_base_type (image);
if (values->type == INDEXED)
values->type = RGB; /* no indexed images */
}
/* If a cut buffer exists, default to using its size for the new image
* also check to see if a new_image has been opened
*/
if (global_buf && current_cut_buffer)
{
values->width = global_buf->width;
values->height = global_buf->height;
}
ui_new_image_window_create (values);
image_new_values_free (values);
}
void
image_new_set_default_values (const GimpImageNewValues *values)
{
g_return_if_fail (values != NULL);
image_new_init ();
memcpy(&last_values, values, sizeof (GimpImageNewValues));
current_cut_buffer = FALSE;
}
GimpImageNewValues*
image_new_values_new (const GimpImageNewValues *src_values)
{
GimpImageNewValues *values;
image_new_init ();
values = g_new (GimpImageNewValues, 1);
if (src_values)
memcpy(values, src_values, sizeof (GimpImageNewValues));
else
memcpy(values, &last_values, sizeof (GimpImageNewValues));
return values;
}
void
image_new_values_free (GimpImageNewValues *values)
{
g_return_if_fail (values != NULL);
g_free (values);
}
void
image_new_create_image (const GimpImageNewValues *values)
{
GimpImage *image;
GDisplay *display;
Layer *layer;
GimpImageType type;
gint width, height;
g_return_if_fail (values != NULL);
image_new_set_default_values (values);
switch (values->fill_type)
{
case FOREGROUND_FILL:
case BACKGROUND_FILL:
case WHITE_FILL:
type = (values->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (values->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_IMAGE;
break;
}
image = gimage_new (values->width, values->height, values->type);
gimp_image_set_resolution (image, values->xresolution, values->yresolution);
gimp_image_set_unit (image, values->unit);
/* Make the background (or first) layer */
width = gimp_image_get_width (image);
height = gimp_image_get_height(image);
layer = layer_new (image, width, height,
type, _("Background"), OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
/* add the new layer to the gimage */
gimp_image_disable_undo (image);
gimp_image_add_layer (image, layer, 0);
gimp_image_enable_undo (image);
drawable_fill (GIMP_DRAWABLE (layer), values->fill_type);
gimp_image_clean_all (image);
display = gdisplay_new (image, 0x0101);
gimp_context_set_display (gimp_context_get_user (), display);
}
}
gdouble
image_new_calculate_size (GimpImageNewValues *values)
{
gdouble width, height, size;
width = (gdouble) values->width;
height = (gdouble) values->height;
size =
width * height *
((values->type == RGB ? 3 : 1) + /* bytes per pixel */
(values->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
return size;
}
gchar*
image_new_get_size_string (gdouble size)
{
if (size < 4096)
return g_strdup_printf (_("%d Bytes"), (gint) size);
else if (size < 1024 * 10)
return g_strdup_printf (_("%.2f KB"), size / 1024);
else if (size < 1024 * 100)
return g_strdup_printf (_("%.1f KB"), size / 1024);
else if (size < 1024 * 1024)
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
else if (size < 1024 * 1024 * 10)
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
else
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
}
void
image_new_reset_current_cut_buffer ()
{
/* This function just changes the status of current_cut_buffer
if there hass been a cut/copy since the last file new */
current_cut_buffer = TRUE;
}

73
app/image_new.h Normal file
View file

@ -0,0 +1,73 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __IMAGE_NEW_H__
#define __IMAGE_NEW_H__
#include "gimpimage.h"
#include "gimpdrawable.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
GimpImageBaseType type;
gchar *name;
} GimpImageBaseTypeName;
typedef struct {
GimpFillType type;
gchar *name;
} GimpFillTypeName;
typedef struct {
gint width;
gint height;
GUnit unit;
gdouble xresolution;
gdouble yresolution;
GUnit res_unit;
GimpImageBaseType type;
GimpFillType fill_type;
} GimpImageNewValues;
GList* image_new_get_fill_type_names ();
GList* image_new_get_image_base_type_names ();
void image_new_create_window (const GimpImageNewValues *values,
const GimpImage *image);
void image_new_set_default_values (const GimpImageNewValues *values);
GimpImageNewValues* image_new_values_new (const GimpImageNewValues *src_vals);
void image_new_values_free (GimpImageNewValues *values);
void image_new_create_image (const GimpImageNewValues *values);
gdouble image_new_calculate_size (GimpImageNewValues *values);
gchar* image_new_get_size_string (gdouble size);
void image_new_reset_current_cut_buffer ();
#ifdef __cplusplus
}
#endif
#endif /* __IMAGE_NEW__ */

View file

@ -72,6 +72,7 @@
#undef HAVE_GETTEXT #undef HAVE_GETTEXT
#undef HAVE_IPC_H #undef HAVE_IPC_H
#undef HAVE_LC_MESSAGES #undef HAVE_LC_MESSAGES
#undef HAVE_MMAP
#undef HAVE_NDIR_H #undef HAVE_NDIR_H
#undef HAVE_PROGRESSIVE_JPEG #undef HAVE_PROGRESSIVE_JPEG
#undef HAVE_PUTENV #undef HAVE_PUTENV
@ -87,7 +88,6 @@
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
#undef HAVE_VPRINTF #undef HAVE_VPRINTF
#undef HAVE_VSNPRINTF #undef HAVE_VSNPRINTF
#undef HAVE_XSHM_H
#undef IPC_RMID_DEFERRED_RELEASE #undef IPC_RMID_DEFERRED_RELEASE
@ -120,6 +120,9 @@
/* Define if you have the getpagesize function. */ /* Define if you have the getpagesize function. */
#undef HAVE_GETPAGESIZE #undef HAVE_GETPAGESIZE
/* Define if you have the mmap function. */
#undef HAVE_MMAP
/* Define if you have the munmap function. */ /* Define if you have the munmap function. */
#undef HAVE_MUNMAP #undef HAVE_MUNMAP