xref: /haiku/headers/os/interface/Alert.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Erik Jaesler (erik@cgsoftware.com)
7  */
8 #ifndef	_ALERT_H
9 #define	_ALERT_H
10 
11 
12 #include <BeBuild.h>
13 #include <Window.h>
14 
15 
16 class BBitmap;
17 class BButton;
18 class BInvoker;
19 class BTextView;
20 
21 // enum for flavors of alert
22 enum alert_type {
23 	B_EMPTY_ALERT = 0,
24 	B_INFO_ALERT,
25 	B_IDEA_ALERT,
26 	B_WARNING_ALERT,
27 	B_STOP_ALERT
28 };
29 
30 enum button_spacing {
31 	B_EVEN_SPACING = 0,
32 	B_OFFSET_SPACING
33 };
34 
35 
36 class BAlert : public BWindow {
37 	public:
38 							BAlert(const char* title, const char* text,
39 								const char* button1, const char* button2 = NULL,
40 								const char* button3 = NULL,
41 								button_width width = B_WIDTH_AS_USUAL,
42 								alert_type type = B_INFO_ALERT);
43 							BAlert(const char *title, const char *text,
44 								const char *button1, const char *button2,
45 								const char *button3, button_width width,
46 								button_spacing spacing,
47 								alert_type type = B_INFO_ALERT);
48 		virtual				~BAlert();
49 
50 		// Archiving
51 							BAlert(BMessage *data);
52 		static	BArchivable	*Instantiate(BMessage *data);
53 		virtual	status_t	Archive(BMessage *data, bool deep = true) const;
54 
55 		// BAlert guts
56 				void		SetShortcut(int32 button_index, char key);
57 				char		Shortcut(int32 button_index) const;
58 
59 				int32		Go();
60 				status_t	Go(BInvoker *invoker);
61 
62 		virtual	void		MessageReceived(BMessage *an_event);
63 		virtual	void		FrameResized(float new_width, float new_height);
64 				BButton*	ButtonAt(int32 index) const;
65 				BTextView*	TextView() const;
66 
67 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
68 								BMessage* specifier, int32 form,
69 								const char* property);
70 		virtual	status_t	GetSupportedSuites(BMessage *data);
71 
72 		virtual void		DispatchMessage(BMessage* message, BHandler* handler);
73 		virtual	void		Quit();
74 		virtual	bool		QuitRequested();
75 
76 		static	BPoint		AlertPosition(float width, float height);
77 
78 		virtual status_t	Perform(perform_code d, void *arg);
79 
80 	private:
81 		friend class _BAlertFilter_;
82 
83 		virtual	void		_ReservedAlert1();
84 		virtual	void		_ReservedAlert2();
85 		virtual	void		_ReservedAlert3();
86 
87 				void		_InitObject(const char* text, const char* button1,
88 								const char* button2 = NULL,
89 								const char* button3 = NULL,
90 								button_width width = B_WIDTH_AS_USUAL,
91 								button_spacing spacing = B_EVEN_SPACING,
92 								alert_type type = B_INFO_ALERT);
93 				BBitmap*	_InitIcon();
94 				BButton*	_CreateButton(int32 which, const char* label);
95 
96 		sem_id				fAlertSem;
97 		int32				fAlertValue;
98 		BButton*			fButtons[3];
99 		BTextView*			fTextView;
100 		char				fKeys[3];
101 		alert_type			fMsgType;
102 		button_width		fButtonWidth;
103 		BInvoker*			fInvoker;
104 		uint32				_reserved[4];
105 };
106 
107 #endif	// _ALERT_H
108