wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) { m_refData = new wxAccelRefData; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( int i = 0; i < n; i++ ) { const wxAcceleratorEntry& entry = entries[i]; int keycode = entry.GetKeyCode(); if ( wxIsascii(keycode) ) keycode = wxToupper(keycode); M_ACCELDATA->m_accels.Append(new wxAcceleratorEntry(entry.GetFlags(), keycode, entry.GetCommand())); } }
void LoadTerrain() { wxBusyInfo busy (_("Loading terrain groups")); DeleteAllPages(); m_TerrainGroups.Clear(); // Get the list of terrain groups from the engine AtlasMessage::qGetTerrainGroups qry; qry.Post(); std::vector<std::wstring> groupnames = *qry.groupNames; for (std::vector<std::wstring>::iterator it = groupnames.begin(); it != groupnames.end(); ++it) m_TerrainGroups.Add(it->c_str()); for (size_t i = 0; i < m_TerrainGroups.GetCount(); ++i) { wxString visibleName = m_TerrainGroups[i]; // Format name slightly if (visibleName.Len()) visibleName[0] = wxToupper(visibleName[0]); visibleName.Replace(_T("_"), _T(" ")); AddPage(new TextureNotebookPage(m_ScenarioEditor, this, m_TerrainGroups[i]), visibleName); } // On some platforms (wxOSX) there is no initial OnPageChanged event, so it loads with a blank page // and setting selection to 0 won't trigger it either, so just force first page to display // (this is safe because the sidebar has already been displayed) if (GetPageCount() > 0) { static_cast<TextureNotebookPage*>(GetPage(0))->OnDisplay(); } }
FastFormatUnicode &FastFormatUnicode::ToUpper() { wxChar *ch = (wxChar *)m_dest.GetPtr(); for (uint i = 0; i < m_Length; ++i, ++ch) *ch = (wxChar)wxToupper(*ch); return *this; }
// Add spaces into the displayed name so there are more wrapping opportunities static wxString FormatTextureName(wxString name) { if (name.Len()) name[0] = wxToupper(name[0]); name.Replace(_T("_"), _T(" ")); return name; }
wxChar tmKey::CharToUpper(wxChar c) { // static #ifdef __WXMSW__ const LONG inChar = MAKELONG(c, 0); const LONG outChar = (LONG)::CharUpper((LPTSTR)inChar); return (wxChar)LOWORD(outChar); #else return wxToupper(c); #endif // __WXMSW__ }
int wxGpiStrcmp( wxChar* s0 , wxChar* s1 ) { int l0; int l1; int l; int d; int d1; int i; int rc; rc = 0; if(s0 == NULL) { if(s1 == NULL) return 0; else return 32; } else if(s1 == NULL) return 32; l0 = wxStrlen(s0); l1 = wxStrlen(s1); l = l0; if(l0 != l1) { rc++; if(l1 < l0) l = l1; } for(i=0;i<l;i++) { d = s0[i]-s1[i]; if(!d) continue; d1 = wxToupper(s0[i]) - wxToupper(s1[i]); if(!d1) continue; rc += abs(d); } return rc; }
wxChar wxFieldMaskData::PreProcessChar(wxChar chNewChar) { wxChar chProcessedChar=chNewChar; switch(m_eType) { case MaskDataTypeALPHAETICUPPER: chProcessedChar=(wxChar) wxToupper(chNewChar); break; case MaskDataTypeALPHAETICLOWER: chProcessedChar=(wxChar) wxTolower(chNewChar); break; } return chProcessedChar; }
wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) { m_refData = new wxAccelRefData; for ( int i = 0; i < n; i++ ) { const wxAcceleratorEntry& entry = entries[i]; int keycode = entry.GetKeyCode(); if ( wxIsascii(keycode) ) keycode = wxToupper(keycode); M_ACCELDATA->m_accels.Append(new wxAcceleratorEntry(entry.GetFlags(), keycode, entry.GetCommand())); } }
/** * For constant time access, each keystroke is mapped to an int. * The first 8 bits are used to store the modifiers. * The remaining 24 bits are used to store the actual wxKeyCode of the key to press. */ int makeHash(wxString& accel) { wxAcceleratorEntry entry; entry.FromString(wxT("\t")+accel); int code = entry.GetKeyCode(); int flags = entry.GetFlags(); #ifdef __WXMSW__ // ParseAccel does not support windows key if(accel.Lower().Contains(wxT("win"))) flags |= 0x0008; #endif //Win is not recognized as a modifier, so wxwidgets will not auto-capitalize the key codes for us code = wxToupper(code); wxLogDebug(wxT("Hash for %s: %d %d %d"), accel, ((flags << 24) | code), flags, code); return (flags << 24) | code; }
void SymbolList::ActionList::Find(const wxString& searchtext, bool refresh) { m_searchText = searchtext; // cache for later updates if (searchtext.empty()) { SetAllItems(); return; } // Convert to upper case for case insensitive search const wxString text = searchtext.Upper(); m_items.clear(); vector<unsigned int> hlChars; for (unsigned int i = 0; i < m_actions.GetCount(); ++i) { const wxString& name = m_actions[i]; unsigned int charpos = 0; wxChar c = text[charpos]; hlChars.clear(); for (unsigned int textpos = 0; textpos < name.size(); ++textpos) { if ((wxChar)wxToupper(name[textpos]) == c) { hlChars.push_back(textpos); ++charpos; if (charpos == text.size()) { // All chars found. m_items.push_back(aItem(i, &m_actions[i], hlChars)); break; } else c = text[charpos]; } } } sort(m_items.begin(), m_items.end()); Freeze(); SetItemCount(m_items.size()); if (refresh) { if (m_items.empty()) SetSelection(-1); // deselect else SetSelection(0); RefreshAll(); } Thaw(); }
bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) { if (path.empty()) return false; wxFileName fn(path); FSALLOCATE fsaBuf = {0}; APIRET rc = NO_ERROR; ULONG disknum = 0; fn.MakeAbsolute(); if (wxDirExists(fn.GetFullPath()) == false) return false; disknum = wxToupper(fn.GetVolume().GetChar(0)) - _T('A') + 1; rc = ::DosQueryFSInfo(disknum, // 1 = A, 2 = B, 3 = C, ... FSIL_ALLOC, // allocation info (PVOID)&fsaBuf, sizeof(FSALLOCATE)); if (rc != NO_ERROR) return false; else { if(pTotal) { // to try to avoid 32-bit overflow, let's not multiply right away // (num of alloc units) *pTotal = fsaBuf.cUnit; // * (num of sectors per alloc unit) * (num of bytes per sector) (*pTotal) *= fsaBuf.cSectorUnit * fsaBuf.cbSector; } if(pFree) { *pFree = fsaBuf.cUnitAvail; (*pFree) *= fsaBuf.cSectorUnit * fsaBuf.cbSector; } return true; } }
void LoadTerrain() { wxBusyInfo busy (_("Loading terrain groups")); DeleteAllPages(); m_TerrainGroups.Clear(); // Get the list of terrain groups from the engine AtlasMessage::qGetTerrainGroups qry; qry.Post(); std::vector<std::wstring> groupnames = *qry.groupNames; for (std::vector<std::wstring>::iterator it = groupnames.begin(); it != groupnames.end(); ++it) m_TerrainGroups.Add(it->c_str()); for (size_t i = 0; i < m_TerrainGroups.GetCount(); ++i) { wxString visibleName = m_TerrainGroups[i]; if (visibleName.Len()) visibleName[0] = wxToupper(visibleName[0]); AddPage(new TextureNotebookPage(m_ScenarioEditor, this, m_TerrainGroups[i]), visibleName); } }
// // This code assumes that we've already checked for special cases // involving a cygdrive prefix of '/' and a path that isn't a drive path. // // The given path is assumed to already start with cygdrive prefix // wxString eDocumentPath::convert_cygdrive_path_to_windows(const wxString& path) { const size_t n = eDocumentPath::s_cygdrivePrefix.Len(); // Cygdrive prefix length // Get drive letter const wxChar drive = wxToupper(path[n] + 1); if (drive < wxT('A') || wxT('Z') < drive) { // Invalid drive letter; can't do anything with this. wxASSERT(false); return wxEmptyString; } wxString newpath; newpath += drive; newpath += wxT(':'); // Add stuff after the cygdrive+drive letter to the new path, else just add a slash. if (path.size() > n+2) newpath += path.substr(n+2); else newpath += wxT('\\'); newpath.Replace(wxT("/"), wxT("\\")); return newpath; }
wxString CygwinPathToWin(const wxString& path) { // static if (path.empty()) { wxASSERT(false); return wxEmptyString; } wxString newpath; if (path.StartsWith(wxT("/cygdrive/"))) { // Get drive letter const wxChar drive = wxToupper(path[10]); if (drive < wxT('A') || drive > wxT('Z')) { wxASSERT(false); return wxEmptyString; } // Build new path newpath += drive; newpath += wxT(':'); if (path.size() > 11) newpath += path.substr(11); else newpath += wxT('\\'); } else if (path.StartsWith(wxT("/usr/bin/"))) { newpath = GetCygwinDir() + wxT("\\bin\\"); newpath += path.substr(9); } else if (path.GetChar(0) == wxT('/')) { newpath = GetCygwinDir(); newpath += path; } else return path; // no conversion // Convert path seperators for (unsigned int i = 0; i < newpath.size(); ++i) { if (newpath[i] == wxT('/')) newpath[i] = wxT('\\'); } return newpath; }
wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source) { m_Cache = new wxHtmlTagsCacheData; m_CachePos = 0; wxChar tagBuffer[256]; const wxString::const_iterator end = source.end(); for ( wxString::const_iterator pos = source.begin(); pos < end; ++pos ) { if (*pos != wxT('<')) continue; // possible tag start found: // don't cache comment tags if ( wxHtmlParser::SkipCommentTag(pos, end) ) continue; // Remember the starting tag position. wxString::const_iterator stpos = pos++; // And look for the ending one. int i; for ( i = 0; pos < end && i < (int)WXSIZEOF(tagBuffer) - 1 && *pos != wxT('>') && !wxIsspace(*pos); ++i, ++pos ) { tagBuffer[i] = (wxChar)wxToupper(*pos); } tagBuffer[i] = wxT('\0'); while (pos < end && *pos != wxT('>')) ++pos; if ( pos == end ) { // We didn't find a closing bracket, this is not a valid tag after // all. Notice that we need to roll back pos to avoid creating an // invalid iterator when "++pos" is done in the loop statement. --pos; continue; } // We have a valid tag, add it to the cache. size_t tg = Cache().size(); Cache().push_back(wxHtmlCacheItem()); Cache()[tg].Key = stpos; Cache()[tg].Name = new wxChar[i+1]; memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar)); if ((stpos+1) < end && *(stpos+1) == wxT('/')) // ending tag: { Cache()[tg].type = wxHtmlCacheItem::Type_EndingTag; // find matching begin tag: for (i = tg; i >= 0; i--) { if ((Cache()[i].type == wxHtmlCacheItem::Type_NoMatchingEndingTag) && (wxStrcmp(Cache()[i].Name, tagBuffer+1) == 0)) { Cache()[i].type = wxHtmlCacheItem::Type_Normal; Cache()[i].End1 = stpos; Cache()[i].End2 = pos + 1; break; } } } else { Cache()[tg].type = wxHtmlCacheItem::Type_NoMatchingEndingTag; if (wxIsCDATAElement(tagBuffer)) { // store the orig pos in case we are missing the closing // tag (see below) const wxString::const_iterator old_pos = pos; bool foundCloseTag = false; // find next matching tag int tag_len = wxStrlen(tagBuffer); while (pos < end) { // find the ending tag while (pos + 1 < end && (*pos != '<' || *(pos+1) != '/')) ++pos; if (*pos == '<') ++pos; // see if it matches int match_pos = 0; while (pos < end && match_pos < tag_len ) { wxChar c = *pos; if ( c == '>' || c == '<' ) break; // cast to wxChar needed to suppress warning in // Unicode build if ((wxChar)wxToupper(c) == tagBuffer[match_pos]) { ++match_pos; } else if (c == wxT(' ') || c == wxT('\n') || c == wxT('\r') || c == wxT('\t')) { // need to skip over these } else { match_pos = 0; } ++pos; } // found a match if (match_pos == tag_len) { pos = pos - tag_len - 3; foundCloseTag = true; break; } else // keep looking for the closing tag { ++pos; } } if (!foundCloseTag) { // we didn't find closing tag; this means the markup // is incorrect and the best thing we can do is to // ignore the unclosed tag and continue parsing as if // it didn't exist: pos = old_pos; } } } } // ok, we're done, now we'll free .Name members of cache - we don't need it anymore: for ( wxHtmlTagsCacheData::iterator i = Cache().begin(); i != Cache().end(); ++i ) { wxDELETEA(i->Name); } }
// This method handles common code for SendKeyDown, SendKeyUp, and SendChar events. void wxApp::MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , wxChar uniChar ) { #if wxOSX_USE_COCOA_OR_CARBON short keycode, keychar ; keychar = short(keymessage & charCodeMask); keycode = short(keymessage & keyCodeMask) >> 8 ; if ( !(event.GetEventType() == wxEVT_CHAR) && (modifiers & (controlKey | shiftKey | optionKey) ) ) { // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier // and look at the character after #ifdef __LP64__ // TODO new implementation using TextInputSources #else UInt32 state = 0; UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey | shiftKey | optionKey))) | keycode, &state); keychar = short(keyInfo & charCodeMask); #endif } long keyval = wxMacTranslateKey(keychar, keycode) ; if ( keyval == keychar && ( event.GetEventType() == wxEVT_KEY_UP || event.GetEventType() == wxEVT_KEY_DOWN ) ) keyval = wxToupper( keyval ) ; // Check for NUMPAD keys. For KEY_UP/DOWN events we need to use the // WXK_NUMPAD constants, but for the CHAR event we want to use the // standard ascii values if ( event.GetEventType() != wxEVT_CHAR ) { if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92) { keyval = (keyval - '0') + WXK_NUMPAD0; } else if (keycode >= 65 && keycode <= 81) { switch (keycode) { case 76 : keyval = WXK_NUMPAD_ENTER; break; case 81: keyval = WXK_NUMPAD_EQUAL; break; case 67: keyval = WXK_NUMPAD_MULTIPLY; break; case 75: keyval = WXK_NUMPAD_DIVIDE; break; case 78: keyval = WXK_NUMPAD_SUBTRACT; break; case 69: keyval = WXK_NUMPAD_ADD; break; case 65: keyval = WXK_NUMPAD_DECIMAL; break; default: break; } } } event.m_shiftDown = modifiers & shiftKey; event.m_rawControlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_controlDown = modifiers & cmdKey; event.m_keyCode = keyval ; #if wxUSE_UNICODE event.m_uniChar = uniChar ; #endif event.m_rawCode = keymessage; event.m_rawFlags = modifiers; event.SetTimestamp(when); event.SetEventObject(focus); #else wxUnusedVar(event); wxUnusedVar(focus); wxUnusedVar(keymessage); wxUnusedVar(modifiers); wxUnusedVar(when); wxUnusedVar(uniChar); #endif }
void wxFontRefData::InitFromNative() { #if wxUSE_UNICODE // Get native info PangoFontDescription *desc = m_nativeFontInfo.description; // init fields m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE; switch (pango_font_description_get_style( desc )) { case PANGO_STYLE_NORMAL: m_style = wxFONTSTYLE_NORMAL; break; case PANGO_STYLE_ITALIC: m_style = wxFONTSTYLE_ITALIC; break; case PANGO_STYLE_OBLIQUE: m_style = wxFONTSTYLE_SLANT; break; } // Not defined in some Pango versions #define wxPANGO_WEIGHT_SEMIBOLD 600 switch (pango_font_description_get_weight( desc )) { case PANGO_WEIGHT_ULTRALIGHT: case PANGO_WEIGHT_LIGHT: m_weight = wxFONTWEIGHT_LIGHT; break; default: wxFAIL_MSG(wxT("unknown Pango font weight")); // fall through case PANGO_WEIGHT_NORMAL: m_weight = wxFONTWEIGHT_NORMAL; break; case wxPANGO_WEIGHT_SEMIBOLD: case PANGO_WEIGHT_BOLD: case PANGO_WEIGHT_ULTRABOLD: case PANGO_WEIGHT_HEAVY: m_weight = wxFONTWEIGHT_BOLD; break; } if (m_faceName == wxT("monospace")) { m_family = wxFONTFAMILY_TELETYPE; } else if (m_faceName == wxT("sans")) { m_family = wxFONTFAMILY_SWISS; } else { m_family = wxFONTFAMILY_UNKNOWN; } // Pango description are never underlined (?) m_underlined = false; // Cannot we choose that m_encoding = wxFONTENCODING_SYSTEM; #else // X11 // get the font parameters from the XLFD // ------------------------------------- m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY); m_weight = wxFONTWEIGHT_NORMAL; wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper(); if ( !w.empty() && w != wxT('*') ) { // the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD // and BLACK if ( ((w[0u] == wxT('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) || !wxStrcmp(w.c_str() + 1, wxT("LACK"))))) || wxStrstr(w.c_str() + 1, wxT("BOLD")) ) { m_weight = wxFONTWEIGHT_BOLD; } else if ( w == wxT("LIGHT") || w == wxT("THIN") ) { m_weight = wxFONTWEIGHT_LIGHT; } } switch ( wxToupper( m_nativeFontInfo. GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case wxT('I'): // italique m_style = wxFONTSTYLE_ITALIC; break; case wxT('O'): // oblique m_style = wxFONTSTYLE_SLANT; break; default: m_style = wxFONTSTYLE_NORMAL; } long ptSize; if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) ) { // size in XLFD is in 10 point units m_pointSize = (int)(ptSize / 10); } else { m_pointSize = wxDEFAULT_FONT_SIZE; } // examine the spacing: if the font is monospaced, assume wxTELETYPE // family for compatibility with the old code which used it instead of // IsFixedWidth() if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == wxT('M') ) { m_family = wxFONTFAMILY_TELETYPE; } else // not monospaceed { // don't even try guessing it, it doesn't work for too many fonts // anyhow m_family = wxFONTFAMILY_UNKNOWN; } // X fonts are never underlined... m_underlined = false; // deal with font encoding wxString registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(), encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper(); if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } else if ( registry == wxT("KOI8") ) { m_encoding = wxFONTENCODING_KOI8; } else // unknown encoding { // may be give a warning here? or use wxFontMapper? m_encoding = wxFONTENCODING_SYSTEM; } #endif // Pango/X11 }
wx28HtmlTagsCache::wx28HtmlTagsCache(const wxString& source) { const wxChar *src = source.c_str(); int lng = source.length(); wxChar tagBuffer[256]; m_Cache = NULL; m_CacheSize = 0; m_CachePos = 0; int pos = 0; while (pos < lng) { if (src[pos] == wxT('<')) // tag found: { if (m_CacheSize % CACHE_INCREMENT == 0) m_Cache = (wx28HtmlCacheItem*) realloc(m_Cache, (m_CacheSize + CACHE_INCREMENT) * sizeof(wx28HtmlCacheItem)); int tg = m_CacheSize++; int stpos = pos++; m_Cache[tg].Key = stpos; int i; for ( i = 0; pos < lng && i < (int)WXSIZEOF(tagBuffer) - 1 && src[pos] != wxT('>') && !wxIsspace(src[pos]); i++, pos++ ) { tagBuffer[i] = (wxChar)wxToupper(src[pos]); } tagBuffer[i] = wxT('\0'); m_Cache[tg].Name = new wxChar[i+1]; memcpy(m_Cache[tg].Name, tagBuffer, (i+1)*sizeof(wxChar)); while (pos < lng && src[pos] != wxT('>')) pos++; if (src[stpos+1] == wxT('/')) // ending tag: { m_Cache[tg].End1 = m_Cache[tg].End2 = -2; // find matching begin tag: for (i = tg; i >= 0; i--) if ((m_Cache[i].End1 == -1) && (wxStrcmp(m_Cache[i].Name, tagBuffer+1) == 0)) { m_Cache[i].End1 = stpos; m_Cache[i].End2 = pos + 1; break; } } else { m_Cache[tg].End1 = m_Cache[tg].End2 = -1; if (wxIsCDATAElement(tagBuffer)) { // store the orig pos in case we are missing the closing // tag (see below) wxInt32 old_pos = pos; bool foundCloseTag = false; // find next matching tag int tag_len = wxStrlen(tagBuffer); while (pos < lng) { // find the ending tag while (pos + 1 < lng && (src[pos] != '<' || src[pos+1] != '/')) ++pos; if (src[pos] == '<') ++pos; // see if it matches int match_pos = 0; while (pos < lng && match_pos < tag_len && src[pos] != '>' && src[pos] != '<') { // cast to wxChar needed to suppress warning in // Unicode build if ((wxChar)wxToupper(src[pos]) == tagBuffer[match_pos]) { ++match_pos; } else if (src[pos] == wxT(' ') || src[pos] == wxT('\n') || src[pos] == wxT('\r') || src[pos] == wxT('\t')) { // need to skip over these } else { match_pos = 0; } ++pos; } // found a match if (match_pos == tag_len) { pos = pos - tag_len - 3; foundCloseTag = true; break; } else // keep looking for the closing tag { ++pos; } } if (!foundCloseTag) { // we didn't find closing tag; this means the markup // is incorrect and the best thing we can do is to // ignore the unclosed tag and continue parsing as if // it didn't exist: pos = old_pos; } } } } pos++; } // ok, we're done, now we'll free .Name members of cache - we don't need it anymore: for (int i = 0; i < m_CacheSize; i++) { delete[] m_Cache[i].Name; m_Cache[i].Name = NULL; } }
void ReloadPreviews() { Freeze(); m_ScrolledPanel->DestroyChildren(); m_ItemSizer->Clear(); m_LastTerrainSelection = NULL; // clear any reference to deleted button AtlasMessage::qGetTerrainGroupPreviews qry((std::wstring)m_Name.wc_str(), imageWidth, imageHeight); qry.Post(); std::vector<AtlasMessage::sTerrainGroupPreview> previews = *qry.previews; bool allLoaded = true; for (size_t i = 0; i < previews.size(); ++i) { if (!previews[i].loaded) allLoaded = false; // Construct the wrapped-text label wxString name = previews[i].name.c_str(); // Add spaces into the displayed name so there are more wrapping opportunities wxString labelText = name; if (labelText.Len()) labelText[0] = wxToupper(labelText[0]); labelText.Replace(_T("_"), _T(" ")); wxStaticText* label = new wxStaticText(m_ScrolledPanel, wxID_ANY, labelText, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); label->Wrap(imageWidth); unsigned char* buf = (unsigned char*)(malloc(previews[i].imageData.GetSize())); // imagedata.GetBuffer() gives a Shareable<unsigned char>*, which // is stored the same as a unsigned char*, so we can just copy it. memcpy(buf, previews[i].imageData.GetBuffer(), previews[i].imageData.GetSize()); wxImage img (imageWidth, imageHeight, buf); wxButton* button = new wxBitmapButton(m_ScrolledPanel, wxID_ANY, wxBitmap(img)); // Store the texture name in the clientdata slot button->SetClientObject(new wxStringClientData(name)); wxSizer* imageSizer = new wxBoxSizer(wxVERTICAL); imageSizer->Add(button, wxSizerFlags().Center()); imageSizer->Add(label, wxSizerFlags().Proportion(1).Center()); m_ItemSizer->Add(imageSizer, wxSizerFlags().Expand().Center()); } m_ScrolledPanel->Fit(); Layout(); Thaw(); // If not all textures were loaded yet, run a timer to reload the previews // every so often until they've all finished if (allLoaded && m_Timer.IsRunning()) { m_Timer.Stop(); } else if (!allLoaded && !m_Timer.IsRunning()) { m_Timer.Start(2000); } }
Tcl_UniChar Tcl_UniCharToUpper(int ch) { return wxToupper(ch); }
Tcl_UniChar Tcl_UniCharToTitle(int ch) { return wxToupper(ch); }
/** Compare two characaters either case sensitively or not. */ static inline bool IsSame(wxChar ch1, wxChar ch2, CaseSensitivity cs) { return cs == Case_Ignore ? wxToupper(ch1) == wxToupper(ch2) : ch1 == ch2; }
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { if ( !focus ) return false ; short keycode ; short keychar ; keychar = short(keymessage & charCodeMask); keycode = short(keymessage & keyCodeMask) >> 8 ; if ( modifiers & ( controlKey|shiftKey|optionKey ) ) { // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier // and look at the character after UInt32 state = 0; UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); keychar = short(keyInfo & charCodeMask); } long keyval = wxMacTranslateKey(keychar, keycode) ; long realkeyval = keyval ; if ( keyval == keychar ) { // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first) realkeyval = short(keymessage & charCodeMask) ; keyval = wxToupper( keyval ) ; } // Check for NUMPAD keys if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92) { keyval = keyval - '0' + WXK_NUMPAD0; } else if (keycode >= 67 && keycode <= 81) { switch (keycode) { case 76 : keyval = WXK_NUMPAD_ENTER; break; case 81: keyval = WXK_NUMPAD_EQUAL; break; case 67: keyval = WXK_NUMPAD_MULTIPLY; break; case 75: keyval = WXK_NUMPAD_DIVIDE; break; case 78: keyval = WXK_NUMPAD_SUBTRACT; break; case 69: keyval = WXK_NUMPAD_ADD; break; case 65: keyval = WXK_NUMPAD_DECIMAL; break; } // end switch } wxKeyEvent event(wxEVT_KEY_DOWN); bool handled = false ; event.m_shiftDown = modifiers & shiftKey; event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; event.m_keyCode = keyval ; #if wxUSE_UNICODE event.m_uniChar = uniChar ; #endif event.m_rawCode = keymessage; event.m_rawFlags = modifiers; event.m_x = wherex; event.m_y = wherey; event.SetTimestamp(when); event.SetEventObject(focus); handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( handled && event.GetSkipped() ) handled = false ; if ( !handled ) { #if wxUSE_ACCEL if (!handled) { wxWindow *ancestor = focus; while (ancestor) { int command = ancestor->GetAcceleratorTable()->GetCommand( event ); if (command != -1) { wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); break; } if (ancestor->IsTopLevel()) break; ancestor = ancestor->GetParent(); } } #endif // wxUSE_ACCEL } if (!handled) { wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ; if (tlw) { event.Skip( FALSE ) ; event.SetEventType( wxEVT_CHAR_HOOK ); // raw value again event.m_keyCode = realkeyval ; handled = tlw->GetEventHandler()->ProcessEvent( event ); if ( handled && event.GetSkipped() ) handled = false ; } } if ( !handled ) { event.Skip( FALSE ) ; event.SetEventType( wxEVT_CHAR ) ; // raw value again event.m_keyCode = realkeyval ; handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( handled && event.GetSkipped() ) handled = false ; } if ( !handled && (keyval == WXK_TAB) ) { wxWindow* iter = focus->GetParent() ; while( iter && !handled ) { if ( iter->HasFlag( wxTAB_TRAVERSAL ) ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( focus ); new_event.SetDirection( !event.ShiftDown() ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( event.ControlDown() ); new_event.SetCurrentFocus( focus ); handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event ); if ( handled && new_event.GetSkipped() ) handled = false ; } iter = iter->GetParent() ; } } // backdoor handler for default return and command escape if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) { // if window is not having a focus still testing for default enter or cancel // TODO add the UMA version for ActiveNonFloatingWindow wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; if ( focus ) { if ( keyval == WXK_RETURN ) { wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); event.SetEventObject(def); def->Command(event); return true ; } } /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) { wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); new_event.SetEventObject( focus ); handled = focus->GetEventHandler()->ProcessEvent( new_event ); } } } return handled ; }
bool wxKeyTextCtrl::ParseString(const wxChar* s, int len, int &mod, int &key) { mod = key = 0; if (!s || !len) return false; wxString a = wxT('\t'); a.append(s, len); wxAcceleratorEntry ae; #ifndef __WXMAC__ #define check_meta(str) do { \ wxString meta = str; \ for(int ml = 0; (ml = a.find(meta, ml)) != wxString::npos; ml++) { \ if(!ml || a[ml-1] == wxT('-') || a[ml-1] == wxT('+')) { \ mod |= wxMOD_META; \ a.erase(ml, meta.size()); \ ml = -1; \ } \ } \ } while(0) check_meta(wxT("Meta-")); check_meta(wxT("Meta+")); check_meta(_("Meta-")); check_meta(_("Meta+")); #endif // wx disallows standalone modifiers // unlike ToString(), this generates a debug message rather than // an assertion error, so it's easy to ignore and expensive to avoid // beforehand. Instead, check for them on failure if (!ae.FromString(a)) { a.MakeUpper(); #define chk_str(n, k) do { \ wxString t = n; \ if(a.size() > t.size() && a.substr(a.size() - t.size()) == t) { \ a.replace(a.size() - t.size(), t.size(), wxT("F1")); \ wxString ss(s); \ if(ae.FromString(a)) { \ mod |= ae.GetFlags(); \ key = k; \ return true; \ } \ a.replace(a.size() - 2, 2, n); \ } \ } while(0) chk_str(wxT("ALT"), WXK_ALT); chk_str(wxT("SHIFT"), WXK_SHIFT); chk_str(wxT("CTRL"), WXK_CONTROL); chk_str(wxT("CONTROL"), WXK_CONTROL); chk_str(_("ALT"), WXK_ALT); chk_str(_("SHIFT"), WXK_SHIFT); chk_str(_("CTRL"), WXK_CONTROL); chk_str(_("CONTROL"), WXK_CONTROL); return false; } mod |= ae.GetFlags(); key = ae.GetKeyCode(); // wx makes key lower-case, but key events return upper case if (key < WXK_START && wxIslower(key)) key = wxToupper(key); return true; }
void wxFontRefData::InitFromNative() { // get the font parameters from the XLFD // ------------------------------------- m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY); m_weight = wxFONTWEIGHT_NORMAL; wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper(); if ( !w.empty() && w != wxT('*') ) { // the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD // and BLACK if ( ((w[0u] == wxT('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) || !wxStrcmp(w.c_str() + 1, wxT("LACK"))))) || wxStrstr(w.c_str() + 1, wxT("BOLD")) ) { m_weight = wxFONTWEIGHT_BOLD; } else if ( w == wxT("LIGHT") || w == wxT("THIN") ) { m_weight = wxFONTWEIGHT_LIGHT; } } switch ( wxToupper(m_nativeFontInfo. GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case wxT('I'): // italique m_style = wxFONTSTYLE_ITALIC; break; case wxT('O'): // oblique m_style = wxFONTSTYLE_SLANT; break; default: m_style = wxFONTSTYLE_NORMAL; } long ptSize; if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) ) { // size in XLFD is in 10 point units m_pointSize = (int)(ptSize / 10); } else { m_pointSize = wxDEFAULT_FONT_SIZE; } // examine the spacing: if the font is monospaced, assume wxTELETYPE // family for compatibility with the old code which used it instead of // IsFixedWidth() if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == wxT('M') ) { m_family = wxFONTFAMILY_TELETYPE; } else // not monospaceed { // don't even try guessing it, it doesn't work for too many fonts // anyhow m_family = wxFONTFAMILY_UNKNOWN; } // X fonts are never underlined... m_underlined = false; // deal with font encoding wxString registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(), encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper(); if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } else if ( registry == wxT("KOI8") ) { m_encoding = wxFONTENCODING_KOI8; } else // unknown encoding { // may be give a warning here? or use wxFontMapper? m_encoding = wxFONTENCODING_SYSTEM; } }
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { if ( !focus ) return false ; short keycode ; short keychar ; keychar = short(keymessage & charCodeMask); keycode = short(keymessage & keyCodeMask) >> 8 ; if ( modifiers & ( controlKey|shiftKey|optionKey ) ) { // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier // and look at the character after UInt32 state = 0; UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); keychar = short(keyInfo & charCodeMask); } long keyval = wxMacTranslateKey(keychar, keycode) ; if ( keyval == keychar ) { keyval = wxToupper( keyval ) ; } // Check for NUMPAD keys if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92) { keyval = keyval - '0' + WXK_NUMPAD0; } else if (keycode >= 67 && keycode <= 81) { switch (keycode) { case 76 : keyval = WXK_NUMPAD_ENTER; break; case 81: keyval = WXK_NUMPAD_EQUAL; break; case 67: keyval = WXK_NUMPAD_MULTIPLY; break; case 75: keyval = WXK_NUMPAD_DIVIDE; break; case 78: keyval = WXK_NUMPAD_SUBTRACT; break; case 69: keyval = WXK_NUMPAD_ADD; break; case 65: keyval = WXK_NUMPAD_DECIMAL; break; } // end switch } bool handled = false ; wxKeyEvent event(wxEVT_KEY_UP); event.m_shiftDown = modifiers & shiftKey; event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; event.m_keyCode = keyval ; #if wxUSE_UNICODE event.m_uniChar = uniChar ; #endif event.m_rawCode = keymessage; event.m_rawFlags = modifiers; event.m_x = wherex; event.m_y = wherey; event.SetTimestamp(when); event.SetEventObject(focus); handled = focus->GetEventHandler()->ProcessEvent( event ) ; return handled ; }
/* static */ bool wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) { // the parser won't like trailing spaces wxString label = text; label.Trim(true); // the initial \t must be preserved so don't strip leading whitespaces // check for accelerators: they are given after '\t' int posTab = label.Find(wxT('\t')); if ( posTab == wxNOT_FOUND ) { return false; } // parse the accelerator string int accelFlags = wxACCEL_NORMAL; wxString current; for ( size_t n = (size_t)posTab + 1; n < label.length(); n++ ) { if ( (label[n] == '+') || (label[n] == '-') ) { if ( CompareAccelString(current, wxTRANSLATE("ctrl")) ) accelFlags |= wxACCEL_CTRL; else if ( CompareAccelString(current, wxTRANSLATE("alt")) ) accelFlags |= wxACCEL_ALT; else if ( CompareAccelString(current, wxTRANSLATE("shift")) ) accelFlags |= wxACCEL_SHIFT; else // not a recognized modifier name { // we may have "Ctrl-+", for example, but we still want to // catch typos like "Crtl-A" so only give the warning if we // have something before the current '+' or '-', else take // it as a literal symbol if ( current.empty() ) { current += label[n]; // skip clearing it below continue; } else { wxLogDebug(wxT("Unknown accel modifier: '%s'"), current.c_str()); } } current.clear(); } else // not special character { current += (wxChar) wxTolower(label[n]); } } int keyCode; const size_t len = current.length(); switch ( len ) { case 0: wxLogDebug(wxT("No accel key found, accel string ignored.")); return false; case 1: // it's just a letter keyCode = current[0U]; // if the key is used with any modifiers, make it an uppercase one // because Ctrl-A and Ctrl-a are the same; but keep it as is if it's // used alone as 'a' and 'A' are different if ( accelFlags != wxACCEL_NORMAL ) keyCode = wxToupper(keyCode); break; default: keyCode = IsNumberedAccelKey(current, wxTRANSLATE("F"), WXK_F1, 1, 12); if ( !keyCode ) { for ( size_t n = 0; n < WXSIZEOF(wxKeyNames); n++ ) { const wxKeyName& kn = wxKeyNames[n]; if ( CompareAccelString(current, kn.name) ) { keyCode = kn.code; break; } } } if ( !keyCode ) keyCode = IsNumberedAccelKey(current, wxTRANSLATE("KP_"), WXK_NUMPAD0, 0, 9); if ( !keyCode ) keyCode = IsNumberedAccelKey(current, wxTRANSLATE("SPECIAL"), WXK_SPECIAL1, 1, 20); if ( !keyCode ) { wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."), current.c_str()); return false; } } wxASSERT_MSG( keyCode, wxT("logic error: should have key code here") ); if ( flagsOut ) *flagsOut = accelFlags; if ( keyOut ) *keyOut = keyCode; return true; }
void wxFontRefData::InitFromNative() { #if wxUSE_UNICODE // Get native info PangoFontDescription *desc = m_nativeFontInfo.description; // init fields m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); m_pointSize = static_cast<float>(pango_font_description_get_size( desc )) / PANGO_SCALE; switch (pango_font_description_get_style( desc )) { case PANGO_STYLE_NORMAL: m_style = wxFONTSTYLE_NORMAL; break; case PANGO_STYLE_ITALIC: m_style = wxFONTSTYLE_ITALIC; break; case PANGO_STYLE_OBLIQUE: m_style = wxFONTSTYLE_SLANT; break; } m_weight = pango_font_description_get_weight( desc ); #else // X11 // get the font parameters from the XLFD // ------------------------------------- m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY); wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper(); if ( !w.empty() && w != wxT('*') ) m_weight = ParseWeightString(w); else m_weight = wxFONTWEIGHT_NORMAL; switch ( wxToupper( m_nativeFontInfo. GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case wxT('I'): // italique m_style = wxFONTSTYLE_ITALIC; break; case wxT('O'): // oblique m_style = wxFONTSTYLE_SLANT; break; default: m_style = wxFONTSTYLE_NORMAL; } long ptSize; if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) ) { // size in XLFD is in 10 point units m_pointSize = (int)(ptSize / 10); } else { m_pointSize = wxDEFAULT_FONT_SIZE; } // examine the spacing: if the font is monospaced, assume wxFONTFAMILY_TELETYPE // family for compatibility with the old code which used it instead of // IsFixedWidth() if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == wxT('M') ) { m_family = wxFONTFAMILY_TELETYPE; } else // not monospaceed { // don't even try guessing it, it doesn't work for too many fonts // anyhow m_family = wxFONTFAMILY_UNKNOWN; } // X fonts are never underlined... m_underlined = false; // deal with font encoding wxString registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(), encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper(); if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } else if ( registry == wxT("KOI8") ) { m_encoding = wxFONTENCODING_KOI8; } else // unknown encoding { // may be give a warning here? or use wxFontMapper? m_encoding = wxFONTENCODING_SYSTEM; } #endif // Pango/X11 }