📄 preferences.cpp
字号:
tvins.item = tvi; tvins.hInsertAfter = hPrev; tvins.hParent = general_item; //level 3 // Add the item to the tree-view control. hPrev = (HTREEITEM)TreeView_InsertItem( hwndTV, &tvins ); break; } } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); TreeView_SortChildren( hwndTV, general_item, 0 ); } /* * Build a tree of all the plugins */ config_data = new ConfigTreeData; config_data->i_object_id = PLUGIN_ID; config_data->psz_help = strdup("nothing");//strdup( PLUGIN_HELP ); config_data->psz_section = strdup("nothing");//strdup( PLUGIN_TITLE ); tvi.pszText = _T("Modules"); tvi.cchTextMax = lstrlen(_T("Modules")); tvi.lParam = (long)config_data; tvins.item = tvi; tvins.hInsertAfter = TVI_LAST; tvins.hParent = TVI_ROOT; // Add the item to the tree-view control. hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins); plugins_item = hPrev; i_capability_count = 0; for( i_index = 0; i_index < p_list->i_count; i_index++ ) { i_child_index = 0; p_module = (module_t *)p_list->p_values[i_index].p_object; /* Exclude the main module */ if( !strcmp( p_module->psz_object_name, "main" ) ) continue; /* Exclude empty plugins (submodules don't have config options, they * are stored in the parent module) */ if( p_module->b_submodule ) p_item = ((module_t *)p_module->p_parent)->p_config; else p_item = p_module->p_config; if( !p_item ) continue; do { if( p_item->i_type & CONFIG_ITEM ) break; } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); if( p_item->i_type == CONFIG_HINT_END ) continue; /* Find the capability child item */ /*long cookie; size_t i_child_index;*/ capability_item = TreeView_GetChild( hwndTV, plugins_item ); while( capability_item != 0 ) { TVITEM capability_tvi = {0}; TCHAR psz_text[256]; i_child_index++; capability_tvi.mask = TVIF_TEXT; capability_tvi.pszText = psz_text; capability_tvi.cchTextMax = 256; capability_tvi.hItem = capability_item; TreeView_GetItem( hwndTV, &capability_tvi ); if( !strcmp( _TOMB(capability_tvi.pszText), p_module->psz_capability ) ) break; capability_item = TreeView_GetNextSibling( hwndTV, capability_item ); } if( i_child_index == i_capability_count && p_module->psz_capability && *p_module->psz_capability ) { /* We didn't find it, add it */ ConfigTreeData *config_data = new ConfigTreeData; config_data->psz_section = strdup( GetCapabilityHelp( p_module->psz_capability , 1 ) ); config_data->psz_help = strdup( GetCapabilityHelp( p_module->psz_capability , 2 ) ); config_data->i_object_id = CAPABILITY_ID; tvi.pszText = _FROMMB(p_module->psz_capability); tvi.cchTextMax = _tcslen(tvi.pszText); tvi.lParam = (long)config_data; tvins.item = tvi; tvins.hInsertAfter = plugins_item; tvins.hParent = plugins_item;// level 3 // Add the item to the tree-view control. capability_item = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins); i_capability_count++; } /* Add the plugin to the tree */ ConfigTreeData *config_data = new ConfigTreeData; config_data->b_submodule = p_module->b_submodule; config_data->i_object_id = p_module->b_submodule ? ((module_t *)p_module->p_parent)->i_object_id : p_module->i_object_id; config_data->psz_help = NULL; tvi.pszText = _FROMMB(p_module->psz_object_name); tvi.cchTextMax = _tcslen(tvi.pszText); tvi.lParam = (long)config_data; tvins.item = tvi; tvins.hInsertAfter = capability_item; tvins.hParent = capability_item;// level 4 // Add the item to the tree-view control. TreeView_InsertItem( hwndTV, &tvins ); } /* Sort all this mess */ /*long cookie; size_t i_child_index;*/ TreeView_SortChildren( hwndTV, plugins_item, 0 ); capability_item = TreeView_GetChild( hwndTV, plugins_item ); while( capability_item != 0 ) { TreeView_SortChildren( hwndTV, capability_item, 0 ); capability_item = TreeView_GetNextSibling( hwndTV, capability_item ); } /* Clean-up everything */ vlc_list_release( p_list ); TreeView_Expand( hwndTV, general_item, TVE_EXPANDPARTIAL |TVE_EXPAND );}PrefsTreeCtrl::~PrefsTreeCtrl(){}void PrefsTreeCtrl::ApplyChanges(){ /*long cookie, cookie2;*/ ConfigTreeData *config_data; /* Apply changes to the main module */ HTREEITEM item = TreeView_GetChild( hwndTV, general_item ); while( item != 0 ) { TVITEM tvi = {0}; tvi.mask = TVIF_PARAM; tvi.hItem = item; TreeView_GetItem( hwndTV, &tvi ); config_data = (ConfigTreeData *)tvi.lParam; if( config_data && config_data->panel ) { config_data->panel->ApplyChanges(); } item = TreeView_GetNextSibling( hwndTV, item ); } /* Apply changes to the plugins */ item = TreeView_GetChild( hwndTV, plugins_item ); while( item != 0 ) { HTREEITEM item2 = TreeView_GetChild( hwndTV, item ); while( item2 != 0 ) { TVITEM tvi = {0}; tvi.mask = TVIF_PARAM; tvi.hItem = item2; TreeView_GetItem( hwndTV, &tvi ); config_data = (ConfigTreeData *)tvi.lParam; if( config_data && config_data->panel ) { config_data->panel->ApplyChanges(); } item2 = TreeView_GetNextSibling( hwndTV, item2 ); } item = TreeView_GetNextSibling( hwndTV, item ); }}ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data ){ /* We need this complexity because submodules don't have their own config * options. They use the parent module ones. */ if( !config_data || !config_data->b_submodule ) { return config_data; } /*long cookie, cookie2;*/ ConfigTreeData *config_new; HTREEITEM item = TreeView_GetChild( hwndTV, plugins_item ); while( item != 0 ) { HTREEITEM item2 = TreeView_GetChild( hwndTV, item ); while( item2 != 0 ) { TVITEM tvi = {0}; tvi.mask = TVIF_PARAM; tvi.hItem = item2; TreeView_GetItem( hwndTV, &tvi ); config_new = (ConfigTreeData *)tvi.lParam; if( config_new && !config_new->b_submodule && config_new->i_object_id == config_data->i_object_id ) { return config_new; } item2 = TreeView_GetNextSibling( hwndTV, item2 ); } item = TreeView_GetNextSibling( hwndTV, item ); } /* Found nothing */ return NULL;}void PrefsTreeCtrl::OnSelectTreeItem( LPNM_TREEVIEW pnmtv, HWND parent, HINSTANCE hInst ){ ConfigTreeData *config_data = NULL; if( pnmtv->itemOld.hItem ) config_data = FindModuleConfig( (ConfigTreeData *)pnmtv->itemOld.lParam ); if( config_data && config_data->panel ) { config_data->panel->Hide(); } /* Don't use event.GetItem() because we also send fake events */ TVITEM tvi = {0}; tvi.mask = TVIF_PARAM; tvi.hItem = TreeView_GetSelection( hwndTV ); TreeView_GetItem( hwndTV, &tvi ); config_data = FindModuleConfig( (ConfigTreeData *)tvi.lParam ); if( config_data ) { if( !config_data->panel ) { /* The panel hasn't been created yet. Let's do it. */ config_data->panel = new PrefsPanel( parent, hInst, p_intf, p_prefs_dialog, config_data->i_object_id, config_data->psz_section, config_data->psz_help ); } else { config_data->panel->Show(); } }}/***************************************************************************** * PrefsPanel class definition. *****************************************************************************/PrefsPanel::PrefsPanel( HWND parent, HINSTANCE hInst, intf_thread_t *_p_intf, PrefsDialog *_p_prefs_dialog, int i_object_id, char *psz_section, char *psz_help ){ module_config_t *p_item; module_t *p_module = NULL; /* Initializations */ p_intf = _p_intf; p_prefs_dialog = _p_prefs_dialog; b_advanced = VLC_TRUE; if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID || i_object_id == CAPABILITY_ID ) { label = CreateWindow( _T("STATIC"), _FROMMB(psz_section), WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 10 + (15 + 10), 200, 15, parent, NULL, hInst, NULL ); config_window = NULL; } else { /* Get a pointer to the module */ p_module = (module_t *)vlc_object_get( p_intf, i_object_id ); if( p_module->i_object_type != VLC_OBJECT_MODULE ) { /* 0OOoo something went really bad */ return; } /* Enumerate config options and add corresponding config boxes * (submodules don't have config options, they are stored in the * parent module) */ if( p_module->b_submodule ) p_item = ((module_t *)p_module->p_parent)->p_config; else p_item = p_module->p_config; /* Find the category if it has been specified */ if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY ) { while( !(p_item->i_type == CONFIG_HINT_CATEGORY) || strcmp( psz_section, p_item->psz_text ) ) { if( p_item->i_type == CONFIG_HINT_END ) break; p_item++; } } /* Add a head title to the panel */ label = CreateWindow( _T("STATIC"), _FROMMB(psz_section ? p_item->psz_text : p_module->psz_longname), WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 10 + (15 + 10), 250, 15, parent, NULL, hInst, NULL ); WNDCLASS wc; memset( &wc, 0, sizeof(wc) ); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) _p_prefs_dialog->BaseWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst; wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = _T("PrefsPanelClass"); RegisterClass(&wc); RECT rc; GetWindowRect( parent, &rc); config_window = CreateWindow( _T("PrefsPanelClass"), _T("config_window"), WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER, 5, 10 + 2*(15 + 10), rc.right - 5 - 7, 105, parent, NULL, hInst, (void *) _p_prefs_dialog ); int y_pos = 5; if( p_item ) do { /* If a category has been specified, check we finished the job */ if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY && strcmp( psz_section, p_item->psz_text ) ) break; ConfigControl *control = CreateConfigControl( VLC_OBJECT(p_intf), p_item, config_window, hInst, &y_pos ); /* Don't add items that were not recognized */ if( control == NULL ) continue; /* Add the config data to our array so we can keep a trace of it */ config_array.push_back( control ); } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); GetWindowRect( config_window, &rc); maxvalue = y_pos - (rc.bottom - rc.top) + 5; oldvalue = 0; SetScrollRange( config_window, SB_VERT, 0, maxvalue, TRUE ); }}void PrefsPanel::Hide(){ ShowWindow( label, SW_HIDE ); if( config_window ) ShowWindow( config_window, SW_HIDE );}void PrefsPanel::Show(){ ShowWindow( label, SW_SHOW ); if( config_window ) ShowWindow( config_window, SW_SHOW );}void PrefsPanel::ApplyChanges(){ vlc_value_t val; for( size_t i = 0; i < config_array.size(); i++ ) { ConfigControl *control = config_array[i]; switch( control->GetType() ) { case CONFIG_ITEM_STRING: case CONFIG_ITEM_FILE: case CONFIG_ITEM_DIRECTORY: case CONFIG_ITEM_MODULE: config_PutPsz( p_intf, control->GetName(), control->GetPszValue() ); break; case CONFIG_ITEM_KEY: /* So you don't need to restart to have the changes take effect */ val.i_int = control->GetIntValue(); var_Set( p_intf->p_vlc, control->GetName(), val ); case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_BOOL: config_PutInt( p_intf, control->GetName(), control->GetIntValue() ); break; case CONFIG_ITEM_FLOAT: config_PutFloat( p_intf, control->GetName(), control->GetFloatValue() ); break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -