xref: /haiku/src/apps/diskusage/PieView.h (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3  * Distributed under the terms of the MIT/X11 license.
4  *
5  * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software
6  * as long as it is accompanied by it's documentation and this copyright notice.
7  * The software comes with no warranty, etc.
8  */
9 #ifndef PIE_VIEW_H
10 #define PIE_VIEW_H
11 
12 #include <View.h>
13 
14 #include <map>
15 #include <vector>
16 
17 
18 class AppMenuItem;
19 class BEntry;
20 class BMenu;
21 class BPopUpMenu;
22 class BVolume;
23 struct entry_ref;
24 struct FileInfo;
25 class Scanner;
26 class MainWindow;
27 
28 using std::map;
29 using std::vector;
30 
31 class PieView: public BView {
32 public:
33 								PieView(BRect frame, MainWindow* window);
34 	virtual						~PieView();
35 
36 	virtual	void				MessageReceived(BMessage* message);
37 	virtual	void				MouseDown(BPoint where);
38 	virtual	void				MouseUp(BPoint where);
39 	virtual	void				MouseMoved(BPoint where, uint32 transit,
40 									const BMessage* dragMessage);
41 	virtual	void				Draw(BRect updateRect);
42 
43 private:
44 			void				_HandleArg(const BEntry* entry);
45 			void				_ShowVolume(BVolume* volume);
46 			void				_DrawProgressBar(BRect updateRect);
47 			void				_DrawPieChart(BRect updateRect);
48 			float				_DrawDirectory(FileInfo* info,
49 									float parentSpan, float beginAngle,
50 									int colorIdx, int level);
51 			FileInfo*			_FileAt(const BPoint& where);
52 			void				_AddAppToList(vector<AppMenuItem*>& list,
53 									const char* appSignature, int category);
54 			BMenu*				_BuildOpenWithMenu(FileInfo* info);
55 			void				_ShowContextMenu(FileInfo* info, BPoint where);
56 			void				_Launch(FileInfo* info,
57 									const entry_ref* ref = NULL);
58 
59 private:
60 		struct Segment {
61 			Segment()
62 				: begin(0.0), end(0.0), info(NULL) { }
63 			Segment(float b, float e, FileInfo* i)
64 				: begin(b), end(e), info(i) { }
65 			Segment(const Segment &s)
66 				: begin(s.begin), end(s.end), info(s.info) { }
67 			~Segment() { }
68 
69 			float				begin;
70 			float				end;
71 			FileInfo*			info;
72 		};
73 		typedef vector<Segment> SegmentList;
74 		typedef map<int, SegmentList> MouseOverInfo;
75 
76 		typedef map<BVolume*, Scanner*> ScannerMap;
77 
78 private:
79 			MainWindow*			fWindow;
80 			ScannerMap			fScanners;
81 			BVolume*			fCurrentVolume;
82 			FileInfo*			fCurrentDir;
83 			MouseOverInfo		fMouseOverInfo;
84 			BPopUpMenu*			fMouseOverMenu;
85 			BPopUpMenu*			fFileUnavailableMenu;
86 			float				fFontHeight;
87 			bool				fClicked;
88 			bool				fDragging;
89 			BPoint				fDragStart;
90 			FileInfo*			fClickedFile;
91 };
92 
93 #endif // PIE_VIEW_H
94 
95