xref: /haiku/src/apps/mail/Prefs.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 
36 #include "Prefs.h"
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <InterfaceKit.h>
42 #include <StorageKit.h>
43 #include <E-mail.h>
44 #include <Application.h>
45 
46 #ifdef __HAIKU__
47 # include <GridView.h>
48 # include <GroupLayoutBuilder.h>
49 #endif // __HAIKU__
50 
51 #include <MailSettings.h>
52 #include <mail_encoding.h>
53 #include <MDRLanguage.h>
54 
55 #include <String.h>
56 #include <CharacterSet.h>
57 #include <CharacterSetRoster.h>
58 
59 using namespace BPrivate;
60 
61 #include "MailApp.h"
62 #include "MailSupport.h"
63 #include "MailWindow.h"
64 #include "Messages.h"
65 
66 #define BUTTON_WIDTH		70
67 #define BUTTON_HEIGHT		20
68 #define ITEM_SPACE			6
69 
70 #define FONT_TEXT			MDR_DIALECT_CHOICE ("Font:", "フォント:")
71 #define SIZE_TEXT			MDR_DIALECT_CHOICE ("Size:", "サイズ:")
72 #define LEVEL_TEXT			MDR_DIALECT_CHOICE ("User Level:", "ユーザーレベル:")
73 #define WRAP_TEXT			MDR_DIALECT_CHOICE ("Text Wrapping:", "テキスト・ラップ:")
74 #define ATTACH_ATTRIBUTES_TEXT	MDR_DIALECT_CHOICE ("Attach Attributes:", "ファイル属性情報:")
75 #define QUOTES_TEXT			MDR_DIALECT_CHOICE ("Colored Quotes:", "引用部分の着色:")
76 #define ACCOUNT_TEXT		MDR_DIALECT_CHOICE ("Default Account:", "標準アカウント:")
77 #define REPLYTO_TEXT		MDR_DIALECT_CHOICE ("Reply Account:", "返信用アカウント:")
78 #define REPLYTO_USE_DEFAULT_TEXT	MDR_DIALECT_CHOICE ("Use Default Account", "標準アカウントを使う")
79 #define REPLYTO_FROM_MAIL_TEXT		MDR_DIALECT_CHOICE ("Account From Mail", "メールのアカウントを使う")
80 #define REPLY_PREAMBLE_TEXT		MDR_DIALECT_CHOICE ("Reply Preamble:", "返信へ追加:")
81 #define SIGNATURE_TEXT		MDR_DIALECT_CHOICE ("Auto Signature:", "自動署名:")
82 #define ENCODING_TEXT		MDR_DIALECT_CHOICE ("Encoding:", "エンコード形式:")
83 #define WARN_UNENCODABLE_TEXT	MDR_DIALECT_CHOICE ("Warn Unencodable:", "警告: エンコードできません")
84 #define SPELL_CHECK_START_ON_TEXT	MDR_DIALECT_CHOICE ("Initial Spell Check Mode:", "編集時スペルチェック:")
85 #define AUTO_MARK_READ_TEXT	MDR_DIALECT_CHOICE ("Automatically mark mail as read:", "Automatically mark mail as read:")
86 
87 #define BUTTONBAR_TEXT		MDR_DIALECT_CHOICE ("Button Bar:", "ボタンバー:")
88 
89 #define OK_BUTTON_X1		(PREF_WIDTH - BUTTON_WIDTH - 6)
90 #define OK_BUTTON_X2		(OK_BUTTON_X1 + BUTTON_WIDTH)
91 #define OK_BUTTON_TEXT		MDR_DIALECT_CHOICE ("OK", "設定")
92 #define CANCEL_BUTTON_TEXT	MDR_DIALECT_CHOICE ("Cancel", "中止")
93 
94 #define REVERT_BUTTON_X1	8
95 #define REVERT_BUTTON_X2	(REVERT_BUTTON_X1 + BUTTON_WIDTH)
96 #define REVERT_BUTTON_TEXT	MDR_DIALECT_CHOICE ("Revert", "復元")
97 
98 enum	P_MESSAGES			{P_OK = 128, P_CANCEL, P_REVERT, P_FONT,
99 							 P_SIZE, P_LEVEL, P_WRAP, P_ATTACH_ATTRIBUTES,
100 							 P_SIG, P_ENC, P_WARN_UNENCODABLE,
101 							 P_SPELL_CHECK_START_ON, P_BUTTON_BAR,
102 							 P_ACCOUNT, P_REPLYTO, P_REPLY_PREAMBLE,
103 							 P_COLORED_QUOTES, P_MARK_READ};
104 
105 #define ICON_LABEL_TEXT MDR_DIALECT_CHOICE ("Show Icons & Labels", "アイコンとラベル")
106 #define ICON_TEXT MDR_DIALECT_CHOICE ("Show Icons Only", "アイコンのみ")
107 #define HIDE_TEXT MDR_DIALECT_CHOICE ("Hide", "隠す")
108 
109 
110 extern BPoint	prefs_window;
111 
112 #define  ATTRIBUTE_ON_TEXT MDR_DIALECT_CHOICE ("Include BeOS Attributes in Attachments", "BeOSの属性を付ける")
113 #define  ATTRIBUTE_OFF_TEXT MDR_DIALECT_CHOICE ("No BeOS Attributes, just Plain Data", "BeOSの属性を付けない(データのみ)")
114 
115 //#pragma mark -
116 
117 
118 #ifdef __HAIKU__
119 # define USE_LAYOUT_MANAGEMENT 1
120 #else
121 # define USE_LAYOUT_MANAGEMENT 0
122 #endif
123 
124 
125 #if USE_LAYOUT_MANAGEMENT
126 static inline void
127 add_menu_to_layout(BMenuField* menu, BGridLayout* layout, int32& row)
128 {
129 	menu->SetAlignment(B_ALIGN_RIGHT);
130 	layout->AddItem(menu->CreateLabelLayoutItem(), 0, row);
131 	layout->AddItem(menu->CreateMenuBarLayoutItem(), 1, row, 2);
132 	row++;
133 }
134 #endif
135 
136 
137 TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap,
138 	bool* attachAttributes, bool* cquotes, uint32* account, int32* replyTo,
139 	char** preamble, char** sig, uint32* encoding, bool* warnUnencodable,
140 	bool* spellCheckStartOn, bool* autoMarkRead, uint8* buttonBar)
141 	:
142 #if USE_LAYOUT_MANAGEMENT
143 	BWindow(rect, MDR_DIALECT_CHOICE ("Mail Preferences", "Mailの設定"),
144 		B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
145 			| B_AUTO_UPDATE_SIZE_LIMITS),
146 #else
147 	BWindow(rect, MDR_DIALECT_CHOICE ("Mail Preferences", "Mailの設定"),
148 		B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
149 #endif
150 
151 	fNewWrap(wrap),
152 	fWrap(*fNewWrap),
153 
154 	fNewAttachAttributes(attachAttributes),
155 	fAttachAttributes(*fNewAttachAttributes),
156 
157 	fNewButtonBar(buttonBar),
158 	fButtonBar(*fNewButtonBar),
159 
160 	fNewColoredQuotes(cquotes),
161 	fColoredQuotes(*fNewColoredQuotes),
162 
163 	fNewAccount(account),
164 	fAccount(*fNewAccount),
165 
166 	fNewReplyTo(replyTo),
167 	fReplyTo(*fNewReplyTo),
168 
169 	fNewPreamble(preamble),
170 
171 	fNewSignature(sig),
172 	fSignature((char*)malloc(strlen(*fNewSignature) + 1)),
173 
174 	fNewFont(font),
175 	fFont(*fNewFont),
176 
177 	fNewEncoding(encoding),
178 	fEncoding(*fNewEncoding),
179 
180 	fNewWarnUnencodable(warnUnencodable),
181 	fWarnUnencodable(*fNewWarnUnencodable),
182 
183 	fNewSpellCheckStartOn(spellCheckStartOn),
184 	fSpellCheckStartOn(*fNewSpellCheckStartOn),
185 
186 	fNewAutoMarkRead(autoMarkRead),
187 	fAutoMarkRead(*fNewAutoMarkRead)
188 {
189 	strcpy(fSignature, *fNewSignature);
190 
191 	BMenuField* menu;
192 
193 #if USE_LAYOUT_MANAGEMENT
194 	// group boxes
195 
196 	const float kSpacing = 8;
197 
198 	BGridView* interfaceView = new BGridView(kSpacing, kSpacing);
199 	BGridLayout* interfaceLayout = interfaceView->GridLayout();
200 	interfaceLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing);
201 	BGridView* mailView = new BGridView(kSpacing, kSpacing);
202 	BGridLayout* mailLayout = mailView->GridLayout();
203 	mailLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing);
204 
205 	interfaceLayout->AlignLayoutWith(mailLayout, B_HORIZONTAL);
206 
207 	BBox* interfaceBox = new BBox(B_FANCY_BORDER, interfaceView);
208 	interfaceBox->SetLabel(MDR_DIALECT_CHOICE ("User Interface",
209 		"ユーザーインターフェース"));
210 	BBox* mailBox = new BBox(B_FANCY_BORDER, mailView);
211 	mailBox->SetLabel(MDR_DIALECT_CHOICE ("Mailing", "メール関係"));
212 
213 	// revert, ok & cancel
214 
215 	BButton* okButton = new BButton("ok", OK_BUTTON_TEXT, new BMessage(P_OK));
216 	okButton->MakeDefault(true);
217 
218 	BButton* cancelButton = new BButton("cancel", CANCEL_BUTTON_TEXT,
219 		new BMessage(P_CANCEL));
220 
221 	fRevert = new BButton("revert", REVERT_BUTTON_TEXT,
222 		new BMessage(P_REVERT));
223 	fRevert->SetEnabled(false);
224 
225 	// User Interface
226 	int32 layoutRow = 0;
227 
228 	fButtonBarMenu = _BuildButtonBarMenu(*buttonBar);
229 	menu = new BMenuField("bar", BUTTONBAR_TEXT, fButtonBarMenu, NULL);
230 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
231 
232 	fFontMenu = _BuildFontMenu(font);
233 	menu = new BMenuField("font", FONT_TEXT, fFontMenu, NULL);
234 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
235 
236 	fSizeMenu = _BuildSizeMenu(font);
237 	menu = new BMenuField("size", SIZE_TEXT, fSizeMenu, NULL);
238 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
239 
240 	fColoredQuotesMenu = _BuildColoredQuotesMenu(fColoredQuotes);
241 	menu = new BMenuField("cquotes", QUOTES_TEXT, fColoredQuotesMenu, NULL);
242 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
243 
244 	fSpellCheckStartOnMenu = _BuildSpellCheckStartOnMenu(fSpellCheckStartOn);
245 	menu = new BMenuField("spellCheckStartOn", SPELL_CHECK_START_ON_TEXT,
246 		fSpellCheckStartOnMenu, NULL);
247 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
248 
249 	fAutoMarkReadMenu = _BuildAutoMarkReadMenu(fAutoMarkRead);
250 	menu = new BMenuField("autoMarkRead", AUTO_MARK_READ_TEXT,
251 		fAutoMarkReadMenu,	NULL);
252 	add_menu_to_layout(menu, interfaceLayout, layoutRow);
253 	// Mail Accounts
254 
255 	layoutRow = 0;
256 
257 	fAccountMenu = _BuildAccountMenu(fAccount);
258 	menu = new BMenuField("account", ACCOUNT_TEXT, fAccountMenu, NULL);
259 	add_menu_to_layout(menu, mailLayout, layoutRow);
260 
261 	fReplyToMenu = _BuildReplyToMenu(fReplyTo);
262 	menu = new BMenuField("replyTo", REPLYTO_TEXT, fReplyToMenu, NULL);
263 	add_menu_to_layout(menu, mailLayout, layoutRow);
264 
265 	// Mail Contents
266 
267 	fReplyPreamble = new BTextControl("replytext", REPLY_PREAMBLE_TEXT,
268 		*preamble, new BMessage(P_REPLY_PREAMBLE));
269 	fReplyPreamble->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
270 
271 	fReplyPreambleMenu = _BuildReplyPreambleMenu();
272 	menu = new BMenuField("replyPreamble", NULL, fReplyPreambleMenu, NULL);
273 	menu->SetExplicitMaxSize(BSize(27, B_SIZE_UNSET));
274 
275 	mailLayout->AddItem(fReplyPreamble->CreateLabelLayoutItem(), 0, layoutRow);
276 	mailLayout->AddItem(fReplyPreamble->CreateTextViewLayoutItem(), 1,
277 		layoutRow);
278 	mailLayout->AddView(menu, 2, layoutRow);
279 	layoutRow++;
280 
281 	fSignatureMenu = _BuildSignatureMenu(*sig);
282 	menu = new BMenuField("sig", SIGNATURE_TEXT, fSignatureMenu, NULL);
283 	add_menu_to_layout(menu, mailLayout, layoutRow);
284 
285 	fEncodingMenu = _BuildEncodingMenu(fEncoding);
286 	menu = new BMenuField("enc", ENCODING_TEXT, fEncodingMenu, NULL);
287 	add_menu_to_layout(menu, mailLayout, layoutRow);
288 
289 	fWarnUnencodableMenu = _BuildWarnUnencodableMenu(fWarnUnencodable);
290 	menu = new BMenuField("warnUnencodable", WARN_UNENCODABLE_TEXT,
291 		fWarnUnencodableMenu, NULL);
292 	add_menu_to_layout(menu, mailLayout, layoutRow);
293 
294 	fWrapMenu = _BuildWrapMenu(*wrap);
295 	menu = new BMenuField("wrap", WRAP_TEXT, fWrapMenu, NULL);
296 	add_menu_to_layout(menu, mailLayout, layoutRow);
297 
298 	fAttachAttributesMenu = _BuildAttachAttributesMenu(*attachAttributes);
299 	menu = new BMenuField("attachAttributes", ATTACH_ATTRIBUTES_TEXT,
300 		fAttachAttributesMenu, NULL);
301 	add_menu_to_layout(menu, mailLayout, layoutRow);
302 
303 	SetLayout(new BGroupLayout(B_HORIZONTAL));
304 
305 	AddChild(BGroupLayoutBuilder(B_VERTICAL, kSpacing)
306 		.Add(interfaceBox)
307 		.Add(mailBox)
308 		.Add(BGroupLayoutBuilder(B_HORIZONTAL, kSpacing)
309 			.Add(fRevert)
310 			.AddGlue()
311 			.Add(cancelButton)
312 			.Add(okButton)
313 		)
314 		.SetInsets(kSpacing, kSpacing, kSpacing, kSpacing)
315 	);
316 
317 	Show();
318 
319 #else // #if !USE_LAYOUT_MANAGEMENT
320 
321 	BRect r = Bounds();
322 	BView *view = new BView(r, NULL, B_FOLLOW_ALL, B_FRAME_EVENTS);
323 	view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
324 	AddChild(view);
325 
326 	// determine font height
327 	font_height fontHeight;
328 	view->GetFontHeight(&fontHeight);
329 	int32 height = (int32)(fontHeight.ascent + fontHeight.descent
330 		+ fontHeight.leading) + 6;
331 	int32 labelWidth = (int32)view->StringWidth(SPELL_CHECK_START_ON_TEXT)
332 		+ SEPARATOR_MARGIN;
333 
334 	// group boxes
335 
336 	r.Set(8, 4, Bounds().right - 8, 4 + 6 * (height + ITEM_SPACE));
337 	BBox* interfaceBox = new BBox(r , NULL,B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
338 	interfaceBox->SetLabel(MDR_DIALECT_CHOICE ("User Interface",
339 		"ユーザーインターフェース"));
340 	view->AddChild(interfaceBox);
341 
342 	r.top = r.bottom + 8;
343 	r.bottom = r.top + 9 * (height + ITEM_SPACE);
344 	BBox* mailBox = new BBox(r,NULL,B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
345 	mailBox->SetLabel(MDR_DIALECT_CHOICE ("Mailing", "メール関係"));
346 	view->AddChild(mailBox);
347 
348 	// revert, ok & cancel
349 
350 	r.top = r.bottom + 10;
351 	r.bottom = r.top + height;
352 	r.left = OK_BUTTON_X1;
353 	r.right = OK_BUTTON_X2;
354 	BButton* button = new BButton(r, "ok", OK_BUTTON_TEXT, new BMessage(P_OK));
355 	button->MakeDefault(true);
356 	view->AddChild(button);
357 
358 	r.OffsetBy(-(OK_BUTTON_X2 - OK_BUTTON_X1 + 10), 0);
359 	button = new BButton(r, "cancel", CANCEL_BUTTON_TEXT,
360 		new BMessage(P_CANCEL));
361 	view->AddChild(button);
362 
363 	r.left = REVERT_BUTTON_X1;  r.right = REVERT_BUTTON_X2;
364 	fRevert = new BButton(r, "revert", REVERT_BUTTON_TEXT,
365 		new BMessage(P_REVERT));
366 	fRevert->SetEnabled(false);
367 	view->AddChild(fRevert);
368 
369 	// User Interface
370 
371 	r = interfaceBox->Bounds();
372 	r.left += 8;
373 	r.right -= 8;
374 	r.top = height;
375 	r.bottom = r.top + height - 3;
376 	fButtonBarMenu = _BuildButtonBarMenu(*buttonBar);
377 	menu = new BMenuField(r, "bar", BUTTONBAR_TEXT, fButtonBarMenu,
378 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
379 	menu->SetDivider(labelWidth);
380 	menu->SetAlignment(B_ALIGN_RIGHT);
381 	interfaceBox->AddChild(menu);
382 
383 	r.OffsetBy(0, height + ITEM_SPACE);
384 	fFontMenu = _BuildFontMenu(font);
385 	menu = new BMenuField(r, "font", FONT_TEXT, fFontMenu,
386 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
387 	menu->SetDivider(labelWidth);
388 	menu->SetAlignment(B_ALIGN_RIGHT);
389 	interfaceBox->AddChild(menu);
390 
391 	r.OffsetBy(0, height + ITEM_SPACE);
392 	fSizeMenu = _BuildSizeMenu(font);
393 	menu = new BMenuField(r, "size", SIZE_TEXT, fSizeMenu,
394 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
395 	menu->SetDivider(labelWidth);
396 	menu->SetAlignment(B_ALIGN_RIGHT);
397 	interfaceBox->AddChild(menu);
398 
399 	r.OffsetBy(0, height + ITEM_SPACE);
400 	fColoredQuotesMenu = _BuildColoredQuotesMenu(fColoredQuotes);
401 	menu = new BMenuField(r, "cquotes", QUOTES_TEXT, fColoredQuotesMenu,
402 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
403 	menu->SetDivider(labelWidth);
404 	menu->SetAlignment(B_ALIGN_RIGHT);
405 	interfaceBox->AddChild(menu);
406 
407 	r.OffsetBy(0, height + ITEM_SPACE);
408 	fSpellCheckStartOnMenu = _BuildSpellCheckStartOnMenu(fSpellCheckStartOn);
409 	menu = new BMenuField(r, "spellCheckStartOn", SPELL_CHECK_START_ON_TEXT,
410 		fSpellCheckStartOnMenu, B_FOLLOW_ALL,
411 		B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
412 	menu->SetDivider(labelWidth);
413 	menu->SetAlignment(B_ALIGN_RIGHT);
414 	interfaceBox->AddChild(menu);
415 
416 	r.OffsetBy(0, height + ITEM_SPACE);
417 	fAutoMarkReadMenu = _BuildAutoMarkReadMenu(fAutoMarkRead);
418 	menu = new BMenuField("autoMarkRead", AUTO_MARK_READ_TEXT,
419 		fAutoMarkReadMenu,	NULL);
420 	menu->SetDivider(labelWidth);
421 	menu->SetAlignment(B_ALIGN_RIGHT);
422 	interfaceBox->AddChild(menu);
423 
424 	// Mail Accounts
425 
426 	r = mailBox->Bounds();
427 	r.left += 8;
428 	r.right -= 8;
429 	r.top = height;
430 	r.bottom = r.top + height - 3;
431 	fAccountMenu = _BuildAccountMenu(fAccount);
432 	menu = new BMenuField(r, "account", ACCOUNT_TEXT, fAccountMenu,
433 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
434 	menu->SetDivider(labelWidth);
435 	menu->SetAlignment(B_ALIGN_RIGHT);
436 	mailBox->AddChild(menu);
437 
438 	r.OffsetBy(0, height + ITEM_SPACE);
439 	fReplyToMenu = _BuildReplyToMenu(fReplyTo);
440 	menu = new BMenuField(r, "replyTo", REPLYTO_TEXT, fReplyToMenu,
441 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
442 	menu->SetDivider(labelWidth);
443 	menu->SetAlignment(B_ALIGN_RIGHT);
444 	mailBox->AddChild(menu);
445 
446 	// Mail Contents
447 
448 	r.OffsetBy(0, height + ITEM_SPACE);
449 	r.right -= 25;
450 	fReplyPreamble = new BTextControl(r, "replytext", REPLY_PREAMBLE_TEXT,
451 		*preamble, new BMessage(P_REPLY_PREAMBLE), B_FOLLOW_ALL,
452 		B_WILL_DRAW | B_NAVIGABLE);
453 	fReplyPreamble->SetDivider(labelWidth);
454 	fReplyPreamble->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
455 	mailBox->AddChild(fReplyPreamble);
456 
457 	BRect popRect = r;
458 	popRect.left = r.right + 6;
459 	r.right += 25;
460 	popRect.right = r.right;
461 	fReplyPreambleMenu = _BuildReplyPreambleMenu();
462 	menu = new BMenuField(popRect, "replyPreamble", B_EMPTY_STRING,
463 		fReplyPreambleMenu, B_FOLLOW_ALL,
464 		B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
465 	menu->SetDivider(0);
466 	mailBox->AddChild(menu);
467 
468 	r.OffsetBy(0, height + ITEM_SPACE);
469 	fSignatureMenu = _BuildSignatureMenu(*sig);
470 	menu = new BMenuField(r, "sig", SIGNATURE_TEXT, fSignatureMenu,
471 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
472 	menu->SetDivider(labelWidth);
473 	menu->SetAlignment(B_ALIGN_RIGHT);
474 	mailBox->AddChild(menu);
475 
476 	r.OffsetBy(0, height + ITEM_SPACE);
477 	fEncodingMenu = _BuildEncodingMenu(fEncoding);
478 	menu = new BMenuField(r, "enc", ENCODING_TEXT, fEncodingMenu,
479 		B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
480 	menu->SetDivider(labelWidth);
481 	menu->SetAlignment(B_ALIGN_RIGHT);
482 	mailBox->AddChild(menu);
483 
484 	r.OffsetBy(0, height + ITEM_SPACE);
485 	fWarnUnencodableMenu = _BuildWarnUnencodableMenu(fWarnUnencodable);
486 	menu = new BMenuField(r, "warnUnencodable", WARN_UNENCODABLE_TEXT,
487 		fWarnUnencodableMenu, B_FOLLOW_ALL,
488 		B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
489 	menu->SetDivider(labelWidth);
490 	menu->SetAlignment(B_ALIGN_RIGHT);
491 	mailBox->AddChild(menu);
492 
493 	r.OffsetBy(0, height + ITEM_SPACE);
494 	fWrapMenu = _BuildWrapMenu(*wrap);
495 	menu = new BMenuField(r, "wrap", WRAP_TEXT, fWrapMenu, B_FOLLOW_ALL,
496 		B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
497 	menu->SetDivider(labelWidth);
498 	menu->SetAlignment(B_ALIGN_RIGHT);
499 	mailBox->AddChild(menu);
500 
501 	r.OffsetBy(0, height + ITEM_SPACE);
502 	fAttachAttributesMenu = _BuildAttachAttributesMenu(*attachAttributes);
503 	menu = new BMenuField(r, "attachAttributes", ATTACH_ATTRIBUTES_TEXT,
504 		fAttachAttributesMenu, B_FOLLOW_ALL,
505 		B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
506 	menu->SetDivider(labelWidth);
507 	menu->SetAlignment(B_ALIGN_RIGHT);
508 	mailBox->AddChild(menu);
509 
510 	ResizeTo(Frame().Width(), fRevert->Frame().bottom + 8);
511 
512 	Show();
513 
514 #endif // #if !USE_LAYOUT_MANAGEMENT
515 }
516 
517 
518 TPrefsWindow::~TPrefsWindow()
519 {
520 	BMessage msg(WINDOW_CLOSED);
521 	msg.AddInt32("kind", PREFS_WINDOW);
522 	msg.AddPoint("window pos", Frame().LeftTop());
523 	be_app->PostMessage(&msg);
524 }
525 
526 
527 void
528 TPrefsWindow::MessageReceived(BMessage* msg)
529 {
530 	bool revert = true;
531 	const char* family;
532 	const char* signature;
533 	const char* style;
534 	char label[256];
535 	int32 new_size;
536 	int32 old_size;
537 	font_family new_family;
538 	font_family old_family;
539 	font_style new_style;
540 	font_style old_style;
541 	BMenuItem* item;
542 	BMessage message;
543 
544 	switch (msg->what) {
545 		case P_OK:
546 			if (strcmp(fReplyPreamble->Text(), *fNewPreamble)) {
547 				free(*fNewPreamble);
548 				*fNewPreamble
549 					= (char *)malloc(strlen(fReplyPreamble->Text()) + 1);
550 				strcpy(*fNewPreamble, fReplyPreamble->Text());
551 			}
552 			be_app->PostMessage(PREFS_CHANGED);
553 			Quit();
554 			break;
555 
556 		case P_CANCEL:
557 			revert = false;
558 			// supposed to fall through
559 		case P_REVERT:
560 			fFont.GetFamilyAndStyle(&old_family, &old_style);
561 			fNewFont->GetFamilyAndStyle(&new_family, &new_style);
562 			old_size = (int32)fFont.Size();
563 			new_size = (int32)fNewFont->Size();
564 			if (strcmp(old_family, new_family) || strcmp(old_style, new_style)
565 				|| old_size != new_size) {
566 				fNewFont->SetFamilyAndStyle(old_family, old_style);
567 				if (revert) {
568 					sprintf(label, "%s %s", old_family, old_style);
569 					item = fFontMenu->FindItem(label);
570 					if (item != NULL)
571 						item->SetMarked(true);
572 				}
573 
574 				fNewFont->SetSize(old_size);
575 				if (revert) {
576 					sprintf(label, "%ld", old_size);
577 					item = fSizeMenu->FindItem(label);
578 					if (item != NULL)
579 						item->SetMarked(true);
580 				}
581 				message.what = M_FONT;
582 				be_app->PostMessage(&message);
583 			}
584 			*fNewWrap = fWrap;
585 			*fNewAttachAttributes = fAttachAttributes;
586 
587 			if (strcmp(fSignature, *fNewSignature)) {
588 				free(*fNewSignature);
589 				*fNewSignature = (char*)malloc(strlen(fSignature) + 1);
590 				strcpy(*fNewSignature, fSignature);
591 			}
592 
593 			*fNewEncoding = fEncoding;
594 			*fNewWarnUnencodable = fWarnUnencodable;
595 			*fNewSpellCheckStartOn = fSpellCheckStartOn;
596 			*fNewAutoMarkRead = fAutoMarkRead;
597 			*fNewButtonBar = fButtonBar;
598 
599 			be_app->PostMessage(PREFS_CHANGED);
600 
601 			if (revert) {
602 				for (int i = fAccountMenu->CountItems(); --i > 0;) {
603 					BMenuItem *item = fAccountMenu->ItemAt(i);
604 					BMessage* itemMessage = item->Message();
605 					if (itemMessage != NULL
606 						&& itemMessage->FindInt32("id") == *(int32 *)&fAccount) {
607 						item->SetMarked(true);
608 						break;
609 					}
610 				}
611 
612 				strcpy(label,fReplyTo == ACCOUNT_USE_DEFAULT
613 					? REPLYTO_USE_DEFAULT_TEXT : REPLYTO_FROM_MAIL_TEXT);
614 				if ((item = fReplyToMenu->FindItem(label)) != NULL)
615 					item->SetMarked(true);
616 
617 				strcpy(label, fWrap ? "On" : "Off");
618 				if ((item = fWrapMenu->FindItem(label)) != NULL)
619 					item->SetMarked(true);
620 
621 				strcpy(label, fAttachAttributes
622 					? ATTRIBUTE_ON_TEXT : ATTRIBUTE_OFF_TEXT);
623 				if ((item = fAttachAttributesMenu->FindItem(label)) != NULL)
624 					item->SetMarked(true);
625 
626 				strcpy(label, fColoredQuotes ? "On" : "Off");
627 				if ((item = fColoredQuotesMenu->FindItem(label)) != NULL)
628 					item->SetMarked(true);
629 
630 				if (strcmp(fReplyPreamble->Text(), *fNewPreamble))
631 					fReplyPreamble->SetText(*fNewPreamble);
632 
633 				item = fSignatureMenu->FindItem(fSignature);
634 				if (item)
635 					item->SetMarked(true);
636 
637 				uint32 index = 0;
638 				while ((item = fEncodingMenu->ItemAt(index++)) != NULL) {
639 					BMessage* itemMessage = item->Message();
640 					if (itemMessage == NULL)
641 						continue;
642 
643 					int32 encoding;
644 					if (itemMessage->FindInt32("encoding", &encoding) == B_OK
645 						&& (uint32)encoding == *fNewEncoding) {
646 						item->SetMarked(true);
647 						break;
648 					}
649 				}
650 
651 				strcpy(label, fWarnUnencodable ? "On" : "Off");
652 				if ((item = fWarnUnencodableMenu->FindItem(label)) != NULL)
653 					item->SetMarked(true);
654 
655 				strcpy(label, fSpellCheckStartOn ? "On" : "Off");
656 				if ((item = fSpellCheckStartOnMenu->FindItem(label)) != NULL)
657 					item->SetMarked(true);
658 			} else
659 				Quit();
660 			break;
661 
662 		case P_FONT:
663 			family = NULL;
664 			style = NULL;
665 			int32 family_menu_index;
666 			if (msg->FindString("font", &family) == B_OK) {
667 				msg->FindString("style", &style);
668 				fNewFont->SetFamilyAndStyle(family, style);
669 				message.what = M_FONT;
670 				be_app->PostMessage(&message);
671 			}
672 
673 			/* grab this little tidbit so we can set the correct Family */
674 			if (msg->FindInt32("parent_index", &family_menu_index) == B_OK)
675 				fFontMenu->ItemAt(family_menu_index)->SetMarked(true);
676 			break;
677 
678 		case P_SIZE:
679 			old_size = (int32) fNewFont->Size();
680 			msg->FindInt32("size", &new_size);
681 			if (old_size != new_size) {
682 				fNewFont->SetSize(new_size);
683 				message.what = M_FONT;
684 				be_app->PostMessage(&message);
685 			}
686 			break;
687 
688 		case P_WRAP:
689 			msg->FindBool("wrap", fNewWrap);
690 			break;
691 		case P_ATTACH_ATTRIBUTES:
692 			msg->FindBool("attachAttributes", fNewAttachAttributes);
693 			break;
694 		case P_COLORED_QUOTES:
695 			msg->FindBool("cquotes", fNewColoredQuotes);
696 			break;
697 		case P_ACCOUNT:
698 			msg->FindInt32("id",(int32*)fNewAccount);
699 			break;
700 		case P_REPLYTO:
701 			msg->FindInt32("replyTo", fNewReplyTo);
702 			break;
703 		case P_REPLY_PREAMBLE:
704 		{
705 			int32 index = -1;
706 			if (msg->FindInt32("index", &index) < B_OK)
707 				break;
708 			BMenuItem *item = fReplyPreambleMenu->ItemAt(index);
709 			if (item == NULL) {
710 				msg->PrintToStream();
711 				break;
712 			}
713 
714 			BTextView *text = fReplyPreamble->TextView();
715 			// To do: insert at selection point rather than at the end.
716 			text->Insert(text->TextLength(), item->Label(), 2);
717 		}
718 		case P_SIG:
719 			free(*fNewSignature);
720 			if (msg->FindString("signature", &signature) == B_NO_ERROR) {
721 				*fNewSignature = (char *)malloc(strlen(signature) + 1);
722 				strcpy(*fNewSignature, signature);
723 			} else {
724 				*fNewSignature = (char *)malloc(strlen(SIG_NONE) + 1);
725 				strcpy(*fNewSignature, SIG_NONE);
726 			}
727 			break;
728 		case P_ENC:
729 			msg->FindInt32("encoding", (int32 *)fNewEncoding);
730 			break;
731 		case P_WARN_UNENCODABLE:
732 			msg->FindBool("warnUnencodable", fNewWarnUnencodable);
733 			break;
734 		case P_SPELL_CHECK_START_ON:
735 			msg->FindBool("spellCheckStartOn", fNewSpellCheckStartOn);
736 			break;
737 		case P_MARK_READ:
738 			msg->FindBool("autoMarkRead", fNewAutoMarkRead);
739 			be_app->PostMessage(PREFS_CHANGED);
740 			break;
741 		case P_BUTTON_BAR:
742 			msg->FindInt8("bar", (int8 *)fNewButtonBar);
743 			be_app->PostMessage(PREFS_CHANGED);
744 			break;
745 
746 		default:
747 			BWindow::MessageReceived(msg);
748 	}
749 
750 	fFont.GetFamilyAndStyle(&old_family, &old_style);
751 	fNewFont->GetFamilyAndStyle(&new_family, &new_style);
752 	old_size = (int32) fFont.Size();
753 	new_size = (int32) fNewFont->Size();
754 	bool changed = old_size != new_size
755 		|| fWrap != *fNewWrap
756 		|| fAttachAttributes != *fNewAttachAttributes
757 		|| fColoredQuotes != *fNewColoredQuotes
758 		|| fAccount != *fNewAccount
759 		|| fReplyTo != *fNewReplyTo
760 		|| strcmp(old_family, new_family)
761 		|| strcmp(old_style, new_style)
762 		|| strcmp(fReplyPreamble->Text(), *fNewPreamble)
763 		|| strcmp(fSignature, *fNewSignature)
764 		|| fEncoding != *fNewEncoding
765 		|| fWarnUnencodable != *fNewWarnUnencodable
766 		|| fSpellCheckStartOn != *fNewSpellCheckStartOn
767 		|| fAutoMarkRead != *fNewAutoMarkRead
768 		|| fButtonBar != *fNewButtonBar;
769 	fRevert->SetEnabled(changed);
770 }
771 
772 
773 BPopUpMenu*
774 TPrefsWindow::_BuildFontMenu(BFont* font)
775 {
776 	font_family	def_family;
777 	font_style	def_style;
778 	font_family	f_family;
779 	font_style	f_style;
780 
781 	BPopUpMenu *menu = new BPopUpMenu("");
782 	font->GetFamilyAndStyle(&def_family, &def_style);
783 
784 	int32 family_menu_index = 0;
785 	int family_count = count_font_families();
786 	for (int family_loop = 0; family_loop < family_count; family_loop++) {
787 		get_font_family(family_loop, &f_family);
788 		BMenu *family_menu = new BMenu(f_family);
789 
790 		int style_count = count_font_styles(f_family);
791 		for (int style_loop = 0; style_loop < style_count; style_loop++) {
792 			get_font_style(f_family, style_loop, &f_style);
793 
794 			BMessage *msg = new BMessage(P_FONT);
795 			msg->AddString("font", f_family);
796 			msg->AddString("style", f_style);
797 			// we send this to make setting the Family easier when things
798 			// change
799 			msg->AddInt32("parent_index", family_menu_index);
800 
801 			BMenuItem *item = new BMenuItem(f_style, msg);
802 			family_menu->AddItem(item);
803 			if ((strcmp(def_family, f_family) == 0)
804 				&& (strcmp(def_style, f_style) == 0)) {
805 				item->SetMarked(true);
806 			}
807 
808 			item->SetTarget(this);
809 		}
810 
811 		menu->AddItem(family_menu);
812 		BMenuItem *item = menu->ItemAt(family_menu_index);
813 		BMessage *msg = new BMessage(P_FONT);
814 		msg->AddString("font", f_family);
815 
816 		item->SetMessage(msg);
817 		item->SetTarget(this);
818 		if (strcmp(def_family, f_family) == 0)
819 			item->SetMarked(true);
820 
821 		family_menu_index++;
822 	}
823 	return menu;
824 }
825 
826 
827 BPopUpMenu*
828 TPrefsWindow::_BuildLevelMenu(int32 level)
829 {
830 	BMenuItem* item;
831 	BMessage* msg;
832 	BPopUpMenu* menu;
833 
834 	menu = new BPopUpMenu("");
835 	msg = new BMessage(P_LEVEL);
836 	msg->AddInt32("level", L_BEGINNER);
837 	menu->AddItem(item = new BMenuItem(MDR_DIALECT_CHOICE ("Beginner","初心者"),
838 		msg));
839 	if (level == L_BEGINNER)
840 		item->SetMarked(true);
841 
842 	msg = new BMessage(P_LEVEL);
843 	msg->AddInt32("level", L_EXPERT);
844 	menu->AddItem(item = new BMenuItem(MDR_DIALECT_CHOICE ("Expert","上級者"),
845 		msg));
846 	if (level == L_EXPERT)
847 		item->SetMarked(true);
848 
849 	return menu;
850 }
851 
852 
853 BPopUpMenu*
854 TPrefsWindow::_BuildAccountMenu(uint32 account)
855 {
856 	BPopUpMenu* menu = new BPopUpMenu("");
857 	BMenuItem* item;
858 
859 	//menu->SetRadioMode(true);
860 	BList chains;
861 	if (GetOutboundMailChains(&chains) < B_OK) {
862 		menu->AddItem(item = new BMenuItem("<no account found>", NULL));
863 		item->SetEnabled(false);
864 		return menu;
865 	}
866 
867 	BMessage* msg;
868 	for (int32 i = 0; i < chains.CountItems(); i++) {
869 		BMailChain* chain = (BMailChain*)chains.ItemAt(i);
870 		item = new BMenuItem(chain->Name(), msg = new BMessage(P_ACCOUNT));
871 
872 		msg->AddInt32("id",chain->ID());
873 
874 		if (account == chain->ID())
875 			item->SetMarked(true);
876 
877 		menu->AddItem(item);
878 		delete chain;
879 	}
880 	return menu;
881 }
882 
883 
884 BPopUpMenu*
885 TPrefsWindow::_BuildReplyToMenu(int32 account)
886 {
887 	BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING);
888 
889 	BMenuItem* item;
890 	BMessage* msg;
891 	menu->AddItem(item = new BMenuItem(REPLYTO_USE_DEFAULT_TEXT,
892 		msg = new BMessage(P_REPLYTO)));
893 	msg->AddInt32("replyTo", ACCOUNT_USE_DEFAULT);
894 	if (account == ACCOUNT_USE_DEFAULT)
895 		item->SetMarked(true);
896 
897 	menu->AddItem(item = new BMenuItem(REPLYTO_FROM_MAIL_TEXT,
898 		msg = new BMessage(P_REPLYTO)));
899 	msg->AddInt32("replyTo", ACCOUNT_FROM_MAIL);
900 	if (account == ACCOUNT_FROM_MAIL)
901 		item->SetMarked(true);
902 
903 	return menu;
904 }
905 
906 
907 BMenu*
908 TPrefsWindow::_BuildReplyPreambleMenu()
909 {
910 	const char *substitutes[] = {
911 /* To do: Not yet working, leave out for 2.0.0 beta 4:
912 		"%f - First name",
913 		"%l - Last name",
914 */
915 		MDR_DIALECT_CHOICE ("%n - Full name", "%n - フルネーム"),
916 		MDR_DIALECT_CHOICE ("%e - E-mail address", "%e - E-mailアドレス"),
917 		MDR_DIALECT_CHOICE ("%d - Date", "%d - 日付"),
918 		"",
919 		MDR_DIALECT_CHOICE ("\\n - Newline", "\\n - 空行"),
920 		NULL
921 	};
922 
923 	BMenu *menu = new BMenu(B_EMPTY_STRING);
924 
925 	for (int32 i = 0; substitutes[i]; i++) {
926 		if (*substitutes[i] == '\0') {
927 			menu->AddSeparatorItem();
928 		} else {
929 			menu->AddItem(new BMenuItem(substitutes[i],
930 				new BMessage(P_REPLY_PREAMBLE)));
931 		}
932 	}
933 
934 	return menu;
935 }
936 
937 
938 BPopUpMenu*
939 TPrefsWindow::_BuildSignatureMenu(char* sig)
940 {
941 	char name[B_FILE_NAME_LENGTH];
942 	BEntry entry;
943 	BFile file;
944 	BMenuItem* item;
945 	BMessage* msg;
946 	BQuery query;
947 	BVolume vol;
948 	BVolumeRoster volume;
949 
950 	BPopUpMenu* menu = new BPopUpMenu("");
951 
952 	msg = new BMessage(P_SIG);
953 	msg->AddString("signature", SIG_NONE);
954 	menu->AddItem(item = new BMenuItem(SIG_NONE, msg));
955 	if (!strcmp(sig, SIG_NONE))
956 		item->SetMarked(true);
957 
958 	msg = new BMessage(P_SIG);
959 	msg->AddString("signature", SIG_RANDOM);
960 	menu->AddItem(item = new BMenuItem(SIG_RANDOM, msg));
961 	if (!strcmp(sig, SIG_RANDOM))
962 		item->SetMarked(true);
963 	menu->AddSeparatorItem();
964 
965 	volume.GetBootVolume(&vol);
966 	query.SetVolume(&vol);
967 	query.SetPredicate("_signature = *");
968 	query.Fetch();
969 
970 	while (query.GetNextEntry(&entry) == B_NO_ERROR) {
971 		file.SetTo(&entry, O_RDONLY);
972 		if (file.InitCheck() == B_NO_ERROR) {
973 			msg = new BMessage(P_SIG);
974 			file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name));
975 			msg->AddString("signature", name);
976 			menu->AddItem(item = new BMenuItem(name, msg));
977 			if (!strcmp(sig, name))
978 				item->SetMarked(true);
979 		}
980 	}
981 	return menu;
982 }
983 
984 
985 BPopUpMenu*
986 TPrefsWindow::_BuildSizeMenu(BFont* font)
987 {
988 	char label[16];
989 	uint32 loop;
990 	int32 sizes[] = {9, 10, 11, 12, 14, 18, 24};
991 	float size;
992 	BMenuItem* item;
993 	BMessage* msg;
994 	BPopUpMenu* menu;
995 
996 	menu = new BPopUpMenu("");
997 	size = font->Size();
998 	for (loop = 0; loop < sizeof(sizes) / sizeof(int32); loop++) {
999 		msg = new BMessage(P_SIZE);
1000 		msg->AddInt32("size", sizes[loop]);
1001 		sprintf(label, "%ld", sizes[loop]);
1002 		menu->AddItem(item = new BMenuItem(label, msg));
1003 		if (sizes[loop] == (int32)size)
1004 			item->SetMarked(true);
1005 	}
1006 	return menu;
1007 }
1008 
1009 
1010 BPopUpMenu*
1011 TPrefsWindow::_BuildBoolMenu(uint32 what, const char* boolItem, bool isTrue)
1012 {
1013 	BMenuItem* item;
1014 	BMessage* msg;
1015 	BPopUpMenu* menu;
1016 
1017 	menu = new BPopUpMenu("");
1018 	msg = new BMessage(what);
1019 	msg->AddBool(boolItem, true);
1020 	menu->AddItem(item = new BMenuItem("On", msg));
1021 	if (isTrue)
1022 		item->SetMarked(true);
1023 
1024 	msg = new BMessage(what);
1025 	msg->AddInt32(boolItem, false);
1026 	menu->AddItem(item = new BMenuItem("Off", msg));
1027 	if (!isTrue)
1028 		item->SetMarked(true);
1029 
1030 	return menu;
1031 }
1032 
1033 
1034 BPopUpMenu*
1035 TPrefsWindow::_BuildWrapMenu(bool wrap)
1036 {
1037 	return _BuildBoolMenu(P_WRAP, "wrap", wrap);
1038 }
1039 
1040 
1041 BPopUpMenu*
1042 TPrefsWindow::_BuildAttachAttributesMenu(bool attachAttributes)
1043 {
1044 	BMenuItem* item;
1045 	BMessage* msg;
1046 	BPopUpMenu* menu;
1047 
1048 	menu = new BPopUpMenu("");
1049 	msg = new BMessage(P_ATTACH_ATTRIBUTES);
1050 	msg->AddBool("attachAttributes", true);
1051 	menu->AddItem(item = new BMenuItem(ATTRIBUTE_ON_TEXT, msg));
1052 	if (attachAttributes)
1053 		item->SetMarked(true);
1054 
1055 	msg = new BMessage(P_ATTACH_ATTRIBUTES);
1056 	msg->AddInt32("attachAttributes", false);
1057 	menu->AddItem(item = new BMenuItem(ATTRIBUTE_OFF_TEXT, msg));
1058 	if (!attachAttributes)
1059 		item->SetMarked(true);
1060 
1061 	return menu;
1062 }
1063 
1064 
1065 BPopUpMenu*
1066 TPrefsWindow::_BuildColoredQuotesMenu(bool quote)
1067 {
1068 	return _BuildBoolMenu(P_COLORED_QUOTES, "cquotes", quote);
1069 }
1070 
1071 
1072 BPopUpMenu*
1073 TPrefsWindow::_BuildEncodingMenu(uint32 encoding)
1074 {
1075 	BMenuItem* item;
1076 	BMessage* msg;
1077 	BPopUpMenu* menu;
1078 
1079 	menu = new BPopUpMenu("");
1080 
1081 	BCharacterSetRoster roster;
1082 	BCharacterSet charset;
1083 	while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
1084 		BString name(charset.GetPrintName());
1085 		const char* mime = charset.GetMIMEName();
1086 		if (mime)
1087 			name << " (" << mime << ")";
1088 		msg = new BMessage(P_ENC);
1089 		uint32 convert_id;
1090 		if ((mime == 0) || (strcasecmp(mime, "UTF-8") != 0))
1091 			convert_id = charset.GetConversionID();
1092 		else
1093 			convert_id = B_MAIL_UTF8_CONVERSION;
1094 		msg->AddInt32("encoding", convert_id);
1095 		menu->AddItem(item = new BMenuItem(name.String(), msg));
1096 		if (convert_id == encoding)
1097 			item->SetMarked(true);
1098 	}
1099 
1100 	msg = new BMessage(P_ENC);
1101 	msg->AddInt32("encoding", B_MAIL_US_ASCII_CONVERSION);
1102 	menu->AddItem(item = new BMenuItem("US-ASCII", msg));
1103 	if (encoding == B_MAIL_US_ASCII_CONVERSION)
1104 		item->SetMarked(true);
1105 
1106 	return menu;
1107 }
1108 
1109 
1110 BPopUpMenu*
1111 TPrefsWindow::_BuildWarnUnencodableMenu(bool warnUnencodable)
1112 {
1113 	return _BuildBoolMenu(P_WARN_UNENCODABLE, "warnUnencodable",
1114 		warnUnencodable);
1115 }
1116 
1117 
1118 BPopUpMenu*
1119 TPrefsWindow::_BuildSpellCheckStartOnMenu(bool spellCheckStartOn)
1120 {
1121 	return _BuildBoolMenu(P_SPELL_CHECK_START_ON, "spellCheckStartOn",
1122 		spellCheckStartOn);
1123 }
1124 
1125 
1126 BPopUpMenu*
1127 TPrefsWindow::_BuildAutoMarkReadMenu(bool autoMarkRead)
1128 {
1129 	return _BuildBoolMenu(P_MARK_READ, "autoMarkRead",
1130 		autoMarkRead);
1131 }
1132 
1133 
1134 BPopUpMenu*
1135 TPrefsWindow::_BuildButtonBarMenu(uint8 show)
1136 {
1137 	BMenuItem* item;
1138 	BMessage* msg;
1139 	BPopUpMenu* menu = new BPopUpMenu("");
1140 
1141 	msg = new BMessage(P_BUTTON_BAR);
1142 	msg->AddInt8("bar", 1);
1143 	menu->AddItem(item = new BMenuItem(ICON_LABEL_TEXT, msg));
1144 	if (show & 1)
1145 		item->SetMarked(true);
1146 
1147 	msg = new BMessage(P_BUTTON_BAR);
1148 	msg->AddInt8("bar", 2);
1149 	menu->AddItem(item = new BMenuItem(ICON_TEXT, msg));
1150 	if (show & 2)
1151 		item->SetMarked(true);
1152 
1153 	msg = new BMessage(P_BUTTON_BAR);
1154 	msg->AddInt8("bar", 0);
1155 	menu->AddItem(item = new BMenuItem(HIDE_TEXT, msg));
1156 	if (!show)
1157 		item->SetMarked(true);
1158 
1159 	return menu;
1160 }
1161 
1162