102be5353SAxel Dörfler/*
202be5353SAxel DörflerOpen Tracker License
302be5353SAxel Dörfler
402be5353SAxel DörflerTerms and Conditions
502be5353SAxel Dörfler
602be5353SAxel DörflerCopyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler
802be5353SAxel DörflerPermission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörflerthis software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörflerthe Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfleruse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörflerof the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörflerso, subject to the following conditions:
1402be5353SAxel Dörfler
1502be5353SAxel DörflerThe above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörflerand shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler
1802be5353SAxel DörflerTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1902be5353SAxel DörflerIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2002be5353SAxel DörflerFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2102be5353SAxel DörflerBE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2202be5353SAxel DörflerAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2302be5353SAxel DörflerWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2402be5353SAxel Dörfler
2502be5353SAxel DörflerExcept as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörflerused in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörflerthis Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler
2902be5353SAxel DörflerTracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörflerof Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörflernames are registered trademarks or trademarks of their respective holders.
3202be5353SAxel DörflerAll rights reserved.
3302be5353SAxel Dörfler*/
3402be5353SAxel Dörfler
35b05aa8b5SJohn Scipione
364ed28a57SAlexandre Deckner#include <Catalog.h>
374ed28a57SAlexandre Deckner#include <Locale.h>
3802be5353SAxel Dörfler#include <Menu.h>
3902be5353SAxel Dörfler#include <MenuItem.h>
4002be5353SAxel Dörfler#include <Path.h>
4102be5353SAxel Dörfler#include <PopUpMenu.h>
4202be5353SAxel Dörfler#include <MenuItem.h>
4302be5353SAxel Dörfler#include <Query.h>
4402be5353SAxel Dörfler
4502be5353SAxel Dörfler#include "Attributes.h"
4602be5353SAxel Dörfler#include "Commands.h"
4702be5353SAxel Dörfler#include "QueryContainerWindow.h"
4802be5353SAxel Dörfler#include "QueryPoseView.h"
4902be5353SAxel Dörfler
5002be5353SAxel Dörfler
51388dbb6fSJohn Scipione//	#pragma mark - BQueryContainerWindow
52388dbb6fSJohn Scipione
53388dbb6fSJohn Scipione
54546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
55546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "QueryContainerWindow"
564ed28a57SAlexandre Deckner
57388dbb6fSJohn Scipione
58b05aa8b5SJohn ScipioneBQueryContainerWindow::BQueryContainerWindow(LockingList<BWindow>* windowList,
59e7803cf1SAugustin Cavalier	uint32 containerWindowFlags)
60388dbb6fSJohn Scipione	:
61e7803cf1SAugustin Cavalier	BContainerWindow(windowList, containerWindowFlags)
6202be5353SAxel Dörfler{
6302be5353SAxel Dörfler}
6402be5353SAxel Dörfler
6502be5353SAxel Dörfler
66b05aa8b5SJohn ScipioneBPoseView*
67e7803cf1SAugustin CavalierBQueryContainerWindow::NewPoseView(Model* model, uint32)
6802be5353SAxel Dörfler{
69e7803cf1SAugustin Cavalier	return new BQueryPoseView(model);
7002be5353SAxel Dörfler}
7102be5353SAxel Dörfler
7202be5353SAxel Dörfler
73b05aa8b5SJohn ScipioneBQueryPoseView*
7402be5353SAxel DörflerBQueryContainerWindow::PoseView() const
7502be5353SAxel Dörfler{
76b05aa8b5SJohn Scipione	return static_cast<BQueryPoseView*>(fPoseView);
7702be5353SAxel Dörfler}
7802be5353SAxel Dörfler
7902be5353SAxel Dörfler
8002be5353SAxel Dörflervoid
81b05aa8b5SJohn ScipioneBQueryContainerWindow::CreatePoseView(Model* model)
8202be5353SAxel Dörfler{
83e7803cf1SAugustin Cavalier	fPoseView = NewPoseView(model, kListMode);
8402be5353SAxel Dörfler
85e7803cf1SAugustin Cavalier	fBorderedView->GroupLayout()->AddView(fPoseView);
86e7803cf1SAugustin Cavalier	fBorderedView->EnableBorderHighlight(false);
87e7803cf1SAugustin Cavalier	fBorderedView->GroupLayout()->SetInsets(0, 0, 1, 1);
8802be5353SAxel Dörfler}
8902be5353SAxel Dörfler
9002be5353SAxel Dörfler
9102be5353SAxel Dörflervoid
92b05aa8b5SJohn ScipioneBQueryContainerWindow::AddWindowMenu(BMenu* menu)
9302be5353SAxel Dörfler{
94b05aa8b5SJohn Scipione	BMenuItem* item;
9502be5353SAxel Dörfler
964ed28a57SAlexandre Deckner	item = new BMenuItem(B_TRANSLATE("Resize to fit"),
974ed28a57SAlexandre Deckner		new BMessage(kResizeToFit), 'Y');
9802be5353SAxel Dörfler	item->SetTarget(this);
9902be5353SAxel Dörfler	menu->AddItem(item);
10002be5353SAxel Dörfler
101991dadd6SHumdinger	item = new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
1024ed28a57SAlexandre Deckner		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY);
10302be5353SAxel Dörfler	item->SetTarget(PoseView());
10402be5353SAxel Dörfler	menu->AddItem(item);
10502be5353SAxel Dörfler
106ea001e58SJohn Scipione	item = new BMenuItem(B_TRANSLATE("Select all"),
107ea001e58SJohn Scipione		new BMessage(B_SELECT_ALL), 'A');
10802be5353SAxel Dörfler	item->SetTarget(PoseView());
10902be5353SAxel Dörfler	menu->AddItem(item);
11002be5353SAxel Dörfler
1114ed28a57SAlexandre Deckner	item = new BMenuItem(B_TRANSLATE("Invert selection"),
1124ed28a57SAlexandre Deckner		new BMessage(kInvertSelection), 'S');
11302be5353SAxel Dörfler	item->SetTarget(PoseView());
11402be5353SAxel Dörfler	menu->AddItem(item);
11502be5353SAxel Dörfler
116ea001e58SJohn Scipione	item = new BMenuItem(B_TRANSLATE("Close"),
117ea001e58SJohn Scipione		new BMessage(B_QUIT_REQUESTED), 'W');
11802be5353SAxel Dörfler	item->SetTarget(this);
11902be5353SAxel Dörfler	menu->AddItem(item);
12002be5353SAxel Dörfler}
12102be5353SAxel Dörfler
12202be5353SAxel Dörfler
123b05aa8b5SJohn Scipionevoid
124b05aa8b5SJohn ScipioneBQueryContainerWindow::AddWindowContextMenus(BMenu* menu)
12502be5353SAxel Dörfler{
126394609e3SJoachim Seemer	BMenuItem* resizeItem = new BMenuItem(B_TRANSLATE("Resize to fit"),
12702be5353SAxel Dörfler		new BMessage(kResizeToFit), 'Y');
12802be5353SAxel Dörfler	menu->AddItem(resizeItem);
129991dadd6SHumdinger	menu->AddItem(new BMenuItem(B_TRANSLATE("Select" B_UTF8_ELLIPSIS),
1304ed28a57SAlexandre Deckner		new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
1314ed28a57SAlexandre Deckner	menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
1324ed28a57SAlexandre Deckner		new BMessage(B_SELECT_ALL), 'A'));
1334ed28a57SAlexandre Deckner	BMenuItem* closeItem = new BMenuItem(B_TRANSLATE("Close"),
13402be5353SAxel Dörfler		new BMessage(B_QUIT_REQUESTED), 'W');
13502be5353SAxel Dörfler	menu->AddItem(closeItem);
136388dbb6fSJohn Scipione
13702be5353SAxel Dörfler	// target items as needed
13802be5353SAxel Dörfler	menu->SetTargetForItems(PoseView());
13902be5353SAxel Dörfler	closeItem->SetTarget(this);
14002be5353SAxel Dörfler	resizeItem->SetTarget(this);
14102be5353SAxel Dörfler}
14202be5353SAxel Dörfler
14302be5353SAxel Dörfler
144b05aa8b5SJohn Scipionevoid
14502be5353SAxel DörflerBQueryContainerWindow::SetUpDefaultState()
14602be5353SAxel Dörfler{
14702be5353SAxel Dörfler	BNode defaultingNode;
14802be5353SAxel Dörfler
14902be5353SAxel Dörfler	WindowStateNodeOpener opener(this, true);
15002be5353SAxel Dörfler		// this is our destination node, whatever it is for this window
151388dbb6fSJohn Scipione	if (opener.StreamNode() == NULL)
15202be5353SAxel Dörfler		return;
15302be5353SAxel Dörfler
15402be5353SAxel Dörfler	BString defaultStatePath(kQueryTemplates);
15502be5353SAxel Dörfler	BString sanitizedType(PoseView()->SearchForType());
15602be5353SAxel Dörfler
15702be5353SAxel Dörfler	defaultStatePath += '/';
15802be5353SAxel Dörfler	int32 length = sanitizedType.Length();
159b05aa8b5SJohn Scipione	char* buf = sanitizedType.LockBuffer(length);
16002be5353SAxel Dörfler	for (int32 index = length - 1; index >= 0; index--)
16102be5353SAxel Dörfler		if (buf[index] == '/')
16202be5353SAxel Dörfler			buf[index] = '_';
16302be5353SAxel Dörfler	sanitizedType.UnlockBuffer(length);
16402be5353SAxel Dörfler
16502be5353SAxel Dörfler	defaultStatePath += sanitizedType;
16602be5353SAxel Dörfler
167ea001e58SJohn Scipione	PRINT(("looking for default query state at %s\n",
168ea001e58SJohn Scipione		defaultStatePath.String()));
16902be5353SAxel Dörfler
170ea001e58SJohn Scipione	if (!DefaultStateSourceNode(defaultStatePath.String(), &defaultingNode,
171ea001e58SJohn Scipione			false)) {
17202be5353SAxel Dörfler		TRACE();
17302be5353SAxel Dörfler		return;
17402be5353SAxel Dörfler	}
17502be5353SAxel Dörfler
17602be5353SAxel Dörfler	// copy over the attributes
17702be5353SAxel Dörfler
17802be5353SAxel Dörfler	// set up a filter of the attributes we want copied
179b05aa8b5SJohn Scipione	const char* allowAttrs[] = {
18002be5353SAxel Dörfler		kAttrWindowFrame,
18102be5353SAxel Dörfler		kAttrViewState,
18202be5353SAxel Dörfler		kAttrViewStateForeign,
18302be5353SAxel Dörfler		kAttrColumns,
18402be5353SAxel Dörfler		kAttrColumnsForeign,
18502be5353SAxel Dörfler		0
18602be5353SAxel Dörfler	};
18702be5353SAxel Dörfler
18802be5353SAxel Dörfler	// do it
18902be5353SAxel Dörfler	AttributeStreamMemoryNode memoryNode;
19002be5353SAxel Dörfler	NamesToAcceptAttrFilter filter(allowAttrs);
19102be5353SAxel Dörfler	AttributeStreamFileNode fileNode(&defaultingNode);
19202be5353SAxel Dörfler	*opener.StreamNode() << memoryNode << filter << fileNode;
19302be5353SAxel Dörfler}
19402be5353SAxel Dörfler
19502be5353SAxel Dörfler
196b05aa8b5SJohn Scipionebool
19702be5353SAxel DörflerBQueryContainerWindow::ActiveOnDevice(dev_t device) const
19802be5353SAxel Dörfler{
19902be5353SAxel Dörfler	return PoseView()->ActiveOnDevice(device);
20002be5353SAxel Dörfler}
201