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 /****************************************************************************/
16 //
17 /****************************************************************************/
18 
19 /* =========================================================================
20  * included modules
21  * ======================================================================= */
22 #include <config.h>
23 
24 #ifdef WIN32
25 #define NOMINMAX
26 #include <windows.h>
27 #undef NOMINMAX
28 #endif
29 
30 #include "FXLinkLabel.h"
31 
32 
33 FXint
34 FXLinkLabel::fxexecute(FXString link) {
35 #ifdef WIN32
36  return (int)ShellExecute(nullptr, "open", link.text(), nullptr, nullptr, SW_SHOWNORMAL) > 32;
37 #else
38  FXString ext = FXPath::extension(link);
39  FXString list;
40  if (comparecase(link.section(':', 0), "http") == 0 ||
41  comparecase(link.section(':', 0), "ftp") == 0 ||
42  comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
43  comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
44  list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
45  } else if (comparecase(ext, "pdf") == 0) {
46  list = "acroread\tkghostview\tgpdf\txpdf";
47  }
48 
49  if (list.length()) {
50  FXString software;
51  FXint index = 0;
52  FXString path = FXSystem::getExecPath();
53 
54  software = list.section("\t", index);
55  while (!software.empty()) {
56  software = FXPath::search(path, software);
57  if (software.length())
58  return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
59  software.text(), link.text()).text()) > 0 ? 0 : 1;
60  index++;
61  software = list.section("\t", index);
62  }
63  } else if (FXStat::isExecutable(link)) {
64  return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
65  }
66  return 0;
67 #endif
68 }
69 
70 
71 
72 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = {
73  FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress),
74  FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer),
75 };
76 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap))
77 
78 
79 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) {
80  setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
81  setTextColor(FXRGB(0, 0, 255));
82 }
83 
85  getApp()->removeTimeout(this, ID_TIMER);
86 }
87 
88 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
89  FXString link = getTipText();
90  if (link.length()) {
91  getApp()->beginWaitCursor();
92  if (fxexecute(link)) {
93  getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
94  } else {
95  getApp()->endWaitCursor();
96  getApp()->beep();
97  }
98  }
99  return 1;
100 }
101 
102 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
103  getApp()->endWaitCursor();
104  return 1;
105 }
config.h