xref: /haiku/src/apps/webpositive/support/FontSelectionView.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2001-2010, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Mark Hogben
7  *		DarkWyrm <bpmagic@columbus.rr.com>
8  *		Axel Dörfler, axeld@pinc-software.de
9  *		Philippe Saint-Pierre, stpere@gmail.com
10  *		Stephan Aßmus <superstippi@gmx.de>
11  */
12 #ifndef FONT_SELECTION_VIEW_H
13 #define FONT_SELECTION_VIEW_H
14 
15 
16 #include <Font.h>
17 #include <Handler.h>
18 
19 class BLayoutItem;
20 class BBox;
21 class BMenu;
22 class BMenuField;
23 class BPopUpMenu;
24 class BTextView;
25 class BView;
26 
27 
28 class FontSelectionView : public BHandler {
29 public:
30 								FontSelectionView(const char* name,
31 									const char* label, bool separateStyles,
32 									const BFont* font = NULL);
33 	virtual						~FontSelectionView();
34 
35 			void				AttachedToLooper();
36 	virtual void				MessageReceived(BMessage* message);
37 
38 			void				SetMessage(BMessage* message);
39 			void				SetTarget(BHandler* target);
40 
41 			void				SetFont(const BFont& font, float size);
42 			void				SetFont(const BFont& font);
43 			void				SetSize(float size);
44 			const BFont&		Font() const;
45 
46 			void				SetDefaults();
47 			void				Revert();
48 			bool				IsDefaultable();
49 			bool				IsRevertable();
50 
51 			void				UpdateFontsMenu();
52 
53 			BLayoutItem*	 	CreateSizesLabelLayoutItem();
54 			BLayoutItem*		CreateSizesMenuBarLayoutItem();
55 
56 			BLayoutItem* 		CreateFontsLabelLayoutItem();
57 			BLayoutItem*		CreateFontsMenuBarLayoutItem();
58 
59 			BLayoutItem* 		CreateStylesLabelLayoutItem();
60 			BLayoutItem*		CreateStylesMenuBarLayoutItem();
61 
62 			BView*				PreviewBox() const;
63 
64 private:
65 			void				_Invoke();
66 
67 			BFont				_DefaultFont() const;
68 			void				_SelectCurrentFont(bool select);
69 			void				_SelectCurrentSize(bool select);
70 			void				_UpdateFontPreview();
71 			void				_BuildSizesMenu();
72 			void				_AddStylesToMenu(const BFont& font,
73 									BMenu* menu) const;
74 
75 protected:
76 			BMenuField*			fFontsMenuField;
77 			BMenuField*			fStylesMenuField;
78 			BMenuField*			fSizesMenuField;
79 			BPopUpMenu*			fFontsMenu;
80 			BPopUpMenu*			fStylesMenu;
81 			BPopUpMenu*			fSizesMenu;
82 			BTextView*			fPreviewTextView;
83 			float				fPreviewTextWidth;
84 			BBox*				fPreviewBox;
85 
86 			BFont				fSavedFont;
87 			BFont				fCurrentFont;
88 
89 			BMessage*			fMessage;
90 			BHandler*			fTarget;
91 };
92 
93 #endif	// FONT_SELECTION_VIEW_H
94