bsd lang segv fix, enable bsd lv2, lv2 gui enable fix, proxy/ffmpeg toggle resize...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / tipwindow.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 "bcbutton.h"
23 #include "bcdialog.h"
24 #include "bcdisplayinfo.h"
25 #include "bcresources.h"
26 #include "bcsignals.h"
27 #include "bctoggle.h"
28 #include "cstrdup.h"
29 #include "file.h"
30 #include "keys.h"
31 #include "language.h"
32 #include "mainsession.h"
33 #include "mwindow.h"
34 #include "preferences.h"
35 #include "theme.h"
36 #include "tipwindow.h"
37
38
39 // Table of tips of the day
40 static Tips tips;
41
42
43 TipWindow::TipWindow(MWindow *mwindow)
44  : BC_DialogThread()
45 {
46         this->mwindow = mwindow;
47 }
48
49 TipWindow::~TipWindow()
50 {
51         close_window();
52 }
53
54 void TipWindow::load_tips(const char *lang)
55 {
56         tips.remove_all_objects();
57         char tip[0x10000];  tip[0] = 0;
58         char string[BCTEXTLEN];
59         sprintf(string, "%s/%s.%s", File::get_cindat_path(), TIPS_FILE, lang);
60         FILE *fp = fopen(string, "r");
61         if( !fp ) {
62                 sprintf(tip, _("tip file missing:\n %s"), string);
63                 tips.add(tip);
64                 return;
65         }
66
67         while( fgets(string, sizeof(string), fp) ) {
68                 if( string[0] == '\n' && string[1] == 0 && strlen(tip) > 0 ) {
69                         tips.add(tip);
70                         tip[0] = 0;
71                         continue;
72                 }
73                 strcat(tip, string);
74         }
75
76         fclose(fp);
77 }
78
79 void TipWindow::handle_close_event(int result)
80 {
81         gui = 0;
82 }
83
84 BC_Window* TipWindow::new_gui()
85 {
86         BC_DisplayInfo display_info;
87         int x = display_info.get_abs_cursor_x();
88         int y = display_info.get_abs_cursor_y();
89         TipWindowGUI *gui = this->gui = new TipWindowGUI(mwindow, this, x, y);
90         gui->create_objects();
91         return gui;
92 }
93
94 const char* TipWindow::get_current_tip(int n)
95 {
96         mwindow->session->current_tip += n;
97         if( mwindow->session->current_tip < 0 )
98                 mwindow->session->current_tip = tips.size()-1;
99         else if( mwindow->session->current_tip >= tips.size() )
100                 mwindow->session->current_tip = 0;
101         const char *result = tips[mwindow->session->current_tip];
102         mwindow->save_defaults();
103         return result;
104 }
105
106 void TipWindow::next_tip()
107 {
108         gui->tip_text->update(get_current_tip(1));
109 }
110
111 void TipWindow::prev_tip()
112 {
113         gui->tip_text->update(get_current_tip(-1));
114 }
115
116
117
118 TipWindowGUI::TipWindowGUI(MWindow *mwindow, TipWindow *thread, int x, int y)
119  : BC_Window(_(PROGRAM_NAME ": Tip of the day"), x, y,
120                 640, 100, 640, 100, 0, 0, 1)
121 {
122         this->mwindow = mwindow;
123         this->thread = thread;
124 }
125
126 void TipWindowGUI::create_objects()
127 {
128         int x = 10, y = 10;
129         add_subwindow(tip_text = new BC_Title(x, y, thread->get_current_tip(0)));
130         y = get_h() - 30;
131         BC_CheckBox *checkbox;
132         add_subwindow(checkbox = new TipDisable(mwindow, this, x, y));
133         BC_Button *button;
134         y = get_h() - TipClose::calculate_h(mwindow) - 10;
135         x = get_w() - TipClose::calculate_w(mwindow) - 10;
136         add_subwindow(button = new TipClose(mwindow, this, x, y));
137         x -= TipNext::calculate_w(mwindow) + 10;
138         add_subwindow(button = new TipNext(mwindow, this, x, y));
139         x -= TipPrev::calculate_w(mwindow) + 10;
140         add_subwindow(button = new TipPrev(mwindow, this, x, y));
141         x += button->get_w() + 10;
142
143         show_window();
144         raise_window();
145 }
146
147 int TipWindowGUI::keypress_event()
148 {
149         switch(get_keypress()) {
150         case RETURN:
151         case ESC:
152         case 'w':
153                 set_done(0);
154                 break;
155         }
156         return 0;
157 }
158
159
160
161 TipDisable::TipDisable(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
162  : BC_CheckBox(x, y, mwindow->preferences->use_tipwindow,
163         _("Show tip of the day."))
164 {
165         this->mwindow = mwindow;
166         this->gui = gui;
167 }
168
169 int TipDisable::handle_event()
170 {
171         mwindow->preferences->use_tipwindow = get_value();
172         return 1;
173 }
174
175
176
177 TipNext::TipNext(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
178  : BC_Button(x, y, mwindow->theme->get_image_set("next_tip"))
179 {
180         this->mwindow = mwindow;
181         this->gui = gui;
182         set_tooltip(_("Next tip"));
183 }
184 int TipNext::handle_event()
185 {
186         gui->thread->next_tip();
187         return 1;
188 }
189
190 int TipNext::calculate_w(MWindow *mwindow)
191 {
192         return mwindow->theme->get_image_set("next_tip")[0]->get_w();
193 }
194
195
196
197 TipPrev::TipPrev(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
198  : BC_Button(x, y, mwindow->theme->get_image_set("prev_tip"))
199 {
200         this->mwindow = mwindow;
201         this->gui = gui;
202         set_tooltip(_("Previous tip"));
203 }
204
205 int TipPrev::handle_event()
206 {
207         gui->thread->prev_tip();
208         return 1;
209 }
210 int TipPrev::calculate_w(MWindow *mwindow)
211 {
212         return mwindow->theme->get_image_set("prev_tip")[0]->get_w();
213 }
214
215
216 TipClose::TipClose(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
217  : BC_Button(x, y, mwindow->theme->get_image_set("close_tip"))
218 {
219         this->mwindow = mwindow;
220         this->gui = gui;
221         set_tooltip(_("Close"));
222 }
223
224 int TipClose::handle_event()
225 {
226         gui->set_done(0);
227         return 1;
228 }
229
230 int TipClose::calculate_w(MWindow *mwindow)
231 {
232         return mwindow->theme->get_image_set("close_tip")[0]->get_w();
233 }
234 int TipClose::calculate_h(MWindow *mwindow)
235 {
236         return mwindow->theme->get_image_set("close_tip")[0]->get_h();
237 }
238
239
240