关闭

为LibreOffice的工具栏添加一个新功能流程

标签: libreoffice源码开发参考文档
307人阅读 评论(0) 收藏 举报
分类:

Now let's launch a bigger window than just a tiny little InfoBox. So we want to click on a graphic in Writer and have the option of saving the graphic/ picture to disk direct!

Cool! So what we would have to start out with is defining a identifier we will use throughout and we stick it in where all the other identifiers are located:

--- sw/inc/cmdid.h      2004-12-07 18:57:10.000000000 +0530
+++ sw/inc/cmdid.h      2004-12-21 19:08:39.000000000 +0530
@@ -159,6 +159,7 @@ Achtung: Ab sofort sind in diesem File k
 
 #define FN_GET_DOCSTAT                 (FN_FILE + 33)    /* Dokumentstatistik einzeln auslesen */
 
+#define FN_SAVE_GRAPHIC       (FN_FILE + 34)    /* Save embedded graphic as */
 
 #define FN_SAVE_SELECTION       (FN_FILE + 35)    /* Selektion speichern */

So that's going to be our identifier, next we qualify our identifier for what method to call when it is invoked, through whichever channel:

--- sw/sdi/_grfsh.sdi   2004-10-15 16:13:21.000000000 +0530
+++ sw/sdi/_grfsh.sdi   2004-12-21 20:15:52.000000000 +0530
@@ -85,6 +85,13 @@ interface BaseTextGraphic : Selection
                DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR";
        ]
 
+       FN_SAVE_GRAPHIC
+       [
+               ExecMethod = Execute ;
+               StateMethod = NoState ;
+               DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR";
+       ]
+
        SID_INSERT_GRAPHIC // zeigt auf FN_FORMAT_GRAFIC_DLG
        [
                ExecMethod = Execute ;

There are also a whole lot of attributes that need to be defined for any slot that is used to hold a menu item or a toolbar item and these attributes are defined as Sfx...Items:

--- sw/sdi/swriter.sdi  2004-11-29 14:28:57.000000000 +0530
+++ sw/sdi/swriter.sdi  2004-12-21 19:13:45.000000000 +0530
@@ -3466,6 +3466,31 @@ SfxVoidItem GraphicDialog FN_FORMAT_GRAF
 ]
 
 //--------------------------------------------------------------------------
