icon.cpp revision c830d132ea7f29e73b55f87badff602b065f8eac
/** \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 <gtk/gtkiconfactory.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkimage.h>
#include <gtkmm/iconfactory.h>
#include <gtkmm/iconsource.h>
#include <gtkmm/icontheme.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) {
GtkTypeInfo info = {
(gchar*) "SPIcon",
sizeof(SPIcon),
sizeof(SPIconClass),
};
}
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 ) {
GdkPixbuf *pb = sp_icon_image_load_svg( icon->name, Inkscape::getRegisteredIconSize(icon->lsize), icon->psize );
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 void setupLegacyNaming() {
}
static GtkWidget *
{
gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
if ( !sizeMapDone ) {
}
if ( legacyNames.empty() ) {
}
bool flagMe = false;
flagMe = true;
if ( dump ) {
}
} else {
}
if ( img ) {
if ( type == GTK_IMAGE_STOCK ) {
if ( !stockFound ) {
// It's not showing as a stock ID, so assume it will be present internally
// Add a hook to render if set visible before prerender is done.
g_signal_connect( G_OBJECT(img), "map", G_CALLBACK(imageMapCB), GINT_TO_POINTER(static_cast<int>(mappedSize)) );
if ( dump ) {
}
}
img = 0;
if ( dump ) {
g_message( "loaded gtk '%s' %d (GTK_IMAGE_STOCK) %s on %p", name, mappedSize, (stockFound ? "STOCK" : "local"), widget );
}
} else if ( type == GTK_IMAGE_ICON_NAME ) {
img = 0;
// Add a hook to render if set visible before prerender is done.
} else {
}
} else {
if ( dump ) {
}
//g_object_unref( (GObject *)img );
img = 0;
}
}
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;
}
}
{
if (image) {
: 0 );
: 0 );
int const x1 = std::min(area->x + area->width, widget.allocation.x + padx + static_cast<int>(icon->psize) );
int const y1 = std::min(area->y + area->height, widget.allocation.y + pady + static_cast<int>(icon->psize) );
// Limit drawing to when we actually have something. Avoids some crashes.
}
}
}
{
// 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 += ":";
key += ":";
return key;
}
}
return NULL;
}
unsigned /*lsize*/, unsigned psize)
{
// Fall back from user prefs dir into system locations.
iconsvg += ".svg";
// Try each document in turn until we successfully load the icon from one
// Did we already load this doc?
info = 0;
{
}
}
/* Try to load from document. */
if (!info &&
// 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) {
}
// toss the filename
// move on to the next document if we couldn't get anything
}
return px;
}
{
// only add a placeholder if nothing is already set
}
}
if ( !stockFound ) {
if (dump) {
}
}
for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
break;
}
}
for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
src.set_state_wildcarded( true );
}
}
// returns true if icon needed preloading, false if nothing was done
{
if (pb) {
return false;
} else {
if ( !px ) {
// check for a fallback name
if ( dump ) {
}
}
}
if (px) {
} else if (dump) {
}
return true;
}
}
{
if (!pb) {
if (px) {
}
}
if ( pb ) {
// increase refcount since we're handing out ownership
}
return pb;
}
unsigned r, unsigned g, unsigned b)
{
for ( int y = 0; y < height; y += 4 ) {
for ( int x = 0; x < width; x += 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 ) {
}
}
}
class preRenderItem
{
public:
{}
};
static bool callbackHooked = false;
{
if ( !callbackHooked )
{
callbackHooked = true;
}
}
if (!pendingRenders.empty()) {
bool workDone = false;
do {
}
if (!pendingRenders.empty()) {
return TRUE;
} else {
callbackHooked = false;
return FALSE;
}
}
if ( id ) {
//g_message("imageMapCB(%p) for %s:%d:%d", widget, id, lsize, psize);
for ( std::vector<preRenderItem>::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) {
//g_message(" prerender for %s:%d:%d", id, lsize, psize);
}
break;
}
}
}
}
if ( iconName ) {
if ( type == GTK_IMAGE_ICON_NAME ) {
for ( std::vector<preRenderItem>::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) {
break;
}
}
} else {
}
}
}
/*
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 :