1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/fixed.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/window.hxx>
23 #include <vcl/settings.hxx>
24 #include <svl/zforlist.hxx>
25 #include <opencl/openclconfig.hxx>
26 #include <officecfg/Office/Common.hxx>
27 #include <svtools/simptabl.hxx>
28 #include "optHeaderTabListbox.hxx"
30 #include <com/sun/star/configuration/theDefaultProvider.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
33 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
34 #include <com/sun/star/frame/Desktop.hpp>
35 #include <com/sun/star/util/XChangesBatch.hpp>
36 #include <com/sun/star/setup/UpdateCheckConfig.hpp>
39 #include "optopencl.hxx"
40 #include <svtools/treelistentry.hxx>
42 SvxOpenCLTabPage::SvxOpenCLTabPage(vcl::Window
* pParent
, const SfxItemSet
& rSet
) :
43 SfxTabPage(pParent
, "OptOpenCLPage", "cui/ui/optopenclpage.ui", &rSet
),
44 maConfig(OpenCLConfig::get())
46 get(mpUseOpenCL
, "useopencl");
47 get(mpBlackListTable
, "blacklist");
48 get(mpBlackListFrame
,"blacklistframe");
49 get(mpBlackListEdit
, "bledit");
50 get(mpBlackListAdd
, "bladd");
51 get(mpBlackListDelete
, "bldelete");
52 get(mpWhiteListTable
, "whitelist");
53 get(mpWhiteListFrame
,"whitelistframe");
54 get(mpWhiteListEdit
, "wledit");
55 get(mpWhiteListAdd
, "wladd");
56 get(mpWhiteListDelete
, "wldelete");
58 get(mpOSVersion
,"osversion");
59 get(mpDevice
,"device");
60 get(mpVendor
,"vendor");
61 get(mpDrvVersion
,"driverversion");
63 mpUseOpenCL
->Check(maConfig
.mbUseOpenCL
);
64 mpUseOpenCL
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, EnableOpenCLHdl
));
66 mpBlackListEdit
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, BlackListEditHdl
));
67 mpBlackListAdd
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, BlackListAddHdl
));
68 mpBlackListDelete
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, BlackListDeleteHdl
));
70 mpWhiteListEdit
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, WhiteListEditHdl
));
71 mpWhiteListAdd
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, WhiteListAddHdl
));
72 mpWhiteListDelete
->SetClickHdl(LINK(this, SvxOpenCLTabPage
, WhiteListDeleteHdl
));
74 WinBits nBits
= WB_SORT
| WB_HSCROLL
| WB_CLIPCHILDREN
| WB_TABSTOP
;
75 mpBlackList
= VclPtr
<SvSimpleTable
>::Create( *mpBlackListTable
, nBits
);
76 mpWhiteList
= VclPtr
<SvSimpleTable
>::Create( *mpWhiteListTable
, nBits
);
78 HeaderBar
&rBlBar
= mpBlackList
->GetTheHeaderBar();
79 HeaderBar
&rWiBar
= mpWhiteList
->GetTheHeaderBar();
81 HeaderBarItemBits nHBits
= HeaderBarItemBits::LEFT
| HeaderBarItemBits::VCENTER
| HeaderBarItemBits::CLICKABLE
;
82 rBlBar
.InsertItem( 1, mpOS
->GetText(), 0, nHBits
);
83 rBlBar
.InsertItem( 2, mpOSVersion
->GetText(), 0, nHBits
);
84 rBlBar
.InsertItem( 3, mpVendor
->GetText(), 0, nHBits
);
85 rBlBar
.InsertItem( 4, mpDevice
->GetText(), 0, nHBits
);
86 rBlBar
.InsertItem( 5, mpDrvVersion
->GetText(), 0, nHBits
);
88 rWiBar
.InsertItem( 1, mpOS
->GetText(), 0, nHBits
);
89 rWiBar
.InsertItem( 2, mpOSVersion
->GetText(), 0, nHBits
);
90 rWiBar
.InsertItem( 3, mpVendor
->GetText(), 0, nHBits
);
91 rWiBar
.InsertItem( 4, mpDevice
->GetText(), 0, nHBits
);
92 rWiBar
.InsertItem( 5, mpDrvVersion
->GetText(), 0, nHBits
);
94 long aTabs
[] = {5, 0, 0, 0, 0, 0};
95 aTabs
[1] = rBlBar
.GetTextWidth(rBlBar
.GetItemText(1)) + 12;
96 aTabs
[2] = rBlBar
.GetTextWidth(rBlBar
.GetItemText(2)) + aTabs
[1] + 12;
97 aTabs
[3] = rBlBar
.GetTextWidth(rBlBar
.GetItemText(3)) + aTabs
[2] + 12;
98 aTabs
[4] = rBlBar
.GetTextWidth(rBlBar
.GetItemText(4)) + aTabs
[3] + 12;
99 aTabs
[5] = rBlBar
.GetTextWidth(rBlBar
.GetItemText(5)) + aTabs
[4] + 12;
100 mpBlackList
->SetTabs(aTabs
, MAP_PIXEL
);
101 mpWhiteList
->SetTabs(aTabs
, MAP_PIXEL
);
105 SvxOpenCLTabPage::~SvxOpenCLTabPage()
110 void SvxOpenCLTabPage::dispose()
112 for ( sal_uInt16 i
= 0; i
< mpBlackList
->GetEntryCount(); ++i
)
113 delete static_cast<OpenCLConfig::ImplMatcher
*>(mpBlackList
->GetEntry(i
)->GetUserData());
114 for ( sal_uInt16 i
= 0; i
< mpWhiteList
->GetEntryCount(); ++i
)
115 delete static_cast<OpenCLConfig::ImplMatcher
*>(mpWhiteList
->GetEntry(i
)->GetUserData());
116 mpBlackList
.disposeAndClear();
117 mpWhiteList
.disposeAndClear();
120 mpBlackListFrame
.clear();
121 mpBlackListTable
.clear();
122 mpBlackListEdit
.clear();
123 mpBlackListAdd
.clear();
124 mpBlackListDelete
.clear();
129 mpDrvVersion
.clear();
130 mpWhiteListFrame
.clear();
131 mpWhiteListTable
.clear();
132 mpWhiteListEdit
.clear();
133 mpWhiteListAdd
.clear();
134 mpWhiteListDelete
.clear();
136 SfxTabPage::dispose();
139 VclPtr
<SfxTabPage
> SvxOpenCLTabPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
141 return VclPtr
<SvxOpenCLTabPage
>::Create(pParent
, *rAttrSet
);
144 bool SvxOpenCLTabPage::FillItemSet( SfxItemSet
* )
146 bool bModified
= false;
147 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create());
149 if (mpUseOpenCL
->IsValueChangedFromSaved())
150 maConfig
.mbUseOpenCL
= mpUseOpenCL
->IsChecked();
152 if (maConfig
!= OpenCLConfig::get())
166 OUString
format(const OpenCLConfig::ImplMatcher
& rImpl
)
168 return (rImpl
.maOS
+ "\t" +
169 rImpl
.maOSVersion
+ "\t" +
170 rImpl
.maPlatformVendor
+ "\t" +
171 rImpl
.maDevice
+ "\t" +
172 rImpl
.maDriverVersion
);
175 void fillListBox(SvSimpleTable
* pListBox
, const OpenCLConfig::ImplMatcherSet
& rSet
)
177 pListBox
->SetUpdateMode(false);
178 // kill added UserData to treeitem
179 for ( sal_uInt16 i
= 0; i
< pListBox
->GetEntryCount(); ++i
)
180 delete static_cast<OpenCLConfig::ImplMatcher
*>(pListBox
->GetEntry(i
)->GetUserData());
183 for (auto i
= rSet
.cbegin(); i
!= rSet
.cend(); ++i
)
185 OpenCLConfig::ImplMatcher
* pImpl
= new OpenCLConfig::ImplMatcher(*i
);
186 pListBox
->InsertEntry(format(*i
), NULL
, false, TREELIST_APPEND
, pImpl
);
189 pListBox
->SetUpdateMode(true);
194 void SvxOpenCLTabPage::Reset( const SfxItemSet
* )
196 maConfig
= OpenCLConfig::get();
198 mpUseOpenCL
->Check(maConfig
.mbUseOpenCL
);
199 mpUseOpenCL
->SaveValue();
201 fillListBox(mpBlackList
, maConfig
.maBlackList
);
202 fillListBox(mpWhiteList
, maConfig
.maWhiteList
);
205 void SvxOpenCLTabPage::FillUserData()
211 class ListEntryDialog
: public ModalDialog
214 OpenCLConfig::ImplMatcher maEntry
;
216 VclPtr
<ListBox
> mpOS
;
217 VclPtr
<Edit
> mpOSVersion
;
218 VclPtr
<Edit
> mpPlatformVendor
;
219 VclPtr
<Edit
> mpDevice
;
220 VclPtr
<Edit
> mpDriverVersion
;
222 DECL_LINK(OSSelectHdl
, ListBox
*);
223 DECL_LINK(EditModifiedHdl
, Edit
*);
225 ListEntryDialog(vcl::Window
* pParent
, const OpenCLConfig::ImplMatcher
& rEntry
, const OString
& rTag
);
226 virtual ~ListEntryDialog() { disposeOnce(); }
227 virtual void dispose() SAL_OVERRIDE
231 mpPlatformVendor
.clear();
233 mpDriverVersion
.clear();
234 ModalDialog::dispose();
239 ListEntryDialog::ListEntryDialog(vcl::Window
* pParent
, const OpenCLConfig::ImplMatcher
& rEntry
, const OString
& rTag
)
240 : ModalDialog(pParent
, "BlackOrWhiteListEntryDialog",
241 "cui/ui/blackorwhitelistentrydialog.ui"),
245 get(mpOSVersion
, "osversion");
246 get(mpPlatformVendor
, "platformvendor");
247 get(mpDevice
, "device");
248 get(mpDriverVersion
, "driverversion");
250 // Hardcode knowledge that entry 0 is the "Any"
251 if (maEntry
.maOS
.isEmpty())
253 mpOS
->SelectEntryPos(0, false);
257 for (int i
= 0; i
< mpOS
->GetEntryCount(); ++i
)
259 if (maEntry
.maOS
== mpOS
->GetEntry(i
))
260 mpOS
->SelectEntryPos(i
, false);
263 mpOSVersion
->SetText(rEntry
.maOSVersion
);
264 mpPlatformVendor
->SetText(rEntry
.maPlatformVendor
);
265 mpDevice
->SetText(rEntry
.maDevice
);
266 mpDriverVersion
->SetText(rEntry
.maDriverVersion
);
268 mpOS
->SetSelectHdl(LINK( this, ListEntryDialog
, OSSelectHdl
));
269 mpOSVersion
->SetModifyHdl(LINK(this, ListEntryDialog
, EditModifiedHdl
));
270 mpPlatformVendor
->SetModifyHdl(LINK(this, ListEntryDialog
, EditModifiedHdl
));
271 mpDevice
->SetModifyHdl(LINK(this, ListEntryDialog
, EditModifiedHdl
));
272 mpDriverVersion
->SetModifyHdl(LINK(this, ListEntryDialog
, EditModifiedHdl
));
274 SetText(get
<FixedText
>(rTag
+ "title")->GetText());
277 IMPL_LINK(ListEntryDialog
, OSSelectHdl
, ListBox
*, pListBox
)
279 if (pListBox
== mpOS
)
281 if (mpOS
->GetSelectEntryPos() == 0)
282 maEntry
.maOS
.clear();
284 maEntry
.maOS
= mpOS
->GetSelectEntry();
290 IMPL_LINK(ListEntryDialog
, EditModifiedHdl
, Edit
*, pEdit
)
292 if (pEdit
== mpOSVersion
)
293 maEntry
.maOSVersion
= pEdit
->GetText();
294 else if (pEdit
== mpPlatformVendor
)
295 maEntry
.maPlatformVendor
= pEdit
->GetText();
296 else if (pEdit
== mpDevice
)
297 maEntry
.maDevice
= pEdit
->GetText();
298 else if (pEdit
== mpDriverVersion
)
299 maEntry
.maDriverVersion
= pEdit
->GetText();
304 void openListDialog(SvxOpenCLTabPage
* pTabPage
, OpenCLConfig::ImplMatcher
& rEntry
, const OString
& rTag
)
306 ScopedVclPtrInstance
< ListEntryDialog
> aDlg(pTabPage
, rEntry
, rTag
);
308 if (aDlg
->Execute() == RET_OK
)
309 rEntry
= aDlg
->maEntry
;
312 const OpenCLConfig::ImplMatcher
& findCurrentEntry(OpenCLConfig::ImplMatcherSet
& rSet
, SvSimpleTable
* pListBox
)
314 SvTreeListEntry
* pEntry
= pListBox
->FirstSelected() ;
316 const OpenCLConfig::ImplMatcher
* pSet
= static_cast<OpenCLConfig::ImplMatcher
*>(pEntry
->GetUserData());
318 for (auto i
= rSet
.cbegin(); i
!= rSet
.cend(); ++i
)
325 auto i
= rSet
.begin();
331 long SvxOpenCLTabPage::EditHdl(SvSimpleTable
* pListBox
, OpenCLConfig::ImplMatcherSet
& rSet
, const OString
& rTag
)
333 if (!pListBox
->FirstSelected())
336 OpenCLConfig::ImplMatcher
rEntry(findCurrentEntry(rSet
, pListBox
));
338 openListDialog(this, rEntry
, rTag
);
340 fillListBox(pListBox
, rSet
);
345 long SvxOpenCLTabPage::AddHdl(SvSimpleTable
* pListBox
, OpenCLConfig::ImplMatcherSet
& rSet
, const OString
& rTag
)
347 OpenCLConfig::ImplMatcher rEntry
;
348 openListDialog(this, rEntry
, rTag
);
349 if (rEntry
!= OpenCLConfig::ImplMatcher())
352 fillListBox(pListBox
, rSet
);
358 long SvxOpenCLTabPage::DeleteHdl(SvSimpleTable
* pListBox
, OpenCLConfig::ImplMatcherSet
& rSet
)
360 if (!pListBox
->FirstSelected())
363 OpenCLConfig::ImplMatcher
rEntry(findCurrentEntry(rSet
, pListBox
));
365 fillListBox(pListBox
, rSet
);
370 void SvxOpenCLTabPage::EnableOpenCLHdl(VclFrame
* pFrame
, bool aEnable
)
372 pFrame
->Enable(aEnable
);
375 IMPL_LINK_NOARG(SvxOpenCLTabPage
, BlackListEditHdl
)
377 return EditHdl(mpBlackList
, maConfig
.maBlackList
, "bledit");
380 IMPL_LINK_NOARG(SvxOpenCLTabPage
, BlackListAddHdl
)
382 return AddHdl(mpBlackList
, maConfig
.maBlackList
, "bladd");
385 IMPL_LINK_NOARG(SvxOpenCLTabPage
, BlackListDeleteHdl
)
387 return DeleteHdl(mpBlackList
, maConfig
.maBlackList
);
390 IMPL_LINK_NOARG(SvxOpenCLTabPage
, WhiteListEditHdl
)
392 return EditHdl(mpWhiteList
, maConfig
.maWhiteList
, "wledit");
395 IMPL_LINK_NOARG(SvxOpenCLTabPage
, WhiteListAddHdl
)
397 return AddHdl(mpWhiteList
, maConfig
.maWhiteList
, "wladd");
400 IMPL_LINK_NOARG(SvxOpenCLTabPage
, WhiteListDeleteHdl
)
402 return DeleteHdl(mpWhiteList
, maConfig
.maWhiteList
);
405 IMPL_LINK_NOARG(SvxOpenCLTabPage
, EnableOpenCLHdl
)
407 EnableOpenCLHdl(mpBlackListFrame
, mpUseOpenCL
->IsChecked());
408 EnableOpenCLHdl(mpWhiteListFrame
, mpUseOpenCL
->IsChecked());
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */