gboolean gtk_icon_cache_has_icon (GtkIconCache *cache, const gchar *icon_name) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; gint hash; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) return TRUE; chain_offset = GET_UINT32 (cache->buffer, chain_offset); } return FALSE; }
static gint find_image_offset (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; int hash; guint32 image_list_offset, n_images; int i; chain_offset = cache->last_chain_offset; if (chain_offset) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) goto find_dir; } hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { cache->last_chain_offset = chain_offset; goto find_dir; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } cache->last_chain_offset = 0; return 0; find_dir: /* We've found an icon list, now check if we have the right icon in it */ image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (i = 0; i < n_images; i++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) == directory_index) return image_list_offset + 4 + 8 * i; } return 0; }
gboolean gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache, const gchar *icon_name, const gchar *directory) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; gint hash; gboolean found_icon = FALSE; gint directory_index; directory_index = get_directory_index (cache, directory); if (directory_index == -1) return FALSE; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { found_icon = TRUE; break; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } if (found_icon) { guint32 image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); guint32 n_images = GET_UINT32 (cache->buffer, image_list_offset); guint32 image_offset = image_list_offset + 4; gint i; for (i = 0; i < n_images; i++) { guint16 index = GET_UINT16 (cache->buffer, image_offset); if (index == directory_index) return TRUE; image_offset += 8; } } return FALSE; }
static gint find_image_offset (GtkIconCache *cache, const gchar *icon_name, const gchar *directory) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; int hash, directory_index; guint32 image_list_offset, n_images; gboolean found = FALSE; int i; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { found = TRUE; break; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } if (!found) { return 0; } /* We've found an icon list, now check if we have the right icon in it */ directory_index = get_directory_index (cache, directory); image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (i = 0; i < n_images; i++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) == directory_index) return image_list_offset + 4 + 8 * i; } return 0; }