📄 ceditwnd.cpp
字号:
// $Id: CEditWnd.cpp,v 1.90 2005/04/23 00:15:52 genta Exp $
/*! @file
@brief 編集ウィンドウ(外枠)管理クラス
@author Norio Nakatani
$Revision: 1.90 $
*/
/*
Copyright (C) 1998-2001, Norio Nakatani
Copyright (C) 2000-2001, genta, jepro
Copyright (C) 2001, mik, hor
Copyright (C) 2002, YAZAKI, genta, aroka, MIK
Copyright (C) 2003, MIK, wmlhq, ryoji
This source code is designed for sakura editor.
Please contact the copyright holders to use this code for other purpose.
*/
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
#include <io.h>
#include <mbctype.h>
#include <mbstring.h>
#include "CEditApp.h"
#include "CEditWnd.h"
#include "sakura_rc.h"
#include "CEditDoc.h"
#include "debug.h"
#include "CDlgAbout.h"
#include "mymessage.h"
#include "CShareData.h"
#include "CPrint.h"
#include "etc_uty.h"
#include "charcode.h"
#include "global.h"
#include "CDlgPrintSetting.h"
#include "CDlgPrintPage.h"
#include "funccode.h" // Stonee, 2001/03/12
#include "CPrintPreview.h" /// 2002/2/3 aroka
#include "CMarkMgr.h" /// 2002/2/3 aroka
#include "CCommandLine.h" /// 2003/1/26 aroka
#include "CSMacroMgr.h" // Jun. 16, 2002 genta
#include "COsVersioninfo.h" // Sep. 6, 2003 genta
#include "CRunningTimer.h"
#define IDT_TOOLBAR 456
#define ID_TOOLBAR 100
//@@@ 2002.01.14 YAZAKI 印刷プレビューをCPrintPreviewに独立させたので
// 定義を削除
#ifndef TBSTYLE_ALTDRAG
#define TBSTYLE_ALTDRAG 0x0400
#endif
#ifndef TBSTYLE_FLAT
#define TBSTYLE_FLAT 0x0800
#endif
#ifndef TBSTYLE_LIST
#define TBSTYLE_LIST 0x1000
#endif
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#endif
#define YOHAKU_X 4 /* ウィンドウ内の枠と紙の隙間最小値 */
#define YOHAKU_Y 4 /* ウィンドウ内の枠と紙の隙間最小値 */
//@@@ 2002.01.14 YAZAKI 印刷プレビューをCPrintPreviewに独立させたので
// 定義を削除
// /* メッセージループ */
// DWORD MessageLoop_Thread( DWORD pCEditWndObject );
LRESULT CALLBACK CEditWndProc(
HWND hwnd, // handle of window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
CEditWnd* pSEWnd;
// Modified by KEITA for WIN64 2003.9.6
pSEWnd = ( CEditWnd* )::GetWindowLongPtr( hwnd, GWLP_USERDATA );
if( NULL != pSEWnd ){
return pSEWnd->DispatchEvent( hwnd, uMsg, wParam, lParam );
}
return ::DefWindowProc( hwnd, uMsg, wParam, lParam );
}
/*
|| タイマーメッセージのコールバック関数
||
|| ツールバーの状態更新のためにタイマーを使用しています
*/
VOID CALLBACK CEditWndTimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
CEditWnd* pCEdit;
// Modified by KEITA for WIN64 2003.9.6
pCEdit = ( CEditWnd* )::GetWindowLongPtr( hwnd, GWLP_USERDATA );
if( NULL != pCEdit ){
pCEdit->OnTimer( hwnd, uMsg, idEvent, dwTime );
}
return;
}
//by 鬼(2)
void CALLBACK SysMenuTimer(HWND Wnd, UINT Msg, UINT_PTR Event, DWORD Time)
{
CEditWnd *WndObj;
// Modified by KEITA for WIN64 2003.9.6
WndObj = (CEditWnd*)GetWindowLongPtr(Wnd, GWLP_USERDATA);
if(WndObj != NULL)
WndObj->OnSysMenuTimer();
KillTimer(Wnd, Event);
}
// @date 2002.2.17 YAZAKI CShareDataのインスタンスは、CProcessにひとつあるのみ。
CEditWnd::CEditWnd() :
m_hWnd( NULL ),
m_bDragMode( FALSE ),
m_hwndParent( NULL ),
m_hwndToolBar( NULL ),
m_hwndStatusBar( NULL ),
m_hwndProgressBar( NULL ),
m_hdcCompatDC( NULL ), /* 再描画用コンパチブルDC */
m_hbmpCompatBMP( NULL ), /* 再描画用メモリBMP */
m_hbmpCompatBMPOld( NULL ), /* 再描画用メモリBMP(OLD) */
// 20020331 aroka 再変換対応 for 95/NT
m_uMSIMEReconvertMsg( ::RegisterWindowMessage( RWM_RECONVERT ) ),
m_uATOKReconvertMsg( ::RegisterWindowMessage( MSGNAME_ATOK_RECONVERT ) ),
//@@@ 2002.01.14 YAZAKI 印刷プレビューをCPrintPreviewに独立させたことによる変更
m_pPrintPreview( NULL ),
m_pszAppName( GSTR_EDITWINDOWNAME ),
m_hwndSearchBox( NULL ),
m_fontSearchBox( NULL ),
m_nCurrentFocus( 0 ),
m_IconClicked(icNone) //by 鬼(2)
{
// Dec. 4, 2002 genta
InitMenubarMessageFont();
// Sep. 10, 2002 genta
m_cEditDoc.m_pcEditWnd = this;
/* 共有データ構造体のアドレスを返す */
m_pShareData = CShareData::getInstance()->GetShareData();
// MYTRACE( "CEditWnd::CEditWnd()おわり\n" );
return;
}
CEditWnd::~CEditWnd()
{
// Dec. 4, 2002 genta
/* キャレットの行桁位置表示用フォント */
::DeleteObject( m_hFontCaretPosInfo );
/* 再描画用メモリBMP */
if( m_hbmpCompatBMP != NULL ){
/* 再描画用メモリBMP(OLD) */
::SelectObject( m_hdcCompatDC, m_hbmpCompatBMPOld );
::DeleteObject( m_hbmpCompatBMP );
}
/* 再描画用コンパチブルDC */
if( m_hdcCompatDC != NULL ){
::DeleteDC( m_hdcCompatDC );
}
if( NULL != m_hWnd ){
m_hWnd = NULL;
}
return;
}
/*! 作成
@param hInstance [in] Instance Handle
@param hwndParent [in] 親ウィンドウのハンドル
@param pszPath [in] 最初に開くファイルのパス.NULLのとき開くファイル無し.
@param nCharCode [in] 漢字コード
@param bReadOnly [in] 読みとり専用で開くかどうか
@param nDocumentType [in] 文書タイプ.-1のとき強制指定無し.
@date 2002.03.07 genta nDocumentType追加
*/
HWND CEditWnd::Create(
HINSTANCE hInstance,
HWND hwndParent,
const char* pszPath,
int nCharCode,
BOOL bReadOnly,
int nDocumentType
)
{
MY_RUNNINGTIMER( cRunningTimer, "CEditWnd::Create" );
// Dec. 6, 2002 genta
// small icon指定のため RegisterClassExに変更
WNDCLASSEX wc;
HWND hWnd;
ATOM atom;
BOOL bOpened;
char szMsg[512];
if( m_pShareData->m_nEditArrNum >= MAX_EDITWINDOWS ){ //最大値修正 //@@@ 2003.05.31 MIK
wsprintf( szMsg, "編集ウィンドウ数の上限は%dです。\nこれ以上は同時に開けません。", MAX_EDITWINDOWS );
::MessageBox( NULL, szMsg, GSTR_APPNAME, MB_OK );
return NULL;
}
m_hInstance = hInstance;
m_hwndParent = hwndParent;
// Apr. 27, 2000 genta
// サイズ変更時のちらつきを抑えるためCS_HREDRAW | CS_VREDRAW を外した
wc.style = CS_DBLCLKS | CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
wc.lpfnWndProc = CEditWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 32;
wc.hInstance = m_hInstance;
// Dec, 2, 2002 genta アイコン読み込み方法変更
wc.hIcon = GetAppIcon( m_hInstance, ICON_DEFAULT_APP, FN_APP_ICON, false );
wc.hCursor = NULL/*LoadCursor( NULL, IDC_ARROW )*/;
wc.hbrBackground = (HBRUSH)NULL/*(COLOR_3DSHADOW + 1)*/;
wc.lpszMenuName = MAKEINTRESOURCE( IDR_MENU1 );
wc.lpszClassName = m_pszAppName;
// Dec. 6, 2002 genta
// small icon指定のため RegisterClassExに変更
wc.cbSize = sizeof( wc );
wc.hIconSm = GetAppIcon( m_hInstance, ICON_DEFAULT_APP, FN_APP_ICON, true );
if( 0 == ( atom = RegisterClassEx( &wc ) ) ){
// 2004.05.13 Moca return NULLを有効にした
return NULL;
}
/* ウィンドウサイズ継承 */
int nWinCX, nWinCY;
// 2004.05.13 Moca m_Common.m_nSaveWindowSizeをBOOLからenumに変えたため
if( WINSIZEMODE_DEF != m_pShareData->m_Common.m_nSaveWindowSize ){
nWinCX = m_pShareData->m_Common.m_nWinSizeCX;
nWinCY = m_pShareData->m_Common.m_nWinSizeCY;
}else{
nWinCX = CW_USEDEFAULT;
nWinCY = 0;
}
/* ウィンドウサイズ指定 */
FileInfo fi;
CCommandLine::Instance()->GetFileInfo(fi);
if( fi.m_nWindowSizeX >= 0 ){
nWinCX = fi.m_nWindowSizeX;
}
if( fi.m_nWindowSizeY >= 0 ){
nWinCY = fi.m_nWindowSizeY;
}
/* ウィンドウ位置指定 */
int nWinOX, nWinOY;
nWinOX = CW_USEDEFAULT;
nWinOY = 0;
// ウィンドウ位置固定
// 2004.05.13 Moca 保存したウィンドウ位置を使う場合は共有メモリからセット
if( WINSIZEMODE_DEF != m_pShareData->m_Common.m_nSaveWindowPos ){
nWinOX = m_pShareData->m_Common.m_nWinPosX;
nWinOY = m_pShareData->m_Common.m_nWinPosY;
}
// 2004.05.13 Moca マルチディスプレイでは負の値も有効なので,
// 未設定の判定方法を変更.(負の値→CW_USEDEFAULT)
if( fi.m_nWindowOriginX != CW_USEDEFAULT ){
nWinOX = fi.m_nWindowOriginX;
}
if( fi.m_nWindowOriginY != CW_USEDEFAULT ){
nWinOY = fi.m_nWindowOriginY;
}
//From Here @@@ 2003.05.31 MIK
//タブウインドウの場合は現状値を指定
if( m_pShareData->m_Common.m_bDispTabWnd
&& m_pShareData->m_TabWndWndpl.length
&& m_pShareData->m_Common.m_bDispTabWndMultiWin == FALSE )
{
// Sep. 11, 2003 MIK 新規TABウィンドウの位置が上にずれないように
RECT rcArea;
::SystemParametersInfo( SPI_GETWORKAREA, NULL, &rcArea, 0 );
nWinCX = m_pShareData->m_TabWndWndpl.rcNormalPosition.right
- m_pShareData->m_TabWndWndpl.rcNormalPosition.left;
nWinCY = m_pShareData->m_TabWndWndpl.rcNormalPosition.bottom
- m_pShareData->m_TabWndWndpl.rcNormalPosition.top;
nWinOX = m_pShareData->m_TabWndWndpl.rcNormalPosition.left + rcArea.left;
nWinOY = m_pShareData->m_TabWndWndpl.rcNormalPosition.top + rcArea.top;
}
//To Here @@@ 2003.05.31 MIK
hWnd = ::CreateWindowEx(
0 // extended window style
// | WS_EX_CLIENTEDGE
,
m_pszAppName, // pointer to registered class name
m_pszAppName, // pointer to window name
// WS_VISIBLE |
WS_OVERLAPPEDWINDOW |
WS_CLIPCHILDREN |
// WS_HSCROLL | WS_VSCROLL |
0, // window style
nWinOX, // horizontal position of window
nWinOY, // vertical position of window
nWinCX, // window width
nWinCY, // window height
NULL, // handle to parent or owner window
NULL, // handle to menu or child-window identifier
m_hInstance, // handle to application instance
NULL // pointer to window-creation data
);
m_hWnd = hWnd;
// 2004.05.13 Moca ウィンドウ作成失敗。終了
if( NULL == hWnd ){
return NULL;
}
m_cIcons.Create( m_hInstance, m_hWnd ); // CreateImage List
m_CMenuDrawer.Create( m_hInstance, m_hWnd, &m_cIcons );
// if( NULL != m_hWnd ){
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr( m_hWnd, GWLP_USERDATA, (LONG_PTR)this );
/* 再描画用コンパチブルDC */
HDC hdc = ::GetDC( m_hWnd );
m_hdcCompatDC = ::CreateCompatibleDC( hdc );
::ReleaseDC( m_hWnd, hdc );
// }
if( m_pShareData->m_Common.m_bDispTOOLBAR ){ /* 次回ウィンドウを開いたときツールバーを表示する */
/* ツールバー作成 */
CreateToolBar();
}
/* ステータスバー */
if( m_pShareData->m_Common.m_bDispSTATUSBAR ){ /* 次回ウィンドウを開いたときステータスバーを表示する */
/* ステータスバー作成 */
CreateStatusBar();
}
/* ファンクションキー バー */
if( m_pShareData->m_Common.m_bDispFUNCKEYWND ){ /* 次回ウィンドウを開いたときファンクションキーを表示する */
BOOL bSizeBox;
if( m_pShareData->m_Common.m_nFUNCKEYWND_Place == 0 ){ /* ファンクションキー表示位置/0:上 1:下 */
bSizeBox = FALSE;
}else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -