2013년 3월 5일 화요일

vsto 상단 버튼 만들기




http://blog.naver.com/nettalk72/40043967801
http://msdn.microsoft.com/en-us/library/office/bb226712(v=office.12).aspx



보통 VSTO 를 가지고 서는 Word 와 Excel 을 주로 다루고 있다.
이번에 설명하고 하는 것은 PowerPoint 2007 이다. (전체 Full 소스 참조)

물론, PowerPoint 에 대한 자료는 극히 적다. 인터넷을 찾아봐도, 이렇다할 자료가 있지 않음을 확인했다.
돌고 돌다가, http://msdn2.microsoft.com/ko-kr/office/aa905465.aspx 의 PowerPoint 개발 Portal 에서 시작해야 할것 같다.

이번에 설명할 것은 간단하게 ?  템플릿을 적용하고, 새로운 슬라이드및 이미지 슬라이드를 추가 시키는 방법을 설명할 것이다.
이렇게 만들어진 최종 결과는 아래 화면과 비슷하다.

 

그럼 우선 VS.NET2005에서 Powerpoint addin 을 만든다.
그리고 새로운 아이템으로 Ribbon 컨트롤을 추가한다. 이는 위 화면상에 있는 3개의 HappyFace 버튼들을 만들기 위한 것이다.


Add를 선택해서 추가시킨다.

그러면 Ribbon1.cs 와 함께 Ribbon1.xml 이 추가된다.
옆화면처럼 기존 데이타를 변경시킨다.

(Ribbon1.xml 에 것은 추후 Ribbon 만을 상세히 다루는 글을 게재할 예정이다. 이는 기본적인 XML을 수정하는 것과 VS.NET 2008 Beta2 부터 추가된 디자인 툴을 통해서 이뤄진다 )

 
 

이렇게 지정하는 것만으로도 HappyFace 이미지를 가진 버튼 3개가 나타날 환경이 갖쳐졌다.
이제 이를 나타나도록 지시해야 하는데,
Addin 이 호출될때 불려지는 RequestService 메서드에서 생성된 Ribbon을 리턴하므로써 전달 된다.

이를 위해서 Ribbon1.cs 의 첫번쨰 라인에 설명이 나온대로 Uncomment 를 해야 한다.

 // TODO:
 // This is an override of the RequestService method in the ThisAddIn class.
 // To hook up your custom ribbon uncomment this code.
 ...
 //

이 과정으로 Ribbon 에 버튼이 나타날 것이다. 그러나, Button 을 클릭시 해당 하는 코드(메서드)들을 만들어 줘야 한다.
이는  button 에 대해서는 메서드 이름은 XML 에서 정의하고 파라미터는 사전에 button 에 대해서 정의가 되어 있다.
(Ribbon 에 사용되는 모든 컨트롤 들은 자신만의 고유한 파라미터가 미리 정의되어 있다. 이에 대한것은 다음에 살펴볼것이다.)

아래는 Button1 의 클릭시 실행되는 메서드 이다. 

    public void OnButton1(Office.IRibbonControl control)
    {
      // 현재 활성중인 Presentation 을 얻어낸다.
      PowerPoint.Presentation presentation =  Globals.ThisAddIn.Application.ActivePresentation;

      // 기본 Layout 으로 Title 을 선택한다.
      PowerPoint.CustomLayout customLayout =
                       presentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutTitle];

      // 첫위치에 삽입한다.
      PowerPoint.Slide slide = presentation.Slides.AddSlide(1, customLayout);

      // Shape 의 Text 에 값을 입력한다.
      slide.Shapes.Title.TextFrame.TextRange.Text = "VSTO 2005 SE";
      slide.Shapes[2].TextFrame.TextRange.Text = "Nettalk's VSTO Story";
     
      // 템플릿을 지정한다.
      presentation.ApplyTemplate(@"C:\Program Files\Microsoft Office\Document Themes 12\paper.thmx");
   }

다음은 Button2 에 대한 메서드이다.

    public void OnButton2(Office.IRibbonControl control)
    {
        // 현재 활성중인 Presentation 을 얻어낸다.
        PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
  
        // 기본 Layout 으로 Text 을 선택한다.
        PowerPoint.CustomLayout customLayout =
               presentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutText];

        // 마지막 위치에 삽입한다.
        presentation.Slides.AddSlide(presentation.Slides.Count + 1, customLayout);
    }

다음은 Button3 에 대한 메서드 이다.

  public void OnButton3(Office.IRibbonControl control)
    {
      OpenFileDialog dialog = new OpenFileDialog();
      dialog.Filter =
        "All pictures (*.jpg,*.jpeg,*.bmp,*.gif,*.tif)|" +
        "*.jpf;*.jpeg;*.bmp;*.gif;*.tif|" +
        "All files (*.*)|*.*";
      dialog.CheckFileExists = true;
      if (dialog.ShowDialog() == DialogResult.OK)
      {
        AddPicture(dialog.FileName);
      }
    }

    public void AddPicture(String pictureFileName)
    {
        PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
        if (presentation != null)
        {
          // 새로운 Layout (PictureWithCaption)를 추가한다.
          PowerPoint.Slide slide =  presentation.Slides.Add(presentation.Slides.Count + 1,
                                                          PowerPoint.PpSlideLayout.ppLayoutPictureWithCaption);
          // Shapes[2] 는 선택된 부분이 Image 이다.
          PowerPoint.Shape shape = slide.Shapes[2];

          // AddPicture 를 통해서 이미지를 삽입한다.
          slide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse,
                                         Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

          // 파일 이름을 추가(표시) 한다.
          slide.Shapes[1].TextFrame.TextRange.Text = pictureFileName;
          slide.Select();
        }
    }

outlook imageMso





http://soltechs.net/CustomUI/imageMso01.asp?gal=1&count=no



Available Button Graphics for the Word Custom UI Ribbon Control
This is down and dirty, but it works.
  • Click the Gallery link (Gal 1 through Gal 9) to see the images and the imageMso name you need all in one place.
  • Click in the Text Box with the imageMso information. It will select the text and you can copy and paste it into your project...
  • The galleries have between 245 and 321 individual .JPG images in them, so they take a while to load. The "All (overview)" page contains all 2,577 images in a static display.
Excuse the fact that not all the graphics here are perfect. Somehow Microsoft decided that just a few of there pieces of graphic should be 21x20 while about 99 % of them (on the Small Galleries) where 20x20. I did not take the time to clean up the funky ones. The graphics that show in the Ribbon will be complete.
 
Gal 1 (Large)Gal 2 (Large)Gal 3 (Large)Gal 4 (Small)Gal 5 (Small)
Gal 6 (Small)Gal 7 (Small)Gal 8 (Small)Gal 9 (Small)All (overview)

Gallery #1 - 256 Total Images
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253 
254 
255 
256