icon.cpp revision 279571c3b52fb405c355e112e13e04fdbdd7ac47
/** \file
* SPIcon: Generic icon widget
*/
/*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <cstring>
#include <gtkmm.h>
#include "path-prefix.h"
#include "preferences.h"
#include "inkscape.h"
#include "document.h"
#include "sp-item.h"
#include "display/nr-arena.h"
#include "display/nr-arena-item.h"
#include "icon.h"
unsigned r, unsigned g, unsigned b );
static void injectCustomSize();
static GtkWidgetClass *parent_class;
static bool sizeDirty = true;
static bool sizeMapDone = false;
static GtkIconSize iconSizeLookup[] = {
GTK_ICON_SIZE_MENU, // for Inkscape::ICON_SIZE_DECORATION
};
class IconCacheItem
{
public:
{}
};
{
//TODO: switch to GObject
// GtkType and such calls were deprecated a while back with the
// introduction of GObject as a separate layer, with GType instead. --JonCruz
if (!type) {
sizeof(SPIconClass),
NULL,
NULL,
NULL,
NULL,
sizeof(SPIcon),
0,
};
}
return type;
}
static void
{
}
static void
{
}
static void
{
}
}
}
}
}
static void
{
}
static void
{
if (GTK_WIDGET_DRAWABLE(widget)) {
}
}
{
if ( GTK_WIDGET_DRAWABLE(widget) ) {
}
}
return TRUE;
}
// PUBLIC CALL:
{
if ( icon ) {
}
if (!pb) {
pb = sp_icon_image_load_svg( icon->name, Inkscape::getRegisteredIconSize(icon->lsize), icon->psize );
// if this was loaded from SVG, add it as a builtin icon
}
if (!pb) {
}
if ( pb ) {
} else {
/* TODO: We should do something more useful if we can't load the image. */
}
}
}
}
{
}
}
{
}
}
{
//g_message("Got a change bump for this icon");
sizeDirty = true;
}
static GtkWidget *
{
gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
if ( !sizeMapDone ) {
}
if ( stockFound ) {
}
if ( !widget ) {
//g_message("Creating an SPIcon instance for %s:%d", name, (int)lsize);
}
return widget;
}
{
}
// PUBLIC CALL:
{
GtkWidget *widget = sp_icon_new_full( static_cast<Inkscape::IconSize>(Inkscape::getRegisteredIconSize(size)), oid.c_str() );
if ( widget ) {
if ( GTK_IS_IMAGE(widget) ) {
} else {
}
}
return result;
}
sp_icon_get_gtk_size(int size)
{
static int count = 0;
char c[64];
}
}
static void injectCustomSize()
{
// TODO - still need to handle the case of theme changes and resize, especially as we can't re-register a string.
if ( !sizeMapDone )
{
if ( newSizeEnum ) {
if ( dump ) {
g_message("Registered (%d, %d) <= (%d, %d) as index %d", newWidth, newHeight, width, height, newSizeEnum);
}
} else if ( dump ) {
g_message("size lookup array too small to store entry");
}
}
}
sizeMapDone = true;
}
static bool hit = false;
if ( !hit ) {
hit = true;
inkyIcons->add_default();
}
}
{
} else {
}
return other;
}
// PUBLIC CALL:
int sp_icon_get_phys_size(int size)
{
static bool init = false;
if ( !sizeMapDone ) {
}
GtkIconSize const gtkSizes[] = {
};
guint const val_ix = (gtkSizes[i] <= GTK_ICON_SIZE_DIALOG) ? (guint)gtkSizes[i] : (guint)Inkscape::ICON_SIZE_DECORATION;
}
}
}
if ( !init ) {
sizeDirty = false;
if ( dump ) {
g_message( "Default icon sizes:" );
}
GtkIconSize const gtkSizes[] = {
};
"GTK_ICON_SIZE_MENU",
"GTK_ICON_SIZE_SMALL_TOOLBAR",
"GTK_ICON_SIZE_LARGE_TOOLBAR",
"GTK_ICON_SIZE_BUTTON",
"GTK_ICON_SIZE_DND",
"GTK_ICON_SIZE_DIALOG",
"inkscape-decoration"
};
for (unsigned i = 0; i < G_N_ELEMENTS(gtkSizes); ++i) {
guint const val_ix = (gtkSizes[i] <= GTK_ICON_SIZE_DIALOG) ? (guint)gtkSizes[i] : (guint)Inkscape::ICON_SIZE_DECORATION;
bool used = false;
used = true;
}
if (dump) {
g_message(" =-- %u size:%d %c(%d, %d) '%s'",
i, gtkSizes[i],
}
if (pb) {
// TODO perhaps check a few more stock icons to get a range on sizes.
if ( newSize > 0 ) {
}
if (dump) {
}
}
}
//g_object_unref(icon);
init = true;
}
// Fixup workaround
if ((size == GTK_ICON_SIZE_MENU) || (size == GTK_ICON_SIZE_SMALL_TOOLBAR) || (size == GTK_ICON_SIZE_LARGE_TOOLBAR)) {
}
}
}
{
bool unref_image = false;
/* copied from the expose function of GtkImage */
gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used
unref_image = true;
}
if (image) {
int y = floor(widget.allocation.y + ((widget.allocation.height - widget.requisition.height) * 0.5));
// Limit drawing to when we actually have something. Avoids some crashes.
GDK_RGB_DITHER_NORMAL, x, y);
}
}
}
{
// TODO: bulia, please look over
gsize bytesWritten = 0;
-1,
&error);
if (!pb) {
// TODO: bulia, please look over
gsize bytesWritten = 0;
-1,
&error);
}
if (pb) {
if (!gdk_pixbuf_get_has_alpha(pb)) {
}
}
}
return pb;
}
// takes doc, root, icon, and icon name to produce pixels
extern "C" guchar *
{
if (doc) {
/* Find bbox in document */
{
}
/* This is in document coordinates, i.e. pixels */
if ( dbox ) {
/* Update to renderable state */
double sf = 1.0;
/* Item integer bbox in points */
if ( dump ) {
g_message( " box --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
}
/* Find button visible area */
if ( dump ) {
}
{
if ( dump ) {
g_message(" resizing" );
}
/* Item integer bbox in points */
if ( dump ) {
g_message( " box2 --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
}
/* Find button visible area */
if ( dump ) {
}
}
}
//dx = (psize - width) / 2;
//dy = (psize - height) / 2;
dx=(dx-width)/2; // watch out for psize, since 'unsigned'-'signed' can cause problems if the result is negative
/* Actual renderable area */
if ( dump ) {
g_message( " area --'%s' (%f,%f)-(%f,%f)", name, (double)area.x0, (double)area.y0, (double)area.x1, (double)area.y1 );
g_message( " ua --'%s' (%f,%f)-(%f,%f)", name, (double)ua.x0, (double)ua.y0, (double)ua.x1, (double)ua.y1 );
}
/* Set up pixblock */
/* Render */
NRPixBlock B;
nr_pixblock_release(&B);
if ( useOverlay ) {
}
}
}
}
return px;
} // end of sp_icon_doc_icon()
struct svg_doc_cache_t
{
};
{
key += ":";
return key;
}
}
return NULL;
}
{
static bool initialized = false;
if (!initialized) {
// Fall back from user prefs dir into system locations.
initialized = true;
}
return sources;
}
// this function renders icons from icons.svg and returns the pixels.
unsigned /*lsize*/, unsigned psize)
{
// Try each document in turn until we successfully load the icon from one
gchar *doc_filename = *i;
// Did we already load this doc?
info = 0;
{
}
}
/* Try to load from document. */
if (!info &&
//g_message("Loaded icon file %s", doc_filename);
// prep the document
/* Create new arena */
/* Create ArenaItem and set transform */
/* fixme: Memory manage root if needed (Lauris) */
// store into the cache
info = new svg_doc_cache_t;
}
if (info) {
}
// move on to the next document if we couldn't get anything
//if (px) g_message("Found icon %s in %s", name, doc_filename);
}
//if (!px) g_message("Not found icon %s", name);
return px;
}
{
if (!pb) {
if (px) {
}
}
if ( pb ) {
// increase refcount since we're handing out ownership
}
return pb;
}
unsigned r, unsigned g, unsigned b)
{
int bytesPerPixel = 4;
int spacing = 4;
*(ptr++) = r;
*(ptr++) = g;
*(ptr++) = b;
*(ptr++) = 0xff;
}
}
// point at the last pixel
if ( width > 2 ) {
px[4] = r;
px[5] = g;
px[6] = b;
ptr[-12] = r;
ptr[-11] = g;
ptr[-10] = b;
}
ptr[-4] = r;
ptr[-3] = g;
ptr[-2] = b;
if ( height > 2 ) {
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :