Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MFXLinkLabel.cpp
Go to the documentation of this file.
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2006-2024 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
20
//
21
/****************************************************************************/
22
23
/* =========================================================================
24
* included modules
25
* ======================================================================= */
26
#include <config.h>
27
28
#ifdef WIN32
29
#define NOMINMAX
30
#include <windows.h>
31
#undef NOMINMAX
32
#endif
33
34
#include "
MFXLinkLabel.h
"
35
36
37
FXint
38
MFXLinkLabel::fxexecute
(FXString link) {
39
#ifdef WIN32
40
return
(
int
)(intptr_t)ShellExecute(
nullptr
,
"open"
, link.text(),
nullptr
,
nullptr
, SW_SHOWNORMAL) > 32 ? 1 : 0;
41
#else
42
FXString ext = FXPath::extension(link);
43
FXString list;
44
if
(comparecase(link.section(
':'
, 0),
"http"
) == 0 ||
45
comparecase(link.section(
':'
, 0),
"https"
) == 0 ||
46
comparecase(link.section(
':'
, 0),
"ftp"
) == 0 ||
47
comparecase(ext,
"htm"
) == 0 || comparecase(ext,
"html"
) == 0 ||
48
comparecase(ext,
"php"
) == 0 || comparecase(ext,
"asp"
) == 0) {
49
list =
"firefox\tchromium\tkonqueror\tdillo\tlynx\topen"
;
50
}
else
if
(comparecase(ext,
"pdf"
) == 0) {
51
list =
"acroread\tkghostview\tgpdf\txpdf"
;
52
}
53
54
if
(list.length()) {
55
FXString software;
56
FXint index = 0;
57
FXString path = FXSystem::getExecPath();
58
59
software = list.section(
"\t"
, index);
60
while
(!software.empty()) {
61
software = FXPath::search(path, software);
62
if
(software.length())
63
return
system(FXString().format(
"%s \"%s\" >/dev/null 2>&1 & "
,
64
software.text(), link.text()).text()) > 0 ? 0 : 1;
65
index++;
66
software = list.section(
"\t"
, index);
67
}
68
}
else
if
(FXStat::isExecutable(link)) {
69
return
system((link +
" >/dev/null 2>&1 & "
).text()) > 0 ? 0 : 1;
70
}
71
return
0;
72
#endif
73
}
74
75
76
77
FXDEFMAP
(
MFXLinkLabel
) MFXLinkLabelMap[] = {
78
FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0,
MFXLinkLabel::onLeftBtnPress
),
79
FXMAPFUNC(SEL_TIMEOUT,
MFXLinkLabel::ID_TIMER
,
MFXLinkLabel::onTimer
),
80
};
81
FXIMPLEMENT(
MFXLinkLabel
, FXLabel, MFXLinkLabelMap, ARRAYNUMBER(MFXLinkLabelMap))
82
83
84
MFXLinkLabel
::
MFXLinkLabel
(FXComposite* p, const FXString& text, FXIcon* ic, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) : FXLabel(p, text, ic, opts, x, y, w, h, pl, pr, pt, pb) {
85
setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
86
setTextColor(FXRGB(0, 0, 255));
87
}
88
89
MFXLinkLabel::~MFXLinkLabel
() {
90
getApp()->removeTimeout(
this
,
ID_TIMER
);
91
}
92
93
long
MFXLinkLabel::onLeftBtnPress
(FXObject*, FXSelector,
void
*) {
94
FXString link = getTipText();
95
if
(link.length()) {
96
getApp()->beginWaitCursor();
97
if
(
fxexecute
(link)) {
98
getApp()->addTimeout(
this
,
ID_TIMER
, 2000);
// 2 seconds of way cursor
99
}
else
{
100
getApp()->endWaitCursor();
101
getApp()->beep();
102
}
103
}
104
return
1;
105
}
106
107
long
MFXLinkLabel::onTimer
(FXObject*, FXSelector,
void
*) {
108
getApp()->endWaitCursor();
109
return
1;
110
}
FXDEFMAP
FXDEFMAP(MFXLinkLabel) MFXLinkLabelMap[]
MFXLinkLabel.h
MFXLinkLabel
Definition
MFXLinkLabel.h:30
MFXLinkLabel::onTimer
long onTimer(FXObject *, FXSelector, void *)
Definition
MFXLinkLabel.cpp:107
MFXLinkLabel::onLeftBtnPress
long onLeftBtnPress(FXObject *, FXSelector, void *)
Definition
MFXLinkLabel.cpp:93
MFXLinkLabel::fxexecute
static FXint fxexecute(FXString link)
Definition
MFXLinkLabel.cpp:38
MFXLinkLabel::ID_TIMER
@ ID_TIMER
Definition
MFXLinkLabel.h:45
MFXLinkLabel::~MFXLinkLabel
virtual ~MFXLinkLabel()
Destructor.
Definition
MFXLinkLabel.cpp:89
src
utils
foxtools
MFXLinkLabel.cpp
Generated on Sat Nov 9 2024 00:10:31 for Eclipse SUMO - Simulation of Urban MObility by
1.9.8