wxNodeBase::wxNodeBase(wxListBase *list, wxNodeBase *previous, wxNodeBase *next, void *data, const wxListKey& key) { m_list = list; m_data = data; m_previous = previous; m_next = next; switch ( key.GetKeyType() ) { case wxKEY_NONE: break; case wxKEY_INTEGER: m_key.integer = key.GetNumber(); break; case wxKEY_STRING: // to be free()d later m_key.string = wxStrdup(key.GetString()); break; default: wxFAIL_MSG(wxT("invalid key type")); } if ( previous ) previous->m_next = this; if ( next ) next->m_previous = this; }
static void ConvertArgsToUnicode(int argc, char **argv) { gs_initData.argv = new wchar_t *[argc + 1]; int wargc = 0; for ( int i = 0; i < argc; i++ ) { #ifdef __DARWIN__ wxWCharBuffer buf(wxConvFileName->cMB2WX(argv[i])); #else wxWCharBuffer buf(wxConvLocal.cMB2WX(argv[i])); #endif if ( !buf ) { wxLogWarning(_("Command line argument %d couldn't be converted to Unicode and will be ignored."), i); } else // converted ok { gs_initData.argv[wargc++] = wxStrdup(buf); } } gs_initData.argc = wargc; gs_initData.argv[wargc] = NULL; }
EWXWEXPORT(int,FileDataObject_GetFilenames)(void* self,void* _lst) { wxArrayString arr = ((wxFileDataObject*)self)->GetFilenames(); if (_lst) { for (unsigned int i = 0; i < arr.GetCount(); i++) ((const wxChar**)_lst)[i] = wxStrdup (arr.Item(i).wchar_str()); } return arr.GetCount(); }
EWXWEXPORT(int,wxTextValidator_GetIncludeList)(void* self,void* _ref) { #if (wxVERSION_NUMBER <= 2600) if (_ref) { for (unsigned int i = 0; i < ((wxTextValidator*)self)->GetIncludeList().GetCount(); i++) ((const wxChar**)_ref)[i] = wxStrdup(((wxTextValidator*)self)->GetIncludeList().Item(i)->GetData()); } return ((wxTextValidator*)self)->GetIncludeList().GetCount(); #else wxArrayString arr = ((wxTextValidator*)self)->GetIncludes(); if (_ref) { for (unsigned int i = 0; i < arr.GetCount(); i++) ((const wxChar**)_ref)[i] = wxStrdup (arr.Item(i).c_str()); } return arr.GetCount(); #endif }
static void ConvertArgsToUnicode(int argc, char **argv) { gs_initData.argv = new wchar_t *[argc + 1]; for ( int i = 0; i < argc; i++ ) { gs_initData.argv[i] = wxStrdup(wxConvLocal.cMB2WX(argv[i])); } gs_initData.argc = argc; gs_initData.argv[argc] = NULL; }
EWXWEXPORT(int,wxFileType_GetExtensions)(void* self,void* _lst) { wxArrayString arr; if (((wxFileType*)self)->GetExtensions(arr) && _lst) { for (unsigned int i = 0; i < arr.GetCount(); i++) ((const wxChar**)_lst)[i] = wxStrdup (arr.Item(i).wchar_str()); } return arr.GetCount(); }
EWXWEXPORT(int,wxMimeTypesManager_EnumAllFileTypes)(wxMimeTypesManager* self,void* _lst) { wxArrayString arr; int result = (int)self->EnumAllFileTypes(arr); if (_lst) { for (unsigned int i = 0; i < arr.GetCount(); i++) ((const wxChar**)_lst)[i] = wxStrdup (arr.Item(i).wchar_str()); } return result; }
bool wxLocale::DoInit(const wxString& name, const wxString& shortName, const wxString& locale) { wxASSERT_MSG( !m_initialized, wxS("you can't call wxLocale::Init more than once") ); m_initialized = true; m_strLocale = name; m_strShort = shortName; m_language = wxLANGUAGE_UNKNOWN; // change current locale (default: same as long name) wxString szLocale(locale); if ( szLocale.empty() ) { // the argument to setlocale() szLocale = shortName; wxCHECK_MSG( !szLocale.empty(), false, wxS("no locale to set in wxLocale::Init()") ); } const char *oldLocale = wxSetlocale(LC_ALL, szLocale); if ( oldLocale ) m_pszOldLocale = wxStrdup(oldLocale); else m_pszOldLocale = NULL; if ( m_pszOldLocale == NULL ) { wxLogError(_("locale '%s' cannot be set."), szLocale); } // the short name will be used to look for catalog files as well, // so we need something here if ( m_strShort.empty() ) { // FIXME I don't know how these 2 letter abbreviations are formed, // this wild guess is surely wrong if ( !szLocale.empty() ) { m_strShort += (wxChar)wxTolower(szLocale[0]); if ( szLocale.length() > 1 ) m_strShort += (wxChar)wxTolower(szLocale[1]); } } return true; }
int main(int argc, char* argv[]) { if (argc < 2) { wxFprintf(stderr, _T("Usage : ExpandXar <input file> <output file>\n")); return 1; } #if wxUSE_UNICODE wxChar **wxArgv = new wxChar *[argc + 1]; { int n; for (n = 0; n < argc; n++ ) { wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); wxArgv[n] = wxStrdup(warg); } wxArgv[n] = NULL; } #else // !wxUSE_UNICODE #define wxArgv argv #endif // wxUSE_UNICODE/!wxUSE_UNICODE int RetVal = 0; if (!ProcessFile(wxArgv[1], wxArgv[2])) { RetVal = 1; } #if wxUSE_UNICODE { for ( int n = 0; n < argc; n++ ) free(wxArgv[n]); delete [] wxArgv; } #endif // wxUSE_UNICODE wxUnusedVar(argc); wxUnusedVar(argv); return RetVal; }
EWXWEXPORT(void*,wxTextValidator_GetExcludes)(void* self,int* _nitems) { void* retval = NULL; if (_nitems != NULL) { wxArrayString items = ((wxTextValidator*)self)->GetExcludes(); wxChar **items_copy = (wxChar **)malloc(sizeof(wxChar *)* items.GetCount()); for (unsigned int i = 0; i < items.GetCount(); i++) { items_copy[i] = wxStrdup(items.Item(i).wchar_str()); } retval = (void*)items_copy; *_nitems = items.GetCount(); } return retval; }
int wxEntry() { /* There is no command line in PalmOS. For now generate a fake arument * list. Later this may be changed to reflect the application launch code */ wxArrayString args; int argc = args.GetCount(); // +1 here for the terminating NULL wxChar **argv = new wxChar *[argc + 1]; for ( int i = 0; i < argc; i++ ) { argv[i] = wxStrdup(args[i]); } // argv[] must be NULL-terminated argv[argc] = NULL; return wxEntry(argc, argv); }
void Client::StartWorker(workMode pMode, const wxString& pMessage) { char* tmpbuf = wxStrdup(pMessage.mb_str()); int msgsize = strlen(tmpbuf); char* buf = CreateBuffer(&msgsize); memset(buf+2,0x0,msgsize); memcpy(buf+2,tmpbuf,msgsize); free(tmpbuf); if (pMode == THREADS) { ThreadWorker* c = new ThreadWorker(m_host,buf,msgsize+2); if (c->Create() != wxTHREAD_NO_ERROR) { wxLogError(wxT("Cannot create more threads")); } else { c->Run(); m_threadWorkers.Append(c); } } else { EventWorker* e = new EventWorker(m_host,buf,msgsize+2); e->Run(); m_eventWorkers.Append(e); } m_statConnecting++; }
int main(int argc, char **argv) { #if wxUSE_UNICODE wxChar **wxArgv = new wxChar *[argc + 1]; { int n; for (n = 0; n < argc; n++ ) { wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); wxArgv[n] = wxStrdup(warg); } wxArgv[n] = NULL; } #else // !wxUSE_UNICODE #define wxArgv argv #endif // wxUSE_UNICODE/!wxUSE_UNICODE wxInitializer initializer; if ( !initializer ) { fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.\n"); return -1; } wxString src; if (argc != 2) { fprintf(stderr, "version.h path not specified, aborting.\n"); return -1; } wxTextFile f(wxArgv[1]); wxString cur; if (!f.Open(wxConvLibc)) { fprintf(stderr, "Failed to open version.h \"%S\", aborting.\n", wxArgv[1]); return -1; } unsigned long verl[4] = { 0 }; for (cur = f.GetFirstLine(); !f.Eof(); cur = f.GetNextLine()) { fprintf(stdout, "processing \"%S\"\n", cur.c_str()); wxStringTokenizer tkz(cur, L"\t "); wxString ver; while (tkz.HasMoreTokens()) { if (tkz.GetNextToken() == L"PRODUCTVER") { fprintf(stdout, " PRODUCTVER spotted\n"); if (tkz.HasMoreTokens()) { ver = tkz.GetNextToken(); fprintf(stdout, " is %S\n", ver.c_str()); // parse ver // wxStringTokenizer tkzv(ver, L", "); if (tkzv.HasMoreTokens()) tkzv.GetNextToken().ToULong(&verl[0]); if (tkzv.HasMoreTokens()) tkzv.GetNextToken().ToULong(&verl[1]); if (tkzv.HasMoreTokens()) tkzv.GetNextToken().ToULong(&verl[2]); if (tkzv.HasMoreTokens()) tkzv.GetNextToken().ToULong(&verl[3]); fprintf(stdout, " deciphered: %d.%d.%d.%d\n", verl[0], verl[1], verl[2], verl[3]); } } } } if (verl[0] == 0 && verl[1] == 0 && verl[2] == 0 && verl[3] == 0) { ; } else { verl[3]++; f.Clear(); f.AddLine(L"#ifndef __VERSION_H__"); f.AddLine(L"#define __VERSION_H__"); f.AddLine(wxString::Format(L"#define FILEVER %d,%d,%d,%d", verl[0], verl[1], verl[2], verl[3])); f.AddLine(wxString::Format(L"#define PRODUCTVER %d,%d,%d,%d", verl[0], verl[1], verl[2], verl[3])); f.AddLine(wxString::Format(L"#define STRFILEVER \"%d, %d, %d, %d\\0\"", verl[0], verl[1], verl[2], verl[3])); f.AddLine(wxString::Format(L"#define STRPRODUCTVER \"%d, %d, %d, %d\\0\"", verl[0], verl[1], verl[2], verl[3])); f.AddLine(L"#endif"); f.Write(wxTextFileType_None, wxConvLibc); } }
// Find an existing, or create a new, XFontStruct // based on this wxFont and the given scale. Append the // font to list in the private data for future reference. wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const { if ( !Ok() ) return NULL; long intScale = long(scale * 100.0 + 0.5); // key for wxXFont int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100; // search existing fonts first wxList::compatibility_iterator node = M_FONTDATA->m_fonts.GetFirst(); while (node) { wxXFont* f = (wxXFont*) node->GetData(); if ((!display || (f->m_display == display)) && (f->m_scale == intScale)) return f; node = node->GetNext(); } // not found, create a new one wxString xFontSpec; XFontStruct *font = (XFontStruct *) wxLoadQueryNearestFont(pointSize, M_FONTDATA->m_family, M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined, wxT(""), M_FONTDATA->m_encoding, &xFontSpec); if ( !font ) { wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") ); return NULL; } wxXFont* f = new wxXFont; #if wxMOTIF_NEW_FONT_HANDLING XFreeFont( (Display*) display, font ); #else f->m_fontStruct = (WXFontStructPtr)font; #endif f->m_display = ( display ? display : wxGetDisplay() ); f->m_scale = intScale; #if wxMOTIF_USE_RENDER_TABLE XmRendition rendition; XmRenderTable renderTable; Arg args[5]; int count = 0; #if wxMOTIF_NEW_FONT_HANDLING char* fontSpec = wxStrdup(xFontSpec.mb_str()); XtSetArg( args[count], XmNfontName, fontSpec ); ++count; XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count; #else XtSetArg( args[count], XmNfont, font ); ++count; #endif XtSetArg( args[count], XmNunderlineType, GetUnderlined() ? XmSINGLE_LINE : XmNO_LINE ); ++count; rendition = XmRenditionCreate( XmGetXmDisplay( (Display*)f->m_display ), (XmStringTag)"", args, count ); renderTable = XmRenderTableAddRenditions( NULL, &rendition, 1, XmMERGE_REPLACE ); f->m_renderTable = (WXRenderTable)renderTable; f->m_rendition = (WXRendition)rendition; wxASSERT( f->m_renderTable != NULL ); #else // if !wxMOTIF_USE_RENDER_TABLE f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET); wxASSERT( f->m_fontList != NULL ); #endif M_FONTDATA->m_fonts.Append(f); return f; }
int main(int argc, char* argv[]) { #if wxUSE_UNICODE // Set to the user's default locale for these conversions char* pOldLoc = setlocale(LC_CTYPE, ""); wxChar **wxArgv = new wxChar *[argc + 1]; { int n; for (n = 0; n < argc; n++ ) { wxMB2WXbuf warg = wxConvertMB2WX(argv[n]); wxArgv[n] = wxStrdup(warg); } wxArgv[n] = NULL; } // Set back to the old locale (should we be doing this?) setlocale(LC_CTYPE, pOldLoc); #else // !wxUSE_UNICODE #define wxArgv argv #endif // wxUSE_UNICODE/!wxUSE_UNICODE wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); wxInitializer initializer; if ( !initializer ) { fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.\n"); return -1; } // Default to OK exit value int RetVal = 0; static const wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") }, { wxCMD_LINE_SWITCH, _T("g"), _T("progress"), _T("give progress") }, { wxCMD_LINE_SWITCH, _T("p"), _T("prepareexport"), _T("prepare export") }, { wxCMD_LINE_SWITCH, _T("e"), _T("export"), _T("do export") }, { wxCMD_LINE_SWITCH, _T("c"), _T("canimport"), _T("can import") }, { wxCMD_LINE_SWITCH, _T("i"), _T("import"), _T("do import") }, { wxCMD_LINE_SWITCH, _T("z"), _T("compress"), _T("(de)compress (output) input file") }, { wxCMD_LINE_OPTION, _T("f"), _T("file"), _T("input/output file") }, { wxCMD_LINE_OPTION, _T("x"), _T("xmlfile"), _T("xml configuration file") }, #if SVGDEBUG { wxCMD_LINE_OPTION, _T("T"), _T("tracelevel"), _T("enable debug") }, #endif { wxCMD_LINE_NONE } }; wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); switch ( parser.Parse() ) { case -1: wxLogMessage(_T("Help was given, terminating.")); break; case 0: // ShowCmdLine(parser); if (Run(parser)) RetVal = 0; else RetVal = 1; break; default: RetVal = 1; break; } #if wxUSE_UNICODE { for ( int n = 0; n < argc; n++ ) free(wxArgv[n]); delete [] wxArgv; } #endif // wxUSE_UNICODE wxUnusedVar(argc); wxUnusedVar(argv); // May need to use exit(RetVal) here if the OS ignores the return value from main return RetVal; }