void SjViewSettingsPage::OnSize(wxSizeEvent& event) { wxSize size = m_listCtrl->GetClientSize(); m_listCtrl->SetColumnWidth(0, size.x-8); SjDialog::EnsureSelListCtrlItemVisible(m_listCtrl); event.Skip(); // forward event to the next handler }
// Find the selection long wxListCtrlGetSelection(wxListCtrl& listCtrl) { long n = listCtrl.GetItemCount(); long i; for (i = 0; i < n; i++) { if (listCtrl.GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) { return i; } } return -1; }
// Select the given item void wxListCtrlSelectItem(wxListCtrl& listCtrl, long sel, bool deselectOthers) { long n = listCtrl.GetItemCount(); long i; if (deselectOthers) { for (i = 0; i < n; i++) { if (listCtrl.GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED) { listCtrl.SetItemState(i, wxLIST_STATE_SELECTED, 0); } } } listCtrl.SetItemState(sel, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); }
void RestoreItemData(wxListCtrl &list, const Item *items, long count) { for (int ii = 0; ii < count; ++ii) { switch (items[ii].type) { case 0: list.SetItemData(ii, 1); break; case 1: list.SetItemData(ii, 0); break; case 2: default: list.SetItemData(ii, 2); } } }
// Create a drag image for the given list control item bool wxDragImage::Create(const wxListCtrl& listCtrl, long id) { if ( m_hImageList ) ImageList_Destroy(GetHimageList()); POINT pt; pt.x = 0; pt.y = 0; m_hImageList = (WXHIMAGELIST) ListView_CreateDragImage((HWND) listCtrl.GetHWND(), id, & pt); return true; }
SjSettingsSourceItem* SjMyMusicConfigPage::GetSelFromDialog() { long i = SjDialog::GetSelListCtrlItem(m_listCtrl); if( i >= 0 ) { return (SjSettingsSourceItem*)m_listCtrl->GetItemData(i); } return NULL; }
// Find the text of the list control item at the given column wxString wxListCtrlGetItemTextColumn(wxListCtrl& listCtrl, long item, int col) { wxListItem listItem; listItem.m_mask = wxLIST_MASK_TEXT; listItem.m_itemId = item; listItem.m_col = col; if (listCtrl.GetItem(listItem)) return listItem.m_text; else return wxEmptyString; }
wxPanel* SjViewSettingsPage::CreateSkinPage(wxWindow* parent) { // save given objects m_skinEnumerator = NULL; m_skinChangeFromMe = 0; m_loadSkinsMenuButton = NULL; // init dialog wxPanel* page = new wxPanel(parent, -1); wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL); page->SetSizer(sizer1); sizer1->Add(SJ_DLG_SPACE, SJ_DLG_SPACE); // some space wxStaticText* staticText = new wxStaticText(page, -1, wxString::Format(_("With different skins you can change the \"look and feel\" of %s. Just\nselect the skin to use from the list above. You'll find more skins on the web."), SJ_PROGRAM_NAME)); sizer1->Add(staticText, 0, wxALL, SJ_DLG_SPACE); /* add list control */ m_listCtrl = new wxListCtrl(page, IDC_SKINLIST, wxDefaultPosition, wxSize(200, 100), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL | wxSUNKEN_BORDER); m_listCtrl->SetImageList(g_tools->GetIconlist(FALSE), wxIMAGE_LIST_SMALL); //m_listCtrl->SetImageList(g_tools->GetIconlist(TRUE), wxIMAGE_LIST_NORMAL); m_listCtrl->InsertColumn(0, _("Name")); sizer1->Add(m_listCtrl, 1, wxGROW|wxALL, SJ_DLG_SPACE); wxSizer* sizer3 = new wxBoxSizer(wxHORIZONTAL); sizer1->Add(sizer3, 0, wxLEFT|wxRIGHT|wxBOTTOM, SJ_DLG_SPACE); m_loadSkinsMenuButton = new wxButton(page, IDC_LOADSKINSMENUBUTTON, _("Options")+wxString(SJ_BUTTON_MENU_ARROW)); sizer3->Add(m_loadSkinsMenuButton, 0, wxRIGHT, SJ_DLG_SPACE); // init data m_orgSkinPath = g_mainFrame->GetSkinUrl(); UpdateSkinList(m_orgSkinPath); return page; }
void VirtListCtrlTestCase::UpdateSelection() { m_list->SetItemCount(10); CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() ); m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() ); // The item 7 is now invalid and so shouldn't be counted as selected any // more. m_list->SetItemCount(5); CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() ); }
wxPanel* SjMyMusicConfigPage::CreatePage(wxWindow* parent) { wxPanel* page = new wxPanel(parent, -1); wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL); page->SetSizer(sizer1); sizer1->Add(1, SJ_DLG_SPACE); // some space wxStaticText* staticText = new wxStaticText(page, -1, _("Read music-files from the following folders and sources:")); sizer1->Add(staticText, 0, wxALL, SJ_DLG_SPACE); m_listCtrl = new wxListCtrl(page, IDC_IDXLIST, wxPoint(-1, -1), wxSize(200, 80), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL | wxSUNKEN_BORDER ); m_listCtrl->SetImageList(g_tools->GetIconlist(FALSE), wxIMAGE_LIST_SMALL); //m_listCtrl->SetImageList(g_tools->GetIconlist(TRUE), wxIMAGE_LIST_NORMAL); m_listCtrl->InsertColumn(0, _("Read music-files from the following sources:")); sizer1->Add(m_listCtrl, 1, wxGROW|wxLEFT|wxRIGHT|wxTOP, SJ_DLG_SPACE); wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL); sizer1->Add(buttonSizer, 0, wxRIGHT|wxGROW, SJ_DLG_SPACE); m_addButton = new wxButton(page, IDC_IDXADDSOURCES, _("Add source")+wxString(SJ_BUTTON_MENU_ARROW), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); buttonSizer->Add(m_addButton, 0, wxLEFT|wxTOP|wxBOTTOM, SJ_DLG_SPACE); m_removeButton = new wxButton(page, IDC_IDXDELSOURCE, _("Remove source"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); buttonSizer->Add(m_removeButton, 0, wxLEFT|wxTOP|wxBOTTOM, SJ_DLG_SPACE); m_configMenuButton = new wxButton(page, IDC_IDXCONFIGSOURCEMENU, _("Options")+wxString(SJ_BUTTON_MENU_ARROW), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); buttonSizer->Add(m_configMenuButton, 0, wxLEFT|wxTOP|wxBOTTOM, SJ_DLG_SPACE); m_updateButton = new wxButton(page, IDC_IDXUPDATEMENU, wxString::Format(" %s%s ", _("Update music library"), SJ_BUTTON_MENU_ARROW), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); buttonSizer->Add(m_updateButton, 0, wxALL, SJ_DLG_SPACE); return page; }
void SjMyMusicConfigPage::OnColClick(wxListEvent& event) { int newCol = event.GetColumn(); if( m_currSortCol == newCol ) { m_currSortCol = newCol | 0x00001000; /* toggle! */; } else { m_currSortCol = newCol; } m_listCtrl->SortItems(ListCtrlCompareFunction, m_currSortCol); // this may unselect Items on GTK, however, this should be fixed in wxWidgets/GTK }
SjSkinEnumeratorItem* SjViewSettingsPage::GetSkinFromDialog() { long i = SjDialog::GetSelListCtrlItem(m_listCtrl); if( i >= 0 ) { i = m_listCtrl->GetItemData(i); wxASSERT(m_skinEnumerator); SjSkinEnumeratorItem* currSkin = m_skinEnumerator->GetSkin(i); wxASSERT(currSkin); return currSkin; } return NULL; }
void SetItemType(Item &item, wxListCtrl &list, long index, long &searchIndex) { switch (list.GetItemData(index)) { case 0: item.type = 1; break; case 1: item.type = 0; ++searchIndex; break; case 2: default: item.type = 2; } }
// Create a drag image for the given list control item bool wxDragImage::Create(const wxListCtrl& listCtrl, long id) { if ( m_hImageList ) ImageList_Destroy(GetHimageList()); POINT pt; pt.x = pt.y = 0; m_hImageList = (WXHIMAGELIST) ListView_CreateDragImage(GetHwndOf(&listCtrl), id, &pt); if ( !m_hImageList ) { // as for wxTreeCtrl, fall back on dragging just the item text return Create(listCtrl.GetItemText(id)); } return true; }
// Find which column the cursor is on int wxListCtrlFindColumn(wxListCtrl& listCtrl, int noCols, int x) { int col = 0; // Find which column we're on int width = 0; int i; for (i = 0; i < noCols; i++) { width += listCtrl.GetColumnWidth(i); if (x <= width) { col = i; break; } } return col; }
void SjViewSettingsPage::UpdateSkinList(const wxString& selSkin) { m_skinChangeFromMe++; m_listCtrl->Freeze(); m_listCtrl->DeleteAllItems(); if( m_skinEnumerator ) { delete m_skinEnumerator; m_skinEnumerator = NULL; } m_skinEnumerator = new SjSkinEnumerator(); if( m_skinEnumerator ) { int currSkinIndex, new_i; for( currSkinIndex = 0; currSkinIndex < m_skinEnumerator->GetCount(); currSkinIndex++ ) { SjSkinEnumeratorItem* currSkin = m_skinEnumerator->GetSkin(currSkinIndex); wxListItem item; item.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT | wxLIST_MASK_DATA; item.m_itemId = currSkinIndex; item.m_text = currSkin->m_name; item.m_data = currSkinIndex; item.m_image = SJ_ICON_SKIN_FILE; new_i = m_listCtrl->InsertItem(item); if( currSkin->m_url == selSkin ) { m_listCtrl->SetItemState(new_i, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); } } wxSize size = m_listCtrl->GetClientSize(); m_listCtrl->SetColumnWidth(0, size.x-8); } m_listCtrl->Thaw(); m_skinChangeFromMe--; }
void ConvertViewCtrlToTrackData(const wxListCtrl &listctrl, const std::map< wxString, long > &mapping, std::vector<lfmt::TrackData> &tracklist, wxDateTime offset) { auto row_count = listctrl.GetItemCount(); if (row_count < 1) return; // grab column indices from string-long-map which we have just for purpose of dynamic indices (ie. changing column order is easy) auto idx_artist = mapping.find("Artist")->second; auto idx_tname = mapping.find("Trackname")->second; auto idx_album = mapping.find("Album")->second; auto idx_time = mapping.find("Time")->second; wxDateTime last_time = offset; // last track on the list is the most recentry track that was listened to; // moving up the list successive tracks will get earlier times for (int row = row_count-1; row >= 0; --row) { lfmt::TrackData td; // is there a better way of getting the info out of the listviewctrl? // it's questionable if I would have gotten it without the wxforum :( wxListItem item; item.SetId(row); item.SetMask(wxLIST_MASK_TEXT); // "unrolled loop" for all columns item.SetColumn(idx_artist); listctrl.GetItem(item); td.artist = item.GetText(); item.SetColumn(idx_tname); listctrl.GetItem(item); td.trackname = item.GetText(); item.SetColumn(idx_album); listctrl.GetItem(item); td.album = item.GetText(); td.timestamp = last_time.GetTicks(); // set time *before* calculating the descendant item.SetColumn(idx_time); listctrl.GetItem(item); { // now calculate 'last_time' offset according to playtime of the current track // defaults to 3 minutes if we don't know the track's length wxArrayString time_str = wxStringTokenize(item.GetText(), ":"); long minutes, seconds; bool success = true; success &= time_str[0].ToLong(&minutes); success &= time_str[1].ToLong(&seconds); if (success) last_time -= wxTimeSpan(0, minutes, seconds); else { wxLogWarning("Could not parse timespan " + item.GetText() + ". Assuming track length of 3 minutes."); last_time -= wxTimeSpan(0, 3, 0); } } tracklist.push_back(td); wxLogDebug("Converted track " + td.ToString() + " from row %d.", row); } }
// Create a drag image for the given list control item bool wxGenericDragImage::Create(const wxListCtrl& listCtrl, long id) { wxString str = listCtrl.GetItemText(id); return Create(str); }
void SjMyMusicConfigPage::InitPage(const wxString& selSourceUrl) { // create index list m_listOfSources.Clear(); m_listOfSources.DeleteContents(TRUE); SjModuleList* list = g_mainFrame->m_moduleSystem.GetModules(SJ_MODULETYPE_SCANNER); wxASSERT(list); SjModuleList::Node* moduleNode = list->GetFirst(); SjScannerModule* scannerModule; while( moduleNode ) { scannerModule = (SjScannerModule*)moduleNode->GetData(); wxASSERT(scannerModule); wxASSERT(scannerModule->IsLoaded()); long sourceCount = scannerModule->GetSourceCount(); long currSourceIndex; for( currSourceIndex = 0; currSourceIndex < sourceCount; currSourceIndex++ ) { SjSettingsSourceItem* item = new SjSettingsSourceItem(scannerModule, currSourceIndex, scannerModule->GetSourceUrl(currSourceIndex), scannerModule->GetSourceIcon(currSourceIndex)); m_listOfSources.Append(item); } // next moduleNode = moduleNode->GetNext(); } // get list control m_listCtrl->Freeze(); m_listCtrl->DeleteAllItems(); // go through all search directories SjSettingsSourceItem* item; SjSettingsSourceItemList::Node* itemnode = m_listOfSources.GetFirst(); int i = 0; wxString sourceNotes; while( itemnode ) { item = itemnode->GetData(); wxASSERT(item); wxListItem listitem; listitem.m_mask = wxLIST_MASK_IMAGE | wxLIST_MASK_TEXT | wxLIST_MASK_DATA; listitem.m_itemId = i; listitem.m_text = item->GetUrl(); listitem.SetData((void*)item); listitem.m_image = item->GetScannerModule()->GetSourceIcon(item->GetIndex()); sourceNotes = item->GetScannerModule()->GetSourceNotes(item->GetIndex()); if( !sourceNotes.IsEmpty() ) { listitem.m_text.Append(" ("); listitem.m_text.Append(sourceNotes); listitem.m_text.Append(')'); } m_listCtrl->InsertItem(listitem); itemnode = itemnode->GetNext(); i++; } m_listCtrl->SortItems(ListCtrlCompareFunction, m_currSortCol); m_listCtrl->Thaw(); // select the correct item // (should be done after SortItems() on GTK this may remove the selection ...) int i_cnt = m_listCtrl->GetItemCount(); for( i = 0; i < i_cnt; i ++ ) { item = (SjSettingsSourceItem*)m_listCtrl->GetItemData(i); if( item->GetUrl() == selSourceUrl ) { m_listCtrl->SetItemState(i, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); break; } } UpdateButtons(); }
void getFleetData(wxListCtrl& listCtrl) { DataPoll poll; string data = poll.getFleetData(1, LogInHandler::mUsername, LogInHandler::mPassword); if(!poll.getState()) { return; } istringstream input(data); jsonxx::Object o; assert(jsonxx::Object::parse(input, o)); assert(o.has<jsonxx::Array>("data")); long long int profit = 0; double distance = 0, velocity = 0; stringstream sstream; string finalString; //wxString tempHabitable; for(int i = 0; i < o.get<jsonxx::Array>("data").size(); ++i) { profit = o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<jsonxx::number>("profit"); velocity = o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<jsonxx::number>("velocity"); distance = o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<jsonxx::number>("distance"); cout << profit; cout << endl; int minutesToTarget = floor(distance / velocity); if(velocity == 0) { minutesToTarget = 0; } wxString sProfit; sProfit << profit; //wxString sProfit(wxT("4"), wxConvUTF8); wxString sVelocity; sVelocity << velocity; wxString sDistance; sDistance << distance; wxString sMinToTarget; sMinToTarget << minutesToTarget; wxString tempName(o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<string>("name").c_str(), wxConvUTF8); wxString tempStatus(o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<string>("status").c_str(), wxConvUTF8); //bool y = o.get<jsonxx::Array>("data").get<jsonxx::Object>(i).get<bool>("hasHabitable"); //if(y) // tempHabitable = wxString("Yes"); //else // tempHabitable = wxString("No"); wxListItem item; item.SetId(i); long index = listCtrl.InsertItem(item); listCtrl.SetItem(index, 0, tempName); listCtrl.SetItem(index, 1, tempStatus); listCtrl.SetItem(index, 2, sProfit); listCtrl.SetItem(index, 3, sDistance); listCtrl.SetItem(index, 4, sVelocity); listCtrl.SetItem(index, 5, sMinToTarget); //listCtrl.SetItem(index, 2, tempHabitable); sstream.str(""); } }