Development/Resources
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
This page describes how to add new resources to a project. It has been written during the work on bug tdf#31521.
Creating resource files
First, we've to create resource files to handle our images. Resource files are splitted in two parts: the .hrc
and the .src
. The former will be included in cxx
files and contains resource ID assignments, while the later describes each resource (string, image).
Since each resource must have a unique ID, you have to find the file containing global resource IDs for the module you're working on, it's a .hrc often located in module/inc
. For calc it's inc/sc.hrc
, for writer inc/rcid.hrc
. Find the last affected ID range and get the next one. You have to add a define RC_YOUR_CATEGORY
, RC_YOUR_CATEGORY_BEGIN
(which are the same) and RC_YOUR_CATEGORY_END
which will be RC_YOUR_CATEGORY_BEGIN + MAX_RESOURCE_IDS_IN_YOUR_FILE - 1
Then, you can add your own file.hrc
, here is an example:
#ifndef _PAGEFRM_HRC
#define _PAGEFRM_HRC
#include "rcid.hrc"
// Bitmaps for page shadow
#define BMP_PAGE_TOP_RIGHT_SHADOW RC_PAGEFRM_BEGIN
#define BMP_PAGE_RIGHT_SHADOW RC_PAGEFRM_BEGIN + 1
#define BMP_PAGE_BOTTOM_RIGHT_SHADOW RC_PAGEFRM_BEGIN + 2
#define BMP_PAGE_BOTTOM_SHADOW RC_PAGEFRM_BEGIN + 3
#define BMP_PAGE_BOTTOM_LEFT_SHADOW RC_PAGEFRM_BEGIN + 4
// If you add resources, don't forget to update this
#define PAGEFRM_ACT_END BMP_PAGE_BOTTOMLEFT_SHADOW
// Sanity check
#if PAGEFRM_ACT_END > RC_PAINTFRM_END
#error Not enough room for pagefrm resource in #file:#line
#endif
#endif
And the .src
describing resources in details:
#include "pagefrm.hrc"
Bitmap BMP_PAGE_TOP_RIGHT_SHADOW
{
File = "page-topright-shadow.png";
};
Then, you can add the .src to the SRC1FILES
your makefile. Create SRS1NAME=$(TARGET)
if it does not exists.
Add the .srs to the variable RESLIB1LIST
variable of your module's util/makefile.mk
, put your images in default_images/[module]/res
and launch a build, all should be fine.
Accessing your images
If you are performing an incremental build you've to cd packimages && build && deliver
to get images packed correctly.
Loading an image is as simple as BitmapEx aBitmap( SW_RES( MY_ID ) );
(the prefix before _RES
varies between modules).