xref: /haiku/src/kits/tracker/QueryContainerWindow.cpp (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #include <Menu.h>
36 #include <MenuItem.h>
37 #include <Path.h>
38 #include <PopUpMenu.h>
39 #include <MenuItem.h>
40 #include <Query.h>
41 
42 #include "Attributes.h"
43 #include "Commands.h"
44 #include "QueryContainerWindow.h"
45 #include "QueryPoseView.h"
46 
47 
48 BQueryContainerWindow::BQueryContainerWindow(LockingList<BWindow> *windowList,
49 	uint32 containerWindowFlags, window_look look,
50 	window_feel feel, uint32 flags, uint32 workspace)
51 	:	BContainerWindow(windowList, containerWindowFlags, look, feel,
52 			flags, workspace)
53 {
54 }
55 
56 
57 BPoseView *
58 BQueryContainerWindow::NewPoseView(Model *model, BRect rect, uint32)
59 {
60 	return new BQueryPoseView(model, rect);
61 }
62 
63 
64 BQueryPoseView *
65 BQueryContainerWindow::PoseView() const
66 {
67 	return static_cast<BQueryPoseView *>(fPoseView);
68 }
69 
70 
71 void
72 BQueryContainerWindow::CreatePoseView(Model *model)
73 {
74 	BRect rect(Bounds());
75 	rect.right -= B_V_SCROLL_BAR_WIDTH;
76 	rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
77 	fPoseView = NewPoseView(model, rect, kListMode);
78 
79 	AddChild(fPoseView);
80 }
81 
82 
83 void
84 BQueryContainerWindow::AddWindowMenu(BMenu *menu)
85 {
86 	BMenuItem *item;
87 
88 	item = new BMenuItem("Resize to Fit", new BMessage(kResizeToFit), 'Y');
89 	item->SetTarget(this);
90 	menu->AddItem(item);
91 
92 	item = new BMenuItem("Select"B_UTF8_ELLIPSIS, new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY);
93 	item->SetTarget(PoseView());
94 	menu->AddItem(item);
95 
96 	item = new BMenuItem("Select All", new BMessage(B_SELECT_ALL), 'A');
97 	item->SetTarget(PoseView());
98 	menu->AddItem(item);
99 
100 	item = new BMenuItem("Invert Selection", new BMessage(kInvertSelection), 'S');
101 	item->SetTarget(PoseView());
102 	menu->AddItem(item);
103 
104 	item = new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W');
105 	item->SetTarget(this);
106 	menu->AddItem(item);
107 }
108 
109 
110 void
111 BQueryContainerWindow::AddWindowContextMenus(BMenu *menu)
112 {
113 	BMenuItem *resizeItem = new BMenuItem("Resize to Fit",
114 		new BMessage(kResizeToFit), 'Y');
115 	menu->AddItem(resizeItem);
116 	menu->AddItem(new BMenuItem("Select"B_UTF8_ELLIPSIS, new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
117 	menu->AddItem(new BMenuItem("Select All", new BMessage(B_SELECT_ALL), 'A'));
118 	BMenuItem *closeItem = new BMenuItem("Close",
119 		new BMessage(B_QUIT_REQUESTED), 'W');
120 	menu->AddItem(closeItem);
121 	// target items as needed
122 	menu->SetTargetForItems(PoseView());
123 	closeItem->SetTarget(this);
124 	resizeItem->SetTarget(this);
125 }
126 
127 
128 void
129 BQueryContainerWindow::SetUpDefaultState()
130 {
131 	BNode defaultingNode;
132 
133 	WindowStateNodeOpener opener(this, true);
134 		// this is our destination node, whatever it is for this window
135 	if (!opener.StreamNode())
136 		return;
137 
138 	BString defaultStatePath(kQueryTemplates);
139 	BString sanitizedType(PoseView()->SearchForType());
140 
141 	defaultStatePath += '/';
142 	int32 length = sanitizedType.Length();
143 	char *buf = sanitizedType.LockBuffer(length);
144 	for (int32 index = length - 1; index >= 0; index--)
145 		if (buf[index] == '/')
146 			buf[index] = '_';
147 	sanitizedType.UnlockBuffer(length);
148 
149 	defaultStatePath += sanitizedType;
150 
151 	PRINT(("looking for default query state at %s\n", defaultStatePath.String()));
152 
153 	if (!DefaultStateSourceNode(defaultStatePath.String(), &defaultingNode, false)) {
154 		TRACE();
155 		return;
156 	}
157 
158 	// copy over the attributes
159 
160 	// set up a filter of the attributes we want copied
161 	const char *allowAttrs[] = {
162 		kAttrWindowFrame,
163 		kAttrViewState,
164 		kAttrViewStateForeign,
165 		kAttrColumns,
166 		kAttrColumnsForeign,
167 		0
168 	};
169 
170 	// do it
171 	AttributeStreamMemoryNode memoryNode;
172 	NamesToAcceptAttrFilter filter(allowAttrs);
173 	AttributeStreamFileNode fileNode(&defaultingNode);
174 	*opener.StreamNode() << memoryNode << filter << fileNode;
175 }
176 
177 
178 bool
179 BQueryContainerWindow::ActiveOnDevice(dev_t device) const
180 {
181 	return PoseView()->ActiveOnDevice(device);
182 }
183 
184