d3dcompiler_43: Use BOOL type where appropriate.
[wine.git] / dlls / mshtml / editor.c
blobcfab2edef8952553ee308054660c1315e305dcf4
1 /*
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28 #include "mshtmcid.h"
29 #include "shlguid.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "resource.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_SELECTALL "cmd_selectAll"
64 #define NSCMD_SELECTBEGINLINE "cmd_selectBeginLine"
65 #define NSCMD_SELECTBOTTOM "cmd_selectBottom"
66 #define NSCMD_SELECTCHARNEXT "cmd_selectCharNext"
67 #define NSCMD_SELECTCHARPREVIOUS "cmd_selectCharPrevious"
68 #define NSCMD_SELECTENDLINE "cmd_selectEndLine"
69 #define NSCMD_SELECTLINENEXT "cmd_selectLineNext"
70 #define NSCMD_SELECTLINEPREVIOUS "cmd_selectLinePrevious"
71 #define NSCMD_SELECTPAGEDOWN "cmd_selectPageDown"
72 #define NSCMD_SELECTPAGEUP "cmd_selectPageUp"
73 #define NSCMD_SELECTTOP "cmd_selectTop"
74 #define NSCMD_SELECTWORDNEXT "cmd_selectWordNext"
75 #define NSCMD_SELECTWORDPREVIOUS "cmd_selectWordPrevious"
76 #define NSCMD_UL "cmd_ul"
77 #define NSCMD_UNDERLINE "cmd_underline"
78 #define NSCMD_WORDNEXT "cmd_wordNext"
79 #define NSCMD_WORDPREVIOUS "cmd_wordPrevious"
81 #define NSSTATE_ATTRIBUTE "state_attribute"
82 #define NSSTATE_ALL "state_all"
84 #define NSALIGN_CENTER "center"
85 #define NSALIGN_LEFT "left"
86 #define NSALIGN_RIGHT "right"
88 #define DOM_VK_LEFT VK_LEFT
89 #define DOM_VK_UP VK_UP
90 #define DOM_VK_RIGHT VK_RIGHT
91 #define DOM_VK_DOWN VK_DOWN
92 #define DOM_VK_DELETE VK_DELETE
93 #define DOM_VK_HOME VK_HOME
94 #define DOM_VK_END VK_END
96 static const WCHAR fontW[] = {'f','o','n','t',0};
97 static const WCHAR sizeW[] = {'s','i','z','e',0};
99 void set_dirty(HTMLDocument *This, VARIANT_BOOL dirty)
101 nsresult nsres;
103 if(This->doc_obj->usermode != EDITMODE || !This->doc_obj->nscontainer || !This->doc_obj->nscontainer->editor)
104 return;
106 if(dirty) {
107 nsres = nsIEditor_IncrementModificationCount(This->doc_obj->nscontainer->editor, 1);
108 if(NS_FAILED(nsres))
109 ERR("IncrementModificationCount failed: %08x\n", nsres);
110 }else {
111 nsres = nsIEditor_ResetModificationCount(This->doc_obj->nscontainer->editor);
112 if(NS_FAILED(nsres))
113 ERR("ResetModificationCount failed: %08x\n", nsres);
117 static void do_ns_editor_command(NSContainer *This, const char *cmd)
119 nsresult nsres;
121 if(!This->editor_controller)
122 return;
124 nsres = nsIController_DoCommand(This->editor_controller, cmd);
125 if(NS_FAILED(nsres))
126 ERR("DoCommand(%s) failed: %08x\n", debugstr_a(cmd), nsres);
129 static nsresult get_ns_command_state(NSContainer *This, const char *cmd, nsICommandParams *nsparam)
131 nsICommandManager *cmdmgr;
132 nsresult nsres;
134 nsres = get_nsinterface((nsISupports*)This->webbrowser, &IID_nsICommandManager, (void**)&cmdmgr);
135 if(NS_FAILED(nsres)) {
136 ERR("Could not get nsICommandManager: %08x\n", nsres);
137 return nsres;
140 nsres = nsICommandManager_GetCommandState(cmdmgr, cmd, This->doc->basedoc.window->nswindow, nsparam);
141 if(NS_FAILED(nsres))
142 ERR("GetCommandState(%s) failed: %08x\n", debugstr_a(cmd), nsres);
144 nsICommandManager_Release(cmdmgr);
145 return nsres;
148 static DWORD query_ns_edit_status(HTMLDocument *This, const char *nscmd)
150 nsICommandParams *nsparam;
151 cpp_bool b = FALSE;
153 if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
154 return OLECMDF_SUPPORTED;
156 if(This->doc_obj->nscontainer && nscmd) {
157 nsparam = create_nscommand_params();
158 get_ns_command_state(This->doc_obj->nscontainer, nscmd, nsparam);
160 nsICommandParams_GetBooleanValue(nsparam, NSSTATE_ALL, &b);
162 nsICommandParams_Release(nsparam);
165 return OLECMDF_SUPPORTED | OLECMDF_ENABLED | (b ? OLECMDF_LATCHED : 0);
168 static void set_ns_align(HTMLDocument *This, const char *align_str)
170 nsICommandParams *nsparam;
172 if(!This->doc_obj->nscontainer)
173 return;
175 nsparam = create_nscommand_params();
176 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, align_str);
178 do_ns_command(This, NSCMD_ALIGN, nsparam);
180 nsICommandParams_Release(nsparam);
183 static DWORD query_align_status(HTMLDocument *This, const WCHAR *align)
185 DWORD ret = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
186 nsAString justify_str;
187 cpp_bool b;
188 nsresult nsres;
190 if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
191 return OLECMDF_SUPPORTED;
193 nsAString_Init(&justify_str, align);
194 nsres = nsIDOMHTMLDocument_QueryCommandState(This->doc_node->nsdoc, &justify_str, &b);
195 nsAString_Finish(&justify_str);
196 if(NS_SUCCEEDED(nsres) && b)
197 ret |= OLECMDF_LATCHED;
199 return ret;
203 static nsISelection *get_ns_selection(HTMLDocument *This)
205 nsISelection *nsselection = NULL;
206 nsresult nsres;
208 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
209 if(NS_FAILED(nsres))
210 ERR("GetSelection failed %08x\n", nsres);
212 return nsselection;
216 static void remove_child_attr(nsIDOMElement *elem, LPCWSTR tag, nsAString *attr_str)
218 cpp_bool has_children;
219 UINT32 child_cnt, i;
220 nsIDOMNode *child_node;
221 nsIDOMNodeList *node_list;
222 UINT16 node_type;
224 nsIDOMElement_HasChildNodes(elem, &has_children);
225 if(!has_children)
226 return;
228 nsIDOMElement_GetChildNodes(elem, &node_list);
229 nsIDOMNodeList_GetLength(node_list, &child_cnt);
231 for(i=0; i<child_cnt; i++) {
232 nsIDOMNodeList_Item(node_list, i, &child_node);
234 nsIDOMNode_GetNodeType(child_node, &node_type);
235 if(node_type == ELEMENT_NODE) {
236 nsIDOMElement *child_elem;
237 nsAString tag_str;
238 const PRUnichar *ctag;
240 nsIDOMNode_QueryInterface(child_node, &IID_nsIDOMElement, (void**)&child_elem);
242 nsAString_Init(&tag_str, NULL);
243 nsIDOMElement_GetTagName(child_elem, &tag_str);
244 nsAString_GetData(&tag_str, &ctag);
246 if(!strcmpiW(ctag, tag))
247 /* FIXME: remove node if there are no more attributes */
248 nsIDOMElement_RemoveAttribute(child_elem, attr_str);
250 nsAString_Finish(&tag_str);
252 remove_child_attr(child_elem, tag, attr_str);
254 nsIDOMElement_Release(child_elem);
257 nsIDOMNode_Release(child_node);
260 nsIDOMNodeList_Release(node_list);
263 static void get_font_size(HTMLDocument *This, WCHAR *ret)
265 nsISelection *nsselection = get_ns_selection(This);
266 nsIDOMElement *elem = NULL;
267 nsIDOMNode *node = NULL, *tmp_node;
268 nsAString tag_str;
269 LPCWSTR tag;
270 UINT16 node_type;
271 nsresult nsres;
273 *ret = 0;
275 if(!nsselection)
276 return;
278 nsISelection_GetFocusNode(nsselection, &node);
279 nsISelection_Release(nsselection);
281 while(node) {
282 nsres = nsIDOMNode_GetNodeType(node, &node_type);
283 if(NS_FAILED(nsres) || node_type == DOCUMENT_NODE)
284 break;
286 if(node_type == ELEMENT_NODE) {
287 nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
289 nsAString_Init(&tag_str, NULL);
290 nsIDOMElement_GetTagName(elem, &tag_str);
291 nsAString_GetData(&tag_str, &tag);
293 if(!strcmpiW(tag, fontW)) {
294 nsAString size_str, val_str;
295 LPCWSTR val;
297 TRACE("found font tag %p\n", elem);
299 nsAString_InitDepend(&size_str, sizeW);
300 nsAString_Init(&val_str, NULL);
302 nsIDOMElement_GetAttribute(elem, &size_str, &val_str);
303 nsAString_GetData(&val_str, &val);
305 if(*val) {
306 TRACE("found size %s\n", debugstr_w(val));
307 strcpyW(ret, val);
310 nsAString_Finish(&size_str);
311 nsAString_Finish(&val_str);
314 nsAString_Finish(&tag_str);
316 nsIDOMElement_Release(elem);
319 if(*ret)
320 break;
322 tmp_node = node;
323 nsIDOMNode_GetParentNode(node, &node);
324 nsIDOMNode_Release(tmp_node);
327 if(node)
328 nsIDOMNode_Release(node);
331 static void set_font_size(HTMLDocument *This, LPCWSTR size)
333 nsISelection *nsselection;
334 cpp_bool collapsed;
335 nsIDOMHTMLElement *elem;
336 nsIDOMRange *range;
337 LONG range_cnt = 0;
338 nsAString size_str;
339 nsAString val_str;
341 if(!This->doc_node->nsdoc) {
342 WARN("NULL nsdoc\n");
343 return;
346 nsselection = get_ns_selection(This);
347 if(!nsselection)
348 return;
350 nsISelection_GetRangeCount(nsselection, &range_cnt);
351 if(range_cnt != 1) {
352 FIXME("range_cnt %d not supprted\n", range_cnt);
353 if(!range_cnt) {
354 nsISelection_Release(nsselection);
355 return;
359 create_nselem(This->doc_node, fontW, &elem);
361 nsAString_InitDepend(&size_str, sizeW);
362 nsAString_InitDepend(&val_str, size);
364 nsIDOMHTMLElement_SetAttribute(elem, &size_str, &val_str);
365 nsAString_Finish(&val_str);
367 nsISelection_GetRangeAt(nsselection, 0, &range);
368 nsISelection_GetIsCollapsed(nsselection, &collapsed);
369 nsISelection_RemoveAllRanges(nsselection);
371 nsIDOMRange_SurroundContents(range, (nsIDOMNode*)elem);
373 if(collapsed) {
374 nsISelection_Collapse(nsselection, (nsIDOMNode*)elem, 0);
375 }else {
376 /* Remove all size attributes from the range */
377 remove_child_attr((nsIDOMElement*)elem, fontW, &size_str);
378 nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)elem);
381 nsISelection_Release(nsselection);
382 nsIDOMRange_Release(range);
383 nsIDOMHTMLElement_Release(elem);
385 nsAString_Finish(&size_str);
387 set_dirty(This, VARIANT_TRUE);
390 static void handle_arrow_key(HTMLDocument *This, nsIDOMKeyEvent *event, const char * const cmds[4])
392 int i=0;
393 cpp_bool b;
395 nsIDOMKeyEvent_GetCtrlKey(event, &b);
396 if(b)
397 i |= 1;
399 nsIDOMKeyEvent_GetShiftKey(event, &b);
400 if(b)
401 i |= 2;
403 if(cmds[i])
404 do_ns_editor_command(This->doc_obj->nscontainer, cmds[i]);
406 nsIDOMKeyEvent_PreventDefault(event);
409 void handle_edit_event(HTMLDocument *This, nsIDOMEvent *event)
411 nsIDOMKeyEvent *key_event;
412 UINT32 code;
414 nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
416 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
418 switch(code) {
419 case DOM_VK_LEFT: {
420 static const char * const cmds[] = {
421 NSCMD_CHARPREVIOUS,
422 NSCMD_WORDPREVIOUS,
423 NSCMD_SELECTCHARPREVIOUS,
424 NSCMD_SELECTWORDPREVIOUS
427 TRACE("left\n");
428 handle_arrow_key(This, key_event, cmds);
429 break;
431 case DOM_VK_RIGHT: {
432 static const char * const cmds[] = {
433 NSCMD_CHARNEXT,
434 NSCMD_WORDNEXT,
435 NSCMD_SELECTCHARNEXT,
436 NSCMD_SELECTWORDNEXT
439 TRACE("right\n");
440 handle_arrow_key(This, key_event, cmds);
441 break;
443 case DOM_VK_UP: {
444 static const char * const cmds[] = {
445 NSCMD_LINEPREVIOUS,
446 NSCMD_MOVEPAGEUP,
447 NSCMD_SELECTLINEPREVIOUS,
448 NSCMD_SELECTPAGEUP
451 TRACE("up\n");
452 handle_arrow_key(This, key_event, cmds);
453 break;
455 case DOM_VK_DOWN: {
456 static const char * const cmds[] = {
457 NSCMD_LINENEXT,
458 NSCMD_MOVEPAGEDOWN,
459 NSCMD_SELECTLINENEXT,
460 NSCMD_SELECTPAGEDOWN
463 TRACE("down\n");
464 handle_arrow_key(This, key_event, cmds);
465 break;
467 case DOM_VK_DELETE: {
468 static const char * const cmds[] = {
469 NSCMD_DELETECHARFORWARD,
470 NSCMD_DELETEWORDFORWARD,
471 NULL, NULL
474 TRACE("delete\n");
475 handle_arrow_key(This, key_event, cmds);
476 break;
478 case DOM_VK_HOME: {
479 static const char * const cmds[] = {
480 NSCMD_BEGINLINE,
481 NSCMD_MOVETOP,
482 NSCMD_SELECTBEGINLINE,
483 NSCMD_SELECTTOP
486 TRACE("home\n");
487 handle_arrow_key(This, key_event, cmds);
488 break;
490 case DOM_VK_END: {
491 static const char * const cmds[] = {
492 NSCMD_ENDLINE,
493 NSCMD_MOVEBOTTOM,
494 NSCMD_SELECTENDLINE,
495 NSCMD_SELECTBOTTOM
498 TRACE("end\n");
499 handle_arrow_key(This, key_event, cmds);
500 break;
504 nsIDOMKeyEvent_Release(key_event);
507 void handle_edit_load(HTMLDocument *This)
509 get_editor_controller(This->doc_obj->nscontainer);
512 static void set_ns_fontname(HTMLDocument *This, const char *fontname)
514 nsICommandParams *nsparam = create_nscommand_params();
516 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, fontname);
517 do_ns_command(This, NSCMD_FONTFACE, nsparam);
518 nsICommandParams_Release(nsparam);
521 static HRESULT exec_delete(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
523 TRACE("(%p)->(%p %p)\n", This, in, out);
525 if(This->doc_obj->nscontainer)
526 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_DELETECHARFORWARD);
528 update_doc(This, UPDATE_UI);
529 return S_OK;
532 static HRESULT exec_fontname(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
534 TRACE("(%p)->(%p %p)\n", This, in, out);
536 if(!This->doc_obj->nscontainer) {
537 update_doc(This, UPDATE_UI);
538 return E_FAIL;
541 if(in) {
542 char *stra;
544 if(V_VT(in) != VT_BSTR) {
545 FIXME("Unsupported fontname %s\n", debugstr_variant(out));
546 return E_INVALIDARG;
549 TRACE("%s\n", debugstr_w(V_BSTR(in)));
551 stra = heap_strdupWtoA(V_BSTR(in));
552 set_ns_fontname(This, stra);
553 heap_free(stra);
555 update_doc(This, UPDATE_UI);
558 if(out) {
559 nsICommandParams *nsparam;
560 LPWSTR strw;
561 char *stra;
562 DWORD len;
563 nsresult nsres;
565 V_VT(out) = VT_BSTR;
566 V_BSTR(out) = NULL;
568 nsparam = create_nscommand_params();
570 nsres = get_ns_command_state(This->doc_obj->nscontainer, NSCMD_FONTFACE, nsparam);
571 if(NS_FAILED(nsres))
572 return S_OK;
574 nsICommandParams_GetCStringValue(nsparam, NSSTATE_ATTRIBUTE, &stra);
575 nsICommandParams_Release(nsparam);
577 len = MultiByteToWideChar(CP_ACP, 0, stra, -1, NULL, 0);
578 strw = heap_alloc(len*sizeof(WCHAR));
579 MultiByteToWideChar(CP_ACP, 0, stra, -1, strw, len);
580 nsfree(stra);
582 V_BSTR(out) = SysAllocString(strw);
583 heap_free(strw);
586 return S_OK;
589 static HRESULT exec_forecolor(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
591 TRACE("(%p)->(%p %p)\n", This, in, out);
593 if(in) {
594 if(V_VT(in) == VT_I4) {
595 nsICommandParams *nsparam = create_nscommand_params();
596 char color_str[10];
598 sprintf(color_str, "#%02x%02x%02x",
599 V_I4(in)&0xff, (V_I4(in)>>8)&0xff, (V_I4(in)>>16)&0xff);
601 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, color_str);
602 do_ns_command(This, NSCMD_FONTCOLOR, nsparam);
604 nsICommandParams_Release(nsparam);
605 }else {
606 FIXME("unsupported forecolor %s\n", debugstr_variant(in));
609 update_doc(This, UPDATE_UI);
612 if(out) {
613 FIXME("unsupported out\n");
614 return E_NOTIMPL;
617 return S_OK;
620 static HRESULT exec_fontsize(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
622 TRACE("(%p)->(%p %p)\n", This, in, out);
624 if(out) {
625 WCHAR val[10] = {0};
627 get_font_size(This, val);
628 V_VT(out) = VT_I4;
629 V_I4(out) = strtolW(val, NULL, 10);
632 if(in) {
633 switch(V_VT(in)) {
634 case VT_I4: {
635 WCHAR size[10];
636 static const WCHAR format[] = {'%','d',0};
637 wsprintfW(size, format, V_I4(in));
638 set_font_size(This, size);
639 break;
641 case VT_BSTR:
642 set_font_size(This, V_BSTR(in));
643 break;
644 default:
645 FIXME("unsupported fontsize %s\n", debugstr_variant(in));
648 update_doc(This, UPDATE_UI);
651 return S_OK;
654 static HRESULT exec_font(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
657 FIXME("(%p)->(%p %p)\n", This, in, out);
658 return E_NOTIMPL;
661 static HRESULT exec_selectall(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
663 TRACE("(%p)\n", This);
665 if(in || out)
666 FIXME("unsupported args\n");
668 if(This->doc_obj->nscontainer)
669 do_ns_command(This, NSCMD_SELECTALL, NULL);
671 update_doc(This, UPDATE_UI);
672 return S_OK;
675 static HRESULT exec_bold(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
677 TRACE("(%p)\n", This);
679 if(in || out)
680 FIXME("unsupported args\n");
682 if(This->doc_obj->nscontainer)
683 do_ns_command(This, NSCMD_BOLD, NULL);
685 update_doc(This, UPDATE_UI);
686 return S_OK;
689 static HRESULT exec_italic(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
691 TRACE("(%p)\n", This);
693 if(in || out)
694 FIXME("unsupported args\n");
696 if(This->doc_obj->nscontainer)
697 do_ns_command(This, NSCMD_ITALIC, NULL);
699 update_doc(This, UPDATE_UI);
700 return S_OK;
703 static HRESULT query_justify(HTMLDocument *This, OLECMD *cmd)
705 static const PRUnichar justifycenterW[] = {'j','u','s','t','i','f','y','c','e','n','t','e','r',0};
706 static const PRUnichar justifyrightW[] = {'j','u','s','t','i','f','y','r','i','g','h','t',0};
708 switch(cmd->cmdID) {
709 case IDM_JUSTIFYCENTER:
710 TRACE("(%p) IDM_JUSTIFYCENTER\n", This);
711 cmd->cmdf = query_align_status(This, justifycenterW);
712 break;
713 case IDM_JUSTIFYLEFT:
714 TRACE("(%p) IDM_JUSTIFYLEFT\n", This);
715 /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
716 if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
717 cmd->cmdf = OLECMDF_SUPPORTED;
718 else
719 cmd->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
720 break;
721 case IDM_JUSTIFYRIGHT:
722 TRACE("(%p) IDM_JUSTIFYRIGHT\n", This);
723 cmd->cmdf = query_align_status(This, justifyrightW);
724 break;
727 return S_OK;
730 static HRESULT exec_justifycenter(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
732 TRACE("(%p)\n", This);
734 if(in || out)
735 FIXME("unsupported args\n");
737 set_ns_align(This, NSALIGN_CENTER);
738 update_doc(This, UPDATE_UI);
739 return S_OK;
742 static HRESULT exec_justifyleft(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
744 TRACE("(%p)\n", This);
746 if(in || out)
747 FIXME("unsupported args\n");
749 set_ns_align(This, NSALIGN_LEFT);
750 update_doc(This, UPDATE_UI);
751 return S_OK;
754 static HRESULT exec_justifyright(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
756 TRACE("(%p)\n", This);
758 if(in || out)
759 FIXME("unsupported args\n");
761 set_ns_align(This, NSALIGN_RIGHT);
762 update_doc(This, UPDATE_UI);
763 return S_OK;
766 static HRESULT exec_underline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
768 TRACE("(%p)\n", This);
770 if(in || out)
771 FIXME("unsupported args\n");
773 do_ns_command(This, NSCMD_UNDERLINE, NULL);
774 update_doc(This, UPDATE_UI);
775 return S_OK;
778 static HRESULT exec_horizontalline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
780 TRACE("(%p)\n", This);
782 if(in || out)
783 FIXME("unsupported args\n");
785 do_ns_command(This, NSCMD_INSERTHR, NULL);
786 update_doc(This, UPDATE_UI);
787 return S_OK;
790 static HRESULT exec_orderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
792 TRACE("(%p)\n", This);
794 if(in || out)
795 FIXME("unsupported args\n");
797 do_ns_command(This, NSCMD_OL, NULL);
798 update_doc(This, UPDATE_UI);
799 return S_OK;
802 static HRESULT exec_unorderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
804 TRACE("(%p)\n", This);
806 if(in || out)
807 FIXME("unsupported args\n");
809 do_ns_command(This, NSCMD_UL, NULL);
810 update_doc(This, UPDATE_UI);
811 return S_OK;
814 static HRESULT exec_indent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
816 TRACE("(%p)\n", This);
818 if(in || out)
819 FIXME("unsupported args\n");
821 do_ns_command(This, NSCMD_INDENT, NULL);
822 update_doc(This, UPDATE_UI);
823 return S_OK;
826 static HRESULT exec_outdent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
828 TRACE("(%p)\n", This);
830 if(in || out)
831 FIXME("unsupported args\n");
833 do_ns_command(This, NSCMD_OUTDENT, NULL);
834 update_doc(This, UPDATE_UI);
835 return S_OK;
838 static HRESULT exec_composesettings(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
840 WCHAR *ptr;
842 if(out || !in || V_VT(in) != VT_BSTR) {
843 WARN("invalid arg %s\n", debugstr_variant(in));
844 return E_INVALIDARG;
847 TRACE("(%p)->(%x %s)\n", This, cmdexecopt, debugstr_w(V_BSTR(in)));
849 update_doc(This, UPDATE_UI);
851 ptr = V_BSTR(in);
852 if(*ptr == '1')
853 exec_bold(This, cmdexecopt, NULL, NULL);
854 ptr = strchrW(ptr, ',');
855 if(!ptr)
856 return S_OK;
858 if(*++ptr == '1')
859 exec_italic(This, cmdexecopt, NULL, NULL);
860 ptr = strchrW(ptr, ',');
861 if(!ptr)
862 return S_OK;
864 if(*++ptr == '1')
865 exec_underline(This, cmdexecopt, NULL, NULL);
866 ptr = strchrW(ptr, ',');
867 if(!ptr)
868 return S_OK;
870 if(isdigitW(*++ptr)) {
871 VARIANT v;
873 V_VT(&v) = VT_I4;
874 V_I4(&v) = *ptr-'0';
876 exec_fontsize(This, cmdexecopt, &v, NULL);
878 ptr = strchrW(ptr, ',');
879 if(!ptr)
880 return S_OK;
882 if(*++ptr != ',')
883 FIXME("set font color\n");
884 ptr = strchrW(ptr, ',');
885 if(!ptr)
886 return S_OK;
888 if(*++ptr != ',')
889 FIXME("set background color\n");
890 ptr = strchrW(ptr, ',');
891 if(!ptr)
892 return S_OK;
894 ptr++;
895 if(*ptr) {
896 VARIANT v;
898 V_VT(&v) = VT_BSTR;
899 V_BSTR(&v) = SysAllocString(ptr);
901 exec_fontname(This, cmdexecopt, &v, NULL);
903 SysFreeString(V_BSTR(&v));
906 return S_OK;
909 HRESULT editor_exec_copy(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
911 update_doc(This, UPDATE_UI);
913 if(!This->doc_obj->nscontainer)
914 return E_FAIL;
916 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_COPY);
917 return S_OK;
920 HRESULT editor_exec_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
922 update_doc(This, UPDATE_UI);
924 if(!This->doc_obj->nscontainer)
925 return E_FAIL;
927 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_CUT);
928 return S_OK;
931 HRESULT editor_exec_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
933 update_doc(This, UPDATE_UI);
935 if(!This->doc_obj->nscontainer)
936 return E_FAIL;
938 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_PASTE);
939 return S_OK;
942 static HRESULT exec_setdirty(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
944 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
946 if(!in)
947 return S_OK;
949 if(V_VT(in) == VT_BOOL)
950 set_dirty(This, V_BOOL(in));
951 else
952 FIXME("unsupported arg %s\n", debugstr_variant(in));
954 return S_OK;
957 static HRESULT query_edit_status(HTMLDocument *This, OLECMD *cmd)
959 switch(cmd->cmdID) {
960 case IDM_DELETE:
961 TRACE("CGID_MSHTML: IDM_DELETE\n");
962 cmd->cmdf = query_ns_edit_status(This, NULL);
963 break;
964 case IDM_FONTNAME:
965 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
966 cmd->cmdf = query_ns_edit_status(This, NULL);
967 break;
968 case IDM_FONTSIZE:
969 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
970 cmd->cmdf = query_ns_edit_status(This, NULL);
971 break;
972 case IDM_BOLD:
973 TRACE("CGID_MSHTML: IDM_BOLD\n");
974 cmd->cmdf = query_ns_edit_status(This, NSCMD_BOLD);
975 break;
976 case IDM_FORECOLOR:
977 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
978 cmd->cmdf = query_ns_edit_status(This, NULL);
979 break;
980 case IDM_ITALIC:
981 TRACE("CGID_MSHTML: IDM_ITALIC\n");
982 cmd->cmdf = query_ns_edit_status(This, NSCMD_ITALIC);
983 break;
984 case IDM_UNDERLINE:
985 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
986 cmd->cmdf = query_ns_edit_status(This, NSCMD_UNDERLINE);
987 break;
988 case IDM_HORIZONTALLINE:
989 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
990 cmd->cmdf = query_ns_edit_status(This, NULL);
991 break;
992 case IDM_ORDERLIST:
993 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
994 cmd->cmdf = query_ns_edit_status(This, NSCMD_OL);
995 break;
996 case IDM_UNORDERLIST:
997 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
998 cmd->cmdf = query_ns_edit_status(This, NSCMD_UL);
999 break;
1000 case IDM_INDENT:
1001 TRACE("CGID_MSHTML: IDM_INDENT\n");
1002 cmd->cmdf = query_ns_edit_status(This, NULL);
1003 break;
1004 case IDM_OUTDENT:
1005 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
1006 cmd->cmdf = query_ns_edit_status(This, NULL);
1007 break;
1008 case IDM_HYPERLINK:
1009 TRACE("CGID_MSHTML: IDM_HYPERLINK\n");
1010 cmd->cmdf = query_ns_edit_status(This, NULL);
1011 break;
1014 return S_OK;
1017 static INT_PTR CALLBACK hyperlink_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1019 static const WCHAR wszOther[] = {'(','o','t','h','e','r',')',0};
1020 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1021 static const WCHAR wszFtp[] = {'f','t','p',':',0};
1022 static const WCHAR wszHttp[] = {'h','t','t','p',':',0};
1023 static const WCHAR wszHttps[] = {'h','t','t','p','s',':',0};
1024 static const WCHAR wszMailto[] = {'m','a','i','l','t','o',':',0};
1025 static const WCHAR wszNews[] = {'n','e','w','s',':',0};
1027 switch (msg)
1029 case WM_INITDIALOG:
1031 INT def_idx;
1032 HWND hwndCB = GetDlgItem(hwnd, IDC_TYPE);
1033 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1034 INT len;
1036 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
1038 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszOther);
1039 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFile);
1040 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFtp);
1041 def_idx = SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttp);
1042 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttps);
1043 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszMailto);
1044 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszNews);
1045 SendMessageW(hwndCB, CB_SETCURSEL, def_idx, 0);
1047 /* force the updating of the URL edit box */
1048 SendMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE), (LPARAM)hwndCB);
1050 SetFocus(hwndURL);
1051 len = SendMessageW(hwndURL, WM_GETTEXTLENGTH, 0, 0);
1052 SendMessageW(hwndURL, EM_SETSEL, 0, len);
1054 return FALSE;
1056 case WM_COMMAND:
1057 switch (wparam)
1059 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
1060 EndDialog(hwnd, wparam);
1061 return TRUE;
1062 case MAKEWPARAM(IDOK, BN_CLICKED):
1064 BSTR *url = (BSTR *)GetWindowLongPtrW(hwnd, DWLP_USER);
1065 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1066 INT len = GetWindowTextLengthW(hwndURL);
1067 *url = SysAllocStringLen(NULL, len + 1);
1068 GetWindowTextW(hwndURL, *url, len + 1);
1069 EndDialog(hwnd, wparam);
1070 return TRUE;
1072 case MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE):
1074 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1075 INT item;
1076 INT len;
1077 LPWSTR type;
1078 LPWSTR url;
1079 LPWSTR p;
1080 static const WCHAR wszSlashSlash[] = {'/','/'};
1082 /* get string of currently selected hyperlink type */
1083 item = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
1084 len = SendMessageW((HWND)lparam, CB_GETLBTEXTLEN, item, 0);
1085 type = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1086 SendMessageW((HWND)lparam, CB_GETLBTEXT, item, (LPARAM)type);
1088 if (!strcmpW(type, wszOther))
1089 *type = '\0';
1091 /* get current URL */
1092 len = GetWindowTextLengthW(hwndURL);
1093 url = HeapAlloc(GetProcessHeap(), 0, (len + strlenW(type) + 3) * sizeof(WCHAR));
1094 GetWindowTextW(hwndURL, url, len + 1);
1096 /* strip off old protocol */
1097 p = strchrW(url, ':');
1098 if (p && p[1] == '/' && p[2] == '/')
1099 p += 3;
1100 if (!p) p = url;
1101 memmove(url + (*type != '\0' ? strlenW(type) + 2 : 0), p, (len + 1 - (p - url)) * sizeof(WCHAR));
1103 /* add new protocol */
1104 if (*type != '\0')
1106 memcpy(url, type, (strlenW(type) + 1) * sizeof(WCHAR));
1107 if (strcmpW(type, wszMailto) && strcmpW(type, wszNews))
1108 memcpy(url + strlenW(type), wszSlashSlash, sizeof(wszSlashSlash));
1111 SetWindowTextW(hwndURL, url);
1113 HeapFree(GetProcessHeap(), 0, url);
1114 HeapFree(GetProcessHeap(), 0, type);
1115 return TRUE;
1118 return FALSE;
1119 case WM_CLOSE:
1120 EndDialog(hwnd, IDCANCEL);
1121 return TRUE;
1122 default:
1123 return FALSE;
1127 static HRESULT exec_hyperlink(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
1129 nsAString href_str, ns_url;
1130 nsIHTMLEditor *html_editor;
1131 nsIDOMHTMLElement *anchor_elem;
1132 cpp_bool insert_link_at_caret;
1133 nsISelection *nsselection;
1134 BSTR url = NULL;
1135 INT ret;
1136 HRESULT hres = E_FAIL;
1138 static const WCHAR aW[] = {'a',0};
1139 static const WCHAR hrefW[] = {'h','r','e','f',0};
1141 TRACE("%p, 0x%x, %p, %p\n", This, cmdexecopt, in, out);
1143 if (cmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER)
1145 if (!in || V_VT(in) != VT_BSTR)
1147 WARN("invalid arg\n");
1148 return E_INVALIDARG;
1150 url = V_BSTR(in);
1152 else
1154 ret = DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_HYPERLINK), NULL /* FIXME */, hyperlink_dlgproc, (LPARAM)&url);
1155 if (ret != IDOK)
1156 return OLECMDERR_E_CANCELED;
1159 if(!This->doc_node->nsdoc) {
1160 WARN("NULL nsdoc\n");
1161 return E_UNEXPECTED;
1164 nsselection = get_ns_selection(This);
1165 if (!nsselection)
1166 return E_FAIL;
1168 /* create an element for the link */
1169 create_nselem(This->doc_node, aW, &anchor_elem);
1171 nsAString_InitDepend(&href_str, hrefW);
1172 nsAString_InitDepend(&ns_url, url);
1173 nsIDOMHTMLElement_SetAttribute(anchor_elem, &href_str, &ns_url);
1174 nsAString_Finish(&href_str);
1176 nsISelection_GetIsCollapsed(nsselection, &insert_link_at_caret);
1178 /* create an element with text of URL */
1179 if (insert_link_at_caret) {
1180 nsIDOMNode *text_node, *unused_node;
1182 nsIDOMHTMLDocument_CreateTextNode(This->doc_node->nsdoc, &ns_url, (nsIDOMText **)&text_node);
1184 /* wrap the <a> tags around the text element */
1185 nsIDOMHTMLElement_AppendChild(anchor_elem, text_node, &unused_node);
1186 nsIDOMNode_Release(text_node);
1187 nsIDOMNode_Release(unused_node);
1190 nsAString_Finish(&ns_url);
1192 nsIEditor_QueryInterface(This->doc_obj->nscontainer->editor, &IID_nsIHTMLEditor, (void **)&html_editor);
1193 if (html_editor) {
1194 nsresult nsres;
1196 if (insert_link_at_caret) {
1197 /* add them to the document at the caret position */
1198 nsres = nsIHTMLEditor_InsertElementAtSelection(html_editor, (nsIDOMElement*)anchor_elem, FALSE);
1199 nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)anchor_elem);
1200 }else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
1201 nsres = nsIHTMLEditor_InsertLinkAroundSelection(html_editor, (nsIDOMElement*)anchor_elem);
1203 nsIHTMLEditor_Release(html_editor);
1204 hres = NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
1207 nsISelection_Release(nsselection);
1208 nsIDOMHTMLElement_Release(anchor_elem);
1210 if (cmdexecopt != OLECMDEXECOPT_DONTPROMPTUSER)
1211 SysFreeString(url);
1213 TRACE("-- 0x%08x\n", hres);
1214 return hres;
1217 static HRESULT query_selall_status(HTMLDocument *This, OLECMD *cmd)
1219 TRACE("(%p)->(%p)\n", This, cmd);
1221 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1222 return S_OK;
1225 const cmdtable_t editmode_cmds[] = {
1226 {IDM_DELETE, query_edit_status, exec_delete},
1227 {IDM_FONTNAME, query_edit_status, exec_fontname},
1228 {IDM_FONTSIZE, query_edit_status, exec_fontsize},
1229 {IDM_SELECTALL, query_selall_status , exec_selectall},
1230 {IDM_FORECOLOR, query_edit_status, exec_forecolor},
1231 {IDM_BOLD, query_edit_status, exec_bold},
1232 {IDM_ITALIC, query_edit_status, exec_italic},
1233 {IDM_JUSTIFYCENTER, query_justify, exec_justifycenter},
1234 {IDM_JUSTIFYRIGHT, query_justify, exec_justifyright},
1235 {IDM_JUSTIFYLEFT, query_justify, exec_justifyleft},
1236 {IDM_FONT, NULL, exec_font},
1237 {IDM_UNDERLINE, query_edit_status, exec_underline},
1238 {IDM_HORIZONTALLINE, query_edit_status, exec_horizontalline},
1239 {IDM_ORDERLIST, query_edit_status, exec_orderlist},
1240 {IDM_UNORDERLIST, query_edit_status, exec_unorderlist},
1241 {IDM_INDENT, query_edit_status, exec_indent},
1242 {IDM_OUTDENT, query_edit_status, exec_outdent},
1243 {IDM_COMPOSESETTINGS, NULL, exec_composesettings},
1244 {IDM_HYPERLINK, query_edit_status, exec_hyperlink},
1245 {IDM_SETDIRTY, NULL, exec_setdirty},
1246 {0,NULL,NULL}
1249 void init_editor(HTMLDocument *This)
1251 update_doc(This, UPDATE_UI);
1253 set_ns_fontname(This, "Times New Roman");
1256 HRESULT editor_is_dirty(HTMLDocument *This)
1258 cpp_bool modified;
1260 if(!This->doc_obj->nscontainer || !This->doc_obj->nscontainer->editor)
1261 return S_FALSE;
1263 nsIEditor_GetDocumentModified(This->doc_obj->nscontainer->editor, &modified);
1265 return modified ? S_OK : S_FALSE;
1268 HRESULT setup_edit_mode(HTMLDocumentObj *doc)
1270 IMoniker *mon;
1271 HRESULT hres;
1273 if(doc->usermode == EDITMODE)
1274 return S_OK;
1276 doc->usermode = EDITMODE;
1278 if(doc->basedoc.window->mon) {
1279 CLSID clsid = IID_NULL;
1280 hres = IMoniker_GetClassID(doc->basedoc.window->mon, &clsid);
1281 if(SUCCEEDED(hres)) {
1282 /* We should use IMoniker::Save here */
1283 FIXME("Use CLSID %s\n", debugstr_guid(&clsid));
1287 if(doc->frame)
1288 IOleInPlaceFrame_SetStatusText(doc->frame, NULL);
1290 doc->basedoc.window->readystate = READYSTATE_UNINITIALIZED;
1292 if(doc->client) {
1293 IOleCommandTarget *cmdtrg;
1295 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1296 if(SUCCEEDED(hres)) {
1297 VARIANT var;
1299 V_VT(&var) = VT_I4;
1300 V_I4(&var) = 0;
1301 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
1303 IOleCommandTarget_Release(cmdtrg);
1307 if(doc->hostui) {
1308 DOCHOSTUIINFO hostinfo;
1310 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
1311 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
1312 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
1313 if(SUCCEEDED(hres))
1314 /* FIXME: use hostinfo */
1315 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
1316 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
1317 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
1320 update_doc(&doc->basedoc, UPDATE_UI);
1322 if(doc->basedoc.window->mon) {
1323 /* FIXME: We should find nicer way to do this */
1324 remove_target_tasks(doc->basedoc.task_magic);
1326 mon = doc->basedoc.window->mon;
1327 IMoniker_AddRef(mon);
1328 }else {
1329 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
1331 hres = CreateURLMoniker(NULL, about_blankW, &mon);
1332 if(FAILED(hres)) {
1333 FIXME("CreateURLMoniker failed: %08x\n", hres);
1334 return hres;
1338 hres = IPersistMoniker_Load(&doc->basedoc.IPersistMoniker_iface, TRUE, mon, NULL, 0);
1339 IMoniker_Release(mon);
1340 if(FAILED(hres))
1341 return hres;
1343 if(doc->ui_active) {
1344 if(doc->ip_window)
1345 call_set_active_object(doc->ip_window, NULL);
1346 if(doc->hostui)
1347 IDocHostUIHandler_HideUI(doc->hostui);
1350 if(doc->ui_active) {
1351 RECT rcBorderWidths;
1353 if(doc->hostui)
1354 IDocHostUIHandler_ShowUI(doc->hostui, DOCHOSTUITYPE_AUTHOR,
1355 &doc->basedoc.IOleInPlaceActiveObject_iface, &doc->basedoc.IOleCommandTarget_iface,
1356 doc->frame, doc->ip_window);
1358 if(doc->ip_window)
1359 call_set_active_object(doc->ip_window, &doc->basedoc.IOleInPlaceActiveObject_iface);
1361 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
1362 if(doc->frame)
1363 IOleInPlaceFrame_SetBorderSpace(doc->frame, &rcBorderWidths);
1366 return S_OK;