MainWin.cpp revision bae0154c
104a91b97SMarcus Overhagen/*
204a91b97SMarcus Overhagen * MainWin.cpp - Media Player for the Haiku Operating System
304a91b97SMarcus Overhagen *
404a91b97SMarcus Overhagen * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
51b7f76bcSStephan Aßmus * Copyright (C) 2007-2008 Stephan A��mus <superstippi@gmx.de> (GPL->MIT ok)
69327db63SFredrik Modeen * Copyright (C) 2007-2009 Fredrik Mod��en <[FirstName]@[LastName].se> (MIT ok)
704a91b97SMarcus Overhagen *
804a91b97SMarcus Overhagen * This program is free software; you can redistribute it and/or
904a91b97SMarcus Overhagen * modify it under the terms of the GNU General Public License
1004a91b97SMarcus Overhagen * version 2 as published by the Free Software Foundation.
1104a91b97SMarcus Overhagen *
1204a91b97SMarcus Overhagen * This program is distributed in the hope that it will be useful,
1304a91b97SMarcus Overhagen * but WITHOUT ANY WARRANTY; without even the implied warranty of
1404a91b97SMarcus Overhagen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1504a91b97SMarcus Overhagen * GNU General Public License for more details.
1604a91b97SMarcus Overhagen *
1704a91b97SMarcus Overhagen * You should have received a copy of the GNU General Public License
1804a91b97SMarcus Overhagen * along with this program; if not, write to the Free Software
191b7f76bcSStephan Aßmus * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
201b7f76bcSStephan Aßmus * USA.
2104a91b97SMarcus Overhagen *
2204a91b97SMarcus Overhagen */
2304a91b97SMarcus Overhagen#include "MainWin.h"
2404a91b97SMarcus Overhagen
2509464bc9SStephan Aßmus#include <math.h>
2609464bc9SStephan Aßmus#include <stdio.h>
2709464bc9SStephan Aßmus#include <string.h>
2809464bc9SStephan Aßmus
2909464bc9SStephan Aßmus#include <Alert.h>
3009464bc9SStephan Aßmus#include <Application.h>
3109464bc9SStephan Aßmus#include <Autolock.h>
3209464bc9SStephan Aßmus#include <Debug.h>
3304a91b97SMarcus Overhagen#include <Menu.h>
3404a91b97SMarcus Overhagen#include <MenuBar.h>
3504a91b97SMarcus Overhagen#include <MenuItem.h>
3604a91b97SMarcus Overhagen#include <Messenger.h>
3704a91b97SMarcus Overhagen#include <PopUpMenu.h>
38658aafcbSFrançois Revol#include <RecentItems.h>
39658aafcbSFrançois Revol#include <Roster.h>
4009464bc9SStephan Aßmus#include <Screen.h>
4104a91b97SMarcus Overhagen#include <String.h>
4209464bc9SStephan Aßmus#include <View.h>
4304a91b97SMarcus Overhagen
449282400fSStephan Aßmus#include "AudioProducer.h"
455fa5e5feSStephan Aßmus#include "ControllerObserver.h"
4609464bc9SStephan Aßmus#include "MainApp.h"
479282400fSStephan Aßmus#include "PeakView.h"
485fa5e5feSStephan Aßmus#include "PlaylistObserver.h"
495fa5e5feSStephan Aßmus#include "PlaylistWindow.h"
509a5f768bSStephan Aßmus#include "Settings.h"
515fa5e5feSStephan Aßmus
52e1d8d7d6SMarcus Overhagen#define NAME "MediaPlayer"
5399cd5eebSMarcus Overhagen#define MIN_WIDTH 250
54e1d8d7d6SMarcus Overhagen
55399b0e8aSMarcus Overhagen
56399b0e8aSMarcus Overhagen// XXX TODO: why is lround not defined?
57399b0e8aSMarcus Overhagen#define lround(a) ((int)(0.99999 + (a)))
58399b0e8aSMarcus Overhagen
59d329f1d6SStephan Aßmusenum {
6004a91b97SMarcus Overhagen	M_DUMMY = 0x100,
61e1d8d7d6SMarcus Overhagen	M_FILE_OPEN = 0x1000,
62e1d8d7d6SMarcus Overhagen	M_FILE_NEWPLAYER,
63e1d8d7d6SMarcus Overhagen	M_FILE_INFO,
645fa5e5feSStephan Aßmus	M_FILE_PLAYLIST,
65e1d8d7d6SMarcus Overhagen	M_FILE_CLOSE,
66bae0154cSStephan Aßmus	M_FILE_QUIT,
67e1d8d7d6SMarcus Overhagen	M_VIEW_50,
68e1d8d7d6SMarcus Overhagen	M_VIEW_100,
69e1d8d7d6SMarcus Overhagen	M_VIEW_200,
70e1d8d7d6SMarcus Overhagen	M_VIEW_300,
71e1d8d7d6SMarcus Overhagen	M_VIEW_400,
7204a91b97SMarcus Overhagen	M_TOGGLE_FULLSCREEN,
7304a91b97SMarcus Overhagen	M_TOGGLE_NO_BORDER,
7404a91b97SMarcus Overhagen	M_TOGGLE_NO_MENU,
7599cd5eebSMarcus Overhagen	M_TOGGLE_NO_CONTROLS,
7699cd5eebSMarcus Overhagen	M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS,
7704a91b97SMarcus Overhagen	M_TOGGLE_ALWAYS_ON_TOP,
7804a91b97SMarcus Overhagen	M_TOGGLE_KEEP_ASPECT_RATIO,
7904a91b97SMarcus Overhagen	M_VOLUME_UP,
8004a91b97SMarcus Overhagen	M_VOLUME_DOWN,
81540fe7aeSStephan Aßmus	M_SKIP_NEXT,
82540fe7aeSStephan Aßmus	M_SKIP_PREV,
8304a91b97SMarcus Overhagen	M_ASPECT_100000_1,
8404a91b97SMarcus Overhagen	M_ASPECT_106666_1,
8504a91b97SMarcus Overhagen	M_ASPECT_109091_1,
8604a91b97SMarcus Overhagen	M_ASPECT_141176_1,
8704a91b97SMarcus Overhagen	M_ASPECT_720_576,
8804a91b97SMarcus Overhagen	M_ASPECT_704_576,
8904a91b97SMarcus Overhagen	M_ASPECT_544_576,
90e1d8d7d6SMarcus Overhagen	M_SELECT_AUDIO_TRACK		= 0x00000800,
91e1d8d7d6SMarcus Overhagen	M_SELECT_AUDIO_TRACK_END	= 0x00000fff,
92e1d8d7d6SMarcus Overhagen	M_SELECT_VIDEO_TRACK		= 0x00010000,
93e1d8d7d6SMarcus Overhagen	M_SELECT_VIDEO_TRACK_END	= 0x000fffff,
945fa5e5feSStephan Aßmus
959327db63SFredrik Modeen	M_SET_PLAYLIST_POSITION,
96bae0154cSStephan Aßmus
979327db63SFredrik Modeen	M_FILE_DELETE
9804a91b97SMarcus Overhagen};
9904a91b97SMarcus Overhagen
10004a91b97SMarcus Overhagen//#define printf(a...)
10104a91b97SMarcus Overhagen
10204a91b97SMarcus Overhagen
103e1d8d7d6SMarcus OverhagenMainWin::MainWin()
1049a5f768bSStephan Aßmus	: BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW,
1059a5f768bSStephan Aßmus 		B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
1069a5f768bSStephan Aßmus	  fInfoWin(NULL),
1079a5f768bSStephan Aßmus	  fPlaylistWindow(NULL),
1089a5f768bSStephan Aßmus	  fHasFile(false),
1099a5f768bSStephan Aßmus	  fHasVideo(false),
1109a5f768bSStephan Aßmus	  fHasAudio(false),
1119a5f768bSStephan Aßmus	  fPlaylist(new Playlist),
1129a5f768bSStephan Aßmus	  fPlaylistObserver(new PlaylistObserver(this)),
1139a5f768bSStephan Aßmus	  fController(new Controller),
1149a5f768bSStephan Aßmus	  fControllerObserver(new ControllerObserver(this,
1159a5f768bSStephan Aßmus		OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES
1169a5f768bSStephan Aßmus			| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES
1179a5f768bSStephan Aßmus			| OBSERVE_VOLUME_CHANGES)),
1189a5f768bSStephan Aßmus	  fIsFullscreen(false),
1199a5f768bSStephan Aßmus	  fKeepAspectRatio(true),
1209a5f768bSStephan Aßmus	  fAlwaysOnTop(false),
1219a5f768bSStephan Aßmus	  fNoMenu(false),
1229a5f768bSStephan Aßmus	  fNoBorder(false),
1239a5f768bSStephan Aßmus	  fNoControls(false),
1249a5f768bSStephan Aßmus	  fSourceWidth(-1),
1259a5f768bSStephan Aßmus	  fSourceHeight(-1),
1269a5f768bSStephan Aßmus	  fWidthScale(1.0),
1279a5f768bSStephan Aßmus	  fHeightScale(1.0),
1289a5f768bSStephan Aßmus	  fMouseDownTracking(false),
1299a5f768bSStephan Aßmus	  fGlobalSettingsListener(this)
13004a91b97SMarcus Overhagen{
131399b0e8aSMarcus Overhagen	static int pos = 0;
132399b0e8aSMarcus Overhagen	MoveBy(pos * 25, pos * 25);
133399b0e8aSMarcus Overhagen	pos = (pos + 1) % 15;
134bae0154cSStephan Aßmus
13504a91b97SMarcus Overhagen	BRect rect = Bounds();
13604a91b97SMarcus Overhagen
13704a91b97SMarcus Overhagen	// background
1381b7f76bcSStephan Aßmus	fBackground = new BView(rect, "background", B_FOLLOW_ALL,
1391b7f76bcSStephan Aßmus		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
14004a91b97SMarcus Overhagen	fBackground->SetViewColor(0,0,0);
14104a91b97SMarcus Overhagen	AddChild(fBackground);
14204a91b97SMarcus Overhagen
14399cd5eebSMarcus Overhagen	// menu
14404a91b97SMarcus Overhagen	fMenuBar = new BMenuBar(fBackground->Bounds(), "menu");
145d329f1d6SStephan Aßmus	_CreateMenu();
14604a91b97SMarcus Overhagen	fBackground->AddChild(fMenuBar);
147cf4ef413SStephan Aßmus	fMenuBar->SetResizingMode(B_FOLLOW_NONE);
14804a91b97SMarcus Overhagen	fMenuBar->ResizeToPreferred();
1495fa5e5feSStephan Aßmus	fMenuBarWidth = (int)fMenuBar->Frame().Width() + 1;
15004a91b97SMarcus Overhagen	fMenuBarHeight = (int)fMenuBar->Frame().Height() + 1;
15104a91b97SMarcus Overhagen
15204a91b97SMarcus Overhagen	// video view
1531b7f76bcSStephan Aßmus	rect = BRect(0, fMenuBarHeight, fBackground->Bounds().right,
1541b7f76bcSStephan Aßmus		fMenuBarHeight + 10);
1550fc56ed5SStephan Aßmus	fVideoView = new VideoView(rect, "video display", B_FOLLOW_NONE);
15604a91b97SMarcus Overhagen	fBackground->AddChild(fVideoView);
157bae0154cSStephan Aßmus
15899cd5eebSMarcus Overhagen	// controls
1591b7f76bcSStephan Aßmus	rect = BRect(0, fMenuBarHeight + 11, fBackground->Bounds().right,
1601b7f76bcSStephan Aßmus		fBackground->Bounds().bottom);
1615fa5e5feSStephan Aßmus	fControls = new ControllerView(rect, fController, fPlaylist);
16299cd5eebSMarcus Overhagen	fBackground->AddChild(fControls);
16399cd5eebSMarcus Overhagen	fControls->ResizeToPreferred();
16499cd5eebSMarcus Overhagen	fControlsHeight = (int)fControls->Frame().Height() + 1;
16599cd5eebSMarcus Overhagen	fControlsWidth = (int)fControls->Frame().Width() + 1;
166aadc5f57SMarcus Overhagen	fControls->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
167399b0e8aSMarcus Overhagen//	fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1);
168bae0154cSStephan Aßmus
1691b7f76bcSStephan Aßmus//	fVideoView->ResizeTo(fBackground->Bounds().Width(),
1701b7f76bcSStephan Aßmus//		fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
1715fa5e5feSStephan Aßmus
1725fa5e5feSStephan Aßmus	fPlaylist->AddListener(fPlaylistObserver);
17399cd5eebSMarcus Overhagen	fController->SetVideoView(fVideoView);
1745fa5e5feSStephan Aßmus	fController->AddListener(fControllerObserver);
1759282400fSStephan Aßmus	PeakView* peakView = fControls->GetPeakView();
1769282400fSStephan Aßmus	peakView->SetPeakNotificationWhat(MSG_PEAK_NOTIFICATION);
1779282400fSStephan Aßmus	fController->SetPeakListener(peakView);
178bae0154cSStephan Aßmus
1795fa5e5feSStephan Aßmus//	printf("fMenuBarHeight %d\n", fMenuBarHeight);
1805fa5e5feSStephan Aßmus//	printf("fControlsHeight %d\n", fControlsHeight);
1815fa5e5feSStephan Aßmus//	printf("fControlsWidth %d\n", fControlsWidth);
18204a91b97SMarcus Overhagen
183d329f1d6SStephan Aßmus	_SetupWindow();
1845fa5e5feSStephan Aßmus
185bae0154cSStephan Aßmus	// setup the playlist window now, we need to have it
186cc2fbed2SStephan Aßmus	// running for the undo/redo playlist editing
1871b7f76bcSStephan Aßmus	fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 500, 600), fPlaylist,
1881b7f76bcSStephan Aßmus		fController);
189cc2fbed2SStephan Aßmus	fPlaylistWindow->Hide();
190cc2fbed2SStephan Aßmus	fPlaylistWindow->Show();
191cc2fbed2SStephan Aßmus		// this makes sure the window thread is running without
192cc2fbed2SStephan Aßmus		// showing the window just yet
193cc2fbed2SStephan Aßmus
1949a5f768bSStephan Aßmus	Settings::Default()->AddListener(&fGlobalSettingsListener);
1959a5f768bSStephan Aßmus	_AdoptGlobalSettings();
1969a5f768bSStephan Aßmus
197e1d8d7d6SMarcus Overhagen	Show();
19804a91b97SMarcus Overhagen}
19904a91b97SMarcus Overhagen
20004a91b97SMarcus Overhagen
20104a91b97SMarcus OverhagenMainWin::~MainWin()
20204a91b97SMarcus Overhagen{
2039327db63SFredrik Modeen//	printf("MainWin::~MainWin\n");
2045fa5e5feSStephan Aßmus
2054ddc254cSStephan Aßmus	Settings::Default()->RemoveListener(&fGlobalSettingsListener);
2065fa5e5feSStephan Aßmus	fPlaylist->RemoveListener(fPlaylistObserver);
2075fa5e5feSStephan Aßmus	fController->RemoveListener(fControllerObserver);
2089282400fSStephan Aßmus	fController->SetPeakListener(NULL);
2095fa5e5feSStephan Aßmus
2105fa5e5feSStephan Aßmus	// give the views a chance to detach from any notifiers
2115fa5e5feSStephan Aßmus	// before we delete them
2125fa5e5feSStephan Aßmus	fBackground->RemoveSelf();
2135fa5e5feSStephan Aßmus	delete fBackground;
2145fa5e5feSStephan Aßmus
2154ddc254cSStephan Aßmus	if (fInfoWin && fInfoWin->Lock())
216c91fb637SFrançois Revol		fInfoWin->Quit();
2174ddc254cSStephan Aßmus
2184ddc254cSStephan Aßmus	if (fPlaylistWindow && fPlaylistWindow->Lock())
2195fa5e5feSStephan Aßmus		fPlaylistWindow->Quit();
220bae0154cSStephan Aßmus
2215fa5e5feSStephan Aßmus	delete fPlaylist;
2220fc56ed5SStephan Aßmus
2230fc56ed5SStephan Aßmus	// quit the Controller looper thread
2240fc56ed5SStephan Aßmus	thread_id controllerThread = fController->Thread();
2250fc56ed5SStephan Aßmus	fController->PostMessage(B_QUIT_REQUESTED);
2260fc56ed5SStephan Aßmus	status_t exitValue;
2270fc56ed5SStephan Aßmus	wait_for_thread(controllerThread, &exitValue);
228e1d8d7d6SMarcus Overhagen}
229e1d8d7d6SMarcus Overhagen
230e1d8d7d6SMarcus Overhagen
231d329f1d6SStephan Aßmus// #pragma mark -
232e1d8d7d6SMarcus Overhagen
233e1d8d7d6SMarcus Overhagen
234e1d8d7d6SMarcus Overhagenvoid
2354ddc254cSStephan AßmusMainWin::FrameResized(float newWidth, float newHeight)
236e1d8d7d6SMarcus Overhagen{
2374ddc254cSStephan Aßmus	if (newWidth != Bounds().Width() || newHeight != Bounds().Height()) {
238d329f1d6SStephan Aßmus		debugger("size wrong\n");
239d329f1d6SStephan Aßmus	}
2405fa5e5feSStephan Aßmus
2414ddc254cSStephan Aßmus	bool noMenu = fNoMenu || fIsFullscreen;
2424ddc254cSStephan Aßmus	bool noControls = fNoControls || fIsFullscreen;
2434ddc254cSStephan Aßmus
2449327db63SFredrik Modeen//	printf("FrameResized enter: newWidth %.0f, newHeight %.0f\n",
2459327db63SFredrik Modeen//		newWidth, newHeight);
2464ddc254cSStephan Aßmus
2474ddc254cSStephan Aßmus	int maxVideoWidth  = int(newWidth) + 1;
2484ddc254cSStephan Aßmus	int maxVideoHeight = int(newHeight) + 1
2494ddc254cSStephan Aßmus		- (noMenu  ? 0 : fMenuBarHeight)
2504ddc254cSStephan Aßmus		- (noControls ? 0 : fControlsHeight);
2514ddc254cSStephan Aßmus
2524ddc254cSStephan Aßmus	ASSERT(maxVideoHeight >= 0);
2534ddc254cSStephan Aßmus
254d329f1d6SStephan Aßmus	int y = 0;
2554ddc254cSStephan Aßmus
2564ddc254cSStephan Aßmus	if (noMenu) {
257d329f1d6SStephan Aßmus		if (!fMenuBar->IsHidden())
258d329f1d6SStephan Aßmus			fMenuBar->Hide();
25999cd5eebSMarcus Overhagen	} else {
260d329f1d6SStephan Aßmus//		fMenuBar->MoveTo(0, y);
2614ddc254cSStephan Aßmus		fMenuBar->ResizeTo(newWidth, fMenuBarHeight - 1);
262d329f1d6SStephan Aßmus		if (fMenuBar->IsHidden())
263d329f1d6SStephan Aßmus			fMenuBar->Show();
264d329f1d6SStephan Aßmus		y += fMenuBarHeight;
26599cd5eebSMarcus Overhagen	}
2664ddc254cSStephan Aßmus
2674ddc254cSStephan Aßmus	if (maxVideoHeight == 0) {
2684ddc254cSStephan Aßmus		bool hidden = fVideoView->IsHidden();
2699327db63SFredrik Modeen//		printf("  video view hidden: %d\n", hidden);
2704ddc254cSStephan Aßmus		if (!hidden)
271d329f1d6SStephan Aßmus			fVideoView->Hide();
272d329f1d6SStephan Aßmus	} else {
2734ddc254cSStephan Aßmus		_ResizeVideoView(0, y, maxVideoWidth, maxVideoHeight);
274d329f1d6SStephan Aßmus		if (fVideoView->IsHidden())
275d329f1d6SStephan Aßmus			fVideoView->Show();
2764ddc254cSStephan Aßmus		y += maxVideoHeight;
277d329f1d6SStephan Aßmus	}
278bae0154cSStephan Aßmus
2794ddc254cSStephan Aßmus	if (noControls) {
280d329f1d6SStephan Aßmus		if (!fControls->IsHidden())
281d329f1d6SStephan Aßmus			fControls->Hide();
282d329f1d6SStephan Aßmus	} else {
283d329f1d6SStephan Aßmus		fControls->MoveTo(0, y);
2844ddc254cSStephan Aßmus		fControls->ResizeTo(newWidth, fControlsHeight - 1);
285d329f1d6SStephan Aßmus		if (fControls->IsHidden())
286d329f1d6SStephan Aßmus			fControls->Show();
287d329f1d6SStephan Aßmus//		y += fControlsHeight;
2885fa5e5feSStephan Aßmus	}
289d329f1d6SStephan Aßmus
2909327db63SFredrik Modeen//	printf("FrameResized leave\n");
29199cd5eebSMarcus Overhagen}
29299cd5eebSMarcus Overhagen
29399cd5eebSMarcus Overhagen
29499cd5eebSMarcus Overhagenvoid
295d329f1d6SStephan AßmusMainWin::Zoom(BPoint rec_position, float rec_width, float rec_height)
29699cd5eebSMarcus Overhagen{
297d329f1d6SStephan Aßmus	PostMessage(M_TOGGLE_FULLSCREEN);
29804a91b97SMarcus Overhagen}
29904a91b97SMarcus Overhagen
30004a91b97SMarcus Overhagen
30104a91b97SMarcus Overhagenvoid
302d329f1d6SStephan AßmusMainWin::DispatchMessage(BMessage *msg, BHandler *handler)
30304a91b97SMarcus Overhagen{
304d329f1d6SStephan Aßmus	if ((msg->what == B_MOUSE_DOWN)
305d329f1d6SStephan Aßmus		&& (handler == fBackground || handler == fVideoView
306d329f1d6SStephan Aßmus				|| handler == fControls))
307d329f1d6SStephan Aßmus		_MouseDown(msg, dynamic_cast<BView*>(handler));
30804a91b97SMarcus Overhagen
309d329f1d6SStephan Aßmus	if ((msg->what == B_MOUSE_MOVED)
310d329f1d6SStephan Aßmus		&& (handler == fBackground || handler == fVideoView
311d329f1d6SStephan Aßmus				|| handler == fControls))
312d329f1d6SStephan Aßmus		_MouseMoved(msg, dynamic_cast<BView*>(handler));
31304a91b97SMarcus Overhagen
314d329f1d6SStephan Aßmus	if ((msg->what == B_MOUSE_UP)
315d329f1d6SStephan Aßmus		&& (handler == fBackground || handler == fVideoView))
316d329f1d6SStephan Aßmus		_MouseUp(msg);
31704a91b97SMarcus Overhagen
318d329f1d6SStephan Aßmus	if ((msg->what == B_KEY_DOWN)
319d329f1d6SStephan Aßmus		&& (handler == fBackground || handler == fVideoView)) {
320e1d8d7d6SMarcus Overhagen
321d329f1d6SStephan Aßmus		// special case for PrintScreen key
322d329f1d6SStephan Aßmus		if (msg->FindInt32("key") == B_PRINT_KEY) {
323d329f1d6SStephan Aßmus			fVideoView->OverlayScreenshotPrepare();
324d329f1d6SStephan Aßmus			BWindow::DispatchMessage(msg, handler);
325d329f1d6SStephan Aßmus			fVideoView->OverlayScreenshotCleanup();
326d329f1d6SStephan Aßmus			return;
327d329f1d6SStephan Aßmus		}
328bae0154cSStephan Aßmus
329d329f1d6SStephan Aßmus		// every other key gets dispatched to our _KeyDown first
330d329f1d6SStephan Aßmus		if (_KeyDown(msg) == B_OK) {
331d329f1d6SStephan Aßmus			// it got handled, don't pass it on
332d329f1d6SStephan Aßmus			return;
333d329f1d6SStephan Aßmus		}
334e1d8d7d6SMarcus Overhagen	}
335bae0154cSStephan Aßmus
336d329f1d6SStephan Aßmus	BWindow::DispatchMessage(msg, handler);
33704a91b97SMarcus Overhagen}
33804a91b97SMarcus Overhagen
33904a91b97SMarcus Overhagen
34004a91b97SMarcus Overhagenvoid
341d329f1d6SStephan AßmusMainWin::MessageReceived(BMessage *msg)
34204a91b97SMarcus Overhagen{
343540fe7aeSStephan Aßmus//	msg->PrintToStream();
344d329f1d6SStephan Aßmus	switch (msg->what) {
345d329f1d6SStephan Aßmus		case B_REFS_RECEIVED:
346d329f1d6SStephan Aßmus			printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
347d329f1d6SStephan Aßmus			_RefsReceived(msg);
348d329f1d6SStephan Aßmus			break;
349d329f1d6SStephan Aßmus		case B_SIMPLE_DATA:
350d329f1d6SStephan Aßmus			printf("MainWin::MessageReceived: B_SIMPLE_DATA\n");
351658aafcbSFrançois Revol			if (msg->HasRef("refs")) {
352658aafcbSFrançois Revol				// add to recent documents as it's not done with drag-n-drop
353658aafcbSFrançois Revol				entry_ref ref;
354658aafcbSFrançois Revol				for (int32 i = 0; msg->FindRef("refs", i, &ref) == B_OK; i++) {
355658aafcbSFrançois Revol					be_roster->AddToRecentDocuments(&ref, kAppSig);
356658aafcbSFrançois Revol				}
357d329f1d6SStephan Aßmus				_RefsReceived(msg);
358658aafcbSFrançois Revol			}
359d329f1d6SStephan Aßmus			break;
36004a91b97SMarcus Overhagen
361df542f71SStephan Aßmus		case M_MEDIA_SERVER_STARTED:
3629a5f768bSStephan Aßmus			printf("TODO: implement M_MEDIA_SERVER_STARTED\n");
363df542f71SStephan Aßmus			// fController->...
364df542f71SStephan Aßmus			break;
365df542f71SStephan Aßmus
366df542f71SStephan Aßmus		case M_MEDIA_SERVER_QUIT:
3679a5f768bSStephan Aßmus			printf("TODO: implement M_MEDIA_SERVER_QUIT\n");
368df542f71SStephan Aßmus			// fController->...
369df542f71SStephan Aßmus			break;
370df542f71SStephan Aßmus
371d329f1d6SStephan Aßmus		// PlaylistObserver messages
372d329f1d6SStephan Aßmus		case MSG_PLAYLIST_REF_ADDED: {
373d329f1d6SStephan Aßmus			entry_ref ref;
374d329f1d6SStephan Aßmus			int32 index;
375d329f1d6SStephan Aßmus			if (msg->FindRef("refs", &ref) == B_OK
376d329f1d6SStephan Aßmus				&& msg->FindInt32("index", &index) == B_OK) {
377d329f1d6SStephan Aßmus				_AddPlaylistItem(ref, index);
378d329f1d6SStephan Aßmus			}
379d329f1d6SStephan Aßmus			break;
380d329f1d6SStephan Aßmus		}
381d329f1d6SStephan Aßmus		case MSG_PLAYLIST_REF_REMOVED: {
382d329f1d6SStephan Aßmus			int32 index;
383d329f1d6SStephan Aßmus			if (msg->FindInt32("index", &index) == B_OK) {
384d329f1d6SStephan Aßmus				_RemovePlaylistItem(index);
385d329f1d6SStephan Aßmus			}
386d329f1d6SStephan Aßmus			break;
387d329f1d6SStephan Aßmus		}
388d329f1d6SStephan Aßmus		case MSG_PLAYLIST_CURRENT_REF_CHANGED: {
38909464bc9SStephan Aßmus			BAutolock _(fPlaylist);
39009464bc9SStephan Aßmus
391d329f1d6SStephan Aßmus			int32 index;
392d329f1d6SStephan Aßmus			if (msg->FindInt32("index", &index) < B_OK
393d329f1d6SStephan Aßmus				|| index != fPlaylist->CurrentRefIndex())
394d329f1d6SStephan Aßmus				break;
395d329f1d6SStephan Aßmus			entry_ref ref;
396d329f1d6SStephan Aßmus			if (fPlaylist->GetRefAt(index, &ref) == B_OK) {
397d329f1d6SStephan Aßmus				printf("open ref: %s\n", ref.name);
398d329f1d6SStephan Aßmus				OpenFile(ref);
399d329f1d6SStephan Aßmus				_MarkPlaylistItem(index);
400d329f1d6SStephan Aßmus			}
401d329f1d6SStephan Aßmus			break;
402d329f1d6SStephan Aßmus		}
40304a91b97SMarcus Overhagen
404d329f1d6SStephan Aßmus		// ControllerObserver messages
405d329f1d6SStephan Aßmus		case MSG_CONTROLLER_FILE_FINISHED:
4069a5f768bSStephan Aßmus		{
4079a5f768bSStephan Aßmus			bool hadNext = fPlaylist->SetCurrentRefIndex(
4089a5f768bSStephan Aßmus				fPlaylist->CurrentRefIndex() + 1);
4099a5f768bSStephan Aßmus			if (!hadNext) {
4109a5f768bSStephan Aßmus				if (fHasVideo) {
4119a5f768bSStephan Aßmus					if (fCloseWhenDonePlayingMovie)
4129a5f768bSStephan Aßmus						PostMessage(B_QUIT_REQUESTED);
4139a5f768bSStephan Aßmus				} else {
4149a5f768bSStephan Aßmus					if (fCloseWhenDonePlayingSound)
4159a5f768bSStephan Aßmus						PostMessage(B_QUIT_REQUESTED);
4169a5f768bSStephan Aßmus				}
4179a5f768bSStephan Aßmus			}
418d329f1d6SStephan Aßmus			break;
4199a5f768bSStephan Aßmus		}
420d329f1d6SStephan Aßmus		case MSG_CONTROLLER_FILE_CHANGED:
4211b7f76bcSStephan Aßmus			// TODO: move all other GUI changes as a reaction to this
4221b7f76bcSStephan Aßmus			// notification
423d329f1d6SStephan Aßmus//			_UpdatePlaylistMenu();
424d329f1d6SStephan Aßmus			break;
425d329f1d6SStephan Aßmus		case MSG_CONTROLLER_VIDEO_TRACK_CHANGED: {
426d329f1d6SStephan Aßmus			int32 index;
427d329f1d6SStephan Aßmus			if (msg->FindInt32("index", &index) == B_OK) {
428d329f1d6SStephan Aßmus				BMenuItem* item = fVideoTrackMenu->ItemAt(index);
429d329f1d6SStephan Aßmus				if (item)
430d329f1d6SStephan Aßmus					item->SetMarked(true);
431d329f1d6SStephan Aßmus			}
432d329f1d6SStephan Aßmus			break;
43304a91b97SMarcus Overhagen		}
434d329f1d6SStephan Aßmus		case MSG_CONTROLLER_AUDIO_TRACK_CHANGED: {
435d329f1d6SStephan Aßmus			int32 index;
436d329f1d6SStephan Aßmus			if (msg->FindInt32("index", &index) == B_OK) {
437d329f1d6SStephan Aßmus				BMenuItem* item = fAudioTrackMenu->ItemAt(index);
438d329f1d6SStephan Aßmus				if (item)
439d329f1d6SStephan Aßmus					item->SetMarked(true);
440d329f1d6SStephan Aßmus			}
441d329f1d6SStephan Aßmus			break;
442d329f1d6SStephan Aßmus		}
443d329f1d6SStephan Aßmus		case MSG_CONTROLLER_PLAYBACK_STATE_CHANGED: {
444d329f1d6SStephan Aßmus			uint32 state;
445d329f1d6SStephan Aßmus			if (msg->FindInt32("state", (int32*)&state) == B_OK)
446d329f1d6SStephan Aßmus				fControls->SetPlaybackState(state);
447d329f1d6SStephan Aßmus			break;
448d329f1d6SStephan Aßmus		}
449d329f1d6SStephan Aßmus		case MSG_CONTROLLER_POSITION_CHANGED: {
450d329f1d6SStephan Aßmus			float position;
451d329f1d6SStephan Aßmus			if (msg->FindFloat("position", &position) == B_OK)
452d329f1d6SStephan Aßmus				fControls->SetPosition(position);
453d329f1d6SStephan Aßmus			break;
45404a91b97SMarcus Overhagen		}
455540fe7aeSStephan Aßmus		case MSG_CONTROLLER_VOLUME_CHANGED: {
456540fe7aeSStephan Aßmus			float volume;
457540fe7aeSStephan Aßmus			if (msg->FindFloat("volume", &volume) == B_OK)
458540fe7aeSStephan Aßmus				fControls->SetVolume(volume);
459540fe7aeSStephan Aßmus			break;
460540fe7aeSStephan Aßmus		}
461540fe7aeSStephan Aßmus		case MSG_CONTROLLER_MUTED_CHANGED: {
462540fe7aeSStephan Aßmus			bool muted;
463540fe7aeSStephan Aßmus			if (msg->FindBool("muted", &muted) == B_OK)
464540fe7aeSStephan Aßmus				fControls->SetMuted(muted);
465540fe7aeSStephan Aßmus			break;
466540fe7aeSStephan Aßmus		}
467d329f1d6SStephan Aßmus
468d329f1d6SStephan Aßmus		// menu item messages
469d329f1d6SStephan Aßmus		case M_FILE_NEWPLAYER:
470d329f1d6SStephan Aßmus			gMainApp->NewWindow();
471d329f1d6SStephan Aßmus			break;
472126ce071SStephan Aßmus		case M_FILE_OPEN: {
473126ce071SStephan Aßmus			BMessenger target(this);
474126ce071SStephan Aßmus			BMessage result(B_REFS_RECEIVED);
475126ce071SStephan Aßmus			BMessage appMessage(M_SHOW_OPEN_PANEL);
476126ce071SStephan Aßmus			appMessage.AddMessenger("target", target);
477126ce071SStephan Aßmus			appMessage.AddMessage("message", &result);
478126ce071SStephan Aßmus			appMessage.AddString("title", "Open Clips");
479126ce071SStephan Aßmus			appMessage.AddString("label", "Open");
480126ce071SStephan Aßmus			be_app->PostMessage(&appMessage);
481d329f1d6SStephan Aßmus			break;
482126ce071SStephan Aßmus		}
483d329f1d6SStephan Aßmus		case M_FILE_INFO:
484d329f1d6SStephan Aßmus			ShowFileInfo();
485d329f1d6SStephan Aßmus			break;
486d329f1d6SStephan Aßmus		case M_FILE_PLAYLIST:
487d329f1d6SStephan Aßmus			ShowPlaylistWindow();
488d329f1d6SStephan Aßmus			break;
489d329f1d6SStephan Aßmus		case B_ABOUT_REQUESTED:
490d329f1d6SStephan Aßmus			BAlert *alert;
491d329f1d6SStephan Aßmus			alert = new BAlert("about", NAME"\n\n Written by Marcus Overhagen "
4921b7f76bcSStephan Aßmus				", Stephan A��mus and Frederik Mod��en", "Thanks");
493d329f1d6SStephan Aßmus			if (fAlwaysOnTop) {
494d329f1d6SStephan Aßmus				_ToggleAlwaysOnTop();
49547a197acSPhilippe Houdoin				alert->Go(NULL);  // Asynchronous mode
496d329f1d6SStephan Aßmus				_ToggleAlwaysOnTop();
497d329f1d6SStephan Aßmus			} else {
49847a197acSPhilippe Houdoin				alert->Go(NULL); // Asynchronous mode
499d329f1d6SStephan Aßmus			}
500d329f1d6SStephan Aßmus			break;
501d329f1d6SStephan Aßmus		case M_FILE_CLOSE:
502d329f1d6SStephan Aßmus			PostMessage(B_QUIT_REQUESTED);
503d329f1d6SStephan Aßmus			break;
504bae0154cSStephan Aßmus		case M_FILE_QUIT:
505d329f1d6SStephan Aßmus			be_app->PostMessage(B_QUIT_REQUESTED);
506d329f1d6SStephan Aßmus			break;
507d329f1d6SStephan Aßmus
508d329f1d6SStephan Aßmus		case M_TOGGLE_FULLSCREEN:
509d329f1d6SStephan Aßmus			_ToggleFullscreen();
510d329f1d6SStephan Aßmus			break;
511d329f1d6SStephan Aßmus
512d329f1d6SStephan Aßmus		case M_TOGGLE_NO_MENU:
513d329f1d6SStephan Aßmus			_ToggleNoMenu();
514d329f1d6SStephan Aßmus			break;
515bae0154cSStephan Aßmus
516d329f1d6SStephan Aßmus		case M_TOGGLE_NO_CONTROLS:
517d329f1d6SStephan Aßmus			_ToggleNoControls();
518d329f1d6SStephan Aßmus			break;
519bae0154cSStephan Aßmus
520d329f1d6SStephan Aßmus		case M_TOGGLE_NO_BORDER:
521d329f1d6SStephan Aßmus			_ToggleNoBorder();
522d329f1d6SStephan Aßmus			break;
523bae0154cSStephan Aßmus
524d329f1d6SStephan Aßmus		case M_TOGGLE_ALWAYS_ON_TOP:
525d329f1d6SStephan Aßmus			_ToggleAlwaysOnTop();
526d329f1d6SStephan Aßmus			break;
527bae0154cSStephan Aßmus
528d329f1d6SStephan Aßmus		case M_TOGGLE_KEEP_ASPECT_RATIO:
529d329f1d6SStephan Aßmus			_ToggleKeepAspectRatio();
530d329f1d6SStephan Aßmus			break;
531d329f1d6SStephan Aßmus
532d329f1d6SStephan Aßmus		case M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS:
533d329f1d6SStephan Aßmus			_ToggleNoBorderNoMenu();
534d329f1d6SStephan Aßmus			break;
535d329f1d6SStephan Aßmus
536d329f1d6SStephan Aßmus		case M_VIEW_50:
537d329f1d6SStephan Aßmus			if (!fHasVideo)
538d329f1d6SStephan Aßmus				break;
539d329f1d6SStephan Aßmus			if (fIsFullscreen)
540d329f1d6SStephan Aßmus				_ToggleFullscreen();
541d329f1d6SStephan Aßmus			_ResizeWindow(50);
542d329f1d6SStephan Aßmus			break;
543bae0154cSStephan Aßmus
544d329f1d6SStephan Aßmus		case M_VIEW_100:
545d329f1d6SStephan Aßmus			if (!fHasVideo)
546d329f1d6SStephan Aßmus				break;
547d329f1d6SStephan Aßmus			if (fIsFullscreen)
548d329f1d6SStephan Aßmus				_ToggleFullscreen();
549d329f1d6SStephan Aßmus			_ResizeWindow(100);
550d329f1d6SStephan Aßmus			break;
551d329f1d6SStephan Aßmus
552d329f1d6SStephan Aßmus		case M_VIEW_200:
553d329f1d6SStephan Aßmus			if (!fHasVideo)
554d329f1d6SStephan Aßmus				break;
555d329f1d6SStephan Aßmus			if (fIsFullscreen)
556d329f1d6SStephan Aßmus				_ToggleFullscreen();
557d329f1d6SStephan Aßmus			_ResizeWindow(200);
558d329f1d6SStephan Aßmus			break;
559d329f1d6SStephan Aßmus
560d329f1d6SStephan Aßmus		case M_VIEW_300:
561d329f1d6SStephan Aßmus			if (!fHasVideo)
562d329f1d6SStephan Aßmus				break;
563d329f1d6SStephan Aßmus			if (fIsFullscreen)
564d329f1d6SStephan Aßmus				_ToggleFullscreen();
565d329f1d6SStephan Aßmus			_ResizeWindow(300);
566d329f1d6SStephan Aßmus			break;
567d329f1d6SStephan Aßmus
568d329f1d6SStephan Aßmus		case M_VIEW_400:
569d329f1d6SStephan Aßmus			if (!fHasVideo)
570d329f1d6SStephan Aßmus				break;
571d329f1d6SStephan Aßmus			if (fIsFullscreen)
572d329f1d6SStephan Aßmus				_ToggleFullscreen();
573d329f1d6SStephan Aßmus			_ResizeWindow(400);
574d329f1d6SStephan Aßmus			break;
575bae0154cSStephan Aßmus/*
576d329f1d6SStephan Aßmus		case B_ACQUIRE_OVERLAY_LOCK:
577d329f1d6SStephan Aßmus			printf("B_ACQUIRE_OVERLAY_LOCK\n");
578d329f1d6