olta+pulkomandy:

* Introduce an add-on system to allow libbe to call things living inside liblocale (as liblocale depends on libbe, it can't be linked the usual way)
 * This allows localizing the BColorControl class that had some text inside it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36190 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues 2010-04-12 18:07:09 +00:00
parent 3d310bd5f4
commit 4343960f55
9 changed files with 216 additions and 8 deletions

View File

@ -1,6 +1,9 @@
1 english system 1811097932
1 french system 2677153267
%3.2f GiB StringForSize %3.2f Gio
%3.2f KiB StringForSize %3.2f Kio
%d bytes StringForSize %d octets
%.2f TiB StringForSize %.2f Tio
%3.2f MiB StringForSize %3.2f Mio
Red: ColorControl Rouge :
Green: ColorControl Vert :
Blue: ColorControl Bleu :

View File

@ -0,0 +1,34 @@
/*
* Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _LOCALE_BACKEND_H
#define _LOCALE_BACKEND_H
#include <SupportDefs.h>
namespace BPrivate {
class LocaleBackend {
public:
LocaleBackend();
virtual ~LocaleBackend();
virtual const char* GetString(const char* string,
const char* context = NULL,
const char* comment = NULL) = 0;
static status_t LoadBackend();
};
extern LocaleBackend* gLocaleBackend;
} // namespace BPrivate
#endif // _LOCALE_BACKEND_H

View File

@ -0,0 +1,32 @@
/*
* Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _LIBBE_LOCALE_BACKEND_H
#define _LIBBE_LOCALE_BACKEND_H
#include <LocaleBackend.h>
class BCatalogAddOn;
namespace BPrivate {
class LibbeLocaleBackend : public LocaleBackend {
public:
LibbeLocaleBackend();
virtual ~LibbeLocaleBackend();
virtual const char* GetString(const char* string,
const char* context = NULL,
const char* comment = NULL);
private:
BCatalogAddOn* systemCatalog;
};
} // namespace BPrivate
#endif // _LIBBE_LOCALE_BACKEND_H

View File

@ -19,6 +19,7 @@ if $(RUN_WITHOUT_APP_SERVER) != 0 {
UsePrivateHeaders [ FDirName kernel ] ; # For KMessage.h
#UsePrivateHeaders syslog_daemon ; # For syslog.cpp
UsePrivateHeaders libbe ;
# Build our libbe.so
@ -27,6 +28,7 @@ AddResources libbe.so : libbe_version.rdef ;
SetVersionScript libbe.so : libbe_versions ;
SharedLibrary libbe.so :
LocaleBackend.cpp
:
<libbe>app_kit.o
<libbe>interface_kit.o

View File

@ -0,0 +1,62 @@
/*
* Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
* Distributed under the terms of the MIT License.
*/
#include "LocaleBackend.h"
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <image.h>
namespace BPrivate {
LocaleBackend* gLocaleBackend = NULL;
static pthread_once_t sBackendInitOnce = PTHREAD_ONCE_INIT;
static void
LoadBackend()
{
image_id libLocaleAddonID = load_add_on("/system/lib/liblocale.so");
printf("backend-id: %ld\n", libLocaleAddonID);
if (libLocaleAddonID < 0)
return;
LocaleBackend* (*createInstanceFunc)();
if (get_image_symbol(libLocaleAddonID, "CreateLocaleBackendInstance",
B_SYMBOL_TYPE_TEXT, (void**)&createInstanceFunc) != B_OK)
return;
printf("invoking creator func\n");
gLocaleBackend = createInstanceFunc();
}
LocaleBackend::LocaleBackend()
{
}
LocaleBackend::~LocaleBackend()
{
}
status_t
LocaleBackend::LoadBackend()
{
if (gLocaleBackend == NULL)
pthread_once(&sBackendInitOnce, &BPrivate::LoadBackend);
return gLocaleBackend != NULL ? B_OK : B_ERROR;
}
} // namespace BPrivate

View File

@ -23,9 +23,17 @@
#include <Screen.h>
#include <Window.h>
#include <Catalog.h>
#include <LocaleBackend.h>
using BPrivate::gLocaleBackend;
using BPrivate::LocaleBackend;
#include <binary_compatibility/Interface.h>
#undef TR_CONTEXT
#define TR_CONTEXT "ColorControl"
static const uint32 kMsgColorEntered = 'ccol';
static const uint32 kMinCellSize = 6;
static const float kSelectorPenSize = 2.0f;
@ -68,6 +76,14 @@ void
BColorControl::_InitData(color_control_layout layout, float size,
bool useOffscreen, BMessage* archive)
{
// we need to translate some strings, and in order to do so, we need
// to use the LocaleBackend to reache liblocale.so
if (gLocaleBackend == NULL)
{
printf("trying to load backend\n");
LocaleBackend::LoadBackend();
printf("backend = %p\n", gLocaleBackend);
}
fPaletteMode = BScreen(B_MAIN_SCREEN_ID).ColorSpace() == B_CMAP8;
//TODO: we don't support workspace and colorspace changing for now
// so we take the main_screen colorspace at startup
@ -78,6 +94,15 @@ BColorControl::_InitData(color_control_layout layout, float size,
fSelectedPaletteColorIndex = -1;
fPreviousSelectedPaletteColorIndex = -1;
fFocusedComponent = 0;
const char* red = TR_MARK("Red:");
const char* green = TR_MARK("Green:");
const char* blue = TR_MARK("Blue:");
if (gLocaleBackend) {
red = gLocaleBackend->GetString(red, "ColorControl");
green = gLocaleBackend->GetString(green, "ColorControl");
blue = gLocaleBackend->GetString(blue, "ColorControl");
}
if (archive) {
fRedText = (BTextControl*)FindView("_red");
@ -95,7 +120,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
// red
fRedText = new BTextControl(rect, "_red", "Red:", "0",
fRedText = new BTextControl(rect, "_red", red, "0",
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
fRedText->SetDivider(labelWidth);
@ -111,7 +136,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
// green
rect.OffsetBy(0.0f, offset);
fGreenText = new BTextControl(rect, "_green", "Green:", "0",
fGreenText = new BTextControl(rect, "_green", green, "0",
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
fGreenText->SetDivider(labelWidth);
@ -125,7 +150,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
// blue
rect.OffsetBy(0.0f, offset);
fBlueText = new BTextControl(rect, "_blue", "Blue:", "0",
fBlueText = new BTextControl(rect, "_blue", blue, "0",
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
fBlueText->SetDivider(labelWidth);

View File

@ -26,7 +26,7 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
SetSubDirSupportedPlatforms haiku libbe_test ;
UseLibraryHeaders agg icon ;
UsePrivateHeaders app input print interface shared tracker ;
UsePrivateHeaders app input print interface libbe shared tracker ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) textview_support ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) layouter ] ;

View File

@ -1,6 +1,6 @@
SubDir HAIKU_TOP src kits locale ;
UsePrivateHeaders locale shared ;
UsePrivateHeaders libbe locale shared ;
UsePublicHeaders locale storage ;
UseLibraryHeaders icu ;
@ -24,6 +24,7 @@ SharedLibrary liblocale.so
IntegerFormatParameters.cpp
langinfo.cpp
Language.cpp
LibbeLocaleBackend.cpp
LibraryInit.cpp
Locale.cpp
LocaleRoster.cpp
@ -36,9 +37,13 @@ SharedLibrary liblocale.so
: be $(TARGET_LIBSTDC++) libicu-common.so libicu-i18n.so
;
SEARCH on [ FGristFiles StringForSize.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ;
SEARCH on [ FGristFiles ColorControl.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ;
DoCatalogs liblocale.so :
system
: ../shared/StringForSize.cpp
: StringForSize.cpp
ColorControl.cpp
:
: '"systemCatalog\\s*->\\s*GetString\\s*"'
: '"(systemCatalog\\s*->\\s*GetString\\s*|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)"'
;

View File

@ -0,0 +1,45 @@
/*
* Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de.
* Distributed under the terms of the MIT License.
*/
#include "LibbeLocaleBackend.h"
#include "Catalog.h"
#include "Locale.h"
#include "LocaleRoster.h"
#include <new>
namespace BPrivate {
extern "C" LocaleBackend*
CreateLocaleBackendInstance()
{
return new(std::nothrow) LibbeLocaleBackend();
}
LibbeLocaleBackend::LibbeLocaleBackend()
{
be_locale_roster->GetSystemCatalog(&systemCatalog);
}
LibbeLocaleBackend::~LibbeLocaleBackend()
{
}
const char*
LibbeLocaleBackend::GetString(const char* string, const char* context,
const char* comment)
{
return systemCatalog->GetString(string, context, comment);
}
} // namespace BPrivate