⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferences.cpp

📁 VLC媒体播放程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                          wxU(p_module->psz_capability),                                          -1,-1,config_data );        }        /* 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;        AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,                    config_data );    }    /* Sort all this mess */    long cookie; size_t i_child_index;    SortChildren( plugins_item );    wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);    for( i_child_index = 0;         i_child_index < GetChildrenCount( plugins_item, FALSE );         i_child_index++ )    {        SortChildren( capability_item );        capability_item = GetNextChild( plugins_item, cookie );    }    /* Clean-up everything */    vlc_list_release( p_list );    p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );    p_sizer->Layout();    /* Update Tree Ctrl */#ifndef WIN32 /* Workaround a bug in win32 implementation */    SelectItem( GetFirstChild( root_item, cookie ) );#endif    Expand( general_item );}PrefsTreeCtrl::~PrefsTreeCtrl(){}void PrefsTreeCtrl::ApplyChanges(){    long cookie, cookie2;    ConfigTreeData *config_data;    /* Apply changes to the main module */    wxTreeItemId item = GetFirstChild( general_item, cookie );    for( size_t i_child_index = 0;         i_child_index < GetChildrenCount( general_item, FALSE );         i_child_index++ )    {        config_data = (ConfigTreeData *)GetItemData( item );        if( config_data && config_data->panel )        {            config_data->panel->ApplyChanges();        }        item = GetNextChild( general_item, cookie );    }    /* Apply changes to the plugins */    item = GetFirstChild( plugins_item, cookie );    for( size_t i_child_index = 0;         i_child_index < GetChildrenCount( plugins_item, FALSE );         i_child_index++ )    {        wxTreeItemId item2 = GetFirstChild( item, cookie2 );        for( size_t i_child_index = 0;             i_child_index < GetChildrenCount( item, FALSE );             i_child_index++ )        {            config_data = (ConfigTreeData *)GetItemData( item2 );            if( config_data && config_data->panel )            {                config_data->panel->ApplyChanges();            }            item2 = GetNextChild( item, cookie2 );        }        item = GetNextChild( plugins_item, cookie );    }}void PrefsTreeCtrl::CleanChanges(){    long cookie, cookie2;    ConfigTreeData *config_data;    config_data = !GetSelection() ? NULL :        FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );    if( config_data  )    {        config_data->panel->Hide();        p_sizer->Remove( config_data->panel );    }    /* Clean changes for the main module */    wxTreeItemId item = GetFirstChild( general_item, cookie );    for( size_t i_child_index = 0;         i_child_index < GetChildrenCount( general_item, FALSE );         i_child_index++ )    {        config_data = (ConfigTreeData *)GetItemData( item );        if( config_data && config_data->panel )        {            delete config_data->panel;            config_data->panel = NULL;        }        item = GetNextChild( general_item, cookie );    }    /* Clean changes for the plugins */    item = GetFirstChild( plugins_item, cookie );    for( size_t i_child_index = 0;         i_child_index < GetChildrenCount( plugins_item, FALSE );         i_child_index++ )    {        wxTreeItemId item2 = GetFirstChild( item, cookie2 );        for( size_t i_child_index = 0;             i_child_index < GetChildrenCount( item, FALSE );             i_child_index++ )        {            config_data = (ConfigTreeData *)GetItemData( item2 );            if( config_data && config_data->panel )            {                delete config_data->panel;                config_data->panel = NULL;            }            item2 = GetNextChild( item, cookie2 );        }        item = GetNextChild( plugins_item, cookie );    }    if( GetSelection() )    {        wxTreeEvent event;        OnSelectTreeItem( event );    }}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;    wxTreeItemId item = GetFirstChild( plugins_item, cookie );    for( size_t i_child_index = 0;         i_child_index < GetChildrenCount( plugins_item, FALSE );         i_child_index++ )    {        wxTreeItemId item2 = GetFirstChild( item, cookie2 );        for( size_t i_child_index = 0;             i_child_index < GetChildrenCount( item, FALSE );             i_child_index++ )        {            config_new = (ConfigTreeData *)GetItemData( item2 );            if( config_new && !config_new->b_submodule &&                config_new->i_object_id == config_data->i_object_id )            {                return config_new;            }            item2 = GetNextChild( item, cookie2 );        }        item = GetNextChild( plugins_item, cookie );    }    /* Found nothing */    return NULL;}void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ){    ConfigTreeData *config_data = NULL;    if( event.GetOldItem() )        config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(                                        event.GetOldItem() ) );    if( config_data && config_data->panel )    {        config_data->panel->Hide();        p_sizer->Remove( config_data->panel );    }    /* Don't use event.GetItem() because we also send fake events */    config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(                                    GetSelection() ) );    if( config_data )    {        if( !config_data->panel )        {            /* The panel hasn't been created yet. Let's do it. */            config_data->panel =                new PrefsPanel( p_parent, p_intf, p_prefs_dialog,                                config_data->i_object_id,                                config_data->psz_section,                                config_data->psz_help );            config_data->panel->SwitchAdvanced( b_advanced );        }        else        {            config_data->panel->SwitchAdvanced( b_advanced );            config_data->panel->Show();        }        p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );        p_sizer->Layout();    }}void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event ){    b_advanced = event.GetInt();    ConfigTreeData *config_data = !GetSelection() ? NULL :        FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );    if( config_data  )    {        config_data->panel->Hide();        p_sizer->Remove( config_data->panel );    }    if( GetSelection() )    {        wxTreeEvent event;        OnSelectTreeItem( event );    }}/***************************************************************************** * PrefsPanel class definition. *****************************************************************************/PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,                        PrefsDialog *_p_prefs_dialog,                        int i_object_id, char *psz_section, char *psz_help )  :  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ){    module_config_t *p_item;    wxStaticText *label;    wxStaticText *help;    wxArrayString array;    module_t *p_module = NULL;    /* Initializations */    p_intf = _p_intf;    p_prefs_dialog =_p_prefs_dialog,    b_advanced = VLC_TRUE;    SetAutoLayout( TRUE );    wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );    if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||        i_object_id == CAPABILITY_ID )    {        label = new wxStaticText( this, -1,wxU(_( psz_section )));        wxFont heading_font = label->GetFont();        heading_font.SetPointSize( heading_font.GetPointSize() + 5 );        label->SetFont( heading_font );        sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );        sizer->Add( new wxStaticLine( this, 0 ), 0,                    wxEXPAND | wxLEFT | wxRIGHT, 2 );        help = new wxStaticText( this, -1, wxU(_( psz_help ) ) );        sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );        config_sizer = 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 = new wxStaticText( this, -1,                                  wxU(_(psz_section ? p_item->psz_text :                                  p_module->psz_longname )));        wxFont heading_font = label->GetFont();        heading_font.SetPointSize( heading_font.GetPointSize() + 5 );        label->SetFont( heading_font );        sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );        sizer->Add( new wxStaticLine( this, 0 ), 0,                    wxEXPAND | wxLEFT | wxRIGHT, 2 );        /* Now put all the config options into a scrolled window */        config_sizer = new wxBoxSizer( wxVERTICAL );        config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,            wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );        config_window->SetAutoLayout( TRUE );        config_window->SetScrollRate( 5, 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 );            /* 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.Add( control );            config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );        }        while( p_item->i_type != CONFIG_HINT_END && p_item++ );        config_sizer->Layout();        config_window->SetSizer( config_sizer );        sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );        /* And at last put a useful help string if available */        if( psz_help && *psz_help )        {            sizer->Add( new wxStaticLine( this, 0 ), 0,                        wxEXPAND | wxLEFT | wxRIGHT, 2 );            help = new wxStaticText( this, -1, wxU(_(psz_help)),                                     wxDefaultPosition, wxDefaultSize,                                     wxALIGN_LEFT,                                     wxT("") );            sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );        }    }    sizer->Layout();    SetSizer( sizer );}void PrefsPanel::ApplyChanges(){    vlc_value_t val;    for( size_t i = 0; i < config_array.GetCount(); i++ )    {        ConfigControl *control = config_array.Item(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().mb_str(),                           control->GetPszValue().mb_str() );            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().mb_str(), val );        case CONFIG_ITEM_INTEGER:        case CONFIG_ITEM_BOOL:            config_PutInt( p_intf, control->GetName().mb_str(),                           control->GetIntValue() );            break;        case CONFIG_ITEM_FLOAT:            config_PutFloat( p_intf, control->GetName().mb_str(),                             control->GetFloatValue() );            break;        }    }}void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced ){    if( b_advanced == b_new_advanced ) return;    if( config_sizer && config_window )    {        b_advanced = b_new_advanced;        for( size_t i = 0; i < config_array.GetCount(); i++ )        {            ConfigControl *control = config_array.Item(i);            if( control->IsAdvanced() )            {                control->Show( b_advanced );                config_sizer->Show( control, b_advanced );            }        }        config_sizer->Layout();        config_window->FitInside();        config_window->Refresh();    }    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -