📄 mmview.cpp
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA// MmView.cpp : implementation of the MmView class//#include "stdafx.h"#include "ambulant/gui/dx/html_bridge.h"#include "AmbulantPlayer.h"#include "MainFrm.h"#include "MmDoc.h"#include "MmView.h"#include "LogWindow.h"#include "ShowMessage.h"#include <fstream>#include <string>// DX Player#include "ambulant/gui/dx/dx_player.h"#include "ambulant/gui/dx/dx_wmuser.h"// DG Player#include "ambulant/gui/dg/dg_player.h"#include "ambulant/gui/dg/dg_wmuser.h"#include "ambulant/common/preferences.h"#include "ambulant/lib/logger.h"#include "ambulant/lib/textptr.h"#include "ambulant/smil2/test_attrs.h"#include "ambulant/lib/win32/win32_asb.h"#include "ambulant/net/url.h"#include "ambulant/lib/string_util.h"#include "ambulant/version.h"#include "MmView.h"#include "HtmlView.h"#ifdef _DEBUG#define new DEBUG_NEW#endif#ifdef WITHOUT_LOG_WINDOWconst TCHAR log_name[] = TEXT("amlog.txt");static std::string get_log_filename() { TCHAR buf[_MAX_PATH]; GetModuleFileName(NULL, buf, _MAX_PATH); TCHAR *p1 = text_strrchr(buf,'\\'); if(p1 != NULL) *p1='\0'; text_strcat(buf, TEXT("\\")); text_strcat(buf, log_name); return std::string(ambulant::lib::textptr(buf).str());}#endif // WITHOUT_LOG_WINDOWstatic TCHAR *get_directory(const TCHAR *fn) { static TCHAR buf[_MAX_PATH]; buf[0] = 0; text_strcat(buf, fn); TCHAR *p1 = text_strrchr(buf,'\\'); if(p1 != NULL) *p1='\0'; return buf;}#ifdef WITHOUT_LOG_WINDOWstd::ofstream log_os(get_log_filename().c_str());#endifusing namespace ambulant;//#define AM_PLAYER_DG#ifdef AM_PLAYER_DGtypedef gui::dg::dg_player dg_or_dx_player;typedef gui::dg::dg_player_callbacks gui_callbacks;#else typedef gui::dx::dx_player dg_or_dx_player;typedef gui::dx::dx_player_callbacks gui_callbacks;#endif// The handle of the single window instancestatic HWND s_hwnd;class html_browser;// A class with callbacks, also instantiated onceclass my_player_callbacks : public gui_callbacks { public: HWND new_os_window(); void destroy_os_window(HWND hwnd); html_browser *new_html_browser(int left, int top, int width, int height);};my_player_callbacks s_player_callbacks;HWNDmy_player_callbacks::new_os_window() { // Return the handle of the single instance for now // This means paint bits of the new window // to the single instance return s_hwnd;}voidmy_player_callbacks::destroy_os_window(HWND hwnd) { // none for now; keep the single instance}html_browser *my_player_callbacks::new_html_browser(int left, int top, int width, int height){ return ::new_html_browser(left, top, width, height);}class my_player_feedback : public common::player_feedback { public: void document_loaded(lib::document *doc) {} void document_started() { set_status_line("Playing"); } void document_stopped() { set_status_line("Stopped"); } void node_started(const lib::node *n) {}; void node_stopped(const lib::node *n) {}; void node_focussed(const lib::node *n) { if (n == NULL) { set_status_line(""); return; } const char *alt = n->get_attribute("alt"); if (alt) { set_status_line(alt); return; } const char *href = n->get_attribute("href"); if (href) { static std::string msg; msg = "Go to "; msg += href; set_status_line(msg.c_str()); return; } set_status_line(""); } };my_player_feedback s_player_feedback;static dg_or_dx_player* create_player_instance(const net::url& u, common::player_feedback *feedback) { return new dg_or_dx_player(s_player_callbacks, feedback, u);}static dg_or_dx_player *player = 0;static needs_done_redraw = false;CWnd* topView = NULL; // MmViewIMPLEMENT_DYNCREATE(MmView, CView)BEGIN_MESSAGE_MAP(MmView, CView) ON_WM_DESTROY() ON_COMMAND(ID_FILE_PLAY, OnFilePlay) ON_UPDATE_COMMAND_UI(ID_FILE_PLAY, OnUpdateFilePlay) ON_COMMAND(ID_FILE_PAUSE, OnFilePause) ON_UPDATE_COMMAND_UI(ID_FILE_PAUSE, OnUpdateFilePause) ON_COMMAND(ID_FILE_STOP, OnFileStop) ON_UPDATE_COMMAND_UI(ID_FILE_STOP, OnUpdateFileStop) ON_WM_TIMER() ON_WM_CREATE() ON_WM_LBUTTONDOWN() ON_WM_CHAR() ON_COMMAND(ID_PLAY_ADVANCEFOCUS, OnFocusAdvance) ON_COMMAND(ID_PLAY_ACTIVATEFOCUS, OnFocusActivate) ON_COMMAND(ID_VIEW_SOURCE, OnViewSource) ON_UPDATE_COMMAND_UI(ID_VIEW_SOURCE, OnUpdateViewSource) ON_UPDATE_COMMAND_UI(ID_VIEW_LOG, OnUpdateViewLog) ON_COMMAND(ID_VIEW_LOG, OnViewLog) ON_MESSAGE(WM_SET_CLIENT_RECT, OnSetClientRect) ON_COMMAND(ID_VIEW_TESTS, OnOpenFilter) ON_COMMAND(ID_VIEW_FILTER, OnViewFilter) ON_UPDATE_COMMAND_UI(ID_VIEW_FILTER, OnUpdateViewFilter) ON_WM_MOUSEMOVE() ON_UPDATE_COMMAND_UI(ID_VIEW_TESTS, OnUpdateOpenFilter) ON_COMMAND(ID_VIEW_AUTOPLAY, OnViewAutoplay) ON_UPDATE_COMMAND_UI(ID_VIEW_AUTOPLAY, OnUpdateViewAutoplay) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) ON_COMMAND(ID_HELP_WELCOME, OnHelpWelcome) ON_UPDATE_COMMAND_UI(ID_HELP_WELCOME, OnUpdateHelpWelcome) ON_MESSAGE(WM_REPLACE_DOC, OnReplaceDoc)END_MESSAGE_MAP()// MmView construction/destructionMmView::MmView():#ifndef WITHOUT_LOG_WINDOW m_logwindow(NULL),#endif // WITHOUT_LOG_WINDOW m_timer_id(0), m_cursor_id(0), m_autoplay(true){ lib::logger::get_logger()->set_show_message(log_show_message);#ifdef WITHOUT_LOG_WINDOW lib::logger::get_logger()->set_std_ostream(log_os);#else lib::logger::get_logger()->set_ostream(new logwindow_ostream());#endif // WITHOUT_LOG_WINDOW lib::logger::get_logger()->debug(gettext("Ambulant Player: compile time version %s, runtime version %s"), AMBULANT_VERSION, ambulant::get_version()); lib::logger::get_logger()->debug(gettext("Ambulant Player: built on %s for Windows/MFC"), __DATE__);#if ENABLE_NLS lib::logger::get_logger()->debug(gettext("Ambulant Player: localization enabled (english)"));#endif#ifdef AMBULANT_USE_DLL lib::logger::get_logger()->debug(gettext("Ambulant Player: using AmbulantPlayer in DLL"));#endif#ifdef AM_PLAYER_DG lib::logger::get_logger()->debug("Ambulant Player: using DG Player");#else lib::logger::get_logger()->debug("Ambulant Player: using DX Player");#endif topView = this;}MmView::~MmView(){ topView = NULL;}BOOL MmView::PreCreateWindow(CREATESTRUCT& cs){ // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style |= WS_CLIPCHILDREN; // reduce flicker return CView::PreCreateWindow(cs);}// MmView drawingvoid MmView::OnDraw(CDC* pDC){ MmDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here if(player) player->redraw(m_hWnd, pDC->m_hDC); }// MmView diagnostics#ifdef _DEBUGvoid MmView::AssertValid() const{ CView::AssertValid();}void MmView::Dump(CDumpContext& dc) const{ CView::Dump(dc);}MmDoc* MmView::GetDocument() const // non-debug version is inline{ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(MmDoc))); return (MmDoc*)m_pDocument;}#endif //_DEBUG// MmView message handlersint MmView::OnCreate(LPCREATESTRUCT lpCreateStruct){ if (CView::OnCreate(lpCreateStruct) == -1) return -1; m_timer_id = SetTimer(1, 500, 0); // Set static handle s_hwnd = GetSafeHwnd(); ModifyStyle(0, WS_CLIPCHILDREN); // reduce flicker if(LocateWelcomeDoc(TEXT("..\\..\\Extras\\Welcome\\Welcome.smil")) || LocateWelcomeDoc(TEXT("Extras\\Welcome\\Welcome.smil")) || LocateWelcomeDoc(TEXT("Welcome.smil"))){;} PostMessage(WM_SET_CLIENT_RECT, common::default_layout_width, ambulant::common::default_layout_height); CWinApp* pApp = AfxGetApp(); CString val = pApp->GetProfileString(_T("Settings"), _T("Welcome")); if(val.IsEmpty()) { // first time; write the string and play welcome pApp->WriteProfileString(_T("Settings"), _T("Welcome"), _T("1")); if(!m_welcomeDocFilename.IsEmpty()) PostMessage(WM_COMMAND, ID_HELP_WELCOME); } return 0;}void MmView::OnInitialUpdate(){ CView::OnInitialUpdate();}void MmView::OnDestroy(){ if(player) { player->stop(); delete player; player = 0; } if(m_timer_id) KillTimer(m_timer_id); CView::OnDestroy();}void MmView::SetMMDocument(LPCTSTR lpszPathName, bool autostart) { USES_CONVERSION; dg_or_dx_player *dummy = player; player = 0; if(dummy) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -