⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvframe.cpp

📁 俄罗斯人开发的大名鼎鼎的Pocket Pc 阅读器haaliread的源代码,visual c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 2001,2002,2003 Mike Matsnev.  All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice immediately at the beginning of the file, without modification,
 *    this list of conditions, and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Absolutely no warranty of function or purpose is made by the author
 *    Mike Matsnev.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * $Id: TVFrame.cpp,v 1.75.2.20 2004/11/01 11:15:10 mike Exp $
 * 
 */

#include <afxcmn.h>
#include <afxtempl.h>
#include <afxext.h>

#include "resource.h"

#include "ptr.h"
#include "Unicode.h"
#include "TextViewNG.h"
#include "TVFrame.h"
#include "FileOpenDialog.h"
#include "DummyView.h"
#include "XMLParser.h"
#include "Keys.h"
#include "TextFile.h"
#include "TextFormatter.h"
#include "Rotate.h"
#include "TView.h"
#include "config.h"
#include "DictSetupDlg.h"
#include "Colors.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define	MSG_OPEN_FILE (WM_APP+1)

#define	MAXTTSIZE     128

/////////////////////////////////////////////////////////////////////////////
// CTVFrame

IMPLEMENT_DYNAMIC(CTVFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CTVFrame, CFrameWnd)
//{{AFX_MSG_MAP(CTVFrame)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_FULLSCREEN, OnFullscreen)
ON_UPDATE_COMMAND_UI(ID_FULLSCREEN, OnUpdateFullscreen)
ON_WM_ACTIVATE()
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_INIT, OnInitView)
ON_WM_COPYDATA()
ON_UPDATE_COMMAND_UI(ID_MAIN_TOOLS, OnUpdateMainTools)
ON_UPDATE_COMMAND_UI(ID_MAIN_OPTIONS, OnUpdateMainOptions)
ON_WM_INITMENUPOPUP()
ON_WM_SIZE()
ON_WM_MOVE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(RECENT_BASE,RECENT_BASE+RECENT_FILES,OnRecentFile)
ON_UPDATE_COMMAND_UI_RANGE(RECENT_BASE,RECENT_BASE+RECENT_FILES,OnUpdateRecentFile)
ON_MESSAGE(MSG_OPEN_FILE,OnOpenFile)
#ifdef WM_POWERBROADCAST
ON_MESSAGE(WM_POWERBROADCAST,OnPower)
#endif
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTVFrame construction/destruction

CTVFrame::CTVFrame() : m_fullscreen(false), m_in_fullscreen(0),
  m_realview(false), m_tooltips(NULL), m_buttoncount(0),
  m_okstate(false)
{
  m_wndView=new DummyView;
  m_toptime.dwLowDateTime=m_toptime.dwHighDateTime=0;
  m_tooltips=NULL;
  m_buttoncount=0;
#ifndef _WIN32_WCE
  m_mainmenu=NULL;
  memset(&m_wndpos,0,sizeof(m_wndpos));
#endif
}

CTVFrame::~CTVFrame() {
  for (int i=0;i<m_buttoncount;++i)
    delete[] m_tooltips[i];
  delete[] m_tooltips;
#ifndef _WIN32_WCE
  delete m_mainmenu;
  if (m_wndpos.length)
    AfxGetApp()->WriteProfileBinary(_T("Parameters"),_T("WindowPos"),(LPBYTE)&m_wndpos,sizeof(m_wndpos));
#endif
}

int CTVFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
  if (!m_wndView->Create(NULL, NULL, WS_VISIBLE, // XXX
    CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
  {
    TRACE0("Failed to create view window\n");
    return -1;
  }

#if POCKETPC
  m_wndCommandBar.m_bShowSharedNewButton = FALSE;
#endif

#ifdef _WIN32_WCE
  if(!m_wndCommandBar.Create(this) ||
     !m_wndCommandBar.LoadToolBar(cIDR_MAINFRAME)
     || !m_wndCommandBar.AddAdornments())
#else
  if(!m_wndCommandBar.CreateEx(this,TBSTYLE_FLAT) ||
     !m_wndCommandBar.LoadToolBar(IDR_MAINFRAME))
#endif
  {
    TRACE0("Failed to create CommandBar\n");
    return -1;      // fail to create
  }

#ifdef _WIN32_WCE
  // now add tooltips
  CToolBarCtrl&	  tbc=m_wndCommandBar.GetToolBarCtrl();
  m_buttoncount=tbc.GetButtonCount();
  m_tooltips=new TCHAR*[m_buttoncount];
  TBBUTTON  tb;
  TCHAR	    buf[MAXTTSIZE];
  for (int i=0;i<m_buttoncount;++i) {
    tbc.GetButton(i,&tb);
    int len=LoadString(AfxGetResourceHandle(),tb.idCommand,buf,MAXTTSIZE);
    m_tooltips[i]=new TCHAR[len+1];
    memcpy(m_tooltips[i],buf,len*sizeof(TCHAR));
    m_tooltips[i][len]=_T('\0');
  }
  m_wndCommandBar.SendMessage(TB_SETTOOLTIPS,m_buttoncount,(LPARAM)m_tooltips);
  m_wndCommandBar.SetBarStyle(m_wndCommandBar.GetBarStyle() | CBRS_TOOLTIPS);
#endif

  GetWindowRect(&m_normsize);

#if BE300
  HWND hSQWnd=::FindWindow(_T("SQ Tray"),NULL);
  m_fSQTray= hSQWnd && GetWindowLong(hSQWnd,GWL_STYLE)&WS_VISIBLE;
#endif

  m_recent=CreatePopupMenu();
  m_dicts=CreatePopupMenu();
  CMenu	*main=new CMenu;
  if (main) {
    main->LoadMenu(IDR_MAINFRAME);
    CMenu   *sub=main->GetSubMenu(0);
    if (sub)
      sub->InsertMenu(ID_FILE_OPEN,MF_BYCOMMAND|MF_POPUP,(UINT)m_recent,_T("Recent Files"));
    sub=main->GetSubMenu(1);
    if (sub) {
      m_colors = sub->GetSubMenu(5)->Detach();
      sub->InsertMenu(ID_MISCOPT,MF_BYCOMMAND|MF_POPUP,(UINT)m_dicts,_T("Dictionaries"));
    }
#ifdef _WIN32_WCE
    SetMenu(main);
#else
    m_mainmenu=main;
    SetMenu(NULL);
#endif
  }

  return 0;
}

void  CTVFrame::InitWindowPos(int nCmdShow) {
#ifdef _WIN32_WCE
  ShowWindow(nCmdShow);
#else
  UINT	  sz;
  LPBYTE  buffer=NULL;
  if (AfxGetApp()->GetProfileBinary(_T("Parameters"),_T("WindowPos"),&buffer,&sz) &&
      sz==sizeof(m_wndpos) && buffer)
  {
    memcpy(&m_wndpos,buffer,sizeof(m_wndpos));
    ::SetWindowPlacement(m_hWnd,&m_wndpos);
  } else
    ShowWindow(nCmdShow);
  delete[] buffer;
#endif
}

/////////////////////////////////////////////////////////////////////////////
// CTVFrame diagnostics



/////////////////////////////////////////////////////////////////////////////
// CTVFrame message handlers
void CTVFrame::OnSetFocus(CWnd* pOldWnd) {
  // forward focus to the view window
  if (m_wndView.get() && m_wndView->m_hWnd)
    m_wndView->SetFocus();
}

BOOL CTVFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
  // let the view have first crack at the command
  if (m_wndView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    return TRUE;

  // otherwise, do default handling
  return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

void CTVFrame::DoFullScreen(bool fs)
{
  if (m_in_fullscreen)
    return;
  m_in_fullscreen++;
  if (fs) {
#ifdef _WIN32_WCE
#if POCKETPC
    SHSipPreference(m_hWnd,SIP_FORCEDOWN);
    SHFullScreen(m_hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
#else
    HWND  hTaskBar=::FindWindow(_T("HHTaskBar"),NULL);
    if (hTaskBar)
      ::ShowWindow(hTaskBar,SW_HIDE);
#if BE300
    if (m_fSQTray) {
      hTaskBar=::FindWindow(_T("SQ Tray"),NULL);
      if (hTaskBar)
	::ShowWindow(hTaskBar,SW_HIDE);
    }
#endif
#endif
#else
    ::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
    ModifyStyle(WS_CAPTION|WS_THICKFRAME,0,SWP_FRAMECHANGED);
#endif
    m_wndCommandBar.ShowWindow(SW_HIDE);
    ::SetWindowPos(m_hWnd,NULL,0,0,
      GetSystemMetrics(SM_CXSCREEN),
      GetSystemMetrics(SM_CYSCREEN),
      SWP_NOZORDER|SWP_NOACTIVATE);
  } else {
#ifdef _WIN32_WCE
#if POCKETPC
    SHFullScreen(m_hWnd,SHFS_SHOWTASKBAR|SHFS_SHOWSIPBUTTON);
#else
    HWND  hTaskBar=::FindWindow(_T("HHTaskBar"),NULL);
    if (hTaskBar)
      ::ShowWindow(hTaskBar,SW_SHOW);
#if BE300
    if (m_fSQTray) {
      hTaskBar=::FindWindow(_T("SQ Tray"),NULL);
      if (hTaskBar)
	::ShowWindow(hTaskBar,SW_SHOW);
    }
#endif
#endif
#else
    ::SetWindowPos(m_hWnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
    ModifyStyle(0,WS_CAPTION|WS_THICKFRAME,SWP_FRAMECHANGED);
#endif
#ifdef _WIN32_WCE
    m_wndCommandBar.ShowWindow(SW_SHOWNA);
#else
    m_wndCommandBar.ShowWindow(SW_SHOW);
#endif
#if POCKETPC
    RECT	rcw;
    SystemParametersInfo(SPI_GETWORKAREA,0,&rcw,0);
    ::SetWindowPos(m_hWnd,NULL,
      rcw.left,rcw.top,
      rcw.right,rcw.bottom,
      SWP_NOZORDER|SWP_NOACTIVATE);
#else
    ::SetWindowPos(m_hWnd,NULL,
      m_normsize.left,m_normsize.top,
      m_normsize.right-m_normsize.left,m_normsize.bottom-m_normsize.top,
      SWP_NOZORDER|SWP_NOACTIVATE);
#endif
  }
  m_in_fullscreen--;
}

void CTVFrame::OnFullscreen()
{
  m_fullscreen=!m_fullscreen;
  DoFullScreen(m_fullscreen);
}

void CTVFrame::OnUpdateFullscreen(CCmdUI* pCmdUI)
{
  pCmdUI->SetCheck(m_fullscreen);
  pCmdUI->Enable();
}

void CTVFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
  CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
  if (nState==WA_ACTIVE || nState==WA_CLICKACTIVE) {
    DoFullScreen(m_fullscreen);
    // this hack is needed for CE 2.x and HPC 2k because I am too lazy to find out
    // what's wrong with focus setting
    if (m_wndView.get() && m_wndView->m_hWnd) { // always focus view when we are activated
      m_wndView->SetFocus();
      Keys::SetWindow(m_wndView->m_hWnd);
    }
  } else { // we should really remove fullscreen when the frame is deactivated
    // haha fun, this isnt called under emulation, so take care
    DoFullScreen(false);
    Keys::SetWindow(0);
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -