SUMO - Simulation of Urban MObility
|
00001 /* ========================================================================= 00002 * included modules 00003 * ======================================================================= */ 00004 #ifdef _MSC_VER 00005 #include <windows_config.h> 00006 #else 00007 #include <config.h> 00008 #endif 00009 00010 #ifdef WIN32 00011 #include <windows.h> 00012 #endif 00013 00014 #include "FXLinkLabel.h" 00015 00016 #ifdef CHECK_MEMORY_LEAKS 00017 #include <foreign/nvwa/debug_new.h> 00018 #endif // CHECK_MEMORY_LEAKS 00019 00020 00021 FXint fxexecute(FXString link) { 00022 #ifdef WIN32 00023 FXString quoted = FXPath::enquote(link); 00024 return (size_t)ShellExecute(NULL, "open", quoted.text(), NULL, NULL, SW_SHOW) > 32; 00025 #else 00026 FXString ext = FXPath::extension(link); 00027 FXString list; 00028 if (comparecase(link.section(':', 0), "http") == 0 || 00029 comparecase(link.section(':', 0), "ftp") == 0 || 00030 comparecase(ext, "htm") == 0 || comparecase(ext, "html") == 0 || 00031 comparecase(ext, "php") == 0 || comparecase(ext, "asp") == 0) { 00032 list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx"; 00033 } else if (comparecase(ext, "pdf") == 0) { 00034 list = "acroread\tkghostview\tgpdf\txpdf"; 00035 } 00036 00037 if (list.length()) { 00038 FXString software; 00039 FXint index = 0; 00040 FXString path = FXSystem::getExecPath(); 00041 00042 software = list.section("\t", index); 00043 while (!software.empty()) { 00044 software = FXPath::search(path, software); 00045 if (software.length()) 00046 return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ", 00047 software.text(), link.text()).text()) > 0 ? 0 : 1; 00048 index++; 00049 software = list.section("\t", index); 00050 } 00051 } else if (FXStat::isExecutable(link)) { 00052 return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0 : 1; 00053 } 00054 return 0; 00055 #endif 00056 } 00057 00058 00059 00060 FXDEFMAP(FXLinkLabel) FXLinkLabelMap[] = { 00061 FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, FXLinkLabel::onLeftBtnPress), 00062 FXMAPFUNC(SEL_TIMEOUT, FXLinkLabel::ID_TIMER, FXLinkLabel::onTimer), 00063 }; 00064 FXIMPLEMENT(FXLinkLabel, FXLabel, FXLinkLabelMap, ARRAYNUMBER(FXLinkLabelMap)) 00065 00066 00067 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) { 00068 setDefaultCursor(getApp()->getDefaultCursor(DEF_HAND_CURSOR)); 00069 setTextColor(FXRGB(0, 0, 255)); 00070 } 00071 00072 FXLinkLabel::~FXLinkLabel() { 00073 getApp()->removeTimeout(this, ID_TIMER); 00074 } 00075 00076 long FXLinkLabel::onLeftBtnPress(FXObject*, FXSelector, void*) { 00077 FXString link = getTipText(); 00078 if (link.length()) { 00079 getApp()->beginWaitCursor(); 00080 if (fxexecute(link)) { 00081 getApp()->addTimeout(this, ID_TIMER, 2000); // 2 seconds of way cursor 00082 } else { 00083 getApp()->endWaitCursor(); 00084 getApp()->beep(); 00085 } 00086 } 00087 return 1; 00088 } 00089 00090 long FXLinkLabel::onTimer(FXObject*, FXSelector, void*) { 00091 getApp()->endWaitCursor(); 00092 return 1; 00093 }