]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/interaction.cpp
Beginning of a WX implementation
[vlc] / modules / gui / wxwidgets / dialogs / interaction.cpp
1 /*****************************************************************************
2  * interaction.cpp: wxWidgets handling of interaction dialogs
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id: bookmarks.cpp 13106 2005-11-02 19:20:34Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "dialogs/interaction.hpp"
28
29 #include <wx/statline.h>
30
31 /*****************************************************************************
32  * Event Table.
33  *****************************************************************************/
34
35 /* IDs for the controls and the menu commands */
36 enum
37 {
38      OkYes_Event,
39      No_Event,
40      Cancel_Event
41 };
42
43 BEGIN_EVENT_TABLE( InteractionDialog, wxFrame)
44     EVT_CLOSE( InteractionDialog::OnClose )
45     EVT_BUTTON( OkYes_Event, InteractionDialog::OnOkYes )
46     EVT_BUTTON( Cancel_Event, InteractionDialog::OnCancel)
47     EVT_BUTTON( No_Event, InteractionDialog::OnNo )
48 END_EVENT_TABLE()
49
50 /*****************************************************************************
51  * Constructor.
52  *****************************************************************************/
53 InteractionDialog::InteractionDialog( intf_thread_t *_p_intf,
54                                       wxWindow *p_parent,
55                                       interaction_dialog_t *_p_dialog )
56   : wxFrame( p_parent, -1, wxU( _p_dialog->psz_title ) )
57 {
58     /* Initializations */
59     p_intf = _p_intf;
60     p_dialog = _p_dialog;
61     SetIcon( *p_intf->p_sys->p_icon );
62
63     widgets_panel = new wxPanel( this, -1 );
64     widgets_sizer = new wxBoxSizer( wxVERTICAL );
65     widgets_panel->SetSizer( widgets_sizer );
66
67     buttons_panel = new wxPanel( this, -1 );
68     buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
69     buttons_panel->SetSizer( buttons_sizer );
70
71     main_sizer = new wxBoxSizer( wxVERTICAL );
72     main_sizer->Add( widgets_panel, 0, wxEXPAND | wxALL, 5 );
73     main_sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND  );
74     main_sizer->Add( buttons_panel, 0, wxEXPAND | wxALL, 5 );
75     SetSizer( main_sizer );
76
77     Render();
78 }
79
80 InteractionDialog::~InteractionDialog()
81 {
82 }
83
84 void InteractionDialog::Update( )
85 {
86     widgets_panel->DestroyChildren();
87     buttons_panel->DestroyChildren();
88     input_widgets.clear();
89     Render();
90     Show();
91 }
92
93 /// \todo Dirty - Clean that up
94 void InteractionDialog::Render()
95 {
96     wxStaticText *label;
97     wxTextCtrl *input;
98
99     //-------------- Widgets ------------------
100     for( int i = 0 ; i< p_dialog->i_widgets; i++ )
101     {
102         user_widget_t* p_widget = p_dialog->pp_widgets[i];
103         /// \todo Merge cleanly with preferences widgets
104         switch( p_widget->i_type )
105         {
106         case WIDGET_TEXT:
107             label = new wxStaticText( widgets_panel, -1,
108                                       wxU( p_widget->psz_text ) );
109             widgets_sizer->Add( label );
110             break;
111         case WIDGET_INPUT_TEXT:
112             label = new wxStaticText( widgets_panel, -1,
113                                       wxU( p_widget->psz_text ) );
114             input = new wxTextCtrl( widgets_panel, -1 );
115             widgets_sizer->Add( label );
116             widgets_sizer->Add( input );
117
118             InputWidget widget;
119             widget.control = input;
120             widget.val = &p_widget->val;
121             input_widgets.push_back( widget );
122         }
123     }
124     widgets_sizer->Layout();
125     widgets_panel->SetSizerAndFit( widgets_sizer );
126     main_sizer->Layout();
127     SetSizerAndFit( main_sizer );
128
129     //-------------- Buttons ------------------
130     if( p_dialog->i_flags & DIALOG_OK_CANCEL )
131     {
132         wxButton *ok = new wxButton( buttons_panel,
133                                      OkYes_Event, wxU( _("OK") ) );
134         wxButton *cancel = new wxButton( buttons_panel,
135                                          Cancel_Event, wxU( _("Cancel") ) );
136         buttons_sizer->Add( ok, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
137         buttons_sizer->Add( cancel, 0, wxEXPAND | wxRIGHT| wxLEFT, 5 );
138     }
139
140 }
141
142 /*****************************************************************************
143  * Private methods.
144  *****************************************************************************/
145 void InteractionDialog::OnClose( wxCloseEvent& event )
146 {
147     Finish( DIALOG_CANCELLED );
148 }
149
150 void InteractionDialog::OnCancel( wxCommandEvent& event )
151 {
152     Finish( DIALOG_CANCELLED );
153 }
154
155 void InteractionDialog::OnNo( wxCommandEvent& event )
156 {
157     Finish( DIALOG_NO );
158 }
159
160 void InteractionDialog::OnOkYes( wxCommandEvent& event )
161 {
162     Finish( DIALOG_OK_YES );
163 }
164
165 void InteractionDialog::Finish( int i_ret )
166 {
167     vector<InputWidget>::iterator it = input_widgets.begin();
168     while ( it < input_widgets.end() )
169     {
170         (*it).val->psz_string = strdup( (*it).control->GetValue().mb_str() );
171         it++;
172     }
173     Hide();
174     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
175     p_dialog->i_status = ANSWERED_DIALOG;
176     p_dialog->i_return = i_ret;
177     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
178 }