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