Merge pull request #4630 from Red-F/gotham-resume-pvr-lastplayedposition
[vuplus_xbmc] / xbmc / dialogs / GUIDialogSlider.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIDialogSlider.h"
22 #include "guilib/GUISliderControl.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "guilib/Key.h"
25 #include "guilib/LocalizeStrings.h"
26
27 #define CONTROL_HEADING 10
28 #define CONTROL_SLIDER  11
29 #define CONTROL_LABEL   12
30
31 CGUIDialogSlider::CGUIDialogSlider(void)
32     : CGUIDialog(WINDOW_DIALOG_SLIDER, "DialogSlider.xml")
33 {
34   m_callback = NULL;
35   m_callbackData = NULL;
36   m_loadType = KEEP_IN_MEMORY;
37 }
38
39 CGUIDialogSlider::~CGUIDialogSlider(void)
40 {
41 }
42
43 bool CGUIDialogSlider::OnAction(const CAction &action)
44 {
45   if (action.GetID() == ACTION_SELECT_ITEM)
46   {
47     Close();
48     return true;
49   }
50   return CGUIDialog::OnAction(action);
51 }
52
53 bool CGUIDialogSlider::OnMessage(CGUIMessage& message)
54 {
55   switch ( message.GetMessage() )
56   {
57   case GUI_MSG_CLICKED:
58     if (message.GetSenderId() == CONTROL_SLIDER)
59     {
60       CGUISliderControl *slider = (CGUISliderControl *)GetControl(CONTROL_SLIDER);
61       if (slider && m_callback)
62       {
63         m_callback->OnSliderChange(m_callbackData, slider);
64         SET_CONTROL_LABEL(CONTROL_LABEL, slider->GetDescription());
65       }
66     }
67     break;
68   case GUI_MSG_WINDOW_DEINIT:
69     m_callback = NULL;
70     m_callbackData = NULL;
71     break;
72   }
73   return CGUIDialog::OnMessage(message);
74 }
75
76 void CGUIDialogSlider::SetSlider(const CStdString &label, float value, float min, float delta, float max, ISliderCallback *callback, void *callbackData)
77 {
78   SET_CONTROL_LABEL(CONTROL_HEADING, label);
79   CGUISliderControl *slider = (CGUISliderControl *)GetControl(CONTROL_SLIDER);
80   m_callback = callback;
81   m_callbackData = callbackData;
82   if (slider)
83   {
84     slider->SetType(SPIN_CONTROL_TYPE_FLOAT);
85     slider->SetFloatRange(min, max);
86     slider->SetFloatInterval(delta);
87     slider->SetFloatValue(value);
88     if (m_callback)
89     {
90       m_callback->OnSliderChange(m_callbackData, slider);
91       SET_CONTROL_LABEL(CONTROL_LABEL, slider->GetDescription());
92     }
93   }
94 }
95
96 void CGUIDialogSlider::OnWindowLoaded()
97 {
98   // ensure our callbacks are NULL, incase we were loaded via some non-standard means
99   m_callback = NULL;
100   m_callbackData = NULL;
101   CGUIDialog::OnWindowLoaded();
102 }
103
104 void CGUIDialogSlider::ShowAndGetInput(const CStdString &label, float value, float min, float delta, float max, ISliderCallback *callback, void *callbackData)
105 {
106   // grab the slider dialog
107   CGUIDialogSlider *slider = (CGUIDialogSlider *)g_windowManager.GetWindow(WINDOW_DIALOG_SLIDER);
108   if (!slider)
109     return;
110
111   // set the label and value
112   slider->Initialize();
113   slider->SetSlider(label, value, min, delta, max, callback, callbackData);
114   slider->DoModal();
115 }
116
117 void CGUIDialogSlider::Display(int label, float value, float min, float delta, float max, ISliderCallback *callback)
118 {
119   // grab the slider dialog
120   CGUIDialogSlider *slider = (CGUIDialogSlider *)g_windowManager.GetWindow(WINDOW_DIALOG_SLIDER);
121   if (!slider)
122     return;
123
124   // set the label and value
125   slider->Initialize();
126   slider->SetAutoClose(1000);
127   slider->SetSlider(g_localizeStrings.Get(label), value, min, delta, max, callback, NULL);
128   slider->Show();
129 }