options.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include <precomp.h>
  2. #include "options.h"
  3. //#include <api/wac/main.h>//CUT!!
  4. #include <api/wnd/wndtrack.h>
  5. #include <bfc/util/inifile.h>
  6. #include <api/config/items/attribs.h>
  7. #include <api/config/items/attrcb.h>
  8. #include <bfc/wasabi_std_wnd.h>
  9. #include <api/locales/localesmgr.h>
  10. #include <api/font/font.h>
  11. #define ININAME "wasabi.ini"
  12. // {280876CF-48C0-40bc-8E86-73CE6BB462E5}
  13. const GUID options_guid =
  14. { 0x280876cf, 0x48c0, 0x40bc, { 0x8e, 0x86, 0x73, 0xce, 0x6b, 0xb4, 0x62, 0xe5 } };
  15. #ifndef GEN_FF
  16. static void setMultipleInstance(int val)
  17. {
  18. StringPrintf fn("%s%s%s", WASABI_API_APP->path_getAppPath(), DIRCHARSTR, ININAME);
  19. IniFile(fn).setBool("Wasabi", "MultipleInstance", val);
  20. }
  21. _int forward_skip_time("Forward skip time", 5000);
  22. _int reverse_skip_time("Reverse skip time", 5000);
  23. #endif
  24. _bool cfg_options_altfonts(L"Alternate Fonts", FALSE);
  25. _bool cfg_options_allowbitmapfonts(L"Use bitmap fonts (no international support)", FALSE);
  26. _string cfg_options_defaultfont(L"Default font", WASABI_DEFAULT_FONTNAMEW L".ttf");
  27. _int cfg_options_defaultfontscale(L"Default font scale", 100);
  28. _string cfg_options_ttfoverridefont(L"TTF font override", WASABI_DEFAULT_FONTNAMEW L".ttf");
  29. _int cfg_options_ttfoverridescale(L"TTF Override Scale", 100);
  30. _bool cfg_options_no7bitsttfoverride(L"No 7-bit TTF override", TRUE);
  31. _bool cfg_options_noalt7bitsttfoverride(L"No 7-bit TTF AltFonts", TRUE);
  32. _bool cfg_options_usefontmapper(L"Enable Font Mapper", FALSE);
  33. #ifdef USEAPPBAR
  34. _bool cfg_options_appbarondrag(L"Dock Appbars on Window Drag", FALSE);
  35. _int cfg_options_appbardockingdistance(L"Appbars Docking Distance", 5);
  36. #endif
  37. void invalidateAll(int b) {
  38. #ifdef WASABI_COMPILE_WNDMGR
  39. WASABI_API_WNDMGR->wndTrackInvalidateAll();
  40. #endif
  41. }
  42. void onDefaultFontChanged(const wchar_t *attribute) {
  43. Font::uninstallAll(1);
  44. Wasabi::Std::setDefaultFont(cfg_options_defaultfont.getValue());
  45. invalidateAll(1);
  46. }
  47. void onOverrideFontChanged(const wchar_t *attribute) {
  48. Font::uninstallAll(1);
  49. invalidateAll(1);
  50. }
  51. void onDefaultFontScaleChanged(int scale) {
  52. Wasabi::Std::setDefaultFontScale(scale);
  53. invalidateAll(1);
  54. }
  55. void onOverrideFontScaleChanged(int scale) {
  56. invalidateAll(1);
  57. }
  58. void onFontRendererChanged(const wchar_t *s) {
  59. Font::uninstallAll(1);
  60. invalidateAll(1);
  61. }
  62. void onFontMapperChanged(int b) {
  63. Font::uninstallAll(1);
  64. invalidateAll(1);
  65. }
  66. _bool cfg_audiooptions_crossfader(L"Enable crossfading", DEFAULT_CROSSFADE_ENABLED);
  67. _bool cfg_options_alwaysontop(L"Always on top", FALSE);
  68. _bool cfg_options_docking(L"Enable docking", TRUE);
  69. _int cfg_options_dockingdistance(L"Docking distance", DEFAULT_DOCK_DIST);
  70. _string cfg_options_fontrenderer(L"Font Renderer", WASABI_FONT_RENDERER);
  71. _int cfg_options_freetypecharmap(L"Character mapping", -1);
  72. Options::Options() : CfgItemI(L"Options", options_guid)
  73. {
  74. #ifdef _WASABIRUNTIME
  75. registerAttribute(&cfg_options_alwaysontop, new int_attrCB(Main::setOnTop));
  76. #else
  77. extern void setOnTop(int ontop);
  78. registerAttribute(&cfg_options_alwaysontop, new int_attrCB(setOnTop));
  79. #endif
  80. /* TODO: benski> move to wndmgr.w5s (or wherever it's final home is */
  81. registerAttribute(&cfg_options_dockingdistance, new int_attrCB(WindowTracker::setDockDistance));
  82. registerAttribute(&cfg_options_docking, new int_attrCB(WindowTracker::setEnableDocking));
  83. /* --- END TO MOVE --- */
  84. registerAttribute(new _bool(L"Find open rect", FALSE));
  85. registerAttribute(new _bool(L"Animated rects", TRUE));
  86. registerAttribute(&cfg_options_fontrenderer, new string_attrCB(onFontRendererChanged));
  87. registerAttribute(&cfg_options_allowbitmapfonts, new int_attrCB(invalidateAll));
  88. registerAttribute(&cfg_options_altfonts, new int_attrCB(invalidateAll));
  89. registerAttribute(&cfg_options_defaultfont, new string_attrCB(onDefaultFontChanged));
  90. registerAttribute(&cfg_options_ttfoverridefont, new string_attrCB(onOverrideFontChanged));
  91. registerAttribute(&cfg_options_ttfoverridescale, new int_attrCB(onOverrideFontScaleChanged));
  92. registerAttribute(&cfg_options_defaultfontscale, new int_attrCB(onDefaultFontScaleChanged));
  93. registerAttribute(&cfg_options_freetypecharmap, new int_attrCB(invalidateAll));
  94. registerAttribute(&cfg_options_no7bitsttfoverride, new int_attrCB(invalidateAll));
  95. registerAttribute(&cfg_options_noalt7bitsttfoverride, new int_attrCB(invalidateAll));
  96. registerAttribute(&cfg_options_usefontmapper, new int_attrCB(onFontMapperChanged));
  97. #ifdef USEAPPBAR
  98. registerAttribute(&cfg_options_appbarondrag);
  99. registerAttribute(&cfg_options_appbardockingdistance);
  100. #endif
  101. #ifdef _WASABIRUNTIME
  102. registerAttribute(new _bool(L"Allow multiple instances", FALSE), new int_attrCB(setMultipleInstance));
  103. registerAttribute(new _int(L"Icon mode", 1), new int_attrCB(Main::setIconMode));
  104. registerAttribute(new _bool(L"Auto-play at startup", FALSE));
  105. registerAttribute(new _string(L"Language", "English"), new LanguageCB(this));
  106. #ifdef WIN32
  107. registerAttribute(new _bool("Associate with audio CDs", TRUE), new int_attrCB(Filetypes::registerCdPlayer));
  108. #endif
  109. registerAttribute(new _string("Monitor aspect ratio", "4:3"));
  110. registerAttribute(new _int("Internet connection",3)); //3==autodetect
  111. registerAttribute(&forward_skip_time);
  112. registerAttribute(&reverse_skip_time);
  113. #endif
  114. //registerAttribute(new _bool("Use Mozilla instead of IE for minibrowser", FALSE)); // TODO:move into minibrowser component
  115. /* registerAttribute(new _bool("Force antialias on all TTF", FALSE));*/
  116. addChildItem(&audio_options);
  117. addChildItem(&ui_options);
  118. }
  119. void Options::checkCd() {
  120. #ifdef _WASABIRUNTIME
  121. #ifdef WIN32
  122. if(getDataAsInt("Associate with audio CDs") && !Filetypes::isCdPlayer()) setDataAsInt("Associate with audio CDs",false);
  123. #endif
  124. #endif
  125. }
  126. // {FC3EAF78-C66E-4ed2-A0AA-1494DFCC13FF}
  127. static const GUID audio_options_guid =
  128. { 0xfc3eaf78, 0xc66e, 0x4ed2, { 0xa0, 0xaa, 0x14, 0x94, 0xdf, 0xcc, 0x13, 0xff } };
  129. AudioOptions::AudioOptions() : CfgItemI(L"Audio options", audio_options_guid)
  130. {
  131. #ifdef GEN_FF
  132. #ifdef WASABI_COMPILE_MEDIACORE
  133. extern void setCrossfader(int crossfade);
  134. registerAttribute(&cfg_audiooptions_crossfader, new int_attrCB(setCrossfader));
  135. #endif
  136. #endif
  137. #ifdef _WASABIRUNTIME
  138. registerAttribute(&cfg_audiooptions_crossfader);
  139. int use_dsound=0;
  140. #ifdef WIN32
  141. //check for Windows version for whether we make DSOUND default
  142. DWORD dwVersion = GetVersion();
  143. DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  144. if (dwVersion < 0x80000000) {
  145. if(dwWindowsMajorVersion<=4) use_dsound=0; // no dsound on NT4/3.51
  146. else use_dsound=1; // dsound yes on 2000/XP
  147. } else
  148. use_dsound=0; // no dsound by default on win9x (per PP)
  149. #endif
  150. registerAttribute(new _bool("DirectSound output", use_dsound));
  151. #endif
  152. }
  153. #ifdef _WASABIRUNTIME
  154. // {C1BD5354-5EC4-406c-B5C0-549718D3AF45}
  155. static const GUID setup_guid =
  156. { 0xc1bd5354, 0x5ec4, 0x406c, { 0xb5, 0xc0, 0x54, 0x97, 0x18, 0xd3, 0xaf, 0x45 } };
  157. SetupOptions::SetupOptions() : CfgItemI("Setup", setup_guid) {
  158. #ifdef WIN32
  159. addChildItem(&filetypes);
  160. #endif
  161. }
  162. // {99CFD75C-1CA7-49e5-B8C0-7D78AA443C10}
  163. static const GUID installed_guid =
  164. { 0x99cfd75c, 0x1ca7, 0x49e5, { 0xb8, 0xc0, 0x7d, 0x78, 0xaa, 0x44, 0x3c, 0x10 } };
  165. InstalledComponents::InstalledComponents() : CfgItemI("Installed components", installed_guid) {
  166. //CUT setCfgXml("config.components");
  167. }
  168. void LanguageCB::onValueChange(Attribute *attr) {
  169. char bufero[WA_MAX_PATH]="";
  170. attr->getData(bufero, WA_MAX_PATH-1);
  171. const char *locname;
  172. for(int i=0;locname=LocalesManager::enumLoadableLocales(i);i++) {
  173. if (STRCASEEQLSAFE(bufero, locname)) {
  174. LocalesManager::setNewLocaleNum(i);
  175. return;
  176. }
  177. }
  178. 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);
  179. }
  180. #endif