SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FXLinkLabel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 //
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2006-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 /* =========================================================================
24  * included modules
25  * ======================================================================= */
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef WIN32
33 #define NOMINMAX
34 #include <windows.h>
35 #undef NOMINMAX
36 #endif
37 
38 #include "FXLinkLabel.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 FXint fxexecute(FXString link) {
46 #ifdef WIN32
47  FXString quoted = FXPath::enquote(link);
48  return (size_t)ShellExecute(NULL, "open", quoted.text(), NULL, NULL, SW_SHOW) > 32;
49 #else
50  FXString ext = FXPath::extension(link);
51  FXString list;
52  if (comparecase(link.section(':', 0), "http") == 0 ||
53  comparecase(link.section(':', 0), "ftp") == 0 ||
54  comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 ||
55  comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) {
56  list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx";
57  } else if (comparecase(ext, "pdf") == 0) {
58  list = "acroread\tkghostview\tgpdf\txpdf";
59  }
60 
61  if (list.length()) {
62  FXString software;
63  FXint index = 0;
64  FXString path = FXSystem::getExecPath();
65 
66  software = list.section("\t", index);
67  while (!software.empty()) {
68  software = FXPath::search(path, software);
69  if (software.length())
70  return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ",
71  software.text(), link.text()).text()) > 0 ? 0 : 1;
72  index++;
73  software = list.section("\t", index);
74  }
75  } else if (FXStat::isExecutable(link)) {
76  return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1;
77  }
78  return 0;
79 #endif
80 }
81 
82 
83 
84 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = {
85  FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress),
86  FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer),
87 };
88 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap))
89 
90 
91 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) {
92  setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR));
93  setTextColor(FXRGB(0, 0, 255));
94 }
95 
97  getApp()->removeTimeout(this, ID_TIMER);
98 }
99 
100 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) {
101  FXString link = getTipText();
102  if (link.length()) {
103  getApp()->beginWaitCursor();
104  if (fxexecute(link)) {
105  getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor
106  } else {
107  getApp()->endWaitCursor();
108  getApp()->beep();
109  }
110  }
111  return 1;
112 }
113 
114 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) {
115  getApp()->endWaitCursor();
116  return 1;
117 }