Difference between revisions of "Tutorial Writer"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
 
(One intermediate revision by one other user not shown)
Line 12: Line 12:
 
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:
 
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:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/inc/cmdid.h      2004-12-07 18:57:10.000000000 +0530
 
--- sw/inc/cmdid.h      2004-12-07 18:57:10.000000000 +0530
 
+++ sw/inc/cmdid.h      2004-12-21 19:08:39.000000000 +0530
 
+++ sw/inc/cmdid.h      2004-12-21 19:08:39.000000000 +0530
Line 22: Line 22:
 
   
 
   
 
  #define FN_SAVE_SELECTION      (FN_FILE + 35)    /* Selektion speichern */
 
  #define FN_SAVE_SELECTION      (FN_FILE + 35)    /* Selektion speichern */
−
</pre>
+
</syntaxhighlight>
 
   
 
   
 
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:
 
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:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/sdi/_grfsh.sdi  2004-10-15 16:13:21.000000000 +0530
 
--- sw/sdi/_grfsh.sdi  2004-10-15 16:13:21.000000000 +0530
 
+++ sw/sdi/_grfsh.sdi  2004-12-21 20:15:52.000000000 +0530
 
+++ sw/sdi/_grfsh.sdi  2004-12-21 20:15:52.000000000 +0530
Line 43: Line 43:
 
         [
 
         [
 
                 ExecMethod = Execute ;
 
                 ExecMethod = Execute ;
−
</pre>
+
</syntaxhighlight>
  
 
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:
 
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:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/sdi/swriter.sdi  2004-11-29 14:28:57.000000000 +0530
 
--- sw/sdi/swriter.sdi  2004-11-29 14:28:57.000000000 +0530
 
+++ sw/sdi/swriter.sdi  2004-12-21 19:13:45.000000000 +0530
 
+++ sw/sdi/swriter.sdi  2004-12-21 19:13:45.000000000 +0530
Line 82: Line 82:
 
  ()
 
  ()
 
  [
 
  [
−
</pre>
+
</syntaxhighlight>
  
 
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:
 
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:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/source/ui/app/mn.src    2004-11-29 14:29:10.000000000 +0530
 
--- 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
 
+++ sw/source/ui/app/mn.src    2004-12-21 20:28:27.000000000 +0530
Line 103: Line 103:
 
             HelpID = FN_FORMAT_GRAFIC_DLG ;  
 
             HelpID = FN_FORMAT_GRAFIC_DLG ;  
 
             Text [ de ] = "~Grafik..." ;  
 
             Text [ de ] = "~Grafik..." ;  
−
</pre>
+
</syntaxhighlight>
  
 
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:
 
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:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/source/ui/shells/grfsh.cxx      2004-12-07 18:57:35.000000000 +0530
 
--- 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
 
+++ sw/source/ui/shells/grfsh.cxx      2004-12-21 22:19:53.684296352 +0530
Line 122: Line 122:
 
                 case FN_FORMAT_GRAFIC_DLG:
 
                 case FN_FORMAT_GRAFIC_DLG:
 
                 {
 
                 {
−
</pre>
+
</syntaxhighlight>
  
 
So we define a method called SaveGraphic that will be invoked when this item is clicked, and then the definition of the method:
 
So we define a method called SaveGraphic that will be invoked when this item is clicked, and then the definition of the method:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/source/ui/shells/grfsh.cxx      2004-12-07 18:57:35.000000000 +0530
 
--- 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
 
+++ sw/source/ui/shells/grfsh.cxx      2004-12-21 22:19:53.684296352 +0530
Line 149: Line 149:
 
  SwGrfShell::SwGrfShell(SwView &amp;rView) :
 
  SwGrfShell::SwGrfShell(SwView &amp;rView) :
 
         SwBaseShell(rView)
 
         SwBaseShell(rView)
−
</pre>
+
</syntaxhighlight>
 
   
 
   
 
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
 
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
Line 155: Line 155:
 
For all these objects we have used, we need to declare them as well:
 
For all these objects we have used, we need to declare them as well:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/source/ui/shells/grfsh.cxx      2004-12-07 18:57:35.000000000 +0530
 
--- 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
 
+++ sw/source/ui/shells/grfsh.cxx      2004-12-21 22:19:53.684296352 +0530
Line 176: Line 176:
 
  #include &lt;fmturl.hxx&gt;
 
  #include &lt;fmturl.hxx&gt;
 
  #endif
 
  #endif
−
</pre>
+
</syntaxhighlight>
  
 
And we also have to declare the new method that we have added to the class in the class definition:
 
And we also have to declare the new method that we have added to the class in the class definition:
  
−
<pre>
+
<syntaxhighlight lang="cpp">
 
--- sw/source/ui/inc/grfsh.hxx  2000-10-05 17:04:19.000000000 +0530
 
--- 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
 
+++ sw/source/ui/inc/grfsh.hxx  2004-12-21 19:24:14.000000000 +0530
Line 191: Line 191:
 
                         SwGrfShell(SwView &amp;rView);
 
                         SwGrfShell(SwView &amp;rView);
 
  };
 
  };
−
</pre>
+
</syntaxhighlight>
  
 
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 :-)
 
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 :-)
Line 208: Line 208:
 
</table>
 
</table>
  
−
[[Category:Tutorials]]
+
[[Category:Tutorial]]

Latest revision as of 15:04, 26 December 2025

Hack Writer! Tutorial_Help

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 &amp;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  &lt; XFilePicker &gt; xFP = aDlgHelper.GetFilePicker();
+       aDlgHelper.Execute();
+
+       InfoBox( NULL, xFP-&gt;getFiles()[0] ).Execute();
+}
+
+
 SwGrfShell::SwGrfShell(SwView &amp;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 &lt;svx/tbxcolor.hxx&gt;<br>

 #endif
 
+#ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_
+#include &lt;com/sun/star/ui/dialogs/XFilePicker.hpp&gt;
+#endif
+#ifndef  _COM_SUN_STAR_UI_DIALOGS_TEMPLATEDESCRIPTION_HPP_
+#include &lt;com/sun/star/ui/dialogs/TemplateDescription.hpp&gt;
+#endif
+#ifndef _FILEDLGHELPER_HXX
+#include &lt;sfx2/filedlghelper.hxx&gt;
+#endif
+
 #ifndef _FMTURL_HXX //autogen
 #include &lt;fmturl.hxx&gt;
 #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 &amp;);
        void    ExecAttr(SfxRequest &amp;);
        void    GetAttrState(SfxItemSet &amp;);
+       void    SaveGraphic();
 
                        SwGrfShell(SwView &amp;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! :-)


sw-save-image-context-menu.diff Next: Tutorial_Impress
Personal tools