2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
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.
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.
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
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
40 #define NSCMD_ALIGN "cmd_align"
41 #define NSCMD_BOLD "cmd_bold"
42 #define NSCMD_CHARNEXT "cmd_charNext"
43 #define NSCMD_CHARPREVIOUS "cmd_charPrevious"
44 #define NSCMD_COPY "cmd_copy"
45 #define NSCMD_CUT "cmd_cut"
46 #define NSCMD_DELETECHARFORWARD "cmd_deleteCharForward"
47 #define NSCMD_DELETEWORDFORWARD "cmd_deleteWordForward"
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_ITALIC "cmd_italic"
53 #define NSCMD_LINENEXT "cmd_lineNext"
54 #define NSCMD_LINEPREVIOUS "cmd_linePrevious"
55 #define NSCMD_MOVEPAGEDOWN "cmd_movePageDown"
56 #define NSCMD_MOVEPAGEUP "cmd_movePageUp"
57 #define NSCMD_OL "cmd_ol"
58 #define NSCMD_OUTDENT "cmd_outdent"
59 #define NSCMD_PASTE "cmd_paste"
60 #define NSCMD_SELECTCHARNEXT "cmd_selectCharNext"
61 #define NSCMD_SELECTCHARPREVIOUS "cmd_selectCharPrevious"
62 #define NSCMD_SELECTLINENEXT "cmd_selectLineNext"
63 #define NSCMD_SELECTLINEPREVIOUS "cmd_selectLinePrevious"
64 #define NSCMD_SELECTPAGEDOWN "cmd_selectPageDown"
65 #define NSCMD_SELECTPAGEUP "cmd_selectPageUp"
66 #define NSCMD_SELECTWORDNEXT "cmd_selectWordNext"
67 #define NSCMD_SELECTWORDPREVIOUS "cmd_selectWordPrevious"
68 #define NSCMD_UL "cmd_ul"
69 #define NSCMD_UNDERLINE "cmd_underline"
70 #define NSCMD_WORDNEXT "cmd_wordNext"
71 #define NSCMD_WORDPREVIOUS "cmd_wordPrevious"
73 #define NSSTATE_ATTRIBUTE "state_attribute"
74 #define NSSTATE_ALL "state_all"
76 #define NSALIGN_CENTER "center"
77 #define NSALIGN_LEFT "left"
78 #define NSALIGN_RIGHT "right"
80 #define DOM_VK_LEFT VK_LEFT
81 #define DOM_VK_UP VK_UP
82 #define DOM_VK_RIGHT VK_RIGHT
83 #define DOM_VK_DOWN VK_DOWN
84 #define DOM_VK_DELETE VK_DELETE
86 static const WCHAR wszFont
[] = {'f','o','n','t',0};
87 static const WCHAR wszSize
[] = {'s','i','z','e',0};
89 static void do_ns_command(NSContainer
*This
, const char *cmd
, nsICommandParams
*nsparam
)
91 nsICommandManager
*cmdmgr
;
92 nsIInterfaceRequestor
*iface_req
;
95 TRACE("(%p)\n", This
);
97 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
98 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
99 if(NS_FAILED(nsres
)) {
100 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
104 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsICommandManager
,
106 nsIInterfaceRequestor_Release(iface_req
);
107 if(NS_FAILED(nsres
)) {
108 ERR("Could not get nsICommandManager: %08x\n", nsres
);
112 nsres
= nsICommandManager_DoCommand(cmdmgr
, cmd
, nsparam
, NULL
);
114 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
116 nsICommandManager_Release(cmdmgr
);
119 static void do_ns_editor_command(NSContainer
*This
, const char *cmd
)
123 if(!This
->editor_controller
)
126 nsres
= nsIController_DoCommand(This
->editor_controller
, cmd
);
128 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
131 static nsresult
get_ns_command_state(NSContainer
*This
, const char *cmd
, nsICommandParams
*nsparam
)
133 nsICommandManager
*cmdmgr
;
134 nsIInterfaceRequestor
*iface_req
;
137 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
138 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
139 if(NS_FAILED(nsres
)) {
140 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
144 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsICommandManager
,
146 nsIInterfaceRequestor_Release(iface_req
);
147 if(NS_FAILED(nsres
)) {
148 ERR("Could not get nsICommandManager: %08x\n", nsres
);
152 nsres
= nsICommandManager_GetCommandState(cmdmgr
, cmd
, NULL
, nsparam
);
154 ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
156 nsICommandManager_Release(cmdmgr
);
160 static DWORD
query_ns_edit_status(HTMLDocument
*This
, const char *nscmd
)
162 nsICommandParams
*nsparam
;
165 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
166 return OLECMDF_SUPPORTED
;
168 if(This
->nscontainer
&& nscmd
) {
169 nsparam
= create_nscommand_params();
170 get_ns_command_state(This
->nscontainer
, nscmd
, nsparam
);
172 nsICommandParams_GetBooleanValue(nsparam
, NSSTATE_ALL
, &b
);
174 nsICommandParams_Release(nsparam
);
177 return OLECMDF_SUPPORTED
| OLECMDF_ENABLED
| (b
? OLECMDF_LATCHED
: 0);
180 static void set_ns_align(HTMLDocument
*This
, const char *align_str
)
182 nsICommandParams
*nsparam
;
184 if(!This
->nscontainer
)
187 nsparam
= create_nscommand_params();
188 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, align_str
);
190 do_ns_command(This
->nscontainer
, NSCMD_ALIGN
, nsparam
);
192 nsICommandParams_Release(nsparam
);
195 static DWORD
query_align_status(HTMLDocument
*This
, const char *align_str
)
197 nsICommandParams
*nsparam
;
200 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
201 return OLECMDF_SUPPORTED
;
203 if(This
->nscontainer
) {
204 nsparam
= create_nscommand_params();
205 get_ns_command_state(This
->nscontainer
, NSCMD_ALIGN
, nsparam
);
207 nsICommandParams_GetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, &align
);
209 nsICommandParams_Release(nsparam
);
212 return OLECMDF_SUPPORTED
| OLECMDF_ENABLED
213 | (align
&& !strcmp(align_str
, align
) ? OLECMDF_LATCHED
: 0);
217 static nsISelection
*get_ns_selection(HTMLDocument
*This
)
219 nsIDOMWindow
*dom_window
;
220 nsISelection
*nsselection
= NULL
;
223 if(!This
->nscontainer
)
226 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->nscontainer
->webbrowser
, &dom_window
);
230 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
231 nsIDOMWindow_Release(dom_window
);
237 static void remove_child_attr(nsIDOMElement
*elem
, LPCWSTR tag
, nsAString
*attr_str
)
240 PRUint32 child_cnt
, i
;
241 nsIDOMNode
*child_node
;
242 nsIDOMNodeList
*node_list
;
245 nsIDOMElement_HasChildNodes(elem
, &has_children
);
249 nsIDOMElement_GetChildNodes(elem
, &node_list
);
250 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
252 for(i
=0; i
<child_cnt
; i
++) {
253 nsIDOMNodeList_Item(node_list
, i
, &child_node
);
255 nsIDOMNode_GetNodeType(child_node
, &node_type
);
256 if(node_type
== ELEMENT_NODE
) {
257 nsIDOMElement
*child_elem
;
259 const PRUnichar
*ctag
;
261 nsIDOMNode_QueryInterface(child_node
, &IID_nsIDOMElement
, (void**)&child_elem
);
263 nsAString_Init(&tag_str
, NULL
);
264 nsIDOMElement_GetTagName(child_elem
, &tag_str
);
265 nsAString_GetData(&tag_str
, &ctag
, NULL
);
267 if(!strcmpiW(ctag
, tag
))
268 /* FIXME: remove node if there are no more attributes */
269 nsIDOMElement_RemoveAttribute(child_elem
, attr_str
);
271 nsAString_Finish(&tag_str
);
273 remove_child_attr(child_elem
, tag
, attr_str
);
275 nsIDOMNode_Release(child_elem
);
278 nsIDOMNode_Release(child_node
);
281 nsIDOMNodeList_Release(node_list
);
284 static void get_font_size(HTMLDocument
*This
, WCHAR
*ret
)
286 nsISelection
*nsselection
= get_ns_selection(This
);
287 nsIDOMElement
*elem
= NULL
;
288 nsIDOMNode
*node
= NULL
, *tmp_node
;
299 nsISelection_GetFocusNode(nsselection
, &node
);
300 nsISelection_Release(nsselection
);
303 nsres
= nsIDOMNode_GetNodeType(node
, &node_type
);
304 if(NS_FAILED(nsres
) || node_type
== DOCUMENT_NODE
)
307 if(node_type
== ELEMENT_NODE
) {
308 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
310 nsAString_Init(&tag_str
, NULL
);
311 nsIDOMElement_GetTagName(elem
, &tag_str
);
312 nsAString_GetData(&tag_str
, &tag
, NULL
);
314 if(!strcmpiW(tag
, wszFont
)) {
315 nsAString size_str
, val_str
;
318 TRACE("found font tag %p\n", elem
);
320 nsAString_Init(&size_str
, wszSize
);
321 nsAString_Init(&val_str
, NULL
);
323 nsIDOMElement_GetAttribute(elem
, &size_str
, &val_str
);
324 nsAString_GetData(&val_str
, &val
, NULL
);
327 TRACE("found size %s\n", debugstr_w(val
));
331 nsAString_Finish(&size_str
);
332 nsAString_Finish(&val_str
);
335 nsAString_Finish(&tag_str
);
337 nsIDOMElement_Release(elem
);
344 nsIDOMNode_GetParentNode(node
, &node
);
345 nsIDOMNode_Release(tmp_node
);
349 nsIDOMNode_Release(node
);
352 static void set_font_size(HTMLDocument
*This
, LPCWSTR size
)
354 nsISelection
*nsselection
;
356 nsIDOMDocument
*nsdoc
;
359 PRInt32 range_cnt
= 0;
365 nsselection
= get_ns_selection(This
);
370 nsISelection_GetRangeCount(nsselection
, &range_cnt
);
372 FIXME("range_cnt %d not supprted\n", range_cnt
);
374 nsISelection_Release(nsselection
);
379 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
383 nsAString_Init(&font_str
, wszFont
);
384 nsAString_Init(&size_str
, wszSize
);
385 nsAString_Init(&val_str
, size
);
387 nsIDOMDocument_CreateElement(nsdoc
, &font_str
, &elem
);
388 nsIDOMElement_SetAttribute(elem
, &size_str
, &val_str
);
390 nsISelection_GetRangeAt(nsselection
, 0, &range
);
391 nsISelection_GetIsCollapsed(nsselection
, &collapsed
);
392 nsISelection_RemoveAllRanges(nsselection
);
394 nsIDOMRange_SurroundContents(range
, (nsIDOMNode
*)elem
);
397 nsISelection_Collapse(nsselection
, (nsIDOMNode
*)elem
, 0);
399 /* Remove all size attrbutes from the range */
400 remove_child_attr(elem
, wszFont
, &size_str
);
401 nsISelection_SelectAllChildren(nsselection
, (nsIDOMNode
*)elem
);
404 nsIDOMRange_Release(range
);
405 nsIDOMElement_Release(elem
);
407 nsAString_Finish(&font_str
);
408 nsAString_Finish(&size_str
);
409 nsAString_Finish(&val_str
);
411 nsISelection_Release(nsselection
);
412 nsIDOMDocument_Release(nsdoc
);
415 static BOOL
is_visible_text_node(nsIDOMNode
*node
)
417 nsIDOMCharacterData
*char_data
;
422 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMCharacterData
, (void**)&char_data
);
424 nsIDOMCharacterData_GetLength(char_data
, &len
);
426 nsAString_Init(&data_str
, NULL
);
427 nsIDOMCharacterData_GetData(char_data
, &data_str
);
428 nsAString_GetData(&data_str
, &data
, NULL
);
432 for(ptr
=data
+1; ptr
&& isspaceW(*ptr
); ptr
++)
436 nsAString_Finish(&data_str
);
438 nsIDOMCharacterData_Release(char_data
);
443 static nsIDOMNode
*get_child_text_node(nsIDOMNode
*node
, BOOL first
)
445 nsIDOMNode
*iter
, *iter2
;
448 nsIDOMNode_GetFirstChild(node
, &iter
);
450 nsIDOMNode_GetLastChild(node
, &iter
);
455 nsIDOMNode_GetNodeType(iter
, &node_type
);
458 if(is_visible_text_node(iter
))
461 iter2
= get_child_text_node(iter
, first
);
463 nsIDOMNode_Release(iter
);
469 nsIDOMNode_GetNextSibling(iter
, &iter2
);
471 nsIDOMNode_GetPreviousSibling(iter
, &iter2
);
473 nsIDOMNode_Release(iter
);
480 static void handle_arrow_key(HTMLDocument
*This
, nsIDOMKeyEvent
*event
, const char **cmds
)
485 nsIDOMKeyEvent_GetCtrlKey(event
, &b
);
489 nsIDOMKeyEvent_GetShiftKey(event
, &b
);
494 do_ns_editor_command(This
->nscontainer
, cmds
[i
]);
496 nsIDOMKeyEvent_PreventDefault(event
);
499 void handle_edit_event(HTMLDocument
*This
, nsIDOMEvent
*event
)
501 nsIDOMKeyEvent
*key_event
;
504 nsIDOMEvent_QueryInterface(event
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
506 nsIDOMKeyEvent_GetKeyCode(key_event
, &code
);
510 static const char *cmds
[] = {
513 NSCMD_SELECTCHARPREVIOUS
,
514 NSCMD_SELECTWORDPREVIOUS
518 handle_arrow_key(This
, key_event
, cmds
);
522 static const char *cmds
[] = {
525 NSCMD_SELECTCHARNEXT
,
530 handle_arrow_key(This
, key_event
, cmds
);
534 static const char *cmds
[] = {
537 NSCMD_SELECTLINEPREVIOUS
,
542 handle_arrow_key(This
, key_event
, cmds
);
546 static const char *cmds
[] = {
549 NSCMD_SELECTLINENEXT
,
554 handle_arrow_key(This
, key_event
, cmds
);
557 case DOM_VK_DELETE
: {
558 static const char *cmds
[] = {
559 NSCMD_DELETECHARFORWARD
,
560 NSCMD_DELETEWORDFORWARD
,
565 handle_arrow_key(This
, key_event
, cmds
);
570 nsIDOMKeyEvent_Release(key_event
);
573 static void set_ns_fontname(NSContainer
*This
, const char *fontname
)
575 nsICommandParams
*nsparam
= create_nscommand_params();
577 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, fontname
);
578 do_ns_command(This
, NSCMD_FONTFACE
, nsparam
);
579 nsICommandParams_Release(nsparam
);
582 static HRESULT
exec_delete(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
584 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
586 if(This
->nscontainer
)
587 do_ns_editor_command(This
->nscontainer
, NSCMD_DELETECHARFORWARD
);
589 update_doc(This
, UPDATE_UI
);
593 static HRESULT
exec_fontname(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
595 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
597 if(!This
->nscontainer
) {
598 update_doc(This
, UPDATE_UI
);
606 if(V_VT(in
) != VT_BSTR
) {
607 FIXME("Unsupported vt=%d\n", V_VT(out
));
611 TRACE("%s\n", debugstr_w(V_BSTR(in
)));
613 len
= WideCharToMultiByte(CP_ACP
, 0, V_BSTR(in
), -1, NULL
, 0, NULL
, NULL
);
614 stra
= mshtml_alloc(len
);
615 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(in
), -1, stra
, -1, NULL
, NULL
);
617 set_ns_fontname(This
->nscontainer
, stra
);
621 update_doc(This
, UPDATE_UI
);
625 nsICommandParams
*nsparam
;
631 nsparam
= create_nscommand_params();
633 nsres
= get_ns_command_state(This
->nscontainer
, NSCMD_FONTFACE
, nsparam
);
637 nsICommandParams_GetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, &stra
);
638 nsICommandParams_Release(nsparam
);
640 len
= MultiByteToWideChar(CP_ACP
, 0, stra
, -1, NULL
, 0);
641 strw
= mshtml_alloc(len
*sizeof(WCHAR
));
642 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, strw
, -1);
646 V_BSTR(out
) = SysAllocString(strw
);
653 static HRESULT
exec_forecolor(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
655 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
658 if(V_VT(in
) == VT_I4
) {
659 nsICommandParams
*nsparam
= create_nscommand_params();
662 sprintf(color_str
, "#%02x%02x%02x",
663 V_I4(in
)&0xff, (V_I4(in
)>>8)&0xff, (V_I4(in
)>>16)&0xff);
665 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, color_str
);
666 do_ns_command(This
->nscontainer
, NSCMD_FONTCOLOR
, nsparam
);
668 nsICommandParams_Release(nsparam
);
670 FIXME("unsupported in vt=%d\n", V_VT(in
));
673 update_doc(This
, UPDATE_UI
);
677 FIXME("unsupported out\n");
684 static HRESULT
exec_fontsize(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
686 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
691 get_font_size(This
, val
);
693 V_I4(out
) = strtolW(val
, NULL
, 10);
700 static const WCHAR format
[] = {'%','d',0};
701 wsprintfW(size
, format
, V_I4(in
));
702 set_font_size(This
, size
);
706 set_font_size(This
, V_BSTR(in
));
709 FIXME("unsupported vt %d\n", V_VT(in
));
712 update_doc(This
, UPDATE_UI
);
718 static HRESULT
exec_bold(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
720 TRACE("(%p)\n", This
);
723 FIXME("unsupported args\n");
725 if(This
->nscontainer
)
726 do_ns_command(This
->nscontainer
, NSCMD_BOLD
, NULL
);
728 update_doc(This
, UPDATE_UI
);
732 static HRESULT
exec_italic(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
734 TRACE("(%p)\n", This
);
737 FIXME("unsupported args\n");
739 if(This
->nscontainer
)
740 do_ns_command(This
->nscontainer
, NSCMD_ITALIC
, NULL
);
742 update_doc(This
, UPDATE_UI
);
746 static HRESULT
query_justify(HTMLDocument
*This
, OLECMD
*cmd
)
749 case IDM_JUSTIFYCENTER
:
750 TRACE("(%p) IDM_JUSTIFYCENTER\n", This
);
751 cmd
->cmdf
= query_align_status(This
, NSALIGN_CENTER
);
753 case IDM_JUSTIFYLEFT
:
754 TRACE("(%p) IDM_JUSTIFYLEFT\n", This
);
755 /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
756 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
757 cmd
->cmdf
= OLECMDF_SUPPORTED
;
759 cmd
->cmdf
= OLECMDF_SUPPORTED
| OLECMDF_ENABLED
;
761 case IDM_JUSTIFYRIGHT
:
762 TRACE("(%p) IDM_JUSTIFYRIGHT\n", This
);
763 cmd
->cmdf
= query_align_status(This
, NSALIGN_RIGHT
);
770 static HRESULT
exec_justifycenter(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
772 TRACE("(%p)\n", This
);
775 FIXME("unsupported args\n");
777 set_ns_align(This
, NSALIGN_CENTER
);
778 update_doc(This
, UPDATE_UI
);
782 static HRESULT
exec_justifyleft(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
784 TRACE("(%p)\n", This
);
787 FIXME("unsupported args\n");
789 set_ns_align(This
, NSALIGN_LEFT
);
790 update_doc(This
, UPDATE_UI
);
794 static HRESULT
exec_justifyright(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
796 TRACE("(%p)\n", This
);
799 FIXME("unsupported args\n");
801 set_ns_align(This
, NSALIGN_RIGHT
);
802 update_doc(This
, UPDATE_UI
);
806 static HRESULT
exec_underline(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
808 TRACE("(%p)\n", This
);
811 FIXME("unsupported args\n");
813 if(This
->nscontainer
)
814 do_ns_command(This
->nscontainer
, NSCMD_UNDERLINE
, NULL
);
816 update_doc(This
, UPDATE_UI
);
820 static HRESULT
exec_horizontalline(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
822 TRACE("(%p)\n", This
);
825 FIXME("unsupported args\n");
827 if(This
->nscontainer
)
828 do_ns_command(This
->nscontainer
, NSCMD_INSERTHR
, NULL
);
830 update_doc(This
, UPDATE_UI
);
834 static HRESULT
exec_orderlist(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
836 TRACE("(%p)\n", This
);
839 FIXME("unsupported args\n");
841 if(This
->nscontainer
)
842 do_ns_command(This
->nscontainer
, NSCMD_OL
, NULL
);
844 update_doc(This
, UPDATE_UI
);
848 static HRESULT
exec_unorderlist(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
850 TRACE("(%p)\n", This
);
853 FIXME("unsupported args\n");
855 if(This
->nscontainer
)
856 do_ns_command(This
->nscontainer
, NSCMD_UL
, NULL
);
858 update_doc(This
, UPDATE_UI
);
862 static HRESULT
exec_indent(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
864 TRACE("(%p)\n", This
);
867 FIXME("unsupported args\n");
869 if(This
->nscontainer
)
870 do_ns_command(This
->nscontainer
, NSCMD_INDENT
, NULL
);
872 update_doc(This
, UPDATE_UI
);
876 static HRESULT
exec_outdent(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
878 TRACE("(%p)\n", This
);
881 FIXME("unsupported args\n");
883 if(This
->nscontainer
)
884 do_ns_command(This
->nscontainer
, NSCMD_OUTDENT
, NULL
);
886 update_doc(This
, UPDATE_UI
);
890 static HRESULT
exec_composesettings(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
894 if(out
|| !in
|| V_VT(in
) != VT_BSTR
) {
895 WARN("invalid arg\n");
899 TRACE("(%p)->(%x %s)\n", This
, cmdexecopt
, debugstr_w(V_BSTR(in
)));
901 update_doc(This
, UPDATE_UI
);
905 exec_bold(This
, cmdexecopt
, NULL
, NULL
);
906 ptr
= strchrW(ptr
, ',');
911 exec_italic(This
, cmdexecopt
, NULL
, NULL
);
912 ptr
= strchrW(ptr
, ',');
917 exec_underline(This
, cmdexecopt
, NULL
, NULL
);
918 ptr
= strchrW(ptr
, ',');
922 if(isdigitW(*++ptr
)) {
928 exec_fontsize(This
, cmdexecopt
, &v
, NULL
);
930 ptr
= strchrW(ptr
, ',');
935 FIXME("set font color\n");
936 ptr
= strchrW(ptr
, ',');
941 FIXME("set background color\n");
942 ptr
= strchrW(ptr
, ',');
951 V_BSTR(&v
) = SysAllocString(ptr
);
953 exec_fontname(This
, cmdexecopt
, &v
, NULL
);
955 SysFreeString(V_BSTR(&v
));
961 HRESULT
editor_exec_copy(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
963 update_doc(This
, UPDATE_UI
);
965 if(!This
->nscontainer
)
968 do_ns_editor_command(This
->nscontainer
, NSCMD_COPY
);
972 HRESULT
editor_exec_cut(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
974 update_doc(This
, UPDATE_UI
);
976 if(!This
->nscontainer
)
979 do_ns_editor_command(This
->nscontainer
, NSCMD_CUT
);
983 HRESULT
editor_exec_paste(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
985 update_doc(This
, UPDATE_UI
);
987 if(!This
->nscontainer
)
990 do_ns_editor_command(This
->nscontainer
, NSCMD_PASTE
);
994 static HRESULT
query_edit_status(HTMLDocument
*This
, OLECMD
*cmd
)
998 TRACE("CGID_MSHTML: IDM_DELETE\n");
999 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1002 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
1003 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1006 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
1007 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1010 TRACE("CGID_MSHTML: IDM_BOLD\n");
1011 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_BOLD
);
1014 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
1015 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1018 TRACE("CGID_MSHTML: IDM_ITALIC\n");
1019 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_ITALIC
);
1022 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
1023 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_UNDERLINE
);
1025 case IDM_HORIZONTALLINE
:
1026 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1027 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1030 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
1031 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_OL
);
1033 case IDM_UNORDERLIST
:
1034 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1035 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_UL
);
1038 TRACE("CGID_MSHTML: IDM_INDENT\n");
1039 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1042 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
1043 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1050 const cmdtable_t editmode_cmds
[] = {
1051 {IDM_DELETE
, query_edit_status
, exec_delete
},
1052 {IDM_FONTNAME
, query_edit_status
, exec_fontname
},
1053 {IDM_FONTSIZE
, query_edit_status
, exec_fontsize
},
1054 {IDM_FORECOLOR
, query_edit_status
, exec_forecolor
},
1055 {IDM_BOLD
, query_edit_status
, exec_bold
},
1056 {IDM_ITALIC
, query_edit_status
, exec_italic
},
1057 {IDM_JUSTIFYCENTER
, query_justify
, exec_justifycenter
},
1058 {IDM_JUSTIFYRIGHT
, query_justify
, exec_justifyright
},
1059 {IDM_JUSTIFYLEFT
, query_justify
, exec_justifyleft
},
1060 {IDM_UNDERLINE
, query_edit_status
, exec_underline
},
1061 {IDM_HORIZONTALLINE
, query_edit_status
, exec_horizontalline
},
1062 {IDM_ORDERLIST
, query_edit_status
, exec_orderlist
},
1063 {IDM_UNORDERLIST
, query_edit_status
, exec_unorderlist
},
1064 {IDM_INDENT
, query_edit_status
, exec_indent
},
1065 {IDM_OUTDENT
, query_edit_status
, exec_outdent
},
1066 {IDM_COMPOSESETTINGS
, NULL
, exec_composesettings
},
1070 void init_editor(HTMLDocument
*This
)
1072 update_doc(This
, UPDATE_UI
);
1074 if(!This
->nscontainer
)
1077 set_ns_fontname(This
->nscontainer
, "Times New Roman");