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
15enum 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
23enum button_spacing {
24	B_EVEN_SPACING = 0,
25	B_OFFSET_SPACING
26};
27
28
29class BBitmap;
30class BButton;
31class BGroupLayout;
32class BInvoker;
33class BTextView;
34class TAlertView;
35
36
37class BAlert : public BWindow {
38public:
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
95private:
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
111private:
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