wpcap: Implement pcap_major_version and pcap_minor_version.
[wine/multimedia.git] / dlls / mshtml / editor.c
blob14aab53294b8ccea8c338ac9f192033fb11c9188
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 nsIDOMHTMLElement *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_nsIDOMHTMLElement, (void**)&elem);
289 nsAString_Init(&tag_str, NULL);
290 nsIDOMHTMLElement_GetTagName(elem, &tag_str);
291 nsAString_GetData(&tag_str, &tag);
293 if(!strcmpiW(tag, fontW)) {
294 nsAString val_str;
295 const PRUnichar *val;
297 TRACE("found font tag %p\n", elem);
299 get_elem_attr_value(elem, sizeW, &val_str, &val);
300 if(*val) {
301 TRACE("found size %s\n", debugstr_w(val));
302 strcpyW(ret, val);
305 nsAString_Finish(&val_str);
308 nsAString_Finish(&tag_str);
309 nsIDOMHTMLElement_Release(elem);
312 if(*ret)
313 break;
315 tmp_node = node;
316 nsIDOMNode_GetParentNode(node, &node);
317 nsIDOMNode_Release(tmp_node);
320 if(node)
321 nsIDOMNode_Release(node);
324 static void set_font_size(HTMLDocument *This, LPCWSTR size)
326 nsISelection *nsselection;
327 cpp_bool collapsed;
328 nsIDOMHTMLElement *elem;
329 nsIDOMRange *range;
330 LONG range_cnt = 0;
331 nsAString size_str;
332 nsAString val_str;
334 if(!This->doc_node->nsdoc) {
335 WARN("NULL nsdoc\n");
336 return;
339 nsselection = get_ns_selection(This);
340 if(!nsselection)
341 return;
343 nsISelection_GetRangeCount(nsselection, &range_cnt);
344 if(range_cnt != 1) {
345 FIXME("range_cnt %d not supprted\n", range_cnt);
346 if(!range_cnt) {
347 nsISelection_Release(nsselection);
348 return;
352 create_nselem(This->doc_node, fontW, &elem);
354 nsAString_InitDepend(&size_str, sizeW);
355 nsAString_InitDepend(&val_str, size);
357 nsIDOMHTMLElement_SetAttribute(elem, &size_str, &val_str);
358 nsAString_Finish(&val_str);
360 nsISelection_GetRangeAt(nsselection, 0, &range);
361 nsISelection_GetIsCollapsed(nsselection, &collapsed);
362 nsISelection_RemoveAllRanges(nsselection);
364 nsIDOMRange_SurroundContents(range, (nsIDOMNode*)elem);
366 if(collapsed) {
367 nsISelection_Collapse(nsselection, (nsIDOMNode*)elem, 0);
368 }else {
369 /* Remove all size attributes from the range */
370 remove_child_attr((nsIDOMElement*)elem, fontW, &size_str);
371 nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)elem);
374 nsISelection_Release(nsselection);
375 nsIDOMRange_Release(range);
376 nsIDOMHTMLElement_Release(elem);
378 nsAString_Finish(&size_str);
380 set_dirty(This, VARIANT_TRUE);
383 static void handle_arrow_key(HTMLDocument *This, nsIDOMKeyEvent *event, const char * const cmds[4])
385 int i=0;
386 cpp_bool b;
388 nsIDOMKeyEvent_GetCtrlKey(event, &b);
389 if(b)
390 i |= 1;
392 nsIDOMKeyEvent_GetShiftKey(event, &b);
393 if(b)
394 i |= 2;
396 if(cmds[i])
397 do_ns_editor_command(This->doc_obj->nscontainer, cmds[i]);
399 nsIDOMKeyEvent_PreventDefault(event);
402 void handle_edit_event(HTMLDocument *This, nsIDOMEvent *event)
404 nsIDOMKeyEvent *key_event;
405 UINT32 code;
407 nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
409 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
411 switch(code) {
412 case DOM_VK_LEFT: {
413 static const char * const cmds[] = {
414 NSCMD_CHARPREVIOUS,
415 NSCMD_WORDPREVIOUS,
416 NSCMD_SELECTCHARPREVIOUS,
417 NSCMD_SELECTWORDPREVIOUS
420 TRACE("left\n");
421 handle_arrow_key(This, key_event, cmds);
422 break;
424 case DOM_VK_RIGHT: {
425 static const char * const cmds[] = {
426 NSCMD_CHARNEXT,
427 NSCMD_WORDNEXT,
428 NSCMD_SELECTCHARNEXT,
429 NSCMD_SELECTWORDNEXT
432 TRACE("right\n");
433 handle_arrow_key(This, key_event, cmds);
434 break;
436 case DOM_VK_UP: {
437 static const char * const cmds[] = {
438 NSCMD_LINEPREVIOUS,
439 NSCMD_MOVEPAGEUP,
440 NSCMD_SELECTLINEPREVIOUS,
441 NSCMD_SELECTPAGEUP
444 TRACE("up\n");
445 handle_arrow_key(This, key_event, cmds);
446 break;
448 case DOM_VK_DOWN: {
449 static const char * const cmds[] = {
450 NSCMD_LINENEXT,
451 NSCMD_MOVEPAGEDOWN,
452 NSCMD_SELECTLINENEXT,
453 NSCMD_SELECTPAGEDOWN
456 TRACE("down\n");
457 handle_arrow_key(This, key_event, cmds);
458 break;
460 case DOM_VK_DELETE: {
461 static const char * const cmds[] = {
462 NSCMD_DELETECHARFORWARD,
463 NSCMD_DELETEWORDFORWARD,
464 NULL, NULL
467 TRACE("delete\n");
468 handle_arrow_key(This, key_event, cmds);
469 break;
471 case DOM_VK_HOME: {
472 static const char * const cmds[] = {
473 NSCMD_BEGINLINE,
474 NSCMD_MOVETOP,
475 NSCMD_SELECTBEGINLINE,
476 NSCMD_SELECTTOP
479 TRACE("home\n");
480 handle_arrow_key(This, key_event, cmds);
481 break;
483 case DOM_VK_END: {
484 static const char * const cmds[] = {
485 NSCMD_ENDLINE,
486 NSCMD_MOVEBOTTOM,
487 NSCMD_SELECTENDLINE,
488 NSCMD_SELECTBOTTOM
491 TRACE("end\n");
492 handle_arrow_key(This, key_event, cmds);
493 break;
497 nsIDOMKeyEvent_Release(key_event);
500 void handle_edit_load(HTMLDocument *This)
502 get_editor_controller(This->doc_obj->nscontainer);
505 static void set_ns_fontname(HTMLDocument *This, const char *fontname)
507 nsICommandParams *nsparam = create_nscommand_params();
509 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, fontname);
510 do_ns_command(This, NSCMD_FONTFACE, nsparam);
511 nsICommandParams_Release(nsparam);
514 static HRESULT exec_delete(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
516 TRACE("(%p)->(%p %p)\n", This, in, out);
518 if(This->doc_obj->nscontainer)
519 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_DELETECHARFORWARD);
521 update_doc(This, UPDATE_UI);
522 return S_OK;
525 static HRESULT exec_fontname(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
527 TRACE("(%p)->(%p %p)\n", This, in, out);
529 if(!This->doc_obj->nscontainer) {
530 update_doc(This, UPDATE_UI);
531 return E_FAIL;
534 if(in) {
535 char *stra;
537 if(V_VT(in) != VT_BSTR) {
538 FIXME("Unsupported fontname %s\n", debugstr_variant(out));
539 return E_INVALIDARG;
542 TRACE("%s\n", debugstr_w(V_BSTR(in)));
544 stra = heap_strdupWtoA(V_BSTR(in));
545 set_ns_fontname(This, stra);
546 heap_free(stra);
548 update_doc(This, UPDATE_UI);
551 if(out) {
552 nsICommandParams *nsparam;
553 LPWSTR strw;
554 char *stra;
555 DWORD len;
556 nsresult nsres;
558 V_VT(out) = VT_BSTR;
559 V_BSTR(out) = NULL;
561 nsparam = create_nscommand_params();
563 nsres = get_ns_command_state(This->doc_obj->nscontainer, NSCMD_FONTFACE, nsparam);
564 if(NS_FAILED(nsres))
565 return S_OK;
567 nsICommandParams_GetCStringValue(nsparam, NSSTATE_ATTRIBUTE, &stra);
568 nsICommandParams_Release(nsparam);
570 len = MultiByteToWideChar(CP_ACP, 0, stra, -1, NULL, 0);
571 strw = heap_alloc(len*sizeof(WCHAR));
572 MultiByteToWideChar(CP_ACP, 0, stra, -1, strw, len);
573 nsfree(stra);
575 V_BSTR(out) = SysAllocString(strw);
576 heap_free(strw);
579 return S_OK;
582 static HRESULT exec_forecolor(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
584 TRACE("(%p)->(%p %p)\n", This, in, out);
586 if(in) {
587 if(V_VT(in) == VT_I4) {
588 nsICommandParams *nsparam = create_nscommand_params();
589 char color_str[10];
591 sprintf(color_str, "#%02x%02x%02x",
592 V_I4(in)&0xff, (V_I4(in)>>8)&0xff, (V_I4(in)>>16)&0xff);
594 nsICommandParams_SetCStringValue(nsparam, NSSTATE_ATTRIBUTE, color_str);
595 do_ns_command(This, NSCMD_FONTCOLOR, nsparam);
597 nsICommandParams_Release(nsparam);
598 }else {
599 FIXME("unsupported forecolor %s\n", debugstr_variant(in));
602 update_doc(This, UPDATE_UI);
605 if(out) {
606 FIXME("unsupported out\n");
607 return E_NOTIMPL;
610 return S_OK;
613 static HRESULT exec_fontsize(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
615 TRACE("(%p)->(%p %p)\n", This, in, out);
617 if(out) {
618 WCHAR val[10] = {0};
620 get_font_size(This, val);
621 V_VT(out) = VT_I4;
622 V_I4(out) = strtolW(val, NULL, 10);
625 if(in) {
626 switch(V_VT(in)) {
627 case VT_I4: {
628 WCHAR size[10];
629 static const WCHAR format[] = {'%','d',0};
630 wsprintfW(size, format, V_I4(in));
631 set_font_size(This, size);
632 break;
634 case VT_BSTR:
635 set_font_size(This, V_BSTR(in));
636 break;
637 default:
638 FIXME("unsupported fontsize %s\n", debugstr_variant(in));
641 update_doc(This, UPDATE_UI);
644 return S_OK;
647 static HRESULT exec_font(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
650 FIXME("(%p)->(%p %p)\n", This, in, out);
651 return E_NOTIMPL;
654 static HRESULT exec_selectall(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
656 TRACE("(%p)\n", This);
658 if(in || out)
659 FIXME("unsupported args\n");
661 if(This->doc_obj->nscontainer)
662 do_ns_command(This, NSCMD_SELECTALL, NULL);
664 update_doc(This, UPDATE_UI);
665 return S_OK;
668 static HRESULT exec_bold(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
670 TRACE("(%p)\n", This);
672 if(in || out)
673 FIXME("unsupported args\n");
675 if(This->doc_obj->nscontainer)
676 do_ns_command(This, NSCMD_BOLD, NULL);
678 update_doc(This, UPDATE_UI);
679 return S_OK;
682 static HRESULT exec_italic(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
684 TRACE("(%p)\n", This);
686 if(in || out)
687 FIXME("unsupported args\n");
689 if(This->doc_obj->nscontainer)
690 do_ns_command(This, NSCMD_ITALIC, NULL);
692 update_doc(This, UPDATE_UI);
693 return S_OK;
696 static HRESULT query_justify(HTMLDocument *This, OLECMD *cmd)
698 static const PRUnichar justifycenterW[] = {'j','u','s','t','i','f','y','c','e','n','t','e','r',0};
699 static const PRUnichar justifyrightW[] = {'j','u','s','t','i','f','y','r','i','g','h','t',0};
701 switch(cmd->cmdID) {
702 case IDM_JUSTIFYCENTER:
703 TRACE("(%p) IDM_JUSTIFYCENTER\n", This);
704 cmd->cmdf = query_align_status(This, justifycenterW);
705 break;
706 case IDM_JUSTIFYLEFT:
707 TRACE("(%p) IDM_JUSTIFYLEFT\n", This);
708 /* FIXME: We should set OLECMDF_LATCHED only if it's set explicitly. */
709 if(This->doc_obj->usermode != EDITMODE || This->window->readystate < READYSTATE_INTERACTIVE)
710 cmd->cmdf = OLECMDF_SUPPORTED;
711 else
712 cmd->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
713 break;
714 case IDM_JUSTIFYRIGHT:
715 TRACE("(%p) IDM_JUSTIFYRIGHT\n", This);
716 cmd->cmdf = query_align_status(This, justifyrightW);
717 break;
720 return S_OK;
723 static HRESULT exec_justifycenter(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
725 TRACE("(%p)\n", This);
727 if(in || out)
728 FIXME("unsupported args\n");
730 set_ns_align(This, NSALIGN_CENTER);
731 update_doc(This, UPDATE_UI);
732 return S_OK;
735 static HRESULT exec_justifyleft(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
737 TRACE("(%p)\n", This);
739 if(in || out)
740 FIXME("unsupported args\n");
742 set_ns_align(This, NSALIGN_LEFT);
743 update_doc(This, UPDATE_UI);
744 return S_OK;
747 static HRESULT exec_justifyright(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
749 TRACE("(%p)\n", This);
751 if(in || out)
752 FIXME("unsupported args\n");
754 set_ns_align(This, NSALIGN_RIGHT);
755 update_doc(This, UPDATE_UI);
756 return S_OK;
759 static HRESULT exec_underline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
761 TRACE("(%p)\n", This);
763 if(in || out)
764 FIXME("unsupported args\n");
766 do_ns_command(This, NSCMD_UNDERLINE, NULL);
767 update_doc(This, UPDATE_UI);
768 return S_OK;
771 static HRESULT exec_horizontalline(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
773 TRACE("(%p)\n", This);
775 if(in || out)
776 FIXME("unsupported args\n");
778 do_ns_command(This, NSCMD_INSERTHR, NULL);
779 update_doc(This, UPDATE_UI);
780 return S_OK;
783 static HRESULT exec_orderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
785 TRACE("(%p)\n", This);
787 if(in || out)
788 FIXME("unsupported args\n");
790 do_ns_command(This, NSCMD_OL, NULL);
791 update_doc(This, UPDATE_UI);
792 return S_OK;
795 static HRESULT exec_unorderlist(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
797 TRACE("(%p)\n", This);
799 if(in || out)
800 FIXME("unsupported args\n");
802 do_ns_command(This, NSCMD_UL, NULL);
803 update_doc(This, UPDATE_UI);
804 return S_OK;
807 static HRESULT exec_indent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
809 TRACE("(%p)\n", This);
811 if(in || out)
812 FIXME("unsupported args\n");
814 do_ns_command(This, NSCMD_INDENT, NULL);
815 update_doc(This, UPDATE_UI);
816 return S_OK;
819 static HRESULT exec_outdent(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
821 TRACE("(%p)\n", This);
823 if(in || out)
824 FIXME("unsupported args\n");
826 do_ns_command(This, NSCMD_OUTDENT, NULL);
827 update_doc(This, UPDATE_UI);
828 return S_OK;
831 static HRESULT exec_composesettings(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
833 WCHAR *ptr;
835 if(out || !in || V_VT(in) != VT_BSTR) {
836 WARN("invalid arg %s\n", debugstr_variant(in));
837 return E_INVALIDARG;
840 TRACE("(%p)->(%x %s)\n", This, cmdexecopt, debugstr_w(V_BSTR(in)));
842 update_doc(This, UPDATE_UI);
844 ptr = V_BSTR(in);
845 if(*ptr == '1')
846 exec_bold(This, cmdexecopt, NULL, NULL);
847 ptr = strchrW(ptr, ',');
848 if(!ptr)
849 return S_OK;
851 if(*++ptr == '1')
852 exec_italic(This, cmdexecopt, NULL, NULL);
853 ptr = strchrW(ptr, ',');
854 if(!ptr)
855 return S_OK;
857 if(*++ptr == '1')
858 exec_underline(This, cmdexecopt, NULL, NULL);
859 ptr = strchrW(ptr, ',');
860 if(!ptr)
861 return S_OK;
863 if(isdigitW(*++ptr)) {
864 VARIANT v;
866 V_VT(&v) = VT_I4;
867 V_I4(&v) = *ptr-'0';
869 exec_fontsize(This, cmdexecopt, &v, NULL);
871 ptr = strchrW(ptr, ',');
872 if(!ptr)
873 return S_OK;
875 if(*++ptr != ',')
876 FIXME("set font color\n");
877 ptr = strchrW(ptr, ',');
878 if(!ptr)
879 return S_OK;
881 if(*++ptr != ',')
882 FIXME("set background color\n");
883 ptr = strchrW(ptr, ',');
884 if(!ptr)
885 return S_OK;
887 ptr++;
888 if(*ptr) {
889 VARIANT v;
891 V_VT(&v) = VT_BSTR;
892 V_BSTR(&v) = SysAllocString(ptr);
894 exec_fontname(This, cmdexecopt, &v, NULL);
896 SysFreeString(V_BSTR(&v));
899 return S_OK;
902 HRESULT editor_exec_copy(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
904 update_doc(This, UPDATE_UI);
906 if(!This->doc_obj->nscontainer)
907 return E_FAIL;
909 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_COPY);
910 return S_OK;
913 HRESULT editor_exec_cut(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
915 update_doc(This, UPDATE_UI);
917 if(!This->doc_obj->nscontainer)
918 return E_FAIL;
920 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_CUT);
921 return S_OK;
924 HRESULT editor_exec_paste(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
926 update_doc(This, UPDATE_UI);
928 if(!This->doc_obj->nscontainer)
929 return E_FAIL;
931 do_ns_editor_command(This->doc_obj->nscontainer, NSCMD_PASTE);
932 return S_OK;
935 static HRESULT exec_setdirty(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
937 TRACE("(%p)->(%08x %p %p)\n", This, cmdexecopt, in, out);
939 if(!in)
940 return S_OK;
942 if(V_VT(in) == VT_BOOL)
943 set_dirty(This, V_BOOL(in));
944 else
945 FIXME("unsupported arg %s\n", debugstr_variant(in));
947 return S_OK;
950 static HRESULT query_edit_status(HTMLDocument *This, OLECMD *cmd)
952 switch(cmd->cmdID) {
953 case IDM_DELETE:
954 TRACE("CGID_MSHTML: IDM_DELETE\n");
955 cmd->cmdf = query_ns_edit_status(This, NULL);
956 break;
957 case IDM_FONTNAME:
958 TRACE("CGID_MSHTML: IDM_FONTNAME\n");
959 cmd->cmdf = query_ns_edit_status(This, NULL);
960 break;
961 case IDM_FONTSIZE:
962 TRACE("CGID_MSHTML: IDM_FONTSIZE\n");
963 cmd->cmdf = query_ns_edit_status(This, NULL);
964 break;
965 case IDM_BOLD:
966 TRACE("CGID_MSHTML: IDM_BOLD\n");
967 cmd->cmdf = query_ns_edit_status(This, NSCMD_BOLD);
968 break;
969 case IDM_FORECOLOR:
970 TRACE("CGID_MSHTML: IDM_FORECOLOR\n");
971 cmd->cmdf = query_ns_edit_status(This, NULL);
972 break;
973 case IDM_ITALIC:
974 TRACE("CGID_MSHTML: IDM_ITALIC\n");
975 cmd->cmdf = query_ns_edit_status(This, NSCMD_ITALIC);
976 break;
977 case IDM_UNDERLINE:
978 TRACE("CGID_MSHTML: IDM_UNDERLINE\n");
979 cmd->cmdf = query_ns_edit_status(This, NSCMD_UNDERLINE);
980 break;
981 case IDM_HORIZONTALLINE:
982 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
983 cmd->cmdf = query_ns_edit_status(This, NULL);
984 break;
985 case IDM_ORDERLIST:
986 TRACE("CGID_MSHTML: IDM_ORDERLIST\n");
987 cmd->cmdf = query_ns_edit_status(This, NSCMD_OL);
988 break;
989 case IDM_UNORDERLIST:
990 TRACE("CGID_MSHTML: IDM_HORIZONTALLINE\n");
991 cmd->cmdf = query_ns_edit_status(This, NSCMD_UL);
992 break;
993 case IDM_INDENT:
994 TRACE("CGID_MSHTML: IDM_INDENT\n");
995 cmd->cmdf = query_ns_edit_status(This, NULL);
996 break;
997 case IDM_OUTDENT:
998 TRACE("CGID_MSHTML: IDM_OUTDENT\n");
999 cmd->cmdf = query_ns_edit_status(This, NULL);
1000 break;
1001 case IDM_HYPERLINK:
1002 TRACE("CGID_MSHTML: IDM_HYPERLINK\n");
1003 cmd->cmdf = query_ns_edit_status(This, NULL);
1004 break;
1007 return S_OK;
1010 static INT_PTR CALLBACK hyperlink_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1012 static const WCHAR wszOther[] = {'(','o','t','h','e','r',')',0};
1013 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1014 static const WCHAR wszFtp[] = {'f','t','p',':',0};
1015 static const WCHAR wszHttp[] = {'h','t','t','p',':',0};
1016 static const WCHAR wszHttps[] = {'h','t','t','p','s',':',0};
1017 static const WCHAR wszMailto[] = {'m','a','i','l','t','o',':',0};
1018 static const WCHAR wszNews[] = {'n','e','w','s',':',0};
1020 switch (msg)
1022 case WM_INITDIALOG:
1024 INT def_idx;
1025 HWND hwndCB = GetDlgItem(hwnd, IDC_TYPE);
1026 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1027 INT len;
1029 SetWindowLongPtrW(hwnd, DWLP_USER, lparam);
1031 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszOther);
1032 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFile);
1033 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszFtp);
1034 def_idx = SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttp);
1035 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszHttps);
1036 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszMailto);
1037 SendMessageW(hwndCB, CB_INSERTSTRING, -1, (LPARAM)wszNews);
1038 SendMessageW(hwndCB, CB_SETCURSEL, def_idx, 0);
1040 /* force the updating of the URL edit box */
1041 SendMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE), (LPARAM)hwndCB);
1043 SetFocus(hwndURL);
1044 len = SendMessageW(hwndURL, WM_GETTEXTLENGTH, 0, 0);
1045 SendMessageW(hwndURL, EM_SETSEL, 0, len);
1047 return FALSE;
1049 case WM_COMMAND:
1050 switch (wparam)
1052 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
1053 EndDialog(hwnd, wparam);
1054 return TRUE;
1055 case MAKEWPARAM(IDOK, BN_CLICKED):
1057 BSTR *url = (BSTR *)GetWindowLongPtrW(hwnd, DWLP_USER);
1058 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1059 INT len = GetWindowTextLengthW(hwndURL);
1060 *url = SysAllocStringLen(NULL, len + 1);
1061 GetWindowTextW(hwndURL, *url, len + 1);
1062 EndDialog(hwnd, wparam);
1063 return TRUE;
1065 case MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE):
1067 HWND hwndURL = GetDlgItem(hwnd, IDC_URL);
1068 INT item;
1069 INT len;
1070 LPWSTR type;
1071 LPWSTR url;
1072 LPWSTR p;
1073 static const WCHAR wszSlashSlash[] = {'/','/'};
1075 /* get string of currently selected hyperlink type */
1076 item = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
1077 len = SendMessageW((HWND)lparam, CB_GETLBTEXTLEN, item, 0);
1078 type = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1079 SendMessageW((HWND)lparam, CB_GETLBTEXT, item, (LPARAM)type);
1081 if (!strcmpW(type, wszOther))
1082 *type = '\0';
1084 /* get current URL */
1085 len = GetWindowTextLengthW(hwndURL);
1086 url = HeapAlloc(GetProcessHeap(), 0, (len + strlenW(type) + 3) * sizeof(WCHAR));
1087 GetWindowTextW(hwndURL, url, len + 1);
1089 /* strip off old protocol */
1090 p = strchrW(url, ':');
1091 if (p && p[1] == '/' && p[2] == '/')
1092 p += 3;
1093 if (!p) p = url;
1094 memmove(url + (*type != '\0' ? strlenW(type) + 2 : 0), p, (len + 1 - (p - url)) * sizeof(WCHAR));
1096 /* add new protocol */
1097 if (*type != '\0')
1099 memcpy(url, type, (strlenW(type) + 1) * sizeof(WCHAR));
1100 if (strcmpW(type, wszMailto) && strcmpW(type, wszNews))
1101 memcpy(url + strlenW(type), wszSlashSlash, sizeof(wszSlashSlash));
1104 SetWindowTextW(hwndURL, url);
1106 HeapFree(GetProcessHeap(), 0, url);
1107 HeapFree(GetProcessHeap(), 0, type);
1108 return TRUE;
1111 return FALSE;
1112 case WM_CLOSE:
1113 EndDialog(hwnd, IDCANCEL);
1114 return TRUE;
1115 default:
1116 return FALSE;
1120 static HRESULT exec_hyperlink(HTMLDocument *This, DWORD cmdexecopt, VARIANT *in, VARIANT *out)
1122 nsAString href_str, ns_url;
1123 nsIHTMLEditor *html_editor;
1124 nsIDOMHTMLElement *anchor_elem;
1125 cpp_bool insert_link_at_caret;
1126 nsISelection *nsselection;
1127 BSTR url = NULL;
1128 INT ret;
1129 HRESULT hres = E_FAIL;
1131 static const WCHAR aW[] = {'a',0};
1132 static const WCHAR hrefW[] = {'h','r','e','f',0};
1134 TRACE("%p, 0x%x, %p, %p\n", This, cmdexecopt, in, out);
1136 if (cmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER)
1138 if (!in || V_VT(in) != VT_BSTR)
1140 WARN("invalid arg\n");
1141 return E_INVALIDARG;
1143 url = V_BSTR(in);
1145 else
1147 ret = DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_HYPERLINK), NULL /* FIXME */, hyperlink_dlgproc, (LPARAM)&url);
1148 if (ret != IDOK)
1149 return OLECMDERR_E_CANCELED;
1152 if(!This->doc_node->nsdoc) {
1153 WARN("NULL nsdoc\n");
1154 return E_UNEXPECTED;
1157 nsselection = get_ns_selection(This);
1158 if (!nsselection)
1159 return E_FAIL;
1161 /* create an element for the link */
1162 create_nselem(This->doc_node, aW, &anchor_elem);
1164 nsAString_InitDepend(&href_str, hrefW);
1165 nsAString_InitDepend(&ns_url, url);
1166 nsIDOMHTMLElement_SetAttribute(anchor_elem, &href_str, &ns_url);
1167 nsAString_Finish(&href_str);
1169 nsISelection_GetIsCollapsed(nsselection, &insert_link_at_caret);
1171 /* create an element with text of URL */
1172 if (insert_link_at_caret) {
1173 nsIDOMNode *text_node, *unused_node;
1175 nsIDOMHTMLDocument_CreateTextNode(This->doc_node->nsdoc, &ns_url, (nsIDOMText **)&text_node);
1177 /* wrap the <a> tags around the text element */
1178 nsIDOMHTMLElement_AppendChild(anchor_elem, text_node, &unused_node);
1179 nsIDOMNode_Release(text_node);
1180 nsIDOMNode_Release(unused_node);
1183 nsAString_Finish(&ns_url);
1185 nsIEditor_QueryInterface(This->doc_obj->nscontainer->editor, &IID_nsIHTMLEditor, (void **)&html_editor);
1186 if (html_editor) {
1187 nsresult nsres;
1189 if (insert_link_at_caret) {
1190 /* add them to the document at the caret position */
1191 nsres = nsIHTMLEditor_InsertElementAtSelection(html_editor, (nsIDOMElement*)anchor_elem, FALSE);
1192 nsISelection_SelectAllChildren(nsselection, (nsIDOMNode*)anchor_elem);
1193 }else /* add them around the selection using the magic provided to us by nsIHTMLEditor */
1194 nsres = nsIHTMLEditor_InsertLinkAroundSelection(html_editor, (nsIDOMElement*)anchor_elem);
1196 nsIHTMLEditor_Release(html_editor);
1197 hres = NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
1200 nsISelection_Release(nsselection);
1201 nsIDOMHTMLElement_Release(anchor_elem);
1203 if (cmdexecopt != OLECMDEXECOPT_DONTPROMPTUSER)
1204 SysFreeString(url);
1206 TRACE("-- 0x%08x\n", hres);
1207 return hres;
1210 static HRESULT query_selall_status(HTMLDocument *This, OLECMD *cmd)
1212 TRACE("(%p)->(%p)\n", This, cmd);
1214 cmd->cmdf = OLECMDF_SUPPORTED|OLECMDF_ENABLED;
1215 return S_OK;
1218 const cmdtable_t editmode_cmds[] = {
1219 {IDM_DELETE, query_edit_status, exec_delete},
1220 {IDM_FONTNAME, query_edit_status, exec_fontname},
1221 {IDM_FONTSIZE, query_edit_status, exec_fontsize},
1222 {IDM_SELECTALL, query_selall_status , exec_selectall},
1223 {IDM_FORECOLOR, query_edit_status, exec_forecolor},
1224 {IDM_BOLD, query_edit_status, exec_bold},
1225 {IDM_ITALIC, query_edit_status, exec_italic},
1226 {IDM_JUSTIFYCENTER, query_justify, exec_justifycenter},
1227 {IDM_JUSTIFYRIGHT, query_justify, exec_justifyright},
1228 {IDM_JUSTIFYLEFT, query_justify, exec_justifyleft},
1229 {IDM_FONT, NULL, exec_font},
1230 {IDM_UNDERLINE, query_edit_status, exec_underline},
1231 {IDM_HORIZONTALLINE, query_edit_status, exec_horizontalline},
1232 {IDM_ORDERLIST, query_edit_status, exec_orderlist},
1233 {IDM_UNORDERLIST, query_edit_status, exec_unorderlist},
1234 {IDM_INDENT, query_edit_status, exec_indent},
1235 {IDM_OUTDENT, query_edit_status, exec_outdent},
1236 {IDM_COMPOSESETTINGS, NULL, exec_composesettings},
1237 {IDM_HYPERLINK, query_edit_status, exec_hyperlink},
1238 {IDM_SETDIRTY, NULL, exec_setdirty},
1239 {0,NULL,NULL}
1242 void init_editor(HTMLDocument *This)
1244 update_doc(This, UPDATE_UI);
1246 set_ns_fontname(This, "Times New Roman");
1249 HRESULT editor_is_dirty(HTMLDocument *This)
1251 cpp_bool modified;
1253 if(!This->doc_obj->nscontainer || !This->doc_obj->nscontainer->editor)
1254 return S_FALSE;
1256 nsIEditor_GetDocumentModified(This->doc_obj->nscontainer->editor, &modified);
1258 return modified ? S_OK : S_FALSE;
1261 HRESULT setup_edit_mode(HTMLDocumentObj *doc)
1263 IMoniker *mon;
1264 HRESULT hres;
1266 if(doc->usermode == EDITMODE)
1267 return S_OK;
1269 doc->usermode = EDITMODE;
1271 if(doc->basedoc.window->mon) {
1272 CLSID clsid = IID_NULL;
1273 hres = IMoniker_GetClassID(doc->basedoc.window->mon, &clsid);
1274 if(SUCCEEDED(hres)) {
1275 /* We should use IMoniker::Save here */
1276 FIXME("Use CLSID %s\n", debugstr_guid(&clsid));
1280 if(doc->frame)
1281 IOleInPlaceFrame_SetStatusText(doc->frame, NULL);
1283 doc->basedoc.window->readystate = READYSTATE_UNINITIALIZED;
1285 if(doc->client) {
1286 IOleCommandTarget *cmdtrg;
1288 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
1289 if(SUCCEEDED(hres)) {
1290 VARIANT var;
1292 V_VT(&var) = VT_I4;
1293 V_I4(&var) = 0;
1294 IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 37, 0, &var, NULL);
1296 IOleCommandTarget_Release(cmdtrg);
1300 if(doc->hostui) {
1301 DOCHOSTUIINFO hostinfo;
1303 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
1304 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
1305 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
1306 if(SUCCEEDED(hres))
1307 /* FIXME: use hostinfo */
1308 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
1309 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
1310 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
1313 update_doc(&doc->basedoc, UPDATE_UI);
1315 if(doc->basedoc.window->mon) {
1316 /* FIXME: We should find nicer way to do this */
1317 remove_target_tasks(doc->basedoc.task_magic);
1319 mon = doc->basedoc.window->mon;
1320 IMoniker_AddRef(mon);
1321 }else {
1322 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
1324 hres = CreateURLMoniker(NULL, about_blankW, &mon);
1325 if(FAILED(hres)) {
1326 FIXME("CreateURLMoniker failed: %08x\n", hres);
1327 return hres;
1331 hres = IPersistMoniker_Load(&doc->basedoc.IPersistMoniker_iface, TRUE, mon, NULL, 0);
1332 IMoniker_Release(mon);
1333 if(FAILED(hres))
1334 return hres;
1336 if(doc->ui_active) {
1337 if(doc->ip_window)
1338 call_set_active_object(doc->ip_window, NULL);
1339 if(doc->hostui)
1340 IDocHostUIHandler_HideUI(doc->hostui);
1343 if(doc->ui_active) {
1344 RECT rcBorderWidths;
1346 if(doc->hostui)
1347 IDocHostUIHandler_ShowUI(doc->hostui, DOCHOSTUITYPE_AUTHOR,
1348 &doc->basedoc.IOleInPlaceActiveObject_iface, &doc->basedoc.IOleCommandTarget_iface,
1349 doc->frame, doc->ip_window);
1351 if(doc->ip_window)
1352 call_set_active_object(doc->ip_window, &doc->basedoc.IOleInPlaceActiveObject_iface);
1354 memset(&rcBorderWidths, 0, sizeof(rcBorderWidths));
1355 if(doc->frame)
1356 IOleInPlaceFrame_SetBorderSpace(doc->frame, &rcBorderWidths);
1359 return S_OK;