]> git.saurik.com Git - wxWidgets.git/blame - src/msw/utilswin.cpp
Add missing wxEVT_COMMAND_TEXT_ENTER
[wxWidgets.git] / src / msw / utilswin.cpp
CommitLineData
5146904d
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/utilswin.cpp
3// Purpose: Various utility functions only available in Windows GUI
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 21.06.2003 (extracted from msw/utils.cpp)
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#ifndef WX_PRECOMP
19 #include "wx/utils.h"
20#endif //WX_PRECOMP
21
22#include "wx/msw/private.h" // includes <windows.h>
23#include "wx/msw/registry.h"
24#include <shellapi.h> // needed for SHELLEXECUTEINFO
25
26// ----------------------------------------------------------------------------
27// Launch document with default app
28// ----------------------------------------------------------------------------
29
30bool wxLaunchDefaultApplication(const wxString& document, int flags)
31{
32 wxUnusedVar(flags);
33
34 WinStruct<SHELLEXECUTEINFO> sei;
35 sei.lpFile = document.t_str();
36#ifdef __WXWINCE__
37 sei.nShow = SW_SHOWNORMAL; // SW_SHOWDEFAULT not defined under CE (#10216)
38#else
39 sei.nShow = SW_SHOWDEFAULT;
40#endif
41
42 // avoid Windows message box in case of error for consistency with
43 // wxLaunchDefaultBrowser() even if don't show the error ourselves in this
44 // function
45 sei.fMask = SEE_MASK_FLAG_NO_UI;
46
47 if ( ::ShellExecuteEx(&sei) )
48 return true;
49
50 return false;
51}
52
53// ----------------------------------------------------------------------------
54// Launch default browser
55// ----------------------------------------------------------------------------
56
57bool wxDoLaunchDefaultBrowser(const wxString& url, const wxString& scheme, int flags)
58{
59 wxUnusedVar(flags);
60
61#if wxUSE_IPC
62 if ( flags & wxBROWSER_NEW_WINDOW )
63 {
64 // ShellExecuteEx() opens the URL in an existing window by default so
65 // we can't use it if we need a new window
66 wxRegKey key(wxRegKey::HKCR, scheme + wxT("\\shell\\open"));
67 if ( !key.Exists() )
68 {
69 // try the default browser, it must be registered at least for http URLs
70 key.SetName(wxRegKey::HKCR, wxT("http\\shell\\open"));
71 }
72
73 if ( key.Exists() )
74 {
75 wxRegKey keyDDE(key, wxT("DDEExec"));
76 if ( keyDDE.Exists() )
77 {
78 // we only know the syntax of WWW_OpenURL DDE request for IE,
79 // optimistically assume that all other browsers are compatible
80 // with it
81 static const wxChar *TOPIC_OPEN_URL = wxT("WWW_OpenURL");
82 wxString ddeCmd;
83 wxRegKey keyTopic(keyDDE, wxT("topic"));
84 bool ok = keyTopic.Exists() &&
85 keyTopic.QueryDefaultValue() == TOPIC_OPEN_URL;
86 if ( ok )
87 {
88 ddeCmd = keyDDE.QueryDefaultValue();
89 ok = !ddeCmd.empty();
90 }
91
92 if ( ok )
93 {
94 // for WWW_OpenURL, the index of the window to open the URL
95 // in is -1 (meaning "current") by default, replace it with
96 // 0 which means "new" (see KB article 160957)
97 ok = ddeCmd.Replace(wxT("-1"), wxT("0"),
98 false /* only first occurrence */) == 1;
99 }
100
101 if ( ok )
102 {
103 // and also replace the parameters: the topic should
104 // contain a placeholder for the URL
105 ok = ddeCmd.Replace(wxT("%1"), url, false) == 1;
106 }
107
108 if ( ok )
109 {
110 // try to send it the DDE request now but ignore the errors
111 wxLogNull noLog;
112
113 const wxString ddeServer = wxRegKey(keyDDE, wxT("application"));
114 if ( wxExecuteDDE(ddeServer, TOPIC_OPEN_URL, ddeCmd) )
115 return true;
116
117 // this is not necessarily an error: maybe browser is
118 // simply not running, but no matter, in any case we're
119 // going to launch it using ShellExecuteEx() below now and
120 // we shouldn't try to open a new window if we open a new
121 // browser anyhow
122 }
123 }
124 }
125 }
126#endif // wxUSE_IPC
127
128 WinStruct<SHELLEXECUTEINFO> sei;
129 sei.lpFile = url.c_str();
130 sei.lpVerb = wxT("open");
131 sei.nShow = SW_SHOWNORMAL;
132 sei.fMask = SEE_MASK_FLAG_NO_UI; // we give error message ourselves
133
134 if ( ::ShellExecuteEx(&sei) )
135 return true;
136
137 return false;
138}