+SfxVoidItem SaveGraphic FN_SAVE_GRAPHIC
+()
+[
+       /* flags: */
+       AutoUpdate = FALSE,
+       Cachable = Cachable,
+       FastCall = FALSE,
+       HasCoreId = FALSE,
+       HasDialog = TRUE,
+       ReadOnlyDoc = FALSE,
+       Toggle = FALSE,
+       Container = FALSE,
+       RecordAbsolute = FALSE,
+       RecordPerItem;
+       Asynchron;
+
+       /* config: */
+       AccelConfig = TRUE,
+       MenuConfig = TRUE,
+       StatusBarConfig = FALSE,
+       ToolBoxConfig = TRUE,
+       GroupId = GID_GRAPHIC;
+]
+
+//--------------------------------------------------------------------------
 SfxVoidItem Grow FN_GROW_FONT_SIZE
 ()
 [

With that, we are ready to use our brand new sfx item and we'll use it by adding it into the popup menu that is specified as MN_GRF_POPUPMENU in mn.src:

--- sw/source/ui/app/mn.src     2004-11-29 14:29:10.000000000 +0530
+++ sw/source/ui/app/mn.src     2004-12-21 20:28:27.000000000 +0530
@@ -945,6 +945,13 @@ Menu MN_GRF_POPUPMENU
                SEPARATOR ;
         MenuItem
         {
+            Identifier = FN_SAVE_GRAPHIC ; 
+            HelpID = FN_SAVE_GRAPHIC ; 
+            Text [ de ] = "~Grafik speichern..." ; 
+            Text [ en-US ] = "Save ~Graphic..." ; 
+        };
+        MenuItem
+        {
             Identifier = FN_FORMAT_GRAFIC_DLG ; 
             HelpID = FN_FORMAT_GRAFIC_DLG ; 
             Text [ de ] = "~Grafik..." ; 

That adds in the item to the menu and we still need to define what happens when it is clicked as we have specified in our handler that it invokes the Execute method, so we'll fill out the handler for this item in that method:

--- sw/source/ui/shells/grfsh.cxx       2004-12-07 18:57:35.000000000 +0530
+++ sw/source/ui/shells/grfsh.cxx       2004-12-21 22:19:53.684296352 +0530
@@ -217,6 +227,11 @@ void SwGrfShell::Execute(SfxRequest &rRe
        USHORT nSlot = rReq.GetSlot();
        switch(nSlot)
        {
+               case FN_SAVE_GRAPHIC:
+                   SaveGraphic();
+                   rReq.Ignore();
+                   break;
+
                case SID_INSERT_GRAPHIC:
                case FN_FORMAT_GRAFIC_DLG:
                {

So we define a method called SaveGraphic that will be invoked when this item is clicked, and then the definition of the method:

--- sw/source/ui/shells/grfsh.cxx       2004-12-07 18:57:35.000000000 +0530
+++ sw/source/ui/shells/grfsh.cxx       2004-12-21 22:19:53.684296352 +0530
@@ -739,6 +754,20 @@ void SwGrfShell::GetAttrState(SfxItemSet
 }
 
 
+void SwGrfShell::SaveGraphic()
+{
+       using namespace ::sfx2;
+       using namespace com::sun::star::ui::dialogs;
+       using namespace ::com::sun::star::uno;
+
+       FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_SIMPLE, 0 );
+       Reference  < XFilePicker > xFP = aDlgHelper.GetFilePicker();
+       aDlgHelper.Execute();
+
+       InfoBox( NULL, xFP->getFiles()[0] ).Execute();
+}
+
+
 SwGrfShell::SwGrfShell(SwView &rView) :
        SwBaseShell(rView)

Can you predict what the function does ? :-) As promised, it launches a dialog box that is definitely bigger than an InfoBox and then follows up with an InfoBox anyway :-D

For all these objects we have used, we need to declare them as well:

--- sw/source/ui/shells/grfsh.cxx       2004-12-07 18:57:35.000000000 +0530
+++ sw/source/ui/shells/grfsh.cxx       2004-12-21 22:19:53.684296352 +0530
@@ -137,6 +137,16 @@<br>
 #include <svx/tbxcolor.hxx><br>

 #endif
 
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
+#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
+#endif
+#ifndef  _COM_SUN_STAR_UI_DIALOGS_TEMPLATEDESCRIPTION_HPP_
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#endif
+#ifndef _FILEDLGHELPER_HXX
+#include <sfx2/filedlghelper.hxx>
+#endif
+
 #ifndef _FMTURL_HXX //autogen
 #include <fmturl.hxx>
 #endif

And we also have to declare the new method that we have added to the class in the class definition:

--- sw/source/ui/inc/grfsh.hxx  2000-10-05 17:04:19.000000000 +0530
+++ sw/source/ui/inc/grfsh.hxx  2004-12-21 19:24:14.000000000 +0530
@@ -71,6 +71,7 @@ public:
        void    Execute(SfxRequest &);
        void    ExecAttr(SfxRequest &);
        void    GetAttrState(SfxItemSet &);
+       void    SaveGraphic();
 
                        SwGrfShell(SwView &rView);
 };

So there stands the porting of the wonderful sd-save-image-context-menu as we plan to apply to Writer. We still need to extract the selected graphic out of Writer and save it to disk. If that is done, the patch would be complete :-)

Any takers ? :-)

But after understanding this, we can understand another hack on which this is based - the hack in Impress that allows the same capability, the difference being that it is complete! :-)

以上只是核心的步骤,当然还有如何增加界面图标,以及界面如何和功能关联增加不在此描述。

1
0
查看评论

cinder添加一个新功能流程

功能: List manageable volumes 1. 添加版本支持: cinder/api/openstack/api_version_request.py 2. 修改:  cinder/api/v3/router.py 3. 增加文件:...
  • dengxiafubi
  • dengxiafubi
  • 2017-11-17 14:25
  • 57

【初级】VS2015/MFC动态创建工具栏1(使用图标创建工具栏)

使用图标创建工具条,首先要创建图标列表,然后用工具栏关联相关图像列表,首先调用Create方法创建工具栏窗口,然后调用SetButtons方法设置工具栏按钮的索引,通过GetToolBarCtrl方法调用SetImageList方法关联图像列表,调用SetSizeas方法设置工具栏按钮和显示图标的大...
  • CSDNzhwk
  • CSDNzhwk
  • 2015-08-13 21:07
  • 2141

给视图添加工作栏和菜单栏

  在视图添加Action和菜单很简单,我们用RCP自带的邮件模板新建一个RCP工程,将一些无用的代码删除,然后在View.java中声明一个Action对象,我们将这个Action对象加入到View的工具栏上,代码很简单,代码如下 package com.vwpolo.rcp....
  • vwpolo
  • vwpolo
  • 2008-03-04 17:14
  • 1352

添加工具栏的图标按钮

有三种方法可以添加工具栏的图标按钮: 第一种:创建CImageList对象,然后往里面加图标,调用SetImageList方法添加图标,具体步骤如下: m_ImageList.Create(32,32,ILC_COLOR24|ILC_MASK,1,1); //向图像列表中添加图标 m_ImageLi...
  • tengxiaoming
  • tengxiaoming
  • 2010-05-31 01:11
  • 5953

如何:向 Windows 窗体应用程序添加工具栏

您可以轻松地向应用程序添加工具栏,方法是添加一个 ToolStrip 控件,然后再向此工具栏添加一些按钮。您可以添加单独的 ToolStripButton 控件,也可以从一组控件中进行选择(如 ToolStripTextBox 控件)。您可...
  • tyl314
  • tyl314
  • 2013-04-13 19:51
  • 2038

给工具栏按钮添加图标和文字

假设工具栏有两个按钮,为每个按钮添加图标和文字1.新建一个单文档程序,将准备好的图标资源(32×32)复制到res文件夹.2.在资源中打开工具栏编辑器,删除(del)原有的位图和多余的按钮(将按钮拖出工具栏即可删除),并为每个按钮修改ID(双击),比如ID_BTN1~ID_BTN2,可在P...
  • birdzb
  • birdzb
  • 2007-08-02 21:02
  • 3449

给对话框添加菜单 工具栏 状态栏简易方法

先建立一个基于Dialog 的程序,我给他起了个名字叫:DlgMenuToolbar。一、如何往基于Dialog的程序添加菜单[1.1] 先添加菜单(IDR_MENU1)资源,并加上需要的菜单项。[1.2] 编辑对话框资源IDD_DLGMENUTOOLBAR_DIALO...
  • qj840828
  • qj840828
  • 2008-10-17 16:23
  • 5722

vs2010 添加删除工具栏资源的上图标按钮

VS2010 中如果要删除工具栏上多余的图标,直接用DEL 键,或右键菜单中的删除选项,却不能完全删除完,删除后留下了黑块,图标不见命令照常执行,其实正确操作是鼠标左键按住不放,往工具条外一拉就删除了。        添加的操作是选中一个按钮复制后再最后...
  • qing666888
  • qing666888
  • 2016-01-09 20:01
  • 1889

编译LibreOffice for Android

基本环境 系统环境 ubuntu 17.0 jdk 环境 oracle 1.8 android sdk 25.2.5 ndk 14 编译准备 拉取源码 git clone git://anongit.freedesktop.org/libreoffice/core libreoffice ...
  • u011181222
  • u011181222
  • 2017-07-05 22:07
  • 426

为工具栏添加文字

 http://www.vckbase.com/document/viewdoc/?id=266
  • ZiSheng
  • ZiSheng
  • 2007-12-09 16:02
  • 477
    个人资料
    • 访问:11981次
    • 积分:462
    • 等级:
    • 排名:千里之外
    • 原创:32篇
    • 转载:3篇
    • 译文:0篇
    • 评论:6条
    最新评论