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