// WordSntxAddn.cpp : Implementation of CWordSntxAddn
//
// Copyright 2006 (c) RegExLab.com
//
// Author: 史寿伟 (sswater shi)
//
// 2006/05/19 01:52:42
//
#include "stdafx.h"
#include "SntxAddn.h"
#include "WordSntxAddn.h"
#include "SyntaxModule.h"
#include "ProgressThread.h"
#include "BtnFaceUtil.h"
#include "ClipboardBackup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWordSntxAddn
_ATL_FUNC_INFO CWordSntxAddn::OnClickButtonInfo = { CC_STDCALL, VT_EMPTY, 2, { VT_DISPATCH, VT_BYREF | VT_BOOL } };
CWordSntxAddn::CWordSntxAddn()
{
m_spApp = NULL;
for( int i=0; i<MAX_BUTTONS; i++ )
{
m_spButtons[i] = NULL;
m_pSyntax [i] = NULL;
}
}
STDMETHODIMP CWordSntxAddn::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IWordSntxAddn
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP CWordSntxAddn::OnConnection(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
{
// Application
m_spApp = CComQIPtr <_Application> (Application);
// Command Bar
CComPtr <CommandBar> spNewCmdBar = InitCommandBar( m_spApp );
// Load Syntax
LoadSyntaxes();
// Buttons
BOOL bUpdated = InitCommandButtons( spNewCmdBar );
// Show or Hide
if( m_pSyntax[0] != NULL )
{
if( bUpdated )
{
spNewCmdBar->PutVisible(VARIANT_TRUE);
}
}
else
{
spNewCmdBar->PutVisible(VARIANT_FALSE);
}
return S_OK;
}
STDMETHODIMP CWordSntxAddn::OnDisconnection(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom)
{
int i;
for(i=0; i<MAX_BUTTONS; i++)
{
if( m_spButtons[i] != NULL )
{
DispEventUnadvise(i+1, (IDispatch*)m_spButtons[i]);
m_spButtons[i] = NULL;
}
if( m_pSyntax[i] != NULL )
{
delete m_pSyntax[i];
m_pSyntax[i] = NULL;
}
}
if( RemoveMode == ext_dm_UserClosed )
{
RemoveCommandBar( m_spApp );
}
return S_OK;
}
VOID __stdcall CWordSntxAddn::OnButtonClick(IDispatch * Ctrl, VARIANT_BOOL * CancelDefault)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
USES_CONVERSION;
// check document count
if( m_spApp->GetWindows()->GetCount() == 0 )
return;
// check selection type
CComPtr <Selection> selection = m_spApp->GetSelection();
WdSelectionType seltype = selection->GetType();
if( seltype < wdSelectionNormal )
{
// no selection
return;
}
else if( seltype > wdSelectionNormal )
{
// invalid selection
TCHAR info[20];
_tcscpy(info, RSTR(IDS_INFO));
MessageBox(NULL, RSTR(IDS_SEL_INVALID), info, MB_OK);
return;
}
CComQIPtr <_CommandBarButton> spButton( Ctrl );
_bstr_t tag = spButton->GetTag();
CSyntaxModule * pSyntax = NULL;
for( int i=0; i<MAX_BUTTONS; i++ )
{
if( m_pSyntax[i] == NULL )
break;
if( m_pSyntax[i]->m_szSyntaxName == tag )
{
pSyntax = m_pSyntax[i];
break;
}
}
if( pSyntax == NULL )
{
// invalid
return;
}
// infomation
int start = selection->Start;
int end = selection->End;
int len = end - start;
// reset color
selection->Font->PutColor( wdColorAutomatic );
// reset bgcolor
selection->Font->Shading->PutTexture( wdTextureNone );
selection->Font->Shading->PutForegroundPatternColor( wdColorAutomatic );
selection->Font->Shading->PutBackgroundPatternColor( wdColorAutomatic );
// get text
_bstr_t bstr_text = selection->GetText();
LPWSTR text = bstr_text;
// unselect
selection->SetRange( end, end );
// parse
pSyntax->Parse( text, len );
// show progress
CProgressDialog dlg;
dlg.m_nLength = len;
CProgressThread * pThread = (CProgressThread*)AfxBeginThread(RUNTIME_CLASS(CProgressThread),
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED,NULL);
pThread->m_pDialog = &dlg;
pThread->ResumeThread();
// highlight
CComPtr <_Document> doc = m_spApp->GetActiveDocument();
int relative_pos, relative_len;
while( dlg.m_bRunning && pSyntax->GetNextPos(relative_pos, relative_len) )
{
// validation
if( relative_pos >= len )
continue;
if( (relative_pos + relative_len) > len )
relative_len = len - relative_pos;
// get range
VARIANT range_start = { VT_I4 }, range_end = { VT_I4 };
range_start.intVal = start + relative_pos;
range_end .intVal = start + relative_pos + relative_len;
CComPtr <Range> range = doc->Range(&range_start, &range_end);
int color;
// fore color
if( pSyntax->GetColor( color ) )
{
color &= 0xFFFFFF;
range->Font->PutColor( (WdColor)color );
}
// back color
if( pSyntax->GetBgColor( color ) )
{
color &= 0xFFFFFF;
long hol = 0; // head of line
long eol = 0; // end of line
long relative_start = start + relative_pos;
LPCWSTR sz = text + relative_pos;
for( eol=0; eol<=relative_len; eol++ )
{
if( eol==relative_len || (sz[eol] >= 0x0A && sz[eol] <= 0x0D) )
{
if( hol < eol )
{
VARIANT range2_start = { VT_I4 }, range2_end = { VT_I4 };
range2_start.intVal = relative_start+hol;
range2_end .intVal = relative_start+eol;
doc->Range( &range2_start, &range2_end )->Shading->PutForegroundPatternColor( (WdColor)color );
}
hol = eol + 1;
}
}
}
// Progress
dlg.SetProgress(relative_pos + relative_len);
}
// close progress
dlg.m_synCreateProgress.Lock();
if( dlg.m_bRunning && dlg.m_bInitalized )
dlg.SendMessage(WM_CLOSE);
dlg.m_bRunning = FALSE;
dlg.m_synCreateProgress.Unlock();
WaitForSingleObject(pThread->m_hThread, INFINITE);
}
HRESULT CWordSntxAddn::DispEventAdvise ( int index, IDispatch * pDisp )
{
switch( index )
{
case 1: return ButtonEvents1::DispEventAdvise( pDisp );
case 2: return ButtonEvents2::DispEventAdvise( pDisp );
case 3: return ButtonEvents3::DispEventAdvise( pDisp );
case 4: return ButtonEvents4::DispEventAdvise( pDisp );
case 5: return ButtonEvents5::DispEventAdvise( pDisp );
case 6: return ButtonEvents6::DispEventAdvise( pDisp );
case 7: return ButtonEvents7::DispEventAdvise( pDisp );
case 8: return ButtonEvents8::DispEventAdvise( pDisp );
case 9: return ButtonEvents9::DispEventAdvise( pDisp );
}
return 0;
}
HRESULT CWordSntxAddn::DispEventUnadvise( int index, IDispatch * pDisp )
{
switch( index )
{
case 1: return ButtonEvents1::DispEventUnadvise( pDisp );
case 2: return ButtonEvents2::DispEventUnadvise( pDisp );
case 3: return ButtonEvents3::DispEventUnadvise( pDisp );
case 4: return ButtonEvents4::DispEventUnadvise( pDisp );
case 5: return ButtonEvents5::DispEventUnadvise( pDisp );
case 6: return ButtonEvents6::DispEventUnadvise( pDisp );
case 7: return ButtonEvents7::DispEventUnadvise( pDisp );
case 8: return ButtonEvents8::DispEventUnadvise( pDisp );
case 9: return ButtonEvents9::DispEventUnadvise( pDisp );
}
return 0;
}
BOOL CWordSntxAddn::LoadSyntaxes()
{
// build filespec
TCHAR path[_MAX_PATH];
GetModuleFileName(_Module.GetModuleInstance(), path, _MAX_PATH);
int pos = _tcslen(path) - 1;
while(pos >= 0 && path[pos] != '\\' && path[pos] != '/') pos --;
_tcscpy(path + pos + 1, _T("*.dll"));
// find
_tfinddata_t fileinfo;
long handle, result;
int count = 0;
for( result = handle = _tfindfirst(path, &fileinfo); result != -1; result = _tfindnext(handle, &fileinfo) )
{
_tcscpy(path + pos + 1, fileinfo.name);
m_pSyntax[count] = CSyntaxModule::LoadSyntaxModule(path);
if( m_pSyntax[count] != NULL )
{
m_pSyntax[count]->m_szSyntaxName = CString("syntax_mod_") + fileinfo.name;
count ++;
}
if( count >= MAX_BUTTONS )
break;
没有合适的资源?快使用搜索试试~ 我知道了~
COM技术的资料整理
共371个文件
gif:145个
jpg:76个
htm:54个
需积分: 3 19 下载量 13 浏览量
2009-10-14
14:27:35
上传
评论
收藏 4.13MB RAR 举报
温馨提示
COM技术入门加深入的详细资料,不用去总结了,个人总结的,要是不值这分,大家拿鸡蛋砸我!
资源推荐
资源详情
资源评论
收起资源包目录
COM技术的资料整理 (371个子文件)
bitmap1.bmp 246B
magic.bmp 246B
WordSntxAddn.cpp 12KB
BtnFaceUtil.cpp 10KB
SntxAddn.cpp 3KB
ClipboardBackup.cpp 3KB
SyntaxModule.cpp 2KB
ProgressDialog.cpp 2KB
Demo.cpp 1KB
ProgressThread.cpp 1KB
StdAfx.cpp 315B
StdAfx.cpp 291B
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
style.css 1KB
Thumbs.db 23KB
SntxAddn.def 224B
SntxAddn.dsp 13KB
Demo.dsp 4KB
Syntax3.dsw 740B
imgad.gif 46KB
com3_2.gif 33KB
CodeAnalyer2.gif 17KB
com3_1.gif 7KB
CodeAnalyer6.gif 7KB
CodeAnalyer5.gif 7KB
comimg9.gif 7KB
CodeAnalyer4.gif 7KB
090200301.gif 7KB
CodeAnalyer1.gif 5KB
090200302.gif 3KB
comimg4.gif 3KB
CodeAnalyer3.gif 2KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
earch.gif 1KB
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
vckcom.gif 1011B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
go.gif 935B
共 371 条
- 1
- 2
- 3
- 4
资源评论
litomboy
- 粉丝: 9
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Qt开发知识、经验总结 包括Qss,数据库,Excel,Model/View等
- IV数据.xlsx
- 一些深度学习中的小例子,适合新手学习使用
- foldcraftlauncher_262944.apk
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功