1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qaxwidgettaskmenu.h"
|
---|
43 | #include "qdesigneraxwidget.h"
|
---|
44 | #include "qaxwidgetpropertysheet.h"
|
---|
45 |
|
---|
46 | #include <QtDesigner/QDesignerFormWindowInterface>
|
---|
47 | #include <QtDesigner/QDesignerFormWindowCursorInterface>
|
---|
48 | #include <QtDesigner/QDesignerFormEditorInterface>
|
---|
49 | #include <QtDesigner/QExtensionManager>
|
---|
50 |
|
---|
51 | #include <QtGui/QUndoCommand>
|
---|
52 | #include <QtGui/QMessageBox>
|
---|
53 | #include <QtGui/QUndoStack>
|
---|
54 | #include <QtCore/QUuid>
|
---|
55 | #include <ActiveQt/qaxselect.h>
|
---|
56 |
|
---|
57 | #include <olectl.h>
|
---|
58 | #include <qaxtypes.h>
|
---|
59 |
|
---|
60 | QT_BEGIN_NAMESPACE
|
---|
61 |
|
---|
62 | /* SetControlCommand: An undo commands that sets a control bypassing
|
---|
63 | Designer's property system which cannot handle the changing
|
---|
64 | of the 'control' property's index and other cached information
|
---|
65 | when modifying it. */
|
---|
66 |
|
---|
67 | class SetControlCommand : public QUndoCommand
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | SetControlCommand(QDesignerAxWidget *ax, QDesignerFormWindowInterface *core, const QString &newClsid = QString());
|
---|
71 |
|
---|
72 | virtual void redo() { apply(m_newClsid); }
|
---|
73 | virtual void undo() { apply(m_oldClsid); }
|
---|
74 |
|
---|
75 | private:
|
---|
76 | bool apply(const QString &clsid);
|
---|
77 |
|
---|
78 | QDesignerAxWidget *m_axWidget;
|
---|
79 | QDesignerFormWindowInterface *m_formWindow;
|
---|
80 | QString m_oldClsid;
|
---|
81 | QString m_newClsid;
|
---|
82 | };
|
---|
83 |
|
---|
84 | SetControlCommand::SetControlCommand(QDesignerAxWidget *ax, QDesignerFormWindowInterface *fw, const QString &newClsid) :
|
---|
85 | m_axWidget(ax),
|
---|
86 | m_formWindow(fw),
|
---|
87 | m_oldClsid(ax->control()),
|
---|
88 | m_newClsid(newClsid)
|
---|
89 | {
|
---|
90 | if (m_newClsid.isEmpty())
|
---|
91 | setText(QDesignerAxWidget::tr("Reset control"));
|
---|
92 | else
|
---|
93 | setText(QDesignerAxWidget::tr("Set control"));
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool SetControlCommand::apply(const QString &clsid)
|
---|
97 | {
|
---|
98 | if (m_oldClsid == m_newClsid)
|
---|
99 | return true;
|
---|
100 |
|
---|
101 | QObject *ext = m_formWindow->core()->extensionManager()->extension(m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension));
|
---|
102 | QAxWidgetPropertySheet *sheet = qobject_cast<QAxWidgetPropertySheet*>(ext);
|
---|
103 | if (!sheet)
|
---|
104 | return false;
|
---|
105 |
|
---|
106 | const bool hasClsid = !clsid.isEmpty();
|
---|
107 | const int index = sheet->indexOf(QLatin1String(QAxWidgetPropertySheet::controlPropertyName));
|
---|
108 | if (hasClsid)
|
---|
109 | sheet->setProperty(index, clsid);
|
---|
110 | else
|
---|
111 | sheet->reset(index);
|
---|
112 | return true;
|
---|
113 | }
|
---|
114 |
|
---|
115 | // -------------------- QAxWidgetTaskMenu
|
---|
116 | QAxWidgetTaskMenu::QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent) :
|
---|
117 | QObject(parent),
|
---|
118 | m_axwidget(object),
|
---|
119 | m_setAction(new QAction(tr("Set Control"), this)),
|
---|
120 | m_resetAction(new QAction(tr("Reset Control"), this))
|
---|
121 | {
|
---|
122 | connect(m_setAction, SIGNAL(triggered()), this, SLOT(setActiveXControl()));
|
---|
123 | connect(m_resetAction, SIGNAL(triggered()), this, SLOT(resetActiveXControl()));
|
---|
124 | m_taskActions.push_back(m_setAction);
|
---|
125 | m_taskActions.push_back(m_resetAction);
|
---|
126 | }
|
---|
127 |
|
---|
128 | QAxWidgetTaskMenu::~QAxWidgetTaskMenu()
|
---|
129 | {
|
---|
130 | }
|
---|
131 |
|
---|
132 | QList<QAction*> QAxWidgetTaskMenu::taskActions() const
|
---|
133 | {
|
---|
134 | const bool loaded = m_axwidget->loaded();
|
---|
135 | m_setAction->setEnabled(!loaded);
|
---|
136 | m_resetAction->setEnabled(loaded);
|
---|
137 | return m_taskActions;
|
---|
138 | }
|
---|
139 |
|
---|
140 | void QAxWidgetTaskMenu::resetActiveXControl()
|
---|
141 | {
|
---|
142 | QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
|
---|
143 | Q_ASSERT(formWin != 0);
|
---|
144 | formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin));
|
---|
145 | }
|
---|
146 |
|
---|
147 | void QAxWidgetTaskMenu::setActiveXControl()
|
---|
148 | {
|
---|
149 | QAxSelect *dialog = new QAxSelect(m_axwidget->topLevelWidget());
|
---|
150 | if (dialog->exec()) {
|
---|
151 | QUuid clsid = dialog->clsid();
|
---|
152 | QString key;
|
---|
153 |
|
---|
154 | IClassFactory2 *cf2 = 0;
|
---|
155 | CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2, (void**)&cf2);
|
---|
156 |
|
---|
157 | if (cf2) {
|
---|
158 | BSTR bKey;
|
---|
159 | HRESULT hres = cf2->RequestLicKey(0, &bKey);
|
---|
160 | if (hres == CLASS_E_NOTLICENSED) {
|
---|
161 | QMessageBox::warning(m_axwidget->topLevelWidget(), tr("Licensed Control"),
|
---|
162 | tr("The control requires a design-time license"));
|
---|
163 | clsid = QUuid();
|
---|
164 | } else {
|
---|
165 | key = QString::fromWCharArray(bKey);
|
---|
166 | }
|
---|
167 |
|
---|
168 | cf2->Release();
|
---|
169 | }
|
---|
170 |
|
---|
171 | if (!clsid.isNull()) {
|
---|
172 | QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget);
|
---|
173 |
|
---|
174 | Q_ASSERT(formWin != 0);
|
---|
175 | QString value = clsid.toString();
|
---|
176 | if (!key.isEmpty()) {
|
---|
177 | value += QLatin1Char(':');
|
---|
178 | value += key;
|
---|
179 | }
|
---|
180 | formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin, value));
|
---|
181 | }
|
---|
182 | }
|
---|
183 | delete dialog;
|
---|
184 | }
|
---|
185 |
|
---|
186 | QT_END_NAMESPACE
|
---|