登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

自由自在

 
 
 

日志

 
 

在OpenOffice3.0中创建对话框  

2009-04-21 17:17:30|  分类: openoffice |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

yuanlianghua@office
2008-09-10

本文档介绍了如何在OpenOffice3.0中使用自己创建的对话框。

下面以scalc(电子表格)为例,在scalc的格式化工具栏上增加一个工具按钮,点击这个工具按钮后弹出一个自定义的对话框,在对话框中的输入框里会载入当前单元格中的内容(如果有的话),编辑输入框中的内容,点击OK后,关闭对话框并将输入框中的内容填更新到当前单元格。


一、 环境介绍
OS:Ubuntu 8.04.1
OpenOffice3.0安装路径:/opt/openoffice.org, /opt/openoffice.org3
OpenOffice3.0源代码路径:/dev300_28

二、 步骤概述
1、在相应的工具栏上添加工具按钮
2、将工具按钮关联到相应的shell方法
3、定义对话框资源
4、建立对话框类及相应方法
5、编写相应的工厂创建方法
6、在相应shell方法中加入创建并显示对话框的代码
7、编辑相应的makefile文件,将新增的源文件加入编译
8、重新编译sc模块,并将生成的链接库文件拷贝到安装目录

三、 具体步骤

1、在相应的工具栏上添加工具按钮

(1)、编辑文件: /opt/openoffice.org/basis3.0/share/config/soffice.cfg/modules/scalc/toolbar/formatobjectbar.xml

查找uno:ToggleMergeCells,在其后增加工具按钮Filler的配置(新增的Filler按钮将出现在合并单元格按钮MergeCells的后面):

<toolbar:toolbaritem xlink:href=".uno:Filler" toolbar:helpid="helpid:26581" />

Filler按钮的helpid将在后面定义SID时返回来修改

(2)、编辑文件:/opt/openoffice.org/basis3.0/share/registry/data/org/openoffice/Office/UI/CalcCommands.xcu,同样查找 uno:ToggleMergeCells,在其后增加Filler的配置

<node oor:name=".uno:Filler" oor:op="replace">
  <prop oor:name="Label" oor:type="xs:string">
  <value xml:lang="en-US">F~iller Cell</value>
</prop>

<prop oor:name="Properties" oor:type="xs:int">

<value>1</value>

</prop>

</node>

(可将 ToggleMergeCells按扭的配置复制一份再修改为Filler的配置)


关闭OpenOffice里所有已启动的应用,重新启动scalc,将会在MergeCells按钮后面看到

新增的Filler按钮,如图3.1.1:。

(图3.1.1) 新增加的Filler工具按钮

这时看到的Filler按钮是灰色不可点击的,后面的步骤将使得它变为可用。


2、将工具按钮关联到相应的shell方法

(1)、为Filler按钮增加SID

编辑文件:/dev300_m28/sc/inc/sc.hrc

查找:FID_MERGE_TOGGLE,复制其定义并修改为Filler的配置:

#define FID_FILLER (SID_NEW_SLOTS+100)

注意:SID的值要定义为未被占用的下一个ID值,查找到当前最大用到

(SID_NEW_SLOTS+99) 所以这里定义为:(SID_NEW_SLOTS+100) 。

(2)、编辑文件: /dev300_m28/sc/sdi/scalc.sdi

查找ToggleMergeCells,把ToggleMergeCellss配置项复制一份修改为Filler的配置:

SfxVoidItem Filler FID_FILLER

(SfxBoolItem MoveContents FID_FILLER)

[

/* flags: */

AutoUpdate = FALSE,

Cachable = Cachable,

FastCall = FALSE,

HasCoreId = FALSE,

HasDialog = FALSE,

ReadOnlyDoc = TRUE,

Toggle = FALSE,

Container = FALSE,

RecordAbsolute = FALSE,

RecordPerSet;

Synchron;


/* config: */

AccelConfig = TRUE,

MenuConfig = TRUE,

StatusBarConfig = FALSE,

ToolBoxConfig = TRUE,

GroupId = GID_FORMAT;

]


(3)、编辑文件: /dev300_m28/sc/sdi/cellsh.sdi

查找FID_MERGE_TOGGLE,把FID_MERGE_TOGGLE配置复制一份修改为Filler

的配置:

FID_FILLER [ ExecMethod = Execute; StateMethod = GetState; ]





3、定义对话框资源

(1)、定义对话框资源ID(RID )

编辑文件:/dev300_m28/sc/inc/sc.hrc,增加Filler的对话框ID

#define RID_SCDLG_FILLER (SC_DIALOGS_START + 147)

因为SC中当前用到的最后一个RID为(SC_DIALOGS_START + 146) ,

所以这里定义成(SC_DIALOGS_START + 147)。


编辑文件:/dev300_m28/sc/source/ui/inc/miscdlgs.hrc,增加Filler对话框中输入框

的ID

#define ED_NAME 10


(2)、定义对话框界面元素

编辑文件:/dev300_m28/sc/source/ui/src/miscdlgs.src,增加下面的定义

ModalDialog RID_SCDLG_FILLER

{

OutputSize = TRUE ;

HelpId = FID_FILLER;

SVLook = TRUE ;

Size = MAP_APPFONT ( 191 , 70 ) ;

Text [ en-US ] = "Fill cell helper" ;

Moveable = TRUE ;

Closeable = FALSE ;

OKButton BTN_OK

{

Pos = MAP_APPFONT ( 135 , 6 ) ;

Size = MAP_APPFONT ( 50 , 14 ) ;

TabStop = TRUE ;

DefButton = TRUE ;

};

CancelButton BTN_CANCEL

{

Pos = MAP_APPFONT ( 135 , 23 ) ;

Size = MAP_APPFONT ( 50 , 14 ) ;

TabStop = TRUE ;

};

HelpButton BTN_HELP

{

Pos = MAP_APPFONT ( 135 , 43 ) ;

Size = MAP_APPFONT ( 50 , 14 ) ;

TabStop = TRUE ;

};

Edit ED_NAME

{

Border = TRUE ;

Pos = MAP_APPFONT ( 12 , 15 ) ;

Size = MAP_APPFONT ( 50 , 12 ) ;

TabStop = TRUE ;

};

FixedLine FL_FRAME

{

Pos = MAP_APPFONT ( 6 , 3 ) ;

Size = MAP_APPFONT ( 123 , 8 ) ;

Text [ en-US ] = "Fill cell Dialog" ;

};

};


4、建立对话框类及相应方法

(1)、建立对话框类头文件

在/dev300_m28/sc/source/ui/inc下建立fillerdlg.hxx,内容如下:

#ifndef SC_FILLERDLG_HXX

#define SC_FILLERDLG_HXX


#include <vcl/dialog.hxx>

#include <vcl/imagebtn.hxx>

#include <vcl/fixed.hxx>

#include <vcl/edit.hxx>



#include "global.hxx"


//------------------------------------------------------------------------


class ScFillerDlg : public ModalDialog

{

private:

FixedLine aFlFrame;

Edit aEdName;

OKButton aBtnOk;

CancelButton aBtnCancel;

HelpButton aBtnHelp;


public:

ScFillerDlg( Window* pParent, const String& rDefName );

~ScFillerDlg();


void GetNameString( String& rString ) const;

};



#endif // SC_FILLERDLG_HXX



(2)、建立对话框类源文件

在/dev300_m28/sc/source/ui/miscdlgs下建立fillerdlg.cxx,内容如下:


#include "precompiled_sc.hxx"


#undef SC_DLLIMPLEMENTATION




//------------------------------------------------------------------


#include <tools/debug.hxx>


#include "fillerdlg.hxx"

#include "scresid.hxx"

#include "miscdlgs.hrc"



//==================================================================


ScFillerDlg::ScFillerDlg( Window* pParent, const String& rDefName ):

ModalDialog ( pParent, ScResId( RID_SCDLG_FILLER ) ),

//sdf

aFlFrame ( this, ScResId( FL_FRAME ) ),

aEdName ( this, ScResId( ED_NAME ) ),

aBtnOk ( this, ScResId( BTN_OK ) ),

aBtnCancel ( this, ScResId( BTN_CANCEL ) ),

aBtnHelp ( this, ScResId( BTN_HELP ) )

{

aEdName.SetText( rDefName );


//-------------

FreeResource();

}


//------------------------------------------------------------------------


void ScFillerDlg::GetNameString( String& rString ) const

{

rString = aEdName.GetText();

}


__EXPORT ScFillerDlg::~ScFillerDlg()

{

}


5、编写相应的工厂创建方法

(1)、编辑文件:/dev300_m28/sc/inc/scabstdlg.hxx,

在class ScAbstractDialogFactory前加入以下行:


class AbstractScFillerDlg : public VclAbstractDialog //add for ScFillerDlg

{

public:

virtual void GetNameString( String& rString ) const = 0;

};


在ScAbstractDialogFactory类定义体中加入:

virtual AbstractScMyTestDlg * CreateScFillerDlg( Window* pParent, int nId, const String& rDefName ) = 0;



(2)、编辑文件:/dev300_m28/sc/source/ui/attrdlg/scdlgfact.hxx,

在类声明处增加一行:

class ScFillerDlg;


在类class ScAbstractDialogFactory_Impl定义前增加:

class AbstractScFillerDlg_Impl : public AbstractScFillerDlg //add for ScFillerDlg

{

DECL_ABSTDLG_BASE( AbstractScFillerDlg_Impl, ScFillerDlg)

virtual void GetNameString( String& rString ) const;

};


在类ScAbstractDialogFactory_Impl定义体内加入:

virtual AbstractScFillerDlg * CreateScFillerDlg( Window* pParent, //add for ScFillerDlg

int nId,

const String &rDefName );



(3)、编辑文件:/dev300_m28/sc/source/ui/attrdlg/scdlgfact.cxx,

增加文件包含:

#include "fillerdlg.hxx" //add for ScFillerDlg


增加宏语句:

IMPL_ABSTDLG_BASE(AbstractScFillerDlg_Impl); //add for ScFillerDlg


增加以下代码:

void AbstractScFillerDlg_Impl::GetNameString( String& rString ) const

{

pDlg->GetNameString(rString);

}


增加以下代码:

//add for ScFillerDlg begin

AbstractScFillerDlg * ScAbstractDialogFactory_Impl::CreateScFillerDlg( Window* pParent, //add for ScFillerDlg

int nId,

const String& rDefName )

{

ScFillerDlg * pDlg=NULL;

switch ( nId )

{

case RID_SCDLG_FILLER :

pDlg = new ScFillerDlg( pParent, rDefName);

break;

default:

break;

}


if ( pDlg )

return new AbstractScFillerDlg_Impl( pDlg );

return 0;

}

//add for ScFillerDlg end


6、在相应shell方法中加入创建并显示对话框的代码

编辑文件:/dev300_m28/sc/source/ui/view/cellsh3.cxx

在Excute方法中的Switch语句中增加下列代码:


case FID_FILLER:

{

ScDocument* pDoc = GetViewData()->GetDocument();

BOOL bTheFlag=(pDoc->GetChangeTrack()!=NULL);

ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();

DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001


ScAddress curAddr( GetViewData()->GetCurPos() );

ScBaseCell *pTheCell;

pTheCell = pDoc->GetCell(curAddr);


AbstractScFillerDlg* pDlg = pFact->CreateScFillerDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_FILLER, pTheCell == NULL ? String::CreateFromAscii("") : pTheCell->GetStringData() );

DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001

if ( pDlg->Execute() == RET_OK )

{

String sRet;

pDlg->GetNameString(sRet);

pTabViewShell->EnterData(curAddr.Col(),curAddr.Row(),curAddr.Tab(),sRet);

rBindings.Update();

}

delete pDlg;

rReq.Done();

}


break;


由于用到了 ScBaseCell,所以要增加包含头文件:

#include "cell.hxx"


7、编辑相应的makefile文件,将新增的源文件加入编译

编辑文件:/dev300_m28/sc/source/ui/miscdlgs/makefile.mk

在 SLOFILES 项里增加下面一行:

$(SLO)$/fillerdlg.obj \


编辑文件:/dev300_m28/sc/util/makefile.mk

在LIB8OBJFILES项目中增加下面一行:

$(SLO)$/fillerdlg.obj \




8、重新编译sc模块,并将生成的链接库文件拷贝到安装目录

打开终端,进入目录/dev300_m28/sc,运行:

xxx:/dev300_m28/sc$ build

编译模块,完成后将其下的unxlngi6.pro/lib下的所有.so文件拷贝到

/opt/openoffice.org/basis3.0/program下,将unxlngi6.pro/bin下的所有.res文件拷贝到

/opt/openoffice.org/basis3.0/program/resource下,覆盖同名文件。



以上所有步骤均正确完成后,重新启动scalc,应该就能看到新增的Filler工具按钮,

点击它测试一下它的功能,如下图。





  评论这张
 
阅读(383)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018