// Return number of selections and an array of selected integers int wxListBox::GetSelections(wxArrayInt& aSelections) const { aSelections.Empty(); Widget listBox = (Widget) m_mainWidget; int *posList = NULL; int posCnt = 0; bool flag = XmListGetSelectedPos (listBox, &posList, &posCnt); if (flag) { if (posCnt > 0) { aSelections.Alloc(posCnt); int i; for (i = 0; i < posCnt; i++) aSelections.Add(posList[i] - 1); XtFree ((char *) posList); return posCnt; } else return 0; } else return 0; }
int wxListBox::GetSelections( wxArrayInt& aSelections ) const { wxCHECK_MSG( m_list != NULL, wxNOT_FOUND, wxT("invalid listbox") ); // get the number of selected items first GList *child = m_list->children; int count = 0; for (child = m_list->children; child != NULL; child = child->next) { if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED) count++; } aSelections.Empty(); if (count > 0) { // now fill the list aSelections.Alloc(count); // optimization attempt int i = 0; for (child = m_list->children; child != NULL; child = child->next, i++) { if (GTK_WIDGET(child->data)->state == GTK_STATE_SELECTED) aSelections.Add(i); } } return count; }
bool wxGCDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { bool isMeasuringContext = false; wxGraphicsContext* context = m_graphicContext; if (!context) { context = wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext(); isMeasuringContext = true; } widths.Clear(); widths.Add(0,text.Length()); if ( text.IsEmpty() ) return true; wxArrayDouble widthsD; context->GetPartialTextExtents( text, widthsD ); for ( size_t i = 0; i < widths.GetCount(); ++i ) widths[i] = (wxCoord)(widthsD[i] + 0.5); if (isMeasuringContext) delete context; return true; }
unsigned int PositionsPopup::GetCheckedItems(wxArrayInt &checkedItems) const { unsigned int const itemsCount = GetCount(); checkedItems.Empty(); for( unsigned int i = 0; i < itemsCount; ++i ) { if( IsChecked( i ) ) checkedItems.Add( i ); } return checkedItems.GetCount(); }
bool SpellCheckerPlugin::DoGetWordStarts(const wxString& word, wxArrayInt& wordStarts, int numWords) { if (numWords <= 0) // finish split { wordStarts.Add(0); // first word wxString currWord; for (int i = wordStarts.GetCount() - 1; i > 0; --i) // reverse iteration (so numbers are checked lowest to highest) { currWord = word(wordStarts[i], wordStarts[i - 1] - wordStarts[i]); if (currWord.Length() > 3) // capitalize medium/long words so proper nouns work currWord = currWord(0, 1).Upper() + currWord.Mid(1); if (!m_pSpellChecker->IsWordInDictionary(currWord)) { wordStarts.RemoveAt(wordStarts.GetCount() - 1); return false; // no, fall back a level } } currWord = word.Mid(wordStarts[0]); if (currWord.Length() > 3) // capitalize currWord = currWord(0, 1).Upper() + currWord.Mid(1); if (!m_pSpellChecker->IsWordInDictionary(currWord)) // last word (wordStarts[] is reverse sorted) { wordStarts.RemoveAt(wordStarts.GetCount() - 1); return false; // no, fall back a level } return true; // all parts are correctly spelled } // iterate through possibilities of the current word start for (int i = (wordStarts.IsEmpty() ? word.Length() : wordStarts[wordStarts.GetCount() - 1]) - 2; i >= numWords * 2; --i) { wordStarts.Add(i); if (DoGetWordStarts(word, wordStarts, numWords - 1)) { return true; // yes, fall through and return } wordStarts.RemoveAt(wordStarts.GetCount() - 1); } return false; // no, fall back an iteration }
// Return number of selections and an array of selected integers int wxListBox::GetSelections(wxArrayInt& aSelections) const { aSelections.Empty(); if ( HasMultipleSelection() ) { int countSel = ListBox_GetSelCount(GetHwnd()); if ( countSel == LB_ERR ) { wxLogDebug(wxT("ListBox_GetSelCount failed")); } else if ( countSel != 0 ) { int *selections = new int[countSel]; if ( ListBox_GetSelItems(GetHwnd(), countSel, selections) == LB_ERR ) { wxLogDebug(wxT("ListBox_GetSelItems failed")); countSel = -1; } else { aSelections.Alloc(countSel); for ( int n = 0; n < countSel; n++ ) aSelections.Add(selections[n]); } delete [] selections; } return countSel; } else // single-selection listbox { if (ListBox_GetCurSel(GetHwnd()) > -1) aSelections.Add(ListBox_GetCurSel(GetHwnd())); return aSelections.Count(); } }
void xLightsFrame::GetCheckedItems(wxArrayInt& chArray) { chArray.Clear(); int maxch = CheckListBoxTestChannels->GetCount(); for (int ch=0; ch < maxch; ch++) { if (CheckListBoxTestChannels->IsChecked(ch)) { chArray.Add(ch); } } }
int wxCheckListBox::GetSelections(wxArrayInt& aSelections) const { int i; for (i = 0; (unsigned int)i < GetCount(); i++) { int selState = ListView_GetItemState(GetHwnd(), i, LVIS_SELECTED); if (selState == LVIS_SELECTED) aSelections.Add(i); } return aSelections.GetCount(); }
bool SaveTabGroupDlg::GetChoices(wxArrayInt& intArr) const { bool SomeChecked = false; for(unsigned int n = 0; n < m_ListTabs->GetCount(); ++n) { bool item = m_ListTabs->IsChecked(n); intArr.Add(item); if(item) { SomeChecked = true; } } return SomeChecked; }
bool AutoCompData::BuildPageFunctions( const wxString& path, wxArrayString& functions, wxArrayInt& startLines, wxArrayInt& endLines ) const { //wxASSERT( !path.IsEmpty() ); // Find the right file... AutoCompPage* file = AutoCompPage::Find( path, m_Files ); if ( !file ) return false; // First grab all the functions. const AutoCompFunctionArray& funcs = file->GetFunctions(); AutoCompFunction* func; for ( size_t i=0; i < funcs.GetCount(); i++ ) { func = funcs[i]; wxASSERT( func ); functions.Add( func->GetName() ); startLines.Add( func->GetLine() ); endLines.Add( func->GetLineLast() ); } return true; }
bool wxTextMeasureBase::GetPartialTextExtents(const wxString& text, wxArrayInt& widths, double scaleX) { widths.Empty(); if ( text.empty() ) return true; MeasuringGuard guard(*this); widths.Add(0, text.length()); return DoGetPartialTextExtents(text, widths, scaleX); }
// -------------------------------------------------------------------------------- // void GetCoversFromSamePath( const wxString &path, wxArrayString &files, wxArrayString &paths, wxArrayInt &positions ) { int Index; int Count = files.Count(); for( Index = 0; Index < Count; Index++ ) { if( wxPathOnly( files[ Index ] ) == path ) { paths.Add( files[ Index ] ); positions.Add( Index ); } else break; } }
int wxMacDataBrowserListControl::ListGetSelections( wxArrayInt& aSelections ) const { aSelections.Empty(); wxArrayMacDataItemPtr selectedItems; GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); int count = selectedItems.GetCount(); for ( int i = 0; i < count; ++i) { aSelections.Add(GetLineFromItem(selectedItems[i])); } return count; }
// -------------------------------------------------------------------------------- // void GetMediaViewerTracks( const guTrackArray &sourcetracks, const int flags, const guMediaViewer * mediaviewer, guTrackArray &tracks, wxArrayInt &changedflags ) { int Index; int Count = sourcetracks.Count(); for( Index = 0; Index < Count; Index++ ) { guTrack &Track = sourcetracks[ Index ]; if( Track.m_MediaViewer == mediaviewer ) { tracks.Add( new guTrack( Track ) ); changedflags.Add( flags ); } } }
bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { wxCHECK_MSG( m_graphicContext, false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") ); widths.Clear(); widths.Add(0,text.Length()); if ( text.IsEmpty() ) return true; wxArrayDouble widthsD; m_graphicContext->GetPartialTextExtents( text, widthsD ); for ( size_t i = 0; i < widths.GetCount(); ++i ) widths[i] = (wxCoord)(widthsD[i] + 0.5); return true; }
int wxOptionValue::GetOption(const wxString& name, wxArrayInt &values, int count, const wxString& delims) const { wxString value = GetOption(name); wxStringTokenizer tokens(value, delims, wxTOKEN_STRTOK); int read_count = 0; while (((count < 0) || (read_count <= count)) && tokens.HasMoreTokens()) { long num; if (!tokens.GetNextToken().ToLong(&num)) return read_count; values.Add(num); read_count++; } return read_count; }
int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const { int no_sel = 0 ; aSelections.Empty(); Cell cell = { 0 , 0 } ; cell.v = 0 ; while ( LGetSelect( true , &cell ,(ListHandle) m_macList ) ) { aSelections.Add( cell.v ) ; no_sel++ ; cell.v++ ; } return no_sel ; }
bool wxDCBase::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { int totalWidth = 0; size_t i, len = text.Length(); widths.Empty(); widths.Add(0, len); int w, h; // reset the cache if font or horizontal scale have changed if (!s_fontWidthCache.m_widths || (s_fontWidthCache.m_scaleX != m_scaleX) || (s_fontWidthCache.m_font != GetFont())) { s_fontWidthCache.Reset(); s_fontWidthCache.m_font = GetFont(); s_fontWidthCache.m_scaleX = m_scaleX; } // Calculate the position of each character based on the widths of // the previous characters for (i=0; i<len; i++) { const wxChar c = text[i]; unsigned int c_int = (unsigned int)c; if ((c_int < FWC_SIZE) && (s_fontWidthCache.m_widths[c_int] != 0)) { w = s_fontWidthCache.m_widths[c_int]; } else { GetTextExtent(c, &w, &h); if (c_int < FWC_SIZE) s_fontWidthCache.m_widths[c_int] = w; } totalWidth += w; widths[i] = totalWidth; } return true; }
int wxLuaDebugData::RefTable(lua_State* L, int stack_idx, int* flag_type, int extra_flag, wxArrayInt& references) { wxCHECK_MSG(L, LUA_NOREF, wxT("Invalid lua_State")); int lua_ref = LUA_NOREF; if (lua_istable(L, stack_idx)) { if (flag_type) *flag_type |= (WXLUA_DEBUGITEM_IS_REFED | extra_flag); lua_ref = wxluaR_isrefed(L, stack_idx, &wxlua_lreg_debug_refs_key); // don't duplicate refs if (lua_ref == LUA_NOREF) { lua_ref = wxluaR_ref(L, stack_idx, &wxlua_lreg_debug_refs_key); references.Add(lua_ref); } } return lua_ref; }
// -------------------------------------------------------------------------------- // bool ReadEQPresets( const wxString &value, wxArrayInt &preset ) { long CurVal; int index; int count; wxArrayString Values = wxStringTokenize( value, wxT( "," ), wxTOKEN_RET_EMPTY_ALL ); if( ( count = Values.Count() ) == guEQUALIZER_BAND_COUNT ) { for( index = 0; index < count; index++ ) { if( Values[ index ].ToLong( &CurVal ) ) { preset.Add( CurVal ); } else break; } return ( preset.Count() == guEQUALIZER_BAND_COUNT ); } return false; }
int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const { int no_sel = 0 ; aSelections.Empty(); UInt32 first , last ; m_peer->GetSelectionAnchor( &first , &last ) ; if ( first != kDataBrowserNoItem ) { for ( size_t i = first ; i <= last ; ++i ) { if ( m_peer->IsItemSelected( i ) ) { aSelections.Add( i - 1 ) ; no_sel++ ; } } } return no_sel ; }
int ProjectManager::DoAddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets) { if (!project) return 0; // do we have to ask for target? if (targets.GetCount() == 0) { // if project has only one target, use this if (project->GetBuildTargetsCount() == 1) targets.Add(0); // else display multiple target selection dialog else { targets = m_ui->AskForMultiBuildTargetIndex(project); if (targets.GetCount() == 0) return 0; } } // make sure filename is relative to project path wxFileName fname(filename); fname.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, project->GetBasePath()); fname.MakeRelativeTo(project->GetBasePath()); // add the file to the first selected target ProjectFile* pf = project->AddFile(targets[0], fname.GetFullPath()); if (pf) { // if the file was added successfully, // add to this file the rest of the selected targets... for (size_t i = 0; i < targets.GetCount(); ++i) { ProjectBuildTarget* target = project->GetBuildTarget(targets[i]); if (target) pf->AddBuildTarget(target->GetTitle()); } } return targets.GetCount(); }
int wxListBox::GetSelections( wxArrayInt& aSelections ) const { wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") ); aSelections.Empty(); int i = 0; GtkTreeIter iter; GtkTreeSelection* selection = gtk_tree_view_get_selection(m_treeview); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore), &iter)) { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead do { if (gtk_tree_selection_iter_is_selected(selection, &iter)) aSelections.Add(i); i++; } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore), &iter)); } return aSelections.GetCount(); }
void ImagePanelDyn::selectPhoto(wxCommandEvent& event) { panel->SetBackgroundColour(Couleurs::selectColor); // this->GetParent()->SetWindowStyle(wxBORDER_SIMPLE); panel->Refresh(true); idPhotoSelected.Add(idImage0); }
// called on each Timer tick while Test dialog is open void xLightsFrame::OnTimerTest(long curtime) { static int LastNotebookSelection = -1; static int LastBgIntensity,LastFgIntensity,LastBgColor[3],LastFgColor[3],*ShimColor,ShimIntensity; static int LastSequenceSpeed; static int LastAutomatedTest; static long NextSequenceStart = -1; static TestFunctions LastFunc = OFF; static unsigned int interval, rgbCycle, TestSeqIdx; static wxArrayInt chArray,TwinkleState; static float frequency; int v,BgIntensity,FgIntensity,BgColor[3],FgColor[3]; unsigned int i; bool ColorChange; if (!xout) return; xout->TimerStart(curtime); int NotebookSelection = NotebookTest->GetSelection(); if (NotebookSelection != LastNotebookSelection) { LastNotebookSelection = NotebookSelection; CheckChannelList = true; TestSeqIdx=0; TestButtonsOff(); } if (TestFunc != LastFunc) { LastFunc = TestFunc; rgbCycle=0; CheckChannelList = true; NextSequenceStart = -1; } if (CheckChannelList) { // get list of checked channels xout->alloff(); GetCheckedItems(chArray); LastSequenceSpeed=-1; LastBgIntensity=-1; LastFgIntensity=-1; LastAutomatedTest=-1; for (i=0; i < 3; i++) { LastBgColor[i] = -1; LastFgColor[i] = -1; } if (!CheckBoxLightOutput->IsChecked()) { StatusBar1->SetStatusText(_("Testing disabled - Output to Lights is not checked")); } else if (TestFunc == OFF) { StatusBar1->SetStatusText(_("Testing off")); } else { StatusBar1->SetStatusText(wxString::Format(_("Testing %ld channels"),static_cast<long>(chArray.Count()))); } CheckChannelList = false; } if (TestFunc != OFF && chArray.Count() > 0) switch (NotebookSelection) { case 0: // standard tests v=SliderChaseSpeed->GetValue(); // 0-100 BgIntensity = SliderBgIntensity->GetValue(); FgIntensity = SliderFgIntensity->GetValue(); ColorChange = BgIntensity != LastBgIntensity || FgIntensity != LastFgIntensity; LastBgIntensity = BgIntensity; LastFgIntensity = FgIntensity; interval = 1600 - v*15; switch (TestFunc) { case DIM: if (ColorChange) { for (i=0; i < chArray.Count(); i++) { xout->SetIntensity(chArray[i], BgIntensity); } } break; case TWINKLE: if (LastSequenceSpeed < 0) { LastSequenceSpeed=0; TwinkleState.Clear(); for (i=0; i < chArray.Count(); i++) { TestSeqIdx = static_cast<int>(rand01()*TwinkleRatio); TwinkleState.Add(TestSeqIdx == 0 ? -1 : 1); } } for (i=0; i < TwinkleState.Count(); i++) { if (TwinkleState[i] < -1) { // background TwinkleState[i]++; } else if (TwinkleState[i] > 1) { // highlight TwinkleState[i]--; } else if (TwinkleState[i] == -1) { // was background, now highlight for random period TwinkleState[i]=static_cast<int>(rand01()*interval+100) / XTIMER_INTERVAL; xout->SetIntensity(chArray[i], FgIntensity); } else { // was on, now go to bg color for random period TwinkleState[i]=-static_cast<int>(rand01()*interval+100) / XTIMER_INTERVAL * (TwinkleRatio - 1); xout->SetIntensity(chArray[i], BgIntensity); } } break; case SHIMMER: if (ColorChange || curtime >= NextSequenceStart) { ShimIntensity = (ShimIntensity == FgIntensity) ? BgIntensity : FgIntensity; for (i=0; i < chArray.Count(); i++) { xout->SetIntensity(chArray[i], ShimIntensity); } } if (curtime >= NextSequenceStart) { NextSequenceStart = curtime + interval/2; } break; case CHASE: //StatusBar1->SetStatusText(wxString::Format(_("chase curtime=%ld, NextSequenceStart=%ld"),curtime,NextSequenceStart)); if (ColorChange || curtime >= NextSequenceStart) { for (i=0; i < chArray.Count(); i++) { v = (i % ChaseGrouping) == TestSeqIdx ? FgIntensity : BgIntensity; xout->SetIntensity(chArray[i], v); } } if (curtime >= NextSequenceStart) { NextSequenceStart = curtime + interval; TestSeqIdx = (TestSeqIdx + 1) % ChaseGrouping; if (TestSeqIdx >= chArray.Count()) TestSeqIdx=0; } StatusBar1->SetStatusText(wxString::Format(_("Testing %ld channels; chase now at ch# %d"),static_cast<long>(chArray.Count()), TestSeqIdx)); //show current ch# -DJ break; default: break; } break; case 1: // RGB tests v=SliderRgbChaseSpeed->GetValue(); // 0-100 BgColor[0] = SliderBgColorA->GetValue(); BgColor[1] = SliderBgColorB->GetValue(); BgColor[2] = SliderBgColorC->GetValue(); FgColor[0] = SliderFgColorA->GetValue(); FgColor[1] = SliderFgColorB->GetValue(); FgColor[2] = SliderFgColorC->GetValue(); interval = 1600 - v*15; for (ColorChange=false,i=0; i < 3; i++) { ColorChange |= (BgColor[i] != LastBgColor[i]); ColorChange |= (FgColor[i] != LastFgColor[i]); LastBgColor[i] = BgColor[i]; LastFgColor[i] = FgColor[i]; } switch (TestFunc) { case DIM: if (ColorChange) { for (i=0; i < chArray.Count(); i++) { xout->SetIntensity(chArray[i], BgColor[i % 3]); } } break; case TWINKLE: if (LastSequenceSpeed < 0) { LastSequenceSpeed=0; TwinkleState.Clear(); for (i=0; i < chArray.Count()-2; i+=3) { TestSeqIdx = static_cast<int>(rand01()*TwinkleRatio); TwinkleState.Add(TestSeqIdx == 0 ? -1 : 1); } } for (i=0; i < TwinkleState.Count(); i++) { if (TwinkleState[i] < -1) { // background TwinkleState[i]++; } else if (TwinkleState[i] > 1) { // highlight TwinkleState[i]--; } else if (TwinkleState[i] == -1) { // was background, now highlight for random period TwinkleState[i]=static_cast<int>(rand01()*interval+100) / XTIMER_INTERVAL; TestSeqIdx = i * 3; xout->SetIntensity(chArray[TestSeqIdx], FgColor[0]); xout->SetIntensity(chArray[TestSeqIdx+1], FgColor[1]); xout->SetIntensity(chArray[TestSeqIdx+2], FgColor[2]); } else { // was on, now go to bg color for random period TwinkleState[i]=-static_cast<int>(rand01()*interval+100) / XTIMER_INTERVAL * (TwinkleRatio - 1); TestSeqIdx = i * 3; xout->SetIntensity(chArray[TestSeqIdx], BgColor[0]); xout->SetIntensity(chArray[TestSeqIdx+1], BgColor[1]); xout->SetIntensity(chArray[TestSeqIdx+2], BgColor[2]); } } break; case SHIMMER: if (ColorChange || curtime >= NextSequenceStart) { ShimColor = (ShimColor == FgColor) ? BgColor : FgColor; for (i=0; i < chArray.Count(); i++) { xout->SetIntensity(chArray[i], ShimColor[i % 3]); } } if (curtime >= NextSequenceStart) { NextSequenceStart = curtime + interval/2; } break; case CHASE: if (ColorChange || curtime >= NextSequenceStart) { for (i=0; i < chArray.Count(); i++) { v = (i / 3 % ChaseGrouping) == TestSeqIdx ? FgColor[i % 3] : BgColor[i % 3]; xout->SetIntensity(chArray[i], v); } } if (curtime >= NextSequenceStart) { NextSequenceStart = curtime + interval; TestSeqIdx = (TestSeqIdx + 1) % ChaseGrouping; if (TestSeqIdx >= (chArray.Count()+2) / 3) TestSeqIdx=0; } StatusBar1->SetStatusText(wxString::Format(_("Testing %ld channels; chase now at ch# %d"),static_cast<long>(chArray.Count()), TestSeqIdx)); //show current ch# -DJ break; default: break; } break; case 2: // RGB Cycle v=SliderRgbCycleSpeed->GetValue(); // 0-100 if (TestFunc == DIM) { // color mixing if (v != LastSequenceSpeed) { frequency=v/1000.0 + 0.05; LastSequenceSpeed = v; } BgColor[0] = sin(frequency*TestSeqIdx + 0.0) * 127 + 128; BgColor[1] = sin(frequency*TestSeqIdx + 2.0) * 127 + 128; BgColor[2] = sin(frequency*TestSeqIdx + 4.0) * 127 + 128; TestSeqIdx++; for (i=0; i < chArray.Count(); i++) { xout->SetIntensity(chArray[i], BgColor[i % 3]); } } else { // RGB cycle if (v != LastSequenceSpeed) { interval = (101-v)*50; NextSequenceStart = curtime + interval; LastSequenceSpeed = v; } if (curtime >= NextSequenceStart) { for (i=0; i < chArray.Count(); i++) { switch (rgbCycle) { case 3: v=255; break; default: v = (i % 3) == rgbCycle ? 255 : 0; break; } xout->SetIntensity(chArray[i], v); } rgbCycle=(rgbCycle + 1) % ChaseGrouping; NextSequenceStart += interval; } } break; } xout->TimerEnd(); }
size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids) { #ifdef wxHAS_FILESYSTEM_VOLUMES #ifdef __WXWINCE__ // No logical drives; return "\" paths.Add(wxT("\\")); names.Add(wxT("\\")); icon_ids.Add(wxFileIconsTable::computer); #elif defined(__WIN32__) && wxUSE_FSVOLUME // TODO: this code (using wxFSVolumeBase) should be used for all platforms // but unfortunately wxFSVolumeBase is not implemented everywhere const wxArrayString as = wxFSVolumeBase::GetVolumes(); for (size_t i = 0; i < as.GetCount(); i++) { wxString path = as[i]; wxFSVolume vol(path); int imageId; switch (vol.GetKind()) { case wxFS_VOL_FLOPPY: if ( (path == wxT("a:\\")) || (path == wxT("b:\\")) ) imageId = wxFileIconsTable::floppy; else imageId = wxFileIconsTable::removeable; break; case wxFS_VOL_DVDROM: case wxFS_VOL_CDROM: imageId = wxFileIconsTable::cdrom; break; case wxFS_VOL_NETWORK: if (path[0] == wxT('\\')) continue; // skip "\\computer\folder" imageId = wxFileIconsTable::drive; break; case wxFS_VOL_DISK: case wxFS_VOL_OTHER: default: imageId = wxFileIconsTable::drive; break; } paths.Add(path); names.Add(vol.GetDisplayName()); icon_ids.Add(imageId); } #elif defined(__OS2__) APIRET rc; ULONG ulDriveNum = 0; ULONG ulDriveMap = 0; rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap); if ( rc == 0) { size_t i = 0; while (i < 26) { if (ulDriveMap & ( 1 << i )) { const wxString path = wxFileName::GetVolumeString( 'A' + i, wxPATH_GET_SEPARATOR); const wxString name = wxFileName::GetVolumeString( 'A' + i, wxPATH_NO_SEPARATOR); // Note: If _filesys is unsupported by some compilers, // we can always replace it by DosQueryFSAttach char filesysname[20]; #ifdef __WATCOMC__ ULONG cbBuffer = sizeof(filesysname); PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2)filesysname; APIRET rc = ::DosQueryFSAttach(name.fn_str(),0,FSAIL_QUERYNAME,pfsqBuffer,&cbBuffer); if (rc != NO_ERROR) { filesysname[0] = '\0'; } #else _filesys(name.fn_str(), filesysname, sizeof(filesysname)); #endif /* FAT, LAN, HPFS, CDFS, NFS */ int imageId; if (path == wxT("A:\\") || path == wxT("B:\\")) imageId = wxFileIconsTable::floppy; else if (!strcmp(filesysname, "CDFS")) imageId = wxFileIconsTable::cdrom; else if (!strcmp(filesysname, "LAN") || !strcmp(filesysname, "NFS")) imageId = wxFileIconsTable::drive; else imageId = wxFileIconsTable::drive; paths.Add(path); names.Add(name); icon_ids.Add(imageId); } i ++; } } #else // !__WIN32__, !__OS2__ /* If we can switch to the drive, it exists. */ for ( char drive = 'A'; drive <= 'Z'; drive++ ) { const wxString path = wxFileName::GetVolumeString(drive, wxPATH_GET_SEPARATOR); if (wxIsDriveAvailable(path)) { paths.Add(path); names.Add(wxFileName::GetVolumeString(drive, wxPATH_NO_SEPARATOR)); icon_ids.Add(drive <= 2 ? wxFileIconsTable::floppy : wxFileIconsTable::drive); } } #endif // __WIN32__/!__WIN32__ #elif defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ItemCount volumeIndex = 1; OSErr err = noErr ; while( noErr == err ) { HFSUniStr255 volumeName ; FSRef fsRef ; FSVolumeInfo volumeInfo ; err = FSGetVolumeInfo(0, volumeIndex, NULL, kFSVolInfoFlags , &volumeInfo , &volumeName, &fsRef); if( noErr == err ) { wxString path = wxMacFSRefToPath( &fsRef ) ; wxString name = wxMacHFSUniStrToString( &volumeName ) ; if ( (volumeInfo.flags & kFSVolFlagSoftwareLockedMask) || (volumeInfo.flags & kFSVolFlagHardwareLockedMask) ) { icon_ids.Add(wxFileIconsTable::cdrom); } else { icon_ids.Add(wxFileIconsTable::drive); } // todo other removable paths.Add(path); names.Add(name); volumeIndex++ ; } } #elif defined(__UNIX__) || defined(__WXPALMOS__) paths.Add(wxT("/")); names.Add(wxT("/")); icon_ids.Add(wxFileIconsTable::computer); #else #error "Unsupported platform in wxGenericDirCtrl!" #endif wxASSERT_MSG( (paths.GetCount() == names.GetCount()), wxT("The number of paths and their human readable names should be equal in number.")); wxASSERT_MSG( (paths.GetCount() == icon_ids.GetCount()), wxT("Wrong number of icons for available drives.")); return paths.GetCount(); }
// Build PolyTessGeo Object from OGR Polygon // Using OpenGL/GLU tesselator int PolyTessGeo::PolyTessGeoGL(OGRPolygon *poly, bool bSENC_SM, double ref_lat, double ref_lon) { #ifdef ocpnUSE_GL int iir, ip; int *cntr; GLdouble *geoPt; wxString sout; wxString sout1; wxString stemp; // Make a quick sanity check of the polygon coherence bool b_ok = true; OGRLineString *tls = poly->getExteriorRing(); if(!tls) { b_ok = false; } else { int tnpta = poly->getExteriorRing()->getNumPoints(); if(tnpta < 3 ) b_ok = false; } for( iir=0 ; iir < poly->getNumInteriorRings() ; iir++) { int tnptr = poly->getInteriorRing(iir)->getNumPoints(); if( tnptr < 3 ) b_ok = false; } if( !b_ok ) return ERROR_BAD_OGRPOLY; #ifdef __WXMSW__ // If using the OpenGL dlls provided with Windows, // load the dll and establish addresses of the entry points needed #ifdef USE_GLU_DLL if(!s_glu_dll_ready) { s_hGLU_DLL = LoadLibrary("glu32.dll"); if (s_hGLU_DLL != NULL) { s_lpfnTessProperty = (LPFNDLLTESSPROPERTY)GetProcAddress(s_hGLU_DLL,"gluTessProperty"); s_lpfnNewTess = (LPFNDLLNEWTESS)GetProcAddress(s_hGLU_DLL, "gluNewTess"); s_lpfnTessBeginContour = (LPFNDLLTESSBEGINCONTOUR)GetProcAddress(s_hGLU_DLL, "gluTessBeginContour"); s_lpfnTessEndContour = (LPFNDLLTESSENDCONTOUR)GetProcAddress(s_hGLU_DLL, "gluTessEndContour"); s_lpfnTessBeginPolygon = (LPFNDLLTESSBEGINPOLYGON)GetProcAddress(s_hGLU_DLL, "gluTessBeginPolygon"); s_lpfnTessEndPolygon = (LPFNDLLTESSENDPOLYGON)GetProcAddress(s_hGLU_DLL, "gluTessEndPolygon"); s_lpfnDeleteTess = (LPFNDLLDELETETESS)GetProcAddress(s_hGLU_DLL, "gluDeleteTess"); s_lpfnTessVertex = (LPFNDLLTESSVERTEX)GetProcAddress(s_hGLU_DLL, "gluTessVertex"); s_lpfnTessCallback = (LPFNDLLTESSCALLBACK)GetProcAddress(s_hGLU_DLL, "gluTessCallback"); s_glu_dll_ready = true; } else { return ERROR_NO_DLL; } } #endif #endif // Allocate a work buffer, which will be grown as needed #define NINIT_BUFFER_LEN 10000 s_pwork_buf = (GLdouble *)malloc(NINIT_BUFFER_LEN * 2 * sizeof(GLdouble)); s_buf_len = NINIT_BUFFER_LEN * 2; s_buf_idx = 0; // Create an array to hold pointers to allocated vertices created by "combine" callback, // so that they may be deleted after tesselation. s_pCombineVertexArray = new wxArrayPtrVoid; // Create tesselator GLUtessobj = gluNewTess(); // Register the callbacks gluTessCallback(GLUtessobj, GLU_TESS_BEGIN, (GLvoid (__CALL_CONVENTION *) ())&beginCallback); gluTessCallback(GLUtessobj, GLU_TESS_BEGIN, (GLvoid (__CALL_CONVENTION *) ())&beginCallback); gluTessCallback(GLUtessobj, GLU_TESS_VERTEX, (GLvoid (__CALL_CONVENTION *) ())&vertexCallback); gluTessCallback(GLUtessobj, GLU_TESS_END, (GLvoid (__CALL_CONVENTION *) ())&endCallback); gluTessCallback(GLUtessobj, GLU_TESS_COMBINE, (GLvoid (__CALL_CONVENTION *) ())&combineCallback); // gluTessCallback(GLUtessobj, GLU_TESS_ERROR, (GLvoid (__CALL_CONVENTION *) ())&errorCallback); // glShadeModel(GL_SMOOTH); gluTessProperty(GLUtessobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE ); // gluTess algorithm internally selects vertically oriented triangle strips and fans. // This orientation is not optimal for conventional memory-mapped raster display shape filling. // We can "fool" the algorithm by interchanging the x and y vertex values passed to gluTessVertex // and then reverting x and y on the resulting vertexCallbacks. // In this implementation, we will explicitely set the preferred orientation. //Set the preferred orientation tess_orient = TESS_HORZ; // prefer horizontal tristrips // PolyGeo BBox as lat/lon OGREnvelope Envelope; poly->getEnvelope(&Envelope); xmin = Envelope.MinX; ymin = Envelope.MinY; xmax = Envelope.MaxX; ymax = Envelope.MaxY; // Get total number of contours m_ncnt = 1; // always exterior ring int nint = poly->getNumInteriorRings(); // interior rings m_ncnt += nint; // Allocate cntr array cntr = (int *)malloc(m_ncnt * sizeof(int)); // Get total number of points(vertices) int npta = poly->getExteriorRing()->getNumPoints(); cntr[0] = npta; npta += 2; // fluff for( iir=0 ; iir < nint ; iir++) { int nptr = poly->getInteriorRing(iir)->getNumPoints(); cntr[iir+1] = nptr; npta += nptr + 2; } // printf("pPoly npta: %d\n", npta); geoPt = (GLdouble *)malloc((npta) * 3 * sizeof(GLdouble)); // vertex array // Grow the work buffer if necessary if((npta * 4) > s_buf_len) { s_pwork_buf = (GLdouble *)realloc(s_pwork_buf, npta * 4 * sizeof(GLdouble)); s_buf_len = npta * 4; } // Define the polygon gluTessBeginPolygon(GLUtessobj, NULL); // Create input structures // Exterior Ring int npte = poly->getExteriorRing()->getNumPoints(); cntr[0] = npte; GLdouble *ppt = geoPt; // Check and account for winding direction of ring bool cw = !(poly->getExteriorRing()->isClockwise() == 0); double x0, y0, x, y; OGRPoint p; if(cw) { poly->getExteriorRing()->getPoint(0, &p); x0 = p.getX(); y0 = p.getY(); } else { poly->getExteriorRing()->getPoint(npte-1, &p); x0 = p.getX(); y0 = p.getY(); } // Transcribe contour to an array of doubles, with duplicates eliminated double *DPbuffer = (double *)malloc(npte * 2 * sizeof(double)); double *DPrun = DPbuffer; int nPoints = npte; for(ip = 0 ; ip < npte ; ip++) { int pidx; if(cw) pidx = npte - ip - 1; else pidx = ip; poly->getExteriorRing()->getPoint(pidx, &p); x = p.getX(); y = p.getY(); if( ((fabs(x-x0) > EQUAL_EPS) || (fabs(y-y0) > EQUAL_EPS))) { GLdouble *ppt_temp = ppt; if(tess_orient == TESS_VERT) { *DPrun++ = x; *DPrun++ = y; } else { *DPrun++ = y; *DPrun++ = x; } x0 = x; y0 = y; } else nPoints--; } if(nPoints > 5 && (m_LOD_meters > .01)){ index_keep.Clear(); index_keep.Add(0); index_keep.Add(nPoints-1); index_keep.Add(1); index_keep.Add(nPoints-2); DouglasPeucker(DPbuffer, 1, nPoints-2, m_LOD_meters/(1852 * 60), &index_keep); // printf("DP Reduction: %d/%d\n", index_keep.GetCount(), nPoints); g_keep += index_keep.GetCount(); g_orig += nPoints; // printf("...................Running: %g\n", (double)g_keep/g_orig); } else { index_keep.Clear(); for(int i = 0 ; i < nPoints ; i++) index_keep.Add(i); } cntr[0] = index_keep.GetCount(); // Mark the keepers by adding a simple constant to X for(unsigned int i=0 ; i < index_keep.GetCount() ; i++){ int k = index_keep.Item(i); DPbuffer[2*k] += 2000.; } // Declare the gluContour and copy the points gluTessBeginContour(GLUtessobj); DPrun = DPbuffer; for(ip = 0 ; ip < nPoints ; ip++) { x = *DPrun++; y = *DPrun++; if(x > 1000.){ GLdouble *ppt_top = ppt; *ppt++ = x-2000; *ppt++ = y; *ppt++ = 0; gluTessVertex( GLUtessobj, ppt_top, ppt_top ) ; } } gluTessEndContour(GLUtessobj); free(DPbuffer); // Now the interior contours for(iir=0 ; iir < nint ; iir++) { gluTessBeginContour(GLUtessobj); int npti = poly->getInteriorRing(iir)->getNumPoints(); // Check and account for winding direction of ring bool cw = !(poly->getInteriorRing(iir)->isClockwise() == 0); if(!cw) { poly->getInteriorRing(iir)->getPoint(0, &p); x0 = p.getX(); y0 = p.getY(); } else { poly->getInteriorRing(iir)->getPoint(npti-1, &p); x0 = p.getX(); y0 = p.getY(); } // Transcribe points to vertex array, in proper order with no duplicates // also, accounting for tess_orient for(int ip = 0 ; ip < npti ; ip++) { OGRPoint p; int pidx; if(!cw) // interior contours must be cw pidx = npti - ip - 1; else pidx = ip; poly->getInteriorRing(iir)->getPoint(pidx, &p); x = p.getX(); y = p.getY(); if((fabs(x-x0) > EQUAL_EPS) || (fabs(y-y0) > EQUAL_EPS)) { GLdouble *ppt_temp = ppt; if(tess_orient == TESS_VERT) { *ppt++ = x; *ppt++ = y; } else { *ppt++ = y; *ppt++ = x; } *ppt++ = 0.0; gluTessVertex( GLUtessobj, ppt_temp, ppt_temp ) ; // printf("tess from Poly, internal vertex %d %g %g\n", ip, x, y); } else cntr[iir+1]--; x0 = x; y0 = y; } gluTessEndContour(GLUtessobj); } // Store some SM conversion data in static store, // for callback access s_ref_lat = ref_lat; s_ref_lon = ref_lon; s_bSENC_SM = bSENC_SM; s_bmerc_transform = false; // Ready to kick off the tesselator s_pTPG_Last = NULL; s_pTPG_Head = NULL; s_nvmax = 0; gluTessEndPolygon(GLUtessobj); // here it goes m_nvertex_max = s_nvmax; // record largest vertex count, updates in callback // Tesselation all done, so... // Create the data structures m_ppg_head = new PolyTriGroup; m_ppg_head->m_bSMSENC = s_bSENC_SM; m_ppg_head->nContours = m_ncnt; m_ppg_head->pn_vertex = cntr; // pointer to array of poly vertex counts m_ppg_head->data_type = DATA_TYPE_DOUBLE; // Transcribe the raw geometry buffer // Converting to float as we go, and // allowing for tess_orient // Also, convert to SM if requested // Recalculate the size of the geometry buffer int nptfinal = cntr[0] + 2; for(int i=0 ; i < nint ; i++) nptfinal += cntr[i+1] + 2; // No longer need the full geometry in the SENC, nptfinal = 1; m_nwkb = (nptfinal + 1) * 2 * sizeof(float); m_ppg_head->pgroup_geom = (float *)calloc(sizeof(float), (nptfinal + 1) * 2); float *vro = m_ppg_head->pgroup_geom; ppt = geoPt; float tx,ty; for(ip = 0 ; ip < nptfinal ; ip++) { if(TESS_HORZ == tess_orient) { ty = *ppt++; tx = *ppt++; } else { tx = *ppt++; ty = *ppt++; } if(bSENC_SM) { // Calculate SM from chart common reference point double easting, northing; toSM(ty, tx, ref_lat, ref_lon, &easting, &northing); *vro++ = easting; // x *vro++ = northing; // y } else { *vro++ = tx; // lon *vro++ = ty; // lat } ppt++; // skip z } m_ppg_head->tri_prim_head = s_pTPG_Head; // head of linked list of TriPrims // Convert the Triangle vertex arrays into a single memory allocation of floats // to reduce SENC size and enable efficient access later // First calculate the total byte size int total_byte_size = 2 * sizeof(float); TriPrim *p_tp = m_ppg_head->tri_prim_head; while( p_tp ) { total_byte_size += p_tp->nVert * 2 * sizeof(float); p_tp = p_tp->p_next; // pick up the next in chain } float *vbuf = (float *)malloc(total_byte_size); p_tp = m_ppg_head->tri_prim_head; float *p_run = vbuf; while( p_tp ) { float *pfbuf = p_run; GLdouble *pdouble_buf = (GLdouble *)p_tp->p_vertex; for( int i=0 ; i < p_tp->nVert * 2 ; ++i){ float x = (float)( *((GLdouble *)pdouble_buf) ); pdouble_buf++; *p_run++ = x; } free(p_tp->p_vertex); p_tp->p_vertex = (double *)pfbuf; p_tp = p_tp->p_next; // pick up the next in chain } m_ppg_head->bsingle_alloc = true; m_ppg_head->single_buffer = (unsigned char *)vbuf; m_ppg_head->single_buffer_size = total_byte_size; m_ppg_head->data_type = DATA_TYPE_FLOAT; gluDeleteTess(GLUtessobj); free( s_pwork_buf ); s_pwork_buf = NULL; free (geoPt); // Free up any "Combine" vertices created for(unsigned int i = 0; i < s_pCombineVertexArray->GetCount() ; i++) free (s_pCombineVertexArray->Item(i)); delete s_pCombineVertexArray; m_bOK = true; #endif // #ifdef ocpnUSE_GL return 0; }
void wxVideoTerminal::DoSelectGraphicRendition(wxArrayInt &attrs) { if (attrs.GetCount() == 0) attrs.Add( 0 ); unsigned int i; for (i=0; i<attrs.GetCount();++i) { int cur_param = attrs[i]; //wxLogDebug("DoSelectGraphicRendition(%d=%d)", i, cur_param); switch (cur_param) { case 0: // reset m_cursor_attr.value = 0; m_cursor_attr.val.fgcolor = 7; break; case 21: m_cursor_attr.val.bold = false; break; case 22: m_cursor_attr.val.dim = false; break; case 24: // underline-off m_cursor_attr.val.underline = false; break; case 25: // blink-off m_cursor_attr.val.blink = false; break; case 27: // reverse-off m_cursor_attr.val.reverse = false; break; case 1: // bold m_cursor_attr.val.bold = true; break; case 2: // dim m_cursor_attr.val.dim = true; break; case 4: // underline m_cursor_attr.val.underline = true; break; case 5: // blink m_cursor_attr.val.blink = true; break; case 7: // reverse m_cursor_attr.val.reverse = true; break; case 39: // default w/ underscore fgcolor m_cursor_attr.val.fgcolor = 7; break; case 38: // default fgcolor m_cursor_attr.val.fgcolor = 7; break; case 30: // black m_cursor_attr.val.fgcolor = 0; break; case 31: // red m_cursor_attr.val.fgcolor = 1; break; case 32: // green m_cursor_attr.val.fgcolor = 2; break; case 33: // brown m_cursor_attr.val.fgcolor = 3; break; case 34: // blue m_cursor_attr.val.fgcolor = 4; break; case 35: // magenta m_cursor_attr.val.fgcolor = 5; break; case 36: // cyan m_cursor_attr.val.fgcolor = 6; break; case 37: // white m_cursor_attr.val.fgcolor = 7; break; case 49: // default bgcolor m_cursor_attr.val.bgcolor = 0; break; case 40: // black m_cursor_attr.val.bgcolor = 0; break; case 41: // red m_cursor_attr.val.bgcolor = 1; break; case 42: // green m_cursor_attr.val.bgcolor = 2; break; case 43: // brown m_cursor_attr.val.bgcolor = 3; break; case 44: // blue m_cursor_attr.val.bgcolor = 4; break; case 45: // magenta m_cursor_attr.val.bgcolor = 5; break; case 46: // cyan m_cursor_attr.val.bgcolor = 6; break; case 47: // white m_cursor_attr.val.bgcolor = 7; break; } } }
int wxListBox::GetSelections( wxArrayInt& raSelections ) const { int nCount = 0; LONG lItem; raSelections.Empty(); if (HasMultipleSelection()) { lItem = LONGFROMMR(::WinSendMsg( GetHwnd() ,LM_QUERYSELECTION ,(MPARAM)LIT_FIRST ,(MPARAM)0 ) ); if (lItem != LIT_NONE) { nCount++; while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd() ,LM_QUERYSELECTION ,(MPARAM)lItem ,(MPARAM)0 ) )) != LIT_NONE) { nCount++; } raSelections.Alloc(nCount); lItem = LONGFROMMR(::WinSendMsg( GetHwnd() ,LM_QUERYSELECTION ,(MPARAM)LIT_FIRST ,(MPARAM)0 ) ); raSelections.Add((int)lItem); while ((lItem = LONGFROMMR(::WinSendMsg( GetHwnd() ,LM_QUERYSELECTION ,(MPARAM)lItem ,(MPARAM)0 ) )) != LIT_NONE) { raSelections.Add((int)lItem); } return nCount; } } else // single-selection listbox { lItem = LONGFROMMR(::WinSendMsg( GetHwnd() ,LM_QUERYSELECTION ,(MPARAM)LIT_FIRST ,(MPARAM)0 ) ); raSelections.Add((int)lItem); return 1; } return 0; } // end of wxListBox::GetSelections