/*
MPlayer Gui for win32
Copyright (c) 2003 Sascha Sommer <saschasommer@freenet.de>
Copyright (c) 2006 Erik Augustson <erik_27can@yahoo.com>
Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <windows.h>
#include <windowsx.h>
#include <shlobj.h>
#include <version.h>
#include <mplayer.h>
#include <mp_msg.h>
#include <help_mp.h>
#include <cpudetect.h>
#include <input/input.h>
#include <input/mouse.h>
#include <osdep/keycodes.h>
#include <libmpdemux/stream.h>
#include <libvo/video_out.h>
#include <interface.h>
#include "gui.h"
#include "wincfg.h"
#include "dialogs.h"
// HACK around bug in old mingw
#undef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#ifndef WM_XBUTTONDOWN
# define WM_XBUTTONDOWN 0x020B
# define WM_XBUTTONUP 0x020C
# define WM_XBUTTONDBLCLK 0x020D
#endif
#define MP_TITLE "MPlayer " VERSION " (C) 2000-2006 MPlayer Team"
/* Globals / Externs */
extern void renderinfobox(skin_t *skin, window_priv_t *priv);
extern void renderwidget(skin_t *skin, image *dest, widget *item, int state);
extern void mplayer_put_key(int code);
extern int WinID;
float sub_aspect;
DWORD oldtime;
NOTIFYICONDATA nid;
int console_state = 0;
/* Sub window stuff */
static HBRUSH colorbrush = NULL; //Handle to colorkey brush
static COLORREF windowcolor = RGB(0,0,16); //Windowcolor == colorkey
/* vo_gl includes vo_init in w32_common.c, without gl this file is not included */
#if !defined(GL_WIN32) && !defined(HAVE_GL)
int vo_init(void)
{
mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] dummy vo_init()\n");
return 1;
}
#endif
void console_toggle(void)
{
if (console_state)
{
FreeConsole();
console = 0;
console_state = 0;
}
else
{
/* This code comes from: http://dslweb.nwnexus.com/~ast/dload/guicon.htm */
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
HWND hwnd = NULL;
console = 1;
AllocConsole();
SetConsoleTitle(MP_TITLE);
/* disable the close button for now */
while (!hwnd)
{
hwnd = FindWindow(NULL, MP_TITLE);
Sleep(100);
}
DeleteMenu(GetSystemMenu(hwnd, 0), SC_CLOSE, MF_BYCOMMAND);
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = 1000;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
fp = freopen("con", "w", stdout);
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
fp = freopen("con", "r", stdin);
*stdin = *fp;
setvbuf(stdin, NULL, _IONBF, 0);
fp = freopen("con", "w", stdout);
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s\n", MP_TITLE);
GetCpuCaps(&gCpuCaps);
#if defined(ARCH_X86) || defined(ARCH_X86_64)
mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
gCpuCaps.hasMMX, gCpuCaps.hasMMX2,
gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
#ifdef RUNTIME_CPUDETECT
mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);
#else
mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);
#ifdef HAVE_MMX
mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");
#endif
#ifdef HAVE_MMX2
mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");
#endif
#ifdef HAVE_3DNOW
mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");
#endif
#ifdef HAVE_3DNOWEX
mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");
#endif
#ifdef HAVE_SSE
mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");
#endif
#ifdef HAVE_SSE2
mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");
#endif
mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");
#endif
#endif
console_state = 1;
}
}
void capitalize(char *filename)
{
unsigned int i;
BOOL cap = TRUE;
for (i=0; i < strlen(filename); i++)
{
if (cap)
{
cap = FALSE;
filename[i] = toupper(filename[i]);
}
else if (filename[i] == ' ')
cap = TRUE;
else
filename[i] = tolower(filename[i]);
}
}
static image *get_drawground(HWND hwnd)
{
gui_t * gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
unsigned int i;
if(!gui) return NULL;
for(i=0; i<gui->window_priv_count; i++)
if(gui->window_priv[i]->hwnd==hwnd)
return &gui->window_priv[i]->img;
return NULL;
}
static HBITMAP get_bitmap(HWND hwnd)
{
gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
unsigned int i;
if(!gui) return NULL;
for(i=0; i<gui->window_priv_count; i++)
if(gui->window_priv[i]->hwnd == hwnd)
return gui->window_priv[i]->bitmap;
return NULL;
}
static int get_windowtype(HWND hwnd)
{
gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA
|