xref: /haiku/src/kits/tracker/QueryContainerWindow.cpp (revision a629567a9001547736cfe892cdf992be16868fed)
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 
36 #include <Catalog.h>
37 #include <Locale.h>
38 #include <Menu.h>
39 #include <MenuItem.h>
40 #include <Path.h>
41 #include <PopUpMenu.h>
42 #include <MenuItem.h>
43 #include <Query.h>
44 
45 #include "Attributes.h"
46 #include "Commands.h"
47 #include "QueryContainerWindow.h"
48 #include "QueryPoseView.h"
49 
50 
51 //	#pragma mark - BQueryContainerWindow
52 
53 
54 #undef B_TRANSLATION_CONTEXT
55 #define B_TRANSLATION_CONTEXT "QueryContainerWindow"
56 
57 
58 BQueryContainerWindow::BQueryContainerWindow(LockingList<BWindow>* windowList,
59 	uint32 containerWindowFlags, window_look look, window_feel feel,
60 	uint32 flags, uint32 workspace)
61 	:
62 	BContainerWindow(windowList, containerWindowFlags, look, feel,
63 		flags, workspace)
64 {
65 }
66 
67 
68 BPoseView*
69 BQueryContainerWindow::NewPoseView(Model* model, BRect rect, uint32)
70 {
71 	return new BQueryPoseView(model, rect);
72 }
73 
74 
75 BQueryPoseView*
76 BQueryContainerWindow::PoseView() const
77 {
78 	return static_cast<BQueryPoseView*>(fPoseView);
79 }
80 
81 
82 void
83 BQueryContainerWindow::CreatePoseView(Model* model)
84 {
85 	BRect rect(Bounds());
86 	rect.right -= B_V_SCROLL_BAR_WIDTH;
87 	rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
88 	fPoseView = NewPoseView(model, rect, kListMode);
89 
90 	AddChild(fPoseView);
91 }
92 
93 
94 void
95 BQueryContainerWindow::AddWindowMenu(BMenu* menu)
96 {
97 	BMenuItem* item;
98 
99 	item = new BMenuItem(B_TRANSLATE("Resize to fit"),
100 		new BMessage(kResizeToFit), 'Y');
101 	item->SetTarget(this);
102 	menu->AddItem(item);
103 
104 	item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
105 		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY);
106 	item->SetTarget(PoseView());
107 	menu->AddItem(item);
108 
109 	item = new BMenuItem(B_TRANSLATE("Select all"),
110 		new BMessage(B_SELECT_ALL), 'A');
111 	item->SetTarget(PoseView());
112 	menu->AddItem(item);
113 
114 	item = new BMenuItem(B_TRANSLATE("Invert selection"),
115 		new BMessage(kInvertSelection), 'S');
116 	item->SetTarget(PoseView());
117 	menu->AddItem(item);
118 
119 	item = new BMenuItem(B_TRANSLATE("Close"),
120 		new BMessage(B_QUIT_REQUESTED), 'W');
121 	item->SetTarget(this);
122 	menu->AddItem(item);
123 }
124 
125 
126 void
127 BQueryContainerWindow::AddWindowContextMenus(BMenu* menu)
128 {
129 	BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"),
130 		new BMessage(kResizeToFit), 'Y');
131 	menu->AddItem(resizeItem);
132 	menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
133 		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
134 	menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
135 		new BMessage(B_SELECT_ALL), 'A'));
136 	BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"),
137 		new BMessage(B_QUIT_REQUESTED), 'W');
138 	menu->AddItem(closeItem);
139 
140 	// target items as needed
141 	menu->SetTargetForItems(PoseView());
142 	closeItem->SetTarget(this);
143 	resizeItem->SetTarget(this);
144 }
145 
146 
147 void
148 BQueryContainerWindow::SetUpDefaultState()
149 {
150 	BNode defaultingNode;
151 
152 	WindowStateNodeOpener opener(this, true);
153 		// this is our destination node, whatever it is for this window
154 	if (opener.StreamNode() == NULL)
155 		return;
156 
157 	BString defaultStatePath(kQueryTemplates);
158 	BString sanitizedType(PoseView()->SearchForType());
159 
160 	defaultStatePath += '/';
161 	int32 length = sanitizedType.Length();
162 	char* buf = sanitizedType.LockBuffer(length);
163 	for (int32 index = length - 1; index >= 0; index--)
164 		if (buf[index] == '/')
165 			buf[index] = '_';
166 	sanitizedType.UnlockBuffer(length);
167 
168 	defaultStatePath += sanitizedType;
169 
170 	PRINT(("looking for default query state at %s\n",
171 		defaultStatePath.String()));
172 
173 	if (!DefaultStateSourceNode(defaultStatePath.String(), &defaultingNode,
174 			false)) {
175 		TRACE();
176 		return;
177 	}
178 
179 	// copy over the attributes
180 
181 	// set up a filter of the attributes we want copied
182 	const char* allowAttrs[] = {
183 		kAttrWindowFrame,
184 		kAttrViewState,
185 		kAttrViewStateForeign,
186 		kAttrColumns,
187 		kAttrColumnsForeign,
188 		0
189 	};
190 
191 	// do it
192 	AttributeStreamMemoryNode memoryNode;
193 	NamesToAcceptAttrFilter filter(allowAttrs);
194 	AttributeStreamFileNode fileNode(&defaultingNode);
195 	*opener.StreamNode() << memoryNode << filter << fileNode;
196 }
197 
198 
199 bool
200 BQueryContainerWindow::ActiveOnDevice(dev_t device) const
201 {
202 	return PoseView()->ActiveOnDevice(device);
203 }
204