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

📄 csplitterwnd.cpp

📁 日本的开源编辑器源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//	$Id: CSplitterWnd.cpp,v 1.12 2003/09/19 16:41:18 genta Exp $
/*!	@file
	@brief 分割線ウィンドウクラス

	@author Norio Nakatani
	@date 1998/07/07 新規作成
	@date 2002/2/3 aroka 未使用コード除去
	$Revision: 1.12 $
*/
/*
	Copyright (C) 1998-2001, Norio Nakatani
	Copyright (C) 2002, aroka

	This source code is designed for sakura editor.
	Please contact the copyright holder to use this code for other purpose.
*/
#include "CSplitterWnd.h"
#include "CSplitBoxWnd.h"
#include "debug.h"
#include "mymessage.h"
#include "CEditWnd.h"
#include "CEditView.h"
#include <tchar.h>

//	@date 2002.2.17 YAZAKI CShareDataのインスタンスは、CProcessにひとつあるのみ。
CSplitterWnd::CSplitterWnd() :
	m_pszClassName("SplitterWndClass"),	/* クラス名 */
	m_nActivePane(0),					/* アクティブなペイン 0-3 */
	m_nAllSplitRows(1),					/* 分割行数 */
	m_nAllSplitCols(1),					/* 分割桁数 */
	m_nVSplitPos(0),					/* 垂直分割位置 */
	m_nHSplitPos(0),					/* 水平分割位置 */
	m_bDragging(0),						/* 分割バーをドラッグ中か */
	m_nDragPosX(0),						/* ドラッグ位置X */
	m_nDragPosY(0),						/* ドラッグ位置Y */
	m_pCEditWnd(NULL)
{
	strcat( m_szClassInheritances, "::CSplitterWnd" );
	/* 共有データ構造体のアドレスを返す */
	m_pShareData = CShareData::getInstance()->GetShareData();

	m_hcurOld = NULL;						/* もとのマウスカーソル */

	for( int v=0; v < MAXCOUNTOFVIEW; v++ ){
		m_ChildWndArr[v] = NULL;				/* 子ウィンドウ配列 */
	}
	return;
}




CSplitterWnd::~CSplitterWnd()
{
}




/* 初期化 */
HWND CSplitterWnd::Create( HINSTANCE hInstance, HWND hwndParent, void* pCEditWnd )
{
	/* 初期化 */
	m_hInstance = hInstance;	/* アプリケーションインスタンスのハンドル */
	m_hwndParent = hwndParent;	/* オーナーウィンドウのハンドル */
	m_pCEditWnd	= pCEditWnd;

	/* ウィンドウクラス作成 */
	ATOM atWork;
	atWork = RegisterWC(
		/* WNDCLASS用 */
		NULL,// Handle to the class icon.
		NULL,	//Handle to a small icon
		NULL,// Handle to the class cursor.
		(HBRUSH)NULL,// Handle to the class background brush.
		NULL/*MAKEINTRESOURCE( MYDOCUMENT )*/,// Pointer to a null-terminated 
				//character string that specifies the resource name of the class menu,
				//as the name appears in the resource file.
		m_pszClassName// Pointer to a null-terminated string or is an atom.
	);
	if( 0 == atWork ){
		::MYMESSAGEBOX( NULL, MB_OK | MB_ICONSTOP, GSTR_APPNAME,
			_T("SplitterWndクラスの登録に失敗しました。")
		);
	}

	/* 基底クラスメンバ呼び出し */
	return CWnd::Create(
		/* CreateWindowEx()用 */
		0, // extended window style
		m_pszClassName,	// Pointer to a null-terminated string or is an atom.
		m_pszClassName, // pointer to window name
		WS_CHILD | WS_VISIBLE, // window style
		CW_USEDEFAULT, // horizontal position of window
		0, // vertical position of window
		CW_USEDEFAULT, // window width
		0, // window height
		NULL // handle to menu, or child-window identifier
	);
}





/* 子ウィンドウの設定 */
void CSplitterWnd::SetChildWndArr( HWND* pcEditViewArr )
{
	for( int v=0; v < MAXCOUNTOFVIEW; v++ ){
		m_ChildWndArr[v] = pcEditViewArr[v];				/* 子ウィンドウ配列 */
	}

	// 2002/05/11 YAZAKI 不要な処理と思われる
	/* ウィンドウの分割 */
//	DoSplit( m_nHSplitPos, m_nVSplitPos );
//	DoSplit( 0, 0 );
	return;
}




/* 分割フレーム描画 */
void CSplitterWnd::DrawFrame( HDC hdc, RECT* prc )
{
	CSplitBoxWnd::Draw3dRect( hdc, prc->left, prc->top, prc->right, prc->bottom,
		::GetSysColor( COLOR_3DSHADOW ),
		::GetSysColor( COLOR_3DHILIGHT )
	);
	CSplitBoxWnd::Draw3dRect( hdc, prc->left + 1, prc->top + 1, prc->right - 2, prc->bottom - 2,
		RGB( 0, 0, 0 ),
		::GetSysColor( COLOR_3DFACE )
	);
	return;
}




