xref: /haiku/src/apps/tv/MainWin.cpp (revision cbed190f71b8aff814bf95539c39a1bcfb953ed8)
1 /*
2  * Copyright (c) 2004-2007 Marcus Overhagen <marcus@overhagen.de>
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify,
8  * merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include "MainWin.h"
26 #include "MainApp.h"
27 #include "Controller.h"
28 #include "config.h"
29 #include "DeviceRoster.h"
30 
31 #include <stdio.h>
32 #include <string.h>
33 
34 #include <Application.h>
35 #include <Alert.h>
36 #include <Menu.h>
37 #include <MenuBar.h>
38 #include <MenuItem.h>
39 #include <Messenger.h>
40 #include <PopUpMenu.h>
41 #include <Screen.h>
42 #include <String.h>
43 #include <View.h>
44 
45 
46 #undef B_TRANSLATE_CONTEXT
47 #define B_TRANSLATE_CONTEXT "MainWin"
48 
49 static const char* fLocalizedName = B_TRANSLATE_MARK("TV");
50 static const char* fLocalizedRevision = B_TRANSLATE_MARK("unknown");
51 static const char* fLocalizedInfo1 = B_TRANSLATE_MARK("DVB - Digital Video Broadcasting TV");
52 
53 enum
54 {
55 	M_DUMMY = 0x100,
56 	M_FILE_ABOUT,
57 	M_FILE_QUIT,
58 	M_SCALE_TO_NATIVE_SIZE,
59 	M_TOGGLE_FULLSCREEN,
60 	M_TOGGLE_NO_BORDER,
61 	M_TOGGLE_NO_MENU,
62 	M_TOGGLE_NO_BORDER_NO_MENU,
63 	M_TOGGLE_ALWAYS_ON_TOP,
64 	M_TOGGLE_KEEP_ASPECT_RATIO,
65 	M_PREFERENCES,
66 	M_CHANNEL_NEXT,
67 	M_CHANNEL_PREV,
68 	M_VOLUME_UP,
69 	M_VOLUME_DOWN,
70 	M_ASPECT_100000_1,
71 	M_ASPECT_106666_1,
72 	M_ASPECT_109091_1,
73 	M_ASPECT_141176_1,
74 	M_ASPECT_720_576,
75 	M_ASPECT_704_576,
76 	M_ASPECT_544_576,
77 	M_SELECT_INTERFACE		= 0x00000800,
78 	M_SELECT_INTERFACE_END	= 0x00000fff,
79 	M_SELECT_CHANNEL		= 0x00010000,
80 	M_SELECT_CHANNEL_END	= 0x000fffff,
81 		// this limits possible channel count to 0xeffff = 983039
82 };
83 
84 //#define printf(a...)
85 
86 
87 MainWin::MainWin(BRect frame_rect)
88  :	BWindow(frame_rect, B_TRANSLATE(NAME), B_TITLED_WINDOW,
89  	B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
90  ,	fController(new Controller)
91  ,	fIsFullscreen(false)
92  ,	fKeepAspectRatio(true)
93  ,	fAlwaysOnTop(false)
94  ,	fNoMenu(false)
95  ,	fNoBorder(false)
96  ,	fSourceWidth(720)
97  ,	fSourceHeight(576)
98  ,	fWidthScale(1.0)
99  ,	fHeightScale(1.0)
100  ,	fMouseDownTracking(false)
101  ,	fFrameResizedTriggeredAutomatically(false)
102  ,	fIgnoreFrameResized(false)
103  ,	fFrameResizedCalled(true)
104 {
105 	BRect rect = Bounds();
106 
107 	// background
108 	fBackground = new BView(rect, "background", B_FOLLOW_ALL,
109 		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
110 	fBackground->SetViewColor(0,0,0);
111 	AddChild(fBackground);
112 
113 	// menu
114 	fMenuBar = new BMenuBar(fBackground->Bounds(), "menu");
115 	CreateMenu();
116 	fBackground->AddChild(fMenuBar);
117 	fMenuBar->ResizeToPreferred();
118 	fMenuBarHeight = (int)fMenuBar->Frame().Height() + 1;
119 	fMenuBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
120 
121 	// video view
122 	BRect video_rect = BRect(0, fMenuBarHeight, rect.right, rect.bottom);
123 	fVideoView = new VideoView(video_rect, "video display", B_FOLLOW_ALL,
124 		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
125 	fBackground->AddChild(fVideoView);
126 
127 	fVideoView->MakeFocus();
128 
129 //	SetSizeLimits(fControlViewMinWidth - 1, 32767,
130 //		fMenuBarHeight + fControlViewHeight - 1, fMenuBarHeight
131 //		+ fControlViewHeight - 1);
132 
133 //	SetSizeLimits(320 - 1, 32767, 240 + fMenuBarHeight - 1, 32767);
134 
135 	SetSizeLimits(0, 32767, fMenuBarHeight - 1, 32767);
136 
137 	fController->SetVideoView(fVideoView);
138 	fController->SetVideoNode(fVideoView->Node());
139 
140 	fVideoView->IsOverlaySupported();
141 
142 	SetupInterfaceMenu();
143 	SelectInitialInterface();
144 	SetInterfaceMenuMarker();
145 	SetupChannelMenu();
146 	SetChannelMenuMarker();
147 
148 	VideoFormatChange(fSourceWidth, fSourceHeight, fWidthScale, fHeightScale);
149 
150 	CenterOnScreen();
151 }
152 
153 
154 MainWin::~MainWin()
155 {
156 	printf("MainWin::~MainWin\n");
157 	fController->DisconnectInterface();
158 	delete fController;
159 }
160 
161 
162 void
163 MainWin::CreateMenu()
164 {
165 	fFileMenu = new BMenu(B_TRANSLATE(NAME));
166 	fChannelMenu = new BMenu(B_TRANSLATE("Channel"));
167 	fInterfaceMenu = new BMenu(B_TRANSLATE("Interface"));
168 	fSettingsMenu = new BMenu(B_TRANSLATE("Settings"));
169 	fDebugMenu = new BMenu(B_TRANSLATE("Debug"));
170 
171 	fMenuBar->AddItem(fFileMenu);
172 	fMenuBar->AddItem(fChannelMenu);
173 	fMenuBar->AddItem(fInterfaceMenu);
174 	fMenuBar->AddItem(fSettingsMenu);
175 	fMenuBar->AddItem(fDebugMenu);
176 
177 	BString aboutStr = B_TRANSLATE_COMMENT("About %1"B_UTF8_ELLIPSIS,
178 		"Parameter %1 is the name of the application.");
179 	aboutStr.ReplaceFirst("%1", fLocalizedName);
180 	fFileMenu->AddItem(new BMenuItem(aboutStr.String(),
181 		new BMessage(M_FILE_ABOUT)));
182 	fFileMenu->AddSeparatorItem();
183 	fFileMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
184 		new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY));
185 
186 /*
187 	fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Next channel"),
188 		new BMessage(M_CHANNEL_NEXT), '+', B_COMMAND_KEY));
189 	fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Previous channel"),
190 		new BMessage(M_CHANNEL_PREV), '-', B_COMMAND_KEY));
191 	fChannelMenu->AddSeparatorItem();
192 	fChannelMenu->AddItem(new BMenuItem("RTL", new BMessage(M_DUMMY), '0',
193 		B_COMMAND_KEY));
194 	fChannelMenu->AddItem(new BMenuItem("Pro7", new BMessage(M_DUMMY), '1',
195 		B_COMMAND_KEY));
196 
197 	fInterfaceMenu->AddItem(new BMenuItem(B_TRANSLATE("none"),
198 		new BMessage(M_DUMMY)));
199 	fInterfaceMenu->AddItem(new BMenuItem(B_TRANSLATE("none 1"),
200 		new BMessage(M_DUMMY)));
201 	fInterfaceMenu->AddItem(new BMenuItem(B_TRANSLATE("none 2"),
202 		new BMessage(M_DUMMY)));
203 */
204 
205 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("Scale to native size"),
206 		new BMessage(M_SCALE_TO_NATIVE_SIZE), 'N', B_COMMAND_KEY));
207 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("Full screen"),
208 		new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY));
209 	fSettingsMenu->AddSeparatorItem();
210 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("No menu"),
211 		new BMessage(M_TOGGLE_NO_MENU), 'M', B_COMMAND_KEY));
212 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("No border"),
213 		new BMessage(M_TOGGLE_NO_BORDER), 'B', B_COMMAND_KEY));
214 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("Always on top"),
215 		new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T', B_COMMAND_KEY));
216 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("Keep aspect ratio"),
217 		new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY));
218 	fSettingsMenu->AddSeparatorItem();
219 	fSettingsMenu->AddItem(new BMenuItem(B_TRANSLATE("Settings"B_UTF8_ELLIPSIS)
220 		, new BMessage(M_PREFERENCES), 'P', B_COMMAND_KEY));
221 
222 	const char* pixel_ratio = B_TRANSLATE("pixel aspect ratio");
223 	BString str1 = pixel_ratio;
224 	str1 << " 1.00000:1";
225 	fDebugMenu->AddItem(new BMenuItem(str1.String(),
226 		new BMessage(M_ASPECT_100000_1)));
227 	BString str2 = pixel_ratio;
228 	str2 << " 1.06666:1";
229 	fDebugMenu->AddItem(new BMenuItem(str2.String(),
230 		new BMessage(M_ASPECT_106666_1)));
231 	BString str3 = pixel_ratio;
232 	str3 << " 1.09091:1";
233 	fDebugMenu->AddItem(new BMenuItem(str3.String(),
234 		new BMessage(M_ASPECT_109091_1)));
235 	BString str4 = pixel_ratio;
236 	str4 << " 1.41176:1";
237 	fDebugMenu->AddItem(new BMenuItem(str4.String(),
238 		new BMessage(M_ASPECT_141176_1)));
239 	fDebugMenu->AddItem(new BMenuItem(B_TRANSLATE(
240 		"force 720 x 576, display aspect 4:3"),
241 		new BMessage(M_ASPECT_720_576)));
242 	fDebugMenu->AddItem(new BMenuItem(B_TRANSLATE(
243 		"force 704 x 576, display aspect 4:3"),
244 		new BMessage(M_ASPECT_704_576)));
245 	fDebugMenu->AddItem(new BMenuItem(B_TRANSLATE(
246 		"force 544 x 576, display aspect 4:3"),
247 		new BMessage(M_ASPECT_544_576)));
248 
249 	fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
250 	fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
251 	fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
252 	fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
253 	fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
254 	fSettingsMenu->ItemAt(8)->SetEnabled(false);
255 		// XXX disable unused preference menu
256 }
257 
258 
259 void
260 MainWin::SetupInterfaceMenu()
261 {
262 	fInterfaceMenu->RemoveItems(0, fInterfaceMenu->CountItems(), true);
263 
264 	fInterfaceMenu->AddItem(new BMenuItem(B_TRANSLATE("None"),
265 		new BMessage(M_SELECT_INTERFACE)));
266 
267 	int count = gDeviceRoster->DeviceCount();
268 
269 	if (count > 0)
270 		fInterfaceMenu->AddSeparatorItem();
271 
272 	for (int i = 0; i < count; i++) {
273 		// 1 gets subtracted in MessageReceived, so -1 is Interface None,
274 		// and 0 == Interface 0 in SelectInterface()
275 		fInterfaceMenu->AddItem(new BMenuItem(gDeviceRoster->DeviceName(i),
276 			new BMessage(M_SELECT_INTERFACE + i + 1)));
277 	}
278 }
279 
280 
281 void
282 MainWin::SetupChannelMenu()
283 {
284 	fChannelMenu->RemoveItems(0, fChannelMenu->CountItems(), true);
285 
286 	int interface = fController->CurrentInterface();
287 	printf("MainWin::SetupChannelMenu: interface %d\n", interface);
288 
289 	int channels = fController->ChannelCount();
290 
291 	if (channels == 0) {
292 		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("None"),
293 			new BMessage(M_DUMMY)));
294 	} else {
295 		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Next channel"),
296 			new BMessage(M_CHANNEL_NEXT), '+', B_COMMAND_KEY));
297 		fChannelMenu->AddItem(new BMenuItem(B_TRANSLATE("Previous channel"),
298 			new BMessage(M_CHANNEL_PREV), '-', B_COMMAND_KEY));
299 		fChannelMenu->AddSeparatorItem();
300 	}
301 
302 	char s[100];
303 	for (int i = 0; i < channels; i++) {
304 		sprintf(s, "%s%d %s", (i < 9) ? "  " : "", i + 1, fController->ChannelName(i));
305 		fChannelMenu->AddItem(new BMenuItem(s, new BMessage(M_SELECT_CHANNEL + i)));
306 	}
307 }
308 
309 
310 void
311 MainWin::SetInterfaceMenuMarker()
312 {
313 	BMenuItem *item;
314 
315 	int interface = fController->CurrentInterface();
316 	printf("MainWin::SetInterfaceMenuMarker: interface %d\n", interface);
317 
318 	// remove old marker
319 	item = fInterfaceMenu->FindMarked();
320 	if (item)
321 		item->SetMarked(false);
322 
323 	// set new marker
324 	int index = (interface < 0) ? 0 : interface + 2;
325 	item = fInterfaceMenu->ItemAt(index);
326 	if (item)
327 		item->SetMarked(true);
328 }
329 
330 
331 void
332 MainWin::SetChannelMenuMarker()
333 {
334 	BMenuItem *item;
335 
336 	int channel = fController->CurrentChannel();
337 	printf("MainWin::SetChannelMenuMarker: channel %d\n", channel);
338 
339 	// remove old marker
340 	item = fChannelMenu->FindMarked();
341 	if (item)
342 		item->SetMarked(false);
343 
344 	// set new marker
345 	int index = (channel < 0) ? 0 : channel + 3;
346 	item = fChannelMenu->ItemAt(index);
347 	if (item)
348 		item->SetMarked(true);
349 }
350 
351 
352 void
353 MainWin::SelectChannel(int i)
354 {
355 	printf("MainWin::SelectChannel %d\n", i);
356 
357 	if (B_OK != fController->SelectChannel(i))
358 		return;
359 
360 	SetChannelMenuMarker();
361 }
362 
363 
364 void
365 MainWin::SelectInterface(int i)
366 {
367 	printf("MainWin::SelectInterface %d\n", i);
368 	printf("  CurrentInterface %d\n", fController->CurrentInterface());
369 	printf("  CurrentChannel %d\n", fController->CurrentChannel());
370 
371 	// i = -1 means "None"
372 
373 	if (i < 0) {
374 		fController->DisconnectInterface();
375 		goto done;
376 	}
377 
378 	if (!fController->IsInterfaceAvailable(i)) {
379 		BString s;
380 		s << B_TRANSLATE("Error, interface is busy:\n\n");
381 		s << gDeviceRoster->DeviceName(i);
382 		(new BAlert("error", s.String(), B_TRANSLATE("OK")))->Go();
383 		return;
384 	}
385 
386 	fController->DisconnectInterface();
387 	if (fController->ConnectInterface(i) != B_OK) {
388 		BString s;
389 		s << B_TRANSLATE("Error, connecting to interface failed:\n\n");
390 		s << gDeviceRoster->DeviceName(i);
391 		(new BAlert("error", s.String(), B_TRANSLATE("OK")))->Go();
392 	}
393 
394 done:
395 	printf("MainWin::SelectInterface done:\n");
396 	printf("  CurrentInterface %d\n", fController->CurrentInterface());
397 	printf("  CurrentChannel %d\n", fController->CurrentChannel());
398 
399 	SetInterfaceMenuMarker();
400 	SetupChannelMenu();
401 	SetChannelMenuMarker();
402 }
403 
404 
405 void
406 MainWin::SelectInitialInterface()
407 {
408 	printf("MainWin::SelectInitialInterface enter\n");
409 
410 	int count = gDeviceRoster->DeviceCount();
411 	for (int i = 0; i < count; i++) {
412 		if (fController->IsInterfaceAvailable(i)
413 			&& B_OK == fController->ConnectInterface(i)) {
414 			printf("MainWin::SelectInitialInterface connected to interface "
415 				"%d\n", i);
416 			break;
417 		}
418 	}
419 
420 	printf("MainWin::SelectInitialInterface leave\n");
421 }
422 
423 
424 bool
425 MainWin::QuitRequested()
426 {
427 	be_app->PostMessage(B_QUIT_REQUESTED);
428 	return true;
429 }
430 
431 
432 void
433 MainWin::MouseDown(BMessage *msg)
434 {
435 	BPoint screen_where;
436 	uint32 buttons = msg->FindInt32("buttons");
437 
438 	// On Zeta, only "screen_where" is relyable, "where" and "be:view_where"
439 	// seem to be broken
440 	if (B_OK != msg->FindPoint("screen_where", &screen_where)) {
441 		// Workaround for BeOS R5, it has no "screen_where"
442 		fVideoView->GetMouse(&screen_where, &buttons, false);
443 		fVideoView->ConvertToScreen(&screen_where);
444 	}
445 
446 //	msg->PrintToStream();
447 
448 //	if (1 == msg->FindInt32("buttons") && msg->FindInt32("clicks") == 1) {
449 
450 	if (1 == buttons && msg->FindInt32("clicks") % 2 == 0) {
451 		BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1,
452 			screen_where.y + 1);
453 		if (r.Contains(fMouseDownMousePos)) {
454 			PostMessage(M_TOGGLE_FULLSCREEN);
455 			return;
456 		}
457 	}
458 
459 	if (2 == buttons && msg->FindInt32("clicks") % 2 == 0) {
460 		BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1,
461 			screen_where.y + 1);
462 		if (r.Contains(fMouseDownMousePos)) {
463 			PostMessage(M_TOGGLE_NO_BORDER_NO_MENU);
464 			return;
465 		}
466 	}
467 
468 /*
469 		// very broken in Zeta:
470 		fMouseDownMousePos = fVideoView->ConvertToScreen(
471 			msg->FindPoint("where"));
472 */
473 	fMouseDownMousePos = screen_where;
474 	fMouseDownWindowPos = Frame().LeftTop();
475 
476 	if (buttons == 1 && !fIsFullscreen) {
477 		// start mouse tracking
478 		fVideoView->SetMouseEventMask(B_POINTER_EVENTS | B_NO_POINTER_HISTORY
479 			/* | B_LOCK_WINDOW_FOCUS */);
480 		fMouseDownTracking = true;
481 	}
482 
483 	// pop up a context menu if right mouse button is down for 200 ms
484 
485 	if ((buttons & 2) == 0)
486 		return;
487 	bigtime_t start = system_time();
488 	bigtime_t delay = 200000;
489 	BPoint location;
490 	do {
491 		fVideoView->GetMouse(&location, &buttons);
492 		if ((buttons & 2) == 0)
493 			break;
494 		snooze(1000);
495 	} while (system_time() - start < delay);
496 
497 	if (buttons & 2)
498 		ShowContextMenu(screen_where);
499 }
500 
501 
502 void
503 MainWin::MouseMoved(BMessage *msg)
504 {
505 //	msg->PrintToStream();
506 
507 	BPoint mousePos;
508 	uint32 buttons = msg->FindInt32("buttons");
509 
510 	if (1 == buttons && fMouseDownTracking && !fIsFullscreen) {
511 /*
512 		// very broken in Zeta:
513 		BPoint mousePos = msg->FindPoint("where");
514 		printf("view where: %.0f, %.0f => ", mousePos.x, mousePos.y);
515 		fVideoView->ConvertToScreen(&mousePos);
516 */
517 		// On Zeta, only "screen_where" is relyable, "where" and
518 		// "be:view_where" seem to be broken
519 		if (B_OK != msg->FindPoint("screen_where", &mousePos)) {
520 			// Workaround for BeOS R5, it has no "screen_where"
521 			fVideoView->GetMouse(&mousePos, &buttons, false);
522 			fVideoView->ConvertToScreen(&mousePos);
523 		}
524 //		printf("screen where: %.0f, %.0f => ", mousePos.x, mousePos.y);
525 		float delta_x = mousePos.x - fMouseDownMousePos.x;
526 		float delta_y = mousePos.y - fMouseDownMousePos.y;
527 		float x = fMouseDownWindowPos.x + delta_x;
528 		float y = fMouseDownWindowPos.y + delta_y;
529 //		printf("move window to %.0f, %.0f\n", x, y);
530 		MoveTo(x, y);
531 	}
532 }
533 
534 
535 void
536 MainWin::MouseUp(BMessage *msg)
537 {
538 //	msg->PrintToStream();
539 	fMouseDownTracking = false;
540 }
541 
542 
543 void
544 MainWin::ShowContextMenu(const BPoint &screen_point)
545 {
546 	printf("Show context menu\n");
547 	BPopUpMenu *menu = new BPopUpMenu("context menu", false, false);
548 	BMenuItem *item;
549 	menu->AddItem(new BMenuItem(B_TRANSLATE("Scale to native size"),
550 		new BMessage(M_SCALE_TO_NATIVE_SIZE), 'N', B_COMMAND_KEY));
551 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Full screen"),
552 		new BMessage(M_TOGGLE_FULLSCREEN), 'F', B_COMMAND_KEY));
553 	item->SetMarked(fIsFullscreen);
554 	menu->AddSeparatorItem();
555 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("No menu"),
556 		new BMessage(M_TOGGLE_NO_MENU), 'M', B_COMMAND_KEY));
557 	item->SetMarked(fNoMenu);
558 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("No border"),
559 		new BMessage(M_TOGGLE_NO_BORDER), 'B', B_COMMAND_KEY));
560 	item->SetMarked(fNoBorder);
561 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Always on top"),
562 		new BMessage(M_TOGGLE_ALWAYS_ON_TOP), 'T', B_COMMAND_KEY));
563 	item->SetMarked(fAlwaysOnTop);
564 	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Keep aspect ratio"),
565 		new BMessage(M_TOGGLE_KEEP_ASPECT_RATIO), 'K', B_COMMAND_KEY));
566 	item->SetMarked(fKeepAspectRatio);
567 	menu->AddSeparatorItem();
568 	BString aboutStr = B_TRANSLATE_COMMENT("About %1"B_UTF8_ELLIPSIS,
569 		"Parameter %1 is the name of the application.");
570 	aboutStr.ReplaceFirst("%1", fLocalizedName);
571 	menu->AddItem(new BMenuItem(aboutStr.String(),
572 		new BMessage(M_FILE_ABOUT)));
573 	menu->AddSeparatorItem();
574 	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
575 		new BMessage(M_FILE_QUIT), 'Q', B_COMMAND_KEY));
576 
577 	menu->AddSeparatorItem();
578 	const char* pixel_aspect = "pixel aspect ratio";
579 	BString str1 = pixel_aspect;
580 	str1 << " 1.00000:1";
581 	menu->AddItem(new BMenuItem(str1.String(),
582 		new BMessage(M_ASPECT_100000_1)));
583 	BString str2 = pixel_aspect;
584 	str2 << " 1.06666:1";
585 	menu->AddItem(new BMenuItem(str2.String(),
586 		new BMessage(M_ASPECT_106666_1)));
587 	BString str3 = pixel_aspect;
588 	str3 << " 1.09091:1";
589 	menu->AddItem(new BMenuItem(str3.String(),
590 		new BMessage(M_ASPECT_109091_1)));
591 	BString str4 = pixel_aspect;
592 	str4 << " 1.41176:1";
593 	menu->AddItem(new BMenuItem(str4.String(),
594 		new BMessage(M_ASPECT_141176_1)));
595 	menu->AddItem(new BMenuItem(B_TRANSLATE(
596 		"force 720 x 576, display aspect 4:3"),
597 		new BMessage(M_ASPECT_720_576)));
598 	menu->AddItem(new BMenuItem(B_TRANSLATE(
599 		"force 704 x 576, display aspect 4:3"),
600 		new BMessage(M_ASPECT_704_576)));
601 	menu->AddItem(new BMenuItem(B_TRANSLATE(
602 		"force 544 x 576, display aspect 4:3"),
603 		new BMessage(M_ASPECT_544_576)));
604 
605 	menu->SetTargetForItems(this);
606 	BRect r(screen_point.x - 5, screen_point.y - 5, screen_point.x + 5,
607 		screen_point.y + 5);
608 	menu->Go(screen_point, true, true, r, true);
609 }
610 
611 
612 void
613 MainWin::VideoFormatChange(int width, int height, float width_scale,
614 	float height_scale)
615 {
616 	// called when video format or aspect ratio changes
617 
618 	printf("VideoFormatChange enter: width %d, height %d, width_scale %.6f, "
619 		"height_scale %.6f\n", width, height, width_scale, height_scale);
620 
621 	if (width_scale < 1.0 && height_scale >= 1.0) {
622 		width_scale  = 1.0 / width_scale;
623 		height_scale = 1.0 / height_scale;
624 		printf("inverting! new values: width_scale %.6f, height_scale %.6f\n",
625 			width_scale, height_scale);
626 	}
627 
628  	fSourceWidth  = width;
629  	fSourceHeight = height;
630  	fWidthScale   = width_scale;
631  	fHeightScale  = height_scale;
632 
633 //	ResizeWindow(Bounds().Width() + 1, Bounds().Height() + 1, true);
634 
635 	if (fIsFullscreen) {
636 		AdjustFullscreenRenderer();
637 	} else {
638 		AdjustWindowedRenderer(false);
639 	}
640 
641 	printf("VideoFormatChange leave\n");
642 
643 }
644 
645 
646 void
647 MainWin::Zoom(BPoint rec_position, float rec_width, float rec_height)
648 {
649 	PostMessage(M_TOGGLE_FULLSCREEN);
650 }
651 
652 
653 void
654 MainWin::FrameResized(float new_width, float new_height)
655 {
656 	// called when the window got resized
657 	fFrameResizedCalled = true;
658 
659 	if (new_width != Bounds().Width() || new_height != Bounds().Height()) {
660 		debugger("size wrong\n");
661 	}
662 
663 
664 	printf("FrameResized enter: new_width %.0f, new_height %.0f, bounds width "
665 		"%.0f, bounds height %.0f\n", new_width, new_height, Bounds().Width(),
666 		Bounds().Height());
667 
668 	if (fIsFullscreen) {
669 
670 		printf("FrameResized in fullscreen mode\n");
671 
672 		fIgnoreFrameResized = false;
673 		AdjustFullscreenRenderer();
674 
675 	} else {
676 
677 		if (fFrameResizedTriggeredAutomatically) {
678 			fFrameResizedTriggeredAutomatically = false;
679 			printf("FrameResized triggered automatically\n");
680 
681 			fIgnoreFrameResized = false;
682 
683 			AdjustWindowedRenderer(false);
684 		} else {
685 			printf("FrameResized by user in window mode\n");
686 
687 			if (fIgnoreFrameResized) {
688 				fIgnoreFrameResized = false;
689 				printf("FrameResized ignored\n");
690 				return;
691 			}
692 
693 			AdjustWindowedRenderer(true);
694 		}
695 
696 	}
697 
698 	printf("FrameResized leave\n");
699 }
700 
701 
702 
703 void
704 MainWin::UpdateWindowTitle()
705 {
706 	char buf[100];
707 	sprintf(buf, "%s - %d x %d, %.3f:%.3f => %.0f x %.0f", B_TRANSLATE(NAME),
708 		fSourceWidth, fSourceHeight, fWidthScale, fHeightScale,
709 		fVideoView->Bounds().Width() + 1, fVideoView->Bounds().Height() + 1);
710 	SetTitle(buf);
711 }
712 
713 
714 void
715 MainWin::AdjustFullscreenRenderer()
716 {
717 	// n.b. we don't have a menu in fullscreen mode!
718 
719 	if (fKeepAspectRatio) {
720 
721 		// Keep aspect ratio, place render inside
722 		// the background area (may create black bars).
723 		float max_width  = fBackground->Bounds().Width() + 1.0f;
724 		float max_height = fBackground->Bounds().Height() + 1.0f;
725 		float scaled_width  = fSourceWidth * fWidthScale;
726 		float scaled_height = fSourceHeight * fHeightScale;
727 		float factor = min_c(max_width / scaled_width, max_height
728 			/ scaled_height);
729 		int render_width = int(scaled_width * factor);
730 		int render_height = int(scaled_height * factor);
731 		int x_ofs = (int(max_width) - render_width) / 2;
732 		int y_ofs = (int(max_height) - render_height) / 2;
733 
734 		printf("AdjustFullscreenRenderer: background %.1f x %.1f, src video "
735 			"%d x %d, scaled video %.3f x %.3f, factor %.3f, render %d x %d, "
736 			"x-ofs %d, y-ofs %d\n", max_width, max_height, fSourceWidth,
737 			fSourceHeight, scaled_width, scaled_height, factor, render_width,
738 			render_height, x_ofs, y_ofs);
739 
740 		fVideoView->MoveTo(x_ofs, y_ofs);
741 		fVideoView->ResizeTo(render_width - 1, render_height - 1);
742 
743 	} else {
744 
745 		printf("AdjustFullscreenRenderer: using whole background area\n");
746 
747 		// no need to keep aspect ratio, make
748 		// render cover the whole background
749 		fVideoView->MoveTo(0, 0);
750 		fVideoView->ResizeTo(fBackground->Bounds().Width(),
751 			fBackground->Bounds().Height());
752 
753 	}
754 }
755 
756 
757 void
758 MainWin::AdjustWindowedRenderer(bool user_resized)
759 {
760 	printf("AdjustWindowedRenderer enter - user_resized %d\n", user_resized);
761 
762 	// In windowed mode, the renderer always covers the
763 	// whole background, accounting for the menu
764 	fVideoView->MoveTo(0, fNoMenu ? 0 : fMenuBarHeight);
765 	fVideoView->ResizeTo(fBackground->Bounds().Width(),
766 		fBackground->Bounds().Height() - (fNoMenu ? 0 : fMenuBarHeight));
767 
768 	if (fKeepAspectRatio) {
769 		// To keep the aspect ratio correct, we
770 		// do resize the window as required
771 
772 		float max_width  = Bounds().Width() + 1.0f;
773 		float max_height = Bounds().Height() + 1.0f - (fNoMenu ? 0
774 			: fMenuBarHeight);
775 		float scaled_width  = fSourceWidth * fWidthScale;
776 		float scaled_height = fSourceHeight * fHeightScale;
777 
778 		if (!user_resized && (scaled_width > max_width
779 			|| scaled_height > max_height)) {
780 			// A format switch occured, and the window was
781 			// smaller then the video source. As it was not
782 			// initiated by the user resizing the window, we
783 			// enlarge the window to fit the video.
784 			fIgnoreFrameResized = true;
785 			ResizeTo(scaled_width - 1, scaled_height - 1
786 				+ (fNoMenu ? 0 : fMenuBarHeight));
787 //			Sync();
788 			return;
789 		}
790 
791 		float display_aspect_ratio = scaled_width / scaled_height;
792 		int new_width  = int(max_width);
793 		int new_height = int(max_width / display_aspect_ratio + 0.5);
794 
795 		printf("AdjustWindowedRenderer: old display %d x %d, src video "
796 			"%d x %d, scaled video %.3f x %.3f, aspect ratio %.3f, new "
797 			"display %d x %d\n", int(max_width), int(max_height),
798 			fSourceWidth, fSourceHeight, scaled_width, scaled_height,
799 			display_aspect_ratio, new_width, new_height);
800 
801 		fIgnoreFrameResized = true;
802 		ResizeTo(new_width - 1, new_height - 1 + (fNoMenu ? 0
803 			: fMenuBarHeight));
804 //		Sync();
805 	}
806 
807 	printf("AdjustWindowedRenderer leave\n");
808 }
809 
810 
811 void
812 MainWin::ToggleNoBorderNoMenu()
813 {
814 	if (!fNoMenu && fNoBorder) {
815 		// if no border, switch of menu, too
816 		PostMessage(M_TOGGLE_NO_MENU);
817 	} else
818 	if (fNoMenu && !fNoBorder) {
819 		// if no menu, switch of border, too
820 		PostMessage(M_TOGGLE_NO_BORDER);
821 	} else {
822 		// both are either on or off, toggle both
823 		PostMessage(M_TOGGLE_NO_MENU);
824 		PostMessage(M_TOGGLE_NO_BORDER);
825 	}
826 }
827 
828 
829 void
830 MainWin::ToggleFullscreen()
831 {
832 	printf("ToggleFullscreen enter\n");
833 
834 	if (!fFrameResizedCalled) {
835 		printf("ToggleFullscreen - ignoring, as FrameResized wasn't called "
836 			"since last switch\n");
837 		return;
838 	}
839 	fFrameResizedCalled = false;
840 
841 
842 	fIsFullscreen = !fIsFullscreen;
843 
844 	if (fIsFullscreen) {
845 		// switch to fullscreen
846 
847 		// Sync here is probably not required
848 //		Sync();
849 
850 		fSavedFrame = Frame();
851 		printf("saving current frame: %d %d %d %d\n", int(fSavedFrame.left),
852 			int(fSavedFrame.top), int(fSavedFrame.right),
853 			int(fSavedFrame.bottom));
854 		BScreen screen(this);
855 		BRect rect(screen.Frame());
856 
857 		Hide();
858 		if (!fNoMenu) {
859 			// if we have a menu, remove it now
860 			fMenuBar->Hide();
861 		}
862 		fFrameResizedTriggeredAutomatically = true;
863 		MoveTo(rect.left, rect.top);
864 		ResizeTo(rect.Width(), rect.Height());
865 		Show();
866 
867 //		Sync();
868 
869 	} else {
870 		// switch back from full screen mode
871 
872 		Hide();
873 		// if we need a menu, show it now
874 		if (!fNoMenu) {
875 			fMenuBar->Show();
876 		}
877 		fFrameResizedTriggeredAutomatically = true;
878 		MoveTo(fSavedFrame.left, fSavedFrame.top);
879 		ResizeTo(fSavedFrame.Width(), fSavedFrame.Height());
880 		Show();
881 
882 		// We *must* make sure that the window is at
883 		// the correct position before continuing, or
884 		// rapid fullscreen switching by holding down
885 		// the TAB key will expose strange bugs.
886 		// Never remove this Sync!
887 //		Sync();
888 	}
889 
890 	// FrameResized() will do the required adjustments
891 
892 	printf("ToggleFullscreen leave\n");
893 }
894 
895 
896 void
897 MainWin::ToggleNoMenu()
898 {
899 	printf("ToggleNoMenu enter\n");
900 
901 	fNoMenu = !fNoMenu;
902 
903 	if (fIsFullscreen) {
904 		// fullscreen is always without menu
905 		printf("ToggleNoMenu leave, doing nothing, we are fullscreen\n");
906 		return;
907 	}
908 
909 //	fFrameResizedTriggeredAutomatically = true;
910 	fIgnoreFrameResized = true;
911 
912 	if (fNoMenu) {
913 		fMenuBar->Hide();
914 		fVideoView->MoveTo(0, 0);
915 		fVideoView->ResizeBy(0, fMenuBarHeight);
916 		MoveBy(0, fMenuBarHeight);
917 		ResizeBy(0, - fMenuBarHeight);
918 //		Sync();
919 	} else {
920 		fMenuBar->Show();
921 		fVideoView->MoveTo(0, fMenuBarHeight);
922 		fVideoView->ResizeBy(0, -fMenuBarHeight);
923 		MoveBy(0, - fMenuBarHeight);
924 		ResizeBy(0, fMenuBarHeight);
925 //		Sync();
926 	}
927 
928 	printf("ToggleNoMenu leave\n");
929 }
930 
931 
932 void
933 MainWin::ToggleNoBorder()
934 {
935 	printf("ToggleNoBorder enter\n");
936 	fNoBorder = !fNoBorder;
937 //	SetLook(fNoBorder ? B_NO_BORDER_WINDOW_LOOK : B_TITLED_WINDOW_LOOK);
938 	SetLook(fNoBorder ? B_BORDERED_WINDOW_LOOK : B_TITLED_WINDOW_LOOK);
939 	printf("ToggleNoBorder leave\n");
940 }
941 
942 
943 void
944 MainWin::ToggleAlwaysOnTop()
945 {
946 	printf("ToggleAlwaysOnTop enter\n");
947 	fAlwaysOnTop = !fAlwaysOnTop;
948 	SetFeel(fAlwaysOnTop ? B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
949 	printf("ToggleAlwaysOnTop leave\n");
950 }
951 
952 
953 void
954 MainWin::ToggleKeepAspectRatio()
955 {
956 	printf("ToggleKeepAspectRatio enter\n");
957 	fKeepAspectRatio = !fKeepAspectRatio;
958 
959 	fFrameResizedTriggeredAutomatically = true;
960 	FrameResized(Bounds().Width(), Bounds().Height());
961 //	if (fIsFullscreen) {
962 //		AdjustFullscreenRenderer();
963 //	} else {
964 //		AdjustWindowedRenderer(false);
965 //	}
966 	printf("ToggleKeepAspectRatio leave\n");
967 }
968 
969 
970 /* Trap keys that are about to be send to background or renderer view.
971  * Return B_OK if it shouldn't be passed to the view
972  */
973 status_t
974 MainWin::KeyDown(BMessage *msg)
975 {
976 //	msg->PrintToStream();
977 
978 	uint32 key		 = msg->FindInt32("key");
979 	uint32 raw_char  = msg->FindInt32("raw_char");
980 	uint32 modifiers = msg->FindInt32("modifiers");
981 
982 	printf("key 0x%lx, raw_char 0x%lx, modifiers 0x%lx\n", key, raw_char,
983 		modifiers);
984 
985 	switch (raw_char) {
986 		case B_SPACE:
987 			PostMessage(M_TOGGLE_NO_BORDER_NO_MENU);
988 			return B_OK;
989 
990 		case B_ESCAPE:
991 			if (fIsFullscreen) {
992 				PostMessage(M_TOGGLE_FULLSCREEN);
993 				return B_OK;
994 			} else
995 				break;
996 
997 		case B_ENTER:		// Enter / Return
998 			if (modifiers & B_COMMAND_KEY) {
999 				PostMessage(M_TOGGLE_FULLSCREEN);
1000 				return B_OK;
1001 			} else
1002 				break;
1003 
1004 		case B_TAB:
1005 			if ((modifiers & (B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY
1006 				| B_MENU_KEY)) == 0) {
1007 				PostMessage(M_TOGGLE_FULLSCREEN);
1008 				return B_OK;
1009 			} else
1010 				break;
1011 
1012 		case B_UP_ARROW:
1013 			if (modifiers & B_COMMAND_KEY) {
1014 				PostMessage(M_CHANNEL_NEXT);
1015 			} else {
1016 				PostMessage(M_VOLUME_UP);
1017 			}
1018 			return B_OK;
1019 
1020 		case B_DOWN_ARROW:
1021 			if (modifiers & B_COMMAND_KEY) {
1022 				PostMessage(M_CHANNEL_PREV);
1023 			} else {
1024 				PostMessage(M_VOLUME_DOWN);
1025 			}
1026 			return B_OK;
1027 
1028 		case B_RIGHT_ARROW:
1029 			if (modifiers & B_COMMAND_KEY) {
1030 				PostMessage(M_VOLUME_UP);
1031 			} else {
1032 				PostMessage(M_CHANNEL_NEXT);
1033 			}
1034 			return B_OK;
1035 
1036 		case B_LEFT_ARROW:
1037 			if (modifiers & B_COMMAND_KEY) {
1038 				PostMessage(M_VOLUME_DOWN);
1039 			} else {
1040 				PostMessage(M_CHANNEL_PREV);
1041 			}
1042 			return B_OK;
1043 
1044 		case B_PAGE_UP:
1045 			PostMessage(M_CHANNEL_NEXT);
1046 			return B_OK;
1047 
1048 		case B_PAGE_DOWN:
1049 			PostMessage(M_CHANNEL_PREV);
1050 			return B_OK;
1051 	}
1052 
1053 	switch (key) {
1054 		case 0x3a:  		// numeric keypad +
1055 			if ((modifiers & B_COMMAND_KEY) == 0) {
1056 				printf("if\n");
1057 				PostMessage(M_VOLUME_UP);
1058 				return B_OK;
1059 			} else {
1060 				printf("else\n");
1061 				break;
1062 			}
1063 
1064 		case 0x25:  		// numeric keypad -
1065 			if ((modifiers & B_COMMAND_KEY) == 0) {
1066 				PostMessage(M_VOLUME_DOWN);
1067 				return B_OK;
1068 			} else {
1069 				break;
1070 			}
1071 
1072 		case 0x38:			// numeric keypad up arrow
1073 			PostMessage(M_VOLUME_UP);
1074 			return B_OK;
1075 
1076 		case 0x59:			// numeric keypad down arrow
1077 			PostMessage(M_VOLUME_DOWN);
1078 			return B_OK;
1079 
1080 		case 0x39:			// numeric keypad page up
1081 		case 0x4a:			// numeric keypad right arrow
1082 			PostMessage(M_CHANNEL_NEXT);
1083 			return B_OK;
1084 
1085 		case 0x5a:			// numeric keypad page down
1086 		case 0x48:			// numeric keypad left arrow
1087 			PostMessage(M_CHANNEL_PREV);
1088 			return B_OK;
1089 	}
1090 
1091 	return B_ERROR;
1092 }
1093 
1094 
1095 void
1096 MainWin::DispatchMessage(BMessage *msg, BHandler *handler)
1097 {
1098 	if ((msg->what == B_MOUSE_DOWN) && (handler == fBackground
1099 		|| handler == fVideoView))
1100 		MouseDown(msg);
1101 	if ((msg->what == B_MOUSE_MOVED) && (handler == fBackground
1102 		|| handler == fVideoView))
1103 		MouseMoved(msg);
1104 	if ((msg->what == B_MOUSE_UP) && (handler == fBackground
1105 		|| handler == fVideoView))
1106 		MouseUp(msg);
1107 
1108 	if ((msg->what == B_KEY_DOWN) && (handler == fBackground
1109 		|| handler == fVideoView)) {
1110 
1111 		// special case for PrintScreen key
1112 		if (msg->FindInt32("key") == B_PRINT_KEY) {
1113 			fVideoView->OverlayScreenshotPrepare();
1114 			BWindow::DispatchMessage(msg, handler);
1115 			fVideoView->OverlayScreenshotCleanup();
1116 			return;
1117 		}
1118 
1119 		// every other key gets dispatched to our KeyDown first
1120 		if (KeyDown(msg) == B_OK) {
1121 			// it got handled, don't pass it on
1122 			return;
1123 		}
1124 	}
1125 
1126 	BWindow::DispatchMessage(msg, handler);
1127 }
1128 
1129 
1130 void
1131 MainWin::MessageReceived(BMessage *msg)
1132 {
1133 	switch (msg->what) {
1134 		case B_ACQUIRE_OVERLAY_LOCK:
1135 			printf("B_ACQUIRE_OVERLAY_LOCK\n");
1136 			fVideoView->OverlayLockAcquire();
1137 			break;
1138 
1139 		case B_RELEASE_OVERLAY_LOCK:
1140 			printf("B_RELEASE_OVERLAY_LOCK\n");
1141 			fVideoView->OverlayLockRelease();
1142 			break;
1143 
1144 		case B_MOUSE_WHEEL_CHANGED:
1145 		{
1146 			printf("B_MOUSE_WHEEL_CHANGED\n");
1147 			float dx = msg->FindFloat("be:wheel_delta_x");
1148 			float dy = msg->FindFloat("be:wheel_delta_y");
1149 			bool inv = modifiers() & B_COMMAND_KEY;
1150 			if (dx > 0.1)	PostMessage(inv ? M_VOLUME_DOWN : M_CHANNEL_PREV);
1151 			if (dx < -0.1)	PostMessage(inv ? M_VOLUME_UP : M_CHANNEL_NEXT);
1152 			if (dy > 0.1)	PostMessage(inv ? M_CHANNEL_PREV : M_VOLUME_DOWN);
1153 			if (dy < -0.1)	PostMessage(inv ? M_CHANNEL_NEXT : M_VOLUME_UP);
1154 			break;
1155 		}
1156 
1157 		case M_CHANNEL_NEXT:
1158 		{
1159 			printf("M_CHANNEL_NEXT\n");
1160 			int chan = fController->CurrentChannel();
1161 			if (chan != -1) {
1162 				chan++;
1163 				if (chan < fController->ChannelCount())
1164 					SelectChannel(chan);
1165 			}
1166 			break;
1167 		}
1168 
1169 		case M_CHANNEL_PREV:
1170 		{
1171 			printf("M_CHANNEL_PREV\n");
1172 			int chan = fController->CurrentChannel();
1173 			if (chan != -1) {
1174 				chan--;
1175 				if (chan >= 0)
1176 					SelectChannel(chan);
1177 			}
1178 			break;
1179 		}
1180 
1181 		case M_VOLUME_UP:
1182 			printf("M_VOLUME_UP\n");
1183 			fController->VolumeUp();
1184 			break;
1185 
1186 		case M_VOLUME_DOWN:
1187 			printf("M_VOLUME_DOWN\n");
1188 			fController->VolumeDown();
1189 			break;
1190 
1191 		case M_ASPECT_100000_1:
1192 			VideoFormatChange(fSourceWidth, fSourceHeight, 1.0, 1.0);
1193 			break;
1194 
1195 		case M_ASPECT_106666_1:
1196 			VideoFormatChange(fSourceWidth, fSourceHeight, 1.06666, 1.0);
1197 			break;
1198 
1199 		case M_ASPECT_109091_1:
1200 			VideoFormatChange(fSourceWidth, fSourceHeight, 1.09091, 1.0);
1201 			break;
1202 
1203 		case M_ASPECT_141176_1:
1204 			VideoFormatChange(fSourceWidth, fSourceHeight, 1.41176, 1.0);
1205 			break;
1206 
1207 		case M_ASPECT_720_576:
1208 			VideoFormatChange(720, 576, 1.06666, 1.0);
1209 			break;
1210 
1211 		case M_ASPECT_704_576:
1212 			VideoFormatChange(704, 576, 1.09091, 1.0);
1213 			break;
1214 
1215 		case M_ASPECT_544_576:
1216 			VideoFormatChange(544, 576, 1.41176, 1.0);
1217 			break;
1218 
1219 		case B_REFS_RECEIVED:
1220 			printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
1221 //			RefsReceived(msg);
1222 			break;
1223 
1224 		case B_SIMPLE_DATA:
1225 			printf("MainWin::MessageReceived: B_SIMPLE_DATA\n");
1226 //			if (msg->HasRef("refs"))
1227 //				RefsReceived(msg);
1228 			break;
1229 
1230 		case M_FILE_ABOUT:
1231 			{
1232 				BString alertStr = fLocalizedName;
1233 				alertStr << "\n\n";
1234 				alertStr << fLocalizedInfo1;
1235 				#if TIME_BOMB_ACTIVE
1236 					alertStr << "\n\n";
1237 					alertStr << INFO2;
1238 				#endif
1239 				alertStr << "\n\nCopyright ";
1240 				alertStr << COPYRIGHT;
1241 				alertStr << B_TRANSLATE("\nVersion ");
1242 				alertStr << VERSION;
1243 				alertStr << B_TRANSLATE("\nRevision ");
1244 				if (strcmp(REVISION, "unknown") == 0)
1245 					alertStr << fLocalizedRevision;
1246 				else
1247 					alertStr << REVISION;
1248 				alertStr << B_TRANSLATE("\nBuild ");
1249 				alertStr << BUILD;
1250 
1251 				BAlert *alert;
1252 				alert = new BAlert("about", alertStr.String(), B_TRANSLATE("OK"));
1253 				if (fAlwaysOnTop) {
1254 					ToggleAlwaysOnTop();
1255 					alert->Go();
1256 					ToggleAlwaysOnTop();
1257 				} else
1258 					alert->Go();
1259 			}
1260 			break;
1261 
1262 		case M_FILE_QUIT:
1263 //			be_app->PostMessage(B_QUIT_REQUESTED);
1264 			PostMessage(B_QUIT_REQUESTED);
1265 			break;
1266 
1267 		case M_SCALE_TO_NATIVE_SIZE:
1268 			printf("M_SCALE_TO_NATIVE_SIZE\n");
1269 			if (fIsFullscreen) {
1270 				ToggleFullscreen();
1271 			}
1272 			ResizeTo(int(fSourceWidth * fWidthScale),
1273 					 int(fSourceHeight * fHeightScale) + (fNoMenu ? 0
1274 					 	: fMenuBarHeight));
1275 //			Sync();
1276 			break;
1277 
1278 		case M_TOGGLE_FULLSCREEN:
1279 			ToggleFullscreen();
1280 			fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
1281 			break;
1282 
1283 		case M_TOGGLE_NO_MENU:
1284 			ToggleNoMenu();
1285 			fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
1286 			break;
1287 
1288 		case M_TOGGLE_NO_BORDER:
1289 			ToggleNoBorder();
1290 			fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
1291 			break;
1292 
1293 		case M_TOGGLE_ALWAYS_ON_TOP:
1294 			ToggleAlwaysOnTop();
1295 			fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
1296 			break;
1297 
1298 		case M_TOGGLE_KEEP_ASPECT_RATIO:
1299 			ToggleKeepAspectRatio();
1300 			fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
1301 			break;
1302 
1303 		case M_TOGGLE_NO_BORDER_NO_MENU:
1304 			ToggleNoBorderNoMenu();
1305 			break;
1306 
1307 		case M_PREFERENCES:
1308 			break;
1309 
1310 		default:
1311 			if (msg->what >= M_SELECT_CHANNEL
1312 				&& msg->what <= M_SELECT_CHANNEL_END) {
1313 				SelectChannel(msg->what - M_SELECT_CHANNEL);
1314 				break;
1315 			}
1316 			if (msg->what >= M_SELECT_INTERFACE
1317 				&& msg->what <= M_SELECT_INTERFACE_END) {
1318 				SelectInterface(msg->what - M_SELECT_INTERFACE - 1);
1319 				break;
1320 			}
1321 	}
1322 }
1323 
1324