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