/* 分割トラッカーの表示 */
void CSplitterWnd::DrawSplitter( int xPos, int yPos, int bEraseOld )
{
	HDC			hdc;
	HBRUSH		hBrush;
	HBRUSH		hBrushOld;
	RECT		rc;
	RECT		rc2;
	int			nTrackerWidth = 6;

	hdc = ::GetDC( m_hWnd );
	hBrush = ::CreateSolidBrush( RGB(255,255,255) );
	hBrushOld = (HBRUSH)::SelectObject( hdc, hBrush );
	::SetROP2( hdc, R2_XORPEN );
	::SetBkMode( hdc, TRANSPARENT );
	::GetClientRect( m_hWnd, &rc );

	if( bEraseOld ){
		if( m_bDragging & 1 ){	/* 分割バーをドラッグ中か */
			rc2.left = -1;
			rc2.top = m_nDragPosY;
			rc2.right = rc.right;
			rc2.bottom = rc2.top + nTrackerWidth;
			::Rectangle( hdc, rc2.left, rc2.top, rc2.right, rc2.bottom );
		}
		if( m_bDragging & 2 ){	/* 分割バーをドラッグ中か */
			rc2.left = m_nDragPosX;
			rc2.top = 0;
			rc2.right = rc2.left + nTrackerWidth;
			rc2.bottom = rc.bottom;
			::Rectangle( hdc, rc2.left, rc2.top, rc2.right, rc2.bottom );
		}
	}

	m_nDragPosX = xPos;
	m_nDragPosY = yPos;
	if( m_bDragging & 1 ){	/* 分割バーをドラッグ中か */
		rc2.left = -1;
		rc2.top = m_nDragPosY;
		rc2.right = rc.right;
		rc2.bottom = rc2.top + nTrackerWidth;
		::Rectangle( hdc, rc2.left, rc2.top, rc2.right, rc2.bottom );
	}
	if( m_bDragging & 2 ){	/* 分割バーをドラッグ中か */
		rc2.left = m_nDragPosX;
		rc2.top = 0;
		rc2.right = rc2.left + nTrackerWidth;
		rc2.bottom = rc.bottom;
		::Rectangle( hdc, rc2.left, rc2.top, rc2.right, rc2.bottom );
	}

	::SelectObject( hdc, hBrushOld );
	::DeleteObject( hBrush );
	::ReleaseDC( m_hWnd, hdc );
	return;
}




/* 分割バーへのヒットテスト */
int CSplitterWnd::HitTestSplitter( int xPos, int yPos )
{
	int			nFrameWidth = 3;
	int			nMargin = 2;

	if( m_nAllSplitRows == 1 && m_nAllSplitCols == 1 ){
		return 0;
	}else
	if( m_nAllSplitRows == 2 && m_nAllSplitCols == 1 ){
		if( m_nVSplitPos - nMargin < yPos && yPos < m_nVSplitPos + nFrameWidth + nMargin ){
			return 1;
		}else{
			return 0;
		}
	}else
	if( m_nAllSplitRows == 1 && m_nAllSplitCols == 2 ){
		if( m_nHSplitPos - nMargin < xPos && xPos < m_nHSplitPos + nFrameWidth + nMargin ){
			return 2;
		}else{
			return 0;
		}
	}else{
		if( m_nVSplitPos - nMargin < yPos && yPos < m_nVSplitPos + nFrameWidth + nMargin &&
			m_nHSplitPos - nMargin < xPos && xPos < m_nHSplitPos + nFrameWidth + nMargin ){
			return 3;
		}else
		if( m_nVSplitPos - nMargin < yPos && yPos < m_nVSplitPos + nFrameWidth + nMargin ){
			return 1;
		}else
		if( m_nHSplitPos - nMargin < xPos && xPos < m_nHSplitPos + nFrameWidth + nMargin ){
			return 2;
		}else{
			return 0;
		}
	}
}

/* ウィンドウの分割 */
void CSplitterWnd::DoSplit( int nHorizontal, int nVertical )
{
	int					nActivePane;
	int					nLimit = 32;
	RECT				rc;
	int					nAllSplitRowsOld = m_nAllSplitRows;	/* 分割行数 */
	int					nAllSplitColsOld = m_nAllSplitCols;	/* 分割桁数 */
	CEditView*			pcViewArr[MAXCOUNTOFVIEW];
//	int					i;
	BOOL				bVUp;
	BOOL				bHUp;
	BOOL				bSizeBox;
	CEditWnd*			pCEditWnd = (CEditWnd*)m_pCEditWnd;
	bVUp = FALSE;
	bHUp = FALSE;

	if( -1 == nHorizontal && -1 == nVertical ){
		nVertical = m_nVSplitPos;		/* 垂直分割位置 */
		nHorizontal = m_nHSplitPos;		/* 水平分割位置 */
	}
	/*
	|| ファンクションキーを下に表示している場合はサイズボックスを表示しない
	|| ステータスパーを表示している場合はサイズボックスを表示しない
	*/
	if( NULL == pCEditWnd
	 ||( NULL != pCEditWnd->m_CFuncKeyWnd.m_hWnd
	  && 1 == m_pShareData->m_Common.m_nFUNCKEYWND_Place	/* ファンクションキー表示位置/0:上 1:下 */
	  )
	){
		bSizeBox = FALSE;
	}else{
		bSizeBox = TRUE;
		/* ステータスパーを表示している場合はサイズボックスを表示しない */
		if( NULL != pCEditWnd->m_hwndStatusBar ){
			bSizeBox = FALSE;
		}
	}
	/* メインウィンドウが最大化されている場合はサイズボックスを表示しない */
	WINDOWPLACEMENT	wp;
	wp.length = sizeof( WINDOWPLACEMENT );
	::GetWindowPlacement( m_hwndParent, &wp );
	if( SW_SHOWMAXIMIZED == wp.showCmd ){
		bSizeBox = FALSE;
	}

	int v;
	for( v=0; v < MAXCOUNTOFVIEW; v++ ){
		pcViewArr[v] = ( CEditView* )::GetWindowLongPtr( m_ChildWndArr[v], 0 );
	}
	::GetClientRect( m_hWnd, &rc );
	if( nHorizontal < nLimit ){
		if( nHorizontal > 0 ){
			bHUp = TRUE;
		}
		nHorizontal = 0;
	}
	if( nHorizontal > rc.right - nLimit * 2 ){
		nHorizontal = 0;
	}
	if( nVertical < nLimit ){
		if( nVertical > 0 ){
			bVUp = TRUE;
		}
		nVertical = 0;
	}
	if( nVertical > rc.bottom - nLimit * 2 ){
		nVertical = 0;
	}
	m_nVSplitPos = nVertical;		/* 垂直分割位置 */
	m_nHSplitPos = nHorizontal;		/* 水平分割位置 */

	if( nVertical == 0 && nHorizontal == 0 ){
		m_nAllSplitRows = 1;	/* 分割行数 */
		m_nAllSplitCols = 1;	/* 分割桁数 */
		if( m_ChildWndArr[0] != NULL ) ::ShowWindow( m_ChildWndArr[0], SW_SHOW );
		if( m_ChildWndArr[1] != NULL ) ::ShowWindow( m_ChildWndArr[1], SW_HIDE );
		if( m_ChildWndArr[2] != NULL ) ::ShowWindow( m_ChildWndArr[2], SW_HIDE );
		if( m_ChildWndArr[3] != NULL ) ::ShowWindow( m_ChildWndArr[3], SW_HIDE );

		if( NULL != pcViewArr[0] ) pcViewArr[0]->SplitBoxOnOff( TRUE, TRUE, bSizeBox );		/* 縦?横の分割ボックスのON/OFF */
//		if( NULL != pcViewArr[1] ) pcViewArr[1]->SplitBoxOnOff( FALSE, FALSE, FALSE );	/* 縦?横の分割ボックスのON/OFF */
//		if( NULL != pcViewArr[2] ) pcViewArr[2]->SplitBoxOnOff( FALSE, FALSE, FALSE );	/* 縦?横の分割ボックスのON/OFF */
//		if( NULL != pcViewArr[3] ) pcViewArr[3]->SplitBoxOnOff( FALSE, FALSE, FALSE );	/* 縦?横の分割ボックスのON/OFF */

		OnSize( 0, 0, 0, 0 );

		if( nAllSplitRowsOld == 1 && nAllSplitColsOld == 1 ){
		}else
		if( nAllSplitRowsOld > 1 && nAllSplitColsOld == 1 ){
			if( bVUp ){
				/* ペインの表示状態を他のビューにコピー */
				if( NULL != pcViewArr[2] && NULL != pcViewArr[0] ){
					pcViewArr[2]->CopyViewStatus( pcViewArr[0] );
				}
			}else{
				/* ペインの表示状態を他のビューにコピー */
				if( m_nActivePane != 0 &&
					NULL != pcViewArr[m_nActivePane] && NULL != pcViewArr[0] ){
					pcViewArr[m_nActivePane]->CopyViewStatus( pcViewArr[0] );
				}
			}
		}else
		if( nAllSplitRowsOld == 1 && nAllSplitColsOld > 1 ){
			if( bHUp ){
				/* ペインの表示状態を他のビューにコピー */
				if( NULL != pcViewArr[1] && NULL != pcViewArr[0] ){
					pcViewArr[1]->CopyViewStatus( pcViewArr[0] );
				}
			}else{
				/* ペインの表示状態を他のビューにコピー */
				if( m_nActivePane != 0 &&
					NULL != pcViewArr[m_nActivePane] && NULL != pcViewArr[0] ){
					pcViewArr[m_nActivePane]->CopyViewStatus( pcViewArr[0] );
				}
			}
		}else{
			if( !bVUp && !bHUp ){
				/* ペインの表示状態を他のビューにコピー */
				if( m_nActivePane != 0 &&
					NULL != pcViewArr[m_nActivePane] && NULL != pcViewArr[0] ){
					pcViewArr[m_nActivePane]->CopyViewStatus( pcViewArr[0] );
				}
			}else
			if( bVUp && !bHUp ){

⌨️ 快捷键说明

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