Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
176
Src/Wasabi/api/apiconfig.h
Normal file
176
Src/Wasabi/api/apiconfig.h
Normal file
|
@ -0,0 +1,176 @@
|
|||
#ifndef __API_DEF_CFG_H
|
||||
#define __API_DEF_CFG_H
|
||||
|
||||
#define WASABINOMAINAPI
|
||||
|
||||
#ifdef WASABI_COMPILE_APP
|
||||
# define WASABI_API_APP applicationApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SVC
|
||||
# define WASABI_API_SVC serviceApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SYSCB
|
||||
# define WASABI_API_SYSCB sysCallbackApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
# define WASABI_API_COMPONENT componentApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SCRIPT
|
||||
# define WASABI_API_MAKI makiApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_UTF
|
||||
# define WASABI_API_UTF utfApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WND
|
||||
# define WASABI_API_WND wndApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_IMGLDR
|
||||
# define WASABI_API_IMGLDR imgLoaderApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
# define WASABI_API_FILE fileApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_TIMERS
|
||||
# define WASABI_API_TIMER timerApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
# define WASABI_API_WNDMGR wndManagerApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
# define WASABI_API_SKIN skinApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_METADB
|
||||
# define WASABI_API_METADB metadbApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_LOCALES
|
||||
# define WASABI_API_LOCALE localeApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
# define WASABI_API_CONFIG configApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
# define WASABI_API_FONT fontApi
|
||||
// This sets the static font renderer. If you are compiling with api_config, the attribute to set is { 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } }, "Font Renderer"
|
||||
# if defined(WASABI_FONT_RENDERER_USE_WIN32)
|
||||
# define WASABI_FONT_RENDERER "" // "" is Win32
|
||||
# elif defined(WASABI_FONT_RENDERER_USE_FREETYPE)
|
||||
# define WASABI_FONT_RENDERER "Freetype" // Freetype lib
|
||||
# else
|
||||
# define WASABI_FONT_RENDERER "" // "" default for OS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MEMMGR
|
||||
# define WASABI_API_MEMMGR memmgrApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_XMLPARSER
|
||||
# define WASABI_API_XML xmlApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
# define WASABI_API_MEDIACORE coreApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_TEXTMODE
|
||||
# define WASABI_API_TEXTMODE textmodeApi
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
# define WASABI_COMPILE_LINUX
|
||||
# define WASABI_API_LINUX linuxApi
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_STATSWND
|
||||
# if defined(_DEBUG) | defined(WASABI_DEBUG)
|
||||
# define WASABI_COMPILE_STATSWND
|
||||
# ifndef WASABI_DEBUG
|
||||
# define WASABI_DEBUG
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_APP
|
||||
# include <api/application/api_application.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SVC
|
||||
# include <api/service/api_service.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SYSCB
|
||||
# include <api/syscb/api_syscb.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MEMMGR
|
||||
# include <api/memmgr/api_memmgr.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SCRIPT
|
||||
# include <api/script/api_maki.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
# include <api/font/api_font.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WND
|
||||
# include <api/wnd/api_wnd.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_IMGLDR
|
||||
# include <api/imgldr/api_imgldr.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
# include <api/filereader/api_filereader.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_TIMERS
|
||||
# include <api/timer/api_timer.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
# include <api/wndmgr/api_wndmgr.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_LOCALES
|
||||
# include <api/locales/api_locales.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
# include <api/config/api_config.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
# include <api/skin/api_skin.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
# include <api/script/debugger/api_makidebug.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_TEXTMODE
|
||||
# include <api/textmode/api_textmode.h>
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_API_LINUX
|
||||
#include <api/linux/api_linux.h>
|
||||
#endif
|
||||
|
||||
#endif
|
548
Src/Wasabi/api/apiinit.cpp
Normal file
548
Src/Wasabi/api/apiinit.cpp
Normal file
|
@ -0,0 +1,548 @@
|
|||
#include "./wndmgr/layout.h"
|
||||
|
||||
#include <tataki/export.h>
|
||||
//<?#include "<class data="implementationheader"/>"
|
||||
#include "apiinit.h"
|
||||
//?>
|
||||
|
||||
#include <api/memmgr/api_memmgr.h>
|
||||
|
||||
#define WASABI_SAYMYNAME
|
||||
#include <wasabicfg.h>
|
||||
#undef WASABI_SAYMYNAME
|
||||
|
||||
#include <api/service/servicei.h>
|
||||
#include <api/locales/api_localesi.h>
|
||||
#include <api/config/api_configi.h>
|
||||
#include <api/config/items/cfgitem.h>
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
#include <api/font/FontCreator.h>
|
||||
#include <api/font/fontapi.h>
|
||||
#endif
|
||||
#include <api/skin/skinapi.h>
|
||||
#include <api/skin/groupwndcreate.h>
|
||||
#include <api/script/makiapi.h>
|
||||
#include <api/script/objecttable.h>
|
||||
#include <api/wnd/wndapi.h>
|
||||
#include <api/wnd/wndclass/foreignwnd.h>
|
||||
#include <api/wnd/wndclass/clickwnd.h>
|
||||
#include <api/imgldr/imgldrapi.h>
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
#ifdef WIN32
|
||||
# include <api/font/win32/truetypefont_win32.h>
|
||||
#elif defined(LINUX)
|
||||
# include <api/font/linux/truetypefont_linux.h>
|
||||
#else
|
||||
# error port me
|
||||
#endif // platform
|
||||
#endif // fonts
|
||||
|
||||
#include <api/wndmgr/wndmgrapi.h>
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
#include <api/script/debugger/debugapi.h>
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
#include <api/core/api_core.h>
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
#include <api/filereader/filereaderapi.h>
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
#include <api/filereader/zip/zipread.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_LINUX
|
||||
#include <api/linux/api_linuxi.h>
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_TEXTMODE
|
||||
#if defined(WIN32)
|
||||
#include <api/textmode/textmode_win32.h>
|
||||
#elif defined(LINUX)
|
||||
#include <api/textmode/textmode_ncurses.h>
|
||||
#else // dummy
|
||||
#include <api/textmode/api_textmodeI.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WASABI_COMPILE_COMPONENTS) | defined(GEN_FF) // MULTIAPI-FIXME
|
||||
#include <api/wac/compon.h>
|
||||
#endif
|
||||
|
||||
#include <api/wndmgr/gc.h>
|
||||
|
||||
#include <api/application/api_application.h>
|
||||
#ifndef WASABI_CUSTOM_MODULE_SVCMGR
|
||||
DECLARE_MODULE_SVCMGR;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
extern HINSTANCE hInstance;
|
||||
#endif
|
||||
|
||||
extern StringW g_resourcepath;
|
||||
api_application *applicationApi = NULL;
|
||||
timer_api *timerApi = NULL;
|
||||
|
||||
int ApiInit::init(OSMODULEHANDLE hinstance, OSWINDOWHANDLE mainwnd, api_service *wa5_svc)
|
||||
{
|
||||
Tataki::Init(wa5_svc);
|
||||
serviceApi = wa5_svc;
|
||||
initcount++;
|
||||
|
||||
#ifndef WA3COMPATIBILITY
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init callback system
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(syscbApiServiceGuid);
|
||||
if (sf) sysCallbackApi = reinterpret_cast<api_syscb *>(sf->getInterface());
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init application API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
|
||||
if (sf) applicationApi = reinterpret_cast<api_application *>(sf->getInterface());
|
||||
|
||||
g_resourcepath = StringPathCombine(WASABI_API_APP->path_getAppPath(), WASABI_RESOURCES_SUBDIRECTORY);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init centralized memory manager api
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
sf = WASABI_API_SVC->service_getServiceByGuid(memMgrApiServiceGuid);
|
||||
if (sf) WASABI_API_MEMMGR = reinterpret_cast<api_memmgr *>(sf->getInterface());
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
// ------------------------------------------------------------------------
|
||||
// Init file reader api and optional file readers
|
||||
// ------------------------------------------------------------------------
|
||||
fr = new FileReaderApi();
|
||||
fileApi = fr;
|
||||
WASABI_API_SVC->service_register(frapisvc = new FileReaderApiService());
|
||||
//WASABI_API_SVC->service_register(&diskReader);
|
||||
// set up custom file readers
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
zipRead = new waServiceTSingle<svc_fileReader, ZipRead>;
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
WASABI_API_SVC->service_register(zipRead);
|
||||
#endif
|
||||
#endif // WASABI_COMPILE_FILEREADER
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init config api and register optional config items
|
||||
// ------------------------------------------------------------------------
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
cfg = new api_configI();
|
||||
configApi = cfg;
|
||||
WASABI_API_SVC->service_register(cfgapisvc = new ConfigApiService());
|
||||
#endif
|
||||
|
||||
// if no static service was ever declared, we need to init it so we don't hit null
|
||||
INIT_MODULE_SVCMGR();
|
||||
|
||||
DebugStringW(L"Auto-initializing %d services (system pass)\n", staticServiceMgr->__m_modules2.getNumItems());
|
||||
MODULE_SVCMGR_ONINIT2();
|
||||
|
||||
#ifdef WASABI_COMPILE_IMGLDR
|
||||
// ------------------------------------------------------------------------
|
||||
// Init image loading api and optional image formats
|
||||
// ------------------------------------------------------------------------
|
||||
img = new ImgLdrApi();
|
||||
imgLoaderApi = img;
|
||||
WASABI_API_SVC->service_register(imgldrapisvc = new ImgLdrApiService());
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
// ------------------------------------------------------------------------
|
||||
// Init font rendering api
|
||||
// ------------------------------------------------------------------------
|
||||
font = new FontApi();
|
||||
fontApi = font;
|
||||
win32Font = new FontCreator<TrueTypeFont_Win32>;
|
||||
WASABI_API_SVC->service_register(win32Font);
|
||||
WASABI_API_SVC->service_register(fontapisvc = new FontApiService());
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_LOCALES
|
||||
// ------------------------------------------------------------------------
|
||||
// Init localization
|
||||
// ------------------------------------------------------------------------
|
||||
loc = new api_localesI();
|
||||
localesApi = loc;
|
||||
WASABI_API_SVC->service_register(localesapisvc = new LocalesApiService());
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init timer api
|
||||
// ------------------------------------------------------------------------
|
||||
sf = WASABI_API_SVC->service_getServiceByGuid(timerApiServiceGuid);
|
||||
if (sf) timerApi = reinterpret_cast<timer_api *>(sf->getInterface());
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_WND
|
||||
// ------------------------------------------------------------------------
|
||||
// Init window api
|
||||
// ------------------------------------------------------------------------
|
||||
wnd = new WndApi();
|
||||
wndApi = wnd;
|
||||
#ifdef _WIN32
|
||||
if (mainwnd != NULL)
|
||||
{
|
||||
mainWnd = new ForeignWnd(mainwnd, hInstance);
|
||||
DebugStringW(L"main wnd handle is %x\n", mainWnd->gethWnd());
|
||||
wnd->main_setRootWnd(mainWnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
default_mainWnd = new ClickWnd();
|
||||
default_mainWnd->init(hInstance, NULL, TRUE);
|
||||
wnd->main_setRootWnd(default_mainWnd);
|
||||
}
|
||||
#endif
|
||||
WASABI_API_SVC->service_register(wndapisvc = new WndApiService());
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Init media core api
|
||||
// ------------------------------------------------------------------------
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
#ifndef WA3COMPATIBILITY
|
||||
#ifdef WASABI_CUSTOMIMPL_MEDIACORE
|
||||
coreApi = createCustomCoreApi();
|
||||
#else
|
||||
#error "not done yet"
|
||||
#endif
|
||||
#endif
|
||||
WASABI_API_SVC->service_register(coreapisvc = new CoreApiService());
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
// ------------------------------------------------------------------------
|
||||
// Init window manager api
|
||||
// ------------------------------------------------------------------------
|
||||
wndmgr = new WndMgrApi ();
|
||||
wndManagerApi = wndmgr;
|
||||
WASABI_API_SVC->service_register(wndmgrapisvc = new WndMgrApiService());
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
// ------------------------------------------------------------------------
|
||||
// Init skin
|
||||
// ------------------------------------------------------------------------
|
||||
skin = new SkinApi();
|
||||
skinApi = skin;
|
||||
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
groupcreate = new waServiceTSingle<svc_windowCreate, GroupWndCreateSvc>;
|
||||
WASABI_API_SVC->service_register(groupcreate);
|
||||
#endif
|
||||
|
||||
WASABI_API_SVC->service_register(skinapisvc = new SkinApiService());
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
// ------------------------------------------------------------------------
|
||||
// Init script debugger api
|
||||
// ------------------------------------------------------------------------
|
||||
debug = new MakiDebuggerApi();
|
||||
debugApi = debug;
|
||||
WASABI_API_SVC->service_register(makidebugapisvc = new MakiDebugApiService());
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
widgets = new Widgets();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
DebugStringW(L"Auto-initializing %d services (user pass)\n", staticServiceMgr->__m_modules.getNumItems());
|
||||
MODULE_SVCMGR_ONINIT();
|
||||
|
||||
#ifndef WA3COMPATIBILITY
|
||||
|
||||
#ifdef WASABI_COMPILE_SCRIPT
|
||||
// ------------------------------------------------------------------------
|
||||
// Init scripting api
|
||||
// ------------------------------------------------------------------------
|
||||
maki = new api_makiI();
|
||||
makiApi = maki;
|
||||
WASABI_API_SVC->service_register(makiapisvc = new MakiApiService());
|
||||
maki->init();
|
||||
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
garbageCollector = new GarbageCollector();
|
||||
#endif
|
||||
|
||||
ObjectTable::start();
|
||||
#endif
|
||||
|
||||
#endif //wa3compat
|
||||
|
||||
return 1; // success
|
||||
}
|
||||
|
||||
int ApiInit::shutdown()
|
||||
{
|
||||
#ifndef WA3COMPATIBILITY
|
||||
|
||||
garbageCollector->gccb_onGarbageCollect();
|
||||
delete garbageCollector;
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
skin->preShutdown();
|
||||
#endif
|
||||
|
||||
MODULE_SVCMGR_ONSHUTDOWN();
|
||||
|
||||
#ifdef _WIN32
|
||||
ComponentManager::unloadAll();
|
||||
#else
|
||||
#warning port me?
|
||||
#endif
|
||||
|
||||
WASABI_API_SVC->service_deregister(skinapisvc);
|
||||
delete skin;
|
||||
skinApi = NULL;
|
||||
|
||||
delete skinapisvc;
|
||||
skinapisvc = 0;
|
||||
|
||||
#ifdef WASABI_COMPILE_SCRIPT
|
||||
ObjectTable::shutdown();
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
delete widgets;
|
||||
widgets = NULL;
|
||||
#endif
|
||||
WASABI_API_SVC->service_deregister(makiapisvc);
|
||||
delete maki;
|
||||
makiApi = NULL;
|
||||
|
||||
delete makiapisvc;
|
||||
makiapisvc = 0;
|
||||
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
WASABI_API_SVC->service_deregister(groupcreate);
|
||||
delete groupcreate;
|
||||
groupcreate = 0;
|
||||
#endif
|
||||
|
||||
WASABI_API_SVC->service_deregister(win32Font);
|
||||
delete win32Font;
|
||||
win32Font = 0;
|
||||
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
#ifndef WA3COMPATIBILITY
|
||||
#ifdef WASABI_CUSTOMIMPL_MEDIACORE
|
||||
destroyCustomCoreApi(coreApi);
|
||||
#else
|
||||
#error "not done yet"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
WASABI_API_SVC->service_deregister(coreapisvc);
|
||||
delete coreapisvc;
|
||||
coreapisvc = 0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
WASABI_API_SVC->service_deregister(wndmgrapisvc);
|
||||
delete wndmgr;
|
||||
wndManagerApi = NULL;
|
||||
|
||||
|
||||
delete wndmgrapisvc;
|
||||
wndmgrapisvc = 0;
|
||||
|
||||
|
||||
delete loc;
|
||||
localesApi = NULL;
|
||||
|
||||
WASABI_API_SVC->service_deregister(localesapisvc);
|
||||
delete localesapisvc;
|
||||
localesapisvc = 0;
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
WASABI_API_SVC->service_deregister(zipRead);
|
||||
delete zipRead;
|
||||
#endif
|
||||
|
||||
|
||||
delete fr;
|
||||
fileApi = NULL;
|
||||
|
||||
WASABI_API_SVC->service_deregister(frapisvc);
|
||||
delete frapisvc;
|
||||
frapisvc = 0;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
delete mainWnd;
|
||||
mainWnd = NULL;
|
||||
delete default_mainWnd;
|
||||
default_mainWnd = NULL;
|
||||
WASABI_API_SVC->service_deregister(wndapisvc);
|
||||
delete wnd;
|
||||
wndApi = NULL;
|
||||
|
||||
delete wndapisvc;
|
||||
wndapisvc = 0;
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
WASABI_API_SVC->service_deregister(fontapisvc);
|
||||
delete font;
|
||||
fontApi = NULL;
|
||||
|
||||
delete fontapisvc;
|
||||
fontapisvc = 0;
|
||||
#endif
|
||||
|
||||
#ifndef WA3COMPATIBILITY
|
||||
|
||||
|
||||
delete img;
|
||||
imgLoaderApi = NULL;
|
||||
|
||||
WASABI_API_SVC->service_deregister(imgldrapisvc);
|
||||
delete imgldrapisvc;
|
||||
imgldrapisvc = 0;
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
WASABI_API_SVC->service_deregister(cfgapisvc);
|
||||
delete cfg;
|
||||
configApi = NULL;
|
||||
|
||||
delete cfgapisvc;
|
||||
cfgapisvc = 0;
|
||||
#endif
|
||||
|
||||
MODULE_SVCMGR_ONSHUTDOWN2();
|
||||
|
||||
WASABI_API_MEMMGR = NULL;
|
||||
|
||||
applicationApi=NULL;
|
||||
#endif //wa3compatibility
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
delete debug;
|
||||
debugApi = NULL;
|
||||
|
||||
WASABI_API_SVC->service_deregister(makidebugapisvc);
|
||||
delete makidebugapisvc;
|
||||
makidebugapisvc = 0;
|
||||
#endif
|
||||
|
||||
if (alphaMgr)
|
||||
delete alphaMgr;
|
||||
alphaMgr=0;
|
||||
|
||||
// TODO: releaseInterface
|
||||
timerApi = NULL;
|
||||
|
||||
Tataki::Quit();
|
||||
sysCallbackApi = NULL;
|
||||
|
||||
return 1; // success
|
||||
}
|
||||
|
||||
int ApiInit::getInitCount()
|
||||
{
|
||||
return initcount;
|
||||
}
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
waServiceFactoryI * ApiInit::groupcreate = NULL;
|
||||
#endif
|
||||
#endif //WASABI_COMPILE_SKIN
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
waServiceFactoryI * ApiInit::win32Font = NULL;
|
||||
FontApiService *ApiInit::fontapisvc = NULL;
|
||||
#endif //WASABI_COMPILE_FONTS
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
Widgets * ApiInit::widgets = NULL;
|
||||
SkinApiService *ApiInit::skinapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
api_configI * ApiInit::cfg = NULL;
|
||||
ConfigApiService *ApiInit::cfgapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_IMGLDR
|
||||
ImgLdrApi * ApiInit::img = NULL;
|
||||
ImgLdrApiService *ApiInit::imgldrapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
FontApi * ApiInit::font = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
FileReaderApi * ApiInit::fr = NULL;
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
waServiceFactoryI * ApiInit::zipRead = NULL;
|
||||
#endif
|
||||
FileReaderApiService *ApiInit::frapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_LOCALES
|
||||
api_localesI * ApiInit::loc = NULL;
|
||||
LocalesApiService *ApiInit::localesapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WND
|
||||
WndApi * ApiInit::wnd = NULL;
|
||||
ForeignWnd * ApiInit::mainWnd = NULL;
|
||||
ClickWnd * ApiInit::default_mainWnd = NULL;
|
||||
WndApiService *ApiInit::wndapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
WndMgrApi * ApiInit::wndmgr = NULL;
|
||||
WndMgrApiService *ApiInit::wndmgrapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SCRIPT
|
||||
api_makiI * ApiInit::maki = NULL;
|
||||
MakiApiService *ApiInit::makiapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
SkinApi * ApiInit::skin = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
MakiDebuggerApi * ApiInit::debug = NULL;
|
||||
MakiDebugApiService *ApiInit::makidebugapisvc = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
CoreApiService *ApiInit::coreapisvc = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
int ApiInit::initcount = 0;
|
||||
|
||||
api_memmgr *memmgrApi = NULL;
|
255
Src/Wasabi/api/apiinit.h
Normal file
255
Src/Wasabi/api/apiinit.h
Normal file
|
@ -0,0 +1,255 @@
|
|||
#ifndef __API_INIT_H
|
||||
#define __API_INIT_H
|
||||
|
||||
#include <bfc/platform/platform.h>
|
||||
#include <api/skin/widgets.h>
|
||||
#include <bfc/string/bfcstring.h>
|
||||
#include <api/syscb/api_syscbi.h>
|
||||
#include <api/service/service.h>
|
||||
|
||||
class api_configI;
|
||||
class SkinApi;
|
||||
class api_makiI;
|
||||
class MemMgrApi;
|
||||
class TimerApi;
|
||||
class WndApi;
|
||||
class ForeignWnd;
|
||||
class ClickWnd;
|
||||
|
||||
class ImgLdrApi;
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
class FontApi;
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
class WndMgrApi;
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
class MakiDebuggerApi;
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
class FileReaderApi;
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_LOCALES
|
||||
class api_localesI;
|
||||
#endif
|
||||
#ifndef WA3COMPATIBILITY
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
class Core;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <api/syscb/api_syscb.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
|
||||
#include <api/core/api_core.h>
|
||||
|
||||
class CoreApiService : public waServiceBase<api_core, CoreApiService> {
|
||||
public:
|
||||
CoreApiService() : waServiceBase<api_core, CoreApiService>(coreApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Core API"; }
|
||||
virtual api_core *getService() { return coreApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_MEDIACORE
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
|
||||
#include <api/filereader/api_filereader.h>
|
||||
|
||||
class FileReaderApiService : public waServiceBase<api_fileReader, FileReaderApiService> {
|
||||
public:
|
||||
FileReaderApiService() : waServiceBase<api_fileReader, FileReaderApiService>(fileReaderApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "FileReader API"; }
|
||||
virtual api_fileReader *getService() { return fileApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_FILEREADER
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
|
||||
#include <api/config/api_config.h>
|
||||
|
||||
class ConfigApiService : public waServiceBase<api_config, ConfigApiService> {
|
||||
public:
|
||||
ConfigApiService() : waServiceBase<api_config, ConfigApiService>(configApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Config API"; }
|
||||
virtual api_config *getService() { return configApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_CONFIG
|
||||
|
||||
#ifdef WASABI_COMPILE_IMGLDR
|
||||
|
||||
#include <api/imgldr/api_imgldr.h>
|
||||
|
||||
class ImgLdrApiService: public waServiceBase<imgldr_api, ImgLdrApiService> {
|
||||
public:
|
||||
ImgLdrApiService() : waServiceBase<imgldr_api, ImgLdrApiService>(imgLdrApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Image Loading API"; }
|
||||
virtual imgldr_api *getService() { return imgLoaderApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_IMGLDR
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
|
||||
#include <api/font/api_font.h>
|
||||
|
||||
class FontApiService : public waServiceBase<api_font, FontApiService> {
|
||||
public:
|
||||
FontApiService() : waServiceBase<api_font, FontApiService>(fontApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Font Rendering API"; }
|
||||
virtual api_font *getService() { return fontApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_FONT
|
||||
|
||||
|
||||
#include <api/locales/api_locales.h>
|
||||
|
||||
class LocalesApiService : public waServiceBase<api_locales, LocalesApiService> {
|
||||
public:
|
||||
LocalesApiService() : waServiceBase<api_locales, LocalesApiService>(localesApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Locales API"; }
|
||||
virtual api_locales *getService() { return localesApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#include <api/wnd/api_wnd.h>
|
||||
|
||||
class WndApiService : public waServiceBase<wnd_api, WndApiService> {
|
||||
public:
|
||||
WndApiService() : waServiceBase<wnd_api, WndApiService>(wndApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Windowing API"; }
|
||||
virtual wnd_api *getService() { return wndApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
|
||||
#include <api/wndmgr/api_wndmgr.h>
|
||||
|
||||
class WndMgrApiService : public waServiceBase<wndmgr_api, WndMgrApiService> {
|
||||
public:
|
||||
WndMgrApiService() : waServiceBase<wndmgr_api, WndMgrApiService>(wndMgrApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Window Manager API"; }
|
||||
virtual wndmgr_api *getService() { return wndManagerApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#include <api/skin/api_skin.h>
|
||||
|
||||
class SkinApiService : public waServiceBase<api_skin, SkinApiService> {
|
||||
public:
|
||||
SkinApiService() : waServiceBase<api_skin, SkinApiService>(skinApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "Skinning API"; }
|
||||
virtual api_skin *getService() { return skinApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#include <api/script/api_maki.h>
|
||||
|
||||
class MakiApiService : public waServiceBase<api_maki, MakiApiService> {
|
||||
public:
|
||||
MakiApiService() : waServiceBase<api_maki, MakiApiService>(makiApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "MAKI Scripting API"; }
|
||||
virtual api_maki *getService() { return makiApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
|
||||
#include <api/script/debugger/api_makidebug.h>
|
||||
|
||||
class MakiDebugApiService : public waServiceBase<api_makiDebugger, MakiDebugApiService> {
|
||||
public:
|
||||
MakiDebugApiService() : waServiceBase<api_makiDebugger, MakiDebugApiService>(makiDebugApiServiceGuid) {}
|
||||
static const char *getServiceName() { return "MAKI Debugger API"; }
|
||||
virtual api_makiDebugger *getService() { return debugApi; }
|
||||
static FOURCC getServiceType() { return WaSvc::UNIQUE; }
|
||||
};
|
||||
|
||||
#endif // WASABI_COMPILE_SKIN
|
||||
|
||||
class ApiInit
|
||||
{
|
||||
public:
|
||||
static int init(OSMODULEHANDLE hinstance, OSWINDOWHANDLE mainwnd, api_service *wa5_svc); // 0 == error, 1 == success
|
||||
static int shutdown(); // 0 == error, 1 == success
|
||||
static int getInitCount(); // if you do init / shutdown more than once in the session, this may be useful to invalid some caches
|
||||
|
||||
private:
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
static waServiceFactoryI * groupcreate;
|
||||
#endif //WASABI_COMPILE_COMPONENTS
|
||||
#endif //WASABI_COMPILE_SKIN
|
||||
|
||||
static waServiceFactoryI * win32Font;
|
||||
static FontApiService *fontapisvc;
|
||||
|
||||
public:
|
||||
static Widgets * widgets;
|
||||
private:
|
||||
static SkinApiService *skinapisvc;
|
||||
|
||||
static api_configI * cfg;
|
||||
static ConfigApiService *cfgapisvc;
|
||||
static ImgLdrApi * img;
|
||||
static ImgLdrApiService *imgldrapisvc;
|
||||
|
||||
#ifdef WASABI_COMPILE_FONTS
|
||||
static FontApi * font;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_FILEREADER
|
||||
static FileReaderApi * fr;
|
||||
#ifdef WASABI_COMPILE_ZIPREADER
|
||||
static waServiceFactoryI * zipRead;
|
||||
#endif
|
||||
static FileReaderApiService *frapisvc;
|
||||
#endif
|
||||
|
||||
static api_localesI *loc;
|
||||
static LocalesApiService *localesapisvc;
|
||||
|
||||
static WndApi * wnd;
|
||||
static ForeignWnd * mainWnd;
|
||||
static ClickWnd * default_mainWnd;
|
||||
static WndApiService *wndapisvc;
|
||||
|
||||
static WndMgrApi * wndmgr;
|
||||
static WndMgrApiService *wndmgrapisvc;
|
||||
|
||||
|
||||
static api_makiI * maki;
|
||||
static MakiApiService *makiapisvc;
|
||||
|
||||
static SkinApi * skin;
|
||||
|
||||
#ifdef WASABI_COMPILE_MAKIDEBUG
|
||||
static MakiDebuggerApi * debug;
|
||||
static MakiDebugApiService *makidebugapisvc;
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
static CoreApiService *coreapisvc;
|
||||
#endif
|
||||
|
||||
static int initcount;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
12
Src/Wasabi/api/application/api_application.cpp
Normal file
12
Src/Wasabi/api/application/api_application.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Wed May 07 00:55:56 2003]
|
||||
//
|
||||
// File : api_application.cpp
|
||||
// Class : api_application
|
||||
// class layer : Dispatchable Interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <precomp.h>
|
||||
#include "api_application.h"
|
||||
|
||||
|
416
Src/Wasabi/api/application/api_application.h
Normal file
416
Src/Wasabi/api/application/api_application.h
Normal file
|
@ -0,0 +1,416 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Wed May 07 00:55:56 2003]
|
||||
//
|
||||
// File : api_application.h
|
||||
// Class : api_application
|
||||
// class layer : Dispatchable Interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __API_APPLICATION_H
|
||||
#define __API_APPLICATION_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/platform/guid.h>
|
||||
#include <bfc/platform/platform.h>
|
||||
#ifdef _WIN32
|
||||
#include "ifc_messageprocessor.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
API_APPLICATION_SUCCESS = 0,
|
||||
API_APPLICATION_FAILURE = 1,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TRANSLATE_MODE_NORMAL = 0,
|
||||
TRANSLATE_MODE_GLOBAL = 1,
|
||||
TRANSLATE_MODE_CHILD = 2,
|
||||
};
|
||||
|
||||
class NOVTABLE api_application: public Dispatchable
|
||||
{
|
||||
protected:
|
||||
api_application() {}
|
||||
~api_application() {}
|
||||
|
||||
public:
|
||||
const wchar_t *main_getAppName(); // returns (e.g.) "Winamp"
|
||||
const wchar_t *main_getVersionString(); // returns (e.g.) "Winamp 5.12"
|
||||
const wchar_t *main_getVersionNumString(); // returns (e.g.) "5.12"
|
||||
unsigned int main_getBuildNumber(); // returns (e.g.) 666
|
||||
GUID main_getGUID();
|
||||
|
||||
#ifdef _WIN32
|
||||
HANDLE main_getMainThreadHandle(); // This actually gives you a DuplicateHandle, so call CloseHandle() when you are done.
|
||||
HINSTANCE main_gethInstance();
|
||||
#endif // !_WIN32
|
||||
|
||||
const wchar_t *main_getCommandLine();
|
||||
void main_shutdown( int deferred = TRUE );
|
||||
void main_cancelShutdown();
|
||||
int main_isShuttingDown();
|
||||
const wchar_t *path_getAppPath();
|
||||
const wchar_t *path_getUserSettingsPath();
|
||||
|
||||
// added for 5.58+ so gen_ff can fill @SKINSPATH@ in scripts correctly
|
||||
const wchar_t *path_getSkinSettingsPath();
|
||||
int app_getInitCount();
|
||||
intptr_t app_messageLoopStep();
|
||||
|
||||
#ifdef _WIN32
|
||||
void app_addMessageProcessor( ifc_messageprocessor *processor );
|
||||
void app_removeMessageProcessor( ifc_messageprocessor *processor );
|
||||
|
||||
/* accelerators are 5.53+ */
|
||||
void app_addAccelerators( HWND hwnd, HACCEL *phAccel, INT cAccel, UINT translateMode );
|
||||
void app_removeAccelerators( HWND hwnd );
|
||||
bool app_translateAccelerators( MSG *msg );
|
||||
int app_getAccelerators( HWND hwnd, HACCEL *phAccel, INT cchAccelMax, BOOL bGlobal ); // phAccel == NULL && cchAccelMax == 0 -> returns accels count
|
||||
|
||||
/* register window as part of winamp global group (5.54+) */
|
||||
void app_registerGlobalWindow( HWND hwnd );
|
||||
void app_unregisterGlobalWindow( HWND hwnd );
|
||||
|
||||
/* 5.58 + */
|
||||
bool DirectMouseWheel_RegisterSkipClass( ATOM klass );
|
||||
bool DirectMouseWheel_UnregisterSkipClass( ATOM klass );
|
||||
bool DirectMouseWheel_EnableConvertToMouseWheel( HWND hwnd, BOOL enable ); // !!! must be disabled before window destroyed !!!
|
||||
|
||||
/* 5.64 + */
|
||||
BOOL DirectMouseWheel_ProcessDialogMessage( HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam, const int controls[], int controlslen );
|
||||
|
||||
/* 5.61 + */
|
||||
void ActiveDialog_Register( HWND hwnd );
|
||||
void ActiveDialog_Unregister( HWND hwnd );
|
||||
HWND ActiveDialog_Get();
|
||||
|
||||
/* 5.64 + */
|
||||
const wchar_t *getATFString(); // returns the current ATF formatting string
|
||||
|
||||
/* 5.66 + */
|
||||
// used for dpi scaling so we're consistent in usage throughout the UI, etc
|
||||
int getScaleX( int x );
|
||||
int getScaleY( int y );
|
||||
|
||||
#endif // !_WIN32
|
||||
|
||||
/*
|
||||
note: on windows, these two functions DON'T call Set/GetCurrentDirectory, Winamp maintains it's own path
|
||||
because calling SetCurrentDirectory locks the folder
|
||||
Added for 5.34
|
||||
*/
|
||||
const wchar_t *path_getWorkingPath(); // useful to call for populating lpstrInitialDir in GetOpenFileName
|
||||
void path_setWorkingPath(const wchar_t *newPath); // useful to call for populating lpstrInitialDir in GetOpenFileName
|
||||
|
||||
/*
|
||||
The following three function return you unique IDs you can use if you need
|
||||
They are created anonymously, so information cannot be tracked back to a specific person
|
||||
The main reason for their existence is that a few third party libraries require them
|
||||
and some online media providers require this info for billing.
|
||||
You can call this functions with a pointer to any 16 byte data structure cast to a GUID *
|
||||
Added for 5.35
|
||||
*/
|
||||
// returns an ID unique to this computer, but not unique to the logged in user (two windows accts would share this ID)
|
||||
int GetMachineID( GUID *id );
|
||||
// returns an ID unique to this user. Another user logged in to the computer will have a different ID
|
||||
// note that if Winamp was installed with "shared settings", the IDs of multiple users will probably be identical
|
||||
// as we're just storing it in winamp.ini for now
|
||||
int GetUserID( GUID *id );
|
||||
// returns a unique ID for this session. Generated on the fly the first time someone calls this function
|
||||
int GetSessionID( GUID *id );
|
||||
|
||||
/* 5.54 + */
|
||||
size_t AllocateThreadStorage(); // returns an index, -1 for error
|
||||
void *GetThreadStorage(size_t index);
|
||||
void SetThreadStorage(size_t index, void *value);
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
API_APPLICATION_MAIN_GETAPPNAME = 10,
|
||||
API_APPLICATION_MAIN_GETVERSIONSTRING = 20,
|
||||
API_APPLICATION_MAIN_GETVERSIONSTRING2 = 21,
|
||||
API_APPLICATION_MAIN_GETBUILDNUMBER = 30,
|
||||
API_APPLICATION_MAIN_GETGUID = 40,
|
||||
API_APPLICATION_MAIN_GETMAINTHREADHANDLE = 50,
|
||||
API_APPLICATION_MAIN_GETHINSTANCE = 60,
|
||||
API_APPLICATION_MAIN_GETCOMMANDLINE = 70,
|
||||
API_APPLICATION_MAIN_SHUTDOWN = 80,
|
||||
API_APPLICATION_MAIN_CANCELSHUTDOWN = 90,
|
||||
API_APPLICATION_MAIN_ISSHUTTINGDOWN = 100,
|
||||
API_APPLICATION_PATH_GETAPPPATH = 110,
|
||||
API_APPLICATION_PATH_GETUSERSETTINGSPATH = 120,
|
||||
API_APPLICATION_APP_GETINITCOUNT = 130,
|
||||
API_APPLICATION_APP_MESSAGELOOPSTEP = 140,
|
||||
API_APPLICATION_APP_ADDMESSAGEPROCESSOR = 150,
|
||||
API_APPLICATION_APP_REMOVEMESSAGEPROCESSOR = 160,
|
||||
API_APPLICATION_APP_ADDMODELESSDIALOG = 170,
|
||||
API_APPLICATION_APP_REMOVEMODELESSDIALOG = 180,
|
||||
API_APPLICATION_PATH_GETWORKINGPATH = 190,
|
||||
API_APPLICATION_PATH_SETWORKINGPATH = 200,
|
||||
API_APPLICATION_GETMACHINEID = 210,
|
||||
API_APPLICATION_GETUSERID = 220,
|
||||
API_APPLICATION_GETSESSIONID = 230,
|
||||
API_APPLICATION_APP_ADDACCELERATORS = 240,
|
||||
API_APPLICATION_APP_REMOVEACCELERATORS = 250,
|
||||
API_APPLICATION_APP_TRANSLATEACCELERATORS = 260,
|
||||
API_APPLICATION_APP_GETACCELERATORS = 270,
|
||||
API_APPLICATION_APP_REGISTERGLOBALWINDOW = 280,
|
||||
API_APPLICATION_APP_UNREGISTERGLOBALWINDOW = 290,
|
||||
API_APPLICATION_ALLOCATETHREADSTORAGE = 300,
|
||||
API_APPLICATION_GETTHREADSTORAGE = 310,
|
||||
API_APPLICATION_SETTHREADSTORAGE = 320,
|
||||
API_APPLICATION_PATH_GETSKINSETTINGSPATH = 330,
|
||||
API_APPLICATION_DIRECTMOUSEWHEEL_REGISTERSKIPCLASS = 340,
|
||||
API_APPLICATION_DIRECTMOUSEWHEEL_UNREGISTERSKIPCLASS = 350,
|
||||
API_APPLICATION_DIRECTMOUSEWHEEL_ENABLECONVERTTOMOUSEWHEEL = 360,
|
||||
API_APPLICATION_DIRECTMOUSEWHEEL_PROCESSDIALOGMESSAGE = 365,
|
||||
API_APPLICATION_ACTIVEDIALOG_REGISTER = 370,
|
||||
API_APPLICATION_ACTIVEDIALOG_UNREGISTER = 380,
|
||||
API_APPLICATION_ACTIVEDIALOG_GET = 390,
|
||||
API_APPLICATION_GETATFSTRING = 400,
|
||||
API_APPLICATION_GETSCALEX = 500,
|
||||
API_APPLICATION_GETSCALEY = 510,
|
||||
};
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline const wchar_t *api_application::main_getAppName()
|
||||
{
|
||||
const wchar_t *__retval = _call(API_APPLICATION_MAIN_GETAPPNAME, (const wchar_t *)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::main_getVersionString()
|
||||
{
|
||||
const wchar_t *__retval = _call(API_APPLICATION_MAIN_GETVERSIONSTRING, (const wchar_t *)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::main_getVersionNumString()
|
||||
{
|
||||
return _call(API_APPLICATION_MAIN_GETVERSIONSTRING2, (const wchar_t *)0);
|
||||
}
|
||||
|
||||
inline unsigned int api_application::main_getBuildNumber()
|
||||
{
|
||||
return _call(API_APPLICATION_MAIN_GETBUILDNUMBER, 0);
|
||||
}
|
||||
|
||||
inline GUID api_application::main_getGUID()
|
||||
{
|
||||
GUID __retval = _call(API_APPLICATION_MAIN_GETGUID, INVALID_GUID);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
inline HANDLE api_application::main_getMainThreadHandle()
|
||||
{
|
||||
HANDLE __retval = _call(API_APPLICATION_MAIN_GETMAINTHREADHANDLE, (HANDLE)NULL);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline HINSTANCE api_application::main_gethInstance()
|
||||
{
|
||||
HINSTANCE __retval = _call(API_APPLICATION_MAIN_GETHINSTANCE, (HINSTANCE)NULL);
|
||||
return __retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline const wchar_t *api_application::main_getCommandLine()
|
||||
{
|
||||
const wchar_t *__retval = _call(API_APPLICATION_MAIN_GETCOMMANDLINE, (const wchar_t *)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_application::main_shutdown(int deferred)
|
||||
{
|
||||
_voidcall(API_APPLICATION_MAIN_SHUTDOWN, deferred);
|
||||
}
|
||||
|
||||
inline void api_application::main_cancelShutdown()
|
||||
{
|
||||
_voidcall(API_APPLICATION_MAIN_CANCELSHUTDOWN);
|
||||
}
|
||||
|
||||
inline int api_application::main_isShuttingDown()
|
||||
{
|
||||
int __retval = _call(API_APPLICATION_MAIN_ISSHUTTINGDOWN, (int)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::path_getAppPath()
|
||||
{
|
||||
const wchar_t *__retval = _call(API_APPLICATION_PATH_GETAPPPATH, (const wchar_t *)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::path_getUserSettingsPath()
|
||||
{
|
||||
return _call(API_APPLICATION_PATH_GETUSERSETTINGSPATH, (const wchar_t *)0);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::path_getSkinSettingsPath()
|
||||
{
|
||||
return _call(API_APPLICATION_PATH_GETSKINSETTINGSPATH, (const wchar_t *)0);
|
||||
}
|
||||
|
||||
inline int api_application::app_getInitCount()
|
||||
{
|
||||
int __retval = _call(API_APPLICATION_APP_GETINITCOUNT, 0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline intptr_t api_application::app_messageLoopStep()
|
||||
{
|
||||
return _call(API_APPLICATION_APP_MESSAGELOOPSTEP, (intptr_t)1);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
inline void api_application::app_addMessageProcessor(ifc_messageprocessor *processor)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_ADDMESSAGEPROCESSOR, processor);
|
||||
}
|
||||
|
||||
inline void api_application::app_removeMessageProcessor(ifc_messageprocessor *processor)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_REMOVEMESSAGEPROCESSOR, processor);
|
||||
}
|
||||
|
||||
inline void api_application::app_addAccelerators(HWND hwnd, HACCEL *phAccel, INT cAccel, UINT translateMode)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_ADDACCELERATORS, hwnd, phAccel, cAccel, translateMode);
|
||||
}
|
||||
|
||||
inline void api_application::app_removeAccelerators(HWND hwnd)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_REMOVEACCELERATORS, hwnd);
|
||||
}
|
||||
|
||||
inline bool api_application::app_translateAccelerators(MSG *msg)
|
||||
{
|
||||
return _call(API_APPLICATION_APP_TRANSLATEACCELERATORS, (bool)false, msg);
|
||||
}
|
||||
|
||||
inline int api_application::app_getAccelerators(HWND hwnd, HACCEL *phAccel, INT cchAccelMax, BOOL bGlobal)
|
||||
{
|
||||
return _call(API_APPLICATION_APP_GETACCELERATORS, (int)0, hwnd, phAccel, cchAccelMax, bGlobal);
|
||||
}
|
||||
|
||||
inline void api_application::app_registerGlobalWindow(HWND hwnd)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_REGISTERGLOBALWINDOW, hwnd);
|
||||
}
|
||||
|
||||
inline void api_application::app_unregisterGlobalWindow(HWND hwnd)
|
||||
{
|
||||
_voidcall(API_APPLICATION_APP_UNREGISTERGLOBALWINDOW, hwnd);
|
||||
}
|
||||
|
||||
inline bool api_application::DirectMouseWheel_RegisterSkipClass(ATOM klass)
|
||||
{
|
||||
return _call(API_APPLICATION_DIRECTMOUSEWHEEL_REGISTERSKIPCLASS, (bool)false, klass);
|
||||
}
|
||||
|
||||
inline bool api_application::DirectMouseWheel_UnregisterSkipClass(ATOM klass)
|
||||
{
|
||||
return _call(API_APPLICATION_DIRECTMOUSEWHEEL_UNREGISTERSKIPCLASS, (bool)false, klass);
|
||||
}
|
||||
|
||||
inline bool api_application::DirectMouseWheel_EnableConvertToMouseWheel(HWND hwnd, BOOL enable)
|
||||
{
|
||||
return _call(API_APPLICATION_DIRECTMOUSEWHEEL_ENABLECONVERTTOMOUSEWHEEL, (bool)false, hwnd, enable);
|
||||
}
|
||||
|
||||
inline BOOL api_application::DirectMouseWheel_ProcessDialogMessage(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam, const int controls[], int controlslen)
|
||||
{
|
||||
return _call(API_APPLICATION_DIRECTMOUSEWHEEL_PROCESSDIALOGMESSAGE, (BOOL)FALSE, hwnd, uMsg, wParam, lParam, controls, controlslen);
|
||||
}
|
||||
|
||||
inline void api_application::ActiveDialog_Register(HWND hwnd)
|
||||
{
|
||||
_voidcall(API_APPLICATION_ACTIVEDIALOG_REGISTER, hwnd);
|
||||
}
|
||||
|
||||
inline void api_application::ActiveDialog_Unregister(HWND hwnd)
|
||||
{
|
||||
_voidcall(API_APPLICATION_ACTIVEDIALOG_UNREGISTER, hwnd);
|
||||
}
|
||||
|
||||
inline HWND api_application::ActiveDialog_Get()
|
||||
{
|
||||
return _call(API_APPLICATION_ACTIVEDIALOG_GET, (HWND)NULL);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_application::getATFString()
|
||||
{
|
||||
return _call(API_APPLICATION_GETATFSTRING, (wchar_t *)0);
|
||||
}
|
||||
|
||||
inline int api_application::getScaleX(int x)
|
||||
{
|
||||
return _call(API_APPLICATION_GETSCALEX, (int)0, x);
|
||||
}
|
||||
|
||||
inline int api_application::getScaleY(int y)
|
||||
{
|
||||
return _call(API_APPLICATION_GETSCALEY, (int)0, y);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline const wchar_t *api_application::path_getWorkingPath()
|
||||
{
|
||||
return _call(API_APPLICATION_PATH_GETWORKINGPATH, (wchar_t *)0);
|
||||
}
|
||||
|
||||
inline void api_application::path_setWorkingPath(const wchar_t *newPath)
|
||||
{
|
||||
_voidcall(API_APPLICATION_PATH_SETWORKINGPATH, newPath);
|
||||
}
|
||||
|
||||
inline int api_application::GetMachineID(GUID *id)
|
||||
{
|
||||
return _call(API_APPLICATION_GETMACHINEID, (int)API_APPLICATION_FAILURE, id);
|
||||
}
|
||||
|
||||
inline int api_application::GetUserID(GUID *id)
|
||||
{
|
||||
return _call(API_APPLICATION_GETUSERID, (int)API_APPLICATION_FAILURE, id);
|
||||
}
|
||||
|
||||
inline int api_application::GetSessionID(GUID *id)
|
||||
{
|
||||
return _call(API_APPLICATION_GETSESSIONID, (int)API_APPLICATION_FAILURE, id);
|
||||
}
|
||||
|
||||
inline size_t api_application::AllocateThreadStorage()
|
||||
{
|
||||
return _call(API_APPLICATION_ALLOCATETHREADSTORAGE, (size_t)-1);
|
||||
}
|
||||
|
||||
inline void *api_application::GetThreadStorage(size_t index)
|
||||
{
|
||||
return _call(API_APPLICATION_GETTHREADSTORAGE, (void *)0, index);
|
||||
}
|
||||
|
||||
inline void api_application::SetThreadStorage(size_t index, void *value)
|
||||
{
|
||||
_voidcall(API_APPLICATION_SETTHREADSTORAGE, index, value);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// {23B96771-09D7-46d3-9AE2-20DCEA6C86EA}
|
||||
static const GUID applicationApiServiceGuid =
|
||||
{
|
||||
0x23b96771, 0x9d7, 0x46d3, { 0x9a, 0xe2, 0x20, 0xdc, 0xea, 0x6c, 0x86, 0xea }
|
||||
};
|
||||
|
||||
extern api_application *applicationApi;
|
||||
|
||||
#endif // __API_APPLICATION_H
|
204
Src/Wasabi/api/application/api_applicationi.cpp
Normal file
204
Src/Wasabi/api/application/api_applicationi.cpp
Normal file
|
@ -0,0 +1,204 @@
|
|||
#include <precomp.h>
|
||||
//<?#include "<class data="implementationheader"/>"
|
||||
#include "api_applicationi.h"
|
||||
//?>
|
||||
|
||||
#include <wasabicfg.h>
|
||||
#include <api/application/pathmgr.h>
|
||||
#include <api/application/version.h>
|
||||
#include <api/apiinit.h>
|
||||
|
||||
#ifdef WA3COMPATIBILITY
|
||||
#include <runtime/main.h> // CUT!
|
||||
#include <wndmgr/layout.h> // CUT!
|
||||
#include <skin/skinparse.h>
|
||||
#endif
|
||||
|
||||
StringW g_resourcepath;
|
||||
|
||||
// {3CBD4483-DC44-11d3-B608-000086340885}
|
||||
static const GUID _baseGUID =
|
||||
{ 0x3cbd4483, 0xdc44, 0x11d3, { 0xb6, 0x8, 0x0, 0x0, 0x86, 0x34, 0x8, 0x85 } };
|
||||
|
||||
api_application *applicationApi = NULL;
|
||||
api_applicationI::api_applicationI(HINSTANCE instance, const wchar_t *_userPath)
|
||||
: appInstance(instance), mainthread(0), shuttingdown(0)
|
||||
{
|
||||
userPath = _userPath;
|
||||
#ifndef _WASABIRUNTIME
|
||||
|
||||
#ifdef WASABI_DIRS_FROMEXEPATH
|
||||
HINSTANCE hInst = GetModuleHandle(0);
|
||||
#else
|
||||
HINSTANCE hInst = appInstance;
|
||||
#endif
|
||||
|
||||
StringW path;
|
||||
{
|
||||
wchar_t g[WA_MAX_PATH];
|
||||
GetModuleFileNameW(hInst, g, WA_MAX_PATH - 1);
|
||||
wchar_t *p = wcsrchr(g, '\\');
|
||||
if (p) *p = 0;
|
||||
path = g;
|
||||
}
|
||||
#ifdef WIN32
|
||||
g_resourcepath = path;
|
||||
#elif defined(LINUX)
|
||||
g_resourcepath = "/usr/local/share/";
|
||||
g_resourcepath += WasabiVersion::getAppName();
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
//char *file = getenv( "WASABI_LOG_FILE" );
|
||||
//if (!ACCESS(file, 0)) UNLINK(file);
|
||||
#endif
|
||||
|
||||
apppath = path;
|
||||
|
||||
g_resourcepath.AddBackslash();
|
||||
|
||||
#if defined(WASABI_COMPILE_SKIN) || defined(WASABI_COMPILE_IMGLDR)
|
||||
g_resourcepath.AppendPath(WASABI_RESOURCES_SUBDIRECTORY);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
HANDLE h = NULL;
|
||||
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &h, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
mainthread = h; // 32-bit writes assumed atomic
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
DebugString("portme: api main thread handle dup\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
api_applicationI::~api_applicationI()
|
||||
{
|
||||
g_resourcepath.purge();
|
||||
}
|
||||
|
||||
const wchar_t *api_applicationI::main_getAppName()
|
||||
{
|
||||
return WasabiVersion::getAppName();
|
||||
}
|
||||
|
||||
const wchar_t *api_applicationI::main_getVersionString()
|
||||
{
|
||||
return WasabiVersion::getVersionString();
|
||||
}
|
||||
|
||||
unsigned int api_applicationI::main_getBuildNumber()
|
||||
{
|
||||
return WasabiVersion::getBuildNumber();
|
||||
}
|
||||
|
||||
GUID api_applicationI::main_getGUID()
|
||||
{
|
||||
return guid;
|
||||
}
|
||||
|
||||
HANDLE api_applicationI::main_getMainThreadHandle()
|
||||
{
|
||||
if (mainthread == 0) return (HANDLE)0;
|
||||
HANDLE h = (HANDLE)0;
|
||||
#ifdef WIN32
|
||||
DuplicateHandle(GetCurrentProcess(), mainthread, GetCurrentProcess(), &h, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
DebugString("portme: dup handle\n");
|
||||
#endif
|
||||
return h;
|
||||
}
|
||||
|
||||
HINSTANCE api_applicationI::main_gethInstance()
|
||||
{
|
||||
return appInstance;
|
||||
}
|
||||
|
||||
const wchar_t *api_applicationI::main_getCommandLine()
|
||||
{
|
||||
return cmdLine;
|
||||
}
|
||||
|
||||
void api_applicationI::main_shutdown(int deferred)
|
||||
{
|
||||
int x = 1;
|
||||
#ifdef WASABI_CHECK_CAN_EXIT
|
||||
WASABI_CHECK_CAN_EXIT(x)
|
||||
#endif
|
||||
if (!x) return ;
|
||||
shuttingdown = 1;
|
||||
#ifdef _WASABIRUNTIME
|
||||
Main::doAction(ACTION_CLOSE, deferred);
|
||||
#endif
|
||||
#ifdef WASABI_CUSTOM_QUIT
|
||||
WASABI_CUSTOM_QUITFN
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void api_applicationI::main_cancelShutdown()
|
||||
{
|
||||
#ifdef _WASABIRUNTIME
|
||||
Main::cancelShutdown();
|
||||
#endif
|
||||
shuttingdown = 0;
|
||||
}
|
||||
|
||||
int api_applicationI::main_isShuttingDown()
|
||||
{
|
||||
return shuttingdown;
|
||||
}
|
||||
|
||||
const wchar_t *api_applicationI::path_getAppPath()
|
||||
{
|
||||
#ifdef _WASABIRUNTIME
|
||||
return Main::getMainAppPath();
|
||||
#endif
|
||||
return apppath;
|
||||
}
|
||||
|
||||
const wchar_t *api_applicationI::path_getUserSettingsPath()
|
||||
{
|
||||
return userPath;
|
||||
//return PathMgr::getUserSettingsPath();
|
||||
}
|
||||
|
||||
void api_applicationI::setHInstance(HINSTANCE instance)
|
||||
{
|
||||
appInstance = instance;
|
||||
};
|
||||
|
||||
void api_applicationI::setCommandLine(const wchar_t *cmdline)
|
||||
{
|
||||
cmdLine = cmdline;
|
||||
}
|
||||
|
||||
void api_applicationI::setGUID(GUID g)
|
||||
{
|
||||
guid = g;
|
||||
}
|
||||
|
||||
int api_applicationI::app_getInitCount()
|
||||
{
|
||||
return ApiInit::getInitCount();
|
||||
}
|
||||
|
||||
|
||||
int api_applicationI::app_messageLoopStep()
|
||||
{
|
||||
#if defined(WASABI_COMPILE_TIMERS) || defined(WASABI_COMPILE_WND)
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
|
||||
{
|
||||
if (!GetMessage( &msg, NULL, 0, 0 )) return 0;
|
||||
#ifdef WASABI_COMPILE_WND
|
||||
TranslateMessage( &msg );
|
||||
#endif
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
49
Src/Wasabi/api/application/api_applicationi.h
Normal file
49
Src/Wasabi/api/application/api_applicationi.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef __API_APPLICATIONI_IMPL_H
|
||||
#define __API_APPLICATIONI_IMPL_H
|
||||
|
||||
/*<?<autoheader/>*/
|
||||
#include "api_application.h"
|
||||
#include "api_applicationx.h"
|
||||
/*?>*/
|
||||
|
||||
/*[interface.header.h]
|
||||
#include "common/nsGUID.h"
|
||||
class String;
|
||||
*/
|
||||
|
||||
class api_applicationI : public api_applicationX {
|
||||
public:
|
||||
NODISPATCH api_applicationI(HINSTANCE instance, const wchar_t *_userPath);
|
||||
NODISPATCH virtual ~api_applicationI();
|
||||
|
||||
DISPATCH(10) const wchar_t *main_getAppName();
|
||||
DISPATCH(20) const wchar_t *main_getVersionString();
|
||||
DISPATCH(30) unsigned int main_getBuildNumber();
|
||||
DISPATCH(40) GUID main_getGUID();
|
||||
DISPATCH(50) HANDLE main_getMainThreadHandle();
|
||||
DISPATCH(60) HINSTANCE main_gethInstance();
|
||||
DISPATCH(70) const wchar_t *main_getCommandLine();
|
||||
DISPATCH(80) void main_shutdown(int deferred = TRUE);
|
||||
DISPATCH(90) void main_cancelShutdown();
|
||||
DISPATCH(100) int main_isShuttingDown();
|
||||
DISPATCH(110) const wchar_t *path_getAppPath();
|
||||
DISPATCH(120) const wchar_t *path_getUserSettingsPath();
|
||||
DISPATCH(130) int app_getInitCount();
|
||||
DISPATCH(140) int app_messageLoopStep();
|
||||
|
||||
NODISPATCH void setHInstance(HINSTANCE instance);
|
||||
NODISPATCH void setCommandLine(const wchar_t *cmdline);
|
||||
NODISPATCH void setGUID(GUID g);
|
||||
|
||||
protected:
|
||||
|
||||
HINSTANCE appInstance;
|
||||
StringW cmdLine;
|
||||
StringW userPath;
|
||||
HANDLE mainthread;
|
||||
GUID guid;
|
||||
int shuttingdown;
|
||||
StringW apppath;
|
||||
};
|
||||
|
||||
#endif // __API_APPLICATIONI_IMPL_H
|
33
Src/Wasabi/api/application/api_applicationx.cpp
Normal file
33
Src/Wasabi/api/application/api_applicationx.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Wed May 07 00:55:56 2003]
|
||||
//
|
||||
// File : api_applicationx.cpp
|
||||
// Class : api_application
|
||||
// class layer : Dispatchable Receiver
|
||||
// ----------------------------------------------------------------------------
|
||||
#include <precomp.h>
|
||||
|
||||
#include "api_applicationx.h"
|
||||
|
||||
#ifdef CBCLASS
|
||||
#undef CBCLASS
|
||||
#endif
|
||||
|
||||
#define CBCLASS api_applicationX
|
||||
START_DISPATCH;
|
||||
CB(API_APPLICATION_MAIN_GETAPPNAME, main_getAppName);
|
||||
CB(API_APPLICATION_MAIN_GETVERSIONSTRING, main_getVersionString);
|
||||
CB(API_APPLICATION_MAIN_GETBUILDNUMBER, main_getBuildNumber);
|
||||
CB(API_APPLICATION_MAIN_GETGUID, main_getGUID);
|
||||
CB(API_APPLICATION_MAIN_GETMAINTHREADHANDLE, main_getMainThreadHandle);
|
||||
CB(API_APPLICATION_MAIN_GETHINSTANCE, main_gethInstance);
|
||||
CB(API_APPLICATION_MAIN_GETCOMMANDLINE, main_getCommandLine);
|
||||
VCB(API_APPLICATION_MAIN_SHUTDOWN, main_shutdown);
|
||||
VCB(API_APPLICATION_MAIN_CANCELSHUTDOWN, main_cancelShutdown);
|
||||
CB(API_APPLICATION_MAIN_ISSHUTTINGDOWN, main_isShuttingDown);
|
||||
CB(API_APPLICATION_PATH_GETAPPPATH, path_getAppPath);
|
||||
CB(API_APPLICATION_PATH_GETUSERSETTINGSPATH, path_getUserSettingsPath);
|
||||
CB(API_APPLICATION_APP_GETINITCOUNT, app_getInitCount);
|
||||
CB(API_APPLICATION_APP_MESSAGELOOPSTEP, app_messageLoopStep);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
42
Src/Wasabi/api/application/api_applicationx.h
Normal file
42
Src/Wasabi/api/application/api_applicationx.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Wed May 07 00:55:56 2003]
|
||||
//
|
||||
// File : api_applicationx.h
|
||||
// Class : api_application
|
||||
// class layer : Dispatchable Receiver
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __API_APPLICATIONX_H
|
||||
#define __API_APPLICATIONX_H
|
||||
|
||||
#include "api_application.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class api_applicationX : public api_application {
|
||||
protected:
|
||||
api_applicationX() {}
|
||||
public:
|
||||
virtual const wchar_t *main_getAppName()=0;
|
||||
virtual const wchar_t *main_getVersionString()=0;
|
||||
virtual unsigned int main_getBuildNumber()=0;
|
||||
virtual GUID main_getGUID()=0;
|
||||
virtual HANDLE main_getMainThreadHandle()=0;
|
||||
virtual HINSTANCE main_gethInstance()=0;
|
||||
virtual const wchar_t *main_getCommandLine()=0;
|
||||
virtual void main_shutdown(int deferred = TRUE)=0;
|
||||
virtual void main_cancelShutdown()=0;
|
||||
virtual int main_isShuttingDown()=0;
|
||||
virtual const wchar_t *path_getAppPath()=0;
|
||||
virtual const wchar_t *path_getUserSettingsPath()=0;
|
||||
virtual int app_getInitCount()=0;
|
||||
virtual int app_messageLoopStep()=0;
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
#endif // __API_APPLICATIONX_H
|
1
Src/Wasabi/api/application/ifc_messageprocessor.cpp
Normal file
1
Src/Wasabi/api/application/ifc_messageprocessor.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "api_messageprocessor.h"
|
26
Src/Wasabi/api/application/ifc_messageprocessor.h
Normal file
26
Src/Wasabi/api/application/ifc_messageprocessor.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef __WASABI_IFC_MESSAGEPROCESSOR_H
|
||||
#define __WASABI_IFC_MESSAGEPROCESSOR_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <windows.h>
|
||||
class ifc_messageprocessor : public Dispatchable
|
||||
{
|
||||
protected:
|
||||
ifc_messageprocessor() {}
|
||||
~ifc_messageprocessor() {}
|
||||
|
||||
public:
|
||||
bool ProcessMessage(MSG *msg); // return true to 'eat' the message
|
||||
public:
|
||||
DISPATCH_CODES
|
||||
{
|
||||
IFC_MESSAGEPROCESSOR_PROCESS_MESSAGE = 10,
|
||||
};
|
||||
};
|
||||
inline bool ifc_messageprocessor::ProcessMessage(MSG *msg)
|
||||
{
|
||||
return _call(IFC_MESSAGEPROCESSOR_PROCESS_MESSAGE, false, msg);
|
||||
}
|
||||
|
||||
typedef ifc_messageprocessor api_messageprocessor; // TODO: CUT!
|
||||
#endif
|
7
Src/Wasabi/api/application/ifc_messageprocessori.cpp
Normal file
7
Src/Wasabi/api/application/ifc_messageprocessori.cpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "ifc_messageprocessori.h"
|
||||
|
||||
#define CBCLASS ifc_messageprocessorI
|
||||
START_DISPATCH;
|
||||
CB(IFC_MESSAGEPROCESSOR_PROCESS_MESSAGE, ProcessMessage)
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
13
Src/Wasabi/api/application/ifc_messageprocessori.h
Normal file
13
Src/Wasabi/api/application/ifc_messageprocessori.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef NULLSOFT_WASABI_MESSAGEPROCESSORI_H
|
||||
#define NULLSOFT_WASABI_MESSAGEPROCESSORI_H
|
||||
|
||||
#include <api/application/ifc_messageprocessor.h>
|
||||
|
||||
class ifc_messageprocessorI: public ifc_messageprocessor
|
||||
{
|
||||
public:
|
||||
virtual bool ProcessMessage(MSG *msg)=0;
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
#endif
|
97
Src/Wasabi/api/application/ipcs.cpp
Normal file
97
Src/Wasabi/api/application/ipcs.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <precomp.h>
|
||||
#ifdef WASABI_API_COMPONENT
|
||||
#include <api/wac/main.h> //CUT!!!
|
||||
#endif
|
||||
#include "ipcs.h"
|
||||
#ifdef LINUX
|
||||
#include <api/linux/linuxapi.h>
|
||||
#endif
|
||||
|
||||
using namespace IpcsCommand;
|
||||
|
||||
#ifdef WIN32
|
||||
IpcsPtr::IpcsPtr(HWND h) {
|
||||
hwnd = h;
|
||||
}
|
||||
#else
|
||||
IpcsPtr::IpcsPtr(int q) {
|
||||
qid = q;
|
||||
}
|
||||
#endif
|
||||
|
||||
void IpcsPtr::moveToForeground() {
|
||||
#ifdef WIN32
|
||||
if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE);
|
||||
// ShowWindow(hwnd,SW_SHOW); //FG> SW_RESTORE should take care of it and is trapped for taskbar button hiding. Explicitly showing the window will make an iconless button reapear if studio is set to not have a taskbar button
|
||||
SetForegroundWindow(hwnd);
|
||||
#else
|
||||
DebugString( "portme -- IpcsPtr::moveToForeground\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
void IpcsPtr::sendWasabiCommand(int command, void *param, int paramlen) {
|
||||
#ifdef WIN32
|
||||
COPYDATASTRUCT cd;
|
||||
cd.dwData=command;
|
||||
cd.cbData=paramlen;
|
||||
cd.lpData=param;
|
||||
SendMessage(hwnd, WM_COPYDATA, NULL, (long)&cd);
|
||||
#else
|
||||
wa_msgbuf msg;
|
||||
msg.mtype = command;
|
||||
ASSERT( paramlen < IPC_MSGMAX - 4 );
|
||||
msg.paramlen = paramlen;
|
||||
MEMCPY( msg.param, param, paramlen );
|
||||
|
||||
if ( msgsnd( qid , &msg, IPC_MSGMAX, 0 ) == 1 ) {
|
||||
perror( "msgsnd" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void IpcsPtr::sendWasabiCommand(int command, const char *param) {
|
||||
sendWasabiCommand(command, (void *)param, STRLEN(param)+1);
|
||||
}
|
||||
|
||||
|
||||
IpcsPtr *Ipcs::getOtherWasabiInstance() {
|
||||
extern String ipcWindowClassName;
|
||||
|
||||
#ifdef WIN32
|
||||
HWND hwnd_instance=FindWindow(ipcWindowClassName,NULL);
|
||||
if(!hwnd_instance) return NULL;
|
||||
|
||||
return(new IpcsPtr(hwnd_instance));
|
||||
#else
|
||||
int key = ftok( ".", 'w' );
|
||||
|
||||
int qid = msgget( key, 0 );
|
||||
if ( qid == -1 && errno == ENOENT ) {
|
||||
qid = msgget( key, IPC_CREAT | IPC_EXCL | 0660 );
|
||||
|
||||
LinuxAPI::setIPCId( qid );
|
||||
|
||||
return NULL;
|
||||
} else if ( qid == -1 ) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new IpcsPtr( qid );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4060)
|
||||
|
||||
int Ipcs::onIpcsMessage(int command, void *param, int paramlen) {
|
||||
switch(command) {
|
||||
#ifdef WASABI_API_COMPONENT
|
||||
case IPC_COMMANDLINE:
|
||||
Main::processCommandLine((const char *)param);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
60
Src/Wasabi/api/application/ipcs.h
Normal file
60
Src/Wasabi/api/application/ipcs.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#ifndef _IPCS_H
|
||||
#define _IPCS_H
|
||||
|
||||
// same value as winamp 2.x
|
||||
#define WM_WA_IPC WM_USER
|
||||
|
||||
#ifdef LINUX
|
||||
// Stolen from a webpage, I think Linux's is higher, but to be safe...
|
||||
#define IPC_MSGMAX 4056
|
||||
|
||||
struct wa_msgbuf {
|
||||
long mtype;
|
||||
int paramlen;
|
||||
char param[IPC_MSGMAX - 4];
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace IpcsCommand {
|
||||
enum {
|
||||
#ifdef WASABI_API_MEDIACORE
|
||||
// wa2.x IPC messages
|
||||
IPC_PLAYFILE=100,
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_API_COMPONENT
|
||||
// wa3 IPC messages
|
||||
IPC_COMMANDLINE=1000,
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
class IpcsPtr {
|
||||
public:
|
||||
#ifdef WIN32
|
||||
IpcsPtr(HWND hwnd);
|
||||
#else
|
||||
IpcsPtr(int qid);
|
||||
#endif
|
||||
|
||||
void sendWasabiCommand(int command, void *param=0, int paramlen=0);
|
||||
void sendWasabiCommand(int command, const char *param);
|
||||
|
||||
void moveToForeground();
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
HWND hwnd;
|
||||
#else
|
||||
int qid;
|
||||
#endif
|
||||
};
|
||||
|
||||
class Ipcs {
|
||||
public:
|
||||
static IpcsPtr *getOtherWasabiInstance();
|
||||
|
||||
static int onIpcsMessage(int command, void *param, int paramlen);
|
||||
};
|
||||
|
||||
#endif
|
14
Src/Wasabi/api/application/pathmgr.cpp
Normal file
14
Src/Wasabi/api/application/pathmgr.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <precomp.h>
|
||||
#include "pathmgr.h"
|
||||
#include <api/api.h>
|
||||
#include <bfc/util/inifile.h>
|
||||
|
||||
#if !defined(WIN32) && !defined(LINUX)
|
||||
#error port me
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
|
15
Src/Wasabi/api/application/pathmgr.h
Normal file
15
Src/Wasabi/api/application/pathmgr.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef _PATHMGR_H
|
||||
#define _PATHMGR_H
|
||||
|
||||
#include <bfc/std.h>
|
||||
|
||||
class PathMgr
|
||||
{
|
||||
public:
|
||||
//static const char *getUserSettingsPath();
|
||||
#ifdef WASABI_COMPILE_COMPONENTS
|
||||
static const wchar_t *getComponentDataPath(GUID g);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
47
Src/Wasabi/api/application/version.cpp
Normal file
47
Src/Wasabi/api/application/version.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <precomp.h>
|
||||
#include "version.h"
|
||||
#include <bfc/parse/pathparse.h>
|
||||
|
||||
static int buildno = -1;
|
||||
static const wchar_t *WASABI_VERSION = L"";
|
||||
|
||||
#define STRFILEVER "1, 0, 0, 502\0"
|
||||
|
||||
static StringW version_string;
|
||||
|
||||
void WasabiVersion::setAppName(const wchar_t *name)
|
||||
{
|
||||
appname = name;
|
||||
}
|
||||
|
||||
const wchar_t *WasabiVersion::getAppName()
|
||||
{
|
||||
return appname;
|
||||
}
|
||||
|
||||
const wchar_t *WasabiVersion::getVersionString()
|
||||
{
|
||||
if (appname.isempty())
|
||||
appname=L"";
|
||||
if (version_string.isempty())
|
||||
{
|
||||
if (!appname.isempty())
|
||||
version_string = appname.getValue();
|
||||
if (wcslen(WASABI_VERSION))
|
||||
{
|
||||
version_string.cat(L" ");
|
||||
version_string.cat(WASABI_VERSION);
|
||||
}
|
||||
}
|
||||
return version_string;
|
||||
}
|
||||
|
||||
unsigned int WasabiVersion::getBuildNumber()
|
||||
{
|
||||
if (buildno == -1)
|
||||
{
|
||||
PathParser pp(STRFILEVER, ",");
|
||||
buildno = ATOI(pp.enumString(3));
|
||||
}
|
||||
return buildno;
|
||||
}
|
12
Src/Wasabi/api/application/version.h
Normal file
12
Src/Wasabi/api/application/version.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef _VERSION_H
|
||||
#define _VERSION_H
|
||||
/*
|
||||
class WasabiVersion {
|
||||
public:
|
||||
static void setAppName(const wchar_t *name);
|
||||
static const wchar_t *getAppName();
|
||||
static const wchar_t *getVersionString();
|
||||
static unsigned int getBuildNumber();
|
||||
};*/
|
||||
|
||||
#endif
|
12
Src/Wasabi/api/application/wkc.cpp
Normal file
12
Src/Wasabi/api/application/wkc.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "wkc.h"
|
||||
|
||||
#define CBCLASS WasabiKernelControllerI
|
||||
START_DISPATCH;
|
||||
CB(TESTCOMPONENT, testComponent);
|
||||
CB(TESTSCRIPT, testScript);
|
||||
CB(TESTSKIN, testSkin);
|
||||
CB(TESTSKINFILE, testSkinFile);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
61
Src/Wasabi/api/application/wkc.h
Normal file
61
Src/Wasabi/api/application/wkc.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#ifndef _WKC_H
|
||||
#define _WKC_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
/**
|
||||
A callback class for the loader so it can determine which resources wasabi.dll should load.
|
||||
*/
|
||||
class NOVTABLE WasabiKernelController : public Dispatchable {
|
||||
public:
|
||||
/**
|
||||
Check if a component should load.
|
||||
*/
|
||||
int testComponent(const char *filename);
|
||||
int testScript(const char *filename, void *data, int datalen);
|
||||
int testSkin(const char *skinname);
|
||||
int testSkinFile(const char *filename);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
TESTCOMPONENT=1000,
|
||||
TESTSCRIPT=2000,
|
||||
TESTSKIN=3000,
|
||||
TESTSKINFILE=4000,
|
||||
};
|
||||
};
|
||||
|
||||
inline
|
||||
int WasabiKernelController::testComponent(const char *filename) {
|
||||
return _call(TESTCOMPONENT, TRUE, filename);
|
||||
}
|
||||
|
||||
inline
|
||||
int WasabiKernelController::testScript(const char *filename, void *data, int datalen) {
|
||||
return _call(TESTSCRIPT, TRUE, filename, data, datalen);
|
||||
}
|
||||
|
||||
inline
|
||||
int WasabiKernelController::testSkin(const char *skinname) {
|
||||
return _call(TESTSKIN, TRUE, skinname);
|
||||
}
|
||||
|
||||
inline
|
||||
int WasabiKernelController::testSkinFile(const char *filename) {
|
||||
return _call(TESTSKINFILE, TRUE, filename);
|
||||
}
|
||||
|
||||
// implementors derive from this one
|
||||
class WasabiKernelControllerI : public WasabiKernelController {
|
||||
public:
|
||||
// default to OK
|
||||
virtual int testComponent(const char *filename) { return 1; }
|
||||
virtual int testScript(const char *filename, void *data, int datalen) { return 1; }
|
||||
virtual int testSkin(const char *skinname) { return 1; }
|
||||
virtual int testSkinFile(const char *filename) { return 1; }
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
#endif
|
12
Src/Wasabi/api/config/api_config.cpp
Normal file
12
Src/Wasabi/api/config/api_config.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Thu May 15 21:06:24 2003]
|
||||
//
|
||||
// File : api_config.cpp
|
||||
// Class : api_config
|
||||
// class layer : Dispatchable Interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <precomp.h>
|
||||
#include "api_config.h"
|
||||
|
||||
|
149
Src/Wasabi/api/config/api_config.h
Normal file
149
Src/Wasabi/api/config/api_config.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Thu May 15 21:06:24 2003]
|
||||
//
|
||||
// File : api_config.h
|
||||
// Class : api_config
|
||||
// class layer : Dispatchable Interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __API_CONFIG_H
|
||||
#define __API_CONFIG_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/platform/types.h>
|
||||
|
||||
class CfgItem;
|
||||
class ConfigFile;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class NOVTABLE api_config: public Dispatchable
|
||||
{
|
||||
protected:
|
||||
api_config() {}
|
||||
~api_config() {}
|
||||
public:
|
||||
void config_registerCfgItem(CfgItem *cfgitem);
|
||||
void config_deregisterCfgItem(CfgItem *cfgitem);
|
||||
int config_getNumCfgItems();
|
||||
CfgItem *config_enumCfgItem(int n);
|
||||
CfgItem *config_getCfgItemByGuid(GUID g);
|
||||
void setIntPrivate(const wchar_t *name, int val);
|
||||
int getIntPrivate(const wchar_t *name, int def_val);
|
||||
void setIntArrayPrivate(const wchar_t *name, const int *val, int nval);
|
||||
int getIntArrayPrivate(const wchar_t *name, int *val, int nval);
|
||||
void setStringPrivate(const wchar_t *name, const wchar_t *str);
|
||||
int getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
int getStringPrivateLen(const wchar_t *name);
|
||||
void setIntPublic(const wchar_t *name, int val);
|
||||
int getIntPublic(const wchar_t *name, int def_val);
|
||||
void setStringPublic(const wchar_t *name, const wchar_t *str);
|
||||
int getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
API_CONFIG_CONFIG_REGISTERCFGITEM = 10,
|
||||
API_CONFIG_CONFIG_DEREGISTERCFGITEM = 20,
|
||||
API_CONFIG_CONFIG_GETNUMCFGITEMS = 30,
|
||||
API_CONFIG_CONFIG_ENUMCFGITEM = 40,
|
||||
API_CONFIG_CONFIG_GETCFGITEMBYGUID = 50,
|
||||
API_CONFIG_SETINTPRIVATE = 60,
|
||||
API_CONFIG_GETINTPRIVATE = 70,
|
||||
API_CONFIG_SETINTARRAYPRIVATE = 80,
|
||||
API_CONFIG_GETINTARRAYPRIVATE = 90,
|
||||
API_CONFIG_SETSTRINGPRIVATE = 100,
|
||||
API_CONFIG_GETSTRINGPRIVATE = 110,
|
||||
API_CONFIG_GETSTRINGPRIVATELEN = 120,
|
||||
API_CONFIG_SETINTPUBLIC = 130,
|
||||
API_CONFIG_GETINTPUBLIC = 140,
|
||||
API_CONFIG_SETSTRINGPUBLIC = 150,
|
||||
API_CONFIG_GETSTRINGPUBLIC = 160,
|
||||
};
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline void api_config::config_registerCfgItem(CfgItem *cfgitem) {
|
||||
_voidcall(API_CONFIG_CONFIG_REGISTERCFGITEM, cfgitem);
|
||||
}
|
||||
|
||||
inline void api_config::config_deregisterCfgItem(CfgItem *cfgitem) {
|
||||
_voidcall(API_CONFIG_CONFIG_DEREGISTERCFGITEM, cfgitem);
|
||||
}
|
||||
|
||||
inline int api_config::config_getNumCfgItems() {
|
||||
int __retval = _call(API_CONFIG_CONFIG_GETNUMCFGITEMS, (int)0);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline CfgItem *api_config::config_enumCfgItem(int n) {
|
||||
CfgItem *__retval = _call(API_CONFIG_CONFIG_ENUMCFGITEM, (CfgItem *)NULL, n);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline CfgItem *api_config::config_getCfgItemByGuid(GUID g) {
|
||||
CfgItem *__retval = _call(API_CONFIG_CONFIG_GETCFGITEMBYGUID, (CfgItem *)NULL, g);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_config::setIntPrivate(const wchar_t *name, int val) {
|
||||
_voidcall(API_CONFIG_SETINTPRIVATE, name, val);
|
||||
}
|
||||
|
||||
inline int api_config::getIntPrivate(const wchar_t *name, int def_val) {
|
||||
int __retval = _call(API_CONFIG_GETINTPRIVATE, (int)0, name, def_val);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_config::setIntArrayPrivate(const wchar_t *name, const int *val, int nval) {
|
||||
_voidcall(API_CONFIG_SETINTARRAYPRIVATE, name, val, nval);
|
||||
}
|
||||
|
||||
inline int api_config::getIntArrayPrivate(const wchar_t *name, int *val, int nval) {
|
||||
int __retval = _call(API_CONFIG_GETINTARRAYPRIVATE, (int)0, name, val, nval);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_config::setStringPrivate(const wchar_t *name, const wchar_t *str) {
|
||||
_voidcall(API_CONFIG_SETSTRINGPRIVATE, name, str);
|
||||
}
|
||||
|
||||
inline int api_config::getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str) {
|
||||
int __retval = _call(API_CONFIG_GETSTRINGPRIVATE, (int)0, name, buf, buf_len, default_str);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline int api_config::getStringPrivateLen(const wchar_t *name) {
|
||||
int __retval = _call(API_CONFIG_GETSTRINGPRIVATELEN, (int)0, name);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_config::setIntPublic(const wchar_t *name, int val) {
|
||||
_voidcall(API_CONFIG_SETINTPUBLIC, name, val);
|
||||
}
|
||||
|
||||
inline int api_config::getIntPublic(const wchar_t *name, int def_val) {
|
||||
int __retval = _call(API_CONFIG_GETINTPUBLIC, (int)0, name, def_val);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
inline void api_config::setStringPublic(const wchar_t *name, const wchar_t *str) {
|
||||
_voidcall(API_CONFIG_SETSTRINGPUBLIC, name, str);
|
||||
}
|
||||
|
||||
inline int api_config::getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str) {
|
||||
int __retval = _call(API_CONFIG_GETSTRINGPUBLIC, (int)0, name, buf, buf_len, default_str);
|
||||
return __retval;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// {470B890C-4747-4113-ABA5-A8F8F4F8AB7E}
|
||||
static const GUID configApiServiceGuid =
|
||||
{ 0x470b890c, 0x4747, 0x4113, { 0xab, 0xa5, 0xa8, 0xf8, 0xf4, 0xf8, 0xab, 0x7e } };
|
||||
|
||||
extern api_config *configApi;
|
||||
|
||||
#endif // __API_CONFIG_H
|
124
Src/Wasabi/api/config/api_configi.cpp
Normal file
124
Src/Wasabi/api/config/api_configi.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
#include <precomp.h>
|
||||
//<?#include "<class data="implementationheader"/>"
|
||||
#include "api_configi.h"
|
||||
//?>
|
||||
|
||||
#include <bfc/parse/pathparse.h>
|
||||
#include <api/config/cfglist.h>
|
||||
|
||||
|
||||
static CfgList cfglist;
|
||||
|
||||
api_config *configApi = NULL;
|
||||
|
||||
api_configI::api_configI()
|
||||
: public_config(StringPrintfW(INVALID_GUID), L"public data")
|
||||
{
|
||||
public_config.initialize();
|
||||
}
|
||||
|
||||
api_configI::~api_configI()
|
||||
{
|
||||
}
|
||||
|
||||
void api_configI::config_registerCfgItem(CfgItem *cfgitem)
|
||||
{
|
||||
cfglist.addItem(cfgitem);
|
||||
}
|
||||
|
||||
void api_configI::config_deregisterCfgItem(CfgItem *cfgitem)
|
||||
{
|
||||
cfglist.delItem(cfgitem);
|
||||
}
|
||||
|
||||
int api_configI::config_getNumCfgItems()
|
||||
{
|
||||
return cfglist.getNumItems();
|
||||
}
|
||||
|
||||
CfgItem *api_configI::config_enumCfgItem(int n)
|
||||
{
|
||||
return cfglist.enumItem(n);
|
||||
}
|
||||
|
||||
CfgItem *api_configI::config_getCfgItemByGuid(GUID g)
|
||||
{
|
||||
return cfglist.getByGuid(g);
|
||||
}
|
||||
|
||||
// The private config functions are currently pointing at the public config item, this is because
|
||||
// only the monolithic api gets instantiated once per component and thus can know its GUID, this
|
||||
// version of the config api should eventually be instantiated once per component as well when
|
||||
// we start making them use the modular apis
|
||||
void api_configI::setIntPrivate(const wchar_t *name, int val)
|
||||
{
|
||||
public_config.setInt(name, val);
|
||||
}
|
||||
|
||||
int api_configI::getIntPrivate(const wchar_t *name, int def_val)
|
||||
{
|
||||
int ret = public_config.getInt(name, def_val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void api_configI::setIntArrayPrivate(const wchar_t *name, const int *val, int nval)
|
||||
{
|
||||
if (nval > 256) return;
|
||||
wchar_t buf[12*256]=L"";
|
||||
for (int i = 0; i < nval; i++)
|
||||
{
|
||||
wcscat(buf, StringPrintfW(L"%d", val[i]));
|
||||
if (i != nval-1)
|
||||
wcscat(buf, L",");
|
||||
}
|
||||
public_config.setString(name, buf);
|
||||
}
|
||||
|
||||
int api_configI::getIntArrayPrivate(const wchar_t *name, int *val, int nval)
|
||||
{
|
||||
wchar_t buf[12*256]=L"";
|
||||
public_config.getString(name, buf, sizeof(buf)/sizeof(*buf), L"");
|
||||
PathParserW pp(buf, L",");
|
||||
if (pp.getNumStrings() != nval) return 0;
|
||||
for (int i = 0; i < nval; i++) {
|
||||
*val = WTOI(pp.enumString(i));
|
||||
val ++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void api_configI::setStringPrivate(const wchar_t *name, const wchar_t *str)
|
||||
{
|
||||
public_config.setString(name, str);
|
||||
}
|
||||
|
||||
int api_configI::getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str)
|
||||
{
|
||||
int ret = public_config.getString(name, buf, buf_len, default_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int api_configI::getStringPrivateLen(const wchar_t *name)
|
||||
{
|
||||
return public_config.getStringLen(name);
|
||||
}
|
||||
|
||||
void api_configI::setIntPublic(const wchar_t *name, int val)
|
||||
{
|
||||
public_config.setInt(name, val);
|
||||
}
|
||||
|
||||
int api_configI::getIntPublic(const wchar_t *name, int def_val)
|
||||
{
|
||||
return public_config.getInt(name, def_val);
|
||||
}
|
||||
|
||||
void api_configI::setStringPublic(const wchar_t *name, const wchar_t *str)
|
||||
{
|
||||
public_config.setString(name, str);
|
||||
}
|
||||
|
||||
int api_configI::getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str)
|
||||
{
|
||||
return public_config.getString(name, buf, buf_len, default_str);
|
||||
}
|
46
Src/Wasabi/api/config/api_configi.h
Normal file
46
Src/Wasabi/api/config/api_configi.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef __API_CONFIG_IMPL_H
|
||||
#define __API_CONFIG_IMPL_H
|
||||
|
||||
/*<?<autoheader/>*/
|
||||
#include "api_config.h"
|
||||
#include "api_configx.h"
|
||||
#include <api/config/config.h>
|
||||
|
||||
class CfgItem;
|
||||
/*?>*/
|
||||
|
||||
class api_configI : public api_configX
|
||||
{
|
||||
public:
|
||||
api_configI();
|
||||
virtual ~api_configI();
|
||||
|
||||
DISPATCH(10) virtual void config_registerCfgItem(CfgItem *cfgitem);
|
||||
DISPATCH(20) virtual void config_deregisterCfgItem(CfgItem *cfgitem);
|
||||
DISPATCH(30) virtual int config_getNumCfgItems();
|
||||
DISPATCH(40) virtual CfgItem *config_enumCfgItem(int n);
|
||||
DISPATCH(50) virtual CfgItem *config_getCfgItemByGuid(GUID g);
|
||||
DISPATCH(60) virtual void setIntPrivate(const wchar_t *name, int val);
|
||||
DISPATCH(70) virtual int getIntPrivate(const wchar_t *name, int def_val);
|
||||
DISPATCH(80) virtual void setIntArrayPrivate(const wchar_t *name, const int *val, int nval);
|
||||
DISPATCH(90) virtual int getIntArrayPrivate(const wchar_t *name, int *val, int nval);
|
||||
DISPATCH(100) virtual void setStringPrivate(const wchar_t *name, const wchar_t *str);
|
||||
DISPATCH(110) virtual int getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
DISPATCH(120) virtual int getStringPrivateLen(const wchar_t *name);
|
||||
DISPATCH(130) virtual void setIntPublic(const wchar_t *name, int val);
|
||||
DISPATCH(140) virtual int getIntPublic(const wchar_t *name, int def_val);
|
||||
DISPATCH(150) virtual void setStringPublic(const wchar_t *name, const wchar_t *str);
|
||||
DISPATCH(160) virtual int getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
private:
|
||||
ConfigFile public_config;
|
||||
};
|
||||
|
||||
/*[interface.footer.h]
|
||||
// {470B890C-4747-4113-ABA5-A8F8F4F8AB7E}
|
||||
static const GUID configApiServiceGuid =
|
||||
{ 0x470b890c, 0x4747, 0x4113, { 0xab, 0xa5, 0xa8, 0xf8, 0xf4, 0xf8, 0xab, 0x7e } };
|
||||
|
||||
extern api_config *configApi;
|
||||
*/
|
||||
|
||||
#endif // __API_CONFIG_IMPL_H
|
37
Src/Wasabi/api/config/api_configx.cpp
Normal file
37
Src/Wasabi/api/config/api_configx.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Thu May 15 21:06:25 2003]
|
||||
//
|
||||
// File : api_configx.cpp
|
||||
// Class : api_config
|
||||
// class layer : Dispatchable Receiver
|
||||
// ----------------------------------------------------------------------------
|
||||
#include <precomp.h>
|
||||
|
||||
#include "api_configx.h"
|
||||
#include "api_configi.h"
|
||||
|
||||
#ifdef CBCLASS
|
||||
#undef CBCLASS
|
||||
#endif
|
||||
|
||||
#define CBCLASS api_configX
|
||||
START_DISPATCH;
|
||||
VCB(API_CONFIG_CONFIG_REGISTERCFGITEM, config_registerCfgItem);
|
||||
VCB(API_CONFIG_CONFIG_DEREGISTERCFGITEM, config_deregisterCfgItem);
|
||||
CB(API_CONFIG_CONFIG_GETNUMCFGITEMS, config_getNumCfgItems);
|
||||
CB(API_CONFIG_CONFIG_ENUMCFGITEM, config_enumCfgItem);
|
||||
CB(API_CONFIG_CONFIG_GETCFGITEMBYGUID, config_getCfgItemByGuid);
|
||||
VCB(API_CONFIG_SETINTPRIVATE, setIntPrivate);
|
||||
CB(API_CONFIG_GETINTPRIVATE, getIntPrivate);
|
||||
VCB(API_CONFIG_SETINTARRAYPRIVATE, setIntArrayPrivate);
|
||||
CB(API_CONFIG_GETINTARRAYPRIVATE, getIntArrayPrivate);
|
||||
VCB(API_CONFIG_SETSTRINGPRIVATE, setStringPrivate);
|
||||
CB(API_CONFIG_GETSTRINGPRIVATE, getStringPrivate);
|
||||
CB(API_CONFIG_GETSTRINGPRIVATELEN, getStringPrivateLen);
|
||||
VCB(API_CONFIG_SETINTPUBLIC, setIntPublic);
|
||||
CB(API_CONFIG_GETINTPUBLIC, getIntPublic);
|
||||
VCB(API_CONFIG_SETSTRINGPUBLIC, setStringPublic);
|
||||
CB(API_CONFIG_GETSTRINGPUBLIC, getStringPublic);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
||||
|
44
Src/Wasabi/api/config/api_configx.h
Normal file
44
Src/Wasabi/api/config/api_configx.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
// ----------------------------------------------------------------------------
|
||||
// Generated by InterfaceFactory [Thu May 15 21:06:24 2003]
|
||||
//
|
||||
// File : api_configx.h
|
||||
// Class : api_config
|
||||
// class layer : Dispatchable Receiver
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __API_CONFIGX_H
|
||||
#define __API_CONFIGX_H
|
||||
|
||||
#include "api_config.h"
|
||||
|
||||
class CfgItem;
|
||||
class ConfigFile;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class api_configX : public api_config {
|
||||
protected:
|
||||
api_configX() {}
|
||||
public:
|
||||
virtual void config_registerCfgItem(CfgItem *cfgitem)=0;
|
||||
virtual void config_deregisterCfgItem(CfgItem *cfgitem)=0;
|
||||
virtual int config_getNumCfgItems()=0;
|
||||
virtual CfgItem *config_enumCfgItem(int n)=0;
|
||||
virtual CfgItem *config_getCfgItemByGuid(GUID g)=0;
|
||||
virtual void setIntPrivate(const wchar_t *name, int val)=0;
|
||||
virtual int getIntPrivate(const wchar_t *name, int def_val)=0;
|
||||
virtual void setIntArrayPrivate(const wchar_t *name, const int *val, int nval)=0;
|
||||
virtual int getIntArrayPrivate(const wchar_t *name, int *val, int nval)=0;
|
||||
virtual void setStringPrivate(const wchar_t *name, const wchar_t *str)=0;
|
||||
virtual int getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str)=0;
|
||||
virtual int getStringPrivateLen(const wchar_t *name)=0;
|
||||
virtual void setIntPublic(const wchar_t *name, int val)=0;
|
||||
virtual int getIntPublic(const wchar_t *name, int def_val)=0;
|
||||
virtual void setStringPublic(const wchar_t *name, const wchar_t *str)=0;
|
||||
virtual int getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str)=0;
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
#endif // __API_CONFIGX_H
|
50
Src/Wasabi/api/config/cfglist.cpp
Normal file
50
Src/Wasabi/api/config/cfglist.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "cfglist.h"
|
||||
#include <bfc/ptrlist.h>
|
||||
|
||||
void CfgList::addItem(CfgItem *cfgitem)
|
||||
{
|
||||
if (cfgitem == NULL ||
|
||||
cfgitem->getGuid() == INVALID_GUID ||
|
||||
list.haveItem(cfgitem)) return;
|
||||
viewer_addViewItem(cfgitem);
|
||||
list.addItem(cfgitem);
|
||||
|
||||
cfgitem->onRegister(); // recurses children
|
||||
}
|
||||
|
||||
void CfgList::delItem(CfgItem *cfgitem)
|
||||
{
|
||||
if (cfgitem == NULL || !list.haveItem(cfgitem)) return;
|
||||
|
||||
list.removeItem(cfgitem);
|
||||
viewer_delViewItem(cfgitem);
|
||||
|
||||
cfgitem->onDeregister(); // recurses children
|
||||
}
|
||||
|
||||
int CfgList::getNumItems()
|
||||
{
|
||||
return list.getNumItems();
|
||||
}
|
||||
|
||||
CfgItem *CfgList::enumItem(int n)
|
||||
{
|
||||
return list[n];
|
||||
}
|
||||
|
||||
CfgItem *CfgList::getByGuid(GUID g)
|
||||
{
|
||||
if (g == INVALID_GUID) return NULL;
|
||||
foreach(list)
|
||||
if (list.getfor()->getGuid() == g) return list.getfor();
|
||||
endfor
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CfgList::viewer_onItemDeleted(CfgItem *item)
|
||||
{
|
||||
list.removeItem(item);
|
||||
return 1;
|
||||
}
|
23
Src/Wasabi/api/config/cfglist.h
Normal file
23
Src/Wasabi/api/config/cfglist.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _CFGLIST_H
|
||||
#define _CFGLIST_H
|
||||
|
||||
#include <bfc/wasabi_std.h>
|
||||
#include <bfc/depview.h>
|
||||
#include <api/config/items/cfgitem.h>
|
||||
|
||||
class CfgList : public DependentViewerTPtr<CfgItem> {
|
||||
public:
|
||||
void addItem(CfgItem *cfgitem);
|
||||
void delItem(CfgItem *cfgitem);
|
||||
|
||||
int getNumItems();
|
||||
CfgItem *enumItem(int n);
|
||||
CfgItem *getByGuid(GUID g);
|
||||
|
||||
virtual int viewer_onItemDeleted(CfgItem *item);
|
||||
|
||||
private:
|
||||
PtrList<CfgItem> list;
|
||||
};
|
||||
|
||||
#endif
|
371
Src/Wasabi/api/config/cfgscriptobj.cpp
Normal file
371
Src/Wasabi/api/config/cfgscriptobj.cpp
Normal file
|
@ -0,0 +1,371 @@
|
|||
#include <precomp.h>
|
||||
#include "cfgscriptobj.h"
|
||||
|
||||
#include <api/config/items/cfgitemi.h>
|
||||
|
||||
#ifndef _WASABIRUNTIME
|
||||
|
||||
BEGIN_SERVICES(ConfigObject_Svc);
|
||||
DECLARE_SERVICE(ScriptObjectCreator<ConfigScriptObjectSvc>);
|
||||
END_SERVICES(ConfigObject_Svc, _ConfigObject_Svc);
|
||||
|
||||
#ifdef _X86_
|
||||
extern "C" { int _link_ConfigObjectSvc; }
|
||||
#else
|
||||
extern "C" { int __link_ConfigObjectSvc; }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static ConfigScriptObjectController _configController;
|
||||
ScriptObjectController *configController = &_configController;
|
||||
|
||||
static ConfigItemScriptObjectController _configItemController;
|
||||
ScriptObjectController *configItemController = &_configItemController;
|
||||
|
||||
static ConfigAttributeScriptObjectController _configAttributeController;
|
||||
ScriptObjectController *configAttributeController = &_configAttributeController;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// Service
|
||||
|
||||
ScriptObjectController *ConfigScriptObjectSvc::getController(int n)
|
||||
{
|
||||
switch (n) {
|
||||
case 0:
|
||||
return configController;
|
||||
case 1:
|
||||
return configItemController;
|
||||
case 2:
|
||||
return configAttributeController;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ConfigObject
|
||||
|
||||
ConfigObject::ConfigObject() {
|
||||
numobjects++;
|
||||
getScriptObject()->vcpu_setInterface(CONFIG_SCRIPTOBJECT_GUID, (void *)static_cast<ConfigObject *>(this));
|
||||
getScriptObject()->vcpu_setClassName(L"Config");
|
||||
getScriptObject()->vcpu_setController(configController);
|
||||
}
|
||||
|
||||
ConfigObject::~ConfigObject() {
|
||||
numobjects--;
|
||||
mylist.deleteAll();
|
||||
if (numobjects == 0) {
|
||||
foreach(ouraddeditems)
|
||||
WASABI_API_CONFIG->config_deregisterCfgItem(ouraddeditems.getfor());
|
||||
endfor
|
||||
ouraddeditems.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
PtrList<CfgItemI> ConfigObject::ouraddeditems;
|
||||
int ConfigObject::numobjects=0;
|
||||
|
||||
|
||||
function_descriptor_struct ConfigScriptObjectController::exportedFunction[] = {
|
||||
{L"getItem", 1, (void*)ConfigObject::config_getItem},
|
||||
{L"getItemByGuid", 1, (void*)ConfigObject::config_getItemByGuid},
|
||||
{L"newItem", 2, (void*)ConfigObject::config_newItem},
|
||||
};
|
||||
|
||||
int ConfigScriptObjectController::getNumFunctions() {
|
||||
return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
|
||||
}
|
||||
|
||||
scriptVar ConfigObject::config_newItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name, scriptVar configitem_guid)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigObject *co = static_cast<ConfigObject*>(o->vcpu_getInterface(CONFIG_SCRIPTOBJECT_GUID));
|
||||
ConfigItemObject *ret=getItem(GET_SCRIPT_STRING(configitem_name), co);
|
||||
if (!ret)
|
||||
ret = getItem(GET_SCRIPT_STRING(configitem_guid), co);
|
||||
if (ret)
|
||||
return MAKE_SCRIPT_OBJECT(ret->getScriptObject());
|
||||
CfgItemI *item = new CfgItemI(GET_SCRIPT_STRING(configitem_name), nsGUID::fromCharW(GET_SCRIPT_STRING(configitem_guid)));
|
||||
ConfigObject::ouraddeditems.addItem(item);
|
||||
WASABI_API_CONFIG->config_registerCfgItem(item);
|
||||
ret = new ConfigItemObject(item);
|
||||
co->mylist.addItem(ret);
|
||||
return MAKE_SCRIPT_OBJECT(ret->getScriptObject());
|
||||
}
|
||||
|
||||
ConfigItemObject *ConfigObject::getItem(const wchar_t *nameorguid, ConfigObject *co) {
|
||||
int i=0;
|
||||
ConfigItemObject *ret=NULL;
|
||||
GUID g = nsGUID::fromCharW(nameorguid);
|
||||
for (i=0;;i++) {
|
||||
CfgItem *item = WASABI_API_CONFIG->config_enumCfgItem(i);
|
||||
if (!item) break;
|
||||
GUID ig = item->getGuid();
|
||||
if (g == ig || WCSCASEEQLSAFE(nameorguid, item->getName()))
|
||||
{
|
||||
ret = new ConfigItemObject(item);
|
||||
co->mylist.addItem(ret);
|
||||
break;
|
||||
}
|
||||
#if 0//CUT
|
||||
for (int j=0;j<item->getNumChildren();j++) {
|
||||
if (STRCASEEQL(nameorguid, item->enumChild(j)->getName())) {
|
||||
ret = new ConfigItemObject(item->enumChild(j));
|
||||
co->mylist.addItem(ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
scriptVar ConfigObject::config_getItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar cfgitem_name)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigObject *co = static_cast<ConfigObject*>(o->vcpu_getInterface(CONFIG_SCRIPTOBJECT_GUID));
|
||||
ConfigItemObject *ret=getItem(GET_SCRIPT_STRING(cfgitem_name), co);
|
||||
return MAKE_SCRIPT_OBJECT(ret ? ret->getScriptObject() : NULL);
|
||||
}
|
||||
|
||||
scriptVar ConfigObject::config_getItemByGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar cfgitem_guid)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
// GUID g = nsGUID::fromChar(GET_SCRIPT_STRING(guid));
|
||||
// api->
|
||||
int i=0;
|
||||
ConfigItemObject *ret=NULL;
|
||||
ConfigObject *co = static_cast<ConfigObject*>(o->vcpu_getInterface(CONFIG_SCRIPTOBJECT_GUID));
|
||||
|
||||
const wchar_t *p = GET_SCRIPT_STRING(cfgitem_guid);
|
||||
if (p == NULL) {
|
||||
RETURN_SCRIPT_ZERO;
|
||||
}
|
||||
|
||||
GUID g = nsGUID::fromCharW(p);
|
||||
|
||||
for (i=0;;i++) {
|
||||
CfgItem *item = WASABI_API_CONFIG->config_enumCfgItem(i);
|
||||
if (!item) break;
|
||||
if (g == item->getGuid()) {
|
||||
ret = new ConfigItemObject(item);
|
||||
co->mylist.addItem(ret);
|
||||
break;
|
||||
}
|
||||
#if 0//CUT
|
||||
for (int j=0;j<item->getNumChildren();j++) {
|
||||
if (g == item->enumChild(j)->getName()) {
|
||||
ret = new ConfigItemObject(item->enumChild(j));
|
||||
co->mylist.addItem(ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return MAKE_SCRIPT_OBJECT(ret ? ret->getScriptObject() : NULL);
|
||||
}
|
||||
|
||||
ScriptObject *ConfigScriptObjectController::instantiate() {
|
||||
ConfigObject *c = new ConfigObject;
|
||||
if (!c) return NULL;
|
||||
return c->getScriptObject();
|
||||
}
|
||||
|
||||
void ConfigScriptObjectController::destroy(ScriptObject *o) {
|
||||
ConfigObject *obj = static_cast<ConfigObject *>(o->vcpu_getInterface(CONFIG_SCRIPTOBJECT_GUID));
|
||||
ASSERT(obj != NULL);
|
||||
delete obj;
|
||||
}
|
||||
|
||||
void *ConfigScriptObjectController::encapsulate(ScriptObject *o) {
|
||||
return NULL; // no encapsulation for config
|
||||
}
|
||||
|
||||
void ConfigScriptObjectController::deencapsulate(void *) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ConfigItem
|
||||
|
||||
function_descriptor_struct ConfigItemScriptObjectController::exportedFunction[] = {
|
||||
{L"getAttribute", 1, (void*)ConfigItemObject::configItem_getAttribute},
|
||||
{L"getGuid", 0, (void*)ConfigItemObject::configItem_getGuid},
|
||||
{L"newAttribute", 2, (void*)ConfigItemObject::configItem_newAttribute},
|
||||
};
|
||||
|
||||
int ConfigItemScriptObjectController::getNumFunctions() {
|
||||
return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
|
||||
}
|
||||
|
||||
ConfigItemObject::ConfigItemObject(CfgItem *_item)
|
||||
{
|
||||
getScriptObject()->vcpu_setInterface(CONFIGITEM_SCRIPTOBJECT_GUID, (void *)static_cast<ConfigItemObject *>(this));
|
||||
getScriptObject()->vcpu_setClassName(L"ConfigItem");
|
||||
getScriptObject()->vcpu_setController(configItemController);
|
||||
wchar_t strguid[256];
|
||||
nsGUID::toCharW(_item->getGuid(), strguid);
|
||||
guid = strguid;
|
||||
item = _item;
|
||||
}
|
||||
|
||||
ConfigAttributeObject *ConfigItemObject::getAttribute(const wchar_t *name)
|
||||
{
|
||||
if (!item) return NULL;
|
||||
for (int i=0;i<item->getNumAttributes();i++)
|
||||
{
|
||||
if (!WCSICMP(item->enumAttribute(i), name))
|
||||
{
|
||||
ConfigAttributeObject *o = new ConfigAttributeObject(item, name, this);
|
||||
mylist.addItem(o);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ConfigAttributeObject *ConfigItemObject::newAttribute(const wchar_t *name, const wchar_t *defaultvalue)
|
||||
{
|
||||
if (!item) return NULL;
|
||||
ConfigAttributeObject *o = getAttribute(name);
|
||||
if (o != NULL) return o;
|
||||
|
||||
item->addAttribute(name, defaultvalue);
|
||||
|
||||
ConfigAttributeObject *cao = getAttribute(name);
|
||||
cao->setAutoDelete();
|
||||
return cao;
|
||||
}
|
||||
|
||||
ConfigItemObject::~ConfigItemObject()
|
||||
{
|
||||
mylist.deleteAll();
|
||||
}
|
||||
|
||||
scriptVar ConfigItemObject::configItem_getAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar name)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigItemObject *cio = static_cast<ConfigItemObject *>(o->vcpu_getInterface(CONFIGITEM_SCRIPTOBJECT_GUID));
|
||||
ConfigAttributeObject *cao = NULL;
|
||||
if (cio)
|
||||
cao = cio->getAttribute(GET_SCRIPT_STRING(name));
|
||||
return MAKE_SCRIPT_OBJECT(cao ? cao->getScriptObject() : NULL);
|
||||
}
|
||||
|
||||
scriptVar ConfigItemObject::configItem_getGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigItemObject *cio = static_cast<ConfigItemObject *>(o->vcpu_getInterface(CONFIGITEM_SCRIPTOBJECT_GUID));
|
||||
if (cio) return MAKE_SCRIPT_STRING(cio->getGuid());
|
||||
return MAKE_SCRIPT_STRING(L"");
|
||||
}
|
||||
|
||||
scriptVar ConfigItemObject::configItem_newAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar name, scriptVar defval) {
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigItemObject *cio = static_cast<ConfigItemObject *>(o->vcpu_getInterface(CONFIGITEM_SCRIPTOBJECT_GUID));
|
||||
ConfigAttributeObject *cao = NULL;
|
||||
if (cio)
|
||||
cao = cio->newAttribute(GET_SCRIPT_STRING(name), GET_SCRIPT_STRING(defval));
|
||||
return MAKE_SCRIPT_OBJECT(cao ? cao->getScriptObject() : NULL);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ConfigAttribute
|
||||
|
||||
function_descriptor_struct ConfigAttributeScriptObjectController::exportedFunction[] = {
|
||||
{L"getData", 0, (void*)ConfigAttributeObject::configAttr_getData},
|
||||
{L"setData", 1, (void*)ConfigAttributeObject::configAttr_setData},
|
||||
{L"onDataChanged", 0, (void*)ConfigAttributeObject::configAttr_onDataChanged},
|
||||
{L"getParentItem", 0, (void*)ConfigAttributeObject::configAttr_getParentItem},
|
||||
{L"getAttributeName", 0, (void*)ConfigAttributeObject::configAttr_getAttributeName},
|
||||
};
|
||||
|
||||
int ConfigAttributeScriptObjectController::getNumFunctions() {
|
||||
return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
|
||||
}
|
||||
|
||||
void ConfigAttributeObject::setData(const wchar_t *data)
|
||||
{
|
||||
if (!item || !attr) return;
|
||||
item->setData(attr, data);
|
||||
}
|
||||
|
||||
const wchar_t *ConfigAttributeObject::getData()
|
||||
{
|
||||
if (!item || !attr) return NULL;
|
||||
static wchar_t t[WA_MAX_PATH];
|
||||
item->getData(attr, t, WA_MAX_PATH);
|
||||
return t;
|
||||
}
|
||||
|
||||
ConfigAttributeObject::ConfigAttributeObject(CfgItem *_item, const wchar_t *_attr, ConfigItemObject *_parent)
|
||||
{
|
||||
getScriptObject()->vcpu_setInterface(CONFIGATTRIBUTE_SCRIPTOBJECT_GUID, (void *)static_cast<ConfigAttributeObject *>(this));
|
||||
getScriptObject()->vcpu_setClassName(L"ConfigAttribute");
|
||||
getScriptObject()->vcpu_setController(configAttributeController);
|
||||
attr = _attr;
|
||||
item = _item;
|
||||
parent = _parent;
|
||||
viewer_addViewItem(item);
|
||||
autodelete = 0;
|
||||
}
|
||||
|
||||
ConfigAttributeObject::~ConfigAttributeObject() {
|
||||
if (autodelete) getParentItem()->getCfgItem()->delAttribute(attr);
|
||||
}
|
||||
|
||||
int ConfigAttributeObject::viewer_onEvent(CfgItem *item, int event, intptr_t param, void *ptr, size_t ptrlen)
|
||||
{
|
||||
if (event == CfgItem::Event_ATTRIBUTE_CHANGED)
|
||||
{
|
||||
const wchar_t *_attr = reinterpret_cast<const wchar_t *>(ptr);
|
||||
if (!WCSICMP(attr, _attr))
|
||||
configAttr_onDataChanged(SCRIPT_CALL, getScriptObject());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
scriptVar ConfigAttributeObject::configAttr_setData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar val)
|
||||
{
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigAttributeObject *cao = static_cast<ConfigAttributeObject *>(o->vcpu_getInterface(CONFIGATTRIBUTE_SCRIPTOBJECT_GUID));
|
||||
if (cao)
|
||||
cao->setData(GET_SCRIPT_STRING(val));
|
||||
RETURN_SCRIPT_VOID;
|
||||
}
|
||||
|
||||
scriptVar ConfigAttributeObject::configAttr_getData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigAttributeObject *cao = static_cast<ConfigAttributeObject *>(o->vcpu_getInterface(CONFIGATTRIBUTE_SCRIPTOBJECT_GUID));
|
||||
if (cao)
|
||||
return MAKE_SCRIPT_STRING(cao->getData());
|
||||
return MAKE_SCRIPT_STRING(L"");
|
||||
}
|
||||
|
||||
scriptVar ConfigAttributeObject::configAttr_onDataChanged(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT
|
||||
PROCESS_HOOKS0(o, configAttributeController);
|
||||
SCRIPT_FUNCTION_CHECKABORTEVENT;
|
||||
SCRIPT_EXEC_EVENT0(o);
|
||||
}
|
||||
|
||||
scriptVar ConfigAttributeObject::configAttr_getParentItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigAttributeObject *cao = static_cast<ConfigAttributeObject *>(o->vcpu_getInterface(CONFIGATTRIBUTE_SCRIPTOBJECT_GUID));
|
||||
if (cao) return MAKE_SCRIPT_OBJECT(cao->getParentItem()->getScriptObject());
|
||||
return MAKE_SCRIPT_OBJECT(NULL);
|
||||
}
|
||||
|
||||
scriptVar ConfigAttributeObject::configAttr_getAttributeName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT
|
||||
ConfigAttributeObject *cao = static_cast<ConfigAttributeObject *>(o->vcpu_getInterface(CONFIGATTRIBUTE_SCRIPTOBJECT_GUID));
|
||||
|
||||
if (cao)
|
||||
return MAKE_SCRIPT_STRING(cao->getAttributeName());
|
||||
|
||||
return MAKE_SCRIPT_STRING(L"");
|
||||
}
|
||||
|
||||
|
||||
|
198
Src/Wasabi/api/config/cfgscriptobj.h
Normal file
198
Src/Wasabi/api/config/cfgscriptobj.h
Normal file
|
@ -0,0 +1,198 @@
|
|||
#ifndef __CFGSCRIPTOBJ_H
|
||||
#define __CFGSCRIPTOBJ_H
|
||||
|
||||
#include <api/script/objects/rootobj.h>
|
||||
#include <api/script/objcontroller.h>
|
||||
#include <api/script/scriptobj.h>
|
||||
#include <bfc/depview.h>
|
||||
#include <api/service/svcs/svc_scriptobji.h>
|
||||
#include <api/config/items/attribs.h>
|
||||
|
||||
class CfgItem;
|
||||
class ConfigObject;
|
||||
class ConfigItemObject;
|
||||
class ConfigAttributeObject;
|
||||
|
||||
extern ScriptObjectController *configController;
|
||||
extern ScriptObjectController *configItemController;
|
||||
extern ScriptObjectController *configAttributeController;
|
||||
|
||||
enum cfgtypes {
|
||||
CFG_INT = 0,
|
||||
CFG_BOOL = 1,
|
||||
CFG_FLOAT = 2,
|
||||
CFG_STRING = 3,
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ScriptObject Provider Service
|
||||
|
||||
class ConfigScriptObjectSvc : public svc_scriptObjectI {
|
||||
|
||||
public:
|
||||
ConfigScriptObjectSvc() {};
|
||||
virtual ~ConfigScriptObjectSvc() {};
|
||||
|
||||
static const char *getServiceName() { return "Config maki object"; }
|
||||
virtual ScriptObjectController *getController(int n);
|
||||
|
||||
static void addItemObject(ConfigItemObject *item);
|
||||
static void addAttrObject(ConfigAttributeObject *attr);
|
||||
static void removeItemObject(ConfigItemObject *item);
|
||||
static void removeAttrObject(ConfigAttributeObject *attr);
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// Script classes GUIDS
|
||||
|
||||
// {593DBA22-D077-4976-B952-F4713655400B}
|
||||
static const GUID CONFIG_SCRIPTOBJECT_GUID =
|
||||
{ 0x593dba22, 0xd077, 0x4976, { 0xb9, 0x52, 0xf4, 0x71, 0x36, 0x55, 0x40, 0xb } };
|
||||
|
||||
// {D4030282-3AAB-4d87-878D-12326FADFCD5}
|
||||
static const GUID CONFIGITEM_SCRIPTOBJECT_GUID =
|
||||
{ 0xd4030282, 0x3aab, 0x4d87, { 0x87, 0x8d, 0x12, 0x32, 0x6f, 0xad, 0xfc, 0xd5 } };
|
||||
|
||||
// {24DEC283-B76E-4a36-8CCC-9E24C46B6C73}
|
||||
static const GUID CONFIGATTRIBUTE_SCRIPTOBJECT_GUID =
|
||||
{ 0x24dec283, 0xb76e, 0x4a36, { 0x8c, 0xcc, 0x9e, 0x24, 0xc4, 0x6b, 0x6c, 0x73 } };
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ScriptObject Interfaces
|
||||
|
||||
// Config
|
||||
class ConfigObject : public RootObjectInstance {
|
||||
|
||||
public:
|
||||
|
||||
ConfigObject();
|
||||
virtual ~ConfigObject();
|
||||
|
||||
static scriptVar config_getItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name);
|
||||
static scriptVar config_getItemByGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name);
|
||||
static scriptVar config_newItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar configitem_name, scriptVar guid);
|
||||
private:
|
||||
static ConfigItemObject *getItem(const wchar_t *nameorguid, ConfigObject *co);
|
||||
PtrList<ConfigItemObject> mylist;
|
||||
static PtrList<CfgItemI> ouraddeditems;
|
||||
static int numobjects;
|
||||
};
|
||||
|
||||
// ConfigItem
|
||||
class ConfigItemObject : public RootObjectInstance {
|
||||
|
||||
public:
|
||||
|
||||
ConfigItemObject(CfgItem *item);
|
||||
virtual ~ConfigItemObject();
|
||||
|
||||
ConfigAttributeObject *getAttribute(const wchar_t *name);
|
||||
const wchar_t *getGuid() { return guid; }
|
||||
ConfigAttributeObject *newAttribute(const wchar_t *name, const wchar_t *defval);
|
||||
|
||||
CfgItem *getCfgItem() { return item; }
|
||||
|
||||
static scriptVar configItem_getAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar attr_name);
|
||||
static scriptVar configItem_getGuid(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
|
||||
static scriptVar configItem_newAttribute(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar attr_name, scriptVar defval);
|
||||
|
||||
private:
|
||||
CfgItem *item;
|
||||
StringW guid;
|
||||
PtrList<ConfigAttributeObject> mylist;
|
||||
};
|
||||
|
||||
// ConfigAttribute
|
||||
class ConfigAttributeObject : public RootObjectInstance, public DependentViewerTPtr<CfgItem> {
|
||||
|
||||
public:
|
||||
|
||||
ConfigAttributeObject(CfgItem *item, const wchar_t *attr, ConfigItemObject *parent);
|
||||
virtual ~ConfigAttributeObject();
|
||||
|
||||
void setData(const wchar_t *data);
|
||||
const wchar_t *getData();
|
||||
ConfigItemObject *getParentItem() { return parent; }
|
||||
const wchar_t *getAttributeName() { return attr; }
|
||||
void setAutoDelete() { autodelete = 1; }
|
||||
|
||||
virtual int viewer_onEvent(CfgItem *item, int event, intptr_t param, void *ptr, size_t ptrlen);
|
||||
|
||||
static scriptVar configAttr_getData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
|
||||
static scriptVar configAttr_setData(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar val);
|
||||
static scriptVar configAttr_onDataChanged(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
|
||||
static scriptVar configAttr_getParentItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
|
||||
static scriptVar configAttr_getAttributeName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
|
||||
|
||||
private:
|
||||
CfgItem *item;
|
||||
StringW attr;
|
||||
ConfigItemObject *parent;
|
||||
int autodelete;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------
|
||||
// ScriptObjectControllers for our script classes
|
||||
|
||||
// Config
|
||||
class ConfigScriptObjectController : public ScriptObjectControllerI {
|
||||
public:
|
||||
virtual const wchar_t *getClassName() { return L"Config"; }
|
||||
virtual const wchar_t *getAncestorClassName() { return L"Object"; }
|
||||
virtual ScriptObjectController *getAncestorController() { return NULL; }
|
||||
virtual int getNumFunctions();
|
||||
virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
|
||||
virtual GUID getClassGuid() { return CONFIG_SCRIPTOBJECT_GUID; }
|
||||
virtual int getInstantiable() { return 0; }
|
||||
virtual int getReferenceable() { return 0; }
|
||||
virtual ScriptObject *instantiate();
|
||||
virtual void destroy(ScriptObject *o);
|
||||
virtual void *encapsulate(ScriptObject *o);
|
||||
virtual void deencapsulate(void *o);
|
||||
|
||||
private:
|
||||
static function_descriptor_struct exportedFunction[];
|
||||
};
|
||||
|
||||
// ConfigItem
|
||||
class ConfigItemScriptObjectController : public ScriptObjectControllerI {
|
||||
public:
|
||||
virtual const wchar_t *getClassName() { return L"ConfigItem"; }
|
||||
virtual const wchar_t *getAncestorClassName() { return L"Object"; }
|
||||
virtual ScriptObjectController *getAncestorController() { return NULL; }
|
||||
virtual int getNumFunctions();
|
||||
virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
|
||||
virtual GUID getClassGuid() { return CONFIGITEM_SCRIPTOBJECT_GUID; }
|
||||
virtual int getInstantiable() { return 0; }
|
||||
virtual int getReferenceable() { return 1; }
|
||||
virtual ScriptObject *instantiate() { return NULL; };
|
||||
virtual void destroy(ScriptObject *o) { };
|
||||
virtual void *encapsulate(ScriptObject *o) { return NULL; };
|
||||
virtual void deencapsulate(void *o) { };
|
||||
|
||||
private:
|
||||
static function_descriptor_struct exportedFunction[];
|
||||
};
|
||||
|
||||
// ConfigAttribute
|
||||
class ConfigAttributeScriptObjectController : public ScriptObjectControllerI {
|
||||
public:
|
||||
virtual const wchar_t *getClassName() { return L"ConfigAttribute"; }
|
||||
virtual const wchar_t *getAncestorClassName() { return L"Object"; }
|
||||
virtual ScriptObjectController *getAncestorController() { return NULL; }
|
||||
virtual int getNumFunctions();
|
||||
virtual const function_descriptor_struct *getExportedFunctions() { return exportedFunction; }
|
||||
virtual GUID getClassGuid() { return CONFIGATTRIBUTE_SCRIPTOBJECT_GUID; }
|
||||
virtual int getInstantiable() { return 0; }
|
||||
virtual int getReferenceable() { return 1; }
|
||||
virtual ScriptObject *instantiate() { return NULL; };
|
||||
virtual void destroy(ScriptObject *o) { };
|
||||
virtual void *encapsulate(ScriptObject *o) { return NULL; };
|
||||
virtual void deencapsulate(void *o) { };
|
||||
|
||||
private:
|
||||
static function_descriptor_struct exportedFunction[];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
329
Src/Wasabi/api/config/config.cpp
Normal file
329
Src/Wasabi/api/config/config.cpp
Normal file
|
@ -0,0 +1,329 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "config.h"
|
||||
#include <bfc/pair.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
#include <bfc/parse/pathparse.h>
|
||||
#include <api/xml/xmlwrite.h>
|
||||
|
||||
#include "../xml/ifc_xmlreadercallbackI.h"
|
||||
#include "../xml/obj_xml.h"
|
||||
#include <bfc/string/url.h>
|
||||
#include <api/service/waservicefactory.h>
|
||||
|
||||
static StringW iniFile;
|
||||
#define XNFNAME L"studio.xnf"
|
||||
|
||||
class StringPairCompare
|
||||
{
|
||||
public:
|
||||
static int compareItem(StringPair *p1, StringPair *p2)
|
||||
{
|
||||
int r = wcscmp(p1->a.getValue(), p2->a.getValue());
|
||||
if (r == 0)
|
||||
return CMP3(p1, p2);
|
||||
else
|
||||
return r;
|
||||
}
|
||||
static int compareAttrib(const wchar_t *attrib, StringPair *item)
|
||||
{
|
||||
return wcscmp(attrib, item->a.getValue());
|
||||
}
|
||||
};
|
||||
|
||||
static PtrListQuickSorted<StringPair, StringPairCompare> strings;
|
||||
|
||||
class Reader : public ifc_xmlreadercallbackI
|
||||
{
|
||||
public:
|
||||
~Reader();
|
||||
void xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params);
|
||||
void xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag);
|
||||
|
||||
void readem();
|
||||
|
||||
private:
|
||||
PtrList<StringW> sections;
|
||||
};
|
||||
|
||||
Reader::~Reader()
|
||||
{
|
||||
sections.deleteAll();
|
||||
}
|
||||
|
||||
void Reader::xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
|
||||
{
|
||||
if (!WCSICMP(xmltag, L"section"))
|
||||
{
|
||||
const wchar_t *name = params->getItemValue(L"name");
|
||||
if (name == NULL)
|
||||
return ;
|
||||
|
||||
StringW *strName = new StringW(name);
|
||||
Url::decode(*strName);
|
||||
sections.addItem(strName);
|
||||
}
|
||||
else if (!WCSICMP(xmltag, L"entry"))
|
||||
{
|
||||
const wchar_t *name = params->getItemValue(L"name");
|
||||
const wchar_t *value = params->getItemValue(L"value");
|
||||
|
||||
// just in case
|
||||
if (!WCSICMP(name, L"(null)")) name = NULL;
|
||||
if (!WCSICMP(value, L"(null)")) value = NULL;
|
||||
|
||||
if (name == NULL /*| !*name */ || value == NULL /*|| !*value*/) return ;
|
||||
StringW strName = name;
|
||||
Url::decode(strName);
|
||||
|
||||
StringW strValue = value;
|
||||
Url::decode(strValue);
|
||||
|
||||
StringW n;
|
||||
for (int i = 0; i < sections.getNumItems(); i++)
|
||||
{
|
||||
n.catPostSeparator(*sections[i], '/');
|
||||
}
|
||||
n += strName;
|
||||
|
||||
StringPair *p = new StringPair(n, strValue);
|
||||
strings.addItem(p);
|
||||
}
|
||||
}
|
||||
|
||||
void Reader::xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag)
|
||||
{
|
||||
if (!WCSICMP(xmltag, L"section"))
|
||||
{
|
||||
StringW *last = sections.getLast();
|
||||
sections.removeLastItem();
|
||||
delete last;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadXmlFile(obj_xml *parser, const wchar_t *filename);
|
||||
|
||||
void Reader::readem()
|
||||
{
|
||||
strings.deleteAll();
|
||||
|
||||
if (iniFile.isempty())
|
||||
{
|
||||
iniFile = StringPathCombine(WASABI_API_APP->path_getUserSettingsPath(), XNFNAME);
|
||||
}
|
||||
|
||||
waServiceFactory *parserFactory = WASABI_API_SVC->service_getServiceByGuid(obj_xmlGUID);
|
||||
if (parserFactory)
|
||||
{
|
||||
obj_xml *parser = (obj_xml *)parserFactory->getInterface();
|
||||
|
||||
if (parser)
|
||||
{
|
||||
|
||||
parser->xmlreader_registerCallback(L"WinampXML\fconfiguration\f*", this);
|
||||
parser->xmlreader_registerCallback(L"WasabiXML\fconfiguration\f*", this);
|
||||
parser->xmlreader_open();
|
||||
LoadXmlFile(parser, iniFile);
|
||||
|
||||
parser->xmlreader_unregisterCallback(this);
|
||||
parser->xmlreader_close();
|
||||
parserFactory->releaseInterface(parser);
|
||||
parser = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringPair *ConfigFile::getPair(const wchar_t *name)
|
||||
{
|
||||
ASSERT(!sectionname.isempty());
|
||||
StringW nname;
|
||||
nname.catPostSeparator(sectionname.getValue(), '/');
|
||||
nname.cat(name);
|
||||
return strings.findItem(nname.getValue()); // cast to make PtrListSorted happy
|
||||
}
|
||||
|
||||
StringPair *ConfigFile::makePair(const wchar_t *name, const wchar_t *value)
|
||||
{
|
||||
StringPair *ret = getPair(name);
|
||||
if (ret == NULL)
|
||||
{
|
||||
StringW nname;
|
||||
nname.catPostSeparator(sectionname.getValue(), '/');
|
||||
nname.cat(name);
|
||||
|
||||
ret = new StringPair(nname, value);
|
||||
strings.addItem(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret->b.setValue(value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ninstances, inited;
|
||||
|
||||
ConfigFile::ConfigFile(const wchar_t *section, const wchar_t *name)
|
||||
{
|
||||
sectionname = section;
|
||||
prettyname = name;
|
||||
ninstances++;
|
||||
}
|
||||
|
||||
void ConfigFile::initialize()
|
||||
{
|
||||
Reader().readem();
|
||||
}
|
||||
|
||||
ConfigFile::~ConfigFile()
|
||||
{
|
||||
ninstances--;
|
||||
if (ninstances == 0)
|
||||
{
|
||||
FILE *fp = _wfopen(iniFile, WF_WRITE_TEXT);
|
||||
if (fp != NULL)
|
||||
{
|
||||
// write out the file
|
||||
XMLWrite xml(fp, L"WasabiXML");
|
||||
const wchar_t *app = WASABI_API_APP->main_getVersionString();
|
||||
if (!app)
|
||||
app = L"thousands of irascible butt monkeys";
|
||||
xml.comment(StringPrintfW(L"Generated by: %s (%d)", app, WASABI_API_APP->main_getBuildNumber()));
|
||||
xml.pushCategory(L"configuration");
|
||||
|
||||
PtrList<StringW> cats;
|
||||
|
||||
for (int i = 0; i < strings.getNumItems(); i++)
|
||||
{
|
||||
StringPair *p = strings[i];
|
||||
PathParserW pp(p->a);
|
||||
|
||||
int climit = MIN(pp.getNumStrings() - 1, cats.getNumItems());
|
||||
int j;
|
||||
for (j = 0; j < climit; j++)
|
||||
{
|
||||
if (WCSICMP(*cats[j], pp.enumString(j)))
|
||||
{
|
||||
climit = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (cats.getNumItems() > climit)
|
||||
{
|
||||
StringW *s = cats.getLast();
|
||||
xml.popCategory();
|
||||
cats.removeLastItem();
|
||||
delete s;
|
||||
}
|
||||
for (j = climit; j < pp.getNumStrings() - 1; j++)
|
||||
{
|
||||
StringW *s = cats.addItem(new StringW(pp.enumString(j)));
|
||||
xml.pushCategoryAttrib(L"section");
|
||||
StringW enc = *s;
|
||||
Url::encode(enc, FALSE, URLENCODE_EXCLUDE_ABOVEEQ32);
|
||||
xml.writeCategoryAttrib(L"name", enc);
|
||||
xml.closeCategoryAttrib();
|
||||
}
|
||||
|
||||
xml.pushCategoryAttrib(L"entry", TRUE);
|
||||
StringW enc = pp.getLastString();
|
||||
Url::encode(enc, FALSE, URLENCODE_EXCLUDE_ABOVEEQ32);
|
||||
xml.writeCategoryAttrib(L"name", enc);
|
||||
enc = p->b;
|
||||
Url::encode(enc, FALSE, URLENCODE_EXCLUDE_ABOVEEQ32);
|
||||
if (enc.iscaseequal(L"(null)") || enc.getValue() == NULL)
|
||||
enc.setValue(L"");
|
||||
xml.writeCategoryAttrib(L"value", enc);
|
||||
xml.closeCategoryAttrib();
|
||||
xml.popCategory();
|
||||
}
|
||||
|
||||
while (xml.popCategory()) ;
|
||||
|
||||
strings.deleteAll();
|
||||
fclose(fp);
|
||||
} // fp != NULL
|
||||
} // ninstances==0
|
||||
}
|
||||
|
||||
int verifyName(const wchar_t *str)
|
||||
{
|
||||
for (const wchar_t *p = str; *p; p++)
|
||||
{
|
||||
if (!ISALPHA(*p) &&
|
||||
!ISDIGIT(*p) &&
|
||||
!ISPUNCT(*p) &&
|
||||
!ISSPACE(*p) &&
|
||||
*p != '|' && *p != '_')
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ConfigFile::setInt(const wchar_t *name, int val)
|
||||
{
|
||||
INCRITICALSECTION(cs);
|
||||
if (name == NULL) return ;
|
||||
if (!verifyName(name))
|
||||
{
|
||||
DebugStringW(L"illegal name given\n");
|
||||
//__asm { int 3 };
|
||||
return ;
|
||||
}
|
||||
makePair(name, StringPrintfW(val));
|
||||
}
|
||||
|
||||
int ConfigFile::getInt(const wchar_t *name, int def_val)
|
||||
{
|
||||
INCRITICALSECTION(cs);
|
||||
if (name == NULL) return def_val;
|
||||
StringPair *p = getPair(name);
|
||||
if (p == NULL) return def_val;
|
||||
return WTOI(p->b.getValue());
|
||||
}
|
||||
|
||||
void ConfigFile::setString(const wchar_t *name, const wchar_t *str)
|
||||
{
|
||||
INCRITICALSECTION(cs);
|
||||
if (name == NULL) return ;
|
||||
if (!verifyName(name))
|
||||
{
|
||||
DebugStringW(L"illegal name given\n");
|
||||
return ;
|
||||
}
|
||||
if (str == NULL)
|
||||
{
|
||||
StringPair *p = getPair(name);
|
||||
if (p != NULL)
|
||||
{
|
||||
strings.delItem(p);
|
||||
delete p;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
makePair(name, str);
|
||||
}
|
||||
|
||||
int ConfigFile::getString(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *def_str)
|
||||
{
|
||||
INCRITICALSECTION(cs);
|
||||
if (name == NULL || buf == NULL) return -1;
|
||||
if (def_str == NULL)
|
||||
def_str = L"";
|
||||
StringPair *p = getPair(name);
|
||||
if (p == NULL)
|
||||
WCSCPYN(buf, def_str, buf_len);
|
||||
else
|
||||
WCSCPYN(buf, p->b.getValueSafe(), buf_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ConfigFile::getStringLen(const wchar_t *name)
|
||||
{
|
||||
INCRITICALSECTION(cs);
|
||||
if (name == NULL) return -1;
|
||||
StringPair *p = getPair(name);
|
||||
if (p == NULL) return -1;
|
||||
return wcslen(p->b.getValue());
|
||||
}
|
43
Src/Wasabi/api/config/config.h
Normal file
43
Src/Wasabi/api/config/config.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#include <bfc/string/bfcstring.h>
|
||||
#include <bfc/pair.h>
|
||||
#include <bfc/critsec.h>
|
||||
#include <bfc/string/StringW.h>
|
||||
|
||||
class StringPair : public Pair<StringW, StringW>
|
||||
{
|
||||
public:
|
||||
StringPair(StringW &_a, const wchar_t *_b)
|
||||
{
|
||||
b=_b;
|
||||
a.swap(_a);
|
||||
}
|
||||
};
|
||||
|
||||
class ConfigFile
|
||||
{
|
||||
public:
|
||||
ConfigFile(const wchar_t *section, const wchar_t *name);
|
||||
~ConfigFile();
|
||||
|
||||
static void initialize();
|
||||
|
||||
void setInt(const wchar_t *name, int val);
|
||||
int getInt(const wchar_t *name, int default_val);
|
||||
|
||||
void setString(const wchar_t *name, const wchar_t *str);
|
||||
int getString(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
|
||||
int getStringLen(const wchar_t *name);
|
||||
|
||||
private:
|
||||
StringW sectionname;
|
||||
StringW prettyname;
|
||||
StringPair *getPair(const wchar_t *name);
|
||||
StringPair *makePair(const wchar_t *name, const wchar_t *value);
|
||||
CriticalSection cs;
|
||||
};
|
||||
|
||||
#endif
|
95
Src/Wasabi/api/config/configapi.cpp
Normal file
95
Src/Wasabi/api/config/configapi.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include "precomp.h"
|
||||
#include "configapi.h"
|
||||
#include "../../studio/config.h"
|
||||
|
||||
#include "../../studio/cfglist.h"
|
||||
|
||||
config_api *configApi = NULL;
|
||||
|
||||
static CfgList cfglist;
|
||||
|
||||
void ConfigApi::config_registerCfgItem(CfgItem *cfgitem) {
|
||||
cfglist.addItem(cfgitem);
|
||||
}
|
||||
|
||||
void ConfigApi::config_deregisterCfgItem(CfgItem *cfgitem) {
|
||||
cfglist.delItem(cfgitem);
|
||||
}
|
||||
|
||||
int ConfigApi::config_getNumCfgItems() {
|
||||
return cfglist.getNumItems();
|
||||
}
|
||||
|
||||
CfgItem *ConfigApi::config_enumCfgItem(int n) {
|
||||
return cfglist.enumItem(n);
|
||||
}
|
||||
|
||||
CfgItem *ConfigApi::config_getCfgItemByGuid(GUID g) {
|
||||
return NULL;//cfglist.getByGuid(g);
|
||||
}
|
||||
|
||||
void ConfigApi::setIntPrivate(const char *name, int val) {
|
||||
//config->setInt(name, val);
|
||||
}
|
||||
|
||||
int ConfigApi::getIntPrivate(const char *name, int def_val) {
|
||||
/* int ret = config->getInt(name, def_val);
|
||||
return ret;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConfigApi::setIntArrayPrivate(const char *name, const int *val, int nval) {
|
||||
/*if (nval > 256) return;
|
||||
char buf[12*256]="";
|
||||
for (int i = 0; i < nval; i++) {
|
||||
STRCAT(buf, StringPrintf("%d", val[i]));
|
||||
if (i != nval-1) STRCAT(buf, ",");
|
||||
}
|
||||
config->setString(name, buf);*/
|
||||
}
|
||||
|
||||
int ConfigApi::getIntArrayPrivate(const char *name, int *val, int nval) {
|
||||
/* char buf[12*256]="";
|
||||
config->getString(name, buf, sizeof(buf), "");
|
||||
PathParser pp(buf, ",");
|
||||
if (pp.getNumStrings() != nval) return 0;
|
||||
for (int i = 0; i < nval; i++) {
|
||||
*val = ATOI(pp.enumString(i));
|
||||
val ++;
|
||||
}
|
||||
return 1;*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ConfigApi::setStringPrivate(const char *name, const char *str) {
|
||||
//config->setString(name, str);
|
||||
}
|
||||
|
||||
int ConfigApi::getStringPrivate(const char *name, char *buf, int buf_len, const char *default_str) {
|
||||
/* int ret = config->getString(name, buf, buf_len, default_str);
|
||||
return ret;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigApi::getStringPrivateLen(const char *name) {
|
||||
//return config->getStringLen(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConfigApi::setIntPublic(const char *name, int val) {
|
||||
//public_config->setInt(name, val);
|
||||
}
|
||||
|
||||
int ConfigApi::getIntPublic(const char *name, int def_val) {
|
||||
//return public_config->getInt(name, def_val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ConfigApi::setStringPublic(const char *name, const char *str) {
|
||||
// public_config->setString(name, str);
|
||||
}
|
||||
int ConfigApi::getStringPublic(const char *name, char *buf, int buf_len, const char *default_str) {
|
||||
// return public_config->getString(name, buf, buf_len, default_str);
|
||||
return 0;
|
||||
}
|
||||
|
32
Src/Wasabi/api/config/configapi.h
Normal file
32
Src/Wasabi/api/config/configapi.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef __CONFIG_API_H
|
||||
#define __CONFIG_API_H
|
||||
|
||||
#include "../../bfc/api/api_configi.h"
|
||||
|
||||
class ConfigApi : public config_apiI {
|
||||
public:
|
||||
ConfigApi() {}
|
||||
virtual ~ConfigApi() {}
|
||||
|
||||
virtual void config_registerCfgItem(CfgItem *cfgitem);
|
||||
virtual void config_deregisterCfgItem(CfgItem *cfgitem);
|
||||
virtual int config_getNumCfgItems();
|
||||
virtual CfgItem *config_enumCfgItem(int n);
|
||||
virtual CfgItem *config_getCfgItemByGuid(GUID g);
|
||||
virtual void setIntPrivate(const wchar_t *name, int val);
|
||||
virtual int getIntPrivate(const wchar_t *name, int def_val);
|
||||
virtual void setIntArrayPrivate(const wchar_t *name, const int *val, int nval);
|
||||
virtual int getIntArrayPrivate(const wchar_t *name, int *val, int nval);
|
||||
virtual void setStringPrivate(const wchar_t *name, const wchar_t *str);
|
||||
virtual int getStringPrivate(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
virtual int getStringPrivateLen(const wchar_t *name);
|
||||
virtual void setIntPublic(const wchar_t *name, int val);
|
||||
virtual int getIntPublic(const wchar_t *name, int def_val);
|
||||
virtual void setStringPublic(const wchar_t *name, const wchar_t *str);
|
||||
virtual int getStringPublic(const wchar_t *name, wchar_t *buf, int buf_len, const wchar_t *default_str);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
#endif
|
576
Src/Wasabi/api/config/filetypes.cpp
Normal file
576
Src/Wasabi/api/config/filetypes.cpp
Normal file
|
@ -0,0 +1,576 @@
|
|||
#include "precomp.h"
|
||||
#include "filetypes.h"
|
||||
#include "api.h"
|
||||
#include "main.h"
|
||||
#include "core.h"
|
||||
|
||||
#include <bfc/attribs/attribs.h>
|
||||
#include <bfc/attribs/attrcb.h>
|
||||
|
||||
#include "../common/locales.h"
|
||||
#include "../bfc/paramparser.h"
|
||||
|
||||
// {DB26AA7F-0CF4-4e48-8AC8-49F9B9855A98}
|
||||
static const GUID winampa_guid =
|
||||
{ 0xdb26aa7f, 0xcf4, 0x4e48, { 0x8a, 0xc8, 0x49, 0xf9, 0xb9, 0x85, 0x5a, 0x98 } };
|
||||
|
||||
class Filetypes;
|
||||
|
||||
class ExtensionAttrCallback : public AttrCallback {
|
||||
public:
|
||||
ExtensionAttrCallback(const char *extname, Filetypes *ft) : ext(extname), filetypes(ft) {}
|
||||
virtual void onValueChange(Attribute *attr) {
|
||||
Filetypes::registerExtension(ext, attr->getValueAsInt());
|
||||
api->cmd_sendCommand(winampa_guid,"extchange",0,0,attr,sizeof(attr)); // CT> notifies winampa.wac of the change
|
||||
// (dunno if there is a better method)
|
||||
filetypes->updateKeepers();
|
||||
}
|
||||
private:
|
||||
String ext;
|
||||
Filetypes *filetypes;
|
||||
};
|
||||
|
||||
class KeepersCB : public AttrCallback {
|
||||
public:
|
||||
KeepersCB(CfgItemI *_par) : par(_par) { }
|
||||
virtual void onValueChange(Attribute *attr) {
|
||||
//CT> This is REAL SLOW, for each attribute modified, you reregister them all, this needs to have
|
||||
// an old list and just register/unregister what's new
|
||||
char bufero[WA_MAX_PATH]="";
|
||||
char data[WA_MAX_PATH]="";
|
||||
attr->getData(bufero, WA_MAX_PATH-1);
|
||||
ParamParser pp(bufero);
|
||||
const char *ext=api->core_getSupportedExtensions();
|
||||
const char *p=ext;
|
||||
while(*p!=0 && *(p+1)!=0) {
|
||||
if(*p) {
|
||||
int v = !!pp.hasString(p);
|
||||
int r = par->cfgitem_getData(StringPrintf("extension/%s", p), data, WA_MAX_PATH-1);
|
||||
if (r == 0 || (!!ATOI(data) != v)) {
|
||||
par->cfgitem_setData(StringPrintf("extension/%s", p), StringPrintf(v));
|
||||
}
|
||||
}
|
||||
while(*p!=0) p++;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
private:
|
||||
CfgItemI *par;
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
static void DCM_cb(int v) {
|
||||
if (v) {
|
||||
HKEY mp3Key;
|
||||
char programname[MAX_PATH];
|
||||
GetModuleFileName(Main::gethInstance(),programname,sizeof(programname));
|
||||
if (RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Play",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Play in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,(unsigned char*)str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Play\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
StringPrintf mstr("\"%s\" \"%%1\"", programname);
|
||||
const char *blah = mstr;
|
||||
const unsigned char *microsoft_sucks_ass = (const unsigned char*)blah;
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,microsoft_sucks_ass,mstr.len() + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Enqueue",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Enqueue in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,(unsigned char*)str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Enqueue\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
StringPrintf mstr("\"%s\" /ADD \"%%1\"", programname);
|
||||
const char *blah = mstr;
|
||||
const unsigned char *microsoft_sucks_ass = (const unsigned char*)blah;
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,microsoft_sucks_ass,mstr.len() + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
} else {
|
||||
Filetypes::myRegDeleteKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Play");
|
||||
Filetypes::myRegDeleteKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Directory\\shell\\Winamp3.Enqueue");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// {C30C97E6-77E6-4da4-9F4F-C7F848F8F641}
|
||||
const GUID filetypes_guid =
|
||||
{ 0xc30c97e6, 0x77e6, 0x4da4, { 0x9f, 0x4f, 0xc7, 0xf8, 0x48, 0xf8, 0xf6, 0x41 } };
|
||||
|
||||
Filetypes::Filetypes() : CfgItemI("Filetypes", filetypes_guid) { }
|
||||
|
||||
void Filetypes::registerAttributes() {
|
||||
const char *ext=api->core_getSupportedExtensions();
|
||||
if (ext == NULL) return; //BU
|
||||
|
||||
_bool *wantExtensions;
|
||||
registerAttribute(wantExtensions = new _bool("Register associations on Winamp startup", TRUE));
|
||||
|
||||
const char *p=ext;
|
||||
while(*p!=0 && *(p+1)!=0) {
|
||||
if(*p) {
|
||||
_bool *extenabled;
|
||||
registerAttribute(extenabled = new _bool(StringPrintf("extension/%s", p), FALSE), new ExtensionAttrCallback(p, this));
|
||||
if (*wantExtensions) registerExtension(p, *extenabled);
|
||||
} while(*p!=0) p++;
|
||||
p++;
|
||||
}
|
||||
|
||||
registerAttribute(new _string("keepers"), new KeepersCB(this));
|
||||
|
||||
#ifdef WIN32
|
||||
registerAttribute(new _bool("Directory context menus", TRUE), new int_attrCB(DCM_cb));
|
||||
#endif
|
||||
|
||||
// Always steal the ".wal" extension.
|
||||
CfgItem *cift=WASABI_API_CONFIG->config_getCfgItemByGuid(filetypes_guid);
|
||||
if (cift) {
|
||||
cift->setDataAsInt("extension/wal",1);
|
||||
}
|
||||
|
||||
updateKeepers();
|
||||
}
|
||||
|
||||
void Filetypes::updateKeepers() {
|
||||
static int reentry=0;
|
||||
if (reentry) return;
|
||||
const char *ext=api->core_getSupportedExtensions();
|
||||
if (ext == NULL) return; //BU
|
||||
|
||||
reentry = 1;
|
||||
const char *p=ext;
|
||||
String kstr;
|
||||
while(*p!=0 && *(p+1)!=0) {
|
||||
if(*p) {
|
||||
_bool *extenabled = static_cast<_bool *>(getAttributeByName(StringPrintf("extension/%s", p)));
|
||||
if (*extenabled) {
|
||||
if (!kstr.isempty()) kstr += ";";
|
||||
kstr += p;
|
||||
}
|
||||
} while(*p!=0) p++;
|
||||
p++;
|
||||
}
|
||||
_string *k = static_cast<_string *>(getAttributeByName("keepers"));
|
||||
k->setValue(kstr);
|
||||
reentry = 0;
|
||||
}
|
||||
|
||||
LONG Filetypes::myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey)
|
||||
{
|
||||
#ifdef WIN32
|
||||
HKEY key;
|
||||
int retval=RegOpenKey(thiskey,lpSubKey,&key);
|
||||
if (retval==ERROR_SUCCESS)
|
||||
{
|
||||
char buffer[1024];
|
||||
while (RegEnumKey(key,0,buffer,1024)==ERROR_SUCCESS)
|
||||
if ((retval=myRegDeleteKeyEx(key,buffer)) != ERROR_SUCCESS) break;
|
||||
RegCloseKey(key);
|
||||
retval=RegDeleteKey(thiskey,lpSubKey);
|
||||
}
|
||||
return retval;
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::myRegDeleteKeyEx\n" );
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int Filetypes::isRegistered(const char *ext) {
|
||||
char b[256];
|
||||
int rval=0;
|
||||
unsigned long vt,s=sizeof(b);
|
||||
HKEY key;
|
||||
SPRINTF(b,".%s",ext);
|
||||
#ifdef WIN32
|
||||
if (RegOpenKey(HKEY_CLASSES_ROOT,b,&key) != ERROR_SUCCESS) return 0;
|
||||
if (RegQueryValueEx(key,NULL,0,&vt,b,&s) == ERROR_SUCCESS) {
|
||||
if (vt != REG_SZ || (strcmp(b,"Winamp3.File") && strcmp(b,"Winamp3.PlayList") && strcmp(b,"Winamp3.SkinZip"))) rval=0;
|
||||
else rval=1;
|
||||
} else rval=0;
|
||||
RegCloseKey(key);
|
||||
#else
|
||||
DebugString( "portme -- FileTypes::isRegistered\n" );
|
||||
#endif
|
||||
return rval;
|
||||
}
|
||||
|
||||
void Filetypes::regmimetype(const char *mtype, const char *programname, const char *ext, int nsonly) {
|
||||
#ifdef WIN32
|
||||
HKEY mp3Key;
|
||||
if (!nsonly) {
|
||||
char s[MAX_PATH];
|
||||
// Changed these to create rather than just open the mimetypes in the database.
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,ext,&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key,"Content Type",0,REG_SZ,mtype,STRLEN(mtype) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
wsprintf(s,"MIME\\Database\\Content Type\\%s",mtype);
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,s,&mp3Key) == ERROR_SUCCESS) {
|
||||
RegDeleteValue(mp3Key,"CLSID");
|
||||
RegSetValueEx(mp3Key,"Extension",0,REG_SZ,ext,strlen(ext) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
}
|
||||
if (RegOpenKey(HKEY_CURRENT_USER,"Software\\Netscape\\Netscape Navigator\\Viewers",&mp3Key) == ERROR_SUCCESS) {
|
||||
int x;
|
||||
RegSetValueEx(mp3Key, mtype,0,REG_SZ,programname,strlen(programname) + 1);
|
||||
for (x = 0; x < 999; x ++) {
|
||||
char st[100];
|
||||
DWORD vt;
|
||||
DWORD s=128;
|
||||
char b[128];
|
||||
wsprintf(st,"TYPE%d",x);
|
||||
if (RegQueryValueEx(mp3Key,st,0,&vt,b,&s) == ERROR_SUCCESS) {
|
||||
if (!strcmp(b,mtype)) break;
|
||||
} else {
|
||||
RegSetValueEx(mp3Key,st,0,REG_SZ,mtype,strlen(mtype)+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::regmimetype\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Filetypes::registerExtension(const char *ext, int reg) {
|
||||
#ifdef WIN32
|
||||
createWinampTypes();
|
||||
|
||||
char b[128];
|
||||
HKEY mp3Key;
|
||||
char *which_str="Winamp3.File";
|
||||
|
||||
if (!_stricmp(ext,"m3u") || !_stricmp(ext,"pls")) which_str="Winamp3.PlayList";
|
||||
if (!_stricmp(ext,"wsz") || !_stricmp(ext,"wpz") || !_stricmp(ext,"wal"))
|
||||
which_str="Winamp3.SkinZip";
|
||||
wsprintf(b,".%s",ext);
|
||||
if (reg && !_stricmp(ext,"pls")) {
|
||||
char programname[MAX_PATH];
|
||||
GetModuleFileName(Main::gethInstance(),programname,sizeof(programname));
|
||||
regmimetype("audio/x-scpls", programname,".pls",1);
|
||||
regmimetype("audio/scpls", programname,".pls",1);
|
||||
}
|
||||
if (reg && !_stricmp(ext,"wma")) {
|
||||
char programname[MAX_PATH];
|
||||
GetModuleFileName(Main::gethInstance(),programname,sizeof(programname));
|
||||
regmimetype("audio/x-ms-wma", programname,".wma",1);
|
||||
regmimetype("application/x-msdownload", programname,".wma",1);
|
||||
}
|
||||
if (reg && !_stricmp(ext,"m3u")) {
|
||||
char programname[MAX_PATH];
|
||||
GetModuleFileName(Main::gethInstance(),programname,sizeof(programname));
|
||||
regmimetype("audio/x-mpegurl", programname,".m3u",1);
|
||||
regmimetype("audio/mpegurl", programname,".m3u",1);
|
||||
}
|
||||
if (reg && !_stricmp(ext,"mp3")) {
|
||||
char programname[MAX_PATH];
|
||||
GetModuleFileName(Main::gethInstance(),programname,sizeof(programname));
|
||||
regmimetype("audio/x-mpeg", programname,".mp3",1);
|
||||
regmimetype("audio/x-mp3", programname,".mp3",1);
|
||||
regmimetype("audio/x-mpg", programname,".mp3",1);
|
||||
regmimetype("audio/mp3", programname,".mp3",1);
|
||||
regmimetype("audio/mpg", programname,".mp3",1);
|
||||
regmimetype("audio/mpeg", programname,".mp3",1);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,b,&mp3Key) == ERROR_SUCCESS) {
|
||||
if (reg) {
|
||||
unsigned long s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,NULL,0,NULL,b,&s) == ERROR_SUCCESS) {
|
||||
if (strcmp(b,which_str)) {
|
||||
RegSetValueEx(mp3Key,"Winamp_Back",0,REG_SZ,b,strlen(b)+1);
|
||||
RegSetValueEx(mp3Key,NULL,0,REG_SZ,which_str,strlen(which_str)+1);
|
||||
}
|
||||
} else RegSetValueEx(mp3Key,NULL,0,REG_SZ,which_str,strlen(which_str)+1);
|
||||
} else {
|
||||
unsigned long s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,NULL,0,NULL,b,&s) == ERROR_SUCCESS) {
|
||||
if (!strcmp(b,which_str)) {
|
||||
s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,"Winamp_Back",0,NULL,b,&s) == ERROR_SUCCESS) {
|
||||
if (RegSetValueEx(mp3Key, NULL,0,REG_SZ,b,strlen(b)+1) == ERROR_SUCCESS)
|
||||
RegDeleteValue(mp3Key,"Winamp_Back");
|
||||
} else {
|
||||
RegDeleteValue(mp3Key,NULL);
|
||||
RegCloseKey(mp3Key);
|
||||
mp3Key=NULL;
|
||||
wsprintf(b,".%s",ext);
|
||||
myRegDeleteKeyEx(HKEY_CLASSES_ROOT,b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mp3Key) RegCloseKey(mp3Key);
|
||||
}
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::registerExtensions\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Filetypes::createWinampTypes() {
|
||||
#ifdef WIN32
|
||||
HKEY mp3Key;
|
||||
char programname[MAX_PATH];
|
||||
char str[MAX_PATH+32];
|
||||
char buf[128]="Winamp3.File";
|
||||
char buf2[128]="Winamp3.PlayList";
|
||||
char buf3[128]="Winamp3.SkinZip";
|
||||
if (!GetModuleFileName(Main::gethInstance(),programname,sizeof(programname))) return;
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File",&mp3Key) == ERROR_SUCCESS) {
|
||||
strcpy(str,"Winamp media file");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\DefaultIcon",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"%s,%d",programname,whichicon);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell",&mp3Key) == ERROR_SUCCESS) {
|
||||
if (addtolist)
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"Enqueue",8);
|
||||
else
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"Play",5);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\Play",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Play in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\Play\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\open",&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"",1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\open\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\Enqueue",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Enqueue in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\Enqueue\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" /ADD \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\ListBookmark",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("Add to Winamp's &Bookmark list");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.File\\shell\\ListBookmark\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" /BOOKMARK \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.Playlist",&mp3Key) == ERROR_SUCCESS) {
|
||||
strcpy(str,"Winamp playlist file");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
str[0]=0;
|
||||
str[1]=0;
|
||||
str[2]=1;
|
||||
str[3]=0;
|
||||
RegSetValueEx(mp3Key, "EditFlags",0,REG_BINARY,str,4);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\DefaultIcon",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"%s,%d",programname,whichicon2);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell",&mp3Key) == ERROR_SUCCESS) {
|
||||
if (addtolist)
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"Enqueue",8);
|
||||
else
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"Play",5);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\Play",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Play in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\Play\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\open",&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"",1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\open\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\Enqueue",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("&Enqueue in Winamp");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\Enqueue\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" /ADD \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\ListBookmark",&mp3Key) == ERROR_SUCCESS) {
|
||||
const char *str=_("Add to Winamp's &Bookmark list");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.PlayList\\shell\\ListBookmark\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" /BOOKMARK \"%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip",&mp3Key) == ERROR_SUCCESS) {
|
||||
strcpy(str,"Winamp3 skin file");
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
str[0]=0;
|
||||
str[1]=0;
|
||||
str[2]=1;
|
||||
str[3]=0;
|
||||
RegSetValueEx(mp3Key, "EditFlags",0,REG_BINARY,str,4);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\DefaultIcon",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"%s,%d",programname,whichicon);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str)+1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\shell",&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"Install and switch to",8);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\shell\\install",&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"",1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\shell\\install\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"/installskin=%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\shell\\open",&mp3Key) == ERROR_SUCCESS) {
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,"",1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
if (RegCreateKey(HKEY_CLASSES_ROOT,"Winamp3.SkinZip\\shell\\open\\command",&mp3Key) == ERROR_SUCCESS) {
|
||||
wsprintf(str,"\"%s\" \"/installskin=%%1\"",programname);
|
||||
RegSetValueEx(mp3Key, NULL,0,REG_SZ,str,strlen(str) + 1);
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
|
||||
// Register the mimetypes to act like .wal files?
|
||||
|
||||
// regmimetype("interface/x-winamp-skin", programname,".wsz",0);
|
||||
regmimetype("interface/x-winamp-skin", programname,".wal",0);
|
||||
// regmimetype("interface/x-winamp3-skin", programname,".wsz",0);
|
||||
regmimetype("interface/x-winamp3-skin", programname,".wal",0);
|
||||
// regmimetype("application/x-winamp-plugin", programname,"wpz",0);
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::createWinampTypes\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
int Filetypes::isCdPlayer() {
|
||||
int r=0;
|
||||
#ifdef WIN32
|
||||
unsigned long s;
|
||||
HKEY mp3Key;
|
||||
char buf[MAX_PATH],buf2[MAX_PATH]="\"";
|
||||
if (!GetModuleFileName(Main::gethInstance(),buf2+1,sizeof(buf2)-8)) return 0;
|
||||
if (RegOpenKey(HKEY_CLASSES_ROOT,"AudioCD\\shell\\play\\command",&mp3Key) != ERROR_SUCCESS) return 0;
|
||||
strcat(buf2,"\" /CDA:%1");
|
||||
s=sizeof(buf);
|
||||
if (RegQueryValueEx(mp3Key,NULL,0,NULL,buf,&s) == ERROR_SUCCESS)
|
||||
{
|
||||
if (!lstrcmpi(buf,buf2)) r=1;
|
||||
}
|
||||
RegCloseKey(mp3Key);
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::isCdPlayer\n" );
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
void Filetypes::registerCdPlayer(int reg) {
|
||||
#ifdef WIN32
|
||||
char b[MAX_PATH];
|
||||
char buf2[MAX_PATH]="\"";
|
||||
HKEY mp3Key;
|
||||
if (!GetModuleFileName(Main::gethInstance(),buf2+1,sizeof(buf2)-8)) return;
|
||||
strcat(buf2,"\" /CDA:%1");
|
||||
if (RegOpenKey(HKEY_CLASSES_ROOT,"AudioCD\\shell\\play\\command",&mp3Key) == ERROR_SUCCESS)
|
||||
{
|
||||
if (reg)
|
||||
{
|
||||
unsigned long s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,NULL,0,NULL,b,&s) == ERROR_SUCCESS)
|
||||
{
|
||||
if (_stricmp(b,buf2))
|
||||
{
|
||||
char buf3[MAX_PATH];
|
||||
unsigned long st=sizeof(buf3);
|
||||
if (RegQueryValueEx(mp3Key,"Winamp_Back",0,NULL,buf3,&st) != ERROR_SUCCESS ||
|
||||
_stricmp(buf3,b))
|
||||
{
|
||||
RegSetValueEx(mp3Key,"Winamp_Back",0,REG_SZ,b,strlen(b)+1);
|
||||
}
|
||||
RegSetValueEx(mp3Key,NULL,0,REG_SZ,buf2,strlen(buf2)+1);
|
||||
}
|
||||
} else RegSetValueEx(mp3Key,NULL,0,REG_SZ,buf2,strlen(buf2)+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,NULL,0,NULL,b,&s) == ERROR_SUCCESS)
|
||||
{
|
||||
if (!strcmp(b,buf2))
|
||||
{
|
||||
s=sizeof(b);
|
||||
if (RegQueryValueEx(mp3Key,"Winamp_Back",0,NULL,b,&s) == ERROR_SUCCESS)
|
||||
{
|
||||
if (!_stricmp(b,buf2)) b[0]=0;
|
||||
if (RegSetValueEx(mp3Key, NULL,0,REG_SZ,b,strlen(b)+1) == ERROR_SUCCESS)
|
||||
RegDeleteValue(mp3Key,"Winamp_Back");
|
||||
}
|
||||
else
|
||||
{
|
||||
buf2[0]=0;
|
||||
RegSetValueEx(mp3Key,NULL,0,REG_SZ,buf2,strlen(buf2)+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RegCloseKey(mp3Key);
|
||||
}
|
||||
#else
|
||||
DebugString( "portme -- Filetypes::isCdPlayer\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
int Filetypes::whichicon=1;
|
||||
int Filetypes::whichicon2=1;
|
||||
int Filetypes::addtolist=0;
|
46
Src/Wasabi/api/config/filetypes.h
Normal file
46
Src/Wasabi/api/config/filetypes.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef _FILETYPES_H
|
||||
#define _FILETYPES_H
|
||||
|
||||
#include <api/config/items/cfgitemi.h>
|
||||
|
||||
#define FILETYPES_PARENT CfgItemI
|
||||
class Filetypes : public FILETYPES_PARENT {
|
||||
public:
|
||||
Filetypes();
|
||||
void registerAttributes();
|
||||
|
||||
static int isRegistered(const char *ext);
|
||||
static void registerExtension(const char *ext, int reg);
|
||||
static int isCdPlayer();
|
||||
static void registerCdPlayer(int reg);
|
||||
|
||||
void updateKeepers();
|
||||
|
||||
private:
|
||||
|
||||
static void createWinampTypes();
|
||||
static void regmimetype(const char *mtype, const char *programname, const char *ext, int nsonly);
|
||||
|
||||
// workaround for (damn) c++ type checking
|
||||
static LONG RegQueryValueEx(HKEY hKey, LPTSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, char *lpData, LPDWORD lpcbData) {
|
||||
#ifdef WIN32
|
||||
return ::RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, (unsigned char *)lpData, lpcbData);
|
||||
#endif
|
||||
}
|
||||
static LONG RegSetValueEx(HKEY hKey, LPCTSTR lpValueName, DWORD Reserved, DWORD dwType, char *lpData, DWORD cbData) {
|
||||
#ifdef WIN32
|
||||
return ::RegSetValueEx(hKey, lpValueName, Reserved, dwType, (const unsigned char *)lpData, cbData);
|
||||
#endif
|
||||
}
|
||||
static LONG RegSetValueEx(HKEY hKey, LPCTSTR lpValueName, DWORD Reserved, DWORD dwType, const char *lpData, DWORD cbData) {
|
||||
#ifdef WIN32
|
||||
return ::RegSetValueEx(hKey, lpValueName, Reserved, dwType, (const unsigned char *)lpData, cbData);
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
static LONG myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey);
|
||||
|
||||
static int whichicon, whichicon2, addtolist;
|
||||
};
|
||||
|
||||
#endif
|
65
Src/Wasabi/api/config/items/attrbool.h
Normal file
65
Src/Wasabi/api/config/items/attrbool.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef _ATTRBOOL_H
|
||||
#define _ATTRBOOL_H
|
||||
|
||||
#include "attribute.h"
|
||||
|
||||
// inherit from this one, or just use it
|
||||
|
||||
/**
|
||||
Boolean configuration attributes have two values, true or false.
|
||||
They can be used like any other config item.
|
||||
|
||||
@short Boolean configuration attribute.
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see _int
|
||||
@see _string
|
||||
@see _float
|
||||
*/
|
||||
class _bool : public Attribute {
|
||||
public:
|
||||
/**
|
||||
Optionally set the name and default value of
|
||||
your configuration attribute during construction.
|
||||
|
||||
@param name Name of the configuration attribute.
|
||||
@param default_val Default value.
|
||||
*/
|
||||
_bool(const wchar_t *name=NULL, int default_val=0) : Attribute(name) {
|
||||
setValueAsInt(!!default_val, true);
|
||||
}
|
||||
|
||||
// convenience operators
|
||||
/**
|
||||
Get the value of the attribute.
|
||||
*/
|
||||
operator bool() { return !!getValueAsInt(); }
|
||||
|
||||
/**
|
||||
Set the value of the attribute.
|
||||
*/
|
||||
bool operator =(int newval) { setValueAsInt(!!newval); return *this; }
|
||||
|
||||
// from Attribute
|
||||
|
||||
/**
|
||||
Get the attribute type. This will return
|
||||
a constant representing the attribute type.
|
||||
|
||||
These constants can be: BOOL, FLOAT, STRING and INT.
|
||||
|
||||
@see AttributeType
|
||||
@ret The attribute type.
|
||||
*/
|
||||
virtual int getAttributeType() { return AttributeType::BOOL; }
|
||||
|
||||
/**
|
||||
Get the configuration group to be used to represent
|
||||
this attribute in the registry.
|
||||
|
||||
@ret Config group to be used.
|
||||
*/
|
||||
virtual const wchar_t *getConfigGroup() { return L"studio.configgroup.bool"; }
|
||||
};
|
||||
|
||||
#endif
|
127
Src/Wasabi/api/config/items/attrcb.h
Normal file
127
Src/Wasabi/api/config/items/attrcb.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
#ifndef _ATTRCB_H
|
||||
#define _ATTRCB_H
|
||||
|
||||
#include "attribute.h"
|
||||
|
||||
/**
|
||||
Enables you to register callbacks on
|
||||
a specific attribute to monitor if it's
|
||||
value has been changed by the user or other.
|
||||
|
||||
This class is not meant to be used on it's own.
|
||||
Please derive from it instead.
|
||||
|
||||
@short Attribute callback
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see Attribute
|
||||
@see int_attrCB
|
||||
@see _int
|
||||
@see _float
|
||||
@see _string
|
||||
@see _bool
|
||||
*/
|
||||
class AttrCallback {
|
||||
public:
|
||||
/**
|
||||
Does nothing.
|
||||
*/
|
||||
virtual ~AttrCallback() {}
|
||||
|
||||
/**
|
||||
Event triggered when the value of the attribute,
|
||||
for which this callback has been registered, changes.
|
||||
|
||||
This is a pure virtual, please override to implement
|
||||
your custom behavior.
|
||||
|
||||
@param attr Attribute for which the value has changed.
|
||||
*/
|
||||
virtual void onValueChange(Attribute *attr)=0;
|
||||
};
|
||||
|
||||
/**
|
||||
Enables you to register callbacks on a specific
|
||||
integer or boolean attribute to monitor if the
|
||||
value has been changed by the user or other.
|
||||
|
||||
@short Integer or Boolean attribute Callback.
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see Attribute
|
||||
@see _int
|
||||
@see _bool
|
||||
*/
|
||||
class int_attrCB : public AttrCallback {
|
||||
typedef void (*fnPtrType)(int);
|
||||
public:
|
||||
/**
|
||||
Upon construction, you must specify which
|
||||
function will be called when the value of
|
||||
the attribute has indeed changed.
|
||||
|
||||
This is done using a pointer to the function.
|
||||
The function must accept one parameter of type
|
||||
int, like so: void myfunc(int val);
|
||||
|
||||
@param _fn Pointer to the function to use on value change.
|
||||
*/
|
||||
int_attrCB(fnPtrType _fn) { fnptr = _fn; }
|
||||
|
||||
/**
|
||||
Event triggered when the value of the attribute,
|
||||
for which this callback has been registered, changes.
|
||||
|
||||
Override this to implement your own behavior.
|
||||
The default is to send the new value of the attribute
|
||||
to a function which you specify upon construction
|
||||
of this object.
|
||||
|
||||
@param attr Attribute for which the value has changed.
|
||||
*/
|
||||
virtual void onValueChange(Attribute *attr) {
|
||||
ASSERT(attr->getAttributeType() == AttributeType::INT ||
|
||||
attr->getAttributeType() == AttributeType::BOOL);
|
||||
(*fnptr)(attr->getValueAsInt());
|
||||
}
|
||||
private:
|
||||
fnPtrType fnptr;
|
||||
};
|
||||
|
||||
class string_attrCB : public AttrCallback {
|
||||
typedef void (*fnPtrType)(const wchar_t *);
|
||||
public:
|
||||
/**
|
||||
Upon construction, you must specify which
|
||||
function will be called when the value of
|
||||
the attribute has indeed changed.
|
||||
|
||||
This is done using a pointer to the function.
|
||||
The function must accept one parameter of type
|
||||
int, like so: void myfunc(const char *val);
|
||||
|
||||
@param _fn Pointer to the function to use on value change.
|
||||
*/
|
||||
string_attrCB(fnPtrType _fn) { fnptr = _fn; }
|
||||
|
||||
/**
|
||||
Event triggered when the value of the attribute,
|
||||
for which this callback has been registered, changes.
|
||||
|
||||
Override this to implement your own behavior.
|
||||
The default is to send the name of the attribute
|
||||
to a function which you specify upon construction
|
||||
of this object.
|
||||
|
||||
@param attr Attribute for which the value has changed.
|
||||
*/
|
||||
virtual void onValueChange(Attribute *attr)
|
||||
{
|
||||
ASSERT(attr->getAttributeType() == AttributeType::STRING);
|
||||
(*fnptr)(attr->getAttributeName());
|
||||
}
|
||||
private:
|
||||
fnPtrType fnptr;
|
||||
};
|
||||
|
||||
#endif
|
52
Src/Wasabi/api/config/items/attrfloat.h
Normal file
52
Src/Wasabi/api/config/items/attrfloat.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef _ATTRFLOAT_H
|
||||
#define _ATTRFLOAT_H
|
||||
|
||||
#include "attribute.h"
|
||||
|
||||
// actually it's a double :)
|
||||
|
||||
class _float : public Attribute {
|
||||
public:
|
||||
/**
|
||||
Optionally set the name and default value of
|
||||
your configuration attribute during construction.
|
||||
|
||||
@param name Name of the configuration attribute.
|
||||
@param default_val Default value.
|
||||
*/
|
||||
_float(const wchar_t *name=NULL, double default_val=0.f) : Attribute(name) {
|
||||
setValueAsDouble(default_val, true);
|
||||
}
|
||||
|
||||
/**
|
||||
Get the attribute type. This will return
|
||||
a constant representing the attribute type.
|
||||
|
||||
These constants can be: BOOL, FLOAT, STRING and INT.
|
||||
|
||||
@see AttributeType
|
||||
@ret The attribute type.
|
||||
*/
|
||||
virtual int getAttributeType() { return AttributeType::FLOAT; }
|
||||
|
||||
/**
|
||||
Get the configuration group to be used to represent
|
||||
this attribute in the registry.
|
||||
|
||||
@ret Config group to be used.
|
||||
*/
|
||||
virtual const wchar_t *getConfigGroup() { return L"studio.configgroup.float"; }
|
||||
|
||||
// convenience operators
|
||||
/**
|
||||
Get the value of the attribute.
|
||||
*/
|
||||
operator double() { return getValueAsDouble(); }
|
||||
|
||||
/**
|
||||
Set the value of the attribute.
|
||||
*/
|
||||
double operator =(double newval) { return setValueAsDouble(newval) ? newval : getValueAsDouble(); }
|
||||
};
|
||||
|
||||
#endif
|
15
Src/Wasabi/api/config/items/attrfn.h
Normal file
15
Src/Wasabi/api/config/items/attrfn.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef _ATTRFN_H
|
||||
#define _ATTRFN_H
|
||||
|
||||
#include "attrstr.h"
|
||||
|
||||
class _filename : public _string {
|
||||
public:
|
||||
_filename(const wchar_t *name, const wchar_t *default_val=L"")
|
||||
: _string(name, default_val) { }
|
||||
|
||||
virtual int getAttributeType() { return AttributeType::FILENAME; }
|
||||
virtual const wchar_t *getConfigGroup() { return L"studio.configgroup.filename"; }
|
||||
};
|
||||
|
||||
#endif
|
129
Src/Wasabi/api/config/items/attrhandler.h
Normal file
129
Src/Wasabi/api/config/items/attrhandler.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
//!## An object to multiplex the callbacks of multiple attributes.
|
||||
#ifndef _ATTRHANDLER_H
|
||||
#define _ATTRHANDLER_H
|
||||
|
||||
// This class is meant to be subclassed. The methods you must provide
|
||||
// are given as pure virtuals. See ExampleAttrib for more details, and
|
||||
// an example subclass that you can copy for your own use.
|
||||
|
||||
#include "attrcb.h"
|
||||
#include "attribs.h"
|
||||
#include <bfc/map.h>
|
||||
|
||||
//
|
||||
// Forward References
|
||||
class WAComponentClient;
|
||||
class Attribute;
|
||||
|
||||
|
||||
//
|
||||
// Class Definition
|
||||
template <class TCallback>
|
||||
class AttrHandler {
|
||||
protected:
|
||||
// Heh, oops. Can't have one AttrCallback handle lots of different attribs, anymore. I fix.
|
||||
class AttrHandlerChild : public AttrCallback {
|
||||
public:
|
||||
AttrHandlerChild(AttrHandler *_parent) : AttrCallback() {
|
||||
ASSERT(_parent != NULL);
|
||||
recursion = 0;
|
||||
callback = NULL;
|
||||
parent = _parent;
|
||||
}
|
||||
|
||||
// Here is where we split out the different value types
|
||||
virtual void onValueChange(Attribute *attr) {
|
||||
if (!recursion) {
|
||||
// protect our programmers from stack overflow, please.
|
||||
recursion = 1;
|
||||
if ((callback != NULL) && (parent != NULL)) {
|
||||
int id;
|
||||
// find the id from the map (friendly)
|
||||
int success = parent->attribmap.getItem(attr,&id);
|
||||
if (success) {
|
||||
// and send it to the proper handling function (poorman's RTTI)
|
||||
switch (attr->getAttributeType()) {
|
||||
case AttributeType::INT:
|
||||
callback->onIntChange(id,*static_cast<_int *>(attr));
|
||||
break;
|
||||
case AttributeType::BOOL:
|
||||
callback->onBoolChange(id, *static_cast<_bool *>(attr));
|
||||
break;
|
||||
case AttributeType::FLOAT:
|
||||
callback->onFloatChange(id, *static_cast<_float *>(attr));
|
||||
break;
|
||||
case AttributeType::STRING:
|
||||
callback->onStringChange(id, *static_cast<_string *>(attr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
recursion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void bindCallbackObj(TCallback *callbackobj) {
|
||||
// Be advised, this may be null. That's okay, we test for it above.
|
||||
callback = callbackobj;
|
||||
}
|
||||
private:
|
||||
int recursion;
|
||||
TCallback *callback;
|
||||
AttrHandler *parent;
|
||||
};
|
||||
|
||||
public:
|
||||
AttrHandler() {
|
||||
component = NULL;
|
||||
callback = NULL;
|
||||
}
|
||||
|
||||
// Call this method to bind your component (in your component's constructor)
|
||||
virtual void bindComponent(WAComponentClient *parentcomponent) {
|
||||
component = parentcomponent;
|
||||
}
|
||||
|
||||
// Call this method to bind your callback object (usually your window in its constructor)
|
||||
virtual void bindCallbackObj(TCallback *callbackobj) {
|
||||
// Bind ourselves.
|
||||
callback = callbackobj;
|
||||
|
||||
// Then go through and rebind any children.
|
||||
int i, num = attrchildren.getNumItems();
|
||||
for (i = 0; i < num; i++) {
|
||||
AttrHandlerChild *child = attrchildren.enumItem(i);
|
||||
child->bindCallbackObj(callback);
|
||||
}
|
||||
}
|
||||
|
||||
// Call this method to register each attribute.
|
||||
virtual void registerAttribute(Attribute *attr, int id) {
|
||||
ASSERTPR(component != NULL, "BIND YOUR COMPONENT before registering Attributes to a Handler.");
|
||||
// register the attrib with a child object as its callback
|
||||
AttrHandlerChild *child = new AttrHandlerChild(this);
|
||||
attrchildren.addItem(child);
|
||||
component->registerAttribute(attr, child);
|
||||
// and save its id mapping
|
||||
attribmap.addItem(attr, id);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Your callback object (probably your primary window class) must implement
|
||||
// its own versions of these methods here. They will be called by the
|
||||
// switch statement below.
|
||||
virtual void onIntChange(int id, int *attr);
|
||||
virtual void onBoolChange(int id, bool *attr);
|
||||
virtual void onFloatChange(int id, double *attr);
|
||||
virtual void onStringChange(int id, const char *attr);
|
||||
#endif
|
||||
|
||||
|
||||
private:
|
||||
friend AttrHandlerChild;
|
||||
TCallback *callback;
|
||||
WAComponentClient *component;
|
||||
Map< Attribute *, int > attribmap;
|
||||
PtrList<AttrHandlerChild> attrchildren;
|
||||
};
|
||||
|
||||
#endif // _ATTRHANDLER_H
|
12
Src/Wasabi/api/config/items/attribs.h
Normal file
12
Src/Wasabi/api/config/items/attribs.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef _ATTRIBS_H
|
||||
#define _ATTRIBS_H
|
||||
|
||||
// a convenience header to get all the attrib types in one whack
|
||||
|
||||
#include "attrbool.h"
|
||||
#include "attrfloat.h"
|
||||
#include "attrint.h"
|
||||
#include "attrstr.h"
|
||||
#include "attrfn.h"
|
||||
|
||||
#endif
|
131
Src/Wasabi/api/config/items/attribute.cpp
Normal file
131
Src/Wasabi/api/config/items/attribute.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "attribute.h"
|
||||
#include <api/config/items/cfgitemi.h>
|
||||
|
||||
|
||||
Attribute::Attribute(const wchar_t *newname, const wchar_t *_desc) :
|
||||
NamedW(newname), desc(_desc), cfgitemi(NULL), private_storage(NULL) { }
|
||||
|
||||
Attribute::~Attribute() {
|
||||
delete private_storage;
|
||||
}
|
||||
|
||||
const wchar_t *Attribute::getAttributeName() {
|
||||
return NamedW::getName();
|
||||
}
|
||||
|
||||
const wchar_t *Attribute::getAttributeDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
int Attribute::getValueAsInt()
|
||||
{
|
||||
wchar_t buf[1024]=L"";
|
||||
getData(buf, 1024);
|
||||
return WTOI(buf);
|
||||
}
|
||||
|
||||
int Attribute::setValueAsInt(int newval, bool def)
|
||||
{
|
||||
return setData(StringPrintfW(newval), def);
|
||||
}
|
||||
|
||||
double Attribute::getValueAsDouble()
|
||||
{
|
||||
wchar_t buf[1024] = {0};
|
||||
getData(buf, 1024);
|
||||
return WTOF(buf);
|
||||
}
|
||||
|
||||
double Attribute::setValueAsDouble(double newval, bool def)
|
||||
{
|
||||
return setData(StringPrintfW(newval), def);
|
||||
}
|
||||
|
||||
int Attribute::getDataLen() {
|
||||
if (private_storage != NULL)
|
||||
return (int)private_storage->len()+1;
|
||||
|
||||
ASSERTPR(WASABI_API_CONFIG != NULL, "getDataLen() before API");
|
||||
int r = WASABI_API_CONFIG->getStringPrivateLen(mkTag());
|
||||
if (r < 0) {
|
||||
r = (int)default_val.len()+1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int Attribute::getData(wchar_t *data, int data_len)
|
||||
{
|
||||
if (data == NULL || data_len < 0)
|
||||
return 0;
|
||||
if (private_storage != NULL)
|
||||
{
|
||||
if (private_storage->isempty())
|
||||
{
|
||||
if (data_len >= 1) {
|
||||
*data = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
WCSCPYN(data, private_storage->getValue(), data_len);
|
||||
return MIN((int)private_storage->len(), data_len);
|
||||
}
|
||||
ASSERTPR(WASABI_API_CONFIG != NULL, "can't get without api");
|
||||
if (WASABI_API_CONFIG == NULL) return 0;
|
||||
int r = WASABI_API_CONFIG->getStringPrivate(mkTag(), data, data_len, default_val.isempty() ? L"" : default_val.getValue());
|
||||
return r;
|
||||
}
|
||||
|
||||
int Attribute::setData(const wchar_t *data, bool def)
|
||||
{
|
||||
if (def) { // setting default value
|
||||
default_val = data;
|
||||
return 1;
|
||||
}
|
||||
ASSERTPR(WASABI_API_CONFIG != NULL, "can't set data before api");
|
||||
if (WASABI_API_CONFIG == NULL) return 0;
|
||||
|
||||
int r = setDataNoCB(data);
|
||||
if (r && cfgitemi != NULL) cfgitemi->cfgitem_onAttribSetValue(this);
|
||||
return r;
|
||||
}
|
||||
|
||||
int Attribute::setDataNoCB(const wchar_t *data)
|
||||
{
|
||||
if (private_storage != NULL) {
|
||||
private_storage->setValue(data);
|
||||
} else {
|
||||
WASABI_API_CONFIG->setStringPrivate(mkTag(), data);
|
||||
}
|
||||
dependent_sendEvent(Attribute::depend_getClassGuid(), Event_DATACHANGE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Attribute::setCfgItem(CfgItemI *item)
|
||||
{
|
||||
delete private_storage; private_storage = NULL;
|
||||
ASSERT(cfgitemi == NULL || item == NULL);
|
||||
cfgitemi = item;
|
||||
if (cfgitemi != NULL)
|
||||
{
|
||||
if (cfgitemi->cfgitem_usePrivateStorage())
|
||||
private_storage = new StringW;
|
||||
}
|
||||
}
|
||||
|
||||
StringW Attribute::mkTag()
|
||||
{
|
||||
StringW ret;
|
||||
if (cfgitemi)
|
||||
{
|
||||
ret = cfgitemi->cfgitem_getPrefix();
|
||||
}
|
||||
ret.cat(getName());
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Attribute::disconnect() {
|
||||
setCfgItem(NULL);
|
||||
}
|
218
Src/Wasabi/api/config/items/attribute.h
Normal file
218
Src/Wasabi/api/config/items/attribute.h
Normal file
|
@ -0,0 +1,218 @@
|
|||
#ifndef _ATTRIBUTE_H
|
||||
#define _ATTRIBUTE_H
|
||||
|
||||
#include <bfc/depend.h>
|
||||
#include <bfc/named.h>
|
||||
#include <bfc/common.h>
|
||||
#include <bfc/string/StringW.h>
|
||||
|
||||
class CfgItemI;
|
||||
|
||||
// lowercase types are reserved for official Nullsoft use
|
||||
// uppercase are 3rd-party defined
|
||||
namespace AttributeType {
|
||||
/**
|
||||
Attribute types.
|
||||
*/
|
||||
enum {
|
||||
NONE = 0,
|
||||
INT = MK3CC('i','n','t'), // attrint.h
|
||||
STRING = MK3CC('s','t','r'), // attrstr.h
|
||||
BOOL = MK4CC('b','o','o','l'), // attrbool.h
|
||||
FLOAT = MK4CC('f','l','o','t'), // attrfloat.h
|
||||
FILENAME = MK2CC('f','n'), // attrfn.h
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Generic configuration attribute.
|
||||
|
||||
Configuration attributes enable you to store
|
||||
uniquely identifiable values that get pushed
|
||||
to a configuration file automatically upon shutdown
|
||||
of any Wasabi application.
|
||||
|
||||
You shouldn't normally use this on
|
||||
it's own, look at the CfgItemI class
|
||||
instead.
|
||||
|
||||
@short Generic configuration attribute.
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see _float
|
||||
@see _int
|
||||
@see _bool
|
||||
@see _string
|
||||
@see CfgItemI
|
||||
*/
|
||||
class NOVTABLE Attribute : public DependentI, private NamedW
|
||||
{
|
||||
public:
|
||||
static const GUID *depend_getClassGuid() {
|
||||
// {5AB601D4-1628-4604-808A-7ED899849BEB}
|
||||
static const GUID ret =
|
||||
{ 0x5ab601d4, 0x1628, 0x4604, { 0x80, 0x8a, 0x7e, 0xd8, 0x99, 0x84, 0x9b, 0xeb } };
|
||||
return &ret;
|
||||
}
|
||||
protected:
|
||||
|
||||
/**
|
||||
Optionally set the name and default value of
|
||||
your configuration attribute during construction.
|
||||
|
||||
@param name Name of the configuration attribute.
|
||||
@param default_val Default value.
|
||||
*/
|
||||
Attribute(const wchar_t *name=NULL, const wchar_t *desc=NULL);
|
||||
|
||||
public:
|
||||
virtual ~Attribute();
|
||||
|
||||
/**
|
||||
Set the name of the configuration
|
||||
attribute.
|
||||
|
||||
@param newname Name of the attribute.
|
||||
*/
|
||||
void setName(const wchar_t *newname);
|
||||
|
||||
/**
|
||||
Get the name of the configuration
|
||||
attribute.
|
||||
|
||||
@ret Name of the attribute.
|
||||
*/
|
||||
const wchar_t *getAttributeName();
|
||||
|
||||
/**
|
||||
Get the attribute's description.
|
||||
|
||||
@ret Attribute's description.
|
||||
*/
|
||||
const wchar_t *getAttributeDesc();
|
||||
|
||||
/**
|
||||
Get the attribute type. Override
|
||||
this for your custom attribute type.
|
||||
|
||||
@ret Attribute type.
|
||||
*/
|
||||
virtual int getAttributeType()=0; // override me
|
||||
|
||||
/**
|
||||
Get the configuration group to be used to represent
|
||||
this attribute in the registry.
|
||||
|
||||
This is only called if the kernel doesn't have a default
|
||||
config group set for your type already.
|
||||
|
||||
@ret Config group to be used.
|
||||
*/
|
||||
virtual const wchar_t *getConfigGroup() { return NULL; } // override me
|
||||
|
||||
/**
|
||||
Get the attribute's value as signed integer.
|
||||
|
||||
@ret Attribute value, as a signed integer.
|
||||
*/
|
||||
int getValueAsInt();
|
||||
|
||||
/**
|
||||
Set the attribute's value with a signed integer while
|
||||
also being able to replace the default value previously
|
||||
set.
|
||||
|
||||
@param newval Attribute's new value.
|
||||
@param def true, replace the current default value; false, leave the default value unchanged;
|
||||
*/
|
||||
int setValueAsInt(int newval, bool def=false);
|
||||
|
||||
/**
|
||||
Get the attribute's value as signed double.
|
||||
|
||||
@ret Attribute value, as a signed double.
|
||||
*/
|
||||
double getValueAsDouble();
|
||||
|
||||
/**
|
||||
Set the attribute's value with a signed double while
|
||||
also being able to replace the default value previously
|
||||
set.
|
||||
|
||||
@param newval Attribute's new value.
|
||||
@param def true, replace the current default value; false, leave the default value unchanged;
|
||||
*/
|
||||
double setValueAsDouble(double newval, bool def=false);
|
||||
|
||||
/**
|
||||
Get the length of the attribute's value (data)
|
||||
in bytes.
|
||||
|
||||
@ret Attribute value (data) length, in bytes.
|
||||
*/
|
||||
int getDataLen();
|
||||
|
||||
/**
|
||||
Get the attribute's raw data.
|
||||
|
||||
This will return the data the attribute is storing
|
||||
in a char buffer you hand to it.
|
||||
|
||||
@ret Attribute value, as a signed double.
|
||||
@param data Pointer to a char buffer.
|
||||
@param data_len The maximum amount of bytes the char buffer can hold.
|
||||
*/
|
||||
int getData(wchar_t *data, int data_len);
|
||||
|
||||
/**
|
||||
Set the attribute's value with a zero terminated string. Also
|
||||
enables you to replace the default value previously
|
||||
set.
|
||||
|
||||
@param newval Attribute's new value.
|
||||
@param def true, replace the current default value; false, leave the default value unchanged;
|
||||
*/
|
||||
int setData(const wchar_t *data, bool def=false);
|
||||
|
||||
void disconnect();
|
||||
|
||||
enum {
|
||||
Event_DATACHANGE=100,
|
||||
};
|
||||
protected:
|
||||
friend class CfgItemI;
|
||||
|
||||
/**
|
||||
Set the attribute's value without causing
|
||||
a callback.
|
||||
|
||||
@ret 1.
|
||||
@param data Attribute's new value.
|
||||
*/
|
||||
int setDataNoCB(const wchar_t *data);
|
||||
|
||||
/**
|
||||
Set the configuration item associated with this
|
||||
attribute.
|
||||
*/
|
||||
void setCfgItem(CfgItemI *item);
|
||||
|
||||
StringW mkTag();
|
||||
|
||||
private:
|
||||
StringW desc;
|
||||
StringW default_val, *private_storage;
|
||||
CfgItemI *cfgitemi;
|
||||
};
|
||||
|
||||
#define ATTR_PERM_READ 1
|
||||
#define ATTR_PERM_WRITE 2
|
||||
|
||||
#define ATTR_PERM_ALL (~0)
|
||||
|
||||
// render hints for getRenderHint
|
||||
enum {
|
||||
ATTR_RENDER_HINT_INT_CHECKMARK
|
||||
};
|
||||
|
||||
#endif
|
65
Src/Wasabi/api/config/items/attrint.h
Normal file
65
Src/Wasabi/api/config/items/attrint.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef _ATTRINT_H
|
||||
#define _ATTRINT_H
|
||||
|
||||
#include "attribute.h"
|
||||
|
||||
// inherit from this one, or just use it
|
||||
/**
|
||||
Boolean configuration attributes have two values, true or false.
|
||||
They can be used like any other config item.
|
||||
|
||||
@short Integer configuration attribute.
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see CfgItemI
|
||||
@see _bool
|
||||
@see _string
|
||||
@see _float
|
||||
*/
|
||||
class _int : public Attribute {
|
||||
public:
|
||||
/**
|
||||
Optionally set the name and default value of
|
||||
your configuration attribute during construction.
|
||||
|
||||
@param name Name of the configuration attribute.
|
||||
@param default_val Default value.
|
||||
*/
|
||||
_int(const wchar_t *name=NULL, int default_val=0) : Attribute(name) {
|
||||
setValueAsInt(default_val, true);
|
||||
}
|
||||
|
||||
// from AttributeI
|
||||
/**
|
||||
Get the attribute type. This will return
|
||||
a constant representing the attribute type.
|
||||
|
||||
These constants can be: BOOL, FLOAT, STRING and INT.
|
||||
|
||||
@see AttributeType
|
||||
@ret The attribute type.
|
||||
*/
|
||||
virtual int getAttributeType() { return AttributeType::INT; }
|
||||
|
||||
/**
|
||||
Get the configuration group to be used to represent
|
||||
this attribute in the registry.
|
||||
|
||||
@ret Config group to be used.
|
||||
*/
|
||||
virtual const wchar_t *getConfigGroup() { return L"studio.configgroup.int"; }
|
||||
// virtual int getPermissions();
|
||||
|
||||
// convenience operators
|
||||
/**
|
||||
Get the value of the attribute.
|
||||
*/
|
||||
operator int() { return getValueAsInt(); }
|
||||
|
||||
/**
|
||||
Set the value of the attribute.
|
||||
*/
|
||||
int operator =(int newval) { return setValueAsInt(newval) ? newval : getValueAsInt(); }
|
||||
};
|
||||
|
||||
#endif
|
14
Src/Wasabi/api/config/items/attrstr.cpp
Normal file
14
Src/Wasabi/api/config/items/attrstr.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <precomp.h>
|
||||
#include "attrstr.h"
|
||||
|
||||
#include <bfc/memblock.h>
|
||||
|
||||
const wchar_t *_string::getValue()
|
||||
{
|
||||
int l = getDataLen();
|
||||
if (l <= 0) return L"";
|
||||
MemBlock<wchar_t> mb(l+2);
|
||||
getData(mb.getMemory(), l+2);
|
||||
returnval = mb;
|
||||
return returnval;
|
||||
}
|
85
Src/Wasabi/api/config/items/attrstr.h
Normal file
85
Src/Wasabi/api/config/items/attrstr.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
#ifndef _ATTRSTR_H
|
||||
#define _ATTRSTR_H
|
||||
|
||||
#include "attribute.h"
|
||||
|
||||
#include <bfc/string/bfcstring.h>
|
||||
#include <bfc/common.h>
|
||||
|
||||
/**
|
||||
String configuration attributes, can have any string value
|
||||
of any length. They can be used like any other config item.
|
||||
|
||||
@short String configuration attribute.
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see _int
|
||||
@see _bool
|
||||
@see _float
|
||||
*/
|
||||
class _string : public Attribute {
|
||||
public:
|
||||
/**
|
||||
Optionally set the name and default value of
|
||||
your configuration attribute during construction.
|
||||
|
||||
@param name
|
||||
@param default_val
|
||||
*/
|
||||
_string(const wchar_t *name=NULL, const wchar_t *default_val=NULL)
|
||||
: Attribute(name) {
|
||||
setData(default_val, true);
|
||||
}
|
||||
|
||||
/**
|
||||
Get the attribute type. This will return
|
||||
a constant representing the attribute type.
|
||||
|
||||
These constants can be: BOOL, FLOAT, STRING and INT.
|
||||
|
||||
@see AttributeType
|
||||
@ret The attribute type.
|
||||
*/
|
||||
virtual int getAttributeType() { return AttributeType::STRING; }
|
||||
|
||||
/**
|
||||
Get the configuration group to be used to represent
|
||||
this attribute in the registry.
|
||||
|
||||
@ret Config group to be used.
|
||||
*/
|
||||
virtual const wchar_t *getConfigGroup() { return L"studio.configgroup.string"; }
|
||||
|
||||
//CUT virtual int getPermissions() { return ATTR_PERM_ALL; }
|
||||
|
||||
/**
|
||||
Get the value of the attribute.
|
||||
|
||||
@ret The value of the attribute
|
||||
*/
|
||||
const wchar_t *getValue();
|
||||
|
||||
/**
|
||||
Set the value of the attribute.
|
||||
|
||||
@param val The value you want to set.
|
||||
@ret 1, success; 0, failure;
|
||||
*/
|
||||
int setValue(const wchar_t *val) { return setData(val); }
|
||||
|
||||
// convenience operators
|
||||
/**
|
||||
Get the value of the attribute.
|
||||
*/
|
||||
operator const wchar_t *() { return getValue(); }
|
||||
|
||||
/**
|
||||
Set the value of the attribute.
|
||||
*/
|
||||
const wchar_t *operator =(const wchar_t *newval) { return setValue(newval) ? newval : getValue(); }
|
||||
|
||||
private:
|
||||
StringW returnval;
|
||||
};
|
||||
|
||||
#endif
|
233
Src/Wasabi/api/config/items/cfgitem.h
Normal file
233
Src/Wasabi/api/config/items/cfgitem.h
Normal file
|
@ -0,0 +1,233 @@
|
|||
#ifndef _CFGITEM_H
|
||||
#define _CFGITEM_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/platform/types.h>
|
||||
#include <bfc/platform/guid.h>
|
||||
#include <bfc/wasabi_std.h>
|
||||
|
||||
class ifc_dependent;
|
||||
class ifc_window;
|
||||
|
||||
/* A CfgItem is a named, possibly unique (if GUID is set) interface to
|
||||
an object with 0 or more named attributes. If offers api_dependent-based callbacks
|
||||
when those attributes change.
|
||||
*/
|
||||
|
||||
// abstract base class presented to the world
|
||||
/**
|
||||
|
||||
|
||||
@short Base Config Item
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see CfgItemI
|
||||
*/
|
||||
class NOVTABLE CfgItem : public Dispatchable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*/
|
||||
static const GUID *depend_getClassGuid() {
|
||||
// {B4BE480E-2005-457c-A445-294F12387E74}
|
||||
static const GUID ret =
|
||||
{ 0xb4be480e, 0x2005, 0x457c, { 0xa4, 0x45, 0x29, 0x4f, 0x12, 0x38, 0x7e, 0x74 } };
|
||||
return &ret;
|
||||
}
|
||||
|
||||
const wchar_t *getName();
|
||||
|
||||
/**
|
||||
Get the GUID
|
||||
*/
|
||||
GUID getGuid();
|
||||
|
||||
/**
|
||||
Get the number of attributes
|
||||
associated with this configuration
|
||||
item.
|
||||
|
||||
@ret Number of attributes for this configuration item.
|
||||
*/
|
||||
int getNumAttributes();
|
||||
|
||||
const wchar_t *enumAttribute(int n);
|
||||
|
||||
// so people can watch you for changes
|
||||
ifc_dependent *getDependencyPtr();
|
||||
|
||||
// return * to your config xml if you want to specify it
|
||||
const wchar_t *getConfigXML();
|
||||
void onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname=NULL);
|
||||
void onCfgGroupDelete(ifc_window *cfggroup);
|
||||
|
||||
// if you have child cfgitems, list them here
|
||||
int getNumChildren();
|
||||
CfgItem *enumChild(int n);
|
||||
GUID getParentGuid();
|
||||
|
||||
void onRegister(); // kernel calls these
|
||||
void onDeregister();
|
||||
|
||||
int getAttributeType(const wchar_t *name);
|
||||
const wchar_t *getAttributeConfigGroup(const wchar_t *name);
|
||||
int getDataLen(const wchar_t *name);
|
||||
int getData(const wchar_t *name, wchar_t *data, int data_len);
|
||||
int setData(const wchar_t *name, const wchar_t *data);
|
||||
|
||||
int getDataAsInt(const wchar_t *name, int def_val=0)
|
||||
{
|
||||
wchar_t buf[256];
|
||||
if (getData(name, buf, sizeof(buf))==-1) return def_val;
|
||||
return WTOI(buf);
|
||||
}
|
||||
void setDataAsInt(const wchar_t *name, int val) {
|
||||
wchar_t buf[256];
|
||||
WCSNPRINTF(buf, 256, L"%d", val); // this uses SPRINTF ON PURPOSE, motherfucker BU
|
||||
setData(name, buf);
|
||||
}
|
||||
|
||||
double getDataAsFloat(const wchar_t *name, double def_val=0) {
|
||||
wchar_t buf[256];
|
||||
if (getData(name, buf, sizeof(buf))==-1) return def_val;
|
||||
return WTOF(buf);
|
||||
}
|
||||
void setDataAsFloat(const wchar_t *name, double val) {
|
||||
wchar_t buf[256];
|
||||
WCSNPRINTF(buf, 256, L"%f", val); // this uses SPRINTF ON PURPOSE, motherfucker BU
|
||||
setData(name, buf);
|
||||
}
|
||||
|
||||
int addAttribute(const wchar_t *name, const wchar_t *defval);
|
||||
int delAttribute(const wchar_t *name);
|
||||
|
||||
enum {
|
||||
Event_ATTRIBUTE_ADDED=100, // ptr is name of attrib
|
||||
Event_ATTRIBUTE_REMOVED=200,// ptr is name of attrib
|
||||
Event_ATTRIBUTE_CHANGED=300, // ptr is name of attrib
|
||||
Event_NAMECHANGE=400,
|
||||
};
|
||||
|
||||
protected:
|
||||
enum {
|
||||
CFGITEM_GETNAME=100,
|
||||
CFGITEM_GETGUID=110,
|
||||
CFGITEM_GETNUMATTRIBUTES=200,
|
||||
CFGITEM_ENUMATTRIBUTE=210,
|
||||
CFGITEM_GETDEPENDENCYPTR=300,
|
||||
CFGITEM_GETNUMCHILDREN=400,
|
||||
CFGITEM_ENUMCHILD=410,
|
||||
CFGITEM_GETPARENTGUID=420,
|
||||
CFGITEM_ONREGISTER=500,
|
||||
CFGITEM_ONDEREGISTER=510,
|
||||
CFGITEM_GETCONFIGXML=600,
|
||||
CFGITEM_ONCFGGROUPCREATE=610,
|
||||
CFGITEM_ONCFGGROUPDELETE=620,
|
||||
CFGITEM_GETATTRIBUTETYPE=700,
|
||||
CFGITEM_GETATTRIBUTECONFIGGROUP=710,
|
||||
CFGITEM_GETDATALEN=800,
|
||||
CFGITEM_GETDATA=810,
|
||||
CFGITEM_SETDATA=820,
|
||||
CFGITEM_ADDATTRIB=830,
|
||||
CFGITEM_DELATTRIB=840,
|
||||
};
|
||||
};
|
||||
|
||||
inline const wchar_t *CfgItem::getName() {
|
||||
return _call(CFGITEM_GETNAME, L"");
|
||||
}
|
||||
|
||||
inline GUID CfgItem::getGuid() {
|
||||
return _call(CFGITEM_GETGUID, INVALID_GUID);
|
||||
}
|
||||
|
||||
inline int CfgItem::getNumAttributes() {
|
||||
return _call(CFGITEM_GETNUMATTRIBUTES, 0);
|
||||
}
|
||||
|
||||
inline const wchar_t *CfgItem::enumAttribute(int n) {
|
||||
return _call(CFGITEM_ENUMATTRIBUTE, (const wchar_t *)NULL, n);
|
||||
}
|
||||
|
||||
inline ifc_dependent *CfgItem::getDependencyPtr() {
|
||||
return _call(CFGITEM_GETDEPENDENCYPTR, (ifc_dependent*)NULL);
|
||||
}
|
||||
|
||||
inline const wchar_t *CfgItem::getConfigXML() {
|
||||
return _call(CFGITEM_GETCONFIGXML, (const wchar_t*)NULL);
|
||||
}
|
||||
|
||||
inline void CfgItem::onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname) {
|
||||
_voidcall(CFGITEM_ONCFGGROUPCREATE, cfggroup, attrname);
|
||||
}
|
||||
|
||||
inline void CfgItem::onCfgGroupDelete(ifc_window *cfggroup) {
|
||||
_voidcall(CFGITEM_ONCFGGROUPDELETE, cfggroup);
|
||||
}
|
||||
|
||||
inline int CfgItem::getNumChildren() {
|
||||
return _call(CFGITEM_GETNUMCHILDREN, 0);
|
||||
}
|
||||
|
||||
inline CfgItem *CfgItem::enumChild(int n) {
|
||||
return _call(CFGITEM_ENUMCHILD, (CfgItem*)NULL, n);
|
||||
}
|
||||
|
||||
inline
|
||||
GUID CfgItem::getParentGuid() {
|
||||
return _call(CFGITEM_GETPARENTGUID, INVALID_GUID);
|
||||
}
|
||||
|
||||
inline void CfgItem::onRegister() { _voidcall(CFGITEM_ONREGISTER); }
|
||||
inline void CfgItem::onDeregister() { _voidcall(CFGITEM_ONDEREGISTER); }
|
||||
|
||||
inline
|
||||
int CfgItem::getAttributeType(const wchar_t *name) {
|
||||
return _call(CFGITEM_GETATTRIBUTETYPE, 0, name);
|
||||
}
|
||||
|
||||
inline
|
||||
const wchar_t *CfgItem::getAttributeConfigGroup(const wchar_t *name) {
|
||||
return _call(CFGITEM_GETATTRIBUTECONFIGGROUP, (const wchar_t *)NULL, name);
|
||||
}
|
||||
|
||||
inline
|
||||
int CfgItem::getDataLen(const wchar_t *name) {
|
||||
return _call(CFGITEM_GETDATALEN, -1, name);
|
||||
}
|
||||
|
||||
inline
|
||||
int CfgItem::getData(const wchar_t *name, wchar_t *data, int data_len) {
|
||||
return _call(CFGITEM_GETDATA, -1, name, data, data_len);
|
||||
}
|
||||
|
||||
inline
|
||||
int CfgItem::setData(const wchar_t *name, const wchar_t *data) {
|
||||
return _call(CFGITEM_SETDATA, -1, name, data);
|
||||
}
|
||||
|
||||
inline
|
||||
int CfgItem::addAttribute(const wchar_t *name, const wchar_t *defval) {
|
||||
return _call(CFGITEM_ADDATTRIB, 0, name, defval);
|
||||
}
|
||||
|
||||
inline
|
||||
int CfgItem::delAttribute(const wchar_t *name) {
|
||||
return _call(CFGITEM_DELATTRIB, 0, name);
|
||||
}
|
||||
|
||||
inline int _intVal(CfgItem *cfgitem, const wchar_t *name, int def_val=0) {
|
||||
if (cfgitem == NULL) return def_val;
|
||||
return cfgitem->getDataAsInt(name, def_val);
|
||||
}
|
||||
|
||||
#define _int_getValue _intVal
|
||||
|
||||
//CUT kill these
|
||||
inline void _int_setValue(CfgItem *cfgitem, const wchar_t *name, int val) {
|
||||
cfgitem->setDataAsInt(name, val);
|
||||
}
|
||||
// CfgItemI is in cfgitemi.h if you need it
|
||||
|
||||
|
||||
#endif
|
274
Src/Wasabi/api/config/items/cfgitemi.cpp
Normal file
274
Src/Wasabi/api/config/items/cfgitemi.cpp
Normal file
|
@ -0,0 +1,274 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "cfgitemi.h"
|
||||
#include <api/config/items/attrcb.h>
|
||||
#include <api/config/items/attribs.h>
|
||||
|
||||
#include <bfc/wasabi_std.h>
|
||||
#include <bfc/memblock.h>
|
||||
|
||||
CfgItemI::CfgItemI(const wchar_t *name, GUID guid)
|
||||
:NamedW(name), myguid(guid), parent_guid(INVALID_GUID) { }
|
||||
|
||||
CfgItemI::~CfgItemI()
|
||||
{
|
||||
deregisterAll();
|
||||
}
|
||||
|
||||
const wchar_t *CfgItemI::cfgitem_getName()
|
||||
{
|
||||
return NamedW::getName();
|
||||
}
|
||||
|
||||
GUID CfgItemI::cfgitem_getGuid()
|
||||
{
|
||||
return myguid;
|
||||
}
|
||||
|
||||
void CfgItemI::cfgitem_setPrefix(const wchar_t *_prefix)
|
||||
{
|
||||
prefix = _prefix;
|
||||
}
|
||||
|
||||
const wchar_t *CfgItemI::cfgitem_getPrefix()
|
||||
{
|
||||
return prefix.c_str();
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_getNumAttributes()
|
||||
{
|
||||
return attributes.getNumItems();
|
||||
}
|
||||
|
||||
const wchar_t *CfgItemI::cfgitem_enumAttribute(int n)
|
||||
{
|
||||
Attribute *attr = attributes[n];
|
||||
if (attr) return attr->getAttributeName();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const wchar_t *CfgItemI::cfgitem_getConfigXML()
|
||||
{
|
||||
return cfgxml.c_str();
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_getNumChildren()
|
||||
{
|
||||
return children.getNumItems();
|
||||
}
|
||||
|
||||
CfgItem *CfgItemI::cfgitem_enumChild(int n)
|
||||
{
|
||||
return children[n];
|
||||
}
|
||||
|
||||
GUID CfgItemI::cfgitem_getParentGuid()
|
||||
{
|
||||
return parent_guid;
|
||||
}
|
||||
|
||||
void CfgItemI::cfgitem_onRegister()
|
||||
{
|
||||
foreach(children)
|
||||
WASABI_API_CONFIG->config_registerCfgItem(children.getfor());
|
||||
endfor
|
||||
}
|
||||
void CfgItemI::cfgitem_onDeregister()
|
||||
{
|
||||
foreach(children)
|
||||
WASABI_API_CONFIG->config_deregisterCfgItem(children.getfor());
|
||||
endfor
|
||||
}
|
||||
|
||||
Attribute *CfgItemI::getAttributeByName(const wchar_t *name)
|
||||
{
|
||||
Attribute *attr;
|
||||
foreach(attributes)
|
||||
attr = attributes.getfor();
|
||||
if (!WCSICMP(name, attr->getAttributeName())) return attr;
|
||||
endfor
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_getAttributeType(const wchar_t *name)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (attr == NULL) return AttributeType::NONE;
|
||||
return attr->getAttributeType();
|
||||
}
|
||||
|
||||
const wchar_t *CfgItemI::cfgitem_getAttributeConfigGroup(const wchar_t *name)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (attr == NULL) return NULL;
|
||||
return attr->getConfigGroup();
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_getDataLen(const wchar_t *name)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (attr == NULL) return -1;
|
||||
return attr->getDataLen();
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_getData(const wchar_t *name, wchar_t *data, int data_len)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (attr == NULL) return -1;
|
||||
return attr->getData(data, data_len);
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_setData(const wchar_t *name, const wchar_t *data)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (attr == NULL) return -1;
|
||||
int ret = attr->setDataNoCB(data);
|
||||
if (ret) cfgitem_onAttribSetValue(attr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_onAttribSetValue(Attribute *attr)
|
||||
{
|
||||
// notify dependency watchers that an attribute changed
|
||||
dependent_sendEvent(CfgItem::depend_getClassGuid(), Event_ATTRIBUTE_CHANGED, 0, (void*)attr->getAttributeName());
|
||||
|
||||
//for (int i = 0; ; i++)
|
||||
//{
|
||||
// AttrCallback *acb;
|
||||
// if (!callbacks.multiGetItem(attr, i, &acb))
|
||||
// break;
|
||||
//
|
||||
// acb->onValueChange(attr);
|
||||
//}
|
||||
auto elements = callbacks.equal_range(attr);
|
||||
for (auto& it = elements.first; it != elements.second; ++it)
|
||||
{
|
||||
AttrCallback* acb = it->second;
|
||||
if (acb)
|
||||
{
|
||||
acb->onValueChange(attr);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CfgItemI::cfgitem_setGUID(GUID guid)
|
||||
{
|
||||
myguid = guid;
|
||||
}
|
||||
|
||||
int CfgItemI::setName(const wchar_t *name)
|
||||
{
|
||||
NamedW::setName(name);
|
||||
// notify dependency watchers that name changed?
|
||||
dependent_sendEvent(CfgItem::depend_getClassGuid(), Event_NAMECHANGE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CfgItemI::registerAttribute(Attribute *attr, AttrCallback *acb)
|
||||
{
|
||||
if (attributes.haveItem(attr)) return 0;
|
||||
int ret = attributes.addItem(attr) != NULL;
|
||||
if (!ret) return ret;
|
||||
|
||||
attr->setCfgItem(this);
|
||||
|
||||
// set optional callback
|
||||
if (acb != NULL)
|
||||
{
|
||||
addCallback(attr, acb);
|
||||
}
|
||||
|
||||
// notify dependency watchers of new attribute
|
||||
dependent_sendEvent(CfgItem::depend_getClassGuid(), Event_ATTRIBUTE_ADDED, 0, (void*)attr->getAttributeName());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CfgItemI::deregisterAttribute(Attribute *attr)
|
||||
{
|
||||
if (!attributes.haveItem(attr)) return 0;
|
||||
int ret = attributes.removeItem(attr);
|
||||
// notify dependency watchers of attribute going away
|
||||
dependent_sendEvent(CfgItem::depend_getClassGuid(), Event_ATTRIBUTE_REMOVED, 0, (void*)attr->getAttributeName());
|
||||
|
||||
// remove callbacks
|
||||
//callbacks.multiDelAllForItem(attr, TRUE);
|
||||
auto elements = callbacks.equal_range(attr);
|
||||
for (auto& it = elements.first; it != elements.second; ++it)
|
||||
{
|
||||
AttrCallback* acb = it->second;
|
||||
if (acb)
|
||||
{
|
||||
delete acb;
|
||||
}
|
||||
}
|
||||
callbacks.erase(attr);
|
||||
|
||||
|
||||
attr->disconnect();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CfgItemI::addCallback(Attribute *attr, AttrCallback *acb)
|
||||
{
|
||||
ASSERT(attr != NULL);
|
||||
ASSERT(acb != NULL);
|
||||
//callbacks.multiAddItem(attr, acb);
|
||||
callbacks.insert({ attr, acb });
|
||||
}
|
||||
|
||||
void CfgItemI::deregisterAll()
|
||||
{
|
||||
foreach(children)
|
||||
children.getfor()->deregisterAll();
|
||||
endfor
|
||||
while (attributes.getNumItems()) deregisterAttribute(attributes[0]);
|
||||
}
|
||||
|
||||
void CfgItemI::addChildItem(CfgItemI *child)
|
||||
{
|
||||
ASSERT(child != NULL);
|
||||
if (!children.haveItem(child))
|
||||
{
|
||||
children.addItem(child);
|
||||
child->setParentGuid(myguid);
|
||||
}
|
||||
}
|
||||
|
||||
void CfgItemI::setCfgXml(const wchar_t *groupname)
|
||||
{
|
||||
cfgxml = groupname;
|
||||
}
|
||||
|
||||
void CfgItemI::setParentGuid(GUID guid)
|
||||
{
|
||||
parent_guid = guid;
|
||||
}
|
||||
|
||||
void *CfgItemI::dependent_getInterface(const GUID *classguid)
|
||||
{
|
||||
HANDLEGETINTERFACE(CfgItem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_addAttribute(const wchar_t *name, const wchar_t *defval)
|
||||
{
|
||||
if (getAttributeByName(name)) return 0;
|
||||
registerAttribute(newattribs.addItem(new _string(name, defval)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CfgItemI::cfgitem_delAttribute(const wchar_t *name)
|
||||
{
|
||||
Attribute *attr = getAttributeByName(name);
|
||||
if (!newattribs.haveItem(attr)) return 0;
|
||||
deregisterAttribute(attr);
|
||||
delete attr;
|
||||
newattribs.removeItem(attr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
158
Src/Wasabi/api/config/items/cfgitemi.h
Normal file
158
Src/Wasabi/api/config/items/cfgitemi.h
Normal file
|
@ -0,0 +1,158 @@
|
|||
#ifndef _CFGITEMI_H
|
||||
#define _CFGITEMI_H
|
||||
|
||||
#include "cfgitemx.h"
|
||||
|
||||
#include <bfc/named.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
#include <bfc/depend.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class AttrCallback;
|
||||
class Attribute;
|
||||
|
||||
// this is the one you inherit from/use
|
||||
/**
|
||||
|
||||
@short Configuration Item
|
||||
@ver 1.0
|
||||
@author Nullsoft
|
||||
@see Attribute
|
||||
@see _bool
|
||||
@see _int
|
||||
@see _float
|
||||
@see _string
|
||||
*/
|
||||
class CfgItemI : public CfgItemX, public DependentI, private NamedW
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Optionally sets the name and the GUID of the
|
||||
configuration item if they are specified
|
||||
upon creation of the object.
|
||||
|
||||
@param name Name of the configuration item.
|
||||
@param guid GUID of the configuration item.
|
||||
*/
|
||||
CfgItemI(const wchar_t *name=NULL, GUID guid=INVALID_GUID);
|
||||
|
||||
/**
|
||||
Does nothing.
|
||||
*/
|
||||
virtual ~CfgItemI();
|
||||
|
||||
/**
|
||||
Get the name of the configuration item.
|
||||
|
||||
@ret Name of the configuration item.
|
||||
*/
|
||||
const wchar_t *cfgitem_getName();
|
||||
|
||||
/**
|
||||
Get the GUID of the configuration item.
|
||||
|
||||
@ret GUID of the configuration item.
|
||||
*/
|
||||
GUID cfgitem_getGuid();
|
||||
|
||||
/**
|
||||
Sets the prefix to be prepended in the config file for all attributes
|
||||
of this item.
|
||||
|
||||
@see cfgitem_getPrefix
|
||||
@param prefix The prefix.
|
||||
*/
|
||||
void cfgitem_setPrefix(const wchar_t *prefix);
|
||||
/**
|
||||
Gets the config prefix, if any was set.
|
||||
|
||||
@see cfgitem_setPrefix
|
||||
@ret Pointer to the config prefix.
|
||||
*/
|
||||
const wchar_t *cfgitem_getPrefix();
|
||||
|
||||
/**
|
||||
Get the number of attributes registered
|
||||
to this configuration item.
|
||||
|
||||
@ret Number of attributes.
|
||||
*/
|
||||
int cfgitem_getNumAttributes();
|
||||
|
||||
/**
|
||||
Enumerate the attributes registered
|
||||
with this configuration item.
|
||||
|
||||
@ret
|
||||
*/
|
||||
const wchar_t *cfgitem_enumAttribute(int n);
|
||||
|
||||
const wchar_t *cfgitem_getConfigXML();
|
||||
virtual void cfgitem_onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname) {}
|
||||
virtual void cfgitem_onCfgGroupDelete(ifc_window *cfggroup) {}
|
||||
|
||||
virtual int cfgitem_getNumChildren();
|
||||
virtual CfgItem *cfgitem_enumChild(int n);
|
||||
virtual GUID cfgitem_getParentGuid();
|
||||
|
||||
virtual void cfgitem_onRegister();
|
||||
virtual void cfgitem_onDeregister();
|
||||
|
||||
int cfgitem_getAttributeType(const wchar_t *name);
|
||||
const wchar_t *cfgitem_getAttributeConfigGroup(const wchar_t *name);
|
||||
int cfgitem_getDataLen(const wchar_t *name);
|
||||
int cfgitem_getData(const wchar_t *name, wchar_t *data, int data_len);
|
||||
int cfgitem_setData(const wchar_t *name, const wchar_t *data);
|
||||
|
||||
// override these to catch notifications from attribs, call down
|
||||
virtual int cfgitem_onAttribSetValue(Attribute *attr);
|
||||
|
||||
virtual int cfgitem_usePrivateStorage() { return 0; } //override and return 1 to keep stuff out of system settings
|
||||
|
||||
protected:
|
||||
void cfgitem_setGUID(GUID guid);
|
||||
|
||||
public:
|
||||
int setName(const wchar_t *name);
|
||||
int registerAttribute(Attribute *attr, AttrCallback *acb=NULL);
|
||||
// does not call delete on the attribute
|
||||
int deregisterAttribute(Attribute *attr);
|
||||
void deregisterAll();
|
||||
|
||||
void addCallback(Attribute *attr, AttrCallback *acb);
|
||||
|
||||
int cfgitem_addAttribute(const wchar_t *name, const wchar_t *defval);
|
||||
int cfgitem_delAttribute(const wchar_t *name);
|
||||
|
||||
protected:
|
||||
|
||||
// derived classes can override this to catch name changes
|
||||
virtual void cfgitem_onSetName() { }
|
||||
|
||||
Attribute *getAttributeByName(const wchar_t *name);
|
||||
|
||||
void addChildItem(CfgItemI *child);
|
||||
|
||||
void setCfgXml(const wchar_t *groupname);
|
||||
|
||||
void setParentGuid(GUID guid);
|
||||
|
||||
private:
|
||||
api_dependent *cfgitem_getDependencyPtr() { return this; };
|
||||
virtual void *dependent_getInterface(const GUID *classguid);
|
||||
|
||||
// from Named
|
||||
virtual void onSetName() { cfgitem_onSetName(); }
|
||||
|
||||
std::wstring prefix;
|
||||
PtrList<Attribute> attributes;
|
||||
std::multimap<Attribute*, AttrCallback*> callbacks; //CUT
|
||||
PtrList<CfgItemI> children;
|
||||
std::wstring cfgxml;
|
||||
GUID myguid, parent_guid;
|
||||
PtrList<Attribute> newattribs;
|
||||
};
|
||||
|
||||
#endif
|
27
Src/Wasabi/api/config/items/cfgitemx.cpp
Normal file
27
Src/Wasabi/api/config/items/cfgitemx.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <precomp.h>
|
||||
#include "cfgitemx.h"
|
||||
|
||||
#define CBCLASS CfgItemX
|
||||
START_DISPATCH
|
||||
CB(CFGITEM_GETNAME, cfgitem_getName);
|
||||
CB(CFGITEM_GETGUID, cfgitem_getGuid);
|
||||
CB(CFGITEM_GETNUMATTRIBUTES, cfgitem_getNumAttributes);
|
||||
CB(CFGITEM_ENUMATTRIBUTE, cfgitem_enumAttribute);
|
||||
CB(CFGITEM_GETCONFIGXML, cfgitem_getConfigXML);
|
||||
VCB(CFGITEM_ONCFGGROUPCREATE, cfgitem_onCfgGroupCreate);
|
||||
VCB(CFGITEM_ONCFGGROUPDELETE, cfgitem_onCfgGroupDelete);
|
||||
CB(CFGITEM_GETNUMCHILDREN, cfgitem_getNumChildren);
|
||||
CB(CFGITEM_ENUMCHILD, cfgitem_enumChild);
|
||||
CB(CFGITEM_GETPARENTGUID, cfgitem_getParentGuid);
|
||||
VCB(CFGITEM_ONREGISTER, cfgitem_onRegister);
|
||||
VCB(CFGITEM_ONDEREGISTER, cfgitem_onDeregister);
|
||||
CB(CFGITEM_GETATTRIBUTETYPE, cfgitem_getAttributeType);
|
||||
CB(CFGITEM_GETATTRIBUTECONFIGGROUP, cfgitem_getAttributeConfigGroup);
|
||||
CB(CFGITEM_GETDATALEN, cfgitem_getDataLen);
|
||||
CB(CFGITEM_GETDATA, cfgitem_getData);
|
||||
CB(CFGITEM_SETDATA, cfgitem_setData);
|
||||
CB(CFGITEM_GETDEPENDENCYPTR, cfgitem_getDependencyPtr);
|
||||
CB(CFGITEM_ADDATTRIB, cfgitem_addAttribute);
|
||||
CB(CFGITEM_DELATTRIB, cfgitem_delAttribute);
|
||||
END_DISPATCH
|
||||
#undef CBCLASS
|
42
Src/Wasabi/api/config/items/cfgitemx.h
Normal file
42
Src/Wasabi/api/config/items/cfgitemx.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef NULLSOFT_WASABI_CFGITEMX_H
|
||||
#define NULLSOFT_WASABI_CFGITEMX_H
|
||||
|
||||
#include "cfgitem.h"
|
||||
|
||||
class CfgItemX : public CfgItem
|
||||
{
|
||||
public:
|
||||
virtual ~CfgItemX() {}
|
||||
virtual const wchar_t *cfgitem_getName()=0;
|
||||
virtual GUID cfgitem_getGuid()=0;
|
||||
virtual int cfgitem_getNumAttributes()=0;
|
||||
virtual const wchar_t *cfgitem_enumAttribute(int n)=0;
|
||||
virtual const wchar_t *cfgitem_getConfigXML()=0;
|
||||
virtual void cfgitem_onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname)=0;
|
||||
virtual void cfgitem_onCfgGroupDelete(ifc_window *cfggroup)=0;
|
||||
|
||||
virtual int cfgitem_getNumChildren()=0;
|
||||
virtual CfgItem *cfgitem_enumChild(int n)=0;
|
||||
virtual GUID cfgitem_getParentGuid()=0;
|
||||
|
||||
virtual void cfgitem_onRegister()=0;
|
||||
virtual void cfgitem_onDeregister()=0;
|
||||
|
||||
virtual int cfgitem_getAttributeType(const wchar_t *name)=0;
|
||||
virtual const wchar_t *cfgitem_getAttributeConfigGroup(const wchar_t *name)=0;
|
||||
|
||||
virtual int cfgitem_getDataLen(const wchar_t *name)=0;
|
||||
virtual int cfgitem_getData(const wchar_t *name, wchar_t *data, int data_len)=0;
|
||||
virtual int cfgitem_setData(const wchar_t *name, const wchar_t *data)=0;
|
||||
virtual ifc_dependent *cfgitem_getDependencyPtr()=0;
|
||||
virtual int cfgitem_delAttribute(const wchar_t *name)=0;
|
||||
virtual int cfgitem_addAttribute(const wchar_t *name, const wchar_t *defval)=0;
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
49
Src/Wasabi/api/config/items/intarray.cpp
Normal file
49
Src/Wasabi/api/config/items/intarray.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "intarray.h"
|
||||
|
||||
|
||||
enum { MAX_ARRAY=8 };
|
||||
|
||||
int IntArray::read(const wchar_t *name, int *x1, int *x2, int *x3, int *x4, int *x5, int *x6, int *x7, int *x8) {
|
||||
PtrList<int> list;
|
||||
if (x1) { list.addItem(x1); }
|
||||
if (x2) { list.addItem(x2); }
|
||||
if (x3) { list.addItem(x3); }
|
||||
if (x4) { list.addItem(x4); }
|
||||
if (x5) { list.addItem(x5); }
|
||||
if (x6) { list.addItem(x6); }
|
||||
if (x7) { list.addItem(x7); }
|
||||
if (x8) { list.addItem(x8); }
|
||||
ASSERT(list.getNumItems() >= 1);
|
||||
|
||||
int array[MAX_ARRAY]; // gcc rules, msvc drools
|
||||
for (int i = 0; i < list.getNumItems(); i++) {
|
||||
if (list[i]) array[i] = *list[i];
|
||||
}
|
||||
if (!WASABI_API_CONFIG->getIntArrayPrivate(name, array, list.getNumItems())) return 0;
|
||||
for (int j = 0; j < list.getNumItems(); j++) {
|
||||
if (list[j]) *list[j] = array[j];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void IntArray::write(const wchar_t *name, int x1) {
|
||||
int array[] = { x1 };
|
||||
WASABI_API_CONFIG->setIntArrayPrivate(name, array, sizeof(array)/sizeof(int));
|
||||
}
|
||||
|
||||
void IntArray::write(const wchar_t *name, int x1, int x2) {
|
||||
int array[] = { x1, x2 };
|
||||
WASABI_API_CONFIG->setIntArrayPrivate(name, array, sizeof(array)/sizeof(int));
|
||||
}
|
||||
|
||||
void IntArray::write(const wchar_t *name, int x1, int x2, int x3) {
|
||||
int array[] = { x1, x2, x3 };
|
||||
WASABI_API_CONFIG->setIntArrayPrivate(name, array, sizeof(array)/sizeof(int));
|
||||
}
|
||||
|
||||
void IntArray::write(const wchar_t *name, int x1, int x2, int x3, int x4) {
|
||||
int array[] = { x1, x2, x3, x4 };
|
||||
WASABI_API_CONFIG->setIntArrayPrivate(name, array, sizeof(array)/sizeof(int));
|
||||
}
|
18
Src/Wasabi/api/config/items/intarray.h
Normal file
18
Src/Wasabi/api/config/items/intarray.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef _INTARRAY_H
|
||||
#define _INTARRAY_H
|
||||
|
||||
#include <bfc/common.h>
|
||||
#include <bfc/named.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
|
||||
class IntArray
|
||||
{
|
||||
public:
|
||||
static int read(const wchar_t *name, int *x1, int *x2=NULL, int *x3=NULL, int *x4=NULL, int *x5=NULL, int *x6=NULL, int *x7=NULL, int *x8=NULL);
|
||||
static void write(const wchar_t *name, int x1);
|
||||
static void write(const wchar_t *name, int x1, int x2);
|
||||
static void write(const wchar_t *name, int x1, int x2, int x3);
|
||||
static void write(const wchar_t *name, int x1, int x2, int x3, int x4);
|
||||
};
|
||||
|
||||
#endif
|
211
Src/Wasabi/api/config/options.cpp
Normal file
211
Src/Wasabi/api/config/options.cpp
Normal file
|
@ -0,0 +1,211 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "options.h"
|
||||
|
||||
//#include <api/wac/main.h>//CUT!!
|
||||
#include <api/wnd/wndtrack.h>
|
||||
|
||||
#include <bfc/util/inifile.h>
|
||||
#include <api/config/items/attribs.h>
|
||||
#include <api/config/items/attrcb.h>
|
||||
#include <bfc/wasabi_std_wnd.h>
|
||||
|
||||
#include <api/locales/localesmgr.h>
|
||||
#include <api/font/font.h>
|
||||
|
||||
#define ININAME "wasabi.ini"
|
||||
|
||||
// {280876CF-48C0-40bc-8E86-73CE6BB462E5}
|
||||
const GUID options_guid =
|
||||
{ 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } };
|
||||
|
||||
#ifndef GEN_FF
|
||||
|
||||
static void setMultipleInstance(int val)
|
||||
{
|
||||
StringPrintf fn("%s%s%s", WASABI_API_APP->path_getAppPath(), DIRCHARSTR, ININAME);
|
||||
IniFile(fn).setBool("Wasabi", "MultipleInstance", val);
|
||||
}
|
||||
|
||||
_int forward_skip_time("Forward skip time", 5000);
|
||||
_int reverse_skip_time("Reverse skip time", 5000);
|
||||
#endif
|
||||
|
||||
_bool cfg_options_altfonts(L"Alternate Fonts", FALSE);
|
||||
_bool cfg_options_allowbitmapfonts(L"Use bitmap fonts (no international support)", FALSE);
|
||||
_string cfg_options_defaultfont(L"Default font", WASABI_DEFAULT_FONTNAMEW L".ttf");
|
||||
_int cfg_options_defaultfontscale(L"Default font scale", 100);
|
||||
_string cfg_options_ttfoverridefont(L"TTF font override", WASABI_DEFAULT_FONTNAMEW L".ttf");
|
||||
_int cfg_options_ttfoverridescale(L"TTF Override Scale", 100);
|
||||
_bool cfg_options_no7bitsttfoverride(L"No 7-bit TTF override", TRUE);
|
||||
_bool cfg_options_noalt7bitsttfoverride(L"No 7-bit TTF AltFonts", TRUE);
|
||||
_bool cfg_options_usefontmapper(L"Enable Font Mapper", FALSE);
|
||||
|
||||
#ifdef USEAPPBAR
|
||||
_bool cfg_options_appbarondrag(L"Dock Appbars on Window Drag", FALSE);
|
||||
_int cfg_options_appbardockingdistance(L"Appbars Docking Distance", 5);
|
||||
#endif
|
||||
|
||||
void invalidateAll(int b) {
|
||||
#ifdef WASABI_COMPILE_WNDMGR
|
||||
WASABI_API_WNDMGR->wndTrackInvalidateAll();
|
||||
#endif
|
||||
}
|
||||
|
||||
void onDefaultFontChanged(const wchar_t *attribute) {
|
||||
Font::uninstallAll(1);
|
||||
Wasabi::Std::setDefaultFont(cfg_options_defaultfont.getValue());
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
void onOverrideFontChanged(const wchar_t *attribute) {
|
||||
Font::uninstallAll(1);
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
void onDefaultFontScaleChanged(int scale) {
|
||||
Wasabi::Std::setDefaultFontScale(scale);
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
void onOverrideFontScaleChanged(int scale) {
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
void onFontRendererChanged(const wchar_t *s) {
|
||||
Font::uninstallAll(1);
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
void onFontMapperChanged(int b) {
|
||||
Font::uninstallAll(1);
|
||||
invalidateAll(1);
|
||||
}
|
||||
|
||||
_bool cfg_audiooptions_crossfader(L"Enable crossfading", DEFAULT_CROSSFADE_ENABLED);
|
||||
_bool cfg_options_alwaysontop(L"Always on top", FALSE);
|
||||
_bool cfg_options_docking(L"Enable docking", TRUE);
|
||||
_int cfg_options_dockingdistance(L"Docking distance", DEFAULT_DOCK_DIST);
|
||||
_string cfg_options_fontrenderer(L"Font Renderer", WASABI_FONT_RENDERER);
|
||||
_int cfg_options_freetypecharmap(L"Character mapping", -1);
|
||||
|
||||
Options::Options() : CfgItemI(L"Options", options_guid)
|
||||
{
|
||||
#ifdef _WASABIRUNTIME
|
||||
registerAttribute(&cfg_options_alwaysontop, new int_attrCB(Main::setOnTop));
|
||||
#else
|
||||
extern void setOnTop(int ontop);
|
||||
registerAttribute(&cfg_options_alwaysontop, new int_attrCB(setOnTop));
|
||||
#endif
|
||||
/* TODO: benski> move to wndmgr.w5s (or wherever it's final home is */
|
||||
registerAttribute(&cfg_options_dockingdistance, new int_attrCB(WindowTracker::setDockDistance));
|
||||
registerAttribute(&cfg_options_docking, new int_attrCB(WindowTracker::setEnableDocking));
|
||||
/* --- END TO MOVE --- */
|
||||
registerAttribute(new _bool(L"Find open rect", FALSE));
|
||||
registerAttribute(new _bool(L"Animated rects", TRUE));
|
||||
registerAttribute(&cfg_options_fontrenderer, new string_attrCB(onFontRendererChanged));
|
||||
registerAttribute(&cfg_options_allowbitmapfonts, new int_attrCB(invalidateAll));
|
||||
registerAttribute(&cfg_options_altfonts, new int_attrCB(invalidateAll));
|
||||
registerAttribute(&cfg_options_defaultfont, new string_attrCB(onDefaultFontChanged));
|
||||
registerAttribute(&cfg_options_ttfoverridefont, new string_attrCB(onOverrideFontChanged));
|
||||
registerAttribute(&cfg_options_ttfoverridescale, new int_attrCB(onOverrideFontScaleChanged));
|
||||
registerAttribute(&cfg_options_defaultfontscale, new int_attrCB(onDefaultFontScaleChanged));
|
||||
registerAttribute(&cfg_options_freetypecharmap, new int_attrCB(invalidateAll));
|
||||
registerAttribute(&cfg_options_no7bitsttfoverride, new int_attrCB(invalidateAll));
|
||||
registerAttribute(&cfg_options_noalt7bitsttfoverride, new int_attrCB(invalidateAll));
|
||||
registerAttribute(&cfg_options_usefontmapper, new int_attrCB(onFontMapperChanged));
|
||||
#ifdef USEAPPBAR
|
||||
registerAttribute(&cfg_options_appbarondrag);
|
||||
registerAttribute(&cfg_options_appbardockingdistance);
|
||||
#endif
|
||||
#ifdef _WASABIRUNTIME
|
||||
registerAttribute(new _bool(L"Allow multiple instances", FALSE), new int_attrCB(setMultipleInstance));
|
||||
registerAttribute(new _int(L"Icon mode", 1), new int_attrCB(Main::setIconMode));
|
||||
registerAttribute(new _bool(L"Auto-play at startup", FALSE));
|
||||
registerAttribute(new _string(L"Language", "English"), new LanguageCB(this));
|
||||
#ifdef WIN32
|
||||
registerAttribute(new _bool("Associate with audio CDs", TRUE), new int_attrCB(Filetypes::registerCdPlayer));
|
||||
#endif
|
||||
registerAttribute(new _string("Monitor aspect ratio", "4:3"));
|
||||
registerAttribute(new _int("Internet connection",3)); //3==autodetect
|
||||
registerAttribute(&forward_skip_time);
|
||||
registerAttribute(&reverse_skip_time);
|
||||
#endif
|
||||
|
||||
//registerAttribute(new _bool("Use Mozilla instead of IE for minibrowser", FALSE)); // TODO:move into minibrowser component
|
||||
/* registerAttribute(new _bool("Force antialias on all TTF", FALSE));*/
|
||||
addChildItem(&audio_options);
|
||||
addChildItem(&ui_options);
|
||||
}
|
||||
|
||||
void Options::checkCd() {
|
||||
#ifdef _WASABIRUNTIME
|
||||
#ifdef WIN32
|
||||
if(getDataAsInt("Associate with audio CDs") && !Filetypes::isCdPlayer()) setDataAsInt("Associate with audio CDs",false);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// {FC3EAF78-C66E-4ed2-A0AA-1494DFCC13FF}
|
||||
static const GUID audio_options_guid =
|
||||
{ 0xfc3eaf78, 0xc66e, 0x4ed2, { 0xa0, 0xaa, 0x14, 0x94, 0xdf, 0xcc, 0x13, 0xff } };
|
||||
|
||||
AudioOptions::AudioOptions() : CfgItemI(L"Audio options", audio_options_guid)
|
||||
{
|
||||
#ifdef GEN_FF
|
||||
#ifdef WASABI_COMPILE_MEDIACORE
|
||||
extern void setCrossfader(int crossfade);
|
||||
registerAttribute(&cfg_audiooptions_crossfader, new int_attrCB(setCrossfader));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef _WASABIRUNTIME
|
||||
registerAttribute(&cfg_audiooptions_crossfader);
|
||||
int use_dsound=0;
|
||||
#ifdef WIN32
|
||||
//check for Windows version for whether we make DSOUND default
|
||||
DWORD dwVersion = GetVersion();
|
||||
DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
||||
if (dwVersion < 0x80000000) {
|
||||
if(dwWindowsMajorVersion<=4) use_dsound=0; // no dsound on NT4/3.51
|
||||
else use_dsound=1; // dsound yes on 2000/XP
|
||||
} else
|
||||
use_dsound=0; // no dsound by default on win9x (per PP)
|
||||
#endif
|
||||
registerAttribute(new _bool("DirectSound output", use_dsound));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WASABIRUNTIME
|
||||
|
||||
// {C1BD5354-5EC4-406c-B5C0-549718D3AF45}
|
||||
static const GUID setup_guid =
|
||||
{ 0xc1bd5354, 0x5ec4, 0x406c, { 0xb5, 0xc0, 0x54, 0x97, 0x18, 0xd3, 0xaf, 0x45 } };
|
||||
|
||||
SetupOptions::SetupOptions() : CfgItemI("Setup", setup_guid) {
|
||||
#ifdef WIN32
|
||||
addChildItem(&filetypes);
|
||||
#endif
|
||||
}
|
||||
|
||||
// {99CFD75C-1CA7-49e5-B8C0-7D78AA443C10}
|
||||
static const GUID installed_guid =
|
||||
{ 0x99cfd75c, 0x1ca7, 0x49e5, { 0xb8, 0xc0, 0x7d, 0x78, 0xaa, 0x44, 0x3c, 0x10 } };
|
||||
|
||||
InstalledComponents::InstalledComponents() : CfgItemI("Installed components", installed_guid) {
|
||||
//CUT setCfgXml("config.components");
|
||||
}
|
||||
|
||||
void LanguageCB::onValueChange(Attribute *attr) {
|
||||
char bufero[WA_MAX_PATH]="";
|
||||
attr->getData(bufero, WA_MAX_PATH-1);
|
||||
const char *locname;
|
||||
for(int i=0;locname=LocalesManager::enumLoadableLocales(i);i++) {
|
||||
if (STRCASEEQLSAFE(bufero, locname)) {
|
||||
LocalesManager::setNewLocaleNum(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
WASABI_API_WNDMGR->messageBox(StringPrintf("Internal problem switching to language %s, the language name couldn't be found in the list of loaded resources", bufero), "Error", 0, NULL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
64
Src/Wasabi/api/config/options.h
Normal file
64
Src/Wasabi/api/config/options.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef _OPTIONS_H
|
||||
#define _OPTIONS_H
|
||||
|
||||
#include <api/config/items/cfgitemi.h>
|
||||
#include <api/config/items/attrcb.h>
|
||||
|
||||
//#include <api/config/filetypes.h>
|
||||
#include <api/config/uioptions.h>
|
||||
|
||||
class Options;
|
||||
|
||||
class _string;
|
||||
class _int;
|
||||
class _bool;
|
||||
|
||||
extern _string cfg_options_defaultfont;
|
||||
extern _int cfg_options_ttfoverridescale;
|
||||
extern _bool cfg_options_no7bitsttfoverride;
|
||||
extern _bool cfg_options_allowbitmapfonts;
|
||||
extern _string cfg_options_fontrenderer;
|
||||
|
||||
#ifdef _WASABIRUNTIME
|
||||
|
||||
class SetupOptions : public CfgItemI {
|
||||
public:
|
||||
SetupOptions();
|
||||
|
||||
Filetypes filetypes;
|
||||
};
|
||||
|
||||
class InstalledComponents : public CfgItemI {
|
||||
public:
|
||||
InstalledComponents();
|
||||
};
|
||||
#endif
|
||||
|
||||
class AudioOptions : public CfgItemI {
|
||||
public:
|
||||
AudioOptions();
|
||||
};
|
||||
|
||||
#define OPTIONS_PARENT CfgItemI
|
||||
class Options : public OPTIONS_PARENT {
|
||||
public:
|
||||
Options();
|
||||
void checkCd();
|
||||
|
||||
AudioOptions audio_options;
|
||||
UIOptions ui_options;
|
||||
};
|
||||
|
||||
#ifdef _WASABIRUNTIME
|
||||
|
||||
class LanguageCB : public AttrCallback {
|
||||
public:
|
||||
LanguageCB(CfgItemI *_par) : par(_par) { }
|
||||
virtual void onValueChange(Attribute *attr);
|
||||
private:
|
||||
CfgItemI *par;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
109
Src/Wasabi/api/config/uioptions.cpp
Normal file
109
Src/Wasabi/api/config/uioptions.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "uioptions.h"
|
||||
|
||||
#include <api/wndmgr/layout.h>
|
||||
|
||||
#include <api/config/items/attribs.h>
|
||||
#include <api/config/items/attrcb.h>
|
||||
|
||||
#include <api/skin/skinparse.h>
|
||||
#include <api/wndmgr/alphamgr.h>
|
||||
|
||||
// {9149C445-3C30-4e04-8433-5A518ED0FDDE}
|
||||
const GUID uioptions_guid =
|
||||
{ 0x9149c445, 0x3c30, 0x4e04, { 0x84, 0x33, 0x5a, 0x51, 0x8e, 0xd0, 0xfd, 0xde } };
|
||||
|
||||
_bool cfg_uioptions_desktopalpha(L"Enable desktop alpha", DEFAULT_DESKTOPALPHA);
|
||||
_bool cfg_uioptions_linkratio(L"Link layouts scale", DEFAULT_LINKLAYOUTSCALE);
|
||||
_bool cfg_uioptions_linkalpha(L"Link layouts alpha", DEFAULT_LINKLAYOUTSALPHA);
|
||||
_bool cfg_uioptions_linkallalpha(L"Link All layouts alpha", DEFAULT_LINKALLALPHA);
|
||||
_bool cfg_uioptions_linkallratio(L"Link All layouts scale", DEFAULT_LINKALLRATIO);
|
||||
_int cfg_uioptions_linkedalpha(L"Linked layouts alpha", DEFAULT_LINKEDALPHA);
|
||||
_int cfg_uioptions_autoopacitytime(L"Auto Opacity hold time", DEFAULT_AUTOOPACITYTIME);
|
||||
_int cfg_uioptions_autoopacityfadein(L"Auto Opacity fade in time", DEFAULT_AUTOOPACITYFADEIN);
|
||||
_int cfg_uioptions_autoopacityfadeout(L"Auto Opacity fade out time", DEFAULT_AUTOOPACITYFADEOUT);
|
||||
_int cfg_uioptions_autoopacitylinked(L"Use Auto Opacity", DEFAULT_AUTOOPACITYTYPE);
|
||||
_int cfg_uioptions_extendautoopacity(L"Auto Opacity extend by", DEFAULT_EXTENDAUTOOPACITY);
|
||||
_bool cfg_uioptions_uselocks(L"Use layout scale locks", DEFAULT_USERATIOLOCKS);
|
||||
_int cfg_uioptions_timerresolution(L"Multiplexed timers resolution", DEFAULT_TIMERRESOLUTION);
|
||||
_bool cfg_uioptions_tooltips(L"Enable tooltips", DEFAULT_TOOLTIPS);
|
||||
_float cfg_uioptions_textspeed(L"Text Ticker Speed", DEFAULT_TEXTSPEED);
|
||||
_int cfg_uioptions_textincrement(L"Text Ticker Increment", DEFAULT_TEXTINCREMENT);
|
||||
_int cfg_uioptions_appbarshidetime(L"Appbar Hide Time", DEFAULT_APPBARHIDETIME);
|
||||
_int cfg_uioptions_appbarsshowtime(L"Appbar Show Time", DEFAULT_APPBARSHOWTIME);
|
||||
|
||||
void onSetOpacityTime(int n) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setHoldTime(n);
|
||||
}
|
||||
|
||||
void onSetOpacityFadeIn(int n) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setFadeInTime(n);
|
||||
}
|
||||
|
||||
void onSetOpacityFadeOut(int n) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setFadeOutTime(n);
|
||||
}
|
||||
|
||||
void onSetAllRatio(int on) {
|
||||
if (on) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->setRenderRatio(l->getRenderRatio());
|
||||
}
|
||||
}
|
||||
|
||||
void onSetAllAlpha(int on) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setAllLinked(on);
|
||||
}
|
||||
|
||||
void onSetLinkedAlpha(int a) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setGlobalAlpha(a);
|
||||
}
|
||||
|
||||
void onSetLinkedAuto100(int v) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setAutoOpacify(v);
|
||||
}
|
||||
|
||||
void onSetExtendAutoOpacity(int v) {
|
||||
Layout *l = SkinParser::getMainLayout();
|
||||
if (l) l->getAlphaMgr()->setExtendAutoOpacity(v);
|
||||
}
|
||||
|
||||
UIOptions::UIOptions(const wchar_t *name) : CfgItemI(name ? name : L"Skins and UI Tweaks", uioptions_guid)
|
||||
{
|
||||
registerAttribute(&cfg_uioptions_linkratio);
|
||||
registerAttribute(&cfg_uioptions_linkalpha);
|
||||
registerAttribute(&cfg_uioptions_uselocks);
|
||||
registerAttribute(&cfg_uioptions_autoopacitylinked, new int_attrCB(onSetLinkedAuto100));
|
||||
registerAttribute(&cfg_uioptions_linkallratio, new int_attrCB(onSetAllRatio));
|
||||
registerAttribute(&cfg_uioptions_linkallalpha, new int_attrCB(onSetAllAlpha));
|
||||
registerAttribute(&cfg_uioptions_desktopalpha, new int_attrCB(Layout::onGlobalEnableDesktopAlpha));
|
||||
registerAttribute(&cfg_uioptions_linkedalpha, new int_attrCB(onSetLinkedAlpha));
|
||||
registerAttribute(&cfg_uioptions_tooltips);
|
||||
registerAttribute(&cfg_uioptions_timerresolution);
|
||||
registerAttribute(&cfg_uioptions_textspeed);
|
||||
registerAttribute(&cfg_uioptions_textincrement);
|
||||
registerAttribute(&cfg_uioptions_appbarshidetime);
|
||||
registerAttribute(&cfg_uioptions_appbarsshowtime);
|
||||
registerAttribute(&cfg_uioptions_autoopacitytime, new int_attrCB(onSetOpacityTime));
|
||||
registerAttribute(&cfg_uioptions_autoopacityfadein, new int_attrCB(onSetOpacityFadeIn));
|
||||
registerAttribute(&cfg_uioptions_autoopacityfadeout, new int_attrCB(onSetOpacityFadeOut));
|
||||
registerAttribute(&cfg_uioptions_extendautoopacity, new int_attrCB(onSetExtendAutoOpacity));
|
||||
registerAttribute(new _int(L"Timer refresh rate", 30), new int_attrCB(onTimerRefreshRate));
|
||||
registerAttribute(new _int(L"Popup menu alpha", 240));
|
||||
registerAttribute(new _int(L"Spectrum analyzer mode",1));
|
||||
}
|
||||
|
||||
void UIOptions::onTimerRefreshRate(int rate) {
|
||||
if(rate==0 || rate<9 || rate>70) return;
|
||||
int res=1000/rate;
|
||||
CfgItem *ci=WASABI_API_CONFIG->config_getCfgItemByGuid(uioptions_guid);
|
||||
if(!ci) return;
|
||||
ci->setDataAsInt(L"Multiplexed timers resolution",res);
|
||||
}
|
13
Src/Wasabi/api/config/uioptions.h
Normal file
13
Src/Wasabi/api/config/uioptions.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef _UIOPTIONS_H
|
||||
#define _UIOPTIONS_H
|
||||
|
||||
#include <api/config/items/cfgitemi.h>
|
||||
|
||||
#define UIOPTIONS_PARENT CfgItemI
|
||||
class UIOptions : public UIOPTIONS_PARENT {
|
||||
public:
|
||||
UIOptions(const wchar_t *name=NULL);
|
||||
static void onTimerRefreshRate(int rate);
|
||||
};
|
||||
|
||||
#endif
|
33
Src/Wasabi/api/console/console.cpp
Normal file
33
Src/Wasabi/api/console/console.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "console.h"
|
||||
#include <api/service/svcs/svc_console.h>
|
||||
#include <api/service/svc_enum.h>
|
||||
|
||||
void Console::outputString(int severity, const char *string) {
|
||||
if (!console) {
|
||||
console = new ConsoleEnum;
|
||||
}
|
||||
|
||||
if (needscan) {
|
||||
needscan=0;
|
||||
console->reset();
|
||||
svc_console *con = console->getNext();
|
||||
noconsole = (con == NULL);
|
||||
}
|
||||
if (noconsole) return;
|
||||
|
||||
console->reset();
|
||||
svc_console *con = console->getNext();
|
||||
while (con) {
|
||||
con->outputString(severity, string);
|
||||
con = console->getNext();
|
||||
}
|
||||
}
|
||||
|
||||
void Console::reset() {
|
||||
needscan=1;
|
||||
}
|
||||
|
||||
int Console::needscan=1;
|
||||
int Console::noconsole=0;
|
||||
|
||||
ConsoleEnum *Console::console = NULL;
|
19
Src/Wasabi/api/console/console.h
Normal file
19
Src/Wasabi/api/console/console.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef __CONSOLE_H
|
||||
#define __CONSOLE_H
|
||||
|
||||
class ConsoleEnum;
|
||||
|
||||
class Console {
|
||||
public:
|
||||
|
||||
static void outputString(int severity, const char *string);
|
||||
static void reset();
|
||||
|
||||
private:
|
||||
|
||||
static ConsoleEnum *console;
|
||||
static int needscan;
|
||||
static int noconsole;
|
||||
};
|
||||
|
||||
#endif
|
51
Src/Wasabi/api/core/api_core.cpp
Normal file
51
Src/Wasabi/api/core/api_core.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include <precomp.h>
|
||||
#include "api_core.h"
|
||||
|
||||
#ifdef CBCLASS
|
||||
#undef CBCLASS
|
||||
#endif
|
||||
#define CBCLASS api_coreI
|
||||
START_DISPATCH;
|
||||
CB(API_CORE_GETSUPPORTEDEXTENSIONS, core_getSupportedExtensions);
|
||||
CB(API_CORE_GETEXTSUPPORTEDEXTENSIONS, core_getExtSupportedExtensions);
|
||||
CB(API_CORE_CREATE, core_create);
|
||||
CB(API_CORE_FREE, core_free);
|
||||
CB(API_CORE_SETNEXTFILE, core_setNextFile);
|
||||
CB(API_CORE_GETSTATUS, core_getStatus);
|
||||
CB(API_CORE_GETCURRENT, core_getCurrent);
|
||||
CB(API_CORE_GETCURPLAYBACKNUMBER, core_getCurPlaybackNumber);
|
||||
CB(API_CORE_GETPOSITION, core_getPosition);
|
||||
CB(API_CORE_GETWRITEPOSITION, core_getWritePosition);
|
||||
CB(API_CORE_SETPOSITION, core_setPosition);
|
||||
CB(API_CORE_GETLENGTH, core_getLength);
|
||||
CB(API_CORE_GETPLUGINDATA, core_getPluginData);
|
||||
CB(API_CORE_GETVOLUME, core_getVolume);
|
||||
VCB(API_CORE_SETVOLUME, core_setVolume);
|
||||
CB(API_CORE_GETPAN, core_getPan);
|
||||
VCB(API_CORE_SETPAN, core_setPan);
|
||||
VCB(API_CORE_ADDCALLBACK, core_addCallback);
|
||||
VCB(API_CORE_DELCALLBACK, core_delCallback);
|
||||
CB(API_CORE_GETVISDATA, core_getVisData);
|
||||
CB(API_CORE_GETLEFTVUMETER, core_getLeftVuMeter);
|
||||
CB(API_CORE_GETRIGHTVUMETER, core_getRightVuMeter);
|
||||
CB(API_CORE_REGISTERSEQUENCER, core_registerSequencer);
|
||||
CB(API_CORE_DEREGISTERSEQUENCER, core_deregisterSequencer);
|
||||
VCB(API_CORE_USERBUTTON, core_userButton);
|
||||
CB(API_CORE_GETEQSTATUS, core_getEqStatus);
|
||||
VCB(API_CORE_SETEQSTATUS, core_setEqStatus);
|
||||
CB(API_CORE_GETEQPREAMP, core_getEqPreamp);
|
||||
VCB(API_CORE_SETEQPREAMP, core_setEqPreamp);
|
||||
CB(API_CORE_GETEQBAND, core_getEqBand);
|
||||
VCB(API_CORE_SETEQBAND, core_setEqBand);
|
||||
CB(API_CORE_GETEQAUTO, core_getEqAuto);
|
||||
VCB(API_CORE_SETEQAUTO, core_setEqAuto);
|
||||
VCB(API_CORE_SETCUSTOMMSG, core_setCustomMsg);
|
||||
VCB(API_CORE_REGISTEREXTENSION, core_registerExtension);
|
||||
CB(API_CORE_GETEXTENSIONFAMILY, core_getExtensionFamily);
|
||||
VCB(API_CORE_UNREGISTEREXTENSION, core_unregisterExtension);
|
||||
CB(API_CORE_GETTITLE, core_getTitle);
|
||||
CB(API_CORE_GETRATING, core_getRating);
|
||||
VCB(API_CORE_SETRATING, core_setRating);
|
||||
CB(API_CORE_GETDECODERNAME, core_getDecoderName);
|
||||
VCB(API_CORE_SETTITLE, core_setTitle);
|
||||
END_DISPATCH;
|
371
Src/Wasabi/api/core/api_core.h
Normal file
371
Src/Wasabi/api/core/api_core.h
Normal file
|
@ -0,0 +1,371 @@
|
|||
#ifndef __API_CORE_H
|
||||
#define __API_CORE_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
typedef unsigned int CoreToken;
|
||||
class CoreCallback;
|
||||
class ItemSequencer;
|
||||
|
||||
class NOVTABLE api_core : public Dispatchable
|
||||
{
|
||||
public:
|
||||
const wchar_t *core_getSupportedExtensions();
|
||||
const wchar_t *core_getExtSupportedExtensions();
|
||||
CoreToken core_create();
|
||||
int core_free(CoreToken core);
|
||||
int core_setNextFile(CoreToken core, const wchar_t *playstring);
|
||||
int core_getStatus(CoreToken core);
|
||||
const wchar_t *core_getCurrent(CoreToken core);
|
||||
int core_getCurPlaybackNumber(CoreToken core);
|
||||
int core_getPosition(CoreToken core);
|
||||
int core_getWritePosition(CoreToken core);
|
||||
int core_setPosition(CoreToken core, int ms);
|
||||
int core_getLength(CoreToken core);
|
||||
int core_getPluginData(const wchar_t *playstring, const wchar_t *name, wchar_t *data, int data_len, int data_type = 0);
|
||||
unsigned int core_getVolume(CoreToken core);
|
||||
void core_setVolume(CoreToken core, unsigned int vol);
|
||||
int core_getPan(CoreToken core);
|
||||
void core_setPan(CoreToken core, int val);
|
||||
void core_addCallback(CoreToken core, CoreCallback *cb);
|
||||
void core_delCallback(CoreToken core, CoreCallback *cb);
|
||||
int core_getVisData(CoreToken core, void *dataptr, int sizedataptr);
|
||||
int core_getLeftVuMeter(CoreToken core);
|
||||
int core_getRightVuMeter(CoreToken core);
|
||||
int core_registerSequencer(CoreToken core, ItemSequencer *seq);
|
||||
int core_deregisterSequencer(CoreToken core, ItemSequencer *seq);
|
||||
void core_userButton(CoreToken core, int button);
|
||||
int core_getEqStatus(CoreToken core);
|
||||
void core_setEqStatus(CoreToken core, int enable);
|
||||
int core_getEqPreamp(CoreToken core);
|
||||
void core_setEqPreamp(CoreToken core, int pre);
|
||||
int core_getEqBand(CoreToken core, int band);
|
||||
void core_setEqBand(CoreToken core, int band, int val);
|
||||
int core_getEqAuto(CoreToken core);
|
||||
void core_setEqAuto(CoreToken core, int enable);
|
||||
void core_setCustomMsg(CoreToken core, const wchar_t *text);
|
||||
void core_registerExtension(const wchar_t *extensions, const wchar_t *extension_name, const wchar_t *family = NULL);
|
||||
const wchar_t *core_getExtensionFamily(const wchar_t *extension);
|
||||
void core_unregisterExtension(const wchar_t *extensions);
|
||||
const wchar_t *core_getTitle(CoreToken core);
|
||||
void core_setTitle(const wchar_t *new_title);
|
||||
const wchar_t *core_getDecoderName(const wchar_t *filename);
|
||||
// these don't necessarily belong here, but api_core is already over-bloated :)
|
||||
int core_getRating();
|
||||
void core_setRating(int newRating);
|
||||
|
||||
enum
|
||||
{
|
||||
API_CORE_GETSUPPORTEDEXTENSIONS = 0,
|
||||
API_CORE_GETEXTSUPPORTEDEXTENSIONS = 10,
|
||||
API_CORE_CREATE = 20,
|
||||
API_CORE_FREE = 30,
|
||||
API_CORE_SETNEXTFILE = 40,
|
||||
API_CORE_GETSTATUS = 50,
|
||||
API_CORE_GETCURRENT = 60,
|
||||
API_CORE_GETCURPLAYBACKNUMBER = 70,
|
||||
API_CORE_GETPOSITION = 80,
|
||||
API_CORE_GETWRITEPOSITION = 90,
|
||||
API_CORE_SETPOSITION = 100,
|
||||
API_CORE_GETLENGTH = 110,
|
||||
API_CORE_GETPLUGINDATA = 120,
|
||||
API_CORE_GETVOLUME = 130,
|
||||
API_CORE_SETVOLUME = 140,
|
||||
API_CORE_GETPAN = 150,
|
||||
API_CORE_SETPAN = 160,
|
||||
API_CORE_ADDCALLBACK = 170,
|
||||
API_CORE_DELCALLBACK = 180,
|
||||
API_CORE_GETVISDATA = 190,
|
||||
API_CORE_GETLEFTVUMETER = 200,
|
||||
API_CORE_GETRIGHTVUMETER = 210,
|
||||
API_CORE_REGISTERSEQUENCER = 220,
|
||||
API_CORE_DEREGISTERSEQUENCER = 230,
|
||||
API_CORE_USERBUTTON = 240,
|
||||
API_CORE_GETEQSTATUS = 250,
|
||||
API_CORE_SETEQSTATUS = 260,
|
||||
API_CORE_GETEQPREAMP = 270,
|
||||
API_CORE_SETEQPREAMP = 280,
|
||||
API_CORE_GETEQBAND = 290,
|
||||
API_CORE_SETEQBAND = 300,
|
||||
API_CORE_GETEQAUTO = 310,
|
||||
API_CORE_SETEQAUTO = 320,
|
||||
API_CORE_SETCUSTOMMSG = 330,
|
||||
API_CORE_REGISTEREXTENSION = 340,
|
||||
API_CORE_GETEXTENSIONFAMILY = 350,
|
||||
API_CORE_UNREGISTEREXTENSION = 360,
|
||||
API_CORE_GETTITLE = 370,
|
||||
API_CORE_GETRATING = 380,
|
||||
API_CORE_SETRATING = 390,
|
||||
API_CORE_GETDECODERNAME = 400,
|
||||
API_CORE_SETTITLE = 410,
|
||||
};
|
||||
};
|
||||
|
||||
inline const wchar_t *api_core::core_getSupportedExtensions()
|
||||
{
|
||||
return _call(API_CORE_GETSUPPORTEDEXTENSIONS, (const wchar_t *)0);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_core::core_getExtSupportedExtensions()
|
||||
{
|
||||
return _call(API_CORE_GETEXTSUPPORTEDEXTENSIONS, (const wchar_t *)0);
|
||||
}
|
||||
|
||||
inline CoreToken api_core::core_create()
|
||||
{
|
||||
return _call(API_CORE_CREATE, (CoreToken)NULL);
|
||||
}
|
||||
|
||||
inline int api_core::core_free(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_FREE, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_setNextFile(CoreToken core, const wchar_t *playstring)
|
||||
{
|
||||
return _call(API_CORE_SETNEXTFILE, (int)0, core, playstring);
|
||||
}
|
||||
|
||||
inline int api_core::core_getStatus(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETSTATUS, (int)0, core);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_core::core_getCurrent(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETCURRENT, (const wchar_t *)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_getCurPlaybackNumber(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETCURPLAYBACKNUMBER, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_getPosition(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETPOSITION, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_getWritePosition(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETWRITEPOSITION, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_setPosition(CoreToken core, int ms)
|
||||
{
|
||||
return _call(API_CORE_SETPOSITION, (int)0, core, ms);
|
||||
}
|
||||
|
||||
inline int api_core::core_getLength(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETLENGTH, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_getPluginData(const wchar_t *playstring, const wchar_t *name, wchar_t *data, int data_len, int data_type)
|
||||
{
|
||||
return _call(API_CORE_GETPLUGINDATA, (int)0, playstring, name, data, data_len, data_type);
|
||||
}
|
||||
|
||||
inline unsigned int api_core::core_getVolume(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETVOLUME, (unsigned int)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setVolume(CoreToken core, unsigned int vol)
|
||||
{
|
||||
_voidcall(API_CORE_SETVOLUME, core, vol);
|
||||
}
|
||||
|
||||
inline int api_core::core_getPan(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETPAN, (int)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setPan(CoreToken core, int val)
|
||||
{
|
||||
_voidcall(API_CORE_SETPAN, core, val);
|
||||
}
|
||||
|
||||
inline void api_core::core_addCallback(CoreToken core, CoreCallback *cb)
|
||||
{
|
||||
_voidcall(API_CORE_ADDCALLBACK, core, cb);
|
||||
}
|
||||
|
||||
inline void api_core::core_delCallback(CoreToken core, CoreCallback *cb)
|
||||
{
|
||||
_voidcall(API_CORE_DELCALLBACK, core, cb);
|
||||
}
|
||||
|
||||
inline int api_core::core_getVisData(CoreToken core, void *dataptr, int sizedataptr)
|
||||
{
|
||||
return _call(API_CORE_GETVISDATA, (int)0, core, dataptr, sizedataptr);
|
||||
}
|
||||
|
||||
inline int api_core::core_getLeftVuMeter(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETLEFTVUMETER, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_getRightVuMeter(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETRIGHTVUMETER, (int)0, core);
|
||||
}
|
||||
|
||||
inline int api_core::core_registerSequencer(CoreToken core, ItemSequencer *seq)
|
||||
{
|
||||
return _call(API_CORE_REGISTERSEQUENCER, (int)0, core, seq);
|
||||
}
|
||||
|
||||
inline int api_core::core_deregisterSequencer(CoreToken core, ItemSequencer *seq)
|
||||
{
|
||||
return _call(API_CORE_DEREGISTERSEQUENCER, (int)0, core, seq);
|
||||
}
|
||||
|
||||
inline void api_core::core_userButton(CoreToken core, int button)
|
||||
{
|
||||
_voidcall(API_CORE_USERBUTTON, core, button);
|
||||
}
|
||||
|
||||
inline int api_core::core_getEqStatus(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETEQSTATUS, (int)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setEqStatus(CoreToken core, int enable)
|
||||
{
|
||||
_voidcall(API_CORE_SETEQSTATUS, core, enable);
|
||||
}
|
||||
|
||||
inline int api_core::core_getEqPreamp(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETEQPREAMP, (int)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setEqPreamp(CoreToken core, int pre)
|
||||
{
|
||||
_voidcall(API_CORE_SETEQPREAMP, core, pre);
|
||||
}
|
||||
|
||||
inline int api_core::core_getEqBand(CoreToken core, int band)
|
||||
{
|
||||
return _call(API_CORE_GETEQBAND, (int)0, core, band);
|
||||
}
|
||||
|
||||
inline void api_core::core_setEqBand(CoreToken core, int band, int val)
|
||||
{
|
||||
_voidcall(API_CORE_SETEQBAND, core, band, val);
|
||||
}
|
||||
|
||||
inline int api_core::core_getEqAuto(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETEQAUTO, (int)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setEqAuto(CoreToken core, int enable)
|
||||
{
|
||||
_voidcall(API_CORE_SETEQAUTO, core, enable);
|
||||
}
|
||||
|
||||
inline void api_core::core_setCustomMsg(CoreToken core, const wchar_t *text)
|
||||
{
|
||||
_voidcall(API_CORE_SETCUSTOMMSG, core, text);
|
||||
}
|
||||
|
||||
inline void api_core::core_registerExtension(const wchar_t *extensions, const wchar_t *extension_name, const wchar_t *family)
|
||||
{
|
||||
_voidcall(API_CORE_REGISTEREXTENSION, extensions, extension_name, family);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_core::core_getExtensionFamily(const wchar_t *extension)
|
||||
{
|
||||
return _call(API_CORE_GETEXTENSIONFAMILY, (const wchar_t *)0, extension);
|
||||
}
|
||||
|
||||
inline void api_core::core_unregisterExtension(const wchar_t *extensions)
|
||||
{
|
||||
_voidcall(API_CORE_UNREGISTEREXTENSION, extensions);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_core::core_getTitle(CoreToken core)
|
||||
{
|
||||
return _call(API_CORE_GETTITLE, (const wchar_t *)0, core);
|
||||
}
|
||||
|
||||
inline void api_core::core_setTitle(const wchar_t *new_title)
|
||||
{
|
||||
_voidcall(API_CORE_SETTITLE, new_title);
|
||||
}
|
||||
|
||||
inline int api_core::core_getRating()
|
||||
{
|
||||
return _call(API_CORE_GETRATING, (int)0);
|
||||
}
|
||||
|
||||
inline void api_core::core_setRating(int newRating)
|
||||
{
|
||||
_voidcall(API_CORE_SETRATING, newRating);
|
||||
}
|
||||
|
||||
inline const wchar_t *api_core::core_getDecoderName(const wchar_t *filename)
|
||||
{
|
||||
return _call(API_CORE_GETDECODERNAME, (const wchar_t *)0, filename);
|
||||
}
|
||||
|
||||
class api_coreI : public api_core
|
||||
{
|
||||
public:
|
||||
virtual const wchar_t *core_getSupportedExtensions() = 0;
|
||||
virtual const wchar_t *core_getExtSupportedExtensions() = 0;
|
||||
virtual CoreToken core_create() = 0;
|
||||
virtual int core_free(CoreToken core) = 0;
|
||||
virtual int core_setNextFile(CoreToken core, const wchar_t *playstring) = 0;
|
||||
virtual int core_getStatus(CoreToken core) = 0;
|
||||
virtual const wchar_t *core_getCurrent(CoreToken core) = 0;
|
||||
virtual int core_getCurPlaybackNumber(CoreToken core) = 0;
|
||||
virtual int core_getPosition(CoreToken core) = 0;
|
||||
virtual int core_getWritePosition(CoreToken core) = 0;
|
||||
virtual int core_setPosition(CoreToken core, int ms) = 0;
|
||||
virtual int core_getLength(CoreToken core) = 0;
|
||||
virtual int core_getPluginData(const wchar_t *playstring, const wchar_t *name, wchar_t *data, int data_len, int data_type = 0) = 0;
|
||||
virtual unsigned int core_getVolume(CoreToken core) = 0;
|
||||
virtual void core_setVolume(CoreToken core, unsigned int vol) = 0;
|
||||
virtual int core_getPan(CoreToken core) = 0;
|
||||
virtual void core_setPan(CoreToken core, int val) = 0;
|
||||
virtual void core_addCallback(CoreToken core, CoreCallback *cb) = 0;
|
||||
virtual void core_delCallback(CoreToken core, CoreCallback *cb) = 0;
|
||||
virtual int core_getVisData(CoreToken core, void *dataptr, int sizedataptr) = 0;
|
||||
virtual int core_getLeftVuMeter(CoreToken core) = 0;
|
||||
virtual int core_getRightVuMeter(CoreToken core) = 0;
|
||||
virtual int core_registerSequencer(CoreToken core, ItemSequencer *seq) = 0;
|
||||
virtual int core_deregisterSequencer(CoreToken core, ItemSequencer *seq) = 0;
|
||||
virtual void core_userButton(CoreToken core, int button) = 0;
|
||||
virtual int core_getEqStatus(CoreToken core) = 0;
|
||||
virtual void core_setEqStatus(CoreToken core, int enable) = 0;
|
||||
virtual int core_getEqPreamp(CoreToken core) = 0;
|
||||
virtual void core_setEqPreamp(CoreToken core, int pre) = 0;
|
||||
virtual int core_getEqBand(CoreToken core, int band) = 0;
|
||||
virtual void core_setEqBand(CoreToken core, int band, int val) = 0;
|
||||
virtual int core_getEqAuto(CoreToken core) = 0;
|
||||
virtual void core_setEqAuto(CoreToken core, int enable) = 0;
|
||||
virtual void core_setCustomMsg(CoreToken core, const wchar_t *text) = 0;
|
||||
virtual void core_registerExtension(const wchar_t *extensions, const wchar_t *extension_name, const wchar_t *family = NULL) = 0;
|
||||
virtual const wchar_t *core_getExtensionFamily(const wchar_t *extension) = 0;
|
||||
virtual void core_unregisterExtension(const wchar_t *extensions) = 0;
|
||||
virtual const wchar_t *core_getTitle(CoreToken core) = 0;
|
||||
virtual void core_setTitle(const wchar_t *new_title) = 0;
|
||||
virtual int core_getRating()=0;
|
||||
virtual void core_setRating(int newRating)=0;
|
||||
virtual const wchar_t *core_getDecoderName(const wchar_t *filename)=0;
|
||||
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
// {966E3DA1-C2C5-43a9-A931-EB5F8B040A4F}
|
||||
static const GUID coreApiServiceGuid =
|
||||
{ 0x966e3da1, 0xc2c5, 0x43a9, { 0xa9, 0x31, 0xeb, 0x5f, 0x8b, 0x4, 0xa, 0x4f } };
|
||||
|
||||
extern api_core *coreApi;
|
||||
|
||||
#endif
|
18
Src/Wasabi/api/core/buttons.h
Normal file
18
Src/Wasabi/api/core/buttons.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef _BUTTONS_H
|
||||
#define _BUTTONS_H
|
||||
|
||||
// codes for
|
||||
|
||||
namespace UserButton {
|
||||
enum {
|
||||
PREV=0,
|
||||
PLAY,
|
||||
PAUSE,
|
||||
STOP,
|
||||
NEXT,
|
||||
};
|
||||
const int first = PREV;
|
||||
const int last = NEXT;
|
||||
};
|
||||
|
||||
#endif
|
181
Src/Wasabi/api/core/coreactions.cpp
Normal file
181
Src/Wasabi/api/core/coreactions.cpp
Normal file
|
@ -0,0 +1,181 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "coreactions.h"
|
||||
|
||||
#include <api/config/items/cfgitem.h>
|
||||
#include <api/core/buttons.h>
|
||||
#include <api/api.h>
|
||||
#include <api/core/corehandle.h>
|
||||
#include <api/service/svcs/svc_player.h>
|
||||
#include <api/locales/xlatstr.h>
|
||||
|
||||
CoreActions::CoreActions() {
|
||||
registerAction("prev", ACTION_PREV);
|
||||
registerAction("play", ACTION_PLAY);
|
||||
registerAction("pause", ACTION_PAUSE);
|
||||
registerAction("stop", ACTION_STOP);
|
||||
registerAction("next", ACTION_NEXT);
|
||||
registerAction("eject", ACTION_EJECT);
|
||||
registerAction("eject_url", ACTION_EJECTURL);
|
||||
registerAction("eject_dir", ACTION_EJECTDIR);
|
||||
registerAction("seek", ACTION_SEEK);
|
||||
registerAction("volume", ACTION_VOLUME);
|
||||
registerAction("pan", ACTION_PAN);
|
||||
registerAction("volume_up", ACTION_VOLUME_UP);
|
||||
registerAction("volume_down", ACTION_VOLUME_DOWN);
|
||||
registerAction("rewind_5s", ACTION_REWIND_5S);
|
||||
registerAction("ffwd_5s", ACTION_FFWD_5S);
|
||||
registerAction("toggle_repeat", ACTION_TOGGLE_REPEAT);
|
||||
registerAction("toggle_shuffle", ACTION_TOGGLE_SHUFFLE);
|
||||
registerAction("toggle_crossfader", ACTION_TOGGLE_CROSSFADER);
|
||||
registerAction("mute", ACTION_MUTE);
|
||||
registerAction("eq_preamp", ACTION_EQ_PREAMP);
|
||||
registerAction("eq_band", ACTION_EQ_BAND);
|
||||
registerAction("eq_auto", ACTION_EQ_AUTO);
|
||||
registerAction("eq_reset", ACTION_EQ_RESET);
|
||||
registerAction("toggle_repeat", ACTION_TOGGLE_REPEAT);
|
||||
registerAction("toggle_shuffle", ACTION_TOGGLE_SHUFFLE);
|
||||
registerAction("toggle_crossfader", ACTION_TOGGLE_CROSSFADER);
|
||||
registerAction("eq_toggle", ACTION_EQ_TOGGLE);
|
||||
for (int i=0;i<4;i++)
|
||||
registerAction(StringPrintf("play_cd%d", i+1), ACTION_PLAY_CD+i);
|
||||
}
|
||||
|
||||
CoreActions::~CoreActions() {
|
||||
}
|
||||
|
||||
int CoreActions::onActionId(int pvtid, const char *action, const char *param/* =NULL */, int p1/* =0 */, int p2/* =0 */, void *data/* =NULL */, int datalen/* =0 */, api_window *source/* =NULL */) {
|
||||
int d = ATOI(param);
|
||||
CoreHandle ch("main");
|
||||
switch(pvtid) {
|
||||
case ACTION_PREV: { if (d==0) ch.prev(); } break;
|
||||
case ACTION_PLAY: { if (d==0) ch.play(); } break;
|
||||
case ACTION_PAUSE: { if (d==0) ch.pause(); } break;
|
||||
case ACTION_STOP: { if (d==0) ch.stop(); } break;
|
||||
case ACTION_NEXT: { if (d==0) ch.next(); } break;
|
||||
|
||||
case ACTION_EJECT: {
|
||||
svc_player *sp = SvcEnumByGuid<svc_player>();
|
||||
if (d == 0) {
|
||||
if (sp) sp->openFiles(source, "files");
|
||||
} else {
|
||||
if (sp) sp->openFiles(source);
|
||||
}
|
||||
WASABI_API_SVC->service_release(sp);
|
||||
}
|
||||
break;
|
||||
case ACTION_EJECTURL: if (d==0) {
|
||||
svc_player *sp = SvcEnumByGuid<svc_player>();
|
||||
if (sp) sp->openFiles(source, "location");
|
||||
api->service_release(sp);
|
||||
}
|
||||
break;
|
||||
case ACTION_EJECTDIR: if (d==0) {
|
||||
svc_player *sp = SvcEnumByGuid<svc_player>();
|
||||
if (sp) sp->openFiles(source, "directory");
|
||||
api->service_release(sp);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_VOLUME_UP: if (d==0) {
|
||||
int v=ch.getVolume();
|
||||
ch.setVolume(MIN(255,(v+5)));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_VOLUME_DOWN: if (d==0) {
|
||||
int v=ch.getVolume();
|
||||
ch.setVolume(MAX(0,(v-5)));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_REWIND_5S: if (d==0) {
|
||||
int p=ch.getPosition();
|
||||
ch.setPosition(MAX(0,(p-5000)));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_FFWD_5S: if (d==0) {
|
||||
int p=ch.getPosition();
|
||||
int mp=ch.getLength();
|
||||
ch.setPosition(MIN(mp,(p+5000)));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_EQ_AUTO:
|
||||
if (d==0) ch.setEqAuto(!ch.getEqAuto());
|
||||
break;
|
||||
|
||||
case ACTION_EQ_RESET: {
|
||||
if (d==0) for(int i=0;i<10;i++) ch.setEqBand(i,0);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_EQ_TOGGLE: if (d==0) ch.setEqStatus(!ch.getEqStatus()); break;
|
||||
|
||||
case ACTION_MUTE: if (d==0) {
|
||||
ch.setMute(!ch.getMute());;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_TOGGLE_REPEAT:
|
||||
case ACTION_TOGGLE_SHUFFLE: if (d==0) {
|
||||
// {45F3F7C1-A6F3-4ee6-A15E-125E92FC3F8D}
|
||||
const GUID pledit_guid =
|
||||
{ 0x45f3f7c1, 0xa6f3, 0x4ee6, { 0xa1, 0x5e, 0x12, 0x5e, 0x92, 0xfc, 0x3f, 0x8d } };
|
||||
CfgItem *pli=WASABI_API_CONFIG->config_getCfgItemByGuid(pledit_guid);
|
||||
if(pli) {
|
||||
if(pvtid==ACTION_TOGGLE_REPEAT) pli->setDataAsInt("Repeat",!pli->getDataAsInt("Repeat"));
|
||||
if(pvtid==ACTION_TOGGLE_SHUFFLE) pli->setDataAsInt("Shuffle",!pli->getDataAsInt("Shuffle"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTION_TOGGLE_CROSSFADER: if (d==0) {
|
||||
// {FC3EAF78-C66E-4ED2-A0AA-1494DFCC13FF}
|
||||
const GUID xfade_guid =
|
||||
{ 0xFC3EAF78, 0xC66E, 0x4ED2, { 0xA0, 0xAA, 0x14, 0x94, 0xDF, 0xCC, 0x13, 0xFF } };
|
||||
CfgItem *pli=WASABI_API_CONFIG->config_getCfgItemByGuid(xfade_guid);
|
||||
if(pli) pli->setDataAsInt("Enable crossfading",!pli->getDataAsInt("Enable crossfading"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pvtid >= ACTION_PLAY_CD && pvtid < ACTION_PLAY_CD+16) if (d==0) {
|
||||
const GUID cdda_guid =
|
||||
{ 0x86b40069, 0x126f, 0x4e11, { 0xa8, 0x7f, 0x55, 0x8f, 0xfa, 0x3d, 0xff, 0xa8 } };
|
||||
#if 0//BU: need some api to send messages like this
|
||||
ComponentManager::sendNotify(cdda_guid, 12345, pvtid-ACTION_PLAY_CD);
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *CoreActions::getHelp(int action) {
|
||||
static String name;
|
||||
switch (action) {
|
||||
case ACTION_PREV: name = _("Previous track"); break;
|
||||
case ACTION_PAUSE: name = _("Pause/Resume playback"); break;
|
||||
case ACTION_STOP: name = _("Stop playback"); break;
|
||||
case ACTION_NEXT: name = _("Next track"); break;
|
||||
case ACTION_EJECT: name = _("Load file"); break;
|
||||
case ACTION_EJECTURL: name = _("Load URL"); break;
|
||||
case ACTION_EJECTDIR: name = _("Load directory"); break;
|
||||
case ACTION_SEEK: name = _("Seek"); break;
|
||||
case ACTION_VOLUME: name = _("Volume"); break;
|
||||
case ACTION_PAN: name = _("Panning"); break;
|
||||
case ACTION_EQ_TOGGLE: name = _("Toggle equalizer"); break;
|
||||
case ACTION_EQ_PREAMP: name = _("Toggle preamplifier"); break;
|
||||
case ACTION_EQ_BAND: name = _("Change equalizer band"); break;
|
||||
case ACTION_EQ_AUTO: name = _("Auto equalizer"); break;
|
||||
case ACTION_EQ_RESET: name = _("Reset equalizer"); break;
|
||||
case ACTION_VOLUME_UP: name = _("Volume up"); break;
|
||||
case ACTION_VOLUME_DOWN: name = _("Volume down"); break;
|
||||
case ACTION_REWIND_5S: name = _("Rewind 5 seconds"); break;
|
||||
case ACTION_FFWD_5S: name = _("Fast forward 5 seconds"); break;
|
||||
case ACTION_MUTE: name = _("Mute/Unmute sound"); break;
|
||||
case ACTION_TOGGLE_REPEAT: name = _("Toggle repeat"); break;
|
||||
case ACTION_TOGGLE_SHUFFLE: name = _("Toggle shuffle"); break;
|
||||
case ACTION_TOGGLE_CROSSFADER: name = _("Toggle crossfader"); break;
|
||||
}
|
||||
return name;
|
||||
}
|
47
Src/Wasabi/api/core/coreactions.h
Normal file
47
Src/Wasabi/api/core/coreactions.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef __COREACTIONS_H
|
||||
#define __COREACTIONS_H
|
||||
|
||||
#include <api/service/svcs/svc_action.h>
|
||||
|
||||
class CoreActions : public svc_actionI {
|
||||
public :
|
||||
CoreActions();
|
||||
virtual ~CoreActions();
|
||||
|
||||
static const char *getServiceName() { return "Core Actions"; }
|
||||
virtual int onActionId(int pvtid, const wchar_t *action, const wchar_t *param=NULL, int p1=0, int p2=0, void *data=NULL, int datalen=0, ifc_window *source=NULL);
|
||||
virtual const wchar_t *getHelp(int action);
|
||||
|
||||
private:
|
||||
|
||||
enum {
|
||||
ACTION_PREV = 0,
|
||||
ACTION_PLAY,
|
||||
ACTION_PAUSE,
|
||||
ACTION_STOP,
|
||||
ACTION_NEXT,
|
||||
ACTION_EJECT,
|
||||
ACTION_EJECTURL,
|
||||
ACTION_EJECTDIR,
|
||||
ACTION_SEEK,
|
||||
ACTION_VOLUME,
|
||||
ACTION_EQ_TOGGLE,
|
||||
ACTION_EQ_PREAMP,
|
||||
ACTION_EQ_BAND,
|
||||
ACTION_VOLUME_UP,
|
||||
ACTION_VOLUME_DOWN,
|
||||
ACTION_REWIND_5S,
|
||||
ACTION_FFWD_5S,
|
||||
ACTION_PLAY_CD,
|
||||
ACTION_EQ_AUTO = ACTION_PLAY_CD+16,
|
||||
ACTION_EQ_RESET,
|
||||
ACTION_PAN,
|
||||
ACTION_MUTE,
|
||||
ACTION_TOGGLE_REPEAT,
|
||||
ACTION_TOGGLE_SHUFFLE,
|
||||
ACTION_TOGGLE_CROSSFADER,
|
||||
ACTION_PREFS,
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
304
Src/Wasabi/api/core/corehandle.cpp
Normal file
304
Src/Wasabi/api/core/corehandle.cpp
Normal file
|
@ -0,0 +1,304 @@
|
|||
#include <precomp.h>
|
||||
|
||||
#include "corehandle.h"
|
||||
|
||||
#include <api/api.h>
|
||||
#include <api/core/buttons.h>
|
||||
#include <api/service/svcs/svc_coreadmin.h>
|
||||
#include <api/service/svc_enum.h> // for castService
|
||||
|
||||
using namespace UserButton;
|
||||
|
||||
static svc_coreAdmin *da_coreadmin=NULL;
|
||||
static int instancecount=0;
|
||||
|
||||
static void initDaCoreAdmin() {
|
||||
if(!da_coreadmin) {
|
||||
if (WASABI_API_SVC != NULL) {
|
||||
waServiceFactory *s=WASABI_API_SVC->service_enumService(WaSvc::COREADMIN,0);
|
||||
if (s != NULL) {
|
||||
//CUT ASSERTPR(s,"Core Admin non present!");
|
||||
da_coreadmin=castService<svc_coreAdmin>(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CoreHandle::CoreHandle(CoreToken tok) {
|
||||
initDaCoreAdmin();
|
||||
instancecount++;
|
||||
createdcore=0;
|
||||
token = NO_CORE_TOKEN;
|
||||
if (da_coreadmin) {
|
||||
if(da_coreadmin->verifyToken(tok)) token=tok;
|
||||
else {
|
||||
token=da_coreadmin->createCore();
|
||||
createdcore=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CoreHandle::CoreHandle(const char *name) {
|
||||
initDaCoreAdmin();
|
||||
instancecount++;
|
||||
createdcore=0;
|
||||
token = NO_CORE_TOKEN;
|
||||
if (da_coreadmin) {
|
||||
token=da_coreadmin->nameToToken(name);
|
||||
if(token==-1) {
|
||||
token=da_coreadmin->createCore(name);
|
||||
createdcore=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CoreHandle::~CoreHandle() {
|
||||
instancecount--;
|
||||
if (da_coreadmin) {
|
||||
if(createdcore) da_coreadmin->freeCoreByToken(token);
|
||||
if(!instancecount) {
|
||||
WASABI_API_SVC->service_release(da_coreadmin);
|
||||
da_coreadmin=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CoreHandle::isCoreLoaded() {
|
||||
if (!da_coreadmin) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int CoreHandle::setNextFile(const char *playstring, const char *destination) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->setNextFile(token, playstring, destination);
|
||||
}
|
||||
|
||||
void CoreHandle::prev() {
|
||||
userButton(PREV);
|
||||
}
|
||||
|
||||
void CoreHandle::play() {
|
||||
userButton(PLAY);
|
||||
}
|
||||
|
||||
void CoreHandle::pause() {
|
||||
userButton(PAUSE);
|
||||
}
|
||||
|
||||
void CoreHandle::stop() {
|
||||
userButton(STOP);
|
||||
}
|
||||
|
||||
void CoreHandle::next() {
|
||||
userButton(NEXT);
|
||||
}
|
||||
|
||||
void CoreHandle::userButton(int button) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->userButton(token, button);
|
||||
}
|
||||
|
||||
const char *CoreHandle::getSupportedExtensions() {
|
||||
if (da_coreadmin == NULL) return "";
|
||||
return da_coreadmin->getSupportedExtensions();
|
||||
}
|
||||
|
||||
const char *CoreHandle::getExtSupportedExtensions() {
|
||||
if (da_coreadmin == NULL) return "";
|
||||
return da_coreadmin->getExtSupportedExtensions();
|
||||
}
|
||||
|
||||
const char *CoreHandle::getExtensionFamily(const char *extension) {
|
||||
if (da_coreadmin == NULL) return "";
|
||||
return da_coreadmin->getExtensionFamily(extension);
|
||||
}
|
||||
|
||||
void CoreHandle::registerExtension(const char *extensions, const char *extension_name) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->registerExtension(extensions, extension_name);
|
||||
}
|
||||
|
||||
void CoreHandle::unregisterExtension(const char *extensions) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->unregisterExtension(extensions);
|
||||
}
|
||||
|
||||
String CoreHandle::getTitle() {
|
||||
if (da_coreadmin == NULL) return String("");
|
||||
return String(da_coreadmin->getTitle(token));
|
||||
}
|
||||
|
||||
int CoreHandle::getStatus() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getStatus(token);
|
||||
}
|
||||
|
||||
const char *CoreHandle::getCurrent() {
|
||||
if (da_coreadmin == NULL) return "";
|
||||
return da_coreadmin->getCurrent(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getNumTracks() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getNumTracks(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getCurPlaybackNumber() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getCurPlaybackNumber(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getPosition() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getPosition(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getWritePosition() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getWritePosition(token);
|
||||
}
|
||||
|
||||
int CoreHandle::setPosition(int ms) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->setPosition(token,ms);
|
||||
}
|
||||
|
||||
int CoreHandle::getLength() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getLength(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getPluginData(const char *playstring, const char *name, char *data, int data_len, int data_type) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getPluginData(playstring, name, data, data_len, data_type);
|
||||
}
|
||||
|
||||
unsigned int CoreHandle::getVolume() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getVolume(token);
|
||||
}
|
||||
|
||||
void CoreHandle::setVolume(unsigned int vol) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setVolume(token, vol);
|
||||
}
|
||||
|
||||
int CoreHandle::getPan() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getPan(token);
|
||||
}
|
||||
|
||||
void CoreHandle::setPan(int bal) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setPan(token, bal);
|
||||
}
|
||||
|
||||
void CoreHandle::setMute(int mute) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setMute(token, mute);
|
||||
}
|
||||
|
||||
int CoreHandle::getMute() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getMute(token);
|
||||
}
|
||||
|
||||
void CoreHandle::addCallback(CoreCallback *cb) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->addCallback(token, cb);
|
||||
}
|
||||
|
||||
void CoreHandle::delCallback(CoreCallback *cb) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->delCallback(token, cb);
|
||||
}
|
||||
|
||||
int CoreHandle::getVisData(void *dataptr, int sizedataptr) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getVisData(token, dataptr, sizedataptr);
|
||||
}
|
||||
|
||||
int CoreHandle::getLeftVuMeter() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getLeftVuMeter(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getRightVuMeter() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getRightVuMeter(token);
|
||||
}
|
||||
|
||||
int CoreHandle::registerSequencer(ItemSequencer *seq) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->registerSequencer(token, seq);
|
||||
}
|
||||
|
||||
int CoreHandle::deregisterSequencer(ItemSequencer *seq) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->deregisterSequencer(token, seq);
|
||||
}
|
||||
|
||||
ItemSequencer *CoreHandle::getSequencer() {
|
||||
if (da_coreadmin == NULL) return NULL;
|
||||
return da_coreadmin->getSequencer(token);
|
||||
}
|
||||
|
||||
int CoreHandle::getEqStatus() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getEqStatus(token);
|
||||
}
|
||||
|
||||
void CoreHandle::setEqStatus(int enable) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setEqStatus(token, enable);
|
||||
}
|
||||
|
||||
int CoreHandle::getEqPreamp() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getEqPreamp(token);
|
||||
}
|
||||
|
||||
void CoreHandle::setEqPreamp(int pre) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setEqPreamp(token, pre);
|
||||
}
|
||||
|
||||
int CoreHandle::getEqBand(int band) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getEqBand(token, band);
|
||||
}
|
||||
|
||||
void CoreHandle::setEqBand(int band, int val) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setEqBand(token, band, val);
|
||||
}
|
||||
|
||||
int CoreHandle::getEqAuto() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getEqAuto(token);
|
||||
}
|
||||
|
||||
void CoreHandle::setEqAuto(int enable) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setEqAuto(token, enable);
|
||||
}
|
||||
|
||||
void CoreHandle::setPriority(int priority) {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->setPriority(token, priority);
|
||||
}
|
||||
|
||||
int CoreHandle::getPriority() {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->getPriority(token);
|
||||
}
|
||||
|
||||
void CoreHandle::rebuildConvertersChain() {
|
||||
if (da_coreadmin == NULL) return;
|
||||
da_coreadmin->rebuildConvertersChain(token);
|
||||
}
|
||||
|
||||
int CoreHandle::sendConvertersMsg(const char *msg, const char *value) {
|
||||
if (da_coreadmin == NULL) return 0;
|
||||
return da_coreadmin->sendConvertersMsg(token, msg, value);
|
||||
}
|
560
Src/Wasabi/api/core/corehandle.h
Normal file
560
Src/Wasabi/api/core/corehandle.h
Normal file
|
@ -0,0 +1,560 @@
|
|||
#ifndef _COREHANDLE_H
|
||||
#define _COREHANDLE_H
|
||||
|
||||
#include <api/syscb/callbacks/corecb.h>
|
||||
|
||||
// a helper class to access the playback cores within an object for you
|
||||
|
||||
typedef unsigned int CoreToken;
|
||||
#define NO_CORE_TOKEN (CoreToken)(0xffffffff)
|
||||
|
||||
// Fwd References
|
||||
class CfgItem;
|
||||
class ItemSequencer;
|
||||
|
||||
/**
|
||||
Helper class to access the currently instantiated
|
||||
playback cores.
|
||||
|
||||
To create a corehandle on the main playback core
|
||||
use the core token value from the enum ("maincore_token") or
|
||||
the core name "main".
|
||||
|
||||
Here is an example:
|
||||
CoreHandle * ch = new CoreHandle("main");
|
||||
|
||||
@short Access playback cores.
|
||||
@author Nullsoft
|
||||
@ver 1.0
|
||||
@see Core
|
||||
*/
|
||||
class CoreHandle {
|
||||
public:
|
||||
enum { maincore_token=0 };
|
||||
|
||||
/**
|
||||
Create a new CoreHandle while optionally
|
||||
setting the core token to be used.
|
||||
|
||||
Core tokens are handles to cores
|
||||
currently instantiated.
|
||||
|
||||
@see CoreHandle(const char *name)
|
||||
@param token Core token of the core to attach to.
|
||||
*/
|
||||
CoreHandle(CoreToken token=maincore_token);
|
||||
|
||||
/**
|
||||
Create a new CoreHandle for a core
|
||||
using it's name.
|
||||
|
||||
The main core name is "main".
|
||||
|
||||
@see CoreHandle(CoreToken toke=maincore_token)
|
||||
@param name Name of the core to attach to.
|
||||
*/
|
||||
CoreHandle(const wchar_t *name);
|
||||
|
||||
/**
|
||||
Detaches the CoreHandle from the Core.
|
||||
*/
|
||||
virtual ~CoreHandle();
|
||||
|
||||
int isCoreLoaded(); // are we attached to a core?
|
||||
|
||||
/**
|
||||
Get the list of supported extensions
|
||||
from the core. This is a zero delimited list
|
||||
with double zero termination.
|
||||
|
||||
@see getExtSupportedExtensions()
|
||||
@see getExtensionFamily()
|
||||
@ret List of supported extensions.
|
||||
*/
|
||||
const char *getSupportedExtensions(); //just the *.mp3 or whatever
|
||||
|
||||
/**
|
||||
Get the extended list of supported extensions
|
||||
from the core. This will include the proper
|
||||
names of the extensions, for example:
|
||||
"MP3 Files (*.mp3)".
|
||||
|
||||
This is returned as a zero delimited list with double
|
||||
zero termination.
|
||||
|
||||
@see getSupportedExtensions()
|
||||
@see getExtensionFamily()
|
||||
@ret Extended list of supported extensions.
|
||||
*/
|
||||
const char *getExtSupportedExtensions(); // including names
|
||||
|
||||
/**
|
||||
Get the family name to which the extension
|
||||
is associated with (Families are "Audio", "Video", etc.)
|
||||
|
||||
@see getExtSupportedExtensions()
|
||||
@see getSupportedExtensions()
|
||||
@ret Family name of the extension.
|
||||
@param extension Extension to get family name of.
|
||||
*/
|
||||
const wchar_t *getExtensionFamily(const wchar_t *extension);
|
||||
|
||||
/**
|
||||
Register an extension with the core.
|
||||
|
||||
@see unregisterExtension()
|
||||
@see getExtSupportedExtensions()
|
||||
@see getSupportedExtensions()
|
||||
@see getExtensionFamily()
|
||||
@param extensions Extension to register.
|
||||
@param extension_name Name of the extension.
|
||||
*/
|
||||
void registerExtension(const char *extensions, const char *extension_name);
|
||||
|
||||
/**
|
||||
Unregister an extension with the core.
|
||||
|
||||
@see registerExtension()
|
||||
@see getExtSupportedExtensions()
|
||||
@see getSupportedExtensions()
|
||||
@see getExtensionFamily()
|
||||
@param extensions Extension to unregister.
|
||||
*/
|
||||
void unregisterExtension(const char *extensions);
|
||||
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
Set the next file to be played by the core.
|
||||
|
||||
You can manually select the output of this
|
||||
file. Either "WAVEOUT" or "DIRECTSOUND". If
|
||||
you do not specify one, it will be automatically
|
||||
selected for you.
|
||||
|
||||
@ret 1, success; 0, failure;
|
||||
@param playstring Playstring of the next file to be played.
|
||||
@param destination Output to be used for the next file.
|
||||
*/
|
||||
int setNextFile(const char *playstring, const char *destination=NULL);
|
||||
|
||||
/**
|
||||
Get the playback status of the core.
|
||||
|
||||
@see pause()
|
||||
@see play()
|
||||
@see stop()
|
||||
@ret -1, Paused; 0, Stopped; 1, Playing;
|
||||
*/
|
||||
int getStatus(); // returns -1 if paused, 0 if stopped and 1 if playing
|
||||
|
||||
/**
|
||||
Get the playstring of the currently playing
|
||||
item.
|
||||
|
||||
@ret Playstring of the currently playing item.
|
||||
*/
|
||||
const char *getCurrent();
|
||||
|
||||
/**
|
||||
Get the number of items (tracks) present
|
||||
in the currently registered sequencer.
|
||||
|
||||
@see getCurPlaybackNumber()
|
||||
@ret Number of items present in the sequencer.
|
||||
*/
|
||||
int getNumTracks();
|
||||
|
||||
/**
|
||||
Get the index number of the currently
|
||||
playing item of the currently registered
|
||||
sequencer.
|
||||
|
||||
@see getNumTracks()
|
||||
@ret Index number (in the sequencer) of the item playing.
|
||||
*/
|
||||
int getCurPlaybackNumber();
|
||||
|
||||
/**
|
||||
Get the playback position of the currently
|
||||
playing file.
|
||||
|
||||
@see getWritePosition()
|
||||
@see getLength()
|
||||
@see setPosition()
|
||||
@ret Position in the file (in milliseconds).
|
||||
*/
|
||||
int getPosition();
|
||||
|
||||
/**
|
||||
Help?
|
||||
|
||||
@see getPosition()
|
||||
@see getLength()
|
||||
@see setPosition()
|
||||
@ret Current write position (in milliseconds).
|
||||
*/
|
||||
int getWritePosition();
|
||||
|
||||
/**
|
||||
Seek to a specific position in the
|
||||
currently playing item.
|
||||
|
||||
@see getPosition()
|
||||
@see getLength()
|
||||
@see getWritePosition()
|
||||
@ret 1, Success; 0, Failure;
|
||||
@param ms Position in the file (in milliseconds, 0 being the beginning).
|
||||
*/
|
||||
int setPosition(int ms);
|
||||
|
||||
/**
|
||||
Get the length of the currently
|
||||
playing item.
|
||||
|
||||
@see getPosition()
|
||||
@see setPosition()
|
||||
@see getWritePosition()
|
||||
@ret Length of the item (in milliseconds).
|
||||
*/
|
||||
int getLength();
|
||||
|
||||
// this method queries the core plugins directly, bypassing the db
|
||||
/**
|
||||
*/
|
||||
int getPluginData(const char *playstring, const char *name,
|
||||
char *data, int data_len, int data_type=0); // returns size of data
|
||||
|
||||
/**
|
||||
Get the volume of the core.
|
||||
|
||||
@see setVolume()
|
||||
@see getMute()
|
||||
@see setMute()
|
||||
@ret Volume (0 to 255).
|
||||
*/
|
||||
unsigned int getVolume(); // 0..255
|
||||
|
||||
/**
|
||||
Set the volume of the core.
|
||||
|
||||
@see getVolume()
|
||||
@see getMute()
|
||||
@see setMute()
|
||||
@param vol Volume (0 to 255).
|
||||
*/
|
||||
void setVolume(unsigned int vol); // 0..255
|
||||
|
||||
/**
|
||||
Get the panning value of the core.
|
||||
|
||||
@see setPan()
|
||||
@ret Panning value (-127 [left] to 127 [right]).
|
||||
*/
|
||||
int getPan(); // -127..127
|
||||
|
||||
/**
|
||||
Set the panning value of the core.
|
||||
|
||||
@see getPan()
|
||||
@param bal Panning value (-127 [left] to 127 [right])
|
||||
*/
|
||||
void setPan(int bal); // -127..127
|
||||
|
||||
/**
|
||||
Mute the output.
|
||||
|
||||
@see getVolume()
|
||||
@see setVolume()
|
||||
@see getMute()
|
||||
@param mute 0, No muting; 1, Mute;
|
||||
*/
|
||||
void setMute(int mute);
|
||||
|
||||
/**
|
||||
Get the mute state of the output.
|
||||
@see getVolume()
|
||||
@see setVolume()
|
||||
@see setMute()
|
||||
@ret 0, Not muted; 1, Muted;
|
||||
*/
|
||||
int getMute();
|
||||
|
||||
// register here for general callbacks in core status.
|
||||
/**
|
||||
Register a callback with the core to
|
||||
receive core status callbacks.
|
||||
|
||||
@see delCallback()
|
||||
@param cb Core Callback to register.
|
||||
*/
|
||||
void addCallback(CoreCallback *cb);
|
||||
|
||||
/**
|
||||
Unregister a callback with the core.
|
||||
|
||||
@see addCallback()
|
||||
@param cb Core Callback to unregister.
|
||||
*/
|
||||
void delCallback(CoreCallback *cb);
|
||||
|
||||
// get visualization data, returns 0 if you should blank out
|
||||
/**
|
||||
Get visualization data for the currently
|
||||
playing item.
|
||||
|
||||
We suggest using a struct like this to read the vis
|
||||
data:
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
LEFT = 0,
|
||||
RIGHT = 1
|
||||
};
|
||||
unsigned char spectrumData[2][576];
|
||||
char waveformData[2][576];
|
||||
} VisData;
|
||||
|
||||
A call using this struct would like so:
|
||||
|
||||
getVisData(&myVisData, sizeof(VisData));
|
||||
|
||||
@see getLeftVuMeter()
|
||||
@see getRightVuMeter()
|
||||
@ret 0, If there is no VIS data; > 0, VIS data available;
|
||||
@param dataptr Buffer to receive VIS data.
|
||||
@param sizedataptr Size of the buffer.
|
||||
*/
|
||||
int getVisData(void *dataptr, int sizedataptr);
|
||||
|
||||
/**
|
||||
Get the value of the left VU meter.
|
||||
|
||||
@see getVisData()
|
||||
@see getRightVuMeter()
|
||||
@ret Value of the left VU meter (0 to 255).
|
||||
*/
|
||||
int getLeftVuMeter();
|
||||
|
||||
/**
|
||||
Get the value of the left VU meter.
|
||||
|
||||
@see getVisData()
|
||||
@see getLeftVuMeter()
|
||||
@ret Value of the right VU meter (0 to 255).
|
||||
*/
|
||||
int getRightVuMeter();
|
||||
|
||||
/**
|
||||
Register an item sequencer with the core.
|
||||
The item sequencer feeds the playstrings
|
||||
of the next item to be played to the core.
|
||||
|
||||
@see deregisterSequencer()
|
||||
@ret 1, Success; 0, Failure;
|
||||
@param seq Sequencer to register.
|
||||
*/
|
||||
int registerSequencer(ItemSequencer *seq);
|
||||
|
||||
/**
|
||||
Unregister a sequencer with the core.
|
||||
|
||||
@see registerSequencer()
|
||||
@ret 1, Success; 0, Failure;
|
||||
@param seq Sequencer to unregister.
|
||||
*/
|
||||
int deregisterSequencer(ItemSequencer *seq);
|
||||
|
||||
ItemSequencer *getSequencer();
|
||||
|
||||
/**
|
||||
Get the EQ status.
|
||||
|
||||
@see setEqStatus()
|
||||
@see getEqPreamp()
|
||||
@see setEqPreamp()
|
||||
@see getEqBand()
|
||||
@see setEqBand()
|
||||
@ret 1, On; 0, Off;
|
||||
*/
|
||||
int getEqStatus(); // returns 1 if on, 0 if off
|
||||
|
||||
/**
|
||||
Set the EQ state.
|
||||
|
||||
@see getEqStatus()
|
||||
@see getEqPreamp()
|
||||
@see setEqPreamp()
|
||||
@see getEqBand()
|
||||
@see setEqBand()
|
||||
@param enable 1, On; 0, Off;
|
||||
*/
|
||||
void setEqStatus(int enable);
|
||||
|
||||
/**
|
||||
Get the pre-amp value of the EQ.
|
||||
|
||||
@see setEqStatus()
|
||||
@see getEqStatus()
|
||||
@see setEqPreamp()
|
||||
@see getEqBand()
|
||||
@see setEqBand()
|
||||
@ret Pre-amp value (-127 [-20dB] to 127 [+20dB]).
|
||||
*/
|
||||
int getEqPreamp(); // -127 to 127 (-20db to +20db)
|
||||
|
||||
/**
|
||||
Set the pre-amp value of the EQ.
|
||||
|
||||
@see setEqStatus()
|
||||
@see getEqStatus()
|
||||
@see getEqPreamp()
|
||||
@see getEqBand()
|
||||
@see setEqBand()
|
||||
@param pre Pre-amp value (-127 [-20dB] to 127 [+20dB]).
|
||||
*/
|
||||
void setEqPreamp(int pre);
|
||||
|
||||
/**
|
||||
Get the value of an EQ band. There
|
||||
are 10 bands available.
|
||||
|
||||
Here is the list:
|
||||
|
||||
0 - 60 Hz 1 - 170 Hz
|
||||
2 - 310 Hz 3 - 600 Hz
|
||||
4 - 1 kHz 5 - 3 kHz
|
||||
6 - 6 kHz 7 - 12 kHz
|
||||
8 - 14 kHz 9 - 16 kHz
|
||||
|
||||
@see setEqStatus()
|
||||
@see getEqStatus()
|
||||
@see getEqPreamp()
|
||||
@see setEqBand()
|
||||
@ret EQ band value (-127 [-20dB] to 127 [+20dB]).
|
||||
@param band EQ band to read (0 to 9).
|
||||
*/
|
||||
int getEqBand(int band); // band=0-9
|
||||
|
||||
/**
|
||||
Set the value of an EQ band. There
|
||||
are 10 bands available.
|
||||
|
||||
Here is the list:
|
||||
|
||||
0 - 60 Hz 1 - 170 Hz
|
||||
2 - 310 Hz 3 - 600 Hz
|
||||
4 - 1 kHz 5 - 3 kHz
|
||||
6 - 6 kHz 7 - 12 kHz
|
||||
8 - 14 kHz 9 - 16 kHz
|
||||
|
||||
@see setEqStatus()
|
||||
@see getEqStatus()
|
||||
@see getEqPreamp()
|
||||
@see setEqBand()
|
||||
@param band EQ band to set (0 to 9)
|
||||
@param val EQ band value (-127 [-20dB] to 127 [+20dB]).
|
||||
*/
|
||||
void setEqBand(int band, int val);
|
||||
|
||||
/**
|
||||
Get the automatic EQ preset loading state.
|
||||
|
||||
@see setEqAuto()
|
||||
@ret 1, On; 0, Off;
|
||||
*/
|
||||
int getEqAuto(); // returns 1 if on, 0 if off
|
||||
|
||||
/**
|
||||
Set the automatic EQ preset loading.
|
||||
|
||||
@see getEqAuto()
|
||||
@param enable 1, On; 0, Off;
|
||||
*/
|
||||
void setEqAuto(int enable);
|
||||
|
||||
/**
|
||||
Trigger the previous event.
|
||||
|
||||
@see next()
|
||||
@see play()
|
||||
@see stop()
|
||||
@see pause()
|
||||
*/
|
||||
void prev();
|
||||
|
||||
/**
|
||||
Trigger the play event.
|
||||
|
||||
@see prev()
|
||||
@see next()
|
||||
@see stop()
|
||||
@see pause()
|
||||
*/
|
||||
void play();
|
||||
|
||||
/**
|
||||
Trigger the pause event.
|
||||
|
||||
@see prev()
|
||||
@see next()
|
||||
@see stop()
|
||||
@see play()
|
||||
*/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
Trigger the stop event.
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
Trigger the next event.
|
||||
|
||||
@see prev()
|
||||
@see stop()
|
||||
@see play()
|
||||
@see pause()
|
||||
*/
|
||||
void next();
|
||||
|
||||
/**
|
||||
Set the thread priority of the core.
|
||||
|
||||
@see getPriority()
|
||||
@param priority Thread priority.
|
||||
*/
|
||||
void setPriority(int priority);
|
||||
|
||||
/**
|
||||
Get the thread priority of the core.
|
||||
|
||||
@see setPriority()
|
||||
@ret Thread priority level.
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
As the function name implies, rebuilds the converters chain (no shit?)
|
||||
*/
|
||||
void rebuildConvertersChain();
|
||||
|
||||
/**
|
||||
Send a message to all converters in the current
|
||||
playback chain of a core.
|
||||
|
||||
It's possible to pass any pointer using this messanging
|
||||
system, as long as the pointer is valid across dll boundries.
|
||||
|
||||
@param msg Message.
|
||||
@param value Message value.
|
||||
*/
|
||||
int sendConvertersMsg(const char *msg, const char *value);
|
||||
|
||||
private:
|
||||
void userButton(int button);
|
||||
CoreToken token;
|
||||
int createdcore;
|
||||
};
|
||||
|
||||
#endif
|
92
Src/Wasabi/api/core/sequence.cpp
Normal file
92
Src/Wasabi/api/core/sequence.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "precomp.h"
|
||||
|
||||
#include "sequence.h"
|
||||
|
||||
#define CBCLASS ItemSequencerI
|
||||
START_DISPATCH;
|
||||
CB(GETDEPENDENCYPTR, getDependencyPtr);
|
||||
CB(GETNEXTPLAYITEM, getNextPlayItem);
|
||||
CB(GETCURRENTPLAYBACKNUMBER, getCurrentPlaybackNumber);
|
||||
CB(GETNUMITEMS, getNumItems);
|
||||
CB(REWIND, rewind);
|
||||
CB(FORWARD, forward);
|
||||
CB(ONNOTIFY, onNotify);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
||||
|
||||
int ItemSequencerI::onNotify(int msg, int param1, int param2) {
|
||||
switch (msg) {
|
||||
case SEQNOTIFY_ONREGISTER: return onRegister();
|
||||
case SEQNOTIFY_ONDEREGISTER: return onDeregister();
|
||||
case SEQNOTIFY_ONNEXTFILE: return onNextFile();
|
||||
case SEQNOTIFY_ONTITLECHANGE: return onTitleChange();
|
||||
case SEQNOTIFY_ONSTARTED: return onStarted();
|
||||
case SEQNOTIFY_ONSTOPPED: return onStopped();
|
||||
case SEQNOTIFY_ONPAUSED: return onPaused();
|
||||
case SEQNOTIFY_ONUNPAUSED: return onUnpaused();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *ListSequencer::getNextPlayItem() {
|
||||
int pos;
|
||||
const char *ret;
|
||||
|
||||
pos = getCurrent();
|
||||
|
||||
if (pos < 0) return NULL;
|
||||
|
||||
ret = enumItem(pos);
|
||||
|
||||
setCurrent(pos);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ListSequencer::rewind() {
|
||||
|
||||
int pos;
|
||||
|
||||
pos = getCurrent();
|
||||
|
||||
if (pos < 0) return 0;
|
||||
|
||||
pos--;
|
||||
|
||||
if (pos < 0) {
|
||||
if (loop()) {
|
||||
pos = getNumEntries()-1;
|
||||
} else {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
setCurrent(pos);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ListSequencer::forward() {
|
||||
|
||||
int pos;
|
||||
|
||||
pos = getCurrent();
|
||||
|
||||
if (pos < 0) return 0;
|
||||
|
||||
pos++;
|
||||
|
||||
if (pos >= getNumEntries()) {
|
||||
if (loop()) {
|
||||
pos = 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
setCurrent(pos);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ListSequencer::getNumItems() {
|
||||
return getNumEntries();
|
||||
}
|
123
Src/Wasabi/api/core/sequence.h
Normal file
123
Src/Wasabi/api/core/sequence.h
Normal file
|
@ -0,0 +1,123 @@
|
|||
//PORTABLE
|
||||
#ifndef _SEQUENCE_H
|
||||
#define _SEQUENCE_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/depend.h>
|
||||
|
||||
// abstracted version of a playback order
|
||||
class ItemSequencer : public Dispatchable {
|
||||
public:
|
||||
api_dependent *getDependencyPtr();
|
||||
|
||||
const char *getNextPlayItem();
|
||||
int getCurrentPlaybackNumber(); // 0-based, -1 if you don't know
|
||||
int getNumItems(); // -1 if you don't know
|
||||
int rewind();
|
||||
int forward();
|
||||
|
||||
int onNotify(int msg, int param1=0, int param2=0);
|
||||
|
||||
protected:
|
||||
enum {
|
||||
GETNEXTPLAYITEM=100,
|
||||
GETCURRENTPLAYBACKNUMBER=101,
|
||||
GETNUMITEMS=102,
|
||||
REWIND=200,
|
||||
FORWARD=210,
|
||||
ONNOTIFY=300,
|
||||
GETDEPENDENCYPTR=400,
|
||||
};
|
||||
};
|
||||
|
||||
inline api_dependent *ItemSequencer::getDependencyPtr() {
|
||||
return _call(GETDEPENDENCYPTR, (api_dependent*)NULL);
|
||||
}
|
||||
|
||||
inline const char *ItemSequencer::getNextPlayItem() {
|
||||
return _call(GETNEXTPLAYITEM, (const char *)NULL);
|
||||
}
|
||||
|
||||
inline
|
||||
int ItemSequencer::getCurrentPlaybackNumber() {
|
||||
return _call(GETCURRENTPLAYBACKNUMBER, -1);
|
||||
}
|
||||
|
||||
inline
|
||||
int ItemSequencer::getNumItems() {
|
||||
return _call(GETNUMITEMS, -1);
|
||||
}
|
||||
|
||||
inline int ItemSequencer::rewind() {
|
||||
return _call(REWIND, 0);
|
||||
}
|
||||
|
||||
inline int ItemSequencer::forward() {
|
||||
return _call(FORWARD, 0);
|
||||
}
|
||||
|
||||
inline int ItemSequencer::onNotify(int msg, int param1, int param2) {
|
||||
return _call(ONNOTIFY, 0, msg, param1, param2);
|
||||
}
|
||||
|
||||
#define SEQNOTIFY_ONREGISTER 10
|
||||
#define SEQNOTIFY_ONDEREGISTER 20
|
||||
#define SEQNOTIFY_ONNEXTFILE 30
|
||||
#define SEQNOTIFY_ONTITLECHANGE 40
|
||||
#define SEQNOTIFY_ONSTARTED 50
|
||||
#define SEQNOTIFY_ONSTOPPED 60
|
||||
#define SEQNOTIFY_ONPAUSED 70
|
||||
#define SEQNOTIFY_ONUNPAUSED 80
|
||||
|
||||
// override this one
|
||||
class ItemSequencerI : public ItemSequencer, public DependentI {
|
||||
public:
|
||||
api_dependent *getDependencyPtr() { return this; }
|
||||
|
||||
virtual int rewind()=0;
|
||||
virtual int forward()=0;
|
||||
virtual const char *getNextPlayItem()=0;
|
||||
virtual int getCurrentPlaybackNumber() { return -1; }
|
||||
virtual int getNumItems() { return -1; }
|
||||
|
||||
// these are optional callbacks
|
||||
virtual int onRegister() { return 0; };
|
||||
virtual int onDeregister() { return 0; };
|
||||
virtual int onNextFile() { return 0; }// on transition
|
||||
virtual int onTitleChange() { return 0; }
|
||||
virtual int onStarted() { return 0; }
|
||||
virtual int onStopped() { return 0; }
|
||||
virtual int onPaused() { return 0; }
|
||||
virtual int onUnpaused() { return 0; }
|
||||
|
||||
protected:
|
||||
// default implementation calls above callback methods based on msg
|
||||
virtual int onNotify(int msg, int param1, int param2);
|
||||
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
// also somewhat abstract, but implements playing through some arbitrary
|
||||
// list. just override the protected stuff
|
||||
class ListSequencer : public ItemSequencerI {
|
||||
public:
|
||||
virtual const char *getNextPlayItem();
|
||||
virtual int rewind();
|
||||
virtual int forward();
|
||||
|
||||
protected:
|
||||
// override these 4 only
|
||||
virtual int getNumEntries()=0;
|
||||
virtual const char *enumItem(int pos)=0;
|
||||
virtual int getCurrent()=0;
|
||||
virtual int setCurrent(int cur)=0;
|
||||
|
||||
protected:
|
||||
virtual int loop() { return 0; } // override as necessary
|
||||
|
||||
private:
|
||||
virtual int getNumItems(); // calls getNumEntries()
|
||||
};
|
||||
|
||||
#endif
|
||||
|
2
Src/Wasabi/api/dependency/api_dependent.cpp
Normal file
2
Src/Wasabi/api/dependency/api_dependent.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <precomp.h>
|
||||
#include "api_dependent.h"
|
54
Src/Wasabi/api/dependency/api_dependent.h
Normal file
54
Src/Wasabi/api/dependency/api_dependent.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef __WASABI_API_DEPENDENT_H
|
||||
#define __WASABI_API_DEPENDENT_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include "api_dependentviewer.h"
|
||||
|
||||
// we define some common event codes here. if your object needs more send
|
||||
// them as parameters to OBJECTSPECIFIC
|
||||
|
||||
// some system-level codes for cb param. You can implement your own events
|
||||
// with DEPCB_EVENT and the parameters
|
||||
namespace DependentCB
|
||||
{
|
||||
enum {
|
||||
DEPCB_NOP = 0,
|
||||
DEPCB_DELETED = 100, // object being deleted
|
||||
DEPCB_EVENT = 1000, // object-specific event. use param1 etc to send your messages
|
||||
};
|
||||
};
|
||||
|
||||
class NOVTABLE ifc_dependent : public Dispatchable
|
||||
{
|
||||
protected:
|
||||
ifc_dependent() {}
|
||||
~ifc_dependent() {}
|
||||
public:
|
||||
void dependent_regViewer(ifc_dependentviewer *viewer, int add) ;
|
||||
void *dependent_getInterface(const GUID *classguid);
|
||||
|
||||
DISPATCH_CODES
|
||||
{
|
||||
API_DEPENDENT_REGVIEWER = 10,
|
||||
API_DEPENDENT_GETINTERFACE = 20,
|
||||
};
|
||||
};
|
||||
|
||||
inline void ifc_dependent::dependent_regViewer(api_dependentviewer *viewer, int add)
|
||||
{
|
||||
_voidcall(API_DEPENDENT_REGVIEWER, viewer, add);
|
||||
}
|
||||
inline void *ifc_dependent::dependent_getInterface(const GUID *classguid)
|
||||
{
|
||||
return _call(API_DEPENDENT_GETINTERFACE, (void *)0, classguid);
|
||||
}
|
||||
|
||||
|
||||
// this is a helper for dependent_getInterface
|
||||
#define HANDLEGETINTERFACE(x) { \
|
||||
if (*classguid == *x::depend_getClassGuid()) return static_cast<x *>(this); \
|
||||
}
|
||||
|
||||
typedef ifc_dependent api_dependent;
|
||||
|
||||
#endif
|
2
Src/Wasabi/api/dependency/api_dependentviewer.cpp
Normal file
2
Src/Wasabi/api/dependency/api_dependentviewer.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <precomp.h>
|
||||
#include "api_dependentviewer.h"
|
30
Src/Wasabi/api/dependency/api_dependentviewer.h
Normal file
30
Src/Wasabi/api/dependency/api_dependentviewer.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef __WASABI_API_DEPENDENTVIEWER_H
|
||||
#define __WASABI_API_DEPENDENTVIEWER_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
#include <bfc/platform/types.h>
|
||||
class ifc_dependent;
|
||||
|
||||
class NOVTABLE ifc_dependentviewer : public Dispatchable
|
||||
{
|
||||
protected:
|
||||
ifc_dependentviewer() {}
|
||||
~ifc_dependentviewer() {}
|
||||
public:
|
||||
// item calls when it changes or disappears, or whatever
|
||||
int dependentViewer_callback(ifc_dependent *item, const GUID *classguid, int cb, intptr_t param1 = 0, intptr_t param2 = 0, void *ptr = NULL, size_t ptrlen = 0);
|
||||
|
||||
DISPATCH_CODES
|
||||
{
|
||||
DEPENDENTVIEWER_CALLBACK = 10,
|
||||
};
|
||||
};
|
||||
|
||||
inline int ifc_dependentviewer::dependentViewer_callback(ifc_dependent *item, const GUID *classguid, int cb, intptr_t param1 , intptr_t param2 , void *ptr , size_t ptrlen)
|
||||
{
|
||||
return _call(DEPENDENTVIEWER_CALLBACK, (int)0, item, classguid, cb, param1, param2, ptr, ptrlen);
|
||||
}
|
||||
|
||||
typedef ifc_dependentviewer api_dependentviewer;
|
||||
|
||||
#endif
|
20
Src/Wasabi/api/filereader/api_filereader.cpp
Normal file
20
Src/Wasabi/api/filereader/api_filereader.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <precomp.h>
|
||||
#include "api_filereader.h"
|
||||
|
||||
#ifdef CBCLASS
|
||||
#undef CBCLASS
|
||||
#endif
|
||||
#define CBCLASS api_fileReaderI
|
||||
START_DISPATCH;
|
||||
CB(API_FILEREADER_FILEOPEN, fileOpen);
|
||||
VCB(API_FILEREADER_FILECLOSE, fileClose);
|
||||
CB(API_FILEREADER_FILEREAD, fileRead);
|
||||
CB(API_FILEREADER_FILEWRITE, fileWrite);
|
||||
CB(API_FILEREADER_FILESEEK, fileSeek);
|
||||
CB(API_FILEREADER_FILETELL, fileTell);
|
||||
CB(API_FILEREADER_FILEGETFILESIZE, fileGetFileSize);
|
||||
// CB(API_FILEREADER_FILEEXISTS, fileExists);
|
||||
CB(API_FILEREADER_FILEREMOVE, fileRemove);
|
||||
CB(API_FILEREADER_FILEREMOVEUNDOABLE, fileRemoveUndoable);
|
||||
CB(API_FILEREADER_FILEMOVE, fileMove);
|
||||
END_DISPATCH;
|
104
Src/Wasabi/api/filereader/api_filereader.h
Normal file
104
Src/Wasabi/api/filereader/api_filereader.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
#ifndef __API_FILEREADER_H
|
||||
#define __API_FILEREADER_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
class NOVTABLE api_fileReader : public Dispatchable
|
||||
{
|
||||
public:
|
||||
void *fileOpen(const wchar_t *filename, OSFNCSTR mode);
|
||||
void fileClose(void *fileHandle);
|
||||
size_t fileRead(void *buffer, size_t size, void *fileHandle);
|
||||
size_t fileWrite(const void *buffer, int size, void *fileHandle);
|
||||
int fileSeek(int64_t offset, int origin, void *fileHandle);
|
||||
uint64_t fileTell(void *fileHandle);
|
||||
uint64_t fileGetFileSize(void *fileHandle);
|
||||
//int fileExists(const wchar_t *filename);
|
||||
int fileRemove(const wchar_t *filename);
|
||||
int fileRemoveUndoable(const wchar_t *filename);
|
||||
int fileMove(const wchar_t *filename, const wchar_t *destfilename);
|
||||
|
||||
enum {
|
||||
API_FILEREADER_FILEOPEN = 0,
|
||||
API_FILEREADER_FILECLOSE = 10,
|
||||
API_FILEREADER_FILEREAD = 20,
|
||||
API_FILEREADER_FILEWRITE = 30,
|
||||
API_FILEREADER_FILESEEK = 40,
|
||||
API_FILEREADER_FILETELL = 50,
|
||||
API_FILEREADER_FILEGETFILESIZE = 60,
|
||||
//API_FILEREADER_FILEEXISTS = 70,
|
||||
API_FILEREADER_FILEREMOVE = 80,
|
||||
API_FILEREADER_FILEREMOVEUNDOABLE = 90,
|
||||
API_FILEREADER_FILEMOVE = 100,
|
||||
};
|
||||
};
|
||||
|
||||
inline void *api_fileReader::fileOpen(const wchar_t *filename, OSFNCSTR mode) {
|
||||
return _call(API_FILEREADER_FILEOPEN, (void *)NULL, filename, mode);
|
||||
}
|
||||
|
||||
inline void api_fileReader::fileClose(void *fileHandle) {
|
||||
_voidcall(API_FILEREADER_FILECLOSE, fileHandle);
|
||||
}
|
||||
|
||||
inline size_t api_fileReader::fileRead(void *buffer, size_t size, void *fileHandle) {
|
||||
return _call(API_FILEREADER_FILEREAD, (size_t)0, buffer, size, fileHandle);
|
||||
}
|
||||
|
||||
inline size_t api_fileReader::fileWrite(const void *buffer, int size, void *fileHandle) {
|
||||
return _call(API_FILEREADER_FILEWRITE, (size_t)0, buffer, size, fileHandle);
|
||||
}
|
||||
|
||||
inline int api_fileReader::fileSeek(int64_t offset, int origin, void *fileHandle) {
|
||||
return _call(API_FILEREADER_FILESEEK, (int)0, offset, origin, fileHandle);
|
||||
}
|
||||
|
||||
inline uint64_t api_fileReader::fileTell(void *fileHandle) {
|
||||
return _call(API_FILEREADER_FILETELL, (uint64_t)0, fileHandle);
|
||||
}
|
||||
|
||||
inline uint64_t api_fileReader::fileGetFileSize(void *fileHandle) {
|
||||
return _call(API_FILEREADER_FILEGETFILESIZE, (uint64_t)0, fileHandle);
|
||||
}
|
||||
|
||||
/*inline int api_fileReader::fileExists(const wchar_t *filename) {
|
||||
return _call(API_FILEREADER_FILEEXISTS, (int)0, filename);
|
||||
}*/
|
||||
|
||||
inline int api_fileReader::fileRemove(const wchar_t *filename) {
|
||||
return _call(API_FILEREADER_FILEREMOVE, (int)0, filename);
|
||||
}
|
||||
|
||||
inline int api_fileReader::fileRemoveUndoable(const wchar_t *filename) {
|
||||
return _call(API_FILEREADER_FILEREMOVEUNDOABLE, (int)0, filename);
|
||||
}
|
||||
|
||||
inline int api_fileReader::fileMove(const wchar_t *filename, const wchar_t *destfilename) {
|
||||
return _call(API_FILEREADER_FILEMOVE, (int)0, filename, destfilename);
|
||||
}
|
||||
|
||||
class api_fileReaderI : public api_fileReader {
|
||||
public:
|
||||
virtual void *fileOpen(const wchar_t *filename, const wchar_t *mode)=0;
|
||||
virtual void fileClose(void *fileHandle)=0;
|
||||
virtual size_t fileRead(void *buffer, size_t size, void *fileHandle)=0;
|
||||
virtual int fileWrite(const void *buffer, int size, void *fileHandle)=0;
|
||||
virtual int fileSeek(int64_t offset, int origin, void *fileHandle)=0;
|
||||
virtual uint64_t fileTell(void *fileHandle)=0;
|
||||
virtual uint64_t fileGetFileSize(void *fileHandle)=0;
|
||||
//virtual int fileExists(const wchar_t *filename)=0;
|
||||
virtual int fileRemove(const wchar_t *filename)=0;
|
||||
virtual int fileRemoveUndoable(const wchar_t *filename)=0;
|
||||
virtual int fileMove(const wchar_t *filename, const wchar_t *destfilename)=0;
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
// {E357E736-4967-4279-B948-5073A186F565}
|
||||
static const GUID fileReaderApiServiceGuid =
|
||||
{ 0xe357e736, 0x4967, 0x4279, { 0xb9, 0x48, 0x50, 0x73, 0xa1, 0x86, 0xf5, 0x65 } };
|
||||
|
||||
extern api_fileReader *fileApi;
|
||||
|
||||
#endif
|
22
Src/Wasabi/api/filereader/api_readercallback.h
Normal file
22
Src/Wasabi/api/filereader/api_readercallback.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef __WASABI_API_READERCALLBACK_H
|
||||
#define __WASABI_API_READERCALLBACK_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
class NOVTABLE api_readercallback : public Dispatchable
|
||||
{
|
||||
public:
|
||||
void metaDataReader_onData(const char *data, int size);
|
||||
|
||||
enum
|
||||
{
|
||||
METADATAREADERONDATA = 10,
|
||||
};
|
||||
};
|
||||
|
||||
inline void api_readercallback::metaDataReader_onData(const char *data, int size)
|
||||
{
|
||||
_voidcall(METADATAREADERONDATA, data, size);
|
||||
}
|
||||
|
||||
#endif
|
53
Src/Wasabi/api/filereader/filereaderapi.cpp
Normal file
53
Src/Wasabi/api/filereader/filereaderapi.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <precomp.h>
|
||||
#include "filereaderapi.h"
|
||||
#include <api/filereader/local/fileread.h>
|
||||
|
||||
api_fileReader *fileApi = NULL;
|
||||
|
||||
|
||||
FileReaderApi::FileReaderApi() {
|
||||
}
|
||||
|
||||
FileReaderApi::~FileReaderApi() {
|
||||
}
|
||||
|
||||
void *FileReaderApi::fileOpen(const wchar_t *filename, const wchar_t *mode) {
|
||||
return FileReaders::open(filename, mode);
|
||||
}
|
||||
|
||||
void FileReaderApi::fileClose(void *fileHandle) {
|
||||
FileReaders::close(fileHandle);
|
||||
}
|
||||
|
||||
size_t FileReaderApi::fileRead(void *buffer, size_t size, void *fileHandle) {
|
||||
return FileReaders::read(buffer, size, fileHandle);
|
||||
}
|
||||
|
||||
int FileReaderApi::fileWrite(const void *buffer, int size, void *fileHandle) {
|
||||
return FileReaders::write(buffer, size, fileHandle);
|
||||
}
|
||||
|
||||
int FileReaderApi::fileSeek(int64_t offset, int origin, void *fileHandle) {
|
||||
return FileReaders::seek(offset, origin, fileHandle);
|
||||
}
|
||||
|
||||
uint64_t FileReaderApi::fileTell(void *fileHandle) {
|
||||
return FileReaders::tell(fileHandle);
|
||||
}
|
||||
|
||||
uint64_t FileReaderApi::fileGetFileSize(void *fileHandle) {
|
||||
return FileReaders::getFileSize(fileHandle);
|
||||
}
|
||||
|
||||
int FileReaderApi::fileRemove(const wchar_t *filename) {
|
||||
return FileReaders::remove(filename);
|
||||
}
|
||||
|
||||
int FileReaderApi::fileRemoveUndoable(const wchar_t *filename) {
|
||||
return FileReaders::removeUndoable(filename);
|
||||
}
|
||||
|
||||
int FileReaderApi::fileMove(const wchar_t *filename, const wchar_t *destfilename) {
|
||||
return FileReaders::move(filename, destfilename);
|
||||
}
|
||||
|
25
Src/Wasabi/api/filereader/filereaderapi.h
Normal file
25
Src/Wasabi/api/filereader/filereaderapi.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef _FILEREADERAPI_H
|
||||
#define _FILEREADERAPI_H
|
||||
|
||||
#include <api/filereader/api_filereader.h>
|
||||
|
||||
class FileReaderApi : public api_fileReaderI
|
||||
{
|
||||
public:
|
||||
FileReaderApi();
|
||||
virtual ~FileReaderApi();
|
||||
|
||||
virtual void *fileOpen(const wchar_t *filename, const wchar_t *mode);
|
||||
virtual void fileClose(void *fileHandle);
|
||||
virtual size_t fileRead(void *buffer, size_t size, void *fileHandle);
|
||||
virtual int fileWrite(const void *buffer, int size, void *fileHandle);
|
||||
virtual int fileSeek(int64_t offset, int origin, void *fileHandle);
|
||||
virtual uint64_t fileTell(void *fileHandle);
|
||||
virtual uint64_t fileGetFileSize(void *fileHandle);
|
||||
//virtual int fileExists(const wchar_t *filename);
|
||||
virtual int fileRemove(const wchar_t *filename);
|
||||
virtual int fileRemoveUndoable(const wchar_t *filename);
|
||||
virtual int fileMove(const wchar_t *filename, const wchar_t *destfilename);
|
||||
};
|
||||
|
||||
#endif
|
132
Src/Wasabi/api/filereader/local/fileread.cpp
Normal file
132
Src/Wasabi/api/filereader/local/fileread.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
#include <precomp.h>
|
||||
#include "fileread.h"
|
||||
#include <api/service/svc_enum.h>
|
||||
|
||||
void *FileReaders::open(const wchar_t *filename, const wchar_t *mode) {
|
||||
int m=0;
|
||||
|
||||
const wchar_t *p=mode;
|
||||
wchar_t c;
|
||||
while(c=*(p++))
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'r': m=SvcFileReader::READ; break;
|
||||
case 'w': m=SvcFileReader::WRITE; break;
|
||||
case 'a': m=SvcFileReader::APPEND; break;
|
||||
case '+': m|=SvcFileReader::PLUS; break;
|
||||
case 'b': m|=SvcFileReader::BINARY; break;
|
||||
case 't': m|=SvcFileReader::TEXT; break;
|
||||
}
|
||||
}
|
||||
|
||||
return FileReaderEnum(filename, m).getFirst();
|
||||
}
|
||||
|
||||
void FileReaders::close(void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
fr->close();
|
||||
SvcEnum::release(fr);
|
||||
}
|
||||
|
||||
size_t FileReaders::read(void *buffer, size_t size, void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
return fr->read((int8_t *)buffer,size);
|
||||
}
|
||||
|
||||
size_t FileReaders::write(const void *buffer, size_t size, void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
return fr->write((int8_t *)buffer,size);
|
||||
}
|
||||
|
||||
int FileReaders::seek(int64_t offset, int origin, void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
if(!fr->canSeek()) return -1;
|
||||
if(origin==SEEK_SET) return fr->seek(offset);
|
||||
if(origin==SEEK_CUR) return fr->seek(fr->getPos()+offset);
|
||||
return fr->seek(fr->getLength()-offset);
|
||||
}
|
||||
|
||||
uint64_t FileReaders::tell(void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
return fr->getPos();
|
||||
}
|
||||
|
||||
uint64_t FileReaders::getFileSize(void *handle)
|
||||
{
|
||||
svc_fileReader *fr=(svc_fileReader *)handle;
|
||||
return fr->getLength();
|
||||
}
|
||||
|
||||
int FileReaders::exists(const wchar_t *filename) {
|
||||
// Note that we do not do a system lock on the service since we can just
|
||||
// release it directly via the factory
|
||||
waService *s;
|
||||
for(int i=0;s=WASABI_API_SVC->service_enumService(WaSvc::FILEREADER,i);i++) {
|
||||
svc_fileReader *fr=(svc_fileReader *)s->getInterface(FALSE);
|
||||
if(fr->isMine(filename) == 1 || fr->open(filename)) {
|
||||
int ret=fr->exists(filename);
|
||||
fr->close();
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
return ret;
|
||||
}
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FileReaders::remove(const wchar_t *filename) {
|
||||
// Note that we do not do a system lock on the service since we can just
|
||||
// release it directly via the factory
|
||||
waService *s;
|
||||
for(int i=0;s=WASABI_API_SVC->service_enumService(WaSvc::FILEREADER,i);i++) {
|
||||
svc_fileReader *fr=(svc_fileReader *)s->getInterface(FALSE);
|
||||
if (fr->isMine(filename) == 1 || fr->open(filename)) {
|
||||
fr->close();
|
||||
int ret = fr->remove(filename);
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
return ret;
|
||||
}
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FileReaders::removeUndoable(const wchar_t *filename) {
|
||||
// Note that we do not do a system lock on the service since we can just
|
||||
// release it directly via the factory
|
||||
waService *s;
|
||||
for(int i=0;s=WASABI_API_SVC->service_enumService(WaSvc::FILEREADER,i);i++) {
|
||||
svc_fileReader *fr=(svc_fileReader *)s->getInterface(FALSE);
|
||||
if(fr->isMine(filename) == 1 || fr->open(filename)) {
|
||||
fr->close();
|
||||
int ret = fr->removeUndoable(filename);
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
return ret;
|
||||
}
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FileReaders::move(const wchar_t *filename, const wchar_t *destfilename) {
|
||||
// Note that we do not do a system lock on the service since we can just
|
||||
// release it directly via the factory
|
||||
waService *s;
|
||||
for(int i=0;s=WASABI_API_SVC->service_enumService(WaSvc::FILEREADER,i);i++) {
|
||||
svc_fileReader *fr=(svc_fileReader *)s->getInterface(FALSE);
|
||||
if(fr->isMine(filename) == 1 || fr->open(filename)) {
|
||||
fr->close();
|
||||
int ret = fr->move(filename,destfilename);
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
return ret;
|
||||
}
|
||||
s->releaseInterface(fr); fr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
23
Src/Wasabi/api/filereader/local/fileread.h
Normal file
23
Src/Wasabi/api/filereader/local/fileread.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef _FILEREADERS_H
|
||||
#define _FILEREADERS_H
|
||||
|
||||
#include <api/filereader/svc_filereadI.h>
|
||||
#include <api/service/servicei.h>
|
||||
|
||||
class FileReaders
|
||||
{
|
||||
public:
|
||||
static void *open(const wchar_t *filename, const wchar_t *mode);
|
||||
static void close(void *handle);
|
||||
static size_t read(void *buffer, size_t size, void *handle);
|
||||
static size_t write(const void *buffer, size_t size, void *handle);
|
||||
static int seek(int64_t offset, int origin, void *handle);
|
||||
static uint64_t tell(void *handle);
|
||||
static uint64_t getFileSize(void *handle);
|
||||
static int exists(const wchar_t *filename);
|
||||
static int remove(const wchar_t *filename);
|
||||
static int removeUndoable(const wchar_t *filename);
|
||||
static int move(const wchar_t *filename, const wchar_t *destfilename);
|
||||
};
|
||||
|
||||
#endif//_FILEREADERS_H
|
100
Src/Wasabi/api/filereader/svc_filereadI.h
Normal file
100
Src/Wasabi/api/filereader/svc_filereadI.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
#ifndef __WASABI_SVC_FILEREADI_H
|
||||
#define __WASABI_SVC_FILEREADI_H
|
||||
|
||||
#include <api/service/svcs/svc_fileread.h>
|
||||
#include <api/filereader/api_readercallback.h>
|
||||
// derive from this one
|
||||
class NOVTABLE svc_fileReaderI : public svc_fileReader
|
||||
{
|
||||
public:
|
||||
virtual int isMine(const wchar_t *filename, int mode = SvcFileReader::READ) { return -1; }
|
||||
virtual int open(const wchar_t *filename, int mode = SvcFileReader::READ) = 0; // return 1 on success
|
||||
virtual size_t read(int8_t *buffer, size_t length) = 0; // return number of bytes read (if < length then eof)
|
||||
virtual size_t write(const int8_t *buffer, size_t length) = 0; // return number of bytes written
|
||||
virtual void close() = 0; //must be safe to call even when not open
|
||||
|
||||
virtual int canSetEOF() { return 0; }
|
||||
virtual int setEOF(uint64_t newlen) { return -1; }
|
||||
|
||||
virtual void abort() { } // tells the reader to abort its current prebuffering/reader
|
||||
|
||||
virtual int getLength() { return -1; } // return -1 on unknown/infinite
|
||||
virtual int getPos() = 0;
|
||||
|
||||
virtual int canSeek() { return 0; }
|
||||
virtual int seek(uint64_t position) { return 0; }
|
||||
virtual uint64_t bytesAvailable(uint64_t requested) { return requested; }
|
||||
|
||||
virtual int hasHeaders() { return 0; }
|
||||
virtual const char *getHeader(const char *header) { return (const char *)NULL; }
|
||||
|
||||
virtual int exists(const wchar_t *filename) { return 0; } // return 1 if true, 0 if not, -1 if unknown
|
||||
|
||||
virtual int remove(const wchar_t *filename) { return 0; } // return 1 on success, 0 on error
|
||||
|
||||
virtual int removeUndoable(const wchar_t *filename) { return -1; }
|
||||
|
||||
virtual int move(const wchar_t *filename, const wchar_t *destfilename) { return 0; } // return 1 on success, 0 on error
|
||||
|
||||
virtual void setMetaDataCallback(api_readercallback *cb) { }
|
||||
|
||||
virtual int canPrefetch() { return 1; } // return 1 if your reader should prefetch infos about the file in pledit
|
||||
// (HTTP reader will return 0 here for instance)
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
|
||||
// derive from this one
|
||||
class NOVTABLE MetaDataReaderCallbackI : public api_readercallback {
|
||||
public:
|
||||
virtual void metaDataReader_onData(const char *data, int size)=0;
|
||||
|
||||
protected:
|
||||
#undef CBCLASS
|
||||
#define CBCLASS MetaDataReaderCallbackI
|
||||
START_DISPATCH_INLINE;
|
||||
VCB(METADATAREADERONDATA, metaDataReader_onData);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
||||
};
|
||||
|
||||
#include <api/service/svcs/svc_redir.h>
|
||||
#include <bfc/std_file.h> // for WA_MAX_PATH but this needs to be in a better place
|
||||
|
||||
#define MAX_FILEREADER_REDIRECT 256
|
||||
|
||||
// note: this class handles both redirection and calling open()
|
||||
class FileReaderEnum : public SvcEnumT<svc_fileReader> {
|
||||
public:
|
||||
FileReaderEnum(const wchar_t *filename, int mode=SvcFileReader::READ, int allow_redirect=FALSE) :
|
||||
fn(filename), m(mode)
|
||||
{
|
||||
if (allow_redirect) {
|
||||
for (int done = 0, c = 0; !done && c < MAX_FILEREADER_REDIRECT; done = 1, c++) {
|
||||
RedirectEnum re(fn);
|
||||
svc_redirect *svc;
|
||||
while ((svc = re.getNext(FALSE)) != NULL) {
|
||||
wchar_t buf[WA_MAX_PATH]=L"";
|
||||
if (svc->redirect(fn, L"Filename", buf, WA_MAX_PATH)) {
|
||||
fn = buf;
|
||||
done = 0;
|
||||
}
|
||||
re.getLastFactory()->releaseInterface(svc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual int testService(svc_fileReader *svc) {
|
||||
if (!svc->isMine(fn)) return 0;
|
||||
return !!svc->open(fn, m);
|
||||
}
|
||||
|
||||
private:
|
||||
const wchar_t *fn;
|
||||
int m;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
176
Src/Wasabi/api/filereader/zip/zipread.cpp
Normal file
176
Src/Wasabi/api/filereader/zip/zipread.cpp
Normal file
|
@ -0,0 +1,176 @@
|
|||
#include <precomp.h>
|
||||
#define REAL_STDIO
|
||||
#include "zipread.h"
|
||||
#include <zlib/unzip.h>
|
||||
#include <bfc/parse/pathparse.h>
|
||||
#include <api/skin/api_skin.h>
|
||||
|
||||
#define UNZIPBUFSIZE 65536
|
||||
|
||||
int ZipRead::open(const char *filename, int mode) {
|
||||
unzFile f=NULL;
|
||||
int success=0;
|
||||
|
||||
if (WASABI_API_SKIN == NULL) return 0;
|
||||
PathParser pp1(WASABI_API_SKIN->getSkinsPath());
|
||||
PathParser pp2(filename);
|
||||
int v;
|
||||
for (v=0;v<pp1.getNumStrings();v++)
|
||||
if (!STRCASEEQLSAFE(pp1.enumString(v), pp2.enumString(v))) return 0;
|
||||
String walName = pp2.enumString(v);
|
||||
String file;
|
||||
for (v=v+1;v<pp2.getNumStrings();v++) {
|
||||
if (!file.isempty()) file.cat(DIRCHARSTR);
|
||||
file += pp2.enumString(v);
|
||||
}
|
||||
|
||||
// is there a zip file?
|
||||
String zipName;
|
||||
Std::fileInfoStruct zipFi;
|
||||
if(!Std::getFileInfos(zipName=StringPrintf("%s%s.wal",WASABI_API_SKIN->getSkinsPath(),walName.getValue()),&zipFi) &&
|
||||
!Std::getFileInfos(zipName=StringPrintf("%s%s.wsz",WASABI_API_SKIN->getSkinsPath(),walName.getValue()),&zipFi) &&
|
||||
!Std::getFileInfos(zipName=StringPrintf("%s%s.zip",WASABI_API_SKIN->getSkinsPath(),walName.getValue()),&zipFi))
|
||||
return 0; // zip not found
|
||||
|
||||
if(zipTmpDir.isempty()) {
|
||||
char tmpPath[WA_MAX_PATH];
|
||||
Std::getTempPath(sizeof(tmpPath)-1,tmpPath);
|
||||
zipTmpDir=StringPrintf("%s_wa3sktmp",tmpPath);
|
||||
Std::createDirectory(zipTmpDir);
|
||||
}
|
||||
|
||||
// check in cached opened zip dirs
|
||||
int badcrc=0;
|
||||
for(int i=0;i<openedZipHandles.getNumItems();i++) {
|
||||
if(!STRICMP(openedZipHandles[i].name->getValue(), walName)) {
|
||||
if(!MEMCMP(&openedZipHandles[i].checksum,&zipFi,sizeof(zipFi))) {
|
||||
// try to find it in the dezipped temp dir
|
||||
handle=openInTempDir(walName,file);
|
||||
if(handle) return 1;
|
||||
else return 0;
|
||||
} else {
|
||||
// bad checksum
|
||||
badcrc=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// is the dezipped dir is here?
|
||||
if(!badcrc) {
|
||||
StringPrintf tmpf("%s%s%s%s_wa3chksum",zipTmpDir.getValue(),DIRCHARSTR,walName.getValue(),DIRCHARSTR);
|
||||
FILE *fh=fopen(tmpf,"rb");
|
||||
if(fh) {
|
||||
Std::fileInfoStruct tmpFi={0,};
|
||||
fread(&tmpFi,1,sizeof(tmpFi),fh);
|
||||
fclose(fh);
|
||||
if(!MEMCMP(&tmpFi,&zipFi,sizeof(tmpFi))) {
|
||||
// checksum correct
|
||||
openedZipEntry ze={new String(walName), new String(zipName)};
|
||||
ze.checksum=tmpFi;
|
||||
openedZipHandles.addItem(ze);
|
||||
handle=openInTempDir(walName,file);
|
||||
if(handle) return 1;
|
||||
else return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found, so try to find it in a zip file
|
||||
f = unzOpen(zipName);
|
||||
if(!f) return 0;
|
||||
|
||||
StringPrintf zDir("%s%s%s",zipTmpDir.getValue(),DIRCHARSTR,walName.getValue());
|
||||
Std::removeDirectory(zDir,1);
|
||||
|
||||
// unpack the zip in temp folder
|
||||
String dirmask;
|
||||
unzGoToFirstFile(f);
|
||||
Std::createDirectory(zDir);
|
||||
do {
|
||||
char filename[MAX_PATH];
|
||||
unzGetCurrentFileInfo(f,NULL,filename,sizeof(filename),NULL,0,NULL,0);
|
||||
if (unzOpenCurrentFile(f) == UNZ_OK) {
|
||||
int l;
|
||||
dirmask.printf("%s%s%s",zDir.getValue(),DIRCHARSTR,filename);
|
||||
if (Std::isDirChar(dirmask.lastChar())) {
|
||||
// create dir
|
||||
Std::createDirectory(dirmask);
|
||||
} else {
|
||||
// create file
|
||||
FILE *fp = fopen(dirmask,"wb");
|
||||
if(!fp) {
|
||||
String dir=dirmask;
|
||||
char *p=(char *)Std::filename(dir);
|
||||
if(p) {
|
||||
*p=0;
|
||||
Std::createDirectory(dir);
|
||||
fp = fopen(dirmask,"wb");
|
||||
}
|
||||
}
|
||||
if (fp) {
|
||||
do {
|
||||
MemBlock<char> buf(UNZIPBUFSIZE);
|
||||
l=unzReadCurrentFile(f,buf.getMemory(),buf.getSizeInBytes());
|
||||
if (l > 0) fwrite(buf.getMemory(),1,l,fp);
|
||||
} while (l > 0);
|
||||
fclose(fp);
|
||||
success=1;
|
||||
}
|
||||
}
|
||||
if (unzCloseCurrentFile(f) == UNZ_CRCERROR) success=0;
|
||||
}
|
||||
} while (unzGoToNextFile(f) == UNZ_OK);
|
||||
unzClose(f);
|
||||
|
||||
// write the checksum file
|
||||
Std::fileInfoStruct fi;
|
||||
Std::getFileInfos(zipName, &fi);
|
||||
FILE *fh=fopen(StringPrintf("%s%s_wa3chksum",zDir.getValue(),DIRCHARSTR),"wt");
|
||||
fwrite(&fi,1,sizeof(fi),fh);
|
||||
fclose(fh);
|
||||
|
||||
openedZipEntry ze={new String(walName), new String(zipName)};
|
||||
ze.checksum=fi;
|
||||
openedZipHandles.addItem(ze);
|
||||
|
||||
// try to find it (again) in the dezipped temp dir
|
||||
handle=openInTempDir(walName,file);
|
||||
if(handle) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *ZipRead::openInTempDir(const char *walName, const char *file) {
|
||||
StringPrintf tmpf("%s%s%s%s%s",zipTmpDir.getValue(),DIRCHARSTR,walName,DIRCHARSTR,file);
|
||||
FILE *fh=fopen(tmpf,"rb");
|
||||
if(fh) return fh;
|
||||
// okay maybe the file isn't in the root dir of the zip file
|
||||
fh=fopen(StringPrintf("%s%s%s%s%s%s%s",zipTmpDir.getValue(),DIRCHARSTR,walName,DIRCHARSTR,walName,DIRCHARSTR,file),"rb");
|
||||
if(fh) return fh;
|
||||
// definitely not here
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ZipRead::close() {
|
||||
fclose(handle);
|
||||
}
|
||||
|
||||
int ZipRead::read(char *buffer, int size) {
|
||||
return fread(buffer,1,size,handle);
|
||||
}
|
||||
|
||||
int ZipRead::getPos() {
|
||||
return ftell(handle);
|
||||
}
|
||||
|
||||
int ZipRead::getLength() {
|
||||
int pos=ftell(handle);
|
||||
fseek(handle,0,SEEK_END);
|
||||
int length=ftell(handle);
|
||||
fseek(handle,pos,SEEK_SET);
|
||||
return length;
|
||||
}
|
||||
|
||||
using namespace wasabi;
|
||||
|
||||
TList<ZipRead::openedZipEntry> ZipRead::openedZipHandles;;
|
39
Src/Wasabi/api/filereader/zip/zipread.h
Normal file
39
Src/Wasabi/api/filereader/zip/zipread.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef _ZIPREAD_H
|
||||
#define _ZIPREAD_H
|
||||
|
||||
#include <api/service/svcs/svc_fileread.h>
|
||||
#include <api/service/servicei.h>
|
||||
#include <bfc/memblock.h>
|
||||
#include <bfc/string/string.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
#include <bfc/tlist.h>
|
||||
|
||||
class ZipRead : public svc_fileReaderI {
|
||||
public:
|
||||
// service
|
||||
static const char *getServiceName() { return "ZIP file reader"; }
|
||||
|
||||
int open(const char *filename, int mode=SvcFileReader::READ);
|
||||
int read(char *buffer, int length);
|
||||
int write(const char *buffer, int length) { return 0; }
|
||||
void close();
|
||||
int getPos();
|
||||
int getLength();
|
||||
|
||||
private:
|
||||
FILE *openInTempDir(const char *walName, const char *file);
|
||||
|
||||
typedef struct {
|
||||
String *name;
|
||||
String *zipName;
|
||||
Std::fileInfoStruct checksum;
|
||||
} openedZipEntry;
|
||||
|
||||
static wasabi::TList<openedZipEntry> openedZipHandles;
|
||||
|
||||
String zipTmpDir;
|
||||
|
||||
FILE *handle;
|
||||
};
|
||||
|
||||
#endif//_ZIPREAD_H
|
7
Src/Wasabi/api/font/FontCreator.h
Normal file
7
Src/Wasabi/api/font/FontCreator.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <api/service/svcs/svc_font.h>
|
||||
template <class T>
|
||||
class FontCreator : public waServiceFactoryT<svc_font, T>
|
||||
{
|
||||
public:
|
||||
FontCreator(GUID myGuid = INVALID_GUID) : waServiceFactoryT<svc_font, T>(myGuid) {}
|
||||
};
|
18
Src/Wasabi/api/font/FontSvcEnum.h
Normal file
18
Src/Wasabi/api/font/FontSvcEnum.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <bfc/string/StringW.h>
|
||||
#include <api/service/svc_enum.h>
|
||||
|
||||
class FontSvcEnum : public SvcEnumT<svc_font> {
|
||||
public:
|
||||
FontSvcEnum(const wchar_t *_svc_name = NULL) : svc_name(_svc_name) {}
|
||||
protected:
|
||||
virtual int testService(svc_font *svc)
|
||||
{
|
||||
if (!svc_name.len())
|
||||
return 1; // blank name returns all services.
|
||||
return (!WCSICMP(svc->getFontSvcName(),svc_name));
|
||||
}
|
||||
private:
|
||||
StringW svc_name;
|
||||
};
|
||||
|
||||
|
11
Src/Wasabi/api/font/api_font.cpp
Normal file
11
Src/Wasabi/api/font/api_font.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <precomp.h>
|
||||
#include "api_font.h"
|
||||
|
||||
#ifdef CBCLASS
|
||||
#undef CBCLASS
|
||||
#endif
|
||||
#define CBCLASS api_fontI
|
||||
START_DISPATCH;
|
||||
VCB(API_FONT_FONT_TEXTOUT, font_textOut);
|
||||
CB(API_FONT_FONT_GETINFO, font_getInfo);
|
||||
END_DISPATCH;
|
36
Src/Wasabi/api/font/api_font.h
Normal file
36
Src/Wasabi/api/font/api_font.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef __API_FONT_H
|
||||
#define __API_FONT_H
|
||||
|
||||
#include <bfc/dispatch.h>
|
||||
|
||||
class ifc_canvas;
|
||||
|
||||
class NOVTABLE api_font : public Dispatchable
|
||||
{
|
||||
public:
|
||||
void font_textOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt);
|
||||
int font_getInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h);
|
||||
|
||||
enum {
|
||||
API_FONT_FONT_TEXTOUT = 0,
|
||||
API_FONT_FONT_GETINFO = 10,
|
||||
};
|
||||
};
|
||||
|
||||
inline void api_font::font_textOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt)
|
||||
{
|
||||
_voidcall(API_FONT_FONT_TEXTOUT, c, style, x, y, w, h, txt);
|
||||
}
|
||||
|
||||
inline int api_font::font_getInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h)
|
||||
{
|
||||
return _call(API_FONT_FONT_GETINFO, (int)0, c, font, infoid, txt, w, h);
|
||||
}
|
||||
|
||||
// {1FCA9C7E-5923-4b9c-8906-0F8C331DF21C}
|
||||
static const GUID fontApiServiceGuid =
|
||||
{ 0x1fca9c7e, 0x5923, 0x4b9c, { 0x89, 0x6, 0xf, 0x8c, 0x33, 0x1d, 0xf2, 0x1c } };
|
||||
|
||||
extern api_font *fontApi;
|
||||
|
||||
#endif
|
394
Src/Wasabi/api/font/bitmapfont.cpp
Normal file
394
Src/Wasabi/api/font/bitmapfont.cpp
Normal file
|
@ -0,0 +1,394 @@
|
|||
#include "precomp.h"
|
||||
// ============================================================================================================================================================
|
||||
// Font abstract class + statics to install TT fonts and Bitmap fonts
|
||||
// ============================================================================================================================================================
|
||||
#include "bitmapfont.h"
|
||||
#include <api/wnd/fontdef.h>
|
||||
#include <api/config/items/cfgitem.h>
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
#include <api/skin/skin.h>
|
||||
#endif
|
||||
#ifdef WA3COMPATIBILITY
|
||||
#endif
|
||||
|
||||
#include <tataki/canvas/ifc_canvas.h>
|
||||
#include <tataki/region/api_region.h>
|
||||
#include <api/skin/skinparse.h>
|
||||
|
||||
// ============================================================================================================================================================
|
||||
// BitmapFont implementation.
|
||||
// ============================================================================================================================================================
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
BitmapFont::BitmapFont() : scriptid(0), char_width(0), char_height(0), hor_spacing(0), vert_spacing(0) {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
BitmapFont::~BitmapFont() {
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::isBitmap() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t *BitmapFont::getFaceName() {
|
||||
return getFontId();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOut(ifc_canvas *c, int x, int y, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, x+xoffset, y+yoffset, -1, -1, txt, size, bold, opaque, underline, italic, STDFONT_LEFT, color, WA_FONT_TEXTOUT_NORMAL);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOut2(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, x+xoffset, y+yoffset, x+xoffset+w, y+yoffset+h, txt, size, bold, opaque, underline, italic, align, color, WA_FONT_TEXTOUT_RECT);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, x+xoffset, y+yoffset, x+xoffset+w, y+yoffset+h, txt, size, bold, opaque, underline, italic, align, color, WA_FONT_TEXTOUT_ELLIPSED);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, x+xoffset, y+yoffset, x+xoffset+w, y+yoffset+h, txt, size, bold, opaque, underline, italic, align, color, WA_FONT_TEXTOUT_WRAPPED);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, x+xoffset, y+yoffset, x+xoffset+w, -1, txt, size, bold, opaque, underline, italic, align, color, WA_FONT_TEXTOUT_WRAPPEDPATHED);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::textOutCentered(ifc_canvas *c, RECT *r, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
do_textOut(this, c, r->left, r->top, r->right-r->left, r->bottom-r->top, txt, size, bold, opaque, underline, italic, align, color, WA_FONT_TEXTOUT_CENTERED);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getTextWidth(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialiased)
|
||||
{
|
||||
return wcslen(text) * char_width + wcslen(text)*hor_spacing;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getTextHeight(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialiased)
|
||||
{
|
||||
return char_height;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getTextHeight2(ifc_canvas *c, int size, int bold, int underline, int italic, int antialiased)
|
||||
{
|
||||
return char_height;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::getTextExtent(ifc_canvas *c, const wchar_t *text, int *w, int *h, int size, int bold, int underline, int italic, int antialiased)
|
||||
{
|
||||
if (w) *w = getTextWidth(c, text, size, bold, underline, italic, antialiased);
|
||||
if (h) *h = char_height;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::setFontBitmap(const wchar_t *name_or_element, const wchar_t *path)
|
||||
{
|
||||
StringW pathfile;
|
||||
if (!wcschr(name_or_element, L':'))
|
||||
{
|
||||
pathfile = path;
|
||||
pathfile.AddBackslash();
|
||||
}
|
||||
pathfile.cat(name_or_element);
|
||||
if (!WACCESS(pathfile, 0))
|
||||
table = pathfile;
|
||||
else
|
||||
table = name_or_element;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::setFontMetrics(int _char_width, int _char_height, int _hor_spacing, int _vert_spacing) {
|
||||
char_width = _char_width;
|
||||
char_height = _char_height;
|
||||
hor_spacing = _hor_spacing;
|
||||
vert_spacing = _vert_spacing;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getHorizontalSpacing() {
|
||||
return hor_spacing;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getVerticalSpacing() {
|
||||
return vert_spacing;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getCharWidth() {
|
||||
return char_width;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getCharHeight() {
|
||||
return char_height;
|
||||
}
|
||||
|
||||
AutoSkinBitmap *BitmapFont::getCharTable() {
|
||||
return &table;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::getXYfromChar(wchar_t ic, int *x, int *y)
|
||||
{
|
||||
int c,c2=0;
|
||||
switch (ic)
|
||||
{
|
||||
case L'\u00B0': /*¡*/ ic = L'0'; break;
|
||||
case L'\u00C6':/*®*/ ic = L'A'; break;
|
||||
// case '\u00C1':/*ç*/ ic = L'A'; break;
|
||||
// case '\u00C2': ic = L'A'; break;
|
||||
case L'\u00C7': /*‚*/ ic = L'C'; break;
|
||||
case L'\u00C9':/*ƒ*/ ic = L'E'; break;
|
||||
|
||||
case L'\u00E0': /*ˆ*/ case L'\u00E1': /*‡*/ case L'\u00E2': /*‰*/ ic = L'a'; break;
|
||||
case L'\u00E6':/*¾*/ ic = L'a'; break;
|
||||
case L'\u00E7': /*<2A>*/ ic = L'c'; break;
|
||||
case L'\u00E8': /*<2A>*/ case L'\u00E9': /*Ž*/ case L'\u00EB': /*‘*/case L'\u00EA':/*<2A>*/ ic = L'e'; break;
|
||||
case L'\u00EC':/*“*/ case L'\u00ED':/*’*/ case L'\u00EE':/*”*/ case L'\u00EF':/*•*/ ic = L'i'; break;
|
||||
|
||||
#ifdef _WIN32
|
||||
case L'—':/*—*/ case L'˜':/*˜*/ case L'™':/*™*/ ic = L'o'; break;
|
||||
case L'œ':/*œ*/ case L'<EFBFBD>':/*<2A>*/ case L'ž':/*ž*/ ic = L'u'; break;
|
||||
case L'Ø':/*Ø*/ ic = L'y'; break;
|
||||
case L'†':/*†*/ ic = L'U'; break;
|
||||
#else
|
||||
#warning change these to \u
|
||||
#endif
|
||||
case L'\u00D1':/*„*/ ic = L'N'; break;
|
||||
case L'\u00F1':/*–*/ ic = L'n'; break;
|
||||
case L'\u00FC': /*Ÿ*/ ic = L'u'; break;
|
||||
case L'\u0192':/*Ä*/ ic = L'f'; break;
|
||||
default: break;
|
||||
} // quick relocations
|
||||
if (ic <= L'Z' && ic >= L'A') c = (ic-'A');
|
||||
else if (ic <= L'z' && ic >= L'a') c = (ic-'a');
|
||||
else if (ic == L' ') c = 30;
|
||||
else {
|
||||
c2 += char_height;
|
||||
if (ic == L'\1') c=10;
|
||||
else if (ic == L'.') c = 11;
|
||||
else if (ic <= L'9' && ic >= L'0') c = ic - L'0';
|
||||
else if (ic == L':') c = 12;
|
||||
else if (ic == L'(') c = 13;
|
||||
else if (ic == L')') c = 14;
|
||||
else if (ic == L'-') c = 15;
|
||||
else if (ic == L'\'' || ic=='`') c = 16;
|
||||
else if (ic == L'!') c = 17;
|
||||
else if (ic == L'_') c = 18;
|
||||
else if (ic == L'+') c = 19;
|
||||
else if (ic == L'\\') c = 20;
|
||||
else if (ic == L'/') c = 21;
|
||||
else if (ic == L'[' || ic == L'{' || ic == L'<') c = 22;
|
||||
else if (ic == L']' || ic == L'}' || ic == L'>') c = 23;
|
||||
else if (ic == L'~' || ic == L'^') c = 24;
|
||||
else if (ic == L'&') c = 25;
|
||||
else if (ic == L'%') c = 26;
|
||||
else if (ic == L',') c = 27;
|
||||
else if (ic == L'=') c = 28;
|
||||
else if (ic == L'$') c = 29;
|
||||
else if (ic == L'#') c = 30;
|
||||
else
|
||||
{
|
||||
c2 += char_height;
|
||||
#ifdef _WIN32
|
||||
if (ic == L'<EFBFBD>' || ic == L'Œ') c = 0;
|
||||
else if (ic == L'…' || ic == L'š') c = 1;
|
||||
else if (ic == L'€' || ic == L'Š') c = 2;
|
||||
else
|
||||
#else
|
||||
#warning change these to \u
|
||||
#endif
|
||||
if (ic == L'?') c = 3;
|
||||
else if (ic == L'*') c = 4;
|
||||
else {
|
||||
c2 = 0;
|
||||
if (ic == L'"') c = 26;
|
||||
else if (ic == L'@') c = 27;
|
||||
else c = 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
c*=char_width;
|
||||
*x=c;
|
||||
*y=c2;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int BitmapFont::getWordLength(const wchar_t *p) {
|
||||
int n=0;
|
||||
while (p && *p && *p != L' ') {
|
||||
p++;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
wchar_t *BitmapFont::makeLine(const wchar_t *t, BitmapFont *font, int line, int width, int style) {
|
||||
|
||||
static wchar_t str[4096];
|
||||
wchar_t *p = (wchar_t *)t;
|
||||
size_t len = wcslen(t);
|
||||
|
||||
switch (style) {
|
||||
case WA_FONT_TEXTOUT_NORMAL:
|
||||
case WA_FONT_TEXTOUT_RECT:
|
||||
case WA_FONT_TEXTOUT_ELLIPSED:
|
||||
case WA_FONT_TEXTOUT_CENTERED:
|
||||
return line == 0 ? (wchar_t *)t : NULL;
|
||||
case WA_FONT_TEXTOUT_WRAPPEDPATHED:
|
||||
case WA_FONT_TEXTOUT_WRAPPED: {
|
||||
size_t maxchar = width / (font->getCharWidth() + font->getVerticalSpacing());
|
||||
for (int i = 0; i < line; i++) {
|
||||
wchar_t *oldp = p;
|
||||
p += maxchar;
|
||||
if ((size_t)(p-t) >= len) return NULL;
|
||||
while (p >= t) {
|
||||
if (p == t || *(p-1) == L' ')
|
||||
break;
|
||||
p--;
|
||||
}
|
||||
if (p == oldp) {
|
||||
p += maxchar;
|
||||
while (p && *p && *p != L' ')
|
||||
p++;
|
||||
}
|
||||
}
|
||||
WCSCPYN(str, p, maxchar);
|
||||
wchar_t *d = &str[maxchar-1];
|
||||
int wr=0;
|
||||
if (wcslen(p) > maxchar && *(p+maxchar) != L' ' && wcschr(str, L' '))
|
||||
while (d >= str) {
|
||||
if (*d == L' ') {
|
||||
*d = 0;
|
||||
wr=1;
|
||||
}
|
||||
else {
|
||||
if (wr) break;
|
||||
d--;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void BitmapFont::do_textOut(BitmapFont *font, ifc_canvas *c, int x, int y, int x2, int y2, const wchar_t *text, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, int style)
|
||||
{
|
||||
static wchar_t *dotdotdot=L"...";
|
||||
if (!text) return;
|
||||
|
||||
BaseCloneCanvas canvas;
|
||||
int ret = canvas.clone(c);
|
||||
if (!ret) return;
|
||||
|
||||
RECT bounds;
|
||||
|
||||
RECT defbounds={x,y,x2,y2};
|
||||
int __w, __h;
|
||||
c->getDim(&__w, &__h, NULL);
|
||||
if (x2 == -1) defbounds.right = defbounds.left + __w;
|
||||
if (y2 == -1) defbounds.bottom = defbounds.top + __h;
|
||||
#ifdef _WIN32
|
||||
RegionI oldclip(&canvas, &defbounds); // get clipping region in oldclip
|
||||
RegionI *andclip=NULL;
|
||||
oldclip.getBox(&bounds); // get boundaries
|
||||
#else
|
||||
bounds = defbounds;
|
||||
#warning port me
|
||||
#endif
|
||||
|
||||
/* if (x2 != -1 && y2 != -1) {
|
||||
andclip = new RegionI(x, y, x2, y2); // create region for rect
|
||||
andclip->andRegion(oldclip); // and them
|
||||
canvas.selectClipRgn(andclip); // select new clipping rect
|
||||
andclip->getBox(&bounds); // update boundaries
|
||||
}*/
|
||||
|
||||
int lc=-1;
|
||||
wchar_t *p = dotdotdot+3; // just a zero to triger next line
|
||||
|
||||
int _x = x+(font->getHorizontalSpacing()/2);
|
||||
int _y = y;
|
||||
|
||||
if (style == WA_FONT_TEXTOUT_CENTERED) {
|
||||
_y += (y2 - y - font->getCharHeight()) / 2;
|
||||
}
|
||||
|
||||
_y -= font->getCharHeight() + font->getVerticalSpacing();
|
||||
|
||||
int xp, yp;
|
||||
|
||||
while (p) {
|
||||
|
||||
if (!*p) {
|
||||
lc++;
|
||||
p = makeLine(text, font, lc, x2-x, style);
|
||||
if (!p || !*p) break;
|
||||
|
||||
_x = x+(font->getHorizontalSpacing()/2);
|
||||
_y += font->getCharHeight() + font->getVerticalSpacing();
|
||||
if ((align == STDFONT_RIGHT || align == STDFONT_CENTER) && x2 != -1) {
|
||||
int l = wcslen(p);
|
||||
_x -= l * (font->getCharWidth() + font->getHorizontalSpacing()) - (x2-x);
|
||||
}
|
||||
if (align == STDFONT_CENTER)
|
||||
_x = x + (_x - x) / 2;
|
||||
|
||||
}
|
||||
|
||||
if ((style == WA_FONT_TEXTOUT_ELLIPSED || style == WA_FONT_TEXTOUT_WRAPPEDPATHED) && x2 != -1) {
|
||||
if (_x > x2 - 4 * (font->getCharWidth() + font->getHorizontalSpacing()) && wcslen(p) > 3) {
|
||||
p = dotdotdot;
|
||||
}
|
||||
}
|
||||
|
||||
font->getXYfromChar(*p, &xp, &yp);
|
||||
|
||||
RECT r;
|
||||
r.left = xp;
|
||||
r.top = yp;
|
||||
r.right = xp + font->getCharWidth();
|
||||
r.bottom = yp + font->getCharHeight();
|
||||
|
||||
RECT dst;
|
||||
dst.left = _x;
|
||||
dst.top = _y;
|
||||
dst.right = _x + font->getCharWidth();
|
||||
dst.bottom = _y + font->getCharHeight();
|
||||
|
||||
if (Wasabi::Std::rectIntersect(dst, bounds))
|
||||
// if (IntersectRect(&dummy, &dst, &bounds)) // port me / checks clipping, not passed x,y,x2,y2
|
||||
font->getCharTable()->stretchToRectAlpha(&canvas, &r, &dst, 255);
|
||||
|
||||
p++;
|
||||
_x += font->getCharWidth();
|
||||
_x += font->getHorizontalSpacing();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (andclip) {
|
||||
canvas.selectClipRgn(&oldclip); // restore previously saved clipping region
|
||||
delete andclip;
|
||||
}
|
||||
#else
|
||||
#warning port me
|
||||
#endif
|
||||
}
|
||||
|
70
Src/Wasabi/api/font/bitmapfont.h
Normal file
70
Src/Wasabi/api/font/bitmapfont.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
#ifndef __BITMAPFONT_H
|
||||
#define __BITMAPFONT_H
|
||||
|
||||
#include <api/font/svc_fonti.h>
|
||||
|
||||
//#include "font.h"
|
||||
|
||||
#include <bfc/platform/platform.h>
|
||||
#include <bfc/ptrlist.h>
|
||||
#include <bfc/stack.h>
|
||||
#include <tataki/bitmap/autobitmap.h>
|
||||
#include <bfc/string/StringW.h>
|
||||
|
||||
class Font;
|
||||
|
||||
class BitmapFont : public svc_fontI
|
||||
{
|
||||
friend class Font;
|
||||
public:
|
||||
|
||||
virtual void textOut(ifc_canvas *c, int x, int y, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual void textOut2(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual void textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual void textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual void textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual void textOutCentered(ifc_canvas *c, RECT *r, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialiased);
|
||||
virtual int getTextWidth(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialiased);
|
||||
virtual int getTextHeight(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialiased);
|
||||
virtual int getTextHeight2(ifc_canvas *c, int size, int bold, int underline, int italic, int antialiased);
|
||||
virtual void getTextExtent(ifc_canvas *c, const wchar_t *text, int *w, int *h, int size, int bold, int underline, int italic, int antialiased);
|
||||
virtual int isBitmap();
|
||||
|
||||
virtual void setFontBitmap(const wchar_t *name_or_element, const wchar_t *path);
|
||||
virtual void setFontMetrics(int char_width, int char_height, int hor_spacing, int vert_spacing);
|
||||
virtual const wchar_t *getFaceName();
|
||||
|
||||
virtual void setFontId(const wchar_t *id) { font_id = id; }
|
||||
virtual const wchar_t *getFontId() { return font_id; }
|
||||
virtual int getScriptId() { return scriptid; }
|
||||
virtual void setScriptId(int id) { scriptid = id; }
|
||||
virtual void setFontFace(const wchar_t *face) {}
|
||||
virtual int addFontResource(OSFILETYPE f, const wchar_t *name) { return 0; /*failure*/}
|
||||
virtual int addFontResource2(void *mem, int datalen, const wchar_t *name) { return 0; /*failure*/}
|
||||
|
||||
virtual const wchar_t *getFontSvcName() { return L"Bitmap Font"; }
|
||||
|
||||
protected:
|
||||
BitmapFont();
|
||||
virtual ~BitmapFont();
|
||||
|
||||
AutoSkinBitmap *getCharTable();
|
||||
int getCharWidth();
|
||||
int getCharHeight();
|
||||
int getHorizontalSpacing();
|
||||
int getVerticalSpacing();
|
||||
void getXYfromChar(wchar_t ic, int *x, int *y);
|
||||
|
||||
protected:
|
||||
StringW font_id;
|
||||
int scriptid;
|
||||
|
||||
private:
|
||||
AutoSkinBitmap table;
|
||||
int char_width, char_height, hor_spacing, vert_spacing;
|
||||
static void do_textOut(BitmapFont *font, ifc_canvas *c, int x, int y, int x2, int y2, const wchar_t *text, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, int style);
|
||||
static int getWordLength(const wchar_t *p);
|
||||
static wchar_t *makeLine(const wchar_t *t, BitmapFont *font, int line, int physwidth, int style);
|
||||
};
|
||||
|
||||
#endif
|
637
Src/Wasabi/api/font/font.cpp
Normal file
637
Src/Wasabi/api/font/font.cpp
Normal file
|
@ -0,0 +1,637 @@
|
|||
#include "precomp.h"
|
||||
// ============================================================================================================================================================
|
||||
// Font abstract class + statics to install TT fonts and Bitmap fonts
|
||||
// ============================================================================================================================================================
|
||||
|
||||
#include <api/font/font.h>
|
||||
#include <api/font/bitmapfont.h>
|
||||
#include <bfc/parse/pathparse.h>
|
||||
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
#include <api/skin/skin.h>
|
||||
#include <api/skin/skinparse.h>
|
||||
#endif
|
||||
|
||||
#include <tataki/canvas/ifc_canvas.h>
|
||||
#include <api/wnd/fontdef.h>
|
||||
|
||||
#ifdef WASABI_COMPILE_FONT
|
||||
#include <api/service/svcs/svc_font.h>
|
||||
//#include "services/svc_fontmaker.h"
|
||||
#endif
|
||||
|
||||
#ifdef WASABI_API_CONFIG
|
||||
#include <api/config/options.h>
|
||||
#include <api/config/items/attrint.h>
|
||||
#include <api/config/items/attrstr.h>
|
||||
#include <api/config/items/attrbool.h>
|
||||
#endif
|
||||
#include <api/memmgr/api_memmgr.h>
|
||||
#include <api/font/FontSvcEnum.h>
|
||||
|
||||
extern _bool cfg_options_usefontmapper;
|
||||
extern _string cfg_options_ttfoverridefont;
|
||||
extern _int cfg_options_defaultfontscale;
|
||||
|
||||
PtrList<svc_font> Font::fontlist;
|
||||
PtrList<FontDef> Font::fontdefs;
|
||||
|
||||
void Font::init()
|
||||
{
|
||||
#ifdef WASABI_API_CONFIG
|
||||
Wasabi::Std::setDefaultFont(cfg_options_defaultfont.getValue());
|
||||
Wasabi::Std::setDefaultFontScale(cfg_options_defaultfontscale.getValueAsInt());
|
||||
#endif
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void Font::dispatchTextOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt)
|
||||
{
|
||||
int isoverride = 0;
|
||||
if (WASABI_API_APP->main_isShuttingDown()) return;
|
||||
|
||||
int size = c->getTextSize();
|
||||
|
||||
svc_font *f = requestSkinFont(c->getTextFont(), &size);
|
||||
|
||||
ASSERT(f != NULL);
|
||||
|
||||
// After we get the font we want, check to see if it is bitmap.
|
||||
// If bitmap fonts are disallowed, use the truetype override font.
|
||||
if (f->isBitmap() && useTrueTypeOverride(txt))
|
||||
{
|
||||
int gotdefault=0;
|
||||
svc_font *ttFont = requestSkinFont(getTrueTypeOverride(), &size, &gotdefault);
|
||||
if (ttFont != NULL)
|
||||
{
|
||||
if (!gotdefault)
|
||||
isoverride = 1;
|
||||
f = ttFont;
|
||||
}
|
||||
}
|
||||
|
||||
if (isoverride)
|
||||
{
|
||||
double f = (double)getTrueTypeOverrideScale() / 100.0f;
|
||||
size = (int)(size*f);
|
||||
}
|
||||
int bold = c->getTextBold();
|
||||
int opaque = c->getTextOpaque();
|
||||
int underline = c->getTextUnderline();
|
||||
int italic = c->getTextItalic();
|
||||
int align = c->getTextAlign();
|
||||
int antialiased = c->getTextAntialias();
|
||||
ARGB32 color = c->getTextColor();
|
||||
ARGB32 bkcolor = c->getTextBkColor();
|
||||
int xoffset=0, yoffset=0;
|
||||
c->getOffsets(&xoffset, &yoffset);
|
||||
/* if (!f->isBitmap() && _intVal(Main::enumRootCfgItem(0), "Force antialias on all TTF"))
|
||||
antialiased = 1;*/
|
||||
switch (style)
|
||||
{
|
||||
case WA_FONT_TEXTOUT_NORMAL:
|
||||
f->textOut(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
case WA_FONT_TEXTOUT_RECT:
|
||||
f->textOut(c, x, y, w, h, txt, size, bold, opaque, underline, italic, align, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
case WA_FONT_TEXTOUT_ELLIPSED:
|
||||
f->textOutEllipsed(c, x, y, w, h, txt, size, bold, opaque, underline, italic, align, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
case WA_FONT_TEXTOUT_WRAPPED:
|
||||
f->textOutWrapped(c, x, y, w, h, txt, size, bold, opaque, underline, italic, align, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
case WA_FONT_TEXTOUT_WRAPPEDPATHED:
|
||||
f->textOutWrappedPathed(c, x, y, w, txt, size, bold, opaque, underline, italic, align, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
case WA_FONT_TEXTOUT_CENTERED:
|
||||
RECT r;
|
||||
r.left = x;
|
||||
r.top = y;
|
||||
r.right = w;
|
||||
r.bottom = h;
|
||||
f->textOutCentered(c, &r, txt, size, bold, opaque, underline, italic, align, color, bkcolor, xoffset, yoffset, antialiased);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int Font::dispatchGetInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h)
|
||||
{
|
||||
int isoverride = 0;
|
||||
if (WASABI_API_APP->main_isShuttingDown()) return 0;
|
||||
// mig: Let's not crash if we want to see how big a NULL pointer is.
|
||||
if (txt == NULL) {
|
||||
if ( infoid == WA_FONT_GETINFO_WIDTHHEIGHT ) {
|
||||
if (w != NULL) {
|
||||
*w = 0;
|
||||
}
|
||||
if (h != NULL) {
|
||||
*h = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int size = c->getTextSize();
|
||||
|
||||
svc_font *f = requestSkinFont(font, &size);
|
||||
ASSERT(f != NULL);
|
||||
|
||||
// After we get the font we want, check to see if it is bitmap.
|
||||
// If bitmap fonts are disallowed, use the truetype override font.
|
||||
if (f->isBitmap() && useTrueTypeOverride(txt))
|
||||
{
|
||||
int gotdefault = 0;
|
||||
svc_font *ttFont = requestSkinFont(getTrueTypeOverride(), &size, &gotdefault);
|
||||
if (ttFont != NULL)
|
||||
{
|
||||
if (!gotdefault)
|
||||
isoverride = 1;
|
||||
f = ttFont;
|
||||
}
|
||||
}
|
||||
|
||||
if (isoverride) {
|
||||
double f = (double)getTrueTypeOverrideScale() / 100.0f;
|
||||
size = (int)(size*f);
|
||||
}
|
||||
int bold = c->getTextBold();
|
||||
int underline = c->getTextUnderline();
|
||||
int italic = c->getTextItalic();
|
||||
int antialiased = c->getTextAntialias();
|
||||
switch (infoid) {
|
||||
case WA_FONT_GETINFO_WIDTH:
|
||||
return f->getTextWidth(c, txt, size, bold, underline, italic, antialiased);
|
||||
case WA_FONT_GETINFO_HEIGHT:
|
||||
return f->getTextHeight(c, txt, size, bold, underline, italic, antialiased);
|
||||
case WA_FONT_GETINFO_WIDTHHEIGHT:
|
||||
f->getTextExtent(c, txt, w, h, size, bold, underline, italic, antialiased);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Install a truetype font from its filename and associate a script_id to it
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
svc_font *Font::installTrueTypeFont(const wchar_t *filename, const wchar_t *path, const wchar_t *id, int scriptid, int allowmapping, int isttfreload) {
|
||||
|
||||
if (!isttfreload)
|
||||
{
|
||||
FontDef *fd = new FontDef;
|
||||
fd->filename = filename;
|
||||
fd->path = path;
|
||||
fd->id = id;
|
||||
fd->scriptid = scriptid;
|
||||
fd->isbitmap = 0;
|
||||
fd->allowmapping = allowmapping;
|
||||
fontdefs.addItem(fd);
|
||||
}
|
||||
|
||||
StringW file;
|
||||
|
||||
OSFILETYPE ff=OPEN_FAILED;
|
||||
if (wcschr(filename, ':'))
|
||||
ff = WFOPEN(filename, WF_READONLY_BINARY);
|
||||
|
||||
if (ff == OPEN_FAILED)
|
||||
{
|
||||
file = StringPathCombine(path, filename);
|
||||
ff = WFOPEN(file, WF_READONLY_BINARY);
|
||||
}
|
||||
#ifdef WASABI_COMPILE_SKIN
|
||||
if (ff == OPEN_FAILED)
|
||||
{
|
||||
file = StringPathCombine(SkinParser::getXmlRootPath(), filename);
|
||||
ff = WFOPEN(file, WF_READONLY_BINARY);
|
||||
if (ff == OPEN_FAILED)
|
||||
{
|
||||
file = StringPathCombine(Skin::getDefaultSkinPath(), filename);
|
||||
ff = WFOPEN(file, WF_READONLY_BINARY);
|
||||
if (ff == OPEN_FAILED)
|
||||
{
|
||||
DebugString("Font not found %s\n", filename);
|
||||
// todo: do something if still not found
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (ff == OPEN_FAILED) {
|
||||
DebugString("Could not install font %s\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
StringW fs = filename;
|
||||
wchar_t *p = wcschr(fs.getNonConstVal(), '.');
|
||||
if (p)
|
||||
*p = 0;
|
||||
PathParserW pp(fs);
|
||||
fs = pp.getLastString();
|
||||
|
||||
svc_font *f = newTrueTypeFont();
|
||||
if (f && f->addFontResource( ff, fs) )
|
||||
{
|
||||
f->setFontId(id);
|
||||
f->setScriptId(scriptid);
|
||||
fontlist.addItem(f);
|
||||
} else {
|
||||
DebugString("font.cpp ====== CAN'T LOAD FONT FILE.\n");
|
||||
}
|
||||
|
||||
FCLOSE(ff);
|
||||
return f;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Uninstall all installed fonts
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void Font::uninstallAll(int ttfreload) {
|
||||
int i;
|
||||
// delete all by hand
|
||||
for (i = 0; i < fontlist.getNumItems(); i++) {
|
||||
svc_font *f = fontlist.enumItem(i);
|
||||
if (ttfreload && f->isBitmap()) continue;
|
||||
deleteFont(f);
|
||||
fontlist.removeByPos(i);
|
||||
i--;
|
||||
}
|
||||
if (!ttfreload) fontdefs.deleteAll();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Uninstall by scriptid
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void Font::uninstallByScriptId(int scriptid) {
|
||||
for (int i=0;i<fontlist.getNumItems();i++) {
|
||||
svc_font *f = fontlist.enumItem(i);
|
||||
if (f->getScriptId() == scriptid) {
|
||||
fontlist.removeByPos(i);
|
||||
deleteFont(f);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
for (int i=0;i<fontdefs.getNumItems();i++) {
|
||||
FontDef *fd = fontdefs.enumItem(i);
|
||||
if (fd->scriptid == scriptid) {
|
||||
fontdefs.removeByPos(i);
|
||||
delete fd;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Install a bitmap font and associates a script_id to it
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void Font::installBitmapFont(const wchar_t *filename, const wchar_t *path, const wchar_t *id, int cw, int ch, int hs, int vs, int scriptid, int allowmapping)
|
||||
{
|
||||
FontDef *fd = new FontDef;
|
||||
fd->filename = filename;
|
||||
fd->path = path;
|
||||
fd->id = id;
|
||||
fd->scriptid = scriptid;
|
||||
fd->isbitmap = 1;
|
||||
fd->allowmapping = allowmapping;
|
||||
fontdefs.addItem(fd);
|
||||
|
||||
BitmapFont *f = new BitmapFont;
|
||||
f->setFontBitmap(filename, path);
|
||||
f->setFontId(id);
|
||||
f->setFontMetrics(cw, ch, hs, vs);
|
||||
f->setScriptId(scriptid);
|
||||
fontlist.addItem(f);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Requests a Font* from its id
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
svc_font *Font::requestSkinFont(const wchar_t *id, int *size, int *gotdefault)
|
||||
{
|
||||
if (gotdefault) *gotdefault = 0;
|
||||
int oldsize = size ? *size : -1;
|
||||
const wchar_t *mapped_id = getFontMapping(id, size);
|
||||
if (mapped_id != NULL)
|
||||
id = mapped_id;
|
||||
|
||||
// First try to get a font by that id
|
||||
foreach_reverse(fontlist)
|
||||
const wchar_t *thisid = fontlist.getfor()->getFontId();
|
||||
if (thisid && !WCSICMP(thisid, id))
|
||||
return fontlist.getfor();
|
||||
endfor
|
||||
// if it wasnt found, try to load a wa-installed ttfont with this face name
|
||||
foreach_reverse(fontlist)
|
||||
const wchar_t *facename=fontlist.getfor()->getFaceName();
|
||||
if (facename && !WCSICMP(facename, id)) return fontlist.getfor();
|
||||
endfor
|
||||
|
||||
// not found, try to reload it front the list of fonts defined by the skin
|
||||
foreach(fontdefs)
|
||||
FontDef *fd = fontdefs.getfor();
|
||||
if (!WCSICMP(fd->id, id))
|
||||
{
|
||||
if (!fd->isbitmap)
|
||||
{
|
||||
svc_font *f = installTrueTypeFont(fd->filename, fd->path, fd->id, fd->scriptid, fd->allowmapping, 1);
|
||||
if (f) return f;
|
||||
}
|
||||
}
|
||||
endfor;
|
||||
|
||||
/*
|
||||
for (i=fontlist.getNumItems()-1;i>=0;i--) {
|
||||
const char *thisid = fontlist.enumItem(i)->getFontId();
|
||||
if (thisid && STRCASEEQL(thisid, "wasabi.font.ttf.default" ))
|
||||
return fontlist.enumItem(i);
|
||||
}
|
||||
*/
|
||||
|
||||
// not found ? try to find it in the windows fonts directory
|
||||
{
|
||||
wchar_t *fp = WMALLOC(WA_MAX_PATH);
|
||||
Wasabi::Std::getFontPath(WA_MAX_PATH, fp);
|
||||
StringW file;
|
||||
file.own(fp);
|
||||
// FREE(fp); // benski> no need because we now own it
|
||||
file.AppendPath(StringPrintfW(L"%s%s", id, WCSCASESTR(id, L".ttf") == NULL ? L".ttf":L""));
|
||||
|
||||
if (!WACCESS(file, 0))
|
||||
{
|
||||
svc_font *f = newTrueTypeFont();
|
||||
f->setFontFace(id);
|
||||
f->setFontId(id);
|
||||
OSFILETYPE ff = WFOPEN(file, WF_READONLY_BINARY);
|
||||
if (ff != OPEN_FAILED)
|
||||
{
|
||||
if (f->addFontResource(ff, id))
|
||||
{
|
||||
DebugStringW(L"font.cpp ====== FONT FOR ID=%s NOT FOUND. USING WIN FONT FILE:\n%s\n", id, file.getValue());
|
||||
fontlist.addItem(f);
|
||||
}
|
||||
} else {
|
||||
DebugStringW(L"font.cpp ====== FONT FOR ID=%s NOT FOUND. CANNOT OPEN WIN FONT FILE:\n%s\n", id, file.getValue());
|
||||
delete f;
|
||||
f = NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
// not found ? ask the Std:: interface for the folder and the
|
||||
// default fontname (ie: one you know will always be in the OS)
|
||||
svc_font *f = newTrueTypeFont();
|
||||
if (f) {
|
||||
if (gotdefault) *gotdefault = 1;
|
||||
if (oldsize != -1 && size) {
|
||||
*size = oldsize;
|
||||
double f = (double)Wasabi::Std::getDefaultFontScale() / 100.0;
|
||||
*size = (int)(*size*f);
|
||||
}
|
||||
// Query Std:: and build the path to the default font file.
|
||||
wchar_t *fontPath = WMALLOC(WA_MAX_PATH);
|
||||
Wasabi::Std::getFontPath(WA_MAX_PATH, fontPath);
|
||||
wchar_t fontFile[WA_MAX_PATH] = {0};
|
||||
Wasabi::Std::getDefaultFont(WA_MAX_PATH, fontFile);
|
||||
StringW defaultFont;
|
||||
defaultFont.own(fontPath);
|
||||
defaultFont.AppendPath(fontFile);
|
||||
// FREE(fontFile);
|
||||
StringW fs = defaultFont;
|
||||
wchar_t *p = wcschr(fs.getNonConstVal(), '.');
|
||||
if (p) *p = 0;
|
||||
PathParserW pp(fs);
|
||||
fs = pp.getLastString();
|
||||
f->setFontFace(fs);
|
||||
f->setFontId(id);
|
||||
// Open it and load it as the font resource.
|
||||
OSFILETYPE ff = WFOPEN(defaultFont, WF_READONLY_BINARY);
|
||||
if (ff != OPEN_FAILED) {
|
||||
if (f->addFontResource(ff, fs))
|
||||
{
|
||||
DebugStringW(L"font.cpp ====== FONT FOR ID=%s NOT FOUND. USING DEFAULT FONT FILE:\n%s\n", id, defaultFont);
|
||||
fontlist.addItem(f);
|
||||
}
|
||||
} else {
|
||||
DebugStringW(L"font.cpp ====== FONT FOR ID=%s NOT FOUND. CANNOT OPEN FONT FILE:\n%s\n", id, defaultFont);
|
||||
delete f;
|
||||
f = NULL;
|
||||
}
|
||||
} else {
|
||||
DebugString("font.cpp ====== CAN'T GET NEW FONT FILE.\n");
|
||||
delete f;
|
||||
f = NULL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
if (f == NULL) {
|
||||
// not found :((((( grab the default font data and use this, whatever it is
|
||||
f = newTrueTypeFont();
|
||||
if (f)
|
||||
{
|
||||
HDC dc = GetDC(GetDesktopWindow());
|
||||
HDC dc2 = CreateCompatibleDC(dc);
|
||||
SelectObject(dc2, GetStockObject(DEFAULT_GUI_FONT));
|
||||
|
||||
int datalen = GetFontData(dc2, 0, 0, NULL, 0);
|
||||
if (datalen > 0) {
|
||||
void *mem = WASABI_API_MEMMGR->sysMalloc(datalen+1); // freed by the service !!
|
||||
ASSERT(mem != NULL);
|
||||
GetFontData(dc2, 0, 0, mem, datalen);
|
||||
|
||||
f->setFontFace(id);
|
||||
f->setFontId(id);
|
||||
f->addFontResource2(mem, datalen, id);
|
||||
|
||||
ReleaseDC(GetDesktopWindow(), dc);
|
||||
DeleteDC(dc2);
|
||||
fontlist.addItem(f);
|
||||
return f;
|
||||
}
|
||||
delete f;
|
||||
f = NULL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#warning port me
|
||||
#endif
|
||||
|
||||
if (f == NULL) {
|
||||
// ok, NOW I'm getting pissed
|
||||
wchar_t fp[WA_MAX_PATH] = {0};
|
||||
Wasabi::Std::getFontPath(WA_MAX_PATH, fp);
|
||||
#ifdef _WIN32
|
||||
Wasabi::Std::messageBox(StringPrintfW(L"Fatal error trying to load truetype fonts.\n\nYou need arial.ttf at the very least, but it does not appear to be in %s", fp), L"Fatal Error", MB_ICONERROR);
|
||||
#else
|
||||
#warning port me
|
||||
#endif
|
||||
}
|
||||
|
||||
//if (f == NULL) DebugString("font.cpp ====== FALLBACK FOR FONT %s CANNOT BE FOUND IN OUR LISTS.\n",f->getFontId());
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Intelligently delete the font
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void Font::deleteFont(svc_font *f)
|
||||
{
|
||||
if (f)
|
||||
{
|
||||
if (f->isBitmap())
|
||||
{
|
||||
delete static_cast<BitmapFont *>(f); // we delete our own bitmap fonts.
|
||||
}
|
||||
else
|
||||
{
|
||||
SvcEnum::release(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Intelligently make a new truetype font from the service interfaces
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
svc_font *Font::newTrueTypeFont()
|
||||
{
|
||||
/*#ifdef WASABI_COMPILE_CONFIG
|
||||
const GUID options_guid =
|
||||
{ 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } };
|
||||
CfgItem *options = WASABI_API_CONFIG->config_getCfgItemByGuid(options_guid);
|
||||
#endif*/
|
||||
|
||||
svc_font *retval = NULL;
|
||||
const wchar_t *name = NULL;
|
||||
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
//const wchar_t *attr = L"Font Renderer";
|
||||
// First, try to find a font service that matches the attribute.
|
||||
// if (options) {
|
||||
// char buf[256]; // WHEEE for stack arrays
|
||||
// if (options->getData(attr, buf, sizeof buf)) {
|
||||
if (WASABI_API_SKIN->skin_getVersion() >= 1.3) // hardcode win32 renderer for v1.3+ skins
|
||||
retval = FontSvcEnum(L"Win32 TextOut").getFirst();
|
||||
else
|
||||
retval = FontSvcEnum(cfg_options_fontrenderer.getValue()).getFirst();
|
||||
|
||||
#else
|
||||
#ifndef WASABI_FONT_RENDERER
|
||||
#error You need to define WASABI_FONT_RENDERER (ie: #define WASABI_FONT_RENDERER "Freetype")
|
||||
#endif
|
||||
retval = FontSvcEnum(WASABI_FONT_RENDERER).getFirst();
|
||||
#endif
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
// }
|
||||
// }
|
||||
|
||||
// If we can't find one, fallback and just take the first.
|
||||
if (!retval)
|
||||
{
|
||||
retval = FontSvcEnum().getFirst();
|
||||
if (retval != NULL)
|
||||
name = retval->getFontSvcName();
|
||||
}
|
||||
|
||||
// If we had to fallback, remember the fallback service in the attribute.
|
||||
if (name/* && options*/)
|
||||
{
|
||||
//options->setData(attr, name);
|
||||
cfg_options_fontrenderer.setValue(name);
|
||||
}
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Test whether to forbid bitmap fonts.
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int Font::useTrueTypeOverride(const wchar_t *txt)
|
||||
|
||||
{
|
||||
if (cfg_options_no7bitsttfoverride.getValueAsInt())
|
||||
{
|
||||
const wchar_t *p = (const wchar_t *)txt;
|
||||
while (p && *p)
|
||||
{
|
||||
// TODO: benski> some characters above 127 can be handled by the bitmap fonts - it might be worth checking those explicitly
|
||||
if (*p & 0xFF80)
|
||||
break;
|
||||
p++;
|
||||
}
|
||||
if (!*p) return 0;
|
||||
}
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
/* // {280876CF-48C0-40bc-8E86-73CE6BB462E5}
|
||||
const GUID options_guid =
|
||||
{ 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } };
|
||||
return !_intVal(WASABI_API_CONFIG->config_getCfgItemByGuid(options_guid), "Use bitmap fonts (no international support)", 1);*/
|
||||
return !cfg_options_allowbitmapfonts.getValueAsInt();
|
||||
#else
|
||||
return WASABI_FONT_TTFOVERRIDE;
|
||||
#endif
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Get the font to be used to override bitmap fonts.
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t *Font::getTrueTypeOverride()
|
||||
{
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
return cfg_options_ttfoverridefont.getValue();
|
||||
#else
|
||||
return L"Arial";
|
||||
#warning TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
int Font::getTrueTypeOverrideScale()
|
||||
{
|
||||
#ifdef WASABI_COMPILE_CONFIG
|
||||
return cfg_options_ttfoverridescale.getValueAsInt();
|
||||
#else
|
||||
return 1;
|
||||
#warning TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Returns the font mapping for this font & skin, if font mapper is on and if there is a mapping, otherwise returns null
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const wchar_t *Font::getFontMapping(const wchar_t *id, int *size)
|
||||
{
|
||||
if (cfg_options_usefontmapper.getValueAsInt())
|
||||
{
|
||||
wchar_t t[256]=L"";
|
||||
StringW tmp;
|
||||
tmp.printf(L"Skin:%s/Font Mapping/%s",WASABI_API_SKIN->getSkinName(), id);
|
||||
WASABI_API_CONFIG->getStringPrivate(tmp, t, 256, L"");
|
||||
|
||||
tmp.printf(L"Skin:%s/Font Mapping/%s_scale",WASABI_API_SKIN->getSkinName(), id);
|
||||
int v = WASABI_API_CONFIG->getIntPrivate(tmp, -1);
|
||||
if (!*t)
|
||||
{
|
||||
tmp.printf(L"Font Mapping/%s", id);
|
||||
WASABI_API_CONFIG->getStringPrivate(tmp, t, 256, L"");
|
||||
tmp.printf(L"Font Mapping/%s_scale", id);
|
||||
v = WASABI_API_CONFIG->getIntPrivate(tmp, -1);
|
||||
}
|
||||
mapping = t;
|
||||
if (mapping.isempty()) return NULL;
|
||||
if (size != NULL)
|
||||
{
|
||||
if (v != -1)
|
||||
{
|
||||
double f = (double)v / 100.0;
|
||||
*size = (int)((double)*size * f);
|
||||
}
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringW Font::mapping;
|
55
Src/Wasabi/api/font/font.h
Normal file
55
Src/Wasabi/api/font/font.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
#ifndef __FONT_H
|
||||
#define __FONT_H
|
||||
|
||||
#include <bfc/ptrlist.h>
|
||||
#include <bfc/string/StringW.h>
|
||||
|
||||
class ifc_canvas;
|
||||
class svc_font;
|
||||
class svc_fontMaker;
|
||||
|
||||
class FontDef {
|
||||
public:
|
||||
StringW filename;
|
||||
StringW path;
|
||||
StringW id;
|
||||
int allowmapping;
|
||||
int isbitmap;
|
||||
int scriptid;
|
||||
};
|
||||
|
||||
class Font {
|
||||
public:
|
||||
static void init();
|
||||
|
||||
static svc_font *installTrueTypeFont(const wchar_t *filename, const wchar_t *path, const wchar_t *id, int scriptid, int allowmapping, int isreload); // call this to install a new font
|
||||
static void installBitmapFont(const wchar_t *filename, const wchar_t *path, const wchar_t *id, int charwidth, int charheight, int hspacing, int vspacing, int scriptid, int allowmapping);
|
||||
static void uninstallAll(int isttfreload=0);
|
||||
static void uninstallByScriptId(int scriptid);
|
||||
|
||||
static svc_font *requestSkinFont(const wchar_t *id, int *size=NULL, int *gotdefault=NULL); // call this to get a Font pointer to a font id, pass your size if you have one, so that the mapper can do its job.
|
||||
static void dispatchTextOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt);
|
||||
static int dispatchGetInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h);
|
||||
|
||||
static int useTrueTypeOverride(const wchar_t *txt);
|
||||
static const wchar_t *getTrueTypeOverride();
|
||||
static int getTrueTypeOverrideScale();
|
||||
static int getNumFonts() { return fontlist.getNumItems(); }
|
||||
|
||||
static FontDef *enumFontDef(int n) { return fontdefs.enumItem(n); }
|
||||
static int getNumFontDefs() { return fontdefs.getNumItems(); }
|
||||
|
||||
static const wchar_t *getFontMapping(const wchar_t *id, int *size);
|
||||
|
||||
private:
|
||||
static void deleteFont(svc_font *font);
|
||||
static svc_font *newTrueTypeFont();
|
||||
|
||||
static PtrList<svc_font> fontlist;
|
||||
static PtrList<FontDef> fontdefs;
|
||||
StringW font_id;
|
||||
int scriptid;
|
||||
static StringW mapping;
|
||||
};
|
||||
|
||||
#endif
|
32
Src/Wasabi/api/font/fontapi.cpp
Normal file
32
Src/Wasabi/api/font/fontapi.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <precomp.h>
|
||||
#include "fontapi.h"
|
||||
#include <api/font/font.h>
|
||||
|
||||
api_font *fontApi = NULL;
|
||||
|
||||
FontApi::FontApi()
|
||||
{
|
||||
Font::init();
|
||||
}
|
||||
|
||||
FontApi::~FontApi()
|
||||
{
|
||||
Font::uninstallAll();
|
||||
}
|
||||
|
||||
void FontApi::font_textOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt)
|
||||
{
|
||||
Font::dispatchTextOut(c, style, x, y, w, h, txt);
|
||||
}
|
||||
|
||||
int FontApi::font_getInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h)
|
||||
{
|
||||
return Font::dispatchGetInfo(c, font, infoid, txt, w, h);
|
||||
}
|
||||
|
||||
#define CBCLASS FontApi
|
||||
START_DISPATCH;
|
||||
VCB(API_FONT_FONT_TEXTOUT, font_textOut);
|
||||
CB(API_FONT_FONT_GETINFO, font_getInfo);
|
||||
END_DISPATCH;
|
||||
#undef CBCLASS
|
20
Src/Wasabi/api/font/fontapi.h
Normal file
20
Src/Wasabi/api/font/fontapi.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef __FONTAPI_H
|
||||
#define __FONTAPI_H
|
||||
|
||||
#include <api/font/api_font.h>
|
||||
|
||||
class FontApi : public api_font
|
||||
{
|
||||
public:
|
||||
FontApi();
|
||||
~FontApi();
|
||||
void font_textOut(ifc_canvas *c, int style, int x, int y, int w, int h, const wchar_t *txt);
|
||||
int font_getInfo(ifc_canvas *c, const wchar_t *font, int infoid, const wchar_t *txt, int *w, int *h);
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
extern api_font *fontApi;
|
||||
|
||||
#endif
|
472
Src/Wasabi/api/font/linux/truetypefont_linux.cpp
Normal file
472
Src/Wasabi/api/font/linux/truetypefont_linux.cpp
Normal file
|
@ -0,0 +1,472 @@
|
|||
// ============================================================================================================================================================
|
||||
// Font abstract class + statics to install TT fonts and Bitmap fonts
|
||||
// ============================================================================================================================================================
|
||||
|
||||
// what other linux headers need be made?
|
||||
|
||||
#include "truetypefont_linux.h"
|
||||
|
||||
#include <tataki/canvas/ifc_canvas.h>
|
||||
#include "../../bitmap.h"
|
||||
|
||||
// ============================================================================================================================================================
|
||||
// TrueTypeFont_Linux implementation.
|
||||
// ============================================================================================================================================================
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
TrueTypeFont_Linux::TrueTypeFont_Linux() {
|
||||
font = NULL;
|
||||
antialias_canvas = NULL;
|
||||
DColdstate = NULL;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
TrueTypeFont_Linux::~TrueTypeFont_Linux() {
|
||||
ASSERT(fontstack.isempty());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int TrueTypeFont_Linux::isBitmap() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::addFontResource(FILE *in){
|
||||
ASSERT(in != NULL);
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::addFontResource\n" );
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::setFontFace(const char *face) {
|
||||
face_name = face;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
const char *TrueTypeFont_Linux::getFaceName() {
|
||||
return face_name;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::prepareCanvas(ifc_canvas *c, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor) {
|
||||
String fontname = StringPrintf( "-*-%s-%s-%s-*--%d-*-*-*-*-*-*-*",
|
||||
(const char *)face_name,
|
||||
bold?"bold":"medium",
|
||||
italic?"i":"r", size * 3/4 );
|
||||
font = XLoadQueryFont( Linux::getDisplay(), (const char *)fontname );
|
||||
if ( font == NULL ) {
|
||||
fontname = StringPrintf( "-*-arial-%s-%s-*--%d-*-*-*-*-*-*-*",
|
||||
bold?"bold":"medium",
|
||||
italic?"i":"r", size * 3/4 );
|
||||
font = XLoadQueryFont( Linux::getDisplay(), (const char *)fontname );
|
||||
|
||||
if ( font == NULL ) {
|
||||
fontname = StringPrintf( "-*-courier-%s-%s-*--%d-*-*-*-*-*-*-*",
|
||||
bold?"bold":"medium",
|
||||
italic?"i":"r", size * 3/4 );
|
||||
font = XLoadQueryFont( Linux::getDisplay(), (const char *)fontname );
|
||||
}
|
||||
}
|
||||
ASSERTPR( font != NULL, fontname );
|
||||
XSetFont( Linux::getDisplay(), c->getHDC()->gc, font->fid );
|
||||
XSetForeground( Linux::getDisplay(), c->getHDC()->gc, color );
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::restoreCanvas(ifc_canvas *c) {
|
||||
if ( font != NULL ) {
|
||||
XFreeFont( Linux::getDisplay(), font );
|
||||
font = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
ifc_canvas *TrueTypeFont_Linux::prepareAntialias(ifc_canvas *c, int x, int y, const char *txt, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int w, int h) {
|
||||
ASSERT(antialias_canvas == NULL);
|
||||
BaseCloneCanvas canvas(c);
|
||||
prepareCanvas(&canvas, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
al_w = MAX(2,canvas.getTextWidth(txt) * 2 + xoffset*2);
|
||||
al_h = MAX(2,canvas.getTextHeight()*2 + yoffset*2);
|
||||
restoreCanvas(&canvas);
|
||||
if (w != -1) {
|
||||
al_w = w * 2;
|
||||
al_dw = w;
|
||||
} else al_dw = w;
|
||||
if (h != -1) {
|
||||
al_h = h * 2;
|
||||
al_dh = h;
|
||||
} else al_dh = h;
|
||||
al_mask=RGB(0,0,0);
|
||||
if (color == al_mask) al_mask=RGB(255,255,255);
|
||||
antialias_canvas = new BltCanvas(al_w, al_h);
|
||||
antialias_canvas->fillBits(0);
|
||||
prepareCanvas(antialias_canvas, size*2, bold, opaque, underline, italic, color, bkcolor);
|
||||
if (al_mask != 0) antialias_canvas->fillBits(al_mask);
|
||||
al_x = x; al_y = y; al_xo = xoffset; al_yo = yoffset;
|
||||
return antialias_canvas;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::completeAntialias(ifc_canvas *c) {
|
||||
BaseCloneCanvas canvas(c);
|
||||
antialias_canvas->maskColor(al_mask, RGB(0,0,0));
|
||||
BltCanvas *ac = new BltCanvas(al_w/2, al_h/2);
|
||||
antialias_canvas->antiAliasTo(ac, al_w/2, al_h/2, 2);
|
||||
SkinBitmap *b = ac->getSkinBitmap();
|
||||
RECT src={0,0,al_w/2,al_h/2};
|
||||
RECT dst={al_x+al_xo,al_y+al_yo,al_x+al_xo+al_dw,al_y+al_yo+al_dh};
|
||||
b->blitToRect(&canvas, &src, &dst);
|
||||
delete ac;
|
||||
restoreCanvas(antialias_canvas);
|
||||
delete antialias_canvas;
|
||||
antialias_canvas = NULL;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOut(ifc_canvas *c, int x, int y, const char *txt, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
if (antialiased) {
|
||||
ifc_canvas *canvas = prepareAntialias(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, -1, -1);
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, 0, 0, txt, STRLEN(txt) );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, x+xoffset, y+yoffset+ascent, txt, STRLEN(txt) );
|
||||
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOut(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
if (antialiased) {
|
||||
ifc_canvas *canvas = prepareAntialias(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, w, h);
|
||||
RECT al_r={0,0,w*2,h*2};
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, al_r.left, al_r.top, txt, STRLEN(txt) );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
RECT r;
|
||||
r.left = x+xoffset;
|
||||
r.top = y+yoffset;
|
||||
r.right = r.left + w;
|
||||
r.bottom = r.top + h;
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
int xstart = r.left;
|
||||
|
||||
if ( align == DT_RIGHT ) {
|
||||
int width = XTextWidth( font, txt, STRLEN( txt ) );
|
||||
xstart = r.right - width;
|
||||
|
||||
} else if ( align == DT_CENTER ) {
|
||||
int width = XTextWidth( font, txt, STRLEN( txt ) );
|
||||
xstart = (r.right + r.left - width) / 2;
|
||||
}
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, xstart, r.top + ascent, txt, STRLEN(txt) );
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
if (antialiased) {
|
||||
ifc_canvas *canvas = prepareAntialias(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, w, h);
|
||||
RECT al_r={0,0,w*2,h*2};
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutEllipsed (antialiased)\n" );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
RECT r;
|
||||
r.left = x+xoffset;
|
||||
r.top = y+yoffset;
|
||||
r.right = r.left + w;
|
||||
r.bottom = r.top + h;
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
|
||||
if ( txt == NULL )
|
||||
return;
|
||||
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
|
||||
char *tmp = (char *)MALLOC( STRLEN( txt ) + 3 );
|
||||
STRCPY( tmp, txt );
|
||||
|
||||
if ( XTextWidth( font, tmp, STRLEN( tmp ) ) > r.right - r.left ) {
|
||||
int len = STRLEN( tmp );
|
||||
char *p = tmp + len;
|
||||
int width = r.right - r.left - XTextWidth( font, "...", 3 );
|
||||
while( XTextWidth( font, tmp, len ) > width ) {
|
||||
*p-- = '\0';
|
||||
len--;
|
||||
}
|
||||
STRCPY( p, "..." );
|
||||
}
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, r.left, r.top + ascent, tmp, STRLEN(tmp) );
|
||||
|
||||
FREE( tmp );
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
}
|
||||
|
||||
const char *find_break( int (*width_func)(void *, const char *, int ),
|
||||
void *f, const char *str, int width ) {
|
||||
const char *softret, *lastsoft, *hardret;
|
||||
|
||||
if ( width_func( f, str, STRLEN( str ) ) <= width )
|
||||
return str + STRLEN( str );
|
||||
|
||||
for( hardret = str; *hardret; hardret ++ )
|
||||
if ( *hardret == '\r' || *hardret == '\n' )
|
||||
break;
|
||||
|
||||
if ( hardret && width_func( f, str, hardret - str ) <= width ) {
|
||||
return hardret;
|
||||
}
|
||||
for( softret = str; *softret && !isspace( *softret ); softret++ )
|
||||
;
|
||||
|
||||
if ( width_func( f, str, softret - str ) <= width ) {
|
||||
do {
|
||||
lastsoft = softret;
|
||||
|
||||
for( softret = lastsoft+1; *softret && !isspace( *softret ); softret++ )
|
||||
;
|
||||
|
||||
} while ( *lastsoft && width_func( f, str, softret - str ) <= width );
|
||||
|
||||
softret = lastsoft;
|
||||
} else {
|
||||
for( softret = str; *softret; softret++ )
|
||||
if ( width_func( f, str, softret - str ) > width )
|
||||
break;
|
||||
|
||||
softret--;
|
||||
}
|
||||
|
||||
return softret;
|
||||
}
|
||||
|
||||
int xlib_width( void *data, const char *str, int len ) {
|
||||
return XTextWidth( (XFontStruct *)data, str, len );
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
if (antialiased) {
|
||||
ifc_canvas *canvas = prepareAntialias(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, w, h);
|
||||
RECT al_r={0,0,w*2,h*2};
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutWrapped (antialiased)\n" );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
RECT r;
|
||||
r.left = x+xoffset;
|
||||
r.top = y+yoffset;
|
||||
r.right = r.left + w;
|
||||
r.bottom = r.top + h;
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
|
||||
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
HDC hdc = c->getHDC();
|
||||
|
||||
int yoff = r.top + ascent;
|
||||
const char *cur = txt, *next;
|
||||
int length = STRLEN( txt );
|
||||
for (int yoff = r.top + ascent; yoff < r.bottom - descent; yoff += ascent + descent) {
|
||||
next = find_break(xlib_width, font, cur, r.right - r.left);
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, r.left, yoff, cur, next - cur );
|
||||
for ( cur = next; *cur && isspace( *cur ); cur++ )
|
||||
;
|
||||
if ( cur >= txt + length )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
RECT r;
|
||||
char *ptr, *d;
|
||||
const char *s;
|
||||
ptr = (char *)MALLOC(STRLEN(txt)+1+4);
|
||||
for (s = txt, d = ptr; *s; s++, d++) {
|
||||
if (*s == '/') *d = '\\';
|
||||
else *d = *s;
|
||||
}
|
||||
r.left = x+xoffset;
|
||||
r.top = y+yoffset;
|
||||
r.right = r.left + w;
|
||||
r.bottom = r.top + getTextHeight(c, size, bold, underline, italic, antialiased);
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutWrappedPathed\n" );
|
||||
|
||||
for (d = ptr; *d; d++) {
|
||||
if (*d == '\\') *d = '/';
|
||||
}
|
||||
|
||||
if (antialiased) {
|
||||
restoreCanvas(c);
|
||||
|
||||
ifc_canvas *canvas = prepareAntialias(c, x, y, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, w, -1);
|
||||
RECT al_r={0,0,w*2,al_h};
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutWrappedPathed (antialised)\n" );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, r.left, r.top + ascent, txt, STRLEN(txt) );
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutWrappedPathed\n" );
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
|
||||
FREE(ptr);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::textOutCentered(ifc_canvas *c, RECT *r, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialiased) {
|
||||
ASSERT(r != NULL);
|
||||
ASSERT(txt != NULL);
|
||||
RECT rr=*r;
|
||||
rr.left += xoffset;
|
||||
rr.right += xoffset;
|
||||
rr.top += yoffset;
|
||||
rr.bottom += yoffset;
|
||||
|
||||
if (antialiased) {
|
||||
ifc_canvas *canvas = prepareAntialias(c, r->left, r->top, txt, size, bold, opaque, underline, italic, color, bkcolor, xoffset, yoffset, r->right-r->left, r->bottom-r->top);
|
||||
RECT al_r={0,0,(r->right-r->left)*2,(r->bottom-r->top)*2};
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::textoutCentered (antialiased)\n" );
|
||||
|
||||
completeAntialias(c);
|
||||
} else {
|
||||
prepareCanvas(c, size, bold, opaque, underline, italic, color, bkcolor);
|
||||
|
||||
int dir, ascent, descent, width;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
width = XTextWidth( font, txt, STRLEN( txt ) );
|
||||
|
||||
HDC hdc = c->getHDC();
|
||||
XDrawString( Linux::getDisplay(), hdc->d, hdc->gc, (rr.right + rr.left - width) / 2, rr.top + ascent, txt, STRLEN(txt) );
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int TrueTypeFont_Linux::getTextWidth(ifc_canvas *c, const char *text, int size, int bold, int underline, int italic, int antialiased) {
|
||||
int w;
|
||||
getTextExtent(c, text, &w, NULL, size, bold, underline, italic, antialiased);
|
||||
return w;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int TrueTypeFont_Linux::getTextHeight(ifc_canvas *c, const char *text, int size, int bold, int underline, int italic, int antialiased) {
|
||||
int h;
|
||||
getTextExtent(c, text, NULL, &h, size, bold, underline, italic, antialiased);
|
||||
{
|
||||
// calcul for multiline text
|
||||
const char *p=text;
|
||||
int n=0;
|
||||
while(*p!=0) if(*p++=='\n') n++;
|
||||
if(n) h*=(n+1);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
void TrueTypeFont_Linux::getTextExtent(ifc_canvas *c, const char *txt, int *w, int *h, int size, int bold, int underline, int italic, int antialiased) {
|
||||
SIZE rsize={0,0};
|
||||
ASSERT(txt != NULL);
|
||||
if (*txt == 0) {
|
||||
if (w != NULL) *w = 0;
|
||||
if (h != NULL) *h = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (antialiased)
|
||||
prepareCanvas(c, size*2, bold, 0, underline, italic, 0, 0);
|
||||
else
|
||||
prepareCanvas(c, size, bold, 0, underline, italic, 0, 0);
|
||||
|
||||
int dir, ascent, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents( font, txt, STRLEN( txt ), &dir, &ascent, &descent, &overall );
|
||||
rsize.cy = ascent + descent;
|
||||
rsize.cx = XTextWidth( font, txt, STRLEN( txt ) );
|
||||
|
||||
if (w != NULL) *w = rsize.cx;
|
||||
if (h != NULL) *h = rsize.cy;
|
||||
|
||||
if (antialiased) {
|
||||
if (w != NULL) *w /= 2;
|
||||
if (h != NULL) *h /= 2;
|
||||
}
|
||||
|
||||
restoreCanvas(c);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
int TrueTypeFont_Linux::getTextHeight(ifc_canvas *c, int size, int bold, int underline, int italic, int antialiased) {
|
||||
return getTextHeight(c, "My", size, bold, underline, italic, antialiased);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// code from ftp.microsoft.com/Softlib/MSLFILES/FONTINST.EXE
|
||||
// retrieves the friendly font name from its filename
|
||||
char *TrueTypeFont_Linux::filenameToFontFace(const char *pszFile) {
|
||||
static char lpszLongName[256];
|
||||
unsigned i;
|
||||
char namebuf[255];
|
||||
int fp;
|
||||
unsigned short numNames;
|
||||
long curseek;
|
||||
unsigned cTables;
|
||||
sfnt_OffsetTable OffsetTable;
|
||||
sfnt_DirectoryEntry Table;
|
||||
sfnt_NamingTable NamingTable;
|
||||
sfnt_NameRecord NameRecord;
|
||||
|
||||
OutputDebugString( "portme -- TrueTypeFont_Linux::filenameToFontFace\n" );
|
||||
|
||||
return FALSE;
|
||||
}
|
65
Src/Wasabi/api/font/linux/truetypefont_linux.h
Normal file
65
Src/Wasabi/api/font/linux/truetypefont_linux.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef __TRUETYPEFONT_LINUX_H
|
||||
#define __TRUETYPEFONT_LINUX_H
|
||||
|
||||
#include "../../../studio/services/svc_font.h"
|
||||
|
||||
#include "../../string.h"
|
||||
#include "../../stack.h"
|
||||
#include "../truetypefontdef.h"
|
||||
|
||||
class ifc_canvas;
|
||||
class BltCanvas;
|
||||
|
||||
class TrueTypeFont_Linux : public svc_fontI {
|
||||
public:
|
||||
TrueTypeFont_Linux();
|
||||
virtual ~TrueTypeFont_Linux();
|
||||
|
||||
virtual void textOut(ifc_canvas *c, int x, int y, const char *txt, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual void textOut2(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual void textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual void textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual void textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual void textOutCentered(ifc_canvas *c, RECT *r, const char *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
|
||||
virtual int getTextWidth(ifc_canvas *c, const char *text, int size, int bold, int underline, int italic, int antialias);
|
||||
virtual int getTextHeight(ifc_canvas *c, const char *text, int size, int bold, int underline, int italic, int antialias);
|
||||
virtual int getTextHeight2(ifc_canvas *c, int size, int bold, int underline, int italic, int antialias);
|
||||
virtual void getTextExtent(ifc_canvas *c, const char *text, int *w, int *h, int size, int bold, int underline, int italic, int antialias);
|
||||
|
||||
virtual void setFontId(const char *id) { font_id = id; }
|
||||
virtual const char *getFontId() { return font_id; }
|
||||
virtual int getScriptId() { return scriptid; }
|
||||
virtual void setScriptId(int id) { scriptid = id; }
|
||||
|
||||
virtual int isBitmap();
|
||||
virtual void setFontFace(const char *face);
|
||||
virtual int addFontResource(FILE *f);
|
||||
virtual const char *getFaceName();
|
||||
|
||||
virtual const wchar_t *getFontSvcName() { return "Linux"; }
|
||||
static const char *getServiceName() { return "Linux font renderer"; }
|
||||
|
||||
protected:
|
||||
static char *filenameToFontFace(const wchar_t *filename);
|
||||
void prepareCanvas(ifc_canvas *c, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor);
|
||||
void restoreCanvas(ifc_canvas *c);
|
||||
|
||||
protected:
|
||||
String font_id;
|
||||
int scriptid;
|
||||
|
||||
private:
|
||||
ifc_canvas *prepareAntialias(ifc_canvas *c, int x, int y, const char *txt, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int w, int h);
|
||||
void completeAntialias(ifc_canvas *c);
|
||||
|
||||
String face_name;
|
||||
String tmpfilename;
|
||||
int DColdstate;
|
||||
XFontStruct *font;
|
||||
Stack<fontslot*> fontstack;
|
||||
BltCanvas *antialias_canvas;
|
||||
int al_w, al_h, al_x, al_y, al_xo, al_yo, al_dw, al_dh;
|
||||
COLORREF al_mask;
|
||||
};
|
||||
|
||||
#endif
|
43
Src/Wasabi/api/font/skinfont.cpp
Normal file
43
Src/Wasabi/api/font/skinfont.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "precomp.h"
|
||||
#include "skinfont.h"
|
||||
#include "api.h"
|
||||
#include "../bfc/std.h"
|
||||
|
||||
SkinFont::SkinFont() {
|
||||
}
|
||||
|
||||
SkinFont::~SkinFont() {
|
||||
if (!tempFn.isempty()) {
|
||||
#ifdef WIN32
|
||||
RemoveFontResource(tempFn);
|
||||
#else
|
||||
DebugString( "portme -- SkinFont::~SkinFont\n" );
|
||||
#endif
|
||||
UNLINK(tempFn);
|
||||
}
|
||||
}
|
||||
|
||||
int SkinFont::setXmlOption(const char *paramname, const char *strvalue) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SkinFont::installFont(OSFNSTR filename, OSFNSTR path) {
|
||||
FILE *in,*out;
|
||||
StringPrintf temp("%s%s", path, filename);
|
||||
in = WFOPEN(temp, L"rb");
|
||||
if (!in) return;
|
||||
int len = FGETSIZE(in);
|
||||
MemBlock<char> m(len);
|
||||
FREAD(m.getMemory(), len, 1, in);
|
||||
tempFn = TMPNAM(NULL);
|
||||
out = FOPEN(tempFn, "wb");
|
||||
ASSERT(out);
|
||||
FWRITE(m.getMemory(), len, 1, out);
|
||||
FCLOSE(out);
|
||||
FCLOSE(in);
|
||||
#ifdef WIN32
|
||||
AddFontResource(tempFn);
|
||||
#else
|
||||
DebugString( "portme -- SkinFont::installFont\n" );
|
||||
#endif
|
||||
}
|
17
Src/Wasabi/api/font/skinfont.h
Normal file
17
Src/Wasabi/api/font/skinfont.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef _SKINFONT_H
|
||||
#define _SKINFONT_H
|
||||
|
||||
#include <api/skin/xmlobject.h>
|
||||
|
||||
class SkinFont : public XmlObjectI
|
||||
{
|
||||
public:
|
||||
SkinFont();
|
||||
~SkinFont();
|
||||
void installFont(const wchar_t *filename, const wchar_t *path);
|
||||
virtual int setXmlOption(const wchar_t *name, const wchar_t *val);
|
||||
private:
|
||||
StringW tempFn;
|
||||
};
|
||||
|
||||
#endif
|
39
Src/Wasabi/api/font/svc_fontI.h
Normal file
39
Src/Wasabi/api/font/svc_fontI.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef NULLSOFT_WASABI_SVC_FONTI_H
|
||||
#define NULLSOFT_WASABI_SVC_FONTI_H
|
||||
|
||||
#include <api/service/svcs/svc_font.h>
|
||||
//#include <tataki/canvas/canvas.h>
|
||||
class ifc_canvas;
|
||||
// implementor derives from this one
|
||||
class NOVTABLE svc_fontI : public svc_font {
|
||||
public:
|
||||
|
||||
virtual void textOut(ifc_canvas *c, int x, int y, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0; // abstract interface
|
||||
virtual void textOut2(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0;
|
||||
virtual void textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0;
|
||||
virtual void textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0;
|
||||
virtual void textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0;
|
||||
virtual void textOutCentered(ifc_canvas *c, RECT *r, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, ARGB32 color, ARGB32 bkcolor, int xoffset, int yoffset, int antialias)=0;
|
||||
virtual int getTextWidth(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialias)=0;
|
||||
virtual int getTextHeight(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialias)=0;
|
||||
virtual int getTextHeight2(ifc_canvas *c, int size, int bold, int underline, int italic, int antialias)=0;
|
||||
virtual void getTextExtent(ifc_canvas *c, const wchar_t *text, int *w, int *h, int size, int bold, int underline, int italic, int antialias)=0;
|
||||
|
||||
virtual void setFontId(const wchar_t *id)=0;
|
||||
virtual const wchar_t *getFontId()=0;
|
||||
virtual const wchar_t *getFaceName()=0;
|
||||
virtual int isBitmap()=0;
|
||||
virtual int getScriptId()=0;
|
||||
virtual void setScriptId(int id)=0;
|
||||
|
||||
virtual void setFontFace(const wchar_t *face)=0;
|
||||
virtual int addFontResource(OSFILETYPE f, const wchar_t *name)=0;
|
||||
virtual int addFontResource2(void *mem, int datalen, const wchar_t *name)=0;
|
||||
|
||||
virtual const wchar_t * getFontSvcName()=0;
|
||||
|
||||
protected:
|
||||
RECVS_DISPATCH;
|
||||
};
|
||||
|
||||
#endif
|
56
Src/Wasabi/api/font/truetypefontdef.h
Normal file
56
Src/Wasabi/api/font/truetypefontdef.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef __TRUETYPEFONTDEF_H
|
||||
#define __TRUETYPEFONTDEF_H
|
||||
|
||||
// Macros for TrueType portability
|
||||
#define FS_2BYTE(p) ( ((unsigned short)((p)[0]) << 8) | (p)[1])
|
||||
#define FS_4BYTE(p) ( FS_2BYTE((p)+2) | ( (FS_2BYTE(p)+0L) << 16) )
|
||||
#define SWAPW(a) ((short) FS_2BYTE( (unsigned char FAR*)(&a) ))
|
||||
#define SWAPL(a) ((long) FS_4BYTE( (unsigned char FAR*)(&a) ))
|
||||
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
typedef long sfnt_TableTag;
|
||||
|
||||
typedef struct {
|
||||
uint16 platformID;
|
||||
uint16 specificID;
|
||||
uint16 languageID;
|
||||
uint16 nameID;
|
||||
uint16 length;
|
||||
uint16 offset;
|
||||
} sfnt_NameRecord;
|
||||
|
||||
typedef struct {
|
||||
uint16 format;
|
||||
uint16 count;
|
||||
uint16 stringOffset;
|
||||
} sfnt_NamingTable;
|
||||
|
||||
typedef struct {
|
||||
sfnt_TableTag tag;
|
||||
uint32 checkSum;
|
||||
uint32 offset;
|
||||
uint32 length;
|
||||
} sfnt_DirectoryEntry;
|
||||
|
||||
typedef struct {
|
||||
int32 version;
|
||||
uint16 numOffsets;
|
||||
uint16 searchRange;
|
||||
uint16 entrySelector;
|
||||
uint16 rangeShift;
|
||||
sfnt_DirectoryEntry table[1];
|
||||
} sfnt_OffsetTable;
|
||||
#define OFFSETTABLESIZE 12
|
||||
|
||||
typedef struct {
|
||||
int dcstate;
|
||||
HFONT font;
|
||||
HFONT prevfont;
|
||||
} fontslot;
|
||||
|
||||
#define tag_NamingTable 0x656d616e /* 'name' */
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue