xref: /haiku/headers/os/interface/Alert.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
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 								BAlert(BAlert&);
101 			BAlert&				operator=(BAlert&);
102 
103 			void				_Init(const char* text, const char* button1,
104 									const char* button2, const char* button3,
105 									button_width width, button_spacing spacing,
106 									alert_type type);
107 			BBitmap*			_CreateTypeIcon();
108 			BButton*			_CreateButton(int32 which, const char* label);
109 			void				_Prepare();
110 
111 private:
112 			sem_id				fAlertSem;
113 			int32				fAlertValue;
114 			TAlertView*			fIconView;
115 			BTextView*			fTextView;
116 			BGroupLayout*		fButtonLayout;
117 			std::vector<BButton*> fButtons;
118 			std::vector<char>	fKeys;
119 			uint8				fType;
120 			uint8				fButtonSpacing;
121 			uint8				fButtonWidth;
122 			BInvoker*			fInvoker;
123 			uint32				_reserved[1];
124 };
125 
126 
127 #endif	// _ALERT_H
128