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"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
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_ITALIC "cmd_italic"
56 #define NSCMD_LINENEXT "cmd_lineNext"
57 #define NSCMD_LINEPREVIOUS "cmd_linePrevious"
58 #define NSCMD_MOVEBOTTOM "cmd_moveBottom"
59 #define NSCMD_MOVEPAGEDOWN "cmd_movePageDown"
60 #define NSCMD_MOVEPAGEUP "cmd_movePageUp"
61 #define NSCMD_MOVETOP "cmd_moveTop"
62 #define NSCMD_OL "cmd_ol"
63 #define NSCMD_OUTDENT "cmd_outdent"
64 #define NSCMD_PASTE "cmd_paste"
65 #define NSCMD_SELECTALL "cmd_selectAll"
66 #define NSCMD_SELECTBEGINLINE "cmd_selectBeginLine"
67 #define NSCMD_SELECTBOTTOM "cmd_selectBottom"
68 #define NSCMD_SELECTCHARNEXT "cmd_selectCharNext"
69 #define NSCMD_SELECTCHARPREVIOUS "cmd_selectCharPrevious"
70 #define NSCMD_SELECTENDLINE "cmd_selectEndLine"
71 #define NSCMD_SELECTLINENEXT "cmd_selectLineNext"
72 #define NSCMD_SELECTLINEPREVIOUS "cmd_selectLinePrevious"
73 #define NSCMD_SELECTPAGEDOWN "cmd_selectPageDown"
74 #define NSCMD_SELECTPAGEUP "cmd_selectPageUp"
75 #define NSCMD_SELECTTOP "cmd_selectTop"
76 #define NSCMD_SELECTWORDNEXT "cmd_selectWordNext"
77 #define NSCMD_SELECTWORDPREVIOUS "cmd_selectWordPrevious"
78 #define NSCMD_UL "cmd_ul"
79 #define NSCMD_UNDERLINE "cmd_underline"
80 #define NSCMD_WORDNEXT "cmd_wordNext"
81 #define NSCMD_WORDPREVIOUS "cmd_wordPrevious"
83 #define NSSTATE_ATTRIBUTE "state_attribute"
84 #define NSSTATE_ALL "state_all"
86 #define NSALIGN_CENTER "center"
87 #define NSALIGN_LEFT "left"
88 #define NSALIGN_RIGHT "right"
90 #define DOM_VK_LEFT VK_LEFT
91 #define DOM_VK_UP VK_UP
92 #define DOM_VK_RIGHT VK_RIGHT
93 #define DOM_VK_DOWN VK_DOWN
94 #define DOM_VK_DELETE VK_DELETE
95 #define DOM_VK_HOME VK_HOME
96 #define DOM_VK_END VK_END
98 static const WCHAR wszFont
[] = {'f','o','n','t',0};
99 static const WCHAR wszSize
[] = {'s','i','z','e',0};
101 static void do_ns_command(NSContainer
*This
, const char *cmd
, nsICommandParams
*nsparam
)
103 nsICommandManager
*cmdmgr
;
104 nsIInterfaceRequestor
*iface_req
;
107 TRACE("(%p)\n", This
);
109 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
110 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
111 if(NS_FAILED(nsres
)) {
112 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
116 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsICommandManager
,
118 nsIInterfaceRequestor_Release(iface_req
);
119 if(NS_FAILED(nsres
)) {
120 ERR("Could not get nsICommandManager: %08x\n", nsres
);
124 nsres
= nsICommandManager_DoCommand(cmdmgr
, cmd
, nsparam
, NULL
);
126 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
128 nsICommandManager_Release(cmdmgr
);
131 static void do_ns_editor_command(NSContainer
*This
, const char *cmd
)
135 if(!This
->editor_controller
)
138 nsres
= nsIController_DoCommand(This
->editor_controller
, cmd
);
140 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
143 static nsresult
get_ns_command_state(NSContainer
*This
, const char *cmd
, nsICommandParams
*nsparam
)
145 nsICommandManager
*cmdmgr
;
146 nsIInterfaceRequestor
*iface_req
;
149 nsres
= nsIWebBrowser_QueryInterface(This
->webbrowser
,
150 &IID_nsIInterfaceRequestor
, (void**)&iface_req
);
151 if(NS_FAILED(nsres
)) {
152 ERR("Could not get nsIInterfaceRequestor: %08x\n", nsres
);
156 nsres
= nsIInterfaceRequestor_GetInterface(iface_req
, &IID_nsICommandManager
,
158 nsIInterfaceRequestor_Release(iface_req
);
159 if(NS_FAILED(nsres
)) {
160 ERR("Could not get nsICommandManager: %08x\n", nsres
);
164 nsres
= nsICommandManager_GetCommandState(cmdmgr
, cmd
, NULL
, nsparam
);
166 ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
168 nsICommandManager_Release(cmdmgr
);
172 static DWORD
query_ns_edit_status(HTMLDocument
*This
, const char *nscmd
)
174 nsICommandParams
*nsparam
;
177 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
178 return OLECMDF_SUPPORTED
;
180 if(This
->nscontainer
&& nscmd
) {
181 nsparam
= create_nscommand_params();
182 get_ns_command_state(This
->nscontainer
, nscmd
, nsparam
);
184 nsICommandParams_GetBooleanValue(nsparam
, NSSTATE_ALL
, &b
);
186 nsICommandParams_Release(nsparam
);
189 return OLECMDF_SUPPORTED
| OLECMDF_ENABLED
| (b
? OLECMDF_LATCHED
: 0);
192 static void set_ns_align(HTMLDocument
*This
, const char *align_str
)
194 nsICommandParams
*nsparam
;
196 if(!This
->nscontainer
)
199 nsparam
= create_nscommand_params();
200 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, align_str
);
202 do_ns_command(This
->nscontainer
, NSCMD_ALIGN
, nsparam
);
204 nsICommandParams_Release(nsparam
);
207 static DWORD
query_align_status(HTMLDocument
*This
, const char *align_str
)
209 nsICommandParams
*nsparam
;
212 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
213 return OLECMDF_SUPPORTED
;
215 if(This
->nscontainer
) {
216 nsparam
= create_nscommand_params();
217 get_ns_command_state(This
->nscontainer
, NSCMD_ALIGN
, nsparam
);
219 nsICommandParams_GetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, &align
);
221 nsICommandParams_Release(nsparam
);
224 return OLECMDF_SUPPORTED
| OLECMDF_ENABLED
225 | (align
&& !strcmp(align_str
, align
) ? OLECMDF_LATCHED
: 0);
229 static nsISelection
*get_ns_selection(HTMLDocument
*This
)
231 nsIDOMWindow
*dom_window
;
232 nsISelection
*nsselection
= NULL
;
235 if(!This
->nscontainer
)
238 nsres
= nsIWebBrowser_GetContentDOMWindow(This
->nscontainer
->webbrowser
, &dom_window
);
242 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
243 nsIDOMWindow_Release(dom_window
);
249 static void remove_child_attr(nsIDOMElement
*elem
, LPCWSTR tag
, nsAString
*attr_str
)
252 PRUint32 child_cnt
, i
;
253 nsIDOMNode
*child_node
;
254 nsIDOMNodeList
*node_list
;
257 nsIDOMElement_HasChildNodes(elem
, &has_children
);
261 nsIDOMElement_GetChildNodes(elem
, &node_list
);
262 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
264 for(i
=0; i
<child_cnt
; i
++) {
265 nsIDOMNodeList_Item(node_list
, i
, &child_node
);
267 nsIDOMNode_GetNodeType(child_node
, &node_type
);
268 if(node_type
== ELEMENT_NODE
) {
269 nsIDOMElement
*child_elem
;
271 const PRUnichar
*ctag
;
273 nsIDOMNode_QueryInterface(child_node
, &IID_nsIDOMElement
, (void**)&child_elem
);
275 nsAString_Init(&tag_str
, NULL
);
276 nsIDOMElement_GetTagName(child_elem
, &tag_str
);
277 nsAString_GetData(&tag_str
, &ctag
, NULL
);
279 if(!strcmpiW(ctag
, tag
))
280 /* FIXME: remove node if there are no more attributes */
281 nsIDOMElement_RemoveAttribute(child_elem
, attr_str
);
283 nsAString_Finish(&tag_str
);
285 remove_child_attr(child_elem
, tag
, attr_str
);
287 nsIDOMNode_Release(child_elem
);
290 nsIDOMNode_Release(child_node
);
293 nsIDOMNodeList_Release(node_list
);
296 static void get_font_size(HTMLDocument
*This
, WCHAR
*ret
)
298 nsISelection
*nsselection
= get_ns_selection(This
);
299 nsIDOMElement
*elem
= NULL
;
300 nsIDOMNode
*node
= NULL
, *tmp_node
;
311 nsISelection_GetFocusNode(nsselection
, &node
);
312 nsISelection_Release(nsselection
);
315 nsres
= nsIDOMNode_GetNodeType(node
, &node_type
);
316 if(NS_FAILED(nsres
) || node_type
== DOCUMENT_NODE
)
319 if(node_type
== ELEMENT_NODE
) {
320 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
322 nsAString_Init(&tag_str
, NULL
);
323 nsIDOMElement_GetTagName(elem
, &tag_str
);
324 nsAString_GetData(&tag_str
, &tag
, NULL
);
326 if(!strcmpiW(tag
, wszFont
)) {
327 nsAString size_str
, val_str
;
330 TRACE("found font tag %p\n", elem
);
332 nsAString_Init(&size_str
, wszSize
);
333 nsAString_Init(&val_str
, NULL
);
335 nsIDOMElement_GetAttribute(elem
, &size_str
, &val_str
);
336 nsAString_GetData(&val_str
, &val
, NULL
);
339 TRACE("found size %s\n", debugstr_w(val
));
343 nsAString_Finish(&size_str
);
344 nsAString_Finish(&val_str
);
347 nsAString_Finish(&tag_str
);
349 nsIDOMElement_Release(elem
);
356 nsIDOMNode_GetParentNode(node
, &node
);
357 nsIDOMNode_Release(tmp_node
);
361 nsIDOMNode_Release(node
);
364 static void set_font_size(HTMLDocument
*This
, LPCWSTR size
)
366 nsISelection
*nsselection
;
368 nsIDOMDocument
*nsdoc
;
371 PRInt32 range_cnt
= 0;
377 nsselection
= get_ns_selection(This
);
382 nsISelection_GetRangeCount(nsselection
, &range_cnt
);
384 FIXME("range_cnt %d not supprted\n", range_cnt
);
386 nsISelection_Release(nsselection
);
391 nsres
= nsIWebNavigation_GetDocument(This
->nscontainer
->navigation
, &nsdoc
);
395 nsAString_Init(&font_str
, wszFont
);
396 nsAString_Init(&size_str
, wszSize
);
397 nsAString_Init(&val_str
, size
);
399 nsIDOMDocument_CreateElement(nsdoc
, &font_str
, &elem
);
400 nsIDOMElement_SetAttribute(elem
, &size_str
, &val_str
);
402 nsISelection_GetRangeAt(nsselection
, 0, &range
);
403 nsISelection_GetIsCollapsed(nsselection
, &collapsed
);
404 nsISelection_RemoveAllRanges(nsselection
);
406 nsIDOMRange_SurroundContents(range
, (nsIDOMNode
*)elem
);
409 nsISelection_Collapse(nsselection
, (nsIDOMNode
*)elem
, 0);
411 /* Remove all size attrbutes from the range */
412 remove_child_attr(elem
, wszFont
, &size_str
);
413 nsISelection_SelectAllChildren(nsselection
, (nsIDOMNode
*)elem
);
416 nsIDOMRange_Release(range
);
417 nsIDOMElement_Release(elem
);
419 nsAString_Finish(&font_str
);
420 nsAString_Finish(&size_str
);
421 nsAString_Finish(&val_str
);
423 nsISelection_Release(nsselection
);
424 nsIDOMDocument_Release(nsdoc
);
427 static BOOL
is_visible_text_node(nsIDOMNode
*node
)
429 nsIDOMCharacterData
*char_data
;
434 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMCharacterData
, (void**)&char_data
);
436 nsIDOMCharacterData_GetLength(char_data
, &len
);
438 nsAString_Init(&data_str
, NULL
);
439 nsIDOMCharacterData_GetData(char_data
, &data_str
);
440 nsAString_GetData(&data_str
, &data
, NULL
);
444 for(ptr
=data
+1; ptr
&& isspaceW(*ptr
); ptr
++)
448 nsAString_Finish(&data_str
);
450 nsIDOMCharacterData_Release(char_data
);
455 static nsIDOMNode
*get_child_text_node(nsIDOMNode
*node
, BOOL first
)
457 nsIDOMNode
*iter
, *iter2
;
460 nsIDOMNode_GetFirstChild(node
, &iter
);
462 nsIDOMNode_GetLastChild(node
, &iter
);
467 nsIDOMNode_GetNodeType(iter
, &node_type
);
470 if(is_visible_text_node(iter
))
473 iter2
= get_child_text_node(iter
, first
);
475 nsIDOMNode_Release(iter
);
481 nsIDOMNode_GetNextSibling(iter
, &iter2
);
483 nsIDOMNode_GetPreviousSibling(iter
, &iter2
);
485 nsIDOMNode_Release(iter
);
492 static void handle_arrow_key(HTMLDocument
*This
, nsIDOMKeyEvent
*event
, const char * const cmds
[4])
497 nsIDOMKeyEvent_GetCtrlKey(event
, &b
);
501 nsIDOMKeyEvent_GetShiftKey(event
, &b
);
506 do_ns_editor_command(This
->nscontainer
, cmds
[i
]);
508 nsIDOMKeyEvent_PreventDefault(event
);
511 void handle_edit_event(HTMLDocument
*This
, nsIDOMEvent
*event
)
513 nsIDOMKeyEvent
*key_event
;
516 nsIDOMEvent_QueryInterface(event
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
518 nsIDOMKeyEvent_GetKeyCode(key_event
, &code
);
522 static const char * const cmds
[] = {
525 NSCMD_SELECTCHARPREVIOUS
,
526 NSCMD_SELECTWORDPREVIOUS
530 handle_arrow_key(This
, key_event
, cmds
);
534 static const char * const cmds
[] = {
537 NSCMD_SELECTCHARNEXT
,
542 handle_arrow_key(This
, key_event
, cmds
);
546 static const char * const cmds
[] = {
549 NSCMD_SELECTLINEPREVIOUS
,
554 handle_arrow_key(This
, key_event
, cmds
);
558 static const char * const cmds
[] = {
561 NSCMD_SELECTLINENEXT
,
566 handle_arrow_key(This
, key_event
, cmds
);
569 case DOM_VK_DELETE
: {
570 static const char * const cmds
[] = {
571 NSCMD_DELETECHARFORWARD
,
572 NSCMD_DELETEWORDFORWARD
,
577 handle_arrow_key(This
, key_event
, cmds
);
581 static const char * const cmds
[] = {
584 NSCMD_SELECTBEGINLINE
,
589 handle_arrow_key(This
, key_event
, cmds
);
593 static const char * const cmds
[] = {
601 handle_arrow_key(This
, key_event
, cmds
);
606 nsIDOMKeyEvent_Release(key_event
);
609 void handle_edit_load(HTMLDocument
*This
)
611 This
->nscontainer
->editor_controller
= get_editor_controller(This
->nscontainer
);
613 if(This
->ui_active
) {
614 OLECHAR wszHTMLDocument
[30];
618 IOleInPlaceUIWindow_SetActiveObject(This
->ip_window
, NULL
, NULL
);
620 IDocHostUIHandler_HideUI(This
->hostui
);
623 IDocHostUIHandler_ShowUI(This
->hostui
, DOCHOSTUITYPE_AUTHOR
, ACTOBJ(This
), CMDTARGET(This
),
624 This
->frame
, This
->ip_window
);
626 LoadStringW(hInst
, IDS_HTMLDOCUMENT
, wszHTMLDocument
,
627 sizeof(wszHTMLDocument
)/sizeof(WCHAR
));
630 IOleInPlaceUIWindow_SetActiveObject(This
->ip_window
, ACTOBJ(This
), wszHTMLDocument
);
632 memset(&rcBorderWidths
, 0, sizeof(rcBorderWidths
));
633 IOleInPlaceFrame_SetBorderSpace(This
->frame
, &rcBorderWidths
);
637 static void set_ns_fontname(NSContainer
*This
, const char *fontname
)
639 nsICommandParams
*nsparam
= create_nscommand_params();
641 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, fontname
);
642 do_ns_command(This
, NSCMD_FONTFACE
, nsparam
);
643 nsICommandParams_Release(nsparam
);
646 static HRESULT
exec_delete(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
648 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
650 if(This
->nscontainer
)
651 do_ns_editor_command(This
->nscontainer
, NSCMD_DELETECHARFORWARD
);
653 update_doc(This
, UPDATE_UI
);
657 static HRESULT
exec_fontname(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
659 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
661 if(!This
->nscontainer
) {
662 update_doc(This
, UPDATE_UI
);
670 if(V_VT(in
) != VT_BSTR
) {
671 FIXME("Unsupported vt=%d\n", V_VT(out
));
675 TRACE("%s\n", debugstr_w(V_BSTR(in
)));
677 len
= WideCharToMultiByte(CP_ACP
, 0, V_BSTR(in
), -1, NULL
, 0, NULL
, NULL
);
678 stra
= mshtml_alloc(len
);
679 WideCharToMultiByte(CP_ACP
, 0, V_BSTR(in
), -1, stra
, -1, NULL
, NULL
);
681 set_ns_fontname(This
->nscontainer
, stra
);
685 update_doc(This
, UPDATE_UI
);
689 nsICommandParams
*nsparam
;
695 nsparam
= create_nscommand_params();
697 nsres
= get_ns_command_state(This
->nscontainer
, NSCMD_FONTFACE
, nsparam
);
701 nsICommandParams_GetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, &stra
);
702 nsICommandParams_Release(nsparam
);
704 len
= MultiByteToWideChar(CP_ACP
, 0, stra
, -1, NULL
, 0);
705 strw
= mshtml_alloc(len
*sizeof(WCHAR
));
706 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, strw
, -1);
710 V_BSTR(out
) = SysAllocString(strw
);
717 static HRESULT
exec_forecolor(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
719 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
722 if(V_VT(in
) == VT_I4
) {
723 nsICommandParams
*nsparam
= create_nscommand_params();
726 sprintf(color_str
, "#%02x%02x%02x",
727 V_I4(in
)&0xff, (V_I4(in
)>>8)&0xff, (V_I4(in
)>>16)&0xff);
729 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, color_str
);
730 do_ns_command(This
->nscontainer
, NSCMD_FONTCOLOR
, nsparam
);
732 nsICommandParams_Release(nsparam
);
734 FIXME("unsupported in vt=%d\n", V_VT(in
));
737 update_doc(This
, UPDATE_UI
);
741 FIXME("unsupported out\n");
748 static HRESULT
exec_fontsize(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
750 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
755 get_font_size(This
, val
);
757 V_I4(out
) = strtolW(val
, NULL
, 10);
764 static const WCHAR format
[] = {'%','d',0};
765 wsprintfW(size
, format
, V_I4(in
));
766 set_font_size(This
, size
);
770 set_font_size(This
, V_BSTR(in
));
773 FIXME("unsupported vt %d\n", V_VT(in
));
776 update_doc(This
, UPDATE_UI
);
782 static HRESULT
exec_selectall(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
784 TRACE("(%p)\n", This
);
787 FIXME("unsupported args\n");
789 if(This
->nscontainer
)
790 do_ns_command(This
->nscontainer
, NSCMD_SELECTALL
, NULL
);
792 update_doc(This
, UPDATE_UI
);
796 static HRESULT
exec_bold(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
798 TRACE("(%p)\n", This
);
801 FIXME("unsupported args\n");
803 if(This
->nscontainer
)
804 do_ns_command(This
->nscontainer
, NSCMD_BOLD
, NULL
);
806 update_doc(This
, UPDATE_UI
);
810 static HRESULT
exec_italic(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
812 TRACE("(%p)\n", This
);
815 FIXME("unsupported args\n");
817 if(This
->nscontainer
)
818 do_ns_command(This
->nscontainer
, NSCMD_ITALIC
, NULL
);
820 update_doc(This
, UPDATE_UI
);
824 static HRESULT
query_justify(HTMLDocument
*This
, OLECMD
*cmd
)
827 case IDM_JUSTIFYCENTER
:
828 TRACE("(%p) IDM_JUSTIFYCENTER\n", This
);
829 cmd
->cmdf
= query_align_status(This
, NSALIGN_CENTER
);
831 case IDM_JUSTIFYLEFT
:
832 TRACE("(%p) IDM_JUSTIFYLEFT\n", This
);
833 /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
834 if(This
->usermode
!= EDITMODE
|| This
->readystate
< READYSTATE_INTERACTIVE
)
835 cmd
->cmdf
= OLECMDF_SUPPORTED
;
837 cmd
->cmdf
= OLECMDF_SUPPORTED
| OLECMDF_ENABLED
;
839 case IDM_JUSTIFYRIGHT
:
840 TRACE("(%p) IDM_JUSTIFYRIGHT\n", This
);
841 cmd
->cmdf
= query_align_status(This
, NSALIGN_RIGHT
);
848 static HRESULT
exec_justifycenter(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
850 TRACE("(%p)\n", This
);
853 FIXME("unsupported args\n");
855 set_ns_align(This
, NSALIGN_CENTER
);
856 update_doc(This
, UPDATE_UI
);
860 static HRESULT
exec_justifyleft(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
862 TRACE("(%p)\n", This
);
865 FIXME("unsupported args\n");
867 set_ns_align(This
, NSALIGN_LEFT
);
868 update_doc(This
, UPDATE_UI
);
872 static HRESULT
exec_justifyright(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
874 TRACE("(%p)\n", This
);
877 FIXME("unsupported args\n");
879 set_ns_align(This
, NSALIGN_RIGHT
);
880 update_doc(This
, UPDATE_UI
);
884 static HRESULT
exec_underline(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
886 TRACE("(%p)\n", This
);
889 FIXME("unsupported args\n");
891 if(This
->nscontainer
)
892 do_ns_command(This
->nscontainer
, NSCMD_UNDERLINE
, NULL
);
894 update_doc(This
, UPDATE_UI
);
898 static HRESULT
exec_horizontalline(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
900 TRACE("(%p)\n", This
);
903 FIXME("unsupported args\n");
905 if(This
->nscontainer
)
906 do_ns_command(This
->nscontainer
, NSCMD_INSERTHR
, NULL
);
908 update_doc(This
, UPDATE_UI
);
912 static HRESULT
exec_orderlist(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
914 TRACE("(%p)\n", This
);
917 FIXME("unsupported args\n");
919 if(This
->nscontainer
)
920 do_ns_command(This
->nscontainer
, NSCMD_OL
, NULL
);
922 update_doc(This
, UPDATE_UI
);
926 static HRESULT
exec_unorderlist(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
928 TRACE("(%p)\n", This
);
931 FIXME("unsupported args\n");
933 if(This
->nscontainer
)
934 do_ns_command(This
->nscontainer
, NSCMD_UL
, NULL
);
936 update_doc(This
, UPDATE_UI
);
940 static HRESULT
exec_indent(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
942 TRACE("(%p)\n", This
);
945 FIXME("unsupported args\n");
947 if(This
->nscontainer
)
948 do_ns_command(This
->nscontainer
, NSCMD_INDENT
, NULL
);
950 update_doc(This
, UPDATE_UI
);
954 static HRESULT
exec_outdent(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
956 TRACE("(%p)\n", This
);
959 FIXME("unsupported args\n");
961 if(This
->nscontainer
)
962 do_ns_command(This
->nscontainer
, NSCMD_OUTDENT
, NULL
);
964 update_doc(This
, UPDATE_UI
);
968 static HRESULT
exec_composesettings(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
972 if(out
|| !in
|| V_VT(in
) != VT_BSTR
) {
973 WARN("invalid arg\n");
977 TRACE("(%p)->(%x %s)\n", This
, cmdexecopt
, debugstr_w(V_BSTR(in
)));
979 update_doc(This
, UPDATE_UI
);
983 exec_bold(This
, cmdexecopt
, NULL
, NULL
);
984 ptr
= strchrW(ptr
, ',');
989 exec_italic(This
, cmdexecopt
, NULL
, NULL
);
990 ptr
= strchrW(ptr
, ',');
995 exec_underline(This
, cmdexecopt
, NULL
, NULL
);
996 ptr
= strchrW(ptr
, ',');
1000 if(isdigitW(*++ptr
)) {
1004 V_I4(&v
) = *ptr
-'0';
1006 exec_fontsize(This
, cmdexecopt
, &v
, NULL
);
1008 ptr
= strchrW(ptr
, ',');
1013 FIXME("set font color\n");
1014 ptr
= strchrW(ptr
, ',');
1019 FIXME("set background color\n");
1020 ptr
= strchrW(ptr
, ',');
1029 V_BSTR(&v
) = SysAllocString(ptr
);
1031 exec_fontname(This
, cmdexecopt
, &v
, NULL
);
1033 SysFreeString(V_BSTR(&v
));
1039 HRESULT
editor_exec_copy(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
1041 update_doc(This
, UPDATE_UI
);
1043 if(!This
->nscontainer
)
1046 do_ns_editor_command(This
->nscontainer
, NSCMD_COPY
);
1050 HRESULT
editor_exec_cut(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
1052 update_doc(This
, UPDATE_UI
);
1054 if(!This
->nscontainer
)
1057 do_ns_editor_command(This
->nscontainer
, NSCMD_CUT
);
1061 HRESULT
editor_exec_paste(HTMLDocument
*This
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
1063 update_doc(This
, UPDATE_UI
);
1065 if(!This
->nscontainer
)
1068 do_ns_editor_command(This
->nscontainer
, NSCMD_PASTE
);
1072 static HRESULT
query_edit_status(HTMLDocument
*This
, OLECMD
*cmd
)
1074 switch(cmd
->cmdID
) {
1076 TRACE("CGID_MSHTML: IDM_DELETE\n");
1077 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1080 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
1081 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1084 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
1085 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1088 TRACE("CGID_MSHTML: IDM_BOLD\n");
1089 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_BOLD
);
1092 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
1093 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1096 TRACE("CGID_MSHTML: IDM_ITALIC\n");
1097 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_ITALIC
);
1100 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
1101 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_UNDERLINE
);
1103 case IDM_HORIZONTALLINE
:
1104 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1105 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1108 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
1109 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_OL
);
1111 case IDM_UNORDERLIST
:
1112 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
1113 cmd
->cmdf
= query_ns_edit_status(This
, NSCMD_UL
);
1116 TRACE("CGID_MSHTML: IDM_INDENT\n");
1117 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1120 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
1121 cmd
->cmdf
= query_ns_edit_status(This
, NULL
);
1128 static HRESULT
query_selall_status(HTMLDocument
*This
, OLECMD
*cmd
)
1130 TRACE("(%p)->(%p)\n", This
, cmd
);
1132 cmd
->cmdf
= OLECMDF_SUPPORTED
|OLECMDF_ENABLED
;
1136 const cmdtable_t editmode_cmds
[] = {
1137 {IDM_DELETE
, query_edit_status
, exec_delete
},
1138 {IDM_FONTNAME
, query_edit_status
, exec_fontname
},
1139 {IDM_FONTSIZE
, query_edit_status
, exec_fontsize
},
1140 {IDM_SELECTALL
, query_selall_status
, exec_selectall
},
1141 {IDM_FORECOLOR
, query_edit_status
, exec_forecolor
},
1142 {IDM_BOLD
, query_edit_status
, exec_bold
},
1143 {IDM_ITALIC
, query_edit_status
, exec_italic
},
1144 {IDM_JUSTIFYCENTER
, query_justify
, exec_justifycenter
},
1145 {IDM_JUSTIFYRIGHT
, query_justify
, exec_justifyright
},
1146 {IDM_JUSTIFYLEFT
, query_justify
, exec_justifyleft
},
1147 {IDM_UNDERLINE
, query_edit_status
, exec_underline
},
1148 {IDM_HORIZONTALLINE
, query_edit_status
, exec_horizontalline
},
1149 {IDM_ORDERLIST
, query_edit_status
, exec_orderlist
},
1150 {IDM_UNORDERLIST
, query_edit_status
, exec_unorderlist
},
1151 {IDM_INDENT
, query_edit_status
, exec_indent
},
1152 {IDM_OUTDENT
, query_edit_status
, exec_outdent
},
1153 {IDM_COMPOSESETTINGS
, NULL
, exec_composesettings
},
1157 void init_editor(HTMLDocument
*This
)
1159 update_doc(This
, UPDATE_UI
);
1161 if(!This
->nscontainer
)
1164 set_ns_fontname(This
->nscontainer
, "Times New Roman");