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-2026 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#include <windows.h>
30#include <shellapi.h>
31#endif
32
34
35#include "MFXLinkLabel.h"
36
37
38FXint
40#ifdef WIN32
41 return (int)(intptr_t)ShellExecute(nullptr, "open", link.text(), nullptr, nullptr, SW_SHOWNORMAL) > 32 ? 1 : 0;
42#else
43 FXString ext = FXPath::extension(link);
44 FXString list;
45 if (comparecase(link.section(':', 0), "http") == 0 ||
46 comparecase(link.section(':', 0), "https") == 0 ||
47 comparecase(link.section(':', 0), "ftp") == 0 ||
48 comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
49 comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
50 list = "firefox\tchromium\tkonqueror\tdillo\tlynx\topen";
51 } else if (comparecase(ext, "pdf") == 0) {
52 list = "acroread\tkghostview\tgpdf\txpdf";
53 }
54
55 if (list.length()) {
56 FXString software;
57 FXint index = 0;
58 FXString path = FXSystem::getExecPath();
59
60 software = list.section("\t", index);
61 while (!software.empty()) {
62 software = FXPath::search(path, software);
63 if (software.length())
64 return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
65 software.text(), link.text()).text()) > 0 ? 0 : 1;
66 index++;
67 software = list.section("\t", index);
68 }
69 } else if (FXStat::isExecutable(link)) {
70 return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
71 }
72 return 0;
73#endif
74}
75
76
77
78FXDEFMAP(MFXLinkLabel) MFXLinkLabelMap[] = {
79 FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, MFXLinkLabel::onLeftBtnPress),
80 FXMAPFUNC(SEL_TIMEOUT, MFXLinkLabel::ID_TIMER, MFXLinkLabel::onTimer),
81};
82FXIMPLEMENT(MFXLinkLabel, FXLabel, MFXLinkLabelMap, ARRAYNUMBER(MFXLinkLabelMap))
83
84
85MFXLinkLabel::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) {
86 setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
87 setTextColor(GUIDesignTextColorBlue);
88}
89
91 getApp()->removeTimeout(this, ID_TIMER);
92}
93
94long MFXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
95 FXString link = getTipText();
96 if (link.length()) {
97 getApp()->beginWaitCursor();
98 if (fxexecute(link)) {
99 getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
100 } else {
101 getApp()->endWaitCursor();
102 getApp()->beep();
103 }
104 }
105 return 1;
106}
107
108long MFXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
109 getApp()->endWaitCursor();
110 return 1;
111}
#define GUIDesignTextColorBlue
blue color (for default text)
Definition GUIDesigns.h:41