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