PrefApp.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Rene Gollent
  20. */
  21. #include "PrefApp.h"
  22. #include "Vision.h"
  23. #include <stdio.h>
  24. #include <CheckBox.h>
  25. #include <Menu.h>
  26. #include <MenuField.h>
  27. #include <MenuItem.h>
  28. #include <UTF8.h>
  29. AppWindowPrefsView::AppWindowPrefsView (BRect frame)
  30. : BView (frame, "App/Window Prefs", B_FOLLOW_NONE, B_WILL_DRAW)
  31. {
  32. SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  33. BMessage msg (M_APPWINDOWPREFS_SETTING_CHANGED);
  34. float maxWidth (0),
  35. maxHeight (0);
  36. BRect trackingBoundsRect (0.0, 0.0, 0, 0);
  37. BRect checkboxRect(Bounds());
  38. checkboxRect.bottom = checkboxRect.top;
  39. msg.AddString ("setting", "versionParanoid");
  40. fVersionParanoid = new BCheckBox (checkboxRect, "version Paranoid",
  41. S_PREFAPP_VERSION_PARANOID,
  42. new BMessage (msg));
  43. fVersionParanoid->SetValue ((!vision_app->GetBool ("versionParanoid")) ? B_CONTROL_ON : B_CONTROL_OFF);
  44. fVersionParanoid->MoveBy(be_plain_font->StringWidth("S"), 0);
  45. fVersionParanoid->ResizeToPreferred();
  46. trackingBoundsRect = fVersionParanoid->Bounds();
  47. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  48. maxHeight += trackingBoundsRect.Height();
  49. AddChild (fVersionParanoid);
  50. checkboxRect.OffsetBy(0.0, fVersionParanoid->Bounds().Height() * 1.2);
  51. msg.ReplaceString ("setting", "catchAltW");
  52. fCatchAltW = new BCheckBox (checkboxRect, "catch AltW",
  53. S_PREFAPP_CMDW,
  54. new BMessage (msg));
  55. fCatchAltW->SetValue ((vision_app->GetBool ("catchAltW")) ? B_CONTROL_ON : B_CONTROL_OFF);
  56. fCatchAltW->MoveBy(be_plain_font->StringWidth("S"), 0);
  57. fCatchAltW->ResizeToPreferred();
  58. trackingBoundsRect = fCatchAltW->Bounds();
  59. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  60. maxHeight += trackingBoundsRect.Height() * 1.2;
  61. AddChild (fCatchAltW);
  62. checkboxRect.OffsetBy(0.0, fCatchAltW->Bounds().Height() * 1.2);
  63. msg.ReplaceString ("setting", "stripcolors");
  64. fStripColors = new BCheckBox (checkboxRect, "stripcolors",
  65. S_PREFAPP_STRIP_MIRC,
  66. new BMessage (msg));
  67. fStripColors->SetValue ((vision_app->GetBool ("stripcolors")) ? B_CONTROL_ON : B_CONTROL_OFF);
  68. fStripColors->MoveBy(be_plain_font->StringWidth("S"), 0);
  69. fStripColors->ResizeToPreferred();
  70. trackingBoundsRect = fStripColors->Bounds();
  71. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  72. maxHeight += trackingBoundsRect.Height() * 1.5;
  73. AddChild (fStripColors);
  74. checkboxRect.OffsetBy(0.0, fStripColors->Bounds().Height() * 1.2);
  75. msg.ReplaceString ("setting", "Newbie spam mode");
  76. fSpamMode = new BCheckBox (checkboxRect, "newbiespammode",
  77. S_PREFAPP_WARN_MULTILINE,
  78. new BMessage (msg));
  79. fSpamMode->SetValue ((vision_app->GetBool ("Newbie Spam Mode")) ? B_CONTROL_ON : B_CONTROL_OFF);
  80. fSpamMode->MoveBy(be_plain_font->StringWidth("S"), 0);
  81. fSpamMode->ResizeToPreferred();
  82. trackingBoundsRect = fSpamMode->Bounds();
  83. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  84. maxHeight += trackingBoundsRect.Height() * 1.5;
  85. AddChild (fSpamMode);
  86. checkboxRect.OffsetBy(0.0, fSpamMode->Bounds().Height() * 1.2);
  87. msg.ReplaceString ("setting", "queryOnMsg");
  88. fQueryMsg = new BCheckBox (checkboxRect, "queryOnMsg",
  89. S_PREFAPP_QUERY_MSG,
  90. new BMessage (msg));
  91. fQueryMsg->SetValue ((vision_app->GetBool ("queryOnMsg")) ? B_CONTROL_ON : B_CONTROL_OFF);
  92. fQueryMsg->MoveBy(be_plain_font->StringWidth("S"), 0);
  93. fQueryMsg->ResizeToPreferred();
  94. trackingBoundsRect = fSpamMode->Bounds();
  95. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  96. maxHeight += trackingBoundsRect.Height() * 1.5;
  97. AddChild (fQueryMsg);
  98. checkboxRect.OffsetBy(0.0, fQueryMsg->Bounds().Height() * 1.2);
  99. BMenu *encMenu(CreateEncodingMenu());
  100. checkboxRect.left = 0.0;
  101. checkboxRect.right = Bounds().Width();
  102. checkboxRect.bottom += fQueryMsg->Bounds().Height() * 1.2;
  103. fEncodings = new BMenuField(checkboxRect, "encoding", "Encoding: ", encMenu);
  104. AddChild (fEncodings);
  105. fEncodings->Menu()->SetLabelFromMarked(true);
  106. trackingBoundsRect = fEncodings->Bounds();
  107. maxWidth = (maxWidth < trackingBoundsRect.Width()) ? trackingBoundsRect.Width() : maxWidth;
  108. maxHeight += trackingBoundsRect.Height() * 1.5;
  109. ResizeTo(maxWidth, maxHeight);
  110. }
  111. AppWindowPrefsView::~AppWindowPrefsView (void)
  112. {
  113. }
  114. void
  115. AppWindowPrefsView::AttachedToWindow (void)
  116. {
  117. BView::AttachedToWindow();
  118. }
  119. void
  120. AppWindowPrefsView::AllAttached (void)
  121. {
  122. fVersionParanoid->SetTarget (this);
  123. fCatchAltW->SetTarget (this);
  124. fStripColors->SetTarget (this);
  125. fSpamMode->SetTarget (this);
  126. fQueryMsg->SetTarget (this);
  127. fEncodings->Menu()->SetTargetForItems (this);
  128. fEncodings->ResizeTo(Bounds().Width() - 15, fEncodings->Bounds().Height());
  129. fEncodings->SetDivider(StringWidth("Encoding: ") + 5);
  130. fEncodings->MoveTo (fQueryMsg->Frame().left + 5, fQueryMsg->Frame().bottom + 5);
  131. SetEncodingItem(vision_app->GetInt32("encoding"));
  132. BView::AllAttached();
  133. }
  134. void
  135. AppWindowPrefsView::SetEncodingItem(int32 encoding)
  136. {
  137. BMenuItem *item (NULL);
  138. for (int32 i = 0; i < fEncodings->Menu()->CountItems(); i++)
  139. {
  140. item = fEncodings->Menu()->ItemAt(i);
  141. if (item->Message()->FindInt32("encoding") == encoding)
  142. {
  143. item->SetMarked(true);
  144. break;
  145. }
  146. }
  147. }
  148. BMenu *
  149. AppWindowPrefsView::CreateEncodingMenu(void)
  150. {
  151. BMessage msg(M_APPWINDOWPREFS_ENCODING_CHANGED);
  152. BMenu *encMenu (new BMenu("Encodings"));
  153. msg.AddInt32("encoding", B_ISO1_CONVERSION);
  154. encMenu->AddItem (new BMenuItem("Western (ISO 8859-1)", new BMessage(msg)));
  155. msg.ReplaceInt32("encoding", B_ISO2_CONVERSION);
  156. encMenu->AddItem (new BMenuItem("Central European (ISO 8859-2)", new BMessage(msg)));
  157. msg.ReplaceInt32("encoding", B_ISO5_CONVERSION);
  158. encMenu->AddItem (new BMenuItem("Cyrillic (ISO 8859-5)", new BMessage(msg)));
  159. msg.ReplaceInt32("encoding", B_KOI8R_CONVERSION);
  160. encMenu->AddItem (new BMenuItem("Cyrillic (KOI8-R)", new BMessage(msg)));
  161. msg.ReplaceInt32("encoding", B_ISO13_CONVERSION);
  162. encMenu->AddItem (new BMenuItem("Baltic (ISO 8859-13)", new BMessage(msg)));
  163. msg.ReplaceInt32("encoding", B_MS_DOS_866_CONVERSION);
  164. encMenu->AddItem (new BMenuItem("Cyrillic (MS-DOS 866)", new BMessage(msg)));
  165. msg.ReplaceInt32("encoding", B_MS_WINDOWS_1251_CONVERSION);
  166. encMenu->AddItem (new BMenuItem("Cyrillic (Windows 1251)", new BMessage(msg)));
  167. msg.ReplaceInt32("encoding", B_ISO7_CONVERSION);
  168. encMenu->AddItem (new BMenuItem("Greek (ISO 8859-7)", new BMessage(msg)));
  169. msg.ReplaceInt32("encoding", B_SJIS_CONVERSION);
  170. encMenu->AddItem (new BMenuItem("Japanese (Shift-JIS)", new BMessage(msg)));
  171. msg.ReplaceInt32("encoding", B_EUC_CONVERSION);
  172. encMenu->AddItem (new BMenuItem("Japanese (EUC)", new BMessage(msg)));
  173. msg.ReplaceInt32("encoding", B_JIS_CONVERSION);
  174. encMenu->AddItem (new BMenuItem("Japanese (JIS)", new BMessage(msg)));
  175. msg.ReplaceInt32("encoding", B_EUC_KR_CONVERSION);
  176. encMenu->AddItem (new BMenuItem("Korean (EUC)", new BMessage(msg)));
  177. msg.ReplaceInt32("encoding", B_UNICODE_CONVERSION);
  178. encMenu->AddItem (new BMenuItem("Unicode (UTF-8)", new BMessage(msg)));
  179. msg.ReplaceInt32("encoding", B_MAC_ROMAN_CONVERSION);
  180. encMenu->AddItem (new BMenuItem("Western (Mac Roman)", new BMessage(msg)));
  181. msg.ReplaceInt32("encoding", B_MS_WINDOWS_CONVERSION);
  182. encMenu->AddItem (new BMenuItem("Western (Windows)", new BMessage(msg)));
  183. return encMenu;
  184. }
  185. void
  186. AppWindowPrefsView::MessageReceived (BMessage *msg)
  187. {
  188. switch (msg->what)
  189. {
  190. case M_APPWINDOWPREFS_ENCODING_CHANGED:
  191. {
  192. BMenuItem *source (NULL);
  193. msg->FindPointer ("source", reinterpret_cast<void **>(&source));
  194. source->SetMarked(true);
  195. int32 encoding (msg->FindInt32("encoding"));
  196. vision_app->SetInt32("encoding", encoding);
  197. }
  198. break;
  199. case M_APPWINDOWPREFS_SETTING_CHANGED:
  200. {
  201. BControl *source (NULL);
  202. msg->FindPointer ("source", reinterpret_cast<void **>(&source));
  203. BString setting;
  204. msg->FindString ("setting", &setting);
  205. int32 value (source->Value() == B_CONTROL_ON);
  206. if ((setting.ICompare ("versionParanoid") == 0))
  207. value = !value;
  208. vision_app->SetBool (setting.String(), value);
  209. }
  210. break;
  211. default:
  212. BView::MessageReceived(msg);
  213. break;
  214. }
  215. }