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
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
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_SELECTBEGINLINE "cmd_selectBeginLine"
64 #define NSCMD_SELECTBOTTOM "cmd_selectBottom"
65 #define NSCMD_SELECTCHARNEXT "cmd_selectCharNext"
66 #define NSCMD_SELECTCHARPREVIOUS "cmd_selectCharPrevious"
67 #define NSCMD_SELECTENDLINE "cmd_selectEndLine"
68 #define NSCMD_SELECTLINENEXT "cmd_selectLineNext"
69 #define NSCMD_SELECTLINEPREVIOUS "cmd_selectLinePrevious"
70 #define NSCMD_SELECTPAGEDOWN "cmd_selectPageDown"
71 #define NSCMD_SELECTPAGEUP "cmd_selectPageUp"
72 #define NSCMD_SELECTTOP "cmd_selectTop"
73 #define NSCMD_SELECTWORDNEXT "cmd_selectWordNext"
74 #define NSCMD_SELECTWORDPREVIOUS "cmd_selectWordPrevious"
75 #define NSCMD_UL "cmd_ul"
76 #define NSCMD_UNDERLINE "cmd_underline"
77 #define NSCMD_WORDNEXT "cmd_wordNext"
78 #define NSCMD_WORDPREVIOUS "cmd_wordPrevious"
80 #define NSSTATE_ATTRIBUTE "state_attribute"
81 #define NSSTATE_ALL "state_all"
83 #define NSALIGN_CENTER "center"
84 #define NSALIGN_LEFT "left"
85 #define NSALIGN_RIGHT "right"
87 #define DOM_VK_LEFT VK_LEFT
88 #define DOM_VK_UP VK_UP
89 #define DOM_VK_RIGHT VK_RIGHT
90 #define DOM_VK_DOWN VK_DOWN
91 #define DOM_VK_DELETE VK_DELETE
92 #define DOM_VK_HOME VK_HOME
93 #define DOM_VK_END VK_END
95 static const WCHAR fontW
[] = {'f','o','n','t',0};
96 static const WCHAR sizeW
[] = {'s','i','z','e',0};
98 void set_dirty(GeckoBrowser
*browser
, VARIANT_BOOL dirty
)
102 if(browser
->usermode
!= EDITMODE
|| !browser
->editor
)
106 nsres
= nsIEditor_IncrementModificationCount(browser
->editor
, 1);
108 ERR("IncrementModificationCount failed: %08x\n", nsres
);
110 nsres
= nsIEditor_ResetModificationCount(browser
->editor
);
112 ERR("ResetModificationCount failed: %08x\n", nsres
);
116 static void do_ns_editor_command(GeckoBrowser
*This
, const char *cmd
)
120 if(!This
->editor_controller
)
123 nsres
= nsIController_DoCommand(This
->editor_controller
, cmd
);
125 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
128 static nsresult
get_ns_command_state(GeckoBrowser
*This
, const char *cmd
, nsICommandParams
*nsparam
)
130 nsICommandManager
*cmdmgr
;
133 nsres
= get_nsinterface((nsISupports
*)This
->webbrowser
, &IID_nsICommandManager
, (void**)&cmdmgr
);
134 if(NS_FAILED(nsres
)) {
135 ERR("Could not get nsICommandManager: %08x\n", nsres
);
139 nsres
= nsICommandManager_GetCommandState(cmdmgr
, cmd
, This
->doc
->basedoc
.window
->window_proxy
, nsparam
);
141 ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd
), nsres
);
143 nsICommandManager_Release(cmdmgr
);
147 static DWORD
query_ns_edit_status(HTMLDocumentNode
*doc
, const char *nscmd
)
149 nsICommandParams
*nsparam
;
152 if(doc
->browser
->usermode
!= EDITMODE
|| doc
->basedoc
.window
->readystate
< READYSTATE_INTERACTIVE
)
153 return OLECMDF_SUPPORTED
;
156 nsparam
= create_nscommand_params();
157 get_ns_command_state(doc
->browser
, nscmd
, nsparam
);
159 nsICommandParams_GetBooleanValue(nsparam
, NSSTATE_ALL
, &b
);
161 nsICommandParams_Release(nsparam
);
164 return OLECMDF_SUPPORTED
| OLECMDF_ENABLED
| (b
? OLECMDF_LATCHED
: 0);
167 static void set_ns_align(HTMLDocumentNode
*doc
, const char *align_str
)
169 nsICommandParams
*nsparam
;
171 nsparam
= create_nscommand_params();
172 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, align_str
);
174 do_ns_command(doc
, NSCMD_ALIGN
, nsparam
);
176 nsICommandParams_Release(nsparam
);
179 static DWORD
query_align_status(HTMLDocumentNode
*doc
, const WCHAR
*align
)
181 DWORD ret
= OLECMDF_SUPPORTED
| OLECMDF_ENABLED
;
182 nsAString justify_str
;
186 if(doc
->browser
->usermode
!= EDITMODE
|| doc
->basedoc
.window
->readystate
< READYSTATE_INTERACTIVE
)
187 return OLECMDF_SUPPORTED
;
189 nsAString_Init(&justify_str
, align
);
190 nsres
= nsIDOMHTMLDocument_QueryCommandState(doc
->nsdoc
, &justify_str
, &b
);
191 nsAString_Finish(&justify_str
);
192 if(NS_SUCCEEDED(nsres
) && b
)
193 ret
|= OLECMDF_LATCHED
;
199 static nsISelection
*get_ns_selection(HTMLDocumentNode
*doc
)
201 nsISelection
*nsselection
= NULL
;
204 nsres
= nsIDOMWindow_GetSelection(doc
->basedoc
.window
->nswindow
, &nsselection
);
206 ERR("GetSelection failed %08x\n", nsres
);
212 static void remove_child_attr(nsIDOMElement
*elem
, LPCWSTR tag
, nsAString
*attr_str
)
214 cpp_bool has_children
;
216 nsIDOMNode
*child_node
;
217 nsIDOMNodeList
*node_list
;
220 nsIDOMElement_HasChildNodes(elem
, &has_children
);
224 nsIDOMElement_GetChildNodes(elem
, &node_list
);
225 nsIDOMNodeList_GetLength(node_list
, &child_cnt
);
227 for(i
=0; i
<child_cnt
; i
++) {
228 nsIDOMNodeList_Item(node_list
, i
, &child_node
);
230 nsIDOMNode_GetNodeType(child_node
, &node_type
);
231 if(node_type
== ELEMENT_NODE
) {
232 nsIDOMElement
*child_elem
;
234 const PRUnichar
*ctag
;
236 nsIDOMNode_QueryInterface(child_node
, &IID_nsIDOMElement
, (void**)&child_elem
);
238 nsAString_Init(&tag_str
, NULL
);
239 nsIDOMElement_GetTagName(child_elem
, &tag_str
);
240 nsAString_GetData(&tag_str
, &ctag
);
242 if(!wcsicmp(ctag
, tag
))
243 /* FIXME: remove node if there are no more attributes */
244 nsIDOMElement_RemoveAttribute(child_elem
, attr_str
);
246 nsAString_Finish(&tag_str
);
248 remove_child_attr(child_elem
, tag
, attr_str
);
250 nsIDOMElement_Release(child_elem
);
253 nsIDOMNode_Release(child_node
);
256 nsIDOMNodeList_Release(node_list
);
259 static void get_font_size(HTMLDocumentNode
*doc
, WCHAR
*ret
)
261 nsISelection
*nsselection
= get_ns_selection(doc
);
262 nsIDOMElement
*elem
= NULL
;
263 nsIDOMNode
*node
= NULL
, *tmp_node
;
274 nsISelection_GetFocusNode(nsselection
, &node
);
275 nsISelection_Release(nsselection
);
278 nsres
= nsIDOMNode_GetNodeType(node
, &node_type
);
279 if(NS_FAILED(nsres
) || node_type
== DOCUMENT_NODE
)
282 if(node_type
== ELEMENT_NODE
) {
283 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
285 nsAString_Init(&tag_str
, NULL
);
286 nsIDOMElement_GetTagName(elem
, &tag_str
);
287 nsAString_GetData(&tag_str
, &tag
);
289 if(!wcsicmp(tag
, fontW
)) {
291 const PRUnichar
*val
;
293 TRACE("found font tag %p\n", elem
);
295 get_elem_attr_value(elem
, sizeW
, &val_str
, &val
);
297 TRACE("found size %s\n", debugstr_w(val
));
301 nsAString_Finish(&val_str
);
304 nsAString_Finish(&tag_str
);
305 nsIDOMElement_Release(elem
);
312 nsIDOMNode_GetParentNode(node
, &node
);
313 nsIDOMNode_Release(tmp_node
);
317 nsIDOMNode_Release(node
);
320 static void set_font_size(HTMLDocumentNode
*doc
, LPCWSTR size
)
322 nsISelection
*nsselection
;
330 nsselection
= get_ns_selection(doc
);
334 nsISelection_GetRangeCount(nsselection
, &range_cnt
);
336 FIXME("range_cnt %d not supprted\n", range_cnt
);
338 nsISelection_Release(nsselection
);
343 create_nselem(doc
, fontW
, &elem
);
345 nsAString_InitDepend(&size_str
, sizeW
);
346 nsAString_InitDepend(&val_str
, size
);
348 nsIDOMElement_SetAttribute(elem
, &size_str
, &val_str
);
349 nsAString_Finish(&val_str
);
351 nsISelection_GetRangeAt(nsselection
, 0, &range
);
352 nsISelection_GetIsCollapsed(nsselection
, &collapsed
);
353 nsISelection_RemoveAllRanges(nsselection
);
355 nsIDOMRange_SurroundContents(range
, (nsIDOMNode
*)elem
);
358 nsISelection_Collapse(nsselection
, (nsIDOMNode
*)elem
, 0);
360 /* Remove all size attributes from the range */
361 remove_child_attr(elem
, fontW
, &size_str
);
362 nsISelection_SelectAllChildren(nsselection
, (nsIDOMNode
*)elem
);
365 nsISelection_Release(nsselection
);
366 nsIDOMRange_Release(range
);
367 nsIDOMElement_Release(elem
);
369 nsAString_Finish(&size_str
);
371 set_dirty(doc
->browser
, VARIANT_TRUE
);
374 static void handle_arrow_key(HTMLDocumentNode
*doc
, nsIDOMEvent
*event
, nsIDOMKeyEvent
*key_event
, const char * const cmds
[4])
379 nsIDOMKeyEvent_GetCtrlKey(key_event
, &b
);
383 nsIDOMKeyEvent_GetShiftKey(key_event
, &b
);
388 do_ns_editor_command(doc
->browser
, cmds
[i
]);
390 nsIDOMEvent_PreventDefault(event
);
393 void handle_edit_event(HTMLDocumentNode
*doc
, nsIDOMEvent
*event
)
395 nsIDOMKeyEvent
*key_event
;
398 nsIDOMEvent_QueryInterface(event
, &IID_nsIDOMKeyEvent
, (void**)&key_event
);
400 nsIDOMKeyEvent_GetKeyCode(key_event
, &code
);
404 static const char * const cmds
[] = {
407 NSCMD_SELECTCHARPREVIOUS
,
408 NSCMD_SELECTWORDPREVIOUS
412 handle_arrow_key(doc
, event
, key_event
, cmds
);
416 static const char * const cmds
[] = {
419 NSCMD_SELECTCHARNEXT
,
424 handle_arrow_key(doc
, event
, key_event
, cmds
);
428 static const char * const cmds
[] = {
431 NSCMD_SELECTLINEPREVIOUS
,
436 handle_arrow_key(doc
, event
, key_event
, cmds
);
440 static const char * const cmds
[] = {
443 NSCMD_SELECTLINENEXT
,
448 handle_arrow_key(doc
, event
, key_event
, cmds
);
451 case DOM_VK_DELETE
: {
452 static const char * const cmds
[] = {
453 NSCMD_DELETECHARFORWARD
,
454 NSCMD_DELETEWORDFORWARD
,
459 handle_arrow_key(doc
, event
, key_event
, cmds
);
463 static const char * const cmds
[] = {
466 NSCMD_SELECTBEGINLINE
,
471 handle_arrow_key(doc
, event
, key_event
, cmds
);
475 static const char * const cmds
[] = {
483 handle_arrow_key(doc
, event
, key_event
, cmds
);
488 nsIDOMKeyEvent_Release(key_event
);
491 static void set_ns_fontname(HTMLDocumentNode
*doc
, const char *fontname
)
493 nsICommandParams
*nsparam
= create_nscommand_params();
495 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, fontname
);
496 do_ns_command(doc
, NSCMD_FONTFACE
, nsparam
);
497 nsICommandParams_Release(nsparam
);
500 static HRESULT
exec_delete(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
502 TRACE("(%p)->(%p %p)\n", doc
, in
, out
);
504 do_ns_editor_command(doc
->browser
, NSCMD_DELETECHARFORWARD
);
506 update_doc(doc
->browser
->doc
, UPDATE_UI
);
510 static HRESULT
exec_fontname(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
512 TRACE("(%p)->(%p %p)\n", doc
, in
, out
);
517 if(V_VT(in
) != VT_BSTR
) {
518 FIXME("Unsupported fontname %s\n", debugstr_variant(out
));
522 TRACE("%s\n", debugstr_w(V_BSTR(in
)));
524 stra
= heap_strdupWtoA(V_BSTR(in
));
525 set_ns_fontname(doc
, stra
);
528 update_doc(doc
->browser
->doc
, UPDATE_UI
);
532 nsICommandParams
*nsparam
;
541 nsparam
= create_nscommand_params();
543 nsres
= get_ns_command_state(doc
->browser
, NSCMD_FONTFACE
, nsparam
);
547 nsICommandParams_GetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, &stra
);
548 nsICommandParams_Release(nsparam
);
550 len
= MultiByteToWideChar(CP_ACP
, 0, stra
, -1, NULL
, 0);
551 strw
= heap_alloc(len
*sizeof(WCHAR
));
552 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, strw
, len
);
555 V_BSTR(out
) = SysAllocString(strw
);
562 static HRESULT
exec_forecolor(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
564 TRACE("(%p)->(%p %p)\n", doc
, in
, out
);
567 if(V_VT(in
) == VT_I4
) {
568 nsICommandParams
*nsparam
= create_nscommand_params();
571 sprintf(color_str
, "#%02x%02x%02x",
572 V_I4(in
)&0xff, (V_I4(in
)>>8)&0xff, (V_I4(in
)>>16)&0xff);
574 nsICommandParams_SetCStringValue(nsparam
, NSSTATE_ATTRIBUTE
, color_str
);
575 do_ns_command(doc
, NSCMD_FONTCOLOR
, nsparam
);
577 nsICommandParams_Release(nsparam
);
579 FIXME("unsupported forecolor %s\n", debugstr_variant(in
));
582 update_doc(doc
->browser
->doc
, UPDATE_UI
);
586 FIXME("unsupported out\n");
593 static HRESULT
exec_fontsize(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
595 TRACE("(%p)->(%p %p)\n", doc
, in
, out
);
600 get_font_size(doc
, val
);
602 V_I4(out
) = wcstol(val
, NULL
, 10);
609 static const WCHAR format
[] = {'%','d',0};
610 wsprintfW(size
, format
, V_I4(in
));
611 set_font_size(doc
, size
);
615 set_font_size(doc
, V_BSTR(in
));
618 FIXME("unsupported fontsize %s\n", debugstr_variant(in
));
621 update_doc(doc
->browser
->doc
, UPDATE_UI
);
627 static HRESULT
exec_font(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
630 FIXME("(%p)->(%p %p)\n", doc
, in
, out
);
634 static HRESULT
exec_bold(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
636 TRACE("(%p)\n", doc
);
639 FIXME("unsupported args\n");
641 do_ns_command(doc
, NSCMD_BOLD
, NULL
);
642 update_doc(doc
->browser
->doc
, UPDATE_UI
);
646 static HRESULT
exec_italic(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
648 TRACE("(%p)\n", doc
);
651 FIXME("unsupported args\n");
653 do_ns_command(doc
, NSCMD_ITALIC
, NULL
);
654 update_doc(doc
->browser
->doc
, UPDATE_UI
);
658 static HRESULT
query_justify(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
660 static const PRUnichar justifycenterW
[] = {'j','u','s','t','i','f','y','c','e','n','t','e','r',0};
661 static const PRUnichar justifyrightW
[] = {'j','u','s','t','i','f','y','r','i','g','h','t',0};
664 case IDM_JUSTIFYCENTER
:
665 TRACE("(%p) IDM_JUSTIFYCENTER\n", doc
);
666 cmd
->cmdf
= query_align_status(doc
, justifycenterW
);
668 case IDM_JUSTIFYLEFT
:
669 TRACE("(%p) IDM_JUSTIFYLEFT\n", doc
);
670 /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
671 if(doc
->browser
->usermode
!= EDITMODE
|| doc
->basedoc
.window
->readystate
< READYSTATE_INTERACTIVE
)
672 cmd
->cmdf
= OLECMDF_SUPPORTED
;
674 cmd
->cmdf
= OLECMDF_SUPPORTED
| OLECMDF_ENABLED
;
676 case IDM_JUSTIFYRIGHT
:
677 TRACE("(%p) IDM_JUSTIFYRIGHT\n", doc
);
678 cmd
->cmdf
= query_align_status(doc
, justifyrightW
);
685 static HRESULT
exec_justifycenter(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
687 TRACE("(%p)\n", doc
);
690 FIXME("unsupported args\n");
692 set_ns_align(doc
, NSALIGN_CENTER
);
693 update_doc(doc
->browser
->doc
, UPDATE_UI
);
697 static HRESULT
exec_justifyleft(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
699 TRACE("(%p)\n", doc
);
702 FIXME("unsupported args\n");
704 set_ns_align(doc
, NSALIGN_LEFT
);
705 update_doc(doc
->browser
->doc
, UPDATE_UI
);
709 static HRESULT
exec_justifyright(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
711 TRACE("(%p)\n", doc
);
714 FIXME("unsupported args\n");
716 set_ns_align(doc
, NSALIGN_RIGHT
);
717 update_doc(doc
->browser
->doc
, UPDATE_UI
);
721 static HRESULT
exec_underline(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
723 TRACE("(%p)\n", doc
);
726 FIXME("unsupported args\n");
728 do_ns_command(doc
, NSCMD_UNDERLINE
, NULL
);
729 update_doc(doc
->browser
->doc
, UPDATE_UI
);
733 static HRESULT
exec_horizontalline(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
735 TRACE("(%p)\n", doc
);
738 FIXME("unsupported args\n");
740 do_ns_command(doc
, NSCMD_INSERTHR
, NULL
);
741 update_doc(doc
->browser
->doc
, UPDATE_UI
);
745 static HRESULT
exec_orderlist(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
747 TRACE("(%p)\n", doc
);
750 FIXME("unsupported args\n");
752 do_ns_command(doc
, NSCMD_OL
, NULL
);
753 update_doc(doc
->browser
->doc
, UPDATE_UI
);
757 static HRESULT
exec_unorderlist(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
759 TRACE("(%p)\n", doc
);
762 FIXME("unsupported args\n");
764 do_ns_command(doc
, NSCMD_UL
, NULL
);
765 update_doc(doc
->browser
->doc
, UPDATE_UI
);
769 static HRESULT
exec_indent(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
771 TRACE("(%p)\n", doc
);
774 FIXME("unsupported args\n");
776 do_ns_command(doc
, NSCMD_INDENT
, NULL
);
777 update_doc(doc
->browser
->doc
, UPDATE_UI
);
781 static HRESULT
exec_outdent(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
783 TRACE("(%p)\n", doc
);
786 FIXME("unsupported args\n");
788 do_ns_command(doc
, NSCMD_OUTDENT
, NULL
);
789 update_doc(doc
->browser
->doc
, UPDATE_UI
);
793 static HRESULT
exec_composesettings(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
797 if(out
|| !in
|| V_VT(in
) != VT_BSTR
) {
798 WARN("invalid arg %s\n", debugstr_variant(in
));
802 TRACE("(%p)->(%x %s)\n", doc
, cmdexecopt
, debugstr_w(V_BSTR(in
)));
804 update_doc(doc
->browser
->doc
, UPDATE_UI
);
808 exec_bold(doc
, cmdexecopt
, NULL
, NULL
);
809 ptr
= wcschr(ptr
, ',');
814 exec_italic(doc
, cmdexecopt
, NULL
, NULL
);
815 ptr
= wcschr(ptr
, ',');
820 exec_underline(doc
, cmdexecopt
, NULL
, NULL
);
821 ptr
= wcschr(ptr
, ',');
825 if(is_digit(*++ptr
)) {
831 exec_fontsize(doc
, cmdexecopt
, &v
, NULL
);
833 ptr
= wcschr(ptr
, ',');
838 FIXME("set font color\n");
839 ptr
= wcschr(ptr
, ',');
844 FIXME("set background color\n");
845 ptr
= wcschr(ptr
, ',');
854 V_BSTR(&v
) = SysAllocString(ptr
);
856 exec_fontname(doc
, cmdexecopt
, &v
, NULL
);
858 SysFreeString(V_BSTR(&v
));
864 HRESULT
editor_exec_copy(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
866 update_doc(doc
->browser
->doc
, UPDATE_UI
);
867 do_ns_editor_command(doc
->browser
, NSCMD_COPY
);
871 HRESULT
editor_exec_cut(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
873 update_doc(doc
->browser
->doc
, UPDATE_UI
);
874 do_ns_editor_command(doc
->browser
, NSCMD_CUT
);
878 HRESULT
editor_exec_paste(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
880 update_doc(doc
->browser
->doc
, UPDATE_UI
);
881 do_ns_editor_command(doc
->browser
, NSCMD_PASTE
);
885 static HRESULT
exec_setdirty(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
887 TRACE("(%p)->(%08x %p %p)\n", doc
, cmdexecopt
, in
, out
);
892 if(V_VT(in
) == VT_BOOL
)
893 set_dirty(doc
->browser
, V_BOOL(in
));
895 FIXME("unsupported arg %s\n", debugstr_variant(in
));
900 static HRESULT
query_edit_status(HTMLDocumentNode
*doc
, OLECMD
*cmd
)
904 TRACE("CGID_MSHTML: IDM_DELETE\n");
905 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
908 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
909 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
912 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
913 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
916 TRACE("CGID_MSHTML: IDM_BOLD\n");
917 cmd
->cmdf
= query_ns_edit_status(doc
, NSCMD_BOLD
);
920 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
921 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
924 TRACE("CGID_MSHTML: IDM_ITALIC\n");
925 cmd
->cmdf
= query_ns_edit_status(doc
, NSCMD_ITALIC
);
928 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
929 cmd
->cmdf
= query_ns_edit_status(doc
, NSCMD_UNDERLINE
);
931 case IDM_HORIZONTALLINE
:
932 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
933 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
936 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
937 cmd
->cmdf
= query_ns_edit_status(doc
, NSCMD_OL
);
939 case IDM_UNORDERLIST
:
940 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
941 cmd
->cmdf
= query_ns_edit_status(doc
, NSCMD_UL
);
944 TRACE("CGID_MSHTML: IDM_INDENT\n");
945 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
948 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
949 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
952 TRACE("CGID_MSHTML: IDM_HYPERLINK\n");
953 cmd
->cmdf
= query_ns_edit_status(doc
, NULL
);
960 static INT_PTR CALLBACK
hyperlink_dlgproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
962 static const WCHAR wszOther
[] = {'(','o','t','h','e','r',')',0};
963 static const WCHAR wszFile
[] = {'f','i','l','e',':',0};
964 static const WCHAR wszFtp
[] = {'f','t','p',':',0};
965 static const WCHAR wszHttp
[] = {'h','t','t','p',':',0};
966 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':',0};
967 static const WCHAR wszMailto
[] = {'m','a','i','l','t','o',':',0};
968 static const WCHAR wszNews
[] = {'n','e','w','s',':',0};
975 HWND hwndCB
= GetDlgItem(hwnd
, IDC_TYPE
);
976 HWND hwndURL
= GetDlgItem(hwnd
, IDC_URL
);
979 SetWindowLongPtrW(hwnd
, DWLP_USER
, lparam
);
981 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszOther
);
982 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszFile
);
983 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszFtp
);
984 def_idx
= SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszHttp
);
985 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszHttps
);
986 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszMailto
);
987 SendMessageW(hwndCB
, CB_INSERTSTRING
, -1, (LPARAM
)wszNews
);
988 SendMessageW(hwndCB
, CB_SETCURSEL
, def_idx
, 0);
990 /* force the updating of the URL edit box */
991 SendMessageW(hwnd
, WM_COMMAND
, MAKEWPARAM(IDC_TYPE
, CBN_SELCHANGE
), (LPARAM
)hwndCB
);
994 len
= SendMessageW(hwndURL
, WM_GETTEXTLENGTH
, 0, 0);
995 SendMessageW(hwndURL
, EM_SETSEL
, 0, len
);
1002 case MAKEWPARAM(IDCANCEL
, BN_CLICKED
):
1003 EndDialog(hwnd
, wparam
);
1005 case MAKEWPARAM(IDOK
, BN_CLICKED
):
1007 BSTR
*url
= (BSTR
*)GetWindowLongPtrW(hwnd
, DWLP_USER
);
1008 HWND hwndURL
= GetDlgItem(hwnd
, IDC_URL
);
1009 INT len
= GetWindowTextLengthW(hwndURL
);
1010 *url
= SysAllocStringLen(NULL
, len
+ 1);
1011 GetWindowTextW(hwndURL
, *url
, len
+ 1);
1012 EndDialog(hwnd
, wparam
);
1015 case MAKEWPARAM(IDC_TYPE
, CBN_SELCHANGE
):
1017 HWND hwndURL
= GetDlgItem(hwnd
, IDC_URL
);
1023 static const WCHAR wszSlashSlash
[] = {'/','/'};
1025 /* get string of currently selected hyperlink type */
1026 item
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
1027 len
= SendMessageW((HWND
)lparam
, CB_GETLBTEXTLEN
, item
, 0);
1028 type
= HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1029 SendMessageW((HWND
)lparam
, CB_GETLBTEXT
, item
, (LPARAM
)type
);
1031 if (!wcscmp(type
, wszOther
))
1034 /* get current URL */
1035 len
= GetWindowTextLengthW(hwndURL
);
1036 url
= HeapAlloc(GetProcessHeap(), 0, (len
+ lstrlenW(type
) + 3) * sizeof(WCHAR
));
1037 GetWindowTextW(hwndURL
, url
, len
+ 1);
1039 /* strip off old protocol */
1040 p
= wcschr(url
, ':');
1041 if (p
&& p
[1] == '/' && p
[2] == '/')
1044 memmove(url
+ (*type
!= '\0' ? lstrlenW(type
) + 2 : 0), p
, (len
+ 1 - (p
- url
)) * sizeof(WCHAR
));
1046 /* add new protocol */
1049 memcpy(url
, type
, (lstrlenW(type
) + 1) * sizeof(WCHAR
));
1050 if (wcscmp(type
, wszMailto
) && wcscmp(type
, wszNews
))
1051 memcpy(url
+ lstrlenW(type
), wszSlashSlash
, sizeof(wszSlashSlash
));
1054 SetWindowTextW(hwndURL
, url
);
1056 HeapFree(GetProcessHeap(), 0, url
);
1057 HeapFree(GetProcessHeap(), 0, type
);
1063 EndDialog(hwnd
, IDCANCEL
);
1070 static HRESULT
exec_hyperlink(HTMLDocumentNode
*doc
, DWORD cmdexecopt
, VARIANT
*in
, VARIANT
*out
)
1072 nsAString href_str
, ns_url
;
1073 nsIHTMLEditor
*html_editor
;
1074 nsIDOMElement
*anchor_elem
;
1075 cpp_bool insert_link_at_caret
;
1076 nsISelection
*nsselection
;
1079 HRESULT hres
= E_FAIL
;
1081 static const WCHAR aW
[] = {'a',0};
1082 static const WCHAR hrefW
[] = {'h','r','e','f',0};
1084 TRACE("%p, 0x%x, %p, %p\n", doc
, cmdexecopt
, in
, out
);
1086 if (cmdexecopt
== OLECMDEXECOPT_DONTPROMPTUSER
)
1088 if (!in
|| V_VT(in
) != VT_BSTR
)
1090 WARN("invalid arg\n");
1091 return E_INVALIDARG
;
1097 ret
= DialogBoxParamW(hInst
, MAKEINTRESOURCEW(IDD_HYPERLINK
), NULL
/* FIXME */, hyperlink_dlgproc
, (LPARAM
)&url
);
1099 return OLECMDERR_E_CANCELED
;
1103 WARN("NULL nsdoc\n");
1104 return E_UNEXPECTED
;
1107 nsselection
= get_ns_selection(doc
);
1111 /* create an element for the link */
1112 create_nselem(doc
, aW
, &anchor_elem
);
1114 nsAString_InitDepend(&href_str
, hrefW
);
1115 nsAString_InitDepend(&ns_url
, url
);
1116 nsIDOMElement_SetAttribute(anchor_elem
, &href_str
, &ns_url
);
1117 nsAString_Finish(&href_str
);
1119 nsISelection_GetIsCollapsed(nsselection
, &insert_link_at_caret
);
1121 /* create an element with text of URL */
1122 if (insert_link_at_caret
) {
1123 nsIDOMNode
*unused_node
;
1124 nsIDOMText
*text_node
;
1126 nsIDOMHTMLDocument_CreateTextNode(doc
->nsdoc
, &ns_url
, &text_node
);
1128 /* wrap the <a> tags around the text element */
1129 nsIDOMElement_AppendChild(anchor_elem
, (nsIDOMNode
*)text_node
, &unused_node
);
1130 nsIDOMText_Release(text_node
);
1131 nsIDOMNode_Release(unused_node
);
1134 nsAString_Finish(&ns_url
);
1136 nsIEditor_QueryInterface(doc
->browser
->editor
, &IID_nsIHTMLEditor
, (void **)&html_editor
);
1140 if (insert_link_at_caret
) {
1141 /* add them to the document at the caret position */
1142 nsres
= nsIHTMLEditor_InsertElementAtSelection(html_editor
, anchor_elem
, FALSE
);
1143 nsISelection_SelectAllChildren(nsselection
, (nsIDOMNode
*)anchor_elem
);
1144 }else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
1145 nsres
= nsIHTMLEditor_InsertLinkAroundSelection(html_editor
, anchor_elem
);
1147 nsIHTMLEditor_Release(html_editor
);
1148 hres
= NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
1151 nsISelection_Release(nsselection
);
1152 nsIDOMElement_Release(anchor_elem
);
1154 if (cmdexecopt
!= OLECMDEXECOPT_DONTPROMPTUSER
)
1157 TRACE("-- 0x%08x\n", hres
);
1161 const cmdtable_t editmode_cmds
[] = {
1162 {IDM_DELETE
, query_edit_status
, exec_delete
},
1163 {IDM_FONTNAME
, query_edit_status
, exec_fontname
},
1164 {IDM_FONTSIZE
, query_edit_status
, exec_fontsize
},
1165 {IDM_FORECOLOR
, query_edit_status
, exec_forecolor
},
1166 {IDM_BOLD
, query_edit_status
, exec_bold
},
1167 {IDM_ITALIC
, query_edit_status
, exec_italic
},
1168 {IDM_JUSTIFYCENTER
, query_justify
, exec_justifycenter
},
1169 {IDM_JUSTIFYRIGHT
, query_justify
, exec_justifyright
},
1170 {IDM_JUSTIFYLEFT
, query_justify
, exec_justifyleft
},
1171 {IDM_FONT
, NULL
, exec_font
},
1172 {IDM_UNDERLINE
, query_edit_status
, exec_underline
},
1173 {IDM_HORIZONTALLINE
, query_edit_status
, exec_horizontalline
},
1174 {IDM_ORDERLIST
, query_edit_status
, exec_orderlist
},
1175 {IDM_UNORDERLIST
, query_edit_status
, exec_unorderlist
},
1176 {IDM_INDENT
, query_edit_status
, exec_indent
},
1177 {IDM_OUTDENT
, query_edit_status
, exec_outdent
},
1178 {IDM_COMPOSESETTINGS
, NULL
, exec_composesettings
},
1179 {IDM_HYPERLINK
, query_edit_status
, exec_hyperlink
},
1180 {IDM_SETDIRTY
, NULL
, exec_setdirty
},
1184 void init_editor(HTMLDocumentNode
*doc
)
1186 update_doc(doc
->browser
->doc
, UPDATE_UI
);
1188 set_ns_fontname(doc
, "Times New Roman");
1191 HRESULT
browser_is_dirty(GeckoBrowser
*browser
)
1195 if(browser
->usermode
!= EDITMODE
|| !browser
->editor
)
1198 nsIEditor_GetDocumentModified(browser
->editor
, &modified
);
1199 return modified
? S_OK
: S_FALSE
;
1202 HRESULT
setup_edit_mode(HTMLDocumentObj
*doc
)
1207 if(doc
->nscontainer
->usermode
== EDITMODE
)
1210 doc
->nscontainer
->usermode
= EDITMODE
;
1212 if(doc
->basedoc
.window
->mon
) {
1213 CLSID clsid
= IID_NULL
;
1214 hres
= IMoniker_GetClassID(doc
->basedoc
.window
->mon
, &clsid
);
1215 if(SUCCEEDED(hres
)) {
1216 /* We should use IMoniker::Save here */
1217 FIXME("Use CLSID %s\n", debugstr_guid(&clsid
));
1222 IOleInPlaceFrame_SetStatusText(doc
->frame
, NULL
);
1224 doc
->basedoc
.window
->readystate
= READYSTATE_UNINITIALIZED
;
1227 IOleCommandTarget
*cmdtrg
;
1229 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1230 if(SUCCEEDED(hres
)) {
1235 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 37, 0, &var
, NULL
);
1237 IOleCommandTarget_Release(cmdtrg
);
1242 DOCHOSTUIINFO hostinfo
;
1244 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
1245 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
1246 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
1248 /* FIXME: use hostinfo */
1249 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
1250 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
1251 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
1254 update_doc(doc
, UPDATE_UI
);
1256 if(doc
->basedoc
.window
->mon
) {
1257 /* FIXME: We should find nicer way to do this */
1258 remove_target_tasks(doc
->task_magic
);
1260 mon
= doc
->basedoc
.window
->mon
;
1261 IMoniker_AddRef(mon
);
1263 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
1265 hres
= CreateURLMoniker(NULL
, about_blankW
, &mon
);
1267 FIXME("CreateURLMoniker failed: %08x\n", hres
);
1272 hres
= IPersistMoniker_Load(&doc
->basedoc
.IPersistMoniker_iface
, TRUE
, mon
, NULL
, 0);
1273 IMoniker_Release(mon
);
1277 if(doc
->ui_active
) {
1279 call_set_active_object(doc
->ip_window
, NULL
);
1281 IDocHostUIHandler_HideUI(doc
->hostui
);
1284 if(doc
->ui_active
) {
1285 RECT rcBorderWidths
;
1288 IDocHostUIHandler_ShowUI(doc
->hostui
, DOCHOSTUITYPE_AUTHOR
,
1289 &doc
->basedoc
.IOleInPlaceActiveObject_iface
, &doc
->basedoc
.IOleCommandTarget_iface
,
1290 doc
->frame
, doc
->ip_window
);
1293 call_set_active_object(doc
->ip_window
, &doc
->basedoc
.IOleInPlaceActiveObject_iface
);
1295 SetRectEmpty(&rcBorderWidths
);
1297 IOleInPlaceFrame_SetBorderSpace(doc
->frame
, &rcBorderWidths
);