xref: /haiku/src/apps/powerstatus/ExtendedInfoWindow.h (revision 03187b607b2b5eec7ee059f1ead09bdba14991fb)
1 /*
2  * Copyright 2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Clemens Zeidler, haiku@Clemens-Zeidler.de
7  */
8 
9 #ifndef EXTENDED_INFO_WINDOW_H
10 #define EXTENDED_INFO_WINDOW_H
11 
12 
13 #include <ObjectList.h>
14 #include <String.h>
15 #include <View.h>
16 #include <Window.h>
17 
18 #include "DriverInterface.h"
19 #include "PowerStatusView.h"
20 
21 
22 class FontString {
23 public:
24 					FontString();
25 
26 	const BFont*	font;
27 	BString			string;
28 };
29 
30 
31 class BatteryInfoView : public BView {
32 public:
33 							BatteryInfoView();
34 							~BatteryInfoView();
35 
36 	virtual void			Update(battery_info& info,
37 								acpi_extended_battery_info& extInfo);
38 	virtual	void			Draw(BRect updateRect);
39 	virtual void			GetPreferredSize(float* width, float* height);
40 	virtual void			AttachedToWindow();
41 
42 private:
43 			BSize			_MeasureString(const BString& string);
44 			void			_FillStringList();
45 			void			_AddToStringList(FontString* fontString);
46 			void			_ClearStringList();
47 
48 			battery_info				fBatteryInfo;
49 			acpi_extended_battery_info	fBatteryExtendedInfo;
50 
51 			BSize						fPreferredSize;
52 
53 			BObjectList<FontString>		fStringList;
54 			BSize						fMaxStringSize;
55 };
56 
57 
58 class ExtendedInfoWindow;
59 
60 class ExtPowerStatusView : public PowerStatusView {
61 public:
62 								ExtPowerStatusView(
63 									PowerStatusDriverInterface* interface,
64 									BRect frame, int32 resizingMode,
65 									int batteryID, ExtendedInfoWindow* window);
66 
67 	virtual	void				Draw(BRect updateRect);
68 	virtual	void				MouseDown(BPoint where);
69 
70 	virtual void				Select(bool select = true);
71 
72 	// return true if it battery is in a critical state
73 	virtual	bool				IsCritical();
74 
75 protected:
76 	virtual void				Update(bool force = false);
77 
78 private:
79 			ExtendedInfoWindow*	fExtendedInfoWindow;
80 			BatteryInfoView*	fBatteryInfoView;
81 
82 			bool				fSelected;
83 };
84 
85 
86 class ExtendedInfoWindow : public BWindow
87 {
88 public:
89 		ExtendedInfoWindow(PowerStatusDriverInterface* interface);
90 		~ExtendedInfoWindow();
91 
92 	BatteryInfoView*			GetExtendedBatteryInfoView();
93 
94 	void						BatterySelected(ExtPowerStatusView* view);
95 
96 private:
97 	PowerStatusDriverInterface* 		fDriverInterface;
98 	BObjectList<ExtPowerStatusView>		fBatteryViewList;
99 
100 	BatteryInfoView*					fBatteryInfoView;
101 
102 	ExtPowerStatusView*					fSelectedView;
103 };
104 
105 
106 #endif
107