📄 channel_list.cpp
字号:
/* * Copyright (C) 2008 gulikoza, mtrooper * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* $Id$ */#include "main.h"#if (C_HAVE_WXGUI)#include "Channel_List.h"#include "../resource/friptv.xpm"int wxCALLBACK channelListViewCompareFunction(long item1, long item2, long sortData){ int result = 0; long col = sortData / 2; bool asc = (bool)(sortData % 2); switch (col) { case 0: result = item1 - item2; break; case 1: result = strcasecmp(sdl.channel->GetName(item1 - 1).c_str(), sdl.channel->GetName(item2 - 1).c_str()); break; } if(!asc) result = -result; return result;}Channel_List::Channel_List(wxWindow * parent, wxWindowID id, const wxString & title, const wxPoint & position, const wxSize & size, long style) : wxDialog(parent, id, title, position, size, style), num(0), sortColumn(0), sortAsc(true){ CreateGUIControls();}Channel_List::~Channel_List(){}void Channel_List::CreateGUIControls(){ SetTitle(wxT("Channel List")); SetIcon(wxIcon(friptv_xpm)); SetSize(185, 78, 390, 280); Center(); channelListView = new wxListView(this, ID_WXLISTCTRL, wxPoint(0, 0), wxSize(383, 247), wxLC_REPORT | wxLC_SINGLE_SEL | wxSUNKEN_BORDER); channelListView->InsertColumn(0, "No.", wxLIST_FORMAT_CENTRE); channelListView->InsertColumn(1, "Channel", wxLIST_FORMAT_LEFT); channelListView->Connect(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler(Channel_List::OnchannelListViewItemActivated), NULL, this); channelListView->Connect(wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler(Channel_List::OnchannelListViewColumnClick), NULL, this); Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(Channel_List::OnClose)); Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Channel_List::OnChannelListKeyDown)); Connect(wxEVT_ACTIVATE,wxActivateEventHandler(Channel_List::OnActivate)); channelListView->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(Channel_List::OnChannelListKeyDown), NULL, this);}void Channel_List::OnActivate(wxActivateEvent &event){ if(channelListView->GetItemCount() == 0) { wxString channelNumber, channelName = sdl.channel->GetName(num).c_str(); while(!channelName.IsEmpty()) { long chanNumber = num + 1; channelNumber.Printf("%d", chanNumber); long index = channelListView->InsertItem(0, channelNumber); channelListView->SetItem(index, 1, channelName); channelListView->SetItemData(index, chanNumber); num++; channelName = sdl.channel->GetName(num).c_str(); } channelListView->SetColumnWidth(0, 35); channelListView->SetColumnWidth(1, wxLIST_AUTOSIZE); long sortData = sortColumn * 2 + (long)sortAsc; channelListView->SortItems(channelListViewCompareFunction, sortData); }}void Channel_List::OnClose(wxCloseEvent& event){ Show(false);}void Channel_List::OnchannelListViewItemActivated(wxListEvent& event){ long index = event.GetIndex(); long channelNumber = channelListView->GetItemData(index); sdl.channel->SetChannel(channelNumber);#ifdef WIN32 ::SetForegroundWindow(sdl.hwnd);#endif}void Channel_List::FocusChanel(long channelNum){ long index = channelListView->FindItem(-1, channelNum); if(index != -1) { channelListView->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); channelListView->EnsureVisible(index); }}void Channel_List::OnchannelListViewColumnClick(wxListEvent& event){ if(sortColumn == event.GetColumn()) { sortAsc = !sortAsc; } else { sortColumn = event.GetColumn(); sortAsc = true; } long sortData = sortColumn * 2 + (long)sortAsc; channelListView->SortItems(channelListViewCompareFunction, sortData);}void Channel_List::OnChannelListKeyDown(wxKeyEvent& event){ if((event.GetKeyCode() == 'L') || (event.GetKeyCode() == WXK_ESCAPE)) { Show(false); }}#endif // C_HAVE_WXGUI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -