首先我们来明确一下功能需求。
在工作表标签上单击鼠标右键展开其右键菜单,单击“工作表标签颜色”的菜单项,展开颜色子菜单,如上图所示,选中当前标签的颜色所对应的颜色项,默认选中“默认”菜单项,
单击菜单中的颜色项,该颜色项被选中(其前部显示选中状态的对号),关闭菜单,同时在工作表标签上应用该颜色。
当文件编辑完成之后和文件内容一同保存。
(一)增加右键菜单项“工作表标签颜色”。
sc/source/ui/src/popup.src文件是有关弹出菜单项的命名资源文件。
Menu RID_POPUP_TAB中加入“工作表标签颜色”菜单项的命名。加入如下代码:
// Ryan add beging
MenuItem
{
Identifier = FID_TAB_COLORSET ;
HelpId = FID_TAB_COLORSET ;
Text [ en-US ] = "Set Sheet Color" ;
};
// Ryan add end
在对应的本地化模块中,做汉化内容的显示。也就是文件sc/source/ui/src/localize.sdf中加入如下代码:
// Ryan add begin
sc source\ui\src\popup.src 0 menuitem RID_POPUP_CELLS SID_SELECTALL SID_SELECTALL 0 zh-CN 全部选中(~S) 2002-02-02 02:02:02
// Ryan add end
资源文件的投文件 sc/inc/sc.hrc 中给我们新的菜单项分配一个Id. 添加如下代码:
// Ryan add begin
#define FID_TAB_COLORSET (TAB_POPUP_START+8)// Ryan add end
在sc/sdi/scalc.sdi中设置FID_TAB_COLORSET的属性。没有搞懂各元素的意思,仿造其他的就好了。
在sc/sdi/docsh.sdi的interface TableSelection和sc/sdi/tabvwsh.sdi的interface Tables中 中分别添加处理函数(ExecMethod)和状态函数(StateMethod)。
FID_TAB_COLORSET [ ExecMethod = ExecuteTable; StateMethod = GetStateTable; ]
进入SC模块重新编译, 拷贝生成的库文件和资源文件到安装目录,菜单项就可以显示了。
cd unxlngi6.pro/lib/
cp * /opt/openoffice.org/basis3.0/program/
cd ../bin/cp *.res /opt/openoffice.org/basis3.0/program/resource/(二)点击“工作表标签颜色”菜单项弹出PopupMenu,我们创建一个这样的类。
分创造类的头文件和源文件。命名为:sc/inc/TabBarColor.hxx, sc/source/ui/cctrl/TabBarColor.cxx.
如何创建类呢?我们仿造一下Ooo中已经存在的类似东西。仿造svx/inc/svx/fntszctl.hxx这个类怎么实现的就可以了。删除没有用的函数,添加我们自己的函数,把名字修改了就可以。这就叫“优秀的艺术家是拷贝,伟大的艺术家是偷盗”。
sc/inc/TabBarColor.hxx的内容如下:
31 // Ryan add begin
32 #ifndef _SC_TABBARCOLOR_HXX
33 #define _SC_TABBARCOLOR_HXX
34
35
36 // include ---------------------------------------------------------------
37
38 #include
39 #include
40
41 class SfxBindings;
42 class PopupMenu;
43
44 // class ScTabBarColorControl ------------------------------------------
45
46 class ScTabBarColorControl : public SfxMenuControl
47 {
48 private:
49 PopupMenu* pMenu;
50 Menu& rParent;
51
52 //#if 0 // _SOLAR__PRIVATE
53 DECL_LINK( MenuSelect, PopupMenu* );
54 //#endif
55
56 public:
57 ScTabBarColorControl( USHORT nId, Menu&, SfxBindings& );
58 ~ScTabBarColorControl();
59
60 virtual PopupMenu* GetPopup() const;
62 void SetCheckItem();
63 SFX_DECL_MENU_CONTROL();
64 //char* chColor;
65 };
// Ryan add end
sc/source/ui/cctrl/TabBarColor.cxx源文件中,创建弹出窗口的时候插入菜单项。
主要代码:
ScTabBarColorControl::ScTabBarColorControl
(
USHORT _nId,
Menu& rMenu,
SfxBindings& rBindings
) :
SfxMenuControl( _nId, rBindings ),
pMenu ( new PopupMenu ),
rParent ( rMenu )
{
rMenu.SetPopupMenu( _nId, pMenu );
String aString[] = {
String( ScResId(RID_TABBAR_DEFAULT) ),
String( ScResId(RID_TABBAR_COLOR1) ),
String( ScResId(RID_TABBAR_COLOR2) ),
String( ScResId(RID_TABBAR_COLOR3) ),
String( ScResId(RID_TABBAR_COLOR4) ),
String( ScResId(RID_TABBAR_COLOR5) ),
String( ScResId(RID_TABBAR_COLOR6) ),
String( ScResId(RID_TABBAR_COLOR7) ),
String( ScResId(RID_TABBAR_COLOR8) ),
String( ScResId(RID_TABBAR_COLOR9) ),
String( ScResId(RID_TABBAR_COLOR10) ),
String( ScResId(RID_TABBAR_COLOR11) ),
String( ScResId(RID_TABBAR_COLOR12) ),
String( ScResId(RID_TABBAR_COLOR13) ),
String( ScResId(RID_TABBAR_COLOR14) ),
String( ScResId(RID_TABBAR_COLOR15) ),
String( ScResId(RID_TABBAR_COLOR16) ),
String( ScResId(RID_TABBAR_COLOR17) ),
String( ScResId(RID_TABBAR_COLOR18) ),
String( ScResId(RID_TABBAR_COLOR19) ),
String( ScResId(RID_TABBAR_COLOR20) ),
String( ScResId(RID_TABBAR_COLOR21) )
};
ImageList aEntryImages( ScResId(RID_IMAGELIST_TABBARCOLOR) );
pMenu->InsertItem( 0, aString[0] );
for (int i = 1; i < 22; i++)
{
pMenu->InsertItem(i, aString[i], aEntryImages.GetImage( i ) );
}
SetCheckItem();
pMenu->SetSelectHdl( LINK( this, ScTabBarColorControl, MenuSelect ) );
}
以上的菜单项内容和图片资源都在资源文件中申明,并做本地化。
每次选定菜单项的时候我们返回所选择的Color.
IMPL_LINK( ScTabBarColorControl, MenuSelect, PopupMenu*, pMen )
{
USHORT nItemId = pMenu->GetCurItemId();
Color aColor;
switch(nItemId)
{
case 0:
aColor = Color( RGB_COLORDATA(255, 255, 255) );
break;
case 1:
aColor = Color( RGB_COLORDATA(249, 251, 118) );
break;
case 2:
aColor = Color( RGB_COLORDATA(248, 249, 0) );
break;
case 3:
aColor = Color( RGB_COLORDATA(187, 189, 0) );
break;
case 4:
aColor = Color( RGB_COLORDATA(154, 211, 168) );
break;
case 5:
aColor = Color( RGB_COLORDATA(0, 171, 94) );
break;
case 6:
aColor = Color( RGB_COLORDATA(0, 135, 75) );
break;
case 7:
aColor = Color( RGB_COLORDATA(158, 210, 244) );
break;
case 8:
aColor = Color( RGB_COLORDATA(61, 82, 171) );
break;
case 9:
aColor = Color( RGB_COLORDATA(46, 59, 135) );
break;
case 10:
aColor = Color( RGB_COLORDATA(186, 151, 199) );
break;
case 11:
aColor = Color( RGB_COLORDATA(124, 0, 151) );
break;
case 12:
aColor = Color( RGB_COLORDATA(97, 0, 119) );
break;
case 13:
aColor = Color( RGB_COLORDATA(235, 124, 176) );
break;
case 14:
aColor = Color( RGB_COLORDATA(299, 0, 144) );
break;
case 15:
aColor = Color( RGB_COLORDATA(176, 0, 133) );
break;
case 16:
aColor = Color( RGB_COLORDATA(228, 53, 35) );
break;
case 17:
aColor = Color( RGB_COLORDATA(174, 53, 35) );
break;
case 18:
aColor = Color( RGB_COLORDATA(141, 0, 0) );
break;
case 19:
aColor = Color( RGB_COLORDATA(202, 202, 202) );
break;
case 20:
aColor = Color( RGB_COLORDATA(141, 141, 141) );
break;
case 21:
aColor = Color( RGB_COLORDATA(0, 0, 0) );
break;
default:
aColor = Color( RGB_COLORDATA(255, 255, 255) );
break;
}
SvxColorItem aItem( aColor, FID_TAB_COLORSET );//和Slot Id 自动关联。
GetBindings().GetDispatcher()->Execute( FID_TAB_COLORSET, SFX_CALLMODE_RECORD, &aItem, 0L );
return 1;
}
根据菜单项的颜色,确定其选定状态。
void ScTabBarColorControl::SetCheckItem()
{
ScViewData* pViewData=ScDocShell::GetViewData();
Color aFaceColor;
int nTemp = static_cast(pViewData->GetTabNo());
if ( !pViewData->GetViewShell()->GetTabControl()->IsPageSetColor( static_cast(nTemp)+1, aFaceColor ) )
{
pMenu->CheckItem( 0 );
}
else
{
switch( aFaceColor.GetColor() )
{
case 16382838:
pMenu->CheckItem( 1 );
break;
case 16316672:
pMenu->CheckItem( 2 );
break;
case 12303616:
pMenu->CheckItem( 3 );
break;
case 10146728:
pMenu->CheckItem( 4 );
break;
case 43870:
pMenu->CheckItem( 5 );
break;
case 34635:
pMenu->CheckItem( 6 );
break;
case 10408692:
pMenu->CheckItem( 7 );
break;
case 4018859:
pMenu->CheckItem( 8 );
break;
case 3029895:
pMenu->CheckItem( 9 );
break;
case 12228551:
pMenu->CheckItem( 10 );
break;
case 8126615:
pMenu->CheckItem( 11 );
break;
case 6357111:
pMenu->CheckItem( 12 );
break;
case 15432880:
pMenu->CheckItem( 13 );
break;
case 2818192:
pMenu->CheckItem( 14 );
break;
case 11534469:
pMenu->CheckItem( 15 );
break;
case 14955811:
pMenu->CheckItem( 16 );
break;
case 11416867:
pMenu->CheckItem( 17 );
break;
case 9240576:
pMenu->CheckItem( 18 );
break;
case 13290186:
pMenu->CheckItem( 19 );
break;
case 9276813:
pMenu->CheckItem( 20 );
break;
case 0:
pMenu->CheckItem( 21 );
break;
default:
break;
}
}
}
在sc/source/ui/app/scdll.cxx 注册我们的FID_TAB_COLORSET,这样就可以我们定义的FID_TAB_COLORSET和ScTabBarColorControl相关,会根据Ooo的工厂机制动态创建弹出窗口。
ScTabBarColorControl ::RegisterControl(FID_TAB_COLORSET, pMod );
修改sc/source/ui/cctrl/makefile.mk,加入TabBarColor.obj
重新编译。点击的时候就可以弹出菜单了。
阅读(2120) | 评论(1) | 转发(0) |