Eclipse SUMO - Simulation of Urban MObility
FXLinkLabel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 /* =========================================================================
21  * included modules
22  * ======================================================================= */
23 #include <config.h>
24 
25 #ifdef WIN32
26 #define NOMINMAX
27 #include <windows.h>
28 #undef NOMINMAX
29 #endif
30 
31 #include "FXLinkLabel.h"
32 
33 
34 FXint
35 FXLinkLabel::fxexecute(FXString link) {
36 #ifdef WIN32
37  return (int)ShellExecute(nullptr, "open", link.text(), nullptr, nullptr, SW_SHOWNORMAL) > 32;
38 #else
39  FXString ext = FXPath::extension(link);
40  FXString list;
41  if (comparecase(link.section(':', 0), "http") == 0 ||
42  comparecase(link.section(':', 0), "ftp") == 0 ||
43  comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
44  comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
45  list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
46  } else if (comparecase(ext, "pdf") == 0) {
47  list = "acroread\tkghostview\tgpdf\txpdf";
48  }
49 
50  if (list.length()) {
51  FXString software;
52  FXint index = 0;
53  FXString path = FXSystem::getExecPath();
54 
55  software = list.section("\t", index);
56  while (!software.empty()) {
57  software = FXPath::search(path, software);
58  if (software.length())
59  return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
60  software.text(), link.text()).text()) > 0 ? 0 : 1;
61  index++;
62  software = list.section("\t", index);
63  }
64  } else if (FXStat::isExecutable(link)) {
65  return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
66  }
67  return 0;
68 #endif
69 }
70 
71 
72 
73 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = {
74  FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress),
75  FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer),
76 };
77 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap))
78 
79 
80 FXLinkLabel::FXLinkLabel(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) {
81  setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
82  setTextColor(FXRGB(0, 0, 255));
83 }
84 
86  getApp()->removeTimeout(this, ID_TIMER);
87 }
88 
89 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
90  FXString link = getTipText();
91  if (link.length()) {
92  getApp()->beginWaitCursor();
93  if (fxexecute(link)) {
94  getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
95  } else {
96  getApp()->endWaitCursor();
97  getApp()->beep();
98  }
99  }
100  return 1;
101 }
102 
103 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
104  getApp()->endWaitCursor();
105  return 1;
106 }
config.h