1 /*****************************************************************************
2 * text.cpp: Text control
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: text.cpp,v 1.10 2003/06/05 22:16:15 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 void ScrollingTextTimer( void *data )
126 if( (ControlText *)data != NULL
127 && !( (ControlText *)data )->GetSelected() )
129 ( (ControlText *)data )->DoScroll();
133 //-----------------------------------------------------------------------
134 void ControlText::StartScrolling()
136 X11Timer *timer = new X11Timer( g_pIntf, 100000, ScrollingTextTimer,
138 X11TimerManager *timerManager = X11TimerManager::Instance( g_pIntf );
139 timerManager->addTimer( timer );
141 //-----------------------------------------------------------------------
142 void ControlText::StopScrolling()
145 //-----------------------------------------------------------------------
148 //---------------------------------------------------------------------------
153 //---------------------------------------------------------------------------
155 //---------------------------------------------------------------------------
156 ControlText::ControlText( string id, bool visible, int x, int y, string text,
157 string font, int align, int width, string display, bool scroll,
158 int scrollspace, string help, SkinWindow *Parent )
159 : GenericControl( id, visible, help, Parent )
169 // Scrolling parameters
172 ScrollSpace = scrollspace;
175 // Initialize display
176 if( display != "none" )
179 int pos = display.find( ';', 0 );
182 DisplayList.push_back( display.substr( begin, pos - begin ) );
184 pos = display.find( ';', begin );
186 DisplayList.push_back(
187 display.substr( begin, display.size() - begin ) );
188 Display = DisplayList.begin();
192 //---------------------------------------------------------------------------
193 ControlText::~ControlText()
195 if( TextClipRgn != NULL )
200 //---------------------------------------------------------------------------
201 void ControlText::Init()
203 TextFont = p_intf->p_sys->p_theme->FntBank->Get( FontName );
205 // Init clipping region
208 // Get size of control
212 //---------------------------------------------------------------------------
213 void ControlText::SetScrolling()
215 if( !Scroll && TextWidth > Width )
223 else if( Scroll && TextWidth <= Width )
229 //---------------------------------------------------------------------------
230 void ControlText::SetSize()
232 // Get size parameters
234 TextFont->GetSize( Text, w, h );
237 // Get width if not set
246 // Set position wether alignment
247 if( Align == VLC_FONT_ALIGN_CENTER )
249 Left = InitLeft - Width / 2;
250 TextLeft = InitLeft - TextWidth / 2;
252 else if( Align == VLC_FONT_ALIGN_RIGHT )
254 Left = InitLeft - Width;
255 TextLeft = InitLeft - TextWidth;
263 // Create clipping region
264 if( TextClipRgn != NULL )
267 TextClipRgn = (SkinRegion *)new OSRegion( Left, Top, Width, Height );
270 //---------------------------------------------------------------------------
271 bool ControlText::ProcessEvent( Event *evt )
273 unsigned int msg = evt->GetMessage();
274 unsigned int p1 = evt->GetParam1();
275 long p2 = evt->GetParam2();
280 if( DisplayList.size() > 0 )
282 if( p_intf->p_sys->p_theme->EvtBank->Get( (*Display) )
283 ->IsEqual( (Event*)p1 ) )
285 SetText( (char *)p2 );
292 //---------------------------------------------------------------------------
293 void ControlText::Draw( int x, int y, int w, int h, Graphics *dest )
298 // Test if control is in refresh zone
300 if( !GetIntersectRgn( x,y,w,h, Left,Top,Width,Height, xI,yI,wI,hI) )
303 // Change clipping region
304 TextClipRgn->Move( -x, -y );
305 dest->SetClipRegion( TextClipRgn );
308 if( TextWidth <= Width || !Scroll )
310 TextFont->Print( dest, Text, Left - x, Top - y, Width, Height, Align );
314 if( TextLeft > Left + ScrollSpace )
316 TextFont->Print( dest, Text, TextLeft - x, Top - y,
317 TextWidth, Height, Align );
318 TextFont->Print( dest, Text, TextLeft - x - TextWidth - ScrollSpace,
319 Top - y, TextWidth, Height, Align );
321 else if( TextLeft + TextWidth + ScrollSpace < Left + Width )
323 TextFont->Print( dest, Text, TextLeft - x, Top - y,
324 TextWidth, Height, Align );
325 TextFont->Print( dest, Text, TextLeft - x + TextWidth + ScrollSpace,
326 Top - y, TextWidth, Height, Align );
330 TextFont->Print( dest, Text, TextLeft - x, Top - y,
331 TextWidth, Height, Align );
335 // Reset clipping region to old region
336 SkinRegion *destClipRgn = (SkinRegion *)new OSRegion( 0, 0, w, h );
337 dest->SetClipRegion( destClipRgn );
339 TextClipRgn->Move( x, y );
341 //---------------------------------------------------------------------------
342 void ControlText::SetText( const string newText )
344 if( Text != newText )
350 ParentWindow->Refresh( Left, Top, Width, Height );
353 //---------------------------------------------------------------------------
354 void ControlText::DoScroll()
359 if( TextLeft + TextWidth < Left )
360 TextLeft += TextWidth + ScrollSpace;
362 ParentWindow->Refresh( Left, Top, Width, Height );
365 //---------------------------------------------------------------------------
366 void ControlText::MoveRelative( int xOff, int yOff )
372 //---------------------------------------------------------------------------
373 bool ControlText::MouseUp( int x, int y, int button )
376 if( MouseOver( x, y ) && button == 1 )
378 if( DisplayList.size() > 1 || TextWidth > Width )
384 //---------------------------------------------------------------------------
385 bool ControlText::MouseDown( int x, int y, int button )
387 if( MouseOver( x, y ) && button == 1 )
389 if( TextWidth > Width )
391 PauseScroll = !PauseScroll;
392 OSAPI_GetMousePos( MouseX, MouseY );
397 else if( DisplayList.size() > 1 )
404 //---------------------------------------------------------------------------
405 bool ControlText::MouseMove( int x, int y, int button )
407 if( Selected && button == 1 )
409 OSAPI_GetMousePos( MouseX, MouseY );
411 if( MouseX != SelectedX )
413 TextLeft += MouseX - SelectedX;
416 while( TextLeft + TextWidth < Left )
417 TextLeft += TextWidth + ScrollSpace;
419 while( TextLeft > Left + ScrollSpace )
420 TextLeft -= TextWidth + ScrollSpace;
422 ParentWindow->Refresh( Left, Top, Width, Height );
427 //---------------------------------------------------------------------------
428 bool ControlText::MouseOver( int x, int y )
430 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height )
435 //---------------------------------------------------------------------------
436 bool ControlText::MouseDblClick( int x, int y, int button )
439 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height
440 && button == 1 && DisplayList.size() > 1 )
443 if( Display == DisplayList.end() )
444 Display = DisplayList.begin();
452 //---------------------------------------------------------------------------