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