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