initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / bitspopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "bitspopup.h"
23 #include "clip.h"
24 #include "file.h"
25
26
27 BitsPopup::BitsPopup(BC_WindowBase *parent_window, 
28         int x, 
29         int y, 
30         int *output, 
31         int use_ima4, 
32         int use_ulaw,
33         int use_adpcm, 
34         int use_float,
35         int use_32linear,
36         int use_8linear)
37 {
38         this->parent_window = parent_window;
39         this->output = output;
40         this->x = x;
41         this->y = y;
42         this->use_ima4 = use_ima4;
43         this->use_ulaw = use_ulaw;
44         this->use_adpcm = use_adpcm;
45         this->use_float = use_float;
46         this->use_32linear = use_32linear;
47         this->use_8linear = use_8linear;
48 }
49
50 BitsPopup::~BitsPopup()
51 {
52         delete menu;
53         delete textbox;
54         for(int i = 0; i < bits_items.total; i++)
55                 delete bits_items.values[i];
56 }
57
58 void BitsPopup::create_objects()
59 {
60         if(use_8linear) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSLINEAR8)));
61         bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSLINEAR16)));
62         bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSLINEAR24)));
63         if(use_32linear) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSLINEAR32)));
64         if(use_ima4) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSIMA4)));
65         if(use_ulaw) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSULAW)));
66         if(use_adpcm) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITS_ADPCM)));
67         if(use_float) bits_items.append(new BC_ListBoxItem(File::bitstostr(BITSFLOAT)));
68
69         parent_window->add_subwindow(textbox = new BitsPopupText(this, x, y));
70         x += textbox->get_w();
71         parent_window->add_subwindow(menu = new BitsPopupMenu(this, x, y));
72 }
73
74 int BitsPopup::get_w()
75 {
76         return menu->get_w() + textbox->get_w();
77 }
78
79 int BitsPopup::get_h()
80 {
81         return MAX(menu->get_h(), textbox->get_h());
82 }
83
84 BitsPopupMenu::BitsPopupMenu(BitsPopup *popup, int x, int y)
85  : BC_ListBox(x,
86         y,
87         120,
88         100,
89         LISTBOX_TEXT,
90         &popup->bits_items,
91         0,
92         0,
93         1,
94         0,
95         1)
96 {
97         this->popup = popup;
98 }
99
100 int BitsPopupMenu::handle_event()
101 {
102         popup->textbox->update(get_selection(0, 0)->get_text());
103         popup->textbox->handle_event();
104         return 1;
105 }
106
107 BitsPopupText::BitsPopupText(BitsPopup *popup, int x, int y)
108  : BC_TextBox(x, y, 120, 1, File::bitstostr(*popup->output))
109 {
110         this->popup = popup;
111 }
112
113 int BitsPopupText::handle_event()
114 {
115         *popup->output = File::strtobits(get_text());
116         return 1;
117 }