// Make a label FXLabel::FXLabel(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):FXFrame(p,opts,x,y,w,h,pl,pr,pt,pb){ FXString string=text.section('\t',0); flags|=FLAG_ENABLED; label=stripHotKey(string); icon=ic; font=getApp()->getNormalFont(); help=text.section('\t',2); tip=text.section('\t',1); textColor=getApp()->getForeColor(); hotkey=parseHotKey(string); hotoff=findHotKey(string); addHotKey(hotkey); }
// Construct and init FXToggleButton::FXToggleButton(FXComposite* p,const FXString& text1,const FXString& text2,FXIcon* icon1,FXIcon* icon2,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):FXLabel(p,text1,icon1,opts,x,y,w,h,pl,pr,pt,pb){ FXString string=text2.section('\t',0); target=tgt; message=sel; altlabel=stripHotKey(string); alttip=text2.section('\t',1); althelp=text2.section('\t',2); alticon=icon2; althotkey=parseHotKey(string); althotoff=findHotKey(string); addHotKey(althotkey); state=false; down=false; }
void CmdIO::appendLine(FXString&s, FXSelector selid) { if (target&&message) { FXint nlines=s.contains('\n'); FXString trailer=s.section('\n', nlines); s.trunc(s.length()-trailer.length()); if (multiline_mode) { target->handle(this, FXSEL(selid,message), (void*)(&s)); } else { for (FXint i=0; i<nlines; i++) { FXString sect=s.section('\n',i); target->handle(this, FXSEL(selid,message), (void*)(§)); } } s=trailer; } }
// Menu entry FXMenuCaption::FXMenuCaption(FXComposite* p,const FXString& text,FXIcon* ic,FXuint opts): FXWindow(p,opts,0,0,0,0){ FXString string=text.section('\t',0); flags|=FLAG_SHOWN; label=stripHotKey(string); help=text.section('\t',2); icon=ic; font=getApp()->getNormalFont(); hotkey=parseHotKey(string); hotoff=findHotKey(string); addHotKey(hotkey); textColor=getApp()->getForeColor(); seltextColor=getApp()->getSelMenuTextColor(); selbackColor=getApp()->getSelMenuBackColor(); hiliteColor=getApp()->getHiliteColor(); shadowColor=getApp()->getShadowColor(); }
// Fill list by appending items from newline separated strings FXint FXHeader::fillItems(const FXString& strings,FXIcon *icon,FXint size,void* ptr,FXbool notify){ register FXint n=0; FXString text; while(!(text=strings.section('\n',n)).empty()){ appendItem(text,icon,size,ptr,notify); n++; } return n; }
// Change patterns, each pattern separated by newline void FileSelector::setPatternList(const FXString& patterns) { FXString pat; FXint i; filefilter->clearItems(); for(i=0; !(pat=patterns.section('\n',i)).empty(); i++) filefilter->appendItem(pat); if(!filefilter->getNumItems()) filefilter->appendItem(allfiles); setCurrentPattern(0); }
// Look for line number after filename in the form of FILE.EXT:NNN static void ParseLineNumberFromFilename(FXString &filename, FXString &line) { #ifdef WIN32 // Ignore colon in drive spec on WIN32 FXint colons=filename.contains(':'); if (FXPath::isAbsolute(filename)) { if (colons>1) { line=filename.section(':',2); filename=filename.section(':',0,2); } } else { if (colons>0) { line=filename.section(':',1) ; filename=filename.section(':',0); } } #else if (filename.contains(':')) { line=filename.section(':',1) ; filename=filename.section(':',0); } #endif for (FXint i=0; i<line.length(); i++) { if (!Ascii::isDigit(line[i])) { // If it's not all digits, forget it. line=FXString::null; break; } } }
static void SaveSysIncPaths(FXSettings*reg) { reg->deleteSection(sysincs_sect); int n=SysIncs.contains('\n'); if (n>MAX_SYSINC_PATHS) { n=MAX_SYSINC_PATHS; } for (int i=0; i<n; i++) { const FXString value=SysIncs.section('\n',i); if (!value.empty()) { char key[16]; snprintf(key, sizeof(key)-1 ,"Path_%d", i+1); reg->writeStringEntry(sysincs_sect,key,value.text()); } } }
FXint fxexecute(FXString link) { #ifdef WIN32 FXString quoted = FXPath::enquote(link); FXint ret = (int)ShellExecute(NULL,"open",quoted.text(),NULL,NULL,SW_SHOW) > 32; return ret; #else FXString ext = FXPath::extension(link); FXString list; if (comparecase(link.section(':',0), "http")==0 || comparecase(link.section(':',0), "ftp")==0 || comparecase(ext, "htm")==0 || comparecase(ext, "html")==0 || comparecase(ext, "php")==0 || comparecase(ext, "asp")==0) list = "mozilla-firefox\tmozilla\tnetscape\tkonqueror\tdillo\tlynx"; else if (comparecase(ext, "pdf")==0) list = "acroread\tkghostview\tgpdf\txpdf"; if (list.length()) { FXString software; FXint index=0; FXString path = FXSystem::getExecPath(); software = list.section("\t",index); while (!software.empty()) { software = FXPath::search(path, software); if (software.length()) return system(FXString().format("%s \"%s\" >/dev/null 2>&1 & ", software.text(),link.text()).text())>0?0:1; index++; software = list.section("\t",index); } } else if (FXStat::isExecutable(link)) return system((link + " >/dev/null 2>&1 & ").text()) > 0 ? 0:1; return 0; #endif }
// Look for file in system include directories static bool OpenSystemIncludeFile(SciDoc*sci, const FXString &filename, const FXString &line) { const FXString paths=Settings::SystemIncludePaths(); for (FXint i=0; i<paths.contains('\n'); i++) { FXString fullpath=paths.section('\n',i); if (fullpath.empty()) { continue; } fullpath+=PATHSEPSTRING; fullpath+=filename; if (FXStat::exists(fullpath)) { TopWinPub::OpenFile(fullpath.text(),line.text(),false,true); return true; } } return false; }
// Command menu item FXMenuCommand::FXMenuCommand(FXComposite* p,const FXString& text,FXIcon* ic,FXObject* tgt,FXSelector sel,FXuint opts): FXMenuCaption(p,text,ic,opts){ FXAccelTable *table; FXWindow *own; flags|=FLAG_ENABLED; defaultCursor=getApp()->getDefaultCursor(DEF_RARROW_CURSOR); target=tgt; message=sel; accel=text.section('\t',1); acckey=parseAccel(accel); if(acckey){ own=getShell()->getOwner(); if(own){ table=own->getAccelTable(); if(table){ table->addAccel(acckey,this,FXSEL(SEL_COMMAND,ID_ACCEL)); } } } }
// Check for an already-selected filename static void GetFilenameFromSelection(FXMainWindow*tw,SciDoc*sci, FXString &filename) { #ifdef WIN32 sci->GetSelText(filename); #else // On X11 platforms, try first to get a filename from the X-Selection FXuchar*xsel=NULL; FXuint xlen=0; FXDragType types[] = { tw->textType, tw->utf8Type, tw->stringType, 0 }; for ( FXDragType*type=types; *type; type++ ) { if (tw->getDNDData(FROM_SELECTION,*type, xsel, xlen) && xsel && *xsel) { FXuchar*eol=(FXuchar*)memchr(xsel,'\n', xlen); FXuint n = eol ? (eol-xsel) : xlen; filename.assign((FXchar*)xsel,n); filename=filename.simplify(); if (!FXStat::exists(filename.contains(':')?filename.section(':',0):filename)) { filename=FXString::null; } break; } if ( filename.empty() ) { sci->GetSelText(filename); } } #endif }
// When BuildClassTree() is called, ctags parses all source files in the directory list. // This routine is called by the CmdIO object, once for each line of output from ctags. long TagParserBase::onParseAllSources(FXObject*o, FXSelector sel, void*p) { const FXString* s=(const FXString*)p; if (FXSELTYPE(sel)==SEL_IO_EXCEPT) { return 1; } LocationIndex dirindex=(LocationIndex)((FXuval)((CmdIO*)o)->getUserData()); FXString ancestor=FXString::null; FXString scopename=FXString::null; FXint linenum=ExtractLineNumber(s); FXchar kind=s->section('\t', 3)[0]; FXString tagname=s->section('\t',0); FXString filename=s->section('\t',1); if (current_filename!=filename) { current_filename=filename; dirs[dirindex]->append(filename); } const FXchar ext=Ascii::toLower(FXPath::extension(filename)[0]); if ( (kind=='n') ) { if (ext=='c') { return 1; } // namespaces are only interesting if they are in a public header } for (FXint i=4; i<=s->contains('\t'); i++) { const FXString sect=s->section('\t', i); if (sect.find(':')>0) { const FXString key=sect.section(':',0); if ((kind=='s')&&(key=="access")) { // ignore structs defined inside a class return 1; } else if ((kind=='f')&&((key=="class")||(key=="namespace"))) { scopename=sect.section(':',1,1024); StripNamespace(scopename); } else if (key=="inherits") { ancestor=sect.section(':',1); if (ancestor.find(',')>0) { ancestor=ancestor.section(',',0); // can't do multiple inheritence } StripNamespace(ancestor); } } } switch (kind) { case 'c': case 'n': case 's': { tag_info_list->append(kind, tagname, ancestor, dirindex, dirs[dirindex]->no()-1, linenum); break; } default: { FXString* entry = new FXString(); entry->format( "%c\t%s%s%s\t%d", kind, scopename.text(), scopename.empty()?"":"::", tagname.text(), linenum ); dirs[dirindex]->tail()->append(entry); break; } } return 1; }
// Launch a command and initiate a startup notification int runcmd(FXString cmd, FXString cmdname, FXString dir, FXString startdir, FXbool usesn = true, FXString snexcepts = "") { int ret; // Change to current directory ret = chdir(dir.text()); if (ret < 0) { int errcode = errno; if (errcode) { fprintf(stderr, _("Error: Can't enter folder %s: %s"), dir.text(), strerror(errcode)); } else { fprintf(stderr, _("Error: Can't enter folder %s"), dir.text()); } return(-1); } // Get rid of possible command options cmdname = cmdname.before(' '); // Check if command is in the startup notification exception list FXbool startup_notify = true; if (snexcepts != "") { FXString entry; for (int i = 0; ; i++) { entry = snexcepts.section(':', i); if (streq(entry.text(), "")) { break; } if (streq(entry.text(), cmdname.text())) { startup_notify = false; break; } } } // Run command with startup notification if (usesn && startup_notify) { Display* xdisplay; SnDisplay* display; SnLauncherContext* context; Time timestamp; // Open display xdisplay = XOpenDisplay(NULL); if (xdisplay == NULL) { fprintf(stderr, _("Error: Can't open display\n")); ret = chdir(startdir.text()); if (ret < 0) { int errcode = errno; if (errcode) { fprintf(stderr, _("Error: Can't enter folder %s: %s"), startdir.text(), strerror(errcode)); } else { fprintf(stderr, _("Error: Can't enter folder %s"), startdir.text()); } } return(-1); } // Message displayed in the task bar (if any) FXString message; message.format(_("Start of %s"), cmdname.text()); // Initiate launcher context display = sn_display_new(xdisplay, NULL, NULL); context = sn_launcher_context_new(display, DefaultScreen(xdisplay)); sn_launcher_context_set_name(context, message.text()); sn_launcher_context_set_binary_name(context, cmdname.text()); sn_launcher_context_set_description(context, message.text()); sn_launcher_context_set_icon_name(context, cmdname.text()); timestamp = gettimestamp(); sn_launcher_context_initiate(context, "Xfe", cmd.text(), timestamp); // Run command in background cmd += " &"; static pid_t child_pid = 0; switch ((child_pid = fork())) { case -1: fprintf(stderr, _("Error: Fork failed: %s\n"), strerror(errno)); break; case 0: // Child sn_launcher_context_setup_child_process(context); execl("/bin/sh", "sh", "-c", cmd.text(), (char*)NULL); _exit(EXIT_SUCCESS); break; } sn_launcher_context_unref(context); } // Run command without startup notification else { // Run command in background cmd += " &"; ret = system(cmd.text()); if (ret < 0) { fprintf(stderr, _("Error: Can't execute command %s"), cmd.text()); return(-1); } // Just display the wait cursor during a second sleep(1); } // Go back to startup directory ret = chdir(startdir.text()); if (ret < 0) { int errcode = errno; if (errcode) { fprintf(stderr, _("Error: Can't enter folder %s: %s"), startdir.text(), strerror(errcode)); } else { fprintf(stderr, _("Error: Can't enter folder %s"), startdir.text()); } return(-1); } return(0); }
// Run a command in an internal Xvt terminal // Return 0 if success, -1 else // N.B.: zombie process should be dealt with in the main application class FXint runinxvt(FXString cmd) { FXString str1, str2; FXint nbargs, i, j; // First pass to find the number of commmand arguments nbargs=0; i=0; j=1; while (1) { str1=cmd.section(' ',i); if (str1[0]=='\'') // If a ' is found, ignore the spaces till the next ' { str2=cmd.section('\'',j); j+=2; i+=str2.contains(' '); nbargs++; } else nbargs++; if(streq(str1.text(),"")) break; i++; } nbargs--; // Second pass to allocate the argument strings FXchar** args=(FXchar**)malloc((nbargs + 1)*sizeof(FXchar*)); nbargs=0; i=0; j=1; while (1) { str1=cmd.section(' ',i); if (str1[0]=='\'') { str2=cmd.section('\'',j); j+=2; i+=str2.contains(' '); args[nbargs] = (FXchar *)malloc(str2.length()+1); strlcpy(args[nbargs],str2.text(),str2.length()+1); nbargs++; } else { args[nbargs] = (FXchar *)malloc(str1.length()+1); strlcpy(args[nbargs],str1.text(),str1.length()+1); nbargs++; } if(streq(str1.text(),"")) break; i++; } nbargs--; args[nbargs]=NULL; // Launch the command in an internal Xvt terminal FXint res; static pid_t childpid = 0; childpid = fork(); // Fork succeeded if (childpid >= 0) { // Child process if (childpid == 0) { xvt(nbargs,args); exit(0); } // Parent process else { // Non blocking wait for child waitpid(childpid,NULL,WNOHANG); res=0; } } // Fork failed else { fprintf (stderr,_("Error! Fork failed: %s\n"),strerror (errno)); res=-1; } // Free allocated strings for (FXint i=0; i<nbargs; i++) free(args[i]); free(args); return res; }
PopupListItem(const FXString &text, FXIcon *ic=NULL, void *ptr=NULL):FXListItem() { data=strdup((const char*)ptr); setText(stripHotKey(text.section('\t',0))); }