1 /*****************************************************************************
2 * text.cpp: Text control
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: text.cpp,v 1.5 2003/04/17 16:34:31 karibu Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
31 #include "../os_api.h"
32 #include "../src/bitmap.h"
33 #include "../src/banks.h"
34 #include "../src/graphics.h"
35 #include "../os_graphics.h"
36 #include "../src/font.h"
39 #include "../src/event.h"
40 #include "../src/theme.h"
41 #include "../src/window.h"
42 #include "../os_window.h"
43 #include "../src/skin_common.h"
47 //---------------------------------------------------------------------------
48 // Scrolling : one for each OS
49 //---------------------------------------------------------------------------
52 //-----------------------------------------------------------------------
54 //-----------------------------------------------------------------------
55 void CALLBACK ScrollingTextTimer( HWND hwnd, UINT uMsg, UINT_PTR idEvent,
58 if( (ControlText *)idEvent != NULL
59 && !( (ControlText *)idEvent )->GetSelected() )
61 ( (ControlText *)idEvent )->DoScroll();
65 //-----------------------------------------------------------------------
66 void ControlText::StartScrolling()
68 SetTimer( ( (Win32Window *)ParentWindow )->GetHandle(), (UINT_PTR)this,
69 100, (TIMERPROC)ScrollingTextTimer );
71 //-----------------------------------------------------------------------
72 void ControlText::StopScrolling()
74 KillTimer( ( (Win32Window *)ParentWindow )->GetHandle(),
77 //-----------------------------------------------------------------------
81 //-----------------------------------------------------------------------
83 //-----------------------------------------------------------------------
84 gboolean ScrollingTextTimer( gpointer data )
86 if( (ControlText *)data != NULL )
88 if( !( (ControlText *)data )->IsScrolling() )
91 if( !( (ControlText *)data )->GetSelected() )
92 ( (ControlText *)data )->DoScroll();
101 //-----------------------------------------------------------------------
102 void ControlText::StartScrolling()
104 g_timeout_add( 100, (GSourceFunc)ScrollingTextTimer, (gpointer)this );
106 //-----------------------------------------------------------------------
107 void ControlText::StopScrolling()
110 //-----------------------------------------------------------------------
114 //---------------------------------------------------------------------------
119 //---------------------------------------------------------------------------
121 //---------------------------------------------------------------------------
122 ControlText::ControlText( string id, bool visible, int x, int y, string text,
123 string font, int align, int width, string display, bool scroll,
124 int scrollspace, string help, Window *Parent )
125 : GenericControl( id, visible, help, Parent )
135 // Scrolling parameters
138 ScrollSpace = scrollspace;
141 // Initialize display
142 if( display != "none" )
145 int pos = display.find( ';', 0 );
148 DisplayList.push_back( display.substr( begin, pos - begin ) );
150 pos = display.find( ';', begin );
152 DisplayList.push_back(
153 display.substr( begin, display.size() - begin ) );
154 Display = DisplayList.begin();
158 //---------------------------------------------------------------------------
159 ControlText::~ControlText()
161 if( TextClipRgn != NULL )
166 //---------------------------------------------------------------------------
167 void ControlText::Init()
169 TextFont = p_intf->p_sys->p_theme->FntBank->Get( FontName );
171 // Init clipping region
174 // Get size of control
178 //---------------------------------------------------------------------------
179 void ControlText::SetScrolling()
181 if( !Scroll && TextWidth > Width )
189 else if( Scroll && TextWidth <= Width )
195 //---------------------------------------------------------------------------
196 void ControlText::SetSize()
198 // Get size parameters
200 TextFont->GetSize( Text, w, h );
203 // Get width if not set
212 // Set position wether alignment
213 if( Align == DT_CENTER )
215 Left = InitLeft - Width / 2;
216 TextLeft = InitLeft - TextWidth / 2;
218 else if( Align == DT_RIGHT )
220 Left = InitLeft - Width;
221 TextLeft = InitLeft - TextWidth;
229 // Create clipping region
230 if( TextClipRgn != NULL )
233 TextClipRgn = (Region *)new OSRegion( Left, Top, Width, Height );
236 //---------------------------------------------------------------------------
237 bool ControlText::ProcessEvent( Event *evt )
239 unsigned int msg = evt->GetMessage();
240 unsigned int p1 = evt->GetParam1();
241 long p2 = evt->GetParam2();
246 if( DisplayList.size() > 0 )
248 if( p_intf->p_sys->p_theme->EvtBank->Get( (*Display) )
249 ->IsEqual( (Event*)p1 ) )
251 SetText( (char *)p2 );
258 //---------------------------------------------------------------------------
259 void ControlText::Draw( int x, int y, int w, int h, Graphics *dest )
264 // Test if control is in refresh zone
266 if( !GetIntersectRgn( x,y,w,h, Left,Top,Width,Height, xI,yI,wI,hI) )
269 // Change clipping region
270 TextClipRgn->Move( -x, -y );
271 dest->SetClipRegion( TextClipRgn );
274 if( TextWidth <= Width || !Scroll )
276 TextFont->Print( dest, Text, Left - x, Top - y, Width, Height, Align );
280 if( TextLeft > Left + ScrollSpace )
282 TextFont->Print( dest, Text, TextLeft - x, Top - y,
283 TextWidth, Height, Align );
284 TextFont->Print( dest, Text, TextLeft - x - TextWidth - ScrollSpace,
285 Top - y, TextWidth, Height, Align );
287 else if( TextLeft + TextWidth + ScrollSpace < Left + Width )
289 TextFont->Print( dest, Text, TextLeft - x, Top - y,
290 TextWidth, Height, Align );
291 TextFont->Print( dest, Text, TextLeft - x + TextWidth + ScrollSpace,
292 Top - y, TextWidth, Height, Align );
296 TextFont->Print( dest, Text, TextLeft - x, Top - y,
297 TextWidth, Height, Align );
301 // Reset clipping region to old region
302 Region *destClipRgn = (Region *)new OSRegion( 0, 0, w, h );
303 dest->SetClipRegion( destClipRgn );
305 TextClipRgn->Move( x, y );
307 //---------------------------------------------------------------------------
308 void ControlText::SetText( const string newText )
310 if( Text != newText )
316 ParentWindow->Refresh( Left, Top, Width, Height );
319 //---------------------------------------------------------------------------
320 void ControlText::DoScroll()
325 if( TextLeft + TextWidth < Left )
326 TextLeft += TextWidth + ScrollSpace;
328 ParentWindow->Refresh( Left, Top, Width, Height );
331 //---------------------------------------------------------------------------
332 void ControlText::MoveRelative( int xOff, int yOff )
338 //---------------------------------------------------------------------------
339 bool ControlText::MouseUp( int x, int y, int button )
342 if( MouseOver( x, y ) && button == 1 )
344 if( DisplayList.size() > 1 || TextWidth > Width )
350 //---------------------------------------------------------------------------
351 bool ControlText::MouseDown( int x, int y, int button )
353 if( MouseOver( x, y ) && button == 1 )
355 if( TextWidth > Width )
357 PauseScroll = !PauseScroll;
358 OSAPI_GetMousePos( MouseX, MouseY );
363 else if( DisplayList.size() > 1 )
370 //---------------------------------------------------------------------------
371 bool ControlText::MouseMove( int x, int y, int button )
373 if( Selected && button == 1 )
375 OSAPI_GetMousePos( MouseX, MouseY );
377 if( MouseX != SelectedX )
379 TextLeft += MouseX - SelectedX;
382 while( TextLeft + TextWidth < Left )
383 TextLeft += TextWidth + ScrollSpace;
385 while( TextLeft > Left + ScrollSpace )
386 TextLeft -= TextWidth + ScrollSpace;
388 ParentWindow->Refresh( Left, Top, Width, Height );
393 //---------------------------------------------------------------------------
394 bool ControlText::MouseOver( int x, int y )
396 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height )
401 //---------------------------------------------------------------------------
402 bool ControlText::MouseDblClick( int x, int y, int button )
405 if( x >= Left && x < Left + Width && y >= Top && y < Top + Height
406 && button == 1 && DisplayList.size() > 1 )
409 if( Display == DisplayList.end() )
410 Display = DisplayList.begin();
418 //---------------------------------------------------------------------------