xref: /haiku/headers/os/interface/Alert.h (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
1 /*
2  * Copyright 2001-2015 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_ALERT_H
6 #define	_ALERT_H
7 
8 
9 #include <vector>
10 
11 #include <Window.h>
12 
13 
14 // enum for flavors of alert
15 enum alert_type {
16 	B_EMPTY_ALERT = 0,
17 	B_INFO_ALERT,
18 	B_IDEA_ALERT,
19 	B_WARNING_ALERT,
20 	B_STOP_ALERT
21 };
22 
23 enum button_spacing {
24 	B_EVEN_SPACING = 0,
25 	B_OFFSET_SPACING
26 };
27 
28 
29 class BBitmap;
30 class BButton;
31 class BGroupLayout;
32 class BInvoker;
33 class BTextView;
34 class TAlertView;
35 
36 
37 class BAlert : public BWindow {
38 public:
39 								BAlert();
40 								BAlert(const char* title, const char* text,
41 									const char* button1,
42 									const char* button2 = NULL,
43 									const char* button3 = NULL,
44 									button_width width = B_WIDTH_AS_USUAL,
45 									alert_type type = B_INFO_ALERT);
46 								BAlert(const char* title, const char* text,
47 									const char* button1, const char* button2,
48 									const char* button3, button_width width,
49 									button_spacing spacing,
50 									alert_type type = B_INFO_ALERT);
51 								BAlert(BMessage* data);
52 	virtual						~BAlert();
53 
54 	// Archiving
55 	static	BArchivable*		Instantiate(BMessage* data);
56 	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
57 
58 	// BAlert guts
59 			alert_type			Type() const;
60 			void				SetType(alert_type type);
61 			void				SetIcon(BBitmap* bitmap);
62 			void				SetText(const char* text);
63 			void				SetButtonSpacing(button_spacing spacing);
64 			void				SetButtonWidth(button_width width);
65 
66 			void				SetShortcut(int32 buttonIndex, char key);
67 			char				Shortcut(int32 buttonIndex) const;
68 
69 			int32				Go();
70 			status_t			Go(BInvoker* invoker);
71 
72 	virtual	void				MessageReceived(BMessage* message);
73 	virtual	void				FrameResized(float newWidth, float newHeight);
74 
75 			void				AddButton(const char* label, char key = 0);
76 			int32				CountButtons() const;
77 			BButton*			ButtonAt(int32 index) const;
78 
79 			BTextView*			TextView() const;
80 
81 	virtual BHandler*			ResolveSpecifier(BMessage* message, int32 index,
82 									BMessage* specifier, int32 form,
83 									const char* property);
84 	virtual	status_t			GetSupportedSuites(BMessage* data);
85 
86 	virtual void				DispatchMessage(BMessage* message,
87 									BHandler* handler);
88 	virtual	void				Quit();
89 	virtual	bool				QuitRequested();
90 
91 	virtual status_t			Perform(perform_code d, void* arg);
92 
93 	static	BPoint				AlertPosition(float width, float height);
94 
95 private:
96 	virtual	void				_ReservedAlert1();
97 	virtual	void				_ReservedAlert2();
98 	virtual	void				_ReservedAlert3();
99 
100 			void				_Init(const char* text, const char* button1,
101 									const char* button2, const char* button3,
102 									button_width width, button_spacing spacing,
103 									alert_type type);
104 			BBitmap*			_CreateTypeIcon();
105 			BButton*			_CreateButton(int32 which, const char* label);
106 			void				_Prepare();
107 
108 private:
109 			sem_id				fAlertSem;
110 			int32				fAlertValue;
111 			TAlertView*			fIconView;
112 			BTextView*			fTextView;
113 			BGroupLayout*		fButtonLayout;
114 			std::vector<BButton*> fButtons;
115 			std::vector<char>	fKeys;
116 			uint8				fType;
117 			uint8				fButtonSpacing;
118 			uint8				fButtonWidth;
119 			BInvoker*			fInvoker;
120 			uint32				_reserved[1];
121 };
122 
123 
124 #endif	// _ALERT_H
125