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