1 /*****************************************************************************
2 * text.cpp: Text control
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: text.cpp,v 1.11 2003/06/07 12:19:23 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
9 * Cyril Deguet <asmax@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
25 *****************************************************************************/
28 //--- VLC -------------------------------------------------------------------
31 //--- SKIN ------------------------------------------------------------------
32 #include "../os_api.h"
33 #include "../src/bitmap.h"
34 #include "../src/banks.h"
35 #include "../src/graphics.h"
36 #include "../os_graphics.h"
37 #include "../src/font.h"
38 #include "../os_font.h"
41 #include "../src/event.h"
42 #include "../src/theme.h"
43 #include "../src/window.h"
44 #include "../os_window.h"
45 #include "../src/skin_common.h"
48 #include "../x11/x11_timer.h"
49 extern intf_thread_t *g_pIntf;
54 //---------------------------------------------------------------------------
55 // Scrolling : one for each OS
56 //---------------------------------------------------------------------------
59 //-----------------------------------------------------------------------
61 //-----------------------------------------------------------------------
62 void CALLBACK ScrollingTextTimer( HWND hwnd, UINT uMsg, UINT_PTR idEvent,
65 if( (ControlText *)idEvent != NULL
66 && !( (ControlText *)idEvent )->GetSelected() )
68 ( (ControlText *)idEvent )->DoScroll();
72 //-----------------------------------------------------------------------
73 void ControlText::StartScrolling()
75 SetTimer( ( (Win32Window *)ParentWindow )->GetHandle(), (UINT_PTR)this,
76 100, (TIMERPROC)ScrollingTextTimer );
78 //-----------------------------------------------------------------------
79 void ControlText::StopScrolling()
81 KillTimer( ( (Win32Window *)ParentWindow )->GetHandle(),
84 //-----------------------------------------------------------------------
86 #elif defined GTK2_SKINS
88 //-----------------------------------------------------------------------
90 //-----------------------------------------------------------------------
91 gboolean ScrollingTextTimer( gpointer data )
93 if( (ControlText *)data != NULL )
95 if( !( (ControlText *)data )->IsScrolling() )
98 if( !( (ControlText *)data )->GetSelected() )
99 ( (ControlText *)data )->DoScroll();
108 //-----------------------------------------------------------------------
109 void ControlText::StartScrolling()
111 g_timeout_add( 100, (GSourceFunc)ScrollingTextTimer, (gpointer)this );
113 //-----------------------------------------------------------------------
114 void ControlText::StopScrolling()
117 //-----------------------------------------------------------------------
119 #elif defined X11_SKINS
121 //-----------------------------------------------------------------------
123 //-----------------------------------------------------------------------
124 bool ScrollingTextTimer( void *data )
126 if( (ControlText *)data != NULL
127 && !( (ControlText *)data )->GetSelected() )
129 ( (ControlText *)data )->DoScroll();
134 //-----------------------------------------------------------------------
135 void ControlText::StartScrolling()
137 X11Timer *timer = new X11Timer( g_pIntf, 100000, ScrollingTextTimer,
139 X11TimerManager *timerManager = X11TimerManager::Instance( g_pIntf );
140 timerManager->addTimer( timer );
142 //-----------------------------------------------------------------------
143 void ControlText::StopScrolling()
146 //-----------------------------------------------------------------------
149 //---------------------------------------------------------------------------
154 //---------------------------------------------------------------------------
156 //---------------------------------------------------------------------------
157 ControlText::ControlText( string id, bool visible, int x, int y, string text,
158 string font, int align, int width, string display, bool scroll,
159 int scrollspace, string help, SkinWindow *Parent )
160 : GenericControl( id, visible, help, Parent )
170 // Scrolling parameters
173 ScrollSpace = scrollspace;
176 // Initialize display
177 if( display != "none" )
180 int pos = display.find( ';', 0 );
183 DisplayList.push_back( display.substr( begin, pos - begin ) );
185 pos = display.find( ';', begin );
187 DisplayList.push_back(
188 display.substr( begin, display.size() - begin ) );
189 Display = DisplayList.begin();
193 //---------------------------------------------------------------------------
194 ControlText::~ControlText()
196 if( TextClipRgn != NULL )
201 //---------------------------------------------------------------------------
202 void ControlText::Init()
204 TextFont = p_intf->p_sys->p_theme->FntBank->Get( FontName );
206 // Init clipping region
209 // Get size of control
213 //---------------------------------------------------------------------------
214 void ControlText::SetScrolling()
216 if( !Scroll && TextWidth > Width )
224 else if( Scroll && TextWidth <= Width )
230 //---------------------------------------------------------------------------
231 void ControlText::SetSize()
233 // Get size parameters
235 TextFont->GetSize( Text, w, h );
238 // Get width if not set
247 // Set position wether alignment
248 if( Align == VLC_FONT_ALIGN_CENTER )
250 Left = InitLeft - Width / 2;
251 TextLeft = InitLeft - TextWidth / 2;
253 else if( Align == VLC_FONT_ALIGN_RIGHT )
255 Left = InitLeft - Width;
256 TextLeft = InitLeft - TextWidth;
264 // Create clipping region
265 if( TextClipRgn != NULL )
268 TextClipRgn = (SkinRegion *)new OSRegion( Left, Top, Width, Height );
271 //---------------------------------------------------------------------------
272 bool ControlText::ProcessEvent( Event *evt )
274 unsigned int msg = evt->GetMessage();
275 unsigned int p1 = evt->GetParam1();
276 long p2 = evt->GetParam2();
281 if( DisplayList.size() > 0 )
283 if( p_intf->p_sys->p_theme->EvtBank->Get( (*Display) )
284 ->IsEqual( (Event*)p1 ) )
286 SetText( (char *)p2 );
293 //---------------------------------------------------------------------------
294 void ControlText::Draw( int x, int y, int w, int h, Graphics *dest )
299 // Test if control is in refresh zone
301 if( !GetIntersectRgn( x,y,w,h, Left,Top,Width,Height, xI,yI,wI,hI) )
304 // Change clipping region
305 TextClipRgn->Move( -x, -y );
306 dest->SetClipRegion( TextClipRgn );
309 if( TextWidth <= Width || !Scroll )
311 TextFont->Print( dest, Text, Left - x, Top - y, Width, Height, Align );
315 if( TextLeft > Left + ScrollSpace )
317 TextFont->Print( dest, Text, TextLeft - x, Top - y,
318 TextWidth, Height, Align );
319 TextFont->Print( dest, Text, TextLeft - x - TextWidth - ScrollSpace,
320 Top - y, TextWidth, Height, Align );
322 else if( TextLeft + TextWidth + ScrollSpace < Left + Width )
324 TextFont->Print( dest, Text, TextLeft - x, Top - y,
325 TextWidth, Height, Align );
326 TextFont->Print( dest, Text, TextLeft - x + TextWidth + ScrollSpace,
327 Top - y, TextWidth, Height, Align );
331 TextFont->Print( dest, Text, TextLeft - x, Top - y,
332 TextWidth, Height, Align );
336 // Reset clipping region to old region
337 SkinRegion *destClipRgn = (SkinRegion *)new OSRegion( 0, 0, w, h );
338 dest->SetClipRegion( destClipRgn );
340 TextClipRgn->Move( x, y );
342 //---------------------------------------------------------------------------
343 void ControlText::SetText( const string newText )
345 if( Text != newText )
351 ParentWindow->Refresh( Left, Top, Width, Height );
354 //---------------------------------------------------------------------------
355 void ControlText::DoScroll()
360 if( TextLeft + TextWidth < Left )
361 TextLeft += TextWidth + ScrollSpace;
363 ParentWindow->Refresh( Left, Top, Width, Height );
366 //---------------------------------------------------------------------------
367 void ControlText::MoveRelative( int xOff, int yOff )
373 //---------------------------------------------------------------------------
374 bool ControlText::MouseUp( int x, int y, int button )
377 if( MouseOver( x, y ) && button == 1 )
379 if( DisplayList.size() > 1 || TextWidth > Width )
385 //---------------------------------------------------------------------------
386 bool ControlText::MouseDown( int x, int y, int button )
388 if( MouseOver( x, y ) && button == 1 )
390 if( TextWidth > Width )
392 PauseScroll = !PauseScroll;
393 OSAPI_GetMousePos( MouseX, MouseY );
398 else if( DisplayList.size() > 1 )
405 //---------------------------------------------------------------------------
406 bool ControlText::MouseMove( int x, int y, int button )
408 if( Selected && button == 1 )
410 OSAPI_GetMousePos( MouseX, MouseY );
412 if( MouseX != SelectedX )
414 TextLeft += MouseX - SelectedX;
417 while( TextLeft + TextWidth < Left )
418 TextLeft += TextWidth + ScrollSpace;
420 while( TextLeft > Left + ScrollSpace )
421 TextLeft -= TextWidth + ScrollSpace;
423 ParentWindow->Refresh( Left, Top, Width, Height );
428 //---------------------------------------------------------------------------
429 bool ControlText::MouseOver( int x, int y )
431 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height )
436 //---------------------------------------------------------------------------
437 bool ControlText::MouseDblClick( int x, int y, int button )
440 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height
441 && button == 1 && DisplayList.size() > 1 )
444 if( Display == DisplayList.end() )
445 Display = DisplayList.begin();
453 //---------------------------------------------------------------------------