quartz/tests: Remove misplaced ok() call.
[wine] / dlls / mshtml / editor.c
1 /*
2  * Copyright 2006-2007 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20 #include <stdio.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "mshtmcid.h"
29
30 #include "wine/debug.h"
31
32 #include "mshtml_private.h"
33 #include "resource.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36
37 #define NSCMD_ALIGN        "cmd_align"
38 #define NSCMD_BEGINLINE    "cmd_beginLine"
39 #define NSCMD_BOLD         "cmd_bold"
40 #define NSCMD_CHARNEXT     "cmd_charNext"
41 #define NSCMD_CHARPREVIOUS "cmd_charPrevious"
42 #define NSCMD_COPY         "cmd_copy"
43 #define NSCMD_CUT          "cmd_cut"
44 #define NSCMD_DELETECHARFORWARD   "cmd_deleteCharForward"
45 #define NSCMD_DELETEWORDFORWARD   "cmd_deleteWordForward"
46 #define NSCMD_ENDLINE      "cmd_endLine"
47 #define NSCMD_FONTCOLOR    "cmd_fontColor"
48 #define NSCMD_FONTFACE     "cmd_fontFace"
49 #define NSCMD_INDENT       "cmd_indent"
50 #define NSCMD_INSERTHR     "cmd_insertHR"
51 #define NSCMD_INSERTLINKNOUI    "cmd_insertLinkNoUI"
52 #define NSCMD_ITALIC       "cmd_italic"
53 #define NSCMD_LINENEXT     "cmd_lineNext"
54 #define NSCMD_LINEPREVIOUS "cmd_linePrevious"
55 #define NSCMD_MOVEBOTTOM   "cmd_moveBottom"
56 #define NSCMD_MOVEPAGEDOWN "cmd_movePageDown"
57 #define NSCMD_MOVEPAGEUP   "cmd_movePageUp"
58 #define NSCMD_MOVETOP      "cmd_moveTop"
59 #define NSCMD_OL           "cmd_ol"
60 #define NSCMD_OUTDENT      "cmd_outdent"
61 #define NSCMD_PASTE        "cmd_paste"
62 #define NSCMD_SELECTALL           "cmd_selectAll"
63 #define NSCMD_SELECTBEGINLINE     "cmd_selectBeginLine"
64 #define NSCMD_SELECTBOTTOM        "cmd_selectBottom"
65 #define NSCMD_SELECTCHARNEXT      "cmd_selectCharNext"
66 #define NSCMD_SELECTCHARPREVIOUS  "cmd_selectCharPrevious"
67 #define NSCMD_SELECTENDLINE       "cmd_selectEndLine"
68 #define NSCMD_SELECTLINENEXT      "cmd_selectLineNext"
69 #define NSCMD_SELECTLINEPREVIOUS  "cmd_selectLinePrevious"
70 #define NSCMD_SELECTPAGEDOWN      "cmd_selectPageDown"
71 #define NSCMD_SELECTPAGEUP        "cmd_selectPageUp"
72 #define NSCMD_SELECTTOP           "cmd_selectTop"
73 #define NSCMD_SELECTWORDNEXT      "cmd_selectWordNext"
74 #define NSCMD_SELECTWORDPREVIOUS  "cmd_selectWordPrevious"
75 #define NSCMD_UL           "cmd_ul"
76 #define NSCMD_UNDERLINE    "cmd_underline"
77 #define NSCMD_WORDNEXT     "cmd_wordNext"
78 #define NSCMD_WORDPREVIOUS "cmd_wordPrevious"
79
80 #define NSSTATE_ATTRIBUTE "state_attribute"
81 #define NSSTATE_ALL       "state_all"
82
83 #define NSALIGN_CENTER "center"
84 #define NSALIGN_LEFT   "left"
85 #define NSALIGN_RIGHT  "right"
86
87 #define DOM_VK_LEFT     VK_LEFT
88 #define DOM_VK_UP       VK_UP
89 #define DOM_VK_RIGHT    VK_RIGHT
90 #define DOM_VK_DOWN     VK_DOWN
91 #define DOM_VK_DELETE   VK_DELETE
92 #define DOM_VK_HOME     VK_HOME
93 #define DOM_VK_END      VK_END
94
95 static const WCHAR fontW[] = {'f','o','n','t',0};
96 static const WCHAR sizeW[] = {'s','i','z','e',0};
97
98 void set_dirty(HTMLDocument *This, VARIANT_BOOL dirty)
99 {
100     nsresult nsres;
101
102     if(This->doc_obj->usermode != EDITMODE || !This->doc_obj->nscontainer || !This->doc_obj->nscontainer->editor)
103         return;
104
105     if(dirty) {
106         nsres = nsIEditor_IncrementModificationCount(This->doc_obj->nscontainer->editor, 1);
107         if(NS_FAILED(nsres))
108             ERR("IncrementModificationCount failed: %08x\n", nsres);
109     }else {
110         nsres = nsIEditor_ResetModificationCount(This->doc_obj->nscontainer->editor);
111         if(NS_FAILED(nsres))
112             ERR("ResetModificationCount failed: %08x\n", nsres);
113     }
114 }
115
116 static void do_ns_editor_command(NSContainer *This, const char *cmd)
117 {
118     nsresult nsres;
119
120     if(!This->editor_controller)
121         return;
122
123     nsres = nsIController_DoCommand(This->editor_controller, cmd);
124     if(NS_FAILED(nsres))
125         ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd), nsres);
126 }
127
128 static nsresult get_ns_command_state(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
129 {
130     nsICommandManager *cmdmgr;
131     nsresult nsres;
132
133     nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsICommandManager, (void**)&cmdmgr);
134     if(NS_FAILED(nsres)) {
135         ERR("Could not get nsICommandManager: %08x\n", nsres);
136         return nsres;
137     }
138
139     nsres = nsICommandManager_GetCommandState(cmdmgr, cmd, This->doc->basedoc.window->nswindow, nsparam);
140     if(NS_FAILED(nsres))
141         ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd), nsres);
142
143     nsICommandManager_Release(cmdmgr);
144     return nsres;
145 }
146
147 static DWORD query_ns_edit_status(HTMLDocument *This, const char *nscmd)
148 {
149     nsICommandParams *nsparam;
150     cpp_bool b = FALSE;
151
152     if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
153         return OLECMDF_SUPPORTED;
154
155     if(This->doc_obj->nscontainer && nscmd) {
156         nsparam = create_nscommand_params();
157         get_ns_command_state(This->doc_obj->nscontainer, nscmd, nsparam);
158
159         nsICommandParams_GetBooleanValue(nsparam, NSSTATE_ALL, &b);
160
161         nsICommandParams_Release(nsparam);
162     }
163
164     return OLECMDF_SUPPORTED | OLECMDF_ENABLED | (b ? OLECMDF_LATCHED : 0);
165 }
166
167 static void set_ns_align(HTMLDocument *This, const char *align_str)
168 {
169     nsICommandParams *nsparam;
170
171     if(!This->doc_obj->nscontainer)
172         return;
173
174     nsparam = create_nscommand_params();
175     nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, align_str);
176
177     do_ns_command(This, NSCMD_ALIGN, nsparam);
178
179     nsICommandParams_Release(nsparam);
180 }
181
182 static DWORD query_align_status(HTMLDocument *This, const WCHAR *align)
183 {
184     DWORD ret = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
185     nsAString justify_str;
186     cpp_bool b;
187     nsresult nsres;
188
189     if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
190         return OLECMDF_SUPPORTED;
191
192     nsAString_Init(&justify_str, align);
193     nsres = nsIDOMHTMLDocument_QueryCommandState(This->doc_node->nsdoc, &justify_str, &b);
194     nsAString_Finish(&justify_str);
195     if(NS_SUCCEEDED(nsres) && b)
196         ret |= OLECMDF_LATCHED;
197
198     return ret;
199 }
200
201
202 static nsISelection *get_ns_selection(HTMLDocument *This)
203 {
204     nsISelection *nsselection = NULL;
205     nsresult nsres;
206
207     nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
208     if(NS_FAILED(nsres))
209         ERR("GetSelection failed %08x\n", nsres);
210
211     return nsselection;
212
213 }
214
215 static void remove_child_attr(nsIDOMElement *elem, LPCWSTR tag, nsAString *attr_str)
216 {
217     cpp_bool has_children;
218     PRUint32 child_cnt, i;
219     nsIDOMNode *child_node;
220     nsIDOMNodeList *node_list;
221     PRUint16 node_type;
222
223     nsIDOMElement_HasChildNodes(elem, &has_children);
224     if(!has_children)
225         return;
226
227     nsIDOMElement_GetChildNodes(elem, &node_list);
228     nsIDOMNodeList_GetLength(node_list, &child_cnt);
229
230     for(i=0; i<child_cnt; i++) {
231         nsIDOMNodeList_Item(node_list, i, &child_node);
232
233         nsIDOMNode_GetNodeType(child_node, &node_type);
234         if(node_type == ELEMENT_NODE) {
235             nsIDOMElement *child_elem;
236             nsAString tag_str;
237             const PRUnichar *ctag;
238
239             nsIDOMNode_QueryInterface(child_node, &IID_nsIDOMElement, (void**)&child_elem);
240
241             nsAString_Init(&tag_str, NULL);
242             nsIDOMElement_GetTagName(child_elem, &tag_str);
243             nsAString_GetData(&tag_str, &ctag);
244
245             if(!strcmpiW(ctag, tag))
246                 /* FIXME: remove node if there are no more attributes */
247                 nsIDOMElement_RemoveAttribute(child_elem, attr_str);
248
249             nsAString_Finish(&tag_str);
250
251             remove_child_attr(child_elem, tag, attr_str);
252
253             nsIDOMNode_Release(child_elem);
254         }
255
256         nsIDOMNode_Release(child_node);
257     }
258
259     nsIDOMNodeList_Release(node_list);
260 }
261
262 static void get_font_size(HTMLDocument *This, WCHAR *ret)
263 {
264     nsISelection *nsselection = get_ns_selection(This);
265     nsIDOMElement *elem = NULL;
266     nsIDOMNode *node = NULL, *tmp_node;
267     nsAString tag_str;
268     LPCWSTR tag;
269     PRUint16 node_type;
270     nsresult nsres;
271
272     *ret = 0;
273
274     if(!nsselection)
275         return;
276
277     nsISelection_GetFocusNode(nsselection, &node);
278     nsISelection_Release(nsselection);
279
280     while(node) {
281         nsres = nsIDOMNode_GetNodeType(node, &node_type);
282         if(NS_FAILED(nsres) || node_type == DOCUMENT_NODE)
283             break;
284
285         if(node_type == ELEMENT_NODE) {
286             nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
287
288             nsAString_Init(&tag_str, NULL);
289             nsIDOMElement_GetTagName(elem, &tag_str);
290             nsAString_GetData(&tag_str, &tag);
291
292             if(!strcmpiW(tag, fontW)) {
293                 nsAString size_str, val_str;
294                 LPCWSTR val;
295
296                 TRACE("found font tag %p\n", elem);
297
298                 nsAString_InitDepend(&size_str, sizeW);
299                 nsAString_Init(&val_str, NULL);
300
301                 nsIDOMElement_GetAttribute(elem, &size_str, &val_str);
302                 nsAString_GetData(&val_str, &val);
303
304                 if(*val) {
305                     TRACE("found size %s\n", debugstr_w(val));
306                     strcpyW(ret, val);
307                 }
308
309                 nsAString_Finish(&size_str);
310                 nsAString_Finish(&val_str);
311             }
312
313             nsAString_Finish(&tag_str);
314
315             nsIDOMElement_Release(elem);
316         }
317
318         if(*ret)
319             break;
320
321         tmp_node = node;
322         nsIDOMNode_GetParentNode(node, &node);
323         nsIDOMNode_Release(tmp_node);
324     }
325
326     if(node)
327         nsIDOMNode_Release(node);
328 }
329
330 static void set_font_size(HTMLDocument *This, LPCWSTR size)
331 {
332     nsISelection *nsselection;
333     cpp_bool collapsed;
334     nsIDOMHTMLElement *elem;
335     nsIDOMRange *range;
336     PRInt32 range_cnt = 0;
337     nsAString size_str;
338     nsAString val_str;
339
340     if(!This->doc_node->nsdoc) {
341         WARN("NULL nsdoc\n");
342         return;
343     }
344
345     nsselection = get_ns_selection(This);
346     if(!nsselection)
347         return;
348
349     nsISelection_GetRangeCount(nsselection, &range_cnt);
350     if(range_cnt != 1) {
351         FIXME("range_cnt %d not supprted\n", range_cnt);
352         if(!range_cnt) {
353             nsISelection_Release(nsselection);
354             return;
355         }
356     }
357
358     create_nselem(This->doc_node, fontW, &elem);
359
360     nsAString_InitDepend(&size_str, sizeW);
361     nsAString_InitDepend(&val_str, size);
362
363     nsIDOMElement_SetAttribute(elem, &size_str, &val_str);
364     nsAString_Finish(&val_str);
365
366     nsISelection_GetRangeAt(nsselection, 0, &range);
367     nsISelection_GetIsCollapsed(nsselection, &collapsed);
368     nsISelection_RemoveAllRanges(nsselection);
369
370     nsIDOMRange_SurroundContents(range, (nsIDOMNode*)elem);
371
372     if(collapsed) {
373         nsISelection_Collapse(nsselection, (nsIDOMNode*)elem, 0);
374     }else {
375         /* Remove all size attributes from the range */
376         remove_child_attr((nsIDOMElement*)elem, fontW, &size_str);
377         nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)elem);
378     }
379
380     nsISelection_Release(nsselection);
381     nsIDOMRange_Release(range);
382     nsIDOMElement_Release(elem);
383
384     nsAString_Finish(&size_str);
385
386     set_dirty(This, VARIANT_TRUE);
387 }
388
389 static void handle_arrow_key(HTMLDocument *This, nsIDOMKeyEvent *event, const char * const cmds[4])
390 {
391     int i=0;
392     cpp_bool b;
393
394     nsIDOMKeyEvent_GetCtrlKey(event, &b);
395     if(b)
396         i |= 1;
397
398     nsIDOMKeyEvent_GetShiftKey(event, &b);
399     if(b)
400         i |= 2;
401
402     if(cmds[i])
403         do_ns_editor_command(This->doc_obj->nscontainer, cmds[i]);
404
405     nsIDOMKeyEvent_PreventDefault(event);
406 }
407
408 void handle_edit_event(HTMLDocument *This, nsIDOMEvent *event)
409 {
410     nsIDOMKeyEvent *key_event;
411     PRUint32 code;
412
413     nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
414
415     nsIDOMKeyEvent_GetKeyCode(key_event, &code);
416
417     switch(code) {
418     case DOM_VK_LEFT: {
419         static const char * const cmds[] = {
420             NSCMD_CHARPREVIOUS,
421             NSCMD_WORDPREVIOUS,
422             NSCMD_SELECTCHARPREVIOUS,
423             NSCMD_SELECTWORDPREVIOUS
424         };
425
426         TRACE("left\n");
427         handle_arrow_key(This, key_event, cmds);
428         break;
429     }
430     case DOM_VK_RIGHT: {
431         static const char * const cmds[] = {
432             NSCMD_CHARNEXT,
433             NSCMD_WORDNEXT,
434             NSCMD_SELECTCHARNEXT,
435             NSCMD_SELECTWORDNEXT
436         };
437
438         TRACE("right\n");
439         handle_arrow_key(This, key_event, cmds);
440         break;
441     }
442     case DOM_VK_UP: {
443         static const char * const cmds[] = {
444             NSCMD_LINEPREVIOUS,
445             NSCMD_MOVEPAGEUP,
446             NSCMD_SELECTLINEPREVIOUS,
447             NSCMD_SELECTPAGEUP
448         };
449
450         TRACE("up\n");
451         handle_arrow_key(This, key_event, cmds);
452         break;
453     }
454     case DOM_VK_DOWN: {
455         static const char * const cmds[] = {
456             NSCMD_LINENEXT,
457             NSCMD_MOVEPAGEDOWN,
458             NSCMD_SELECTLINENEXT,
459             NSCMD_SELECTPAGEDOWN
460         };
461
462         TRACE("down\n");
463         handle_arrow_key(This, key_event, cmds);
464         break;
465     }
466     case DOM_VK_DELETE: {
467         static const char * const cmds[] = {
468             NSCMD_DELETECHARFORWARD,
469             NSCMD_DELETEWORDFORWARD,
470             NULL, NULL
471         };
472
473         TRACE("delete\n");
474         handle_arrow_key(This, key_event, cmds);
475         break;
476     }
477     case DOM_VK_HOME: {
478         static const char * const cmds[] = {
479             NSCMD_BEGINLINE,
480             NSCMD_MOVETOP,
481             NSCMD_SELECTBEGINLINE,
482             NSCMD_SELECTTOP
483         };
484
485         TRACE("home\n");
486         handle_arrow_key(This, key_event, cmds);
487         break;
488     }
489     case DOM_VK_END: {
490         static const char * const cmds[] = {
491             NSCMD_ENDLINE,
492             NSCMD_MOVEBOTTOM,
493             NSCMD_SELECTENDLINE,
494             NSCMD_SELECTBOTTOM
495         };
496
497         TRACE("end\n");
498         handle_arrow_key(This, key_event, cmds);
499         break;
500     }
501     }
502
503     nsIDOMKeyEvent_Release(key_event);
504 }
505
506 void handle_edit_load(HTMLDocument *This)
507 {
508     get_editor_controller(This->doc_obj->nscontainer);
509 }
510
511 static void set_ns_fontname(HTMLDocument *This, const char *fontname)
512 {
513     nsICommandParams *nsparam = create_nscommand_params();
514
515     nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, fontname);
516     do_ns_command(This, NSCMD_FONTFACE, nsparam);
517     nsICommandParams_Release(nsparam);
518 }
519
520 static HRESULT exec_delete(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
521 {
522     TRACE("(%p)->(%p %p)\n", This, in, out);
523
524     if(This->doc_obj->nscontainer)
525         do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_DELETECHARFORWARD);
526
527     update_doc(This, UPDATE_UI);
528     return S_OK;
529 }
530
531 static HRESULT exec_fontname(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
532 {
533     TRACE("(%p)->(%p %p)\n", This, in, out);
534
535     if(!This->doc_obj->nscontainer) {
536         update_doc(This, UPDATE_UI);
537         return E_FAIL;
538     }
539
540     if(in) {
541         char *stra;
542
543         if(V_VT(in) != VT_BSTR) {
544             FIXME("Unsupported fontname %s\n", debugstr_variant(out));
545             return E_INVALIDARG;
546         }
547
548         TRACE("%s\n", debugstr_w(V_BSTR(in)));
549
550         stra = heap_strdupWtoA(V_BSTR(in));
551         set_ns_fontname(This, stra);
552         heap_free(stra);
553
554         update_doc(This, UPDATE_UI);
555     }
556
557     if(out) {
558         nsICommandParams *nsparam;
559         LPWSTR strw;
560         char *stra;
561         DWORD len;
562         nsresult nsres;
563
564         V_VT(out) = VT_BSTR;
565         V_BSTR(out) = NULL;
566
567         nsparam = create_nscommand_params();
568
569         nsres = get_ns_command_state(This->doc_obj->nscontainer, NSCMD_FONTFACE, nsparam);
570         if(NS_FAILED(nsres))
571             return S_OK;
572
573         nsICommandParams_GetCStringValue(nsparam, NSSTATE_ATTRIBUTE, &stra);
574         nsICommandParams_Release(nsparam);
575
576         len = MultiByteToWideChar(CP_ACP, 0, stra, -1, NULL, 0);
577         strw = heap_alloc(len*sizeof(WCHAR));
578         MultiByteToWideChar(CP_ACP, 0, stra, -1, strw, len);
579         nsfree(stra);
580
581         V_BSTR(out) = SysAllocString(strw);
582         heap_free(strw);
583     }
584
585     return S_OK;
586 }
587
588 static HRESULT exec_forecolor(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
589 {
590     TRACE("(%p)->(%p %p)\n", This, in, out);
591
592     if(in) {
593         if(V_VT(in) == VT_I4) {
594             nsICommandParams *nsparam = create_nscommand_params();
595             char color_str[10];
596
597             sprintf(color_str, "#%02x%02x%02x",
598                     V_I4(in)&0xff, (V_I4(in)>>8)&0xff, (V_I4(in)>>16)&0xff);
599
600             nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, color_str);
601             do_ns_command(This, NSCMD_FONTCOLOR, nsparam);
602
603             nsICommandParams_Release(nsparam);
604         }else {
605             FIXME("unsupported forecolor %s\n", debugstr_variant(in));
606         }
607
608         update_doc(This, UPDATE_UI);
609     }
610
611     if(out) {
612         FIXME("unsupported out\n");
613         return E_NOTIMPL;
614     }
615
616     return S_OK;
617 }
618
619 static HRESULT exec_fontsize(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
620 {
621     TRACE("(%p)->(%p %p)\n", This, in, out);
622
623     if(out) {
624         WCHAR val[10] = {0};
625
626         get_font_size(This, val);
627         V_VT(out) = VT_I4;
628         V_I4(out) = strtolW(val, NULL, 10);
629     }
630
631     if(in) {
632         switch(V_VT(in)) {
633         case VT_I4: {
634             WCHAR size[10];
635             static const WCHAR format[] = {'%','d',0};
636             wsprintfW(size, format, V_I4(in));
637             set_font_size(This, size);
638             break;
639         }
640         case VT_BSTR:
641             set_font_size(This, V_BSTR(in));
642             break;
643         default:
644             FIXME("unsupported fontsize %s\n", debugstr_variant(in));
645         }
646
647         update_doc(This, UPDATE_UI);
648     }
649
650     return S_OK;
651 }
652
653 static HRESULT exec_font(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
654 {
655
656     FIXME("(%p)->(%p %p)\n", This, in, out);
657     return E_NOTIMPL;
658 }
659
660 static HRESULT exec_selectall(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
661 {
662     TRACE("(%p)\n", This);
663
664     if(in || out)
665         FIXME("unsupported args\n");
666
667     if(This->doc_obj->nscontainer)
668         do_ns_command(This, NSCMD_SELECTALL, NULL);
669
670     update_doc(This, UPDATE_UI);
671     return S_OK;
672 }
673
674 static HRESULT exec_bold(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
675 {
676     TRACE("(%p)\n", This);
677
678     if(in || out)
679         FIXME("unsupported args\n");
680
681     if(This->doc_obj->nscontainer)
682         do_ns_command(This, NSCMD_BOLD, NULL);
683
684     update_doc(This, UPDATE_UI);
685     return S_OK;
686 }
687
688 static HRESULT exec_italic(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
689 {
690     TRACE("(%p)\n", This);
691
692     if(in || out)
693         FIXME("unsupported args\n");
694
695     if(This->doc_obj->nscontainer)
696         do_ns_command(This, NSCMD_ITALIC, NULL);
697
698     update_doc(This, UPDATE_UI);
699     return S_OK;
700 }
701
702 static HRESULT query_justify(HTMLDocument *This, OLECMD *cmd)
703 {
704     static const PRUnichar justifycenterW[] = {'j','u','s','t','i','f','y','c','e','n','t','e','r',0};
705     static const PRUnichar justifyrightW[] = {'j','u','s','t','i','f','y','r','i','g','h','t',0};
706
707     switch(cmd->cmdID) {
708     case IDM_JUSTIFYCENTER:
709         TRACE("(%p) IDM_JUSTIFYCENTER\n", This);
710         cmd->cmdf = query_align_status(This, justifycenterW);
711         break;
712     case IDM_JUSTIFYLEFT:
713         TRACE("(%p) IDM_JUSTIFYLEFT\n", This);
714         /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
715         if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
716             cmd->cmdf = OLECMDF_SUPPORTED;
717         else
718             cmd->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
719         break;
720     case IDM_JUSTIFYRIGHT:
721         TRACE("(%p) IDM_JUSTIFYRIGHT\n", This);
722         cmd->cmdf = query_align_status(This, justifyrightW);
723         break;
724     }
725
726     return S_OK;
727 }
728
729 static HRESULT exec_justifycenter(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
730 {
731     TRACE("(%p)\n", This);
732
733     if(in || out)
734         FIXME("unsupported args\n");
735
736     set_ns_align(This, NSALIGN_CENTER);
737     update_doc(This, UPDATE_UI);
738     return S_OK;
739 }
740
741 static HRESULT exec_justifyleft(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
742 {
743     TRACE("(%p)\n", This);
744
745     if(in || out)
746         FIXME("unsupported args\n");
747
748     set_ns_align(This, NSALIGN_LEFT);
749     update_doc(This, UPDATE_UI);
750     return S_OK;
751 }
752
753 static HRESULT exec_justifyright(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
754 {
755     TRACE("(%p)\n", This);
756
757     if(in || out)
758         FIXME("unsupported args\n");
759
760     set_ns_align(This, NSALIGN_RIGHT);
761     update_doc(This, UPDATE_UI);
762     return S_OK;
763 }
764
765 static HRESULT exec_underline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
766 {
767     TRACE("(%p)\n", This);
768
769     if(in || out)
770         FIXME("unsupported args\n");
771
772     do_ns_command(This, NSCMD_UNDERLINE, NULL);
773     update_doc(This, UPDATE_UI);
774     return S_OK;
775 }
776
777 static HRESULT exec_horizontalline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
778 {
779     TRACE("(%p)\n", This);
780
781     if(in || out)
782         FIXME("unsupported args\n");
783
784     do_ns_command(This, NSCMD_INSERTHR, NULL);
785     update_doc(This, UPDATE_UI);
786     return S_OK;
787 }
788
789 static HRESULT exec_orderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
790 {
791     TRACE("(%p)\n", This);
792
793     if(in || out)
794         FIXME("unsupported args\n");
795
796     do_ns_command(This, NSCMD_OL, NULL);
797     update_doc(This, UPDATE_UI);
798     return S_OK;
799 }
800
801 static HRESULT exec_unorderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
802 {
803     TRACE("(%p)\n", This);
804
805     if(in || out)
806         FIXME("unsupported args\n");
807
808     do_ns_command(This, NSCMD_UL, NULL);
809     update_doc(This, UPDATE_UI);
810     return S_OK;
811 }
812
813 static HRESULT exec_indent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
814 {
815     TRACE("(%p)\n", This);
816
817     if(in || out)
818         FIXME("unsupported args\n");
819
820     do_ns_command(This, NSCMD_INDENT, NULL);
821     update_doc(This, UPDATE_UI);
822     return S_OK;
823 }
824
825 static HRESULT exec_outdent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
826 {
827     TRACE("(%p)\n", This);
828
829     if(in || out)
830         FIXME("unsupported args\n");
831
832     do_ns_command(This, NSCMD_OUTDENT, NULL);
833     update_doc(This, UPDATE_UI);
834     return S_OK;
835 }
836
837 static HRESULT exec_composesettings(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
838 {
839     WCHAR *ptr;
840
841     if(out || !in || V_VT(in) != VT_BSTR) {
842         WARN("invalid arg %s\n", debugstr_variant(in));
843         return E_INVALIDARG;
844     }
845
846     TRACE("(%p)->(%x %s)\n", This, cmdexecopt, debugstr_w(V_BSTR(in)));
847
848     update_doc(This, UPDATE_UI);
849
850     ptr = V_BSTR(in);
851     if(*ptr == '1')
852         exec_bold(This, cmdexecopt, NULL, NULL);
853     ptr = strchrW(ptr, ',');
854     if(!ptr)
855         return S_OK;
856
857     if(*++ptr == '1')
858         exec_italic(This, cmdexecopt, NULL, NULL);
859     ptr = strchrW(ptr, ',');
860     if(!ptr)
861         return S_OK;
862
863     if(*++ptr == '1')
864         exec_underline(This, cmdexecopt, NULL, NULL);
865     ptr = strchrW(ptr, ',');
866     if(!ptr)
867         return S_OK;
868
869     if(isdigitW(*++ptr)) {
870         VARIANT v;
871
872         V_VT(&v) = VT_I4;
873         V_I4(&v) = *ptr-'0';
874
875         exec_fontsize(This, cmdexecopt, &v, NULL);
876     }
877     ptr = strchrW(ptr, ',');
878     if(!ptr)
879         return S_OK;
880
881     if(*++ptr != ',')
882         FIXME("set font color\n");
883     ptr = strchrW(ptr, ',');
884     if(!ptr)
885         return S_OK;
886
887     if(*++ptr != ',')
888         FIXME("set background color\n");
889     ptr = strchrW(ptr, ',');
890     if(!ptr)
891         return S_OK;
892
893     ptr++;
894     if(*ptr) {
895         VARIANT v;
896
897         V_VT(&v) = VT_BSTR;
898         V_BSTR(&v) = SysAllocString(ptr);
899
900         exec_fontname(This, cmdexecopt, &v, NULL);
901
902         SysFreeString(V_BSTR(&v));
903     }
904
905     return S_OK;
906 }
907
908 HRESULT editor_exec_copy(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
909 {
910     update_doc(This, UPDATE_UI);
911
912     if(!This->doc_obj->nscontainer)
913         return E_FAIL;
914
915     do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_COPY);
916     return S_OK;
917 }
918
919 HRESULT editor_exec_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
920 {
921     update_doc(This, UPDATE_UI);
922
923     if(!This->doc_obj->nscontainer)
924         return E_FAIL;
925
926     do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_CUT);
927     return S_OK;
928 }
929
930 HRESULT editor_exec_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
931 {
932     update_doc(This, UPDATE_UI);
933
934     if(!This->doc_obj->nscontainer)
935         return E_FAIL;
936
937     do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_PASTE);
938     return S_OK;
939 }
940
941 static HRESULT exec_setdirty(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
942 {
943     TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
944
945     if(!in)
946         return S_OK;
947
948     if(V_VT(in) == VT_BOOL)
949         set_dirty(This, V_BOOL(in));
950     else
951         FIXME("unsupported arg %s\n", debugstr_variant(in));
952
953     return S_OK;
954 }
955
956 static HRESULT query_edit_status(HTMLDocument *This, OLECMD *cmd)
957 {
958     switch(cmd->cmdID) {
959     case IDM_DELETE:
960         TRACE("CGID_MSHTML: IDM_DELETE\n");
961         cmd->cmdf = query_ns_edit_status(This, NULL);
962         break;
963     case IDM_FONTNAME:
964         TRACE("CGID_MSHTML: IDM_FONTNAME\n");
965         cmd->cmdf = query_ns_edit_status(This, NULL);
966         break;
967     case IDM_FONTSIZE:
968         TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
969         cmd->cmdf = query_ns_edit_status(This, NULL);
970         break;
971     case IDM_BOLD:
972         TRACE("CGID_MSHTML: IDM_BOLD\n");
973         cmd->cmdf = query_ns_edit_status(This, NSCMD_BOLD);
974         break;
975     case IDM_FORECOLOR:
976         TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
977         cmd->cmdf = query_ns_edit_status(This, NULL);
978         break;
979     case IDM_ITALIC:
980         TRACE("CGID_MSHTML: IDM_ITALIC\n");
981         cmd->cmdf = query_ns_edit_status(This, NSCMD_ITALIC);
982         break;
983     case IDM_UNDERLINE:
984         TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
985         cmd->cmdf = query_ns_edit_status(This, NSCMD_UNDERLINE);
986         break;
987     case IDM_HORIZONTALLINE:
988         TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
989         cmd->cmdf = query_ns_edit_status(This, NULL);
990         break;
991     case IDM_ORDERLIST:
992         TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
993         cmd->cmdf = query_ns_edit_status(This, NSCMD_OL);
994         break;
995     case IDM_UNORDERLIST:
996         TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
997         cmd->cmdf = query_ns_edit_status(This, NSCMD_UL);
998         break;
999     case IDM_INDENT:
1000         TRACE("CGID_MSHTML: IDM_INDENT\n");
1001         cmd->cmdf = query_ns_edit_status(This, NULL);
1002         break;
1003     case IDM_OUTDENT:
1004         TRACE("CGID_MSHTML: IDM_OUTDENT\n");
1005         cmd->cmdf = query_ns_edit_status(This, NULL);
1006         break;
1007     case IDM_HYPERLINK:
1008         TRACE("CGID_MSHTML: IDM_HYPERLINK\n");
1009         cmd->cmdf = query_ns_edit_status(This, NULL);
1010         break;
1011     }
1012
1013     return S_OK;
1014 }
1015
1016 static INT_PTR CALLBACK hyperlink_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1017 {
1018     static const WCHAR wszOther[] = {'(','o','t','h','e','r',')',0};
1019
1020     switch (msg)
1021     {
1022         case WM_INITDIALOG:
1023         {
1024             static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1025             static const WCHAR wszFtp[] = {'f','t','p',':',0};
1026             static const WCHAR wszHttp[] = {'h','t','t','p',':',0};
1027             static const WCHAR wszHttps[] = {'h','t','t','p','s',':',0};
1028             static const WCHAR wszMailto[] = {'m','a','i','l','t','o',':',0};
1029             static const WCHAR wszNews[] = {'n','e','w','s',':',0};
1030             INT def_idx;
1031             HWND hwndCB = GetDlgItem(hwnd, IDC_TYPE);
1032             HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1033             INT len;
1034
1035             SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
1036
1037             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszOther);
1038             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFile);
1039             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFtp);
1040             def_idx = SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttp);
1041             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttps);
1042             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszMailto);
1043             SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszNews);
1044             SendMessageW(hwndCB, CB_SETCURSEL, def_idx, 0);
1045
1046             /* force the updating of the URL edit box */
1047             SendMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE), (LPARAM)hwndCB);
1048
1049             SetFocus(hwndURL);
1050             len = SendMessageW(hwndURL, WM_GETTEXTLENGTH, 0, 0);
1051             SendMessageW(hwndURL, EM_SETSEL, 0, len);
1052
1053             return FALSE;
1054         }
1055         case WM_COMMAND:
1056             switch (wparam)
1057             {
1058                 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
1059                     EndDialog(hwnd, wparam);
1060                     return TRUE;
1061                 case MAKEWPARAM(IDOK, BN_CLICKED):
1062                 {
1063                     BSTR *url = (BSTR *)GetWindowLongPtrW(hwnd, DWLP_USER);
1064                     HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1065                     INT len = GetWindowTextLengthW(hwndURL);
1066                     *url = SysAllocStringLen(NULL, len + 1);
1067                     GetWindowTextW(hwndURL, *url, len + 1);
1068                     EndDialog(hwnd, wparam);
1069                     return TRUE;
1070                 }
1071                 case MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE):
1072                 {
1073                     HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1074                     INT item;
1075                     INT len;
1076                     LPWSTR type;
1077                     LPWSTR url;
1078                     LPWSTR p;
1079                     static const WCHAR wszSlashSlash[] = {'/','/'};
1080
1081                     /* get string of currently selected hyperlink type */
1082                     item = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
1083                     len = SendMessageW((HWND)lparam, CB_GETLBTEXTLEN, item, 0);
1084                     type = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1085                     SendMessageW((HWND)lparam, CB_GETLBTEXT, item, (LPARAM)type);
1086
1087                     if (!strcmpW(type, wszOther))
1088                         *type = '\0';
1089
1090                     /* get current URL */
1091                     len = GetWindowTextLengthW(hwndURL);
1092                     url = HeapAlloc(GetProcessHeap(), 0, (len + strlenW(type) + 3) * sizeof(WCHAR));
1093                     GetWindowTextW(hwndURL, url, len + 1);
1094
1095                     /* strip off old protocol */
1096                     p = strchrW(url, ':');
1097                     if (p && p[1] == '/' && p[2] == '/')
1098                         p += 3;
1099                     if (!p) p = url;
1100                     memmove(url + (*type != '\0' ? strlenW(type) + 2 : 0), p, (len + 1 - (p - url)) * sizeof(WCHAR));
1101
1102                     /* add new protocol */
1103                     if (*type != '\0')
1104                     {
1105                         memcpy(url, type, strlenW(type) * sizeof(WCHAR));
1106                         memcpy(url + strlenW(type), wszSlashSlash, sizeof(wszSlashSlash));
1107                     }
1108
1109                     SetWindowTextW(hwndURL, url);
1110
1111                     HeapFree(GetProcessHeap(), 0, url);
1112                     HeapFree(GetProcessHeap(), 0, type);
1113                     return TRUE;
1114                 }
1115             }
1116             return FALSE;
1117         case WM_CLOSE:
1118             EndDialog(hwnd, IDCANCEL);
1119             return TRUE;
1120         default:
1121             return FALSE;
1122     }
1123 }
1124
1125 static HRESULT exec_hyperlink(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
1126 {
1127     nsAString href_str, ns_url;
1128     nsIHTMLEditor *html_editor;
1129     nsIDOMHTMLElement *anchor_elem;
1130     cpp_bool insert_link_at_caret;
1131     nsISelection *nsselection;
1132     BSTR url = NULL;
1133     INT ret;
1134     HRESULT hres = E_FAIL;
1135
1136     static const WCHAR aW[] = {'a',0};
1137     static const WCHAR hrefW[] = {'h','r','e','f',0};
1138
1139     TRACE("%p, 0x%x, %p, %p\n", This, cmdexecopt, in, out);
1140
1141     if (cmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER)
1142     {
1143         if (!in || V_VT(in) != VT_BSTR)
1144         {
1145             WARN("invalid arg\n");
1146             return E_INVALIDARG;
1147         }
1148         url = V_BSTR(in);
1149     }
1150     else
1151     {
1152         ret = DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_HYPERLINK), NULL /* FIXME */, hyperlink_dlgproc, (LPARAM)&url);
1153         if (ret != IDOK)
1154             return OLECMDERR_E_CANCELED;
1155     }
1156
1157     if(!This->doc_node->nsdoc) {
1158         WARN("NULL nsdoc\n");
1159         return E_UNEXPECTED;
1160     }
1161
1162     nsselection = get_ns_selection(This);
1163     if (!nsselection)
1164         return E_FAIL;
1165
1166     /* create an element for the link */
1167     create_nselem(This->doc_node, aW, &anchor_elem);
1168
1169     nsAString_InitDepend(&href_str, hrefW);
1170     nsAString_InitDepend(&ns_url, url);
1171     nsIDOMElement_SetAttribute(anchor_elem, &href_str, &ns_url);
1172     nsAString_Finish(&href_str);
1173
1174     nsISelection_GetIsCollapsed(nsselection, &insert_link_at_caret);
1175
1176     /* create an element with text of URL */
1177     if (insert_link_at_caret) {
1178         nsIDOMNode *text_node, *unused_node;
1179
1180         nsIDOMDocument_CreateTextNode(This->doc_node->nsdoc, &ns_url, (nsIDOMText **)&text_node);
1181
1182         /* wrap the <a> tags around the text element */
1183         nsIDOMElement_AppendChild(anchor_elem, text_node, &unused_node);
1184         nsIDOMNode_Release(text_node);
1185         nsIDOMNode_Release(unused_node);
1186     }
1187
1188     nsAString_Finish(&ns_url);
1189
1190     nsIEditor_QueryInterface(This->doc_obj->nscontainer->editor, &IID_nsIHTMLEditor, (void **)&html_editor);
1191     if (html_editor) {
1192         nsresult nsres;
1193
1194         if (insert_link_at_caret) {
1195             /* add them to the document at the caret position */
1196             nsres = nsIHTMLEditor_InsertElementAtSelection(html_editor, (nsIDOMElement*)anchor_elem, FALSE);
1197             nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)anchor_elem);
1198         }else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
1199             nsres = nsIHTMLEditor_InsertLinkAroundSelection(html_editor, (nsIDOMElement*)anchor_elem);
1200
1201         nsIHTMLEditor_Release(html_editor);
1202         hres = NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
1203     }
1204
1205     nsISelection_Release(nsselection);
1206     nsIDOMElement_Release(anchor_elem);
1207
1208     if (cmdexecopt != OLECMDEXECOPT_DONTPROMPTUSER)
1209         SysFreeString(url);
1210
1211     TRACE("-- 0x%08x\n", hres);
1212     return hres;
1213 }
1214
1215 static HRESULT query_selall_status(HTMLDocument *This, OLECMD *cmd)
1216 {
1217     TRACE("(%p)->(%p)\n", This, cmd);
1218
1219     cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1220     return S_OK;
1221 }
1222
1223 const cmdtable_t editmode_cmds[] = {
1224     {IDM_DELETE,          query_edit_status,    exec_delete},
1225     {IDM_FONTNAME,        query_edit_status,    exec_fontname},
1226     {IDM_FONTSIZE,        query_edit_status,    exec_fontsize},
1227     {IDM_SELECTALL,       query_selall_status , exec_selectall},
1228     {IDM_FORECOLOR,       query_edit_status,    exec_forecolor},
1229     {IDM_BOLD,            query_edit_status,    exec_bold},
1230     {IDM_ITALIC,          query_edit_status,    exec_italic},
1231     {IDM_JUSTIFYCENTER,   query_justify,        exec_justifycenter},
1232     {IDM_JUSTIFYRIGHT,    query_justify,        exec_justifyright},
1233     {IDM_JUSTIFYLEFT,     query_justify,        exec_justifyleft},
1234     {IDM_FONT,            NULL,                 exec_font},
1235     {IDM_UNDERLINE,       query_edit_status,    exec_underline},
1236     {IDM_HORIZONTALLINE,  query_edit_status,    exec_horizontalline},
1237     {IDM_ORDERLIST,       query_edit_status,    exec_orderlist},
1238     {IDM_UNORDERLIST,     query_edit_status,    exec_unorderlist},
1239     {IDM_INDENT,          query_edit_status,    exec_indent},
1240     {IDM_OUTDENT,         query_edit_status,    exec_outdent},
1241     {IDM_COMPOSESETTINGS, NULL,                 exec_composesettings},
1242     {IDM_HYPERLINK,       query_edit_status,    exec_hyperlink},
1243     {IDM_SETDIRTY,        NULL,                 exec_setdirty},
1244     {0,NULL,NULL}
1245 };
1246
1247 void init_editor(HTMLDocument *This)
1248 {
1249     update_doc(This, UPDATE_UI);
1250
1251     set_ns_fontname(This, "Times New Roman");
1252 }
1253
1254 HRESULT editor_is_dirty(HTMLDocument *This)
1255 {
1256     cpp_bool modified;
1257
1258     if(!This->doc_obj->nscontainer || !This->doc_obj->nscontainer->editor)
1259         return S_FALSE;
1260
1261     nsIEditor_GetDocumentModified(This->doc_obj->nscontainer->editor, &modified);
1262
1263     return modified ? S_OK : S_FALSE;
1264 }