1 /***************************************************************************
2  *   Copyright (C) 2007 by Vadim Lopatin   *
3  *   vadim.lopatin@coolreader.org   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef CR_GUI_INCLUDED
21 #define CR_GUI_INCLUDED
22 
23 #include "lvtypes.h"
24 #include "lvstring.h"
25 #include "lvptrvec.h"
26 #include "lvdrawbuf.h"
27 #include "lvdocview.h"
28 #include "crskin.h"
29 
30 #ifdef CR_WX_SUPPORT
31 #include <wx/wx.h>
32 #endif
33 
34 class CRGUIWindowManager;
35 
36 #define KEY_FLAG_LONG_PRESS 1
37 
38 /// Accelerator table entry: to convert keypress to command
39 class CRGUIAccelerator
40 {
41     public:
42         int keyCode;
43         int keyFlags;
44         int commandId;
45         int commandParam;
46 };
47 
48 /// accelerator table
49 class CRGUIAcceleratorTable
50 {
51 protected:
52     LVPtrVector<CRGUIAccelerator> _items;
indexOf(int keyCode,int keyFlags)53     int indexOf( int keyCode, int keyFlags )
54     {
55         //CRLog::trace( "indexOf( %d, %d )", (int)keyCode, (int)keyFlags );
56         for ( int i=0; i<_items.length(); i++ ) {
57             //CRLog::trace( " compare( %d, %d )", (int)_items[i]->keyCode, (int)_items[i]->keyFlags );
58             if ( _items[i]->keyCode==keyCode && _items[i]->keyFlags==keyFlags ) {
59                 //CRLog::trace(" found index = %d", i);
60                 return i;
61             }
62         }
63         return -1;
64     }
65 public:
66 	/// find key by command
findCommandKey(int cmd,int param,int & keyCode,int & keyFlags)67     bool findCommandKey( int cmd, int param, int & keyCode, int & keyFlags )
68     {
69         //CRLog::trace( "indexOf( %d, %d )", (int)keyCode, (int)keyFlags );
70         for ( int i=0; i<_items.length(); i++ ) {
71             //CRLog::trace( " compare( %d, %d )", (int)_items[i]->keyCode, (int)_items[i]->keyFlags );
72 			if ( _items[i]->commandId==cmd && _items[i]->commandParam==param ) {
73                 //CRLog::trace(" found index = %d", i);
74 				keyCode = _items[i]->keyCode;
75 				keyFlags = _items[i]->keyFlags;
76 				return true;
77             }
78         }
79         return false;
80     }
81 	/// get item by index
get(int index)82 	const CRGUIAccelerator * get( int index ) const
83 	{
84 		return _items[ index ];
85 	}
86 
87 	/// debug dump of table
dump()88     void dump()
89     {
90         if ( CRLog::isTraceEnabled() ) {
91 #if 0
92             CRLog::trace("Accelerator table:");
93             for ( int i=0; i<_items.length(); i++ ) {
94                 CRGUIAccelerator * p = _items[i];
95                 CRLog::trace("%d, %d => %d, %d\n", p->keyCode, p->keyFlags, p->commandId, p->commandParam);
96             }
97 #endif
98         }
99     }
100 	/// returns number of entries
length()101     int length() { return _items.length(); }
102     /// remove accelerator from table
remove(int keyCode,int keyFlags)103     bool remove( int keyCode, int keyFlags )
104     {
105         int index = indexOf( keyCode, keyFlags );
106         if ( index >= 0 ) {
107             _items.erase( index, 1 );
108             return true;
109         }
110         return false;
111     }
112 
113     /// add accelerator to table or change existing
114     bool add( int keyCode, int keyFlags, int commandId, int commandParam );
115 
116 	/// add all items from another table
117 	void addAll( const CRGUIAcceleratorTable & v );
118 
119     /// translate keycode to command, returns true if translated
translate(int keyCode,int keyFlags,int & commandId,int & commandParam)120     bool translate( int keyCode, int keyFlags, int & commandId, int & commandParam )
121     {
122         int index = indexOf( keyCode, keyFlags );
123         if ( index<0 )
124             return false;
125         commandId = _items[index]->commandId;
126         commandParam = _items[index]->commandParam;
127         return true;
128     }
129     /// translate keycode to command, returns true if translated
findKeyAccelerator(int keyCode,int keyFlags)130     const CRGUIAccelerator * findKeyAccelerator( int keyCode, int keyFlags )
131     {
132         int index = indexOf( keyCode, keyFlags );
133         if ( index<0 )
134             return NULL;
135         return get(index);
136     }
137     /// empty table constructor
CRGUIAcceleratorTable()138     CRGUIAcceleratorTable() { }
139     /// copy constructor
CRGUIAcceleratorTable(const CRGUIAcceleratorTable & v)140     CRGUIAcceleratorTable( const CRGUIAcceleratorTable& v)
141 	{
142 		for ( int i=0; i<v._items.length(); i++ ) {
143 			_items.add( new CRGUIAccelerator(*v._items[i]) );
144 		}
145 	}
146     /// constructor from int array: 4 ints per entry (keyCode, keyFlags, commandId, commandParam), keyCode==0 indicates end of list
CRGUIAcceleratorTable(const int * tableQuadsArray)147     CRGUIAcceleratorTable( const int * tableQuadsArray )
148     {
149         while( *tableQuadsArray ) {
150             CRGUIAccelerator * item = new CRGUIAccelerator();
151             item->keyCode = *tableQuadsArray++;
152             item->keyFlags = *tableQuadsArray++;
153             item->commandId = *tableQuadsArray++;
154             item->commandParam = *tableQuadsArray++;
155             _items.add(item);
156         }
157     }
158 };
159 
160 /// accelerator table reference
161 typedef LVRef<CRGUIAcceleratorTable> CRGUIAcceleratorTableRef;
162 
163 /**
164  * \brief Container for list of named accelerator tables read from files
165  *
166  * File format:
167  * there are two files:
168  *   1) definition file which has key code and command id definitions
169  *   2) keymap file which has several key->command tables
170  *
171  * definition file format:
172  *   # there may be comment lines started with # character
173  *   other lines should be in format
174  *   identifier=value
175  *   where identifier is alphanumeric identifier to name value
176  *   value is either decimal number, hex number with 0x prefix, or character in ''
177  * example:
178  *
179  * # this is sample definition file
180  * XK_Return=0xFF01
181  * KEY_1='1'
182  * KEY_SPACE=32
183  * CMD_CLOSE=100
184  *
185  * keymap file format:
186  *   # there may be comment lines started with # character
187  *   file should be divided into sections using lines like
188  *   [sectionname]
189  *   other lines should be in format
190  *   key[,keyflags]=cmd[,cmdparam]
191  *   (keyflags and cmdparam are optional)
192  *   key, keyflags, cmd, and cmdparam should be either
193  *   identifier defined in definition file, decimal number, hex number with 0x prefix, or character in ''
194  *   it's better to avoid constants in this file, instead just place them to definition file and use by identifiers
195  *
196  * example:
197  *
198  * # this is sample keymap file
199  * [mainwindow]
200  * #this is keymap table for main window, accessible by name "mainwindow"
201  * XK_Return=CMD_SHOW_MENU, 0
202  * XK_Return,LONG=CMD_SHOW_MENU_SETTINGS
203  * XK_Down,LONG=CMD_MOVE_FORWARD, 10
204  * '1'=CMD_GO_TO_PAGE
205  *
206  */
207 class CRGUIAcceleratorTableList
208 {
209 private:
210     LVHashTable<lString32, CRGUIAcceleratorTableRef> _table;
211 public:
212 	/// add all tables
213 	void addAll( const CRGUIAcceleratorTableList & v );
214     /// remove all tables
clear()215     void clear() { _table.clear(); }
216     /// add accelerator table definition from array
add(const char * name,const int * defs)217     void add( const char * name, const int * defs )
218     {
219         add( lString32( name ), defs );
220     }
221     /// add accelerator table definition from array
add(const lString32 & name,const int * defs)222     void add( const lString32 & name, const int * defs )
223     {
224         _table.set( name, CRGUIAcceleratorTableRef( new CRGUIAcceleratorTable( defs ) ) );
225     }
226     /// find accelerator table by name
get(const lString32 & name)227     CRGUIAcceleratorTableRef get( const lString32 & name ) { return _table.get( name ); }
228     CRGUIAcceleratorTableRef get( const lString32 & name, CRPropRef keyRemappingOptions );
229     /// find accelerator table by name
get(const char * name)230     CRGUIAcceleratorTableRef get( const char * name ) { return _table.get( lString32( name ) ); }
231     /// returns true if there are no no tables in list
empty()232     bool empty() { return _table.length()==0; }
233     /// constructs empty list, then it should be filled from file using openFromFile()
CRGUIAcceleratorTableList()234     CRGUIAcceleratorTableList() : _table( 32 )
235     {
236     }
~CRGUIAcceleratorTableList()237     ~CRGUIAcceleratorTableList() { }
238     /// reads definitions from files
239     bool openFromFile( const char  * defFile, const char * mapFile );
240 };
241 
242 class CRKeyboardLayout
243 {
244 	lString32Collection _items;
245 public:
CRKeyboardLayout()246 	CRKeyboardLayout() { }
getItems()247 	const lString32Collection & getItems() { return _items; }
get(int i)248 	lString32 get( int i )
249 	{
250 		if ( i<0 || i>= (int)_items.length() )
251             return lString32::empty_str;
252 		return _items[i];
253 	}
set(int index,lString32 chars)254 	void set( int index, lString32 chars )
255 	{
256 		if ( index<0 || index>20 )
257 			return;
258 		while ( (int)_items.length() <= index )
259             _items.add(lString32::empty_str);
260 		_items[ index ] = chars;
261 	}
262 };
263 
264 class CRKeyboardLayoutSet
265 {
266 public:
267 	lString32 name;
268 	LVRef<CRKeyboardLayout> vKeyboard;
269 	LVRef<CRKeyboardLayout> tXKeyboard;
CRKeyboardLayoutSet()270 	CRKeyboardLayoutSet()
271 		: vKeyboard( new CRKeyboardLayout() ), tXKeyboard( new CRKeyboardLayout() )
272 	{
273 	}
CRKeyboardLayoutSet(const CRKeyboardLayoutSet & v)274 	CRKeyboardLayoutSet( const CRKeyboardLayoutSet & v )
275 		: name( v.name), vKeyboard( v.vKeyboard ), tXKeyboard( v.tXKeyboard )
276 	{
277 	}
278 	CRKeyboardLayoutSet & operator = ( const CRKeyboardLayoutSet & v )
279 	{
280 		name = v.name;
281 		vKeyboard = v.vKeyboard;
282 		tXKeyboard = v.tXKeyboard;
283         return *this;
284 	}
285 };
286 
287 typedef LVRef<CRKeyboardLayoutSet> CRKeyboardLayoutRef;
288 
289 class CRKeyboardLayoutList
290 {
291     LVHashTable<lString32, CRKeyboardLayoutRef> _table;
292 	CRKeyboardLayoutRef _current;
293 public:
294 	// get currently set layout
295 	CRKeyboardLayoutRef getCurrentLayout();
296 	// get next layout
297 	CRKeyboardLayoutRef nextLayout();
298 	// get previous layout
299 	CRKeyboardLayoutRef prevLayout();
300 
get(lString32 name)301 	CRKeyboardLayoutRef get( lString32 name ) { return _table.get( name ); }
set(lString32 name,CRKeyboardLayoutRef v)302 	void set( lString32 name, CRKeyboardLayoutRef v ) { _table.set( name, v ); }
CRKeyboardLayoutList()303 	CRKeyboardLayoutList() : _table(16) { }
304     /// reads definitions from files
305     bool openFromFile( const char  * layoutFile );
306 };
307 
308 /// i18n support interface
309 class CRGUIStringTranslator
310 {
311 public:
312     /// translate string by key, return default value if not found
translateString(const char *,const char * defValue)313     virtual lString32 translateString( const char *, const char * defValue )
314     {
315         return Utf8ToUnicode( lString8(defValue) );
316     }
~CRGUIStringTranslator()317     virtual ~CRGUIStringTranslator() { }
318 };
319 
320 enum CRGUIEventType {
321     CREV_WINDOW_EVENTS_START=1,
322     CREV_KEYDOWN = 1,
323     CREV_KEYUP,
324     CREV_COMMAND,
325 
326     CREV_WM_EVENTS_START=100,
327     CREV_UPDATE = 100,
328     CREV_RESIZE
329 
330 };
331 
332 class CRGUIWindow;
333 class CRGUIWindowManager;
334 
335 class CRGUIEvent
336 {
337 protected:
338     int _type;
339     CRGUIWindow * _targetWindow;
340     int _param1;
341     int _param2;
342 public:
isForVisibleOnly()343     virtual bool isForVisibleOnly() { return false; }
isForModalOnly()344     virtual bool isForModalOnly() { return false; }
isWindowEvent()345     virtual bool isWindowEvent() { return _type<CREV_WM_EVENTS_START; }
isWMEvent()346     virtual bool isWMEvent() { return _type>=CREV_WM_EVENTS_START; }
getType()347     int getType() { return _type; }
handle(CRGUIWindow * window)348     virtual bool handle( CRGUIWindow * window ) { return false; }
handle(CRGUIWindowManager * wm)349     virtual bool handle( CRGUIWindowManager * wm ) { return false; }
setParam1(int v)350     CRGUIEvent & setParam1( int v ) { _param1=v; return *this; }
setParam2(int v)351     CRGUIEvent & setParam2( int v ) { _param2=v; return *this; }
setTargetWindow(CRGUIWindow * targetWindow)352     CRGUIEvent & setTargetWindow( CRGUIWindow * targetWindow ) { _targetWindow = targetWindow; return *this; }
getParam1()353     int getParam1() { return _param1; }
getParam2()354     int getParam2() { return _param2; }
CRGUIEvent(int type)355     CRGUIEvent( int type ) : _type(type), _targetWindow(NULL)
356     {
357 
358     }
~CRGUIEvent()359     virtual ~CRGUIEvent() { }
360 };
361 
362 
363 /// Screen object - provides canvas and interface to device screen
364 class CRGUIScreen
365 {
366     public:
367         // for turbo updates
368         enum UpdateMode {
369             NormalMode,
370             PrepareMode
371         };
setTurboUpdateEnabled(bool flg)372         virtual void setTurboUpdateEnabled( bool flg ) { }
getTurboUpdateEnabled()373         virtual bool getTurboUpdateEnabled() {  return false; }
getTurboUpdateSupported()374         virtual bool getTurboUpdateSupported() {  return false; }
setTurboUpdateMode(UpdateMode mode)375         virtual void setTurboUpdateMode( UpdateMode mode ) { }
376         /// fast update feature parameter setting
377         virtual void setFullUpdateInterval( int pagesBeforeFullupdate=1 ) = 0;
378         /// creates compatible canvas of specified size
379         virtual LVDrawBuf * createCanvas( int dx, int dy ) = 0;
380         /// sets new screen size, returns true if size is changed
381         virtual bool setSize( int dx, int dy ) = 0;
382         /// returns screen width
383         virtual int getWidth() = 0;
384         /// returns screen height
385         virtual int getHeight() = 0;
386         /// returns screen dimension
getRect()387         virtual lvRect getRect() { return lvRect(0, 0, getWidth(), getHeight() ); }
388         /// return pointer to screen canvas
389         virtual LVRef<LVDrawBuf> getCanvas() = 0;
390         /// draw image on screen canvas
391         virtual void draw( LVDrawBuf * img, int x = 0, int y = 0) = 0;
392         /// transfers contents of buffer to device, if full==true, redraws whole screen, otherwise only changed area
393         virtual void flush( bool full ) = 0;
394         /// invalidates rectangle: add it to bounding box of next partial update
invalidateRect(const lvRect & rc)395         virtual void invalidateRect( const lvRect & rc ) { }
~CRGUIScreen()396         virtual ~CRGUIScreen() { }
397 };
398 
399 /// window configure flag, on screen size change
400 #define CRGUI_CONFIGURE_FLAG_SCREEN_SIZE 1
401 /// window configure flag, on screen orientation change
402 #define CRGUI_CONFIGURE_FLAG_SCREEN_ORIENTATION 2
403 
404 /// Window interface
405 class CRGUIWindow
406 {
407     public:
408         /// override to handle
handleEvent(CRGUIEvent * event)409         virtual bool handleEvent( CRGUIEvent * event )
410         {
411             if ( !event->isWindowEvent() )
412                 return false;
413             // by default, allow event to do something with window
414             return event->handle( this );
415         }
416         /// sets scroll label (e.g. "Page $1 of $2" or "$1 / $2")
417         virtual void setScrollLabelTemplate( lString32 text ) = 0;
418         /// returns scroll label (e.g. "$1 of $2")
419         virtual lString32 getScrollLabelTemplate() = 0;
420         /// sets skin name for window
421         virtual void setSkinName( const lString32  & skin ) = 0;
422         /// returns skin name for window
423         virtual lString32 getSkinName() = 0;
424         /// set accelerator table for window
setAccelerators(CRGUIAcceleratorTableRef)425         virtual void setAccelerators( CRGUIAcceleratorTableRef ) { }
426         /// get window accelerator table
getAccelerators()427         virtual CRGUIAcceleratorTableRef getAccelerators() { return CRGUIAcceleratorTableRef(); }
428         /// returns true if key is processed
429         virtual bool onKeyPressed( int key, int flags = 0 ) = 0;
430         /// returns true if command is processed
431         virtual bool onCommand( int command, int params = 0 ) = 0;
432         /// returns true if window is visible
433         virtual bool isVisible() const = 0;
434         /// returns true if window is fullscreen
435         virtual bool isFullscreen() = 0;
436         /// returns true if window is changed but now drawn
437         virtual bool isDirty() = 0;
438         /// sets dirty flag
439         virtual void setDirty() = 0;
440         /// shows or hides window
441         virtual void setVisible( bool visible ) = 0;
442         /// called on system configuration change: screen size and orientation
443         virtual void reconfigure( int flags ) = 0;
444         /// returns window rectangle
445         virtual const lvRect & getRect() = 0;
446         /// sets window rectangle
447         virtual void setRect( const lvRect & rc ) = 0;
448         /// draws content of window to screen
449         virtual void flush() = 0;
450         /// called if window gets focus
activated()451         virtual void activated() { setDirty(); }
reactivated()452         virtual void reactivated() {}
453         /// called if window loss focus
covered()454         virtual void covered() { }
455         /// called if window is being closed
closing()456         virtual void closing() { }
457         /// returns window manager
458         virtual CRGUIWindowManager * getWindowManager() = 0;
459         /// destroys window
~CRGUIWindow()460         virtual ~CRGUIWindow() { }
461 };
462 
463 /// Window manager
464 class CRGUIWindowManager : public CRGUIStringTranslator
465 {
466     protected:
467         LVPtrVector<CRGUIWindow, true> _windows;
468         LVPtrVector<CRGUIEvent, true> _events;
469         CRGUIScreen * _screen;
470         /// if true, we should delete screen in destructor
471         bool _ownScreen;
472         LVRef<CRGUIStringTranslator> _i18n;
473         int _postedCommand;
474         int _postedCommandParam;
475         time_t _lastProgressUpdate;
476         int _lastProgressPercent;
477         CRSkinRef _skin;
478         CRGUIAcceleratorTableList _accTables;
479 		CRKeyboardLayoutList _kbLayouts;
480         cr_rotate_angle_t _orientation;
481         LVRefVec<LVImageSource> m_batteryIcons;
482         bool _stopFlag;
483     public:
484         /// forward events from system queue to application queue
forwardSystemEvents(bool waitForEvent)485         virtual void forwardSystemEvents( bool waitForEvent ) { }
486         /// post application event to message queue
487         virtual void postEvent( CRGUIEvent * event );
488         /// peeks head of application message queue, w/o removing from queue (returns NULL if no events in queue)
peekEvent()489         virtual CRGUIEvent * peekEvent()
490         {
491             forwardSystemEvents( false );
492             return _events.peekHead();
493         }
494         /// returns head of application message queue, removing from queue (returns NULL if no events in queue)
getEvent()495         virtual CRGUIEvent * getEvent()
496         {
497             forwardSystemEvents( false );
498             return _events.popHead();
499         }
500         /// handle all events from queue
501         virtual bool handleAllEvents( bool waitForEvent );
502         /// override to handle
503         virtual bool handleEvent( CRGUIEvent * event );
504         /// called when message queue is empty and application is going to wait for event
idle()505         virtual void idle() { }
506 
507         /// returns list of battery icons
getBatteryIcons()508         virtual LVRefVec<LVImageSource> & getBatteryIcons() { return m_batteryIcons; }
509         /// set list of battery icons to display battery state
setBatteryIcons(LVRefVec<LVImageSource> icons)510         virtual void setBatteryIcons( LVRefVec<LVImageSource> icons )
511         {
512             m_batteryIcons.clear();
513             m_batteryIcons.add(icons);
514         }
515         /// draw battery state to specified rectangle of screen
516         virtual void drawBattery( LVDrawBuf & buf, const lvRect & rc );
517         /// sets screen orientation value, to be red by corresponding getter. Doesn't rotate screen actually.
setScreenOrientation(cr_rotate_angle_t angle)518         virtual void setScreenOrientation( cr_rotate_angle_t angle ) { _orientation = angle; }
519         /// returns current screen orientation
getScreenOrientation()520         virtual cr_rotate_angle_t getScreenOrientation() { return _orientation; }
521         /// draws icon at center of screen, with optional progress gauge
522         virtual void showWaitIcon( lString32 filename, int progressPercent=-1 );
523         /// draws icon with gauge at center of screen, skipping too frequent updates
524         virtual void showProgress( lString32 filename, int progressPercent );
525 		/// loads skin from file
526 	    virtual bool loadSkin( lString32 pathname );
527 		/// returns keyboard layouts
getKeyboardLayouts()528 		virtual CRKeyboardLayoutList & getKeyboardLayouts() { return _kbLayouts; }
529         /// returns accelerator table list
getAccTables()530         virtual CRGUIAcceleratorTableList & getAccTables() { return _accTables; }
531         /// return battery status
getBatteryStatus(int & percent,bool & charging)532         virtual bool getBatteryStatus( int & percent, bool & charging )
533         {
534             // stub
535             percent = 0; charging = false; return false;
536         }
537         /// set skin
setSkin(CRSkinRef skin)538         virtual void setSkin( CRSkinRef skin ) { _skin = skin; }
539         /// returns currently selected skin
getSkin()540         virtual CRSkinRef getSkin() { return _skin; }
541         /// sets another i18n translator
setTranslator(LVRef<CRGUIStringTranslator> i18n)542         virtual void setTranslator( LVRef<CRGUIStringTranslator> i18n )
543         {
544             _i18n = i18n;
545         }
546         /// translate string by key, return default value if not found
translateString(const char * key,const char * defValue)547         virtual lString32 translateString( const char * key, const char * defValue )
548         {
549             if ( _i18n.isNull() )
550                 return Utf8ToUnicode( lString8(defValue) );
551             return _i18n->translateString( key, defValue );
552         }
553         /// returns count of windows
getWindowCount()554         virtual int getWindowCount() { return _windows.length(); }
555         /// changes screen size and orientation
556         virtual void reconfigure( int dx, int dy, cr_rotate_angle_t orientation );
557         /// adds command to message queue
558         virtual void postCommand( int command, int params = 0 );
559         /// runs posted events (commands)
processPostedEvents()560         virtual bool processPostedEvents()
561         {
562             return handleAllEvents( false );
563         }
564         /// returns true if command is processed
565         virtual bool onCommand( int command, int params = 0 )
566         {
567             for ( int i=_windows.length()-1; i>=0; i-- ) {
568                 if ( _windows[i]->isVisible() && _windows[i]->onCommand( command, params ) )
569                     return true;
570             }
571             return false;
572         }
573         /// returns true if key is processed
574         virtual bool onKeyPressed( int key, int flags = 0 );
575         /// returns top visible window
getTopVisibleWindow()576         CRGUIWindow * getTopVisibleWindow()
577         {
578             for ( int i=_windows.length()-1; i>=0; i-- ) {
579                 if ( !_windows[i]->isVisible() )
580                     continue;
581                 return _windows[i];
582             }
583             return NULL;
584         }
585         /// shows or hides window
showWindow(CRGUIWindow * window,bool visible)586         void showWindow( CRGUIWindow * window, bool visible )
587         {
588             int index = _windows.indexOf( window );
589             if ( index >= 0  ) { //&& window->isVisible()!=visible
590                 window->setVisible( visible );
591                 if ( !visible ) {
592                     window->covered();
593                     CRGUIWindow * wnd = getTopVisibleWindow();
594                     if ( wnd )
595                         activateWindow( wnd );
596                 } else
597                     activateWindow( window );
598             }
599         }
600         /// activates window, brings it on top; add to stack if not added
601         void activateWindow( CRGUIWindow * window );
602         /// closes window, removes from stack, destroys object
603         void closeWindow( CRGUIWindow * window );
604         /// redraw one window
605         virtual void updateWindow( CRGUIWindow * window );
606         /// full redraw of all windows
607         void update( bool fullScreenUpdate, bool forceFlushScreen=true );
608         /// returns screen associated with window manager
getScreen()609         virtual CRGUIScreen * getScreen()
610         {
611             return _screen;
612         }
613         /// runs event loop
614         virtual int runEventLoop();
615         /// constructor
CRGUIWindowManager(CRGUIScreen * screen)616         CRGUIWindowManager(CRGUIScreen * screen)
617         : _screen( screen ), _ownScreen(false)
618         , _postedCommand(0)
619         , _postedCommandParam(0)
620         ,_lastProgressUpdate(0)
621         ,_lastProgressPercent(-1)
622         ,_orientation(CR_ROTATE_ANGLE_0)
623         ,_stopFlag(false)
624         {
625         }
closeAllWindows()626         virtual void closeAllWindows()
627         {
628             for ( int i=_windows.length()-1; i>=0; i-- ) {
629                 closeWindow(_windows[i]);
630             }
631         }
632         /// destroy all windows on close
~CRGUIWindowManager()633         virtual ~CRGUIWindowManager()
634         {
635             closeAllWindows();
636             if ( _ownScreen )
637                 delete _screen;
638         }
639 };
640 
641 /// Window base implementation
642 class CRGUIWindowBase : public CRGUIWindow
643 {
644     protected:
645         CRGUIWindowManager * _wm;
646         lvRect _rect;
647         bool _visible;
648         bool _fullscreen;
649         bool _dirty;
650         bool _passKeysToParent;
651         bool _passCommandsToParent;
652         int _page;
653         int _pages;
654         CRGUIAcceleratorTableRef _acceleratorTable;
655         lString32 _skinName;
656         lString32 _scrollLabel;
657         lString32 _caption;
658         lString32 _statusText;
659         lString32 _inputText;
660         LVImageSourceRef _icon; // window title icon
661         // draws frame, title, status and client
662         virtual void draw();
663 
664         /// use to override status text
getStatusText()665         virtual lString32 getStatusText() { return _statusText; }
666 
667         /// draw status bar using current skin, with optional status text and scroll/tab/page indicator
668         virtual void drawStatusBar();
669         /// draw status text
670         virtual void drawStatusText( LVDrawBuf & buf, const lvRect & rc, CRRectSkinRef skin );
671         /// draw title bar using current skin, with optional scroll/tab/page indicator
672         virtual void drawTitleBar();
673         /// draw input box, if any
674         virtual void drawInputBox();
675         /// draw title bar using current skin, with optional scroll/tab/page indicator
676         virtual void drawClient();
677 
678         /// calculates title rectangle for window rectangle
679         virtual bool getTitleRect( lvRect & rc );
680         /// calculates status rectangle for window rectangle
681         virtual bool getStatusRect( lvRect & rc );
682         /// calculates client rectangle for window rectangle
683         virtual bool getClientRect( lvRect & rc );
684         /// calculates input box rectangle for window rectangle
685         virtual bool getInputRect( lvRect & rc );
686         /// calculates scroll rectangle for window rectangle
687         virtual bool getScrollRect( lvRect & rc );
688     public:
689         /// use to override status text
setStatusText(lString32 s)690         virtual void setStatusText( lString32 s ) { _statusText = s; }
691         /// formats scroll label (like "1 of 2")
692         virtual lString32 getScrollLabel( int page, int pages );
693         /// calculates minimum scroll size
694         virtual lvPoint getMinScrollSize( int page, int pages );
695         /// sets scroll label (e.g. "Page $1 of $2" or "$1 / $2")
setScrollLabelTemplate(lString32 text)696         virtual void setScrollLabelTemplate( lString32 text ) { _scrollLabel=text; }
697         /// returns scroll label (e.g. "$1 of $2")
getScrollLabelTemplate()698         virtual lString32 getScrollLabelTemplate() { return _scrollLabel; }
699         /// called on system configuration change: screen size and orientation
700         virtual void reconfigure( int flags );
701         /// sets skin name for window
setSkinName(const lString32 & skin)702         virtual void setSkinName( const lString32  & skin ) { _skinName = skin; }
703         /// returns skin name for window
getSkinName()704         virtual lString32 getSkinName() { return _skinName; }
705         /// returns true if command is processed
706         virtual bool onCommand( int command, int params = 0 ) { return !_passCommandsToParent; }
707         /// returns true if key is processed (by default, let's translate key to command using accelerator table)
708         virtual bool onKeyPressed( int key, int flags = 0 );
709         /// set accelerator table for window
setAccelerators(CRGUIAcceleratorTableRef table)710         virtual void setAccelerators( CRGUIAcceleratorTableRef table ) { _acceleratorTable = table; }
711         /// get window accelerator table
getAccelerators()712         virtual CRGUIAcceleratorTableRef getAccelerators() { return _acceleratorTable; }
713         /// returns window width
getWidth()714         inline int getWidth() { return getRect().width(); }
715         /// returns window height
getHeight()716         inline int getHeight() { return getRect().height(); }
717         /// sets dirty flag
setDirty()718         virtual void setDirty() { _dirty = true; }
719         /// returns true if window is changed but now drawn
isDirty()720         virtual bool isDirty() { return _dirty; }
721         /// shows or hides window
setVisible(bool visible)722         virtual void setVisible( bool visible ) { _visible = visible; setDirty(); }
isVisible()723         virtual bool isVisible() const { return _visible; }
getRect()724         virtual const lvRect & getRect() { return _rect; }
setRect(const lvRect & rc)725         virtual void setRect( const lvRect & rc ) { _rect = rc; setDirty(); }
flush()726         virtual void flush() { draw(); _dirty = false; }
727         /// returns true if window is fullscreen
isFullscreen()728         virtual bool isFullscreen() { return _fullscreen; }
729         /// set fullscreen state for window
setFullscreen(bool fullscreen)730         virtual void setFullscreen( bool fullscreen ) { _fullscreen = fullscreen; }
getWindowManager()731         virtual CRGUIWindowManager * getWindowManager() { return _wm; }
CRGUIWindowBase(CRGUIWindowManager * wm)732         CRGUIWindowBase( CRGUIWindowManager * wm )
733         : _wm(wm), _visible(true), _fullscreen(true), _dirty(true), _passKeysToParent(false), _passCommandsToParent(false)
734         , _page(0), _pages(0)
735         {
736             // fullscreen visible by default
737             _rect = _wm->getScreen()->getRect();
738             //_statusText = "Sample status text";
739         }
~CRGUIWindowBase()740         virtual ~CRGUIWindowBase() { }
741 };
742 
743 /// Base Screen class implementation
744 class CRGUIScreenBase : public CRGUIScreen
745 {
746     protected:
747         int _width;
748         int _height;
749         lvRect _updateRect;
750         LVRef<LVDrawBuf> _canvas;
751         LVRef<LVDrawBuf> _front;
752         int _fullUpdateInterval;
753         int _fullUpdateCounter;
754         /// override in ancessor to transfer image to device
755         virtual void update( const lvRect & rc, bool full ) = 0;
756     public:
757         /// fast update feature parameter setting
758         virtual void setFullUpdateInterval( int pagesBeforeFullupdate=1 )
759         {
760             _fullUpdateInterval = pagesBeforeFullupdate;
761             if ( _fullUpdateInterval>0 )
762                 _fullUpdateCounter = _fullUpdateInterval;
763         }
checkFullUpdateCounter()764         virtual bool checkFullUpdateCounter()
765         {
766             if ( _fullUpdateInterval<=0 )
767                 return false; // always partial update
768             if ( _fullUpdateInterval==1 )
769                 return true;  // always full update
770             _fullUpdateCounter--;
771             if ( _fullUpdateCounter<=0 ) {
772                 _fullUpdateCounter = _fullUpdateInterval;
773                 return true; // full update
774             }
775             return false; // partial update
776         }
777 
778         /// creates compatible canvas of specified size
createCanvas(int dx,int dy)779         virtual LVDrawBuf * createCanvas( int dx, int dy )
780         {
781 #if (COLOR_BACKBUFFER==1)
782             LVDrawBuf * buf = new LVColorDrawBuf( dx, dy );
783 #else
784             LVDrawBuf * buf = new LVGrayDrawBuf( dx, dy, GRAY_BACKBUFFER_BITS );
785 #endif
786             return buf;
787         }
788         /// sets new screen size
setSize(int dx,int dy)789         virtual bool setSize( int dx, int dy )
790         {
791             if ( _width!=dx || _height != dy ) {
792                 _width = dx;
793                 _height = dy;
794                 _canvas = LVRef<LVDrawBuf>( createCanvas( dx, dy ) );
795                 if ( !_front.isNull() )
796                     _front = LVRef<LVDrawBuf>( createCanvas( dx, dy ) );
797                 return true;
798             }
799             return false;
800         }
801 
802         /// returns screen width
getWidth()803         virtual int getWidth() { return _width; }
804         /// returns screen height
getHeight()805         virtual int getHeight() { return _height; }
806         /// return pointer to screen canvas
getCanvas()807         virtual LVRef<LVDrawBuf> getCanvas() { return _canvas; }
808         /// draw image on screen canvas
809         virtual void draw( LVDrawBuf * img, int x = 0, int y = 0)
810         {
811             img->DrawTo( _canvas.get(), x, y, 0, NULL );
812         }
813         /// transfers contents of buffer to device, if full==true, redraws whole screen, otherwise only changed area
814         virtual void flush( bool full );
815         /// invalidates rectangle: add it to bounding box of next partial update
invalidateRect(const lvRect & rc)816         virtual void invalidateRect( const lvRect & rc )
817         {
818             _updateRect.extend( rc );
819         }
CRGUIScreenBase(int width,int height,bool doublebuffer)820         CRGUIScreenBase( int width, int height, bool doublebuffer  )
821         : _width( width ), _height( height ), _canvas(NULL), _front(NULL)
822         , _fullUpdateInterval(1)
823         , _fullUpdateCounter(1)
824         {
825             if ( width && height ) {
826                 _canvas = LVRef<LVDrawBuf>( createCanvas( width, height ) );
827                 if ( doublebuffer )
828                     _front = LVRef<LVDrawBuf>( createCanvas( width, height ) );
829             }
830         }
~CRGUIScreenBase()831         virtual ~CRGUIScreenBase()
832         {
833         }
834 };
835 
836 #ifdef CR_WX_SUPPORT
837 /// WXWidget support: draw to wxImage
838 class CRWxScreen : public CRGUIScreenBase
839 {
840     protected:
841         wxBitmap _wxbitmap;
update(const lvRect & rc,bool full)842         virtual void update( const lvRect & rc, bool full )
843         {
844             wxImage img;
845             int dyy = _canvas->GetHeight();
846             int dxx = _canvas->GetWidth();
847             int dx = dxx;
848             int dy = dyy;
849             img.Create(dx, dy, true);
850             unsigned char * bits = img.GetData();
851             for ( int y=0; y<dy && y<dyy; y++ ) {
852                 int bpp = _canvas->GetBitsPerPixel();
853                 if ( bpp==32 ) {
854                     const lUInt32* src = (const lUInt32*) _canvas->GetScanLine( y );
855                     unsigned char * dst = bits + y*dx*3;
856                     for ( int x=0; x<dx && x<dxx; x++ )
857                     {
858                         lUInt32 c = *src++;
859                         *dst++ = (c>>16) & 255;
860                         *dst++ = (c>>8) & 255;
861                         *dst++ = (c>>0) & 255;
862                     }
863                 } else if ( bpp==2 ) {
864                     //
865                     static const unsigned char palette[4][3] = {
866                         { 0xff, 0xff, 0xff },
867                         { 0xaa, 0xaa, 0xaa },
868                         { 0x55, 0x55, 0x55 },
869                         { 0x00, 0x00, 0x00 },
870                     };
871                     const lUInt8* src = (const lUInt8*) _canvas->GetScanLine( y );
872                     unsigned char * dst = bits + y*dx*3;
873                     for ( int x=0; x<dx && x<dxx; x++ )
874                     {
875                         lUInt32 c = (( src[x>>2] >> ((3-(x&3))<<1) ))&3;
876                         *dst++ = palette[c][0];
877                         *dst++ = palette[c][1];
878                         *dst++ = palette[c][2];
879                     }
880                 } else if ( bpp==1 ) {
881                     //
882                     static const unsigned char palette[2][3] = {
883                         { 0xff, 0xff, 0xff },
884                         { 0x00, 0x00, 0x00 },
885                     };
886                     const lUInt8* src = (const lUInt8*) _canvas->GetScanLine( y );
887                     unsigned char * dst = bits + y*dx*3;
888                     for ( int x=0; x<dx && x<dxx; x++ )
889                     {
890                         lUInt32 c = (( src[x>>3] >> ((7-(x&7))) ))&1;
891                         *dst++ = palette[c][0];
892                         *dst++ = palette[c][1];
893                         *dst++ = palette[c][2];
894                     }
895                 }
896             }
897 
898             // copy to bitmap
899             wxBitmap bmp( img );
900             _wxbitmap = bmp;
901         }
902     public:
CRWxScreen(int width,int height)903         CRWxScreen( int width, int height )
904         :  CRGUIScreenBase( width, height, true ) { }
getWxBitmap()905         wxBitmap getWxBitmap() { return _wxbitmap; }
906 };
907 #endif
908 
909 /// Window to show LVDocView contents
910 class CRDocViewWindow : public CRGUIWindowBase
911 {
912     protected:
913         LVDocView * _docview;
914 	    CRWindowSkinRef _skin;
915         virtual void draw();
916     public:
getDocView()917         LVDocView * getDocView()
918         {
919             return _docview;
920         }
CRDocViewWindow(CRGUIWindowManager * wm)921         CRDocViewWindow( CRGUIWindowManager * wm )
922         : CRGUIWindowBase( wm )
923         {
924             CRLog::trace("CRDocViewWindow()");
925             _docview = new LVDocView( wm->getScreen()->getCanvas()->GetBitsPerPixel() );
926             CRLog::trace("resizing...");
927             _docview->Resize( getWidth(), getHeight() );
928             _docview->setPageMargins( lvRect(10, 10, 10, 10) );
929             CRLog::trace("CRDocViewWindow() finished");
930         }
~CRDocViewWindow()931         virtual ~CRDocViewWindow()
932         {
933             delete _docview;
934             _docview = NULL;
935         }
936 
937         virtual void setRect( const lvRect & rc );
938 
939         /// returns true if command is processed
940         virtual bool onCommand( int command, int params );
941 
942 		/// returns true if window is changed but now drawn
isDirty()943         virtual bool isDirty()
944         {
945             return _dirty || !_docview->isPageImageReady( 0 );
946         }
947 };
948 
949 
950 
951 
952 
953 //===========================================================================================
954 // MENU SUPPORT
955 
956 enum CRMenuControlCmd {
957     MCMD_CANCEL=500,
958     MCMD_OK,
959     MCMD_SCROLL_FORWARD,
960     MCMD_SCROLL_BACK,
961     MCMD_SELECT_0,
962     MCMD_SELECT_1,
963     MCMD_SELECT_2,
964     MCMD_SELECT_3,
965     MCMD_SELECT_4,
966     MCMD_SELECT_5,
967     MCMD_SELECT_6,
968     MCMD_SELECT_7,
969     MCMD_SELECT_8,
970     MCMD_SELECT_9,
971     MCMD_SELECT_0_LONG,
972     MCMD_SELECT_1_LONG,
973     MCMD_SELECT_2_LONG,
974     MCMD_SELECT_3_LONG,
975     MCMD_SELECT_4_LONG,
976     MCMD_SELECT_5_LONG,
977     MCMD_SELECT_6_LONG,
978     MCMD_SELECT_7_LONG,
979     MCMD_SELECT_8_LONG,
980     MCMD_SELECT_9_LONG,
981     MCMD_SCROLL_FORWARD_LONG,
982     MCMD_SCROLL_BACK_LONG,
983     MCMD_CLEAR,
984     MCMD_NEXT_ITEM,
985     MCMD_PREV_ITEM,
986     MCMD_NEXT_PAGE,
987     MCMD_PREV_PAGE,
988     MCMD_SELECT,
989     MCMD_SELECT_LONG
990 };
991 
992 enum CRGUICmd {
993     GCMD_PASS_TO_PARENT = 550
994 };
995 
996 class CRMenu;
997 
998 /// CRGUI menu item base class
999 class CRMenuItem
1000 {
1001     protected:
1002         CRMenu * _menu;
1003         int _id;
1004         lString32 _label;
1005         LVImageSourceRef _image;
1006         LVFontRef _defFont;
1007         lString32 _propValue;
1008         bool _itemDirty;
1009     public:
1010         /// id of item
getId()1011         int getId() { return _id; }
1012         /// set id of item
setId(int id)1013         void setId( int id ) { _id = id; }
1014         /// item label
getLabel()1015         lString32 getLabel() { return _label; }
setLabel(lString32 label)1016         void setLabel(lString32 label) { _label = label; setItemDirty(); }
1017         /// item icon
getImage()1018         LVImageSourceRef getImage() { return _image; }
1019         /// item label font
getFont()1020         virtual LVFontRef getFont() { return _defFont; }
1021         /// constructor
1022         CRMenuItem( CRMenu * menu, int id, lString32 label, LVImageSourceRef image, LVFontRef defFont, const lChar32 * propValue=NULL  )
_menu(menu)1023     : _menu(menu), _id(id), _label(label), _image(image), _defFont(defFont), _propValue(propValue) { }
1024         /// constructor
1025         CRMenuItem( CRMenu * menu, int id, const char * label, LVImageSourceRef image, LVFontRef defFont, const lChar32 * propValue=NULL  )
_menu(menu)1026     : _menu(menu), _id(id), _label(label), _image(image), _defFont(defFont), _propValue(propValue) { }
1027         /// measures item size
1028         virtual lvPoint getItemSize( CRRectSkinRef skin );
1029         /// draws item
1030         virtual void Draw( LVDrawBuf & buf, lvRect & rc, CRRectSkinRef skin, CRRectSkinRef valueSkin, bool selected );
1031         /// returns true if submenu
isSubmenu()1032         virtual bool isSubmenu() const { return false; }
1033         /// called on item selection
onSelect()1034         virtual int onSelect() { return 0; }
~CRMenuItem()1035         virtual ~CRMenuItem() { }
1036         /// submenu for options dialog support
getSubmenuValue()1037         virtual lString32 getSubmenuValue() { return lString32::empty_str; }
1038         /// property value, for options editor support
getPropValue()1039         virtual lString32 getPropValue() { return _propValue; }
isItemDirty()1040         virtual bool isItemDirty() { return _itemDirty; }
setItemDirty()1041         virtual void setItemDirty() { _itemDirty = true; }
onLeave()1042         virtual void onLeave() { CRLog::trace("Menu item %d leave", _id); setItemDirty(); }
onEnter()1043         virtual void onEnter() { CRLog::trace("Menu item %d enter", _id); setItemDirty(); }
1044 };
1045 
1046 /// CRGUI menu base class
1047 class CRMenu : public CRGUIWindowBase, public CRMenuItem {
1048 	private:
1049 		void doCloseMenu(int command, bool highlight = false, int param = 0);
1050     protected:
1051         LVPtrVector<CRMenuItem> _items;
1052         CRPropRef _props;
1053         lString32 _propName;
1054         LVFontRef _valueFont;
1055         int _topItem;
1056         int _pageItems;
1057         int _helpHeight;
1058         int _cmdToHighlight;
1059         int _selectedItem;
1060         bool _pageUpdate;
1061         CRMenuSkinRef _skin;// = _wm->getSkin()->getMenuSkin( path.c_str() );
1062         // override for CRGUIWindow method
1063         virtual void draw();
1064         virtual void Draw( LVDrawBuf & buf, lvRect & rc, CRRectSkinRef skin, CRRectSkinRef valueSkin, bool selected );
1065         //virtual void Draw( LVDrawBuf & buf, int x, int y );
1066         virtual void highlightCommandItem( int cmd );
1067 		virtual bool onItemSelect(int command, int params = 0 );
1068 		int getLastOnPage();
1069     public:
1070         /// returns index of selected item, -1 if no item selected
1071         virtual int getSelectedItemIndex();
getDefaultSelectionIndex()1072         virtual int getDefaultSelectionIndex()
1073         {
1074 #ifdef CR_POCKETBOOK
1075 			if (getProps().isNull())
1076 				return 0;
1077 #endif
1078 			return -1;
1079         }
1080         virtual void activated();
1081         virtual void drawClient();
1082         virtual int getScrollHeight();
1083         CRMenuSkinRef getSkin();
1084         CRMenu( CRGUIWindowManager * wm, CRMenu * parentMenu, int id, lString32 label, LVImageSourceRef image, LVFontRef defFont, LVFontRef valueFont, CRPropRef props=CRPropRef(), const char * propName=NULL, int pageItems=8 )
CRGUIWindowBase(wm)1085         : CRGUIWindowBase( wm ), CRMenuItem( parentMenu, id, label, image, defFont ), _props(props), _propName(Utf8ToUnicode(lString8(propName))), _valueFont(valueFont), _topItem(0), _pageItems(pageItems),
1086           _cmdToHighlight(-1), _selectedItem(-1), _pageUpdate(true)
1087         { _fullscreen = false; _helpHeight=0; }
1088         CRMenu( CRGUIWindowManager * wm, CRMenu * parentMenu, int id, const char * label, LVImageSourceRef image, LVFontRef defFont, LVFontRef valueFont, CRPropRef props=CRPropRef(), const char * propName=NULL, int pageItems=8 )
CRGUIWindowBase(wm)1089         : CRGUIWindowBase( wm ), CRMenuItem( parentMenu, id, label, image, defFont ), _props(props), _propName(Utf8ToUnicode(lString8(propName))), _valueFont(valueFont), _topItem(0), _pageItems(pageItems),
1090         _cmdToHighlight(-1)
1091         { _fullscreen = false; _helpHeight=0; }
isSubmenu()1092         virtual bool isSubmenu() const { return true; }
getItems()1093         LVPtrVector<CRMenuItem> & getItems() { return _items; }
getProps()1094         CRPropRef getProps() const { return _props; }
getPropName()1095         lString32 getPropName() const { return _propName; }
getValueFont()1096         LVFontRef getValueFont() const { return _valueFont; }
setValueFont(LVFontRef font)1097         void setValueFont( LVFontRef font ) { _valueFont = font; }
addItem(CRMenuItem * item)1098         void addItem( CRMenuItem * item ) { _items.add( item ); }
findItem(int id)1099         CRMenuItem * findItem( int id ) {
1100             for ( int i=0; i<_items.length(); i++ )
1101                 if ( _items[i]->getId()==id )
1102                     return _items[i];
1103             return NULL;
1104         }
findSubmenu(int id)1105         CRMenu * findSubmenu( int id ) {
1106             for ( int i=0; i<_items.length(); i++ )
1107                 if ( _items[i]->getId()==id && _items[i]->isSubmenu() )
1108                     return (CRMenu*)_items[i];
1109             return NULL;
1110         }
1111         /// called on system configuration change: screen size and orientation
1112         virtual void reconfigure( int flags );
1113         virtual int getPageCount();
1114         /// returns true if current page is changed
1115         virtual bool setCurPage( int nPage );
1116 		virtual void setCurItem(int nItem);
1117         virtual int getCurPage( );
1118         virtual int getTopItem();
1119         virtual lString32 getSubmenuValue();
1120         virtual void toggleSubmenuValue();
1121         virtual int getItemHeight();
1122         virtual lvPoint getMaxItemSize();
1123         virtual lvPoint getItemSize();
1124         virtual lvPoint getSize();
~CRMenu()1125         virtual ~CRMenu() { }
1126         // CRGUIWindow
1127         virtual const lvRect & getRect();
1128         /// overriden to disable passing key to parent windows
1129         virtual bool onKeyPressed( int key, int flags );
1130         /// returns true if command is processed
1131         virtual bool onCommand( int command, int params = 0 );
1132         /// closes menu and its submenus, posts command
1133         virtual void closeMenu( int command, int params = 0 );
1134         /// closes top level menu and its submenus, posts command
1135         virtual void closeAllMenu( int command, int params = 0 );
1136         /// closes menu and its submenus
1137         virtual void destroyMenu();
covered()1138         virtual void covered() { _pageUpdate = true; }
1139 };
1140 
1141 class CRGUIUpdateEvent : public CRGUIEvent
1142 {
1143 public:
1144     CRGUIUpdateEvent( bool fullScreen=false )
CRGUIEvent(CREV_UPDATE)1145     : CRGUIEvent( CREV_UPDATE )
1146     {
1147         _param1 = fullScreen ? 1 : 0;
1148     }
handle(CRGUIWindow * window)1149     virtual bool handle( CRGUIWindow * window )
1150     {
1151         return false;
1152     }
handle(CRGUIWindowManager * wm)1153     virtual bool handle( CRGUIWindowManager * wm )
1154     {
1155         wm->update( _param1!=0, false );
1156         return true;
1157     }
1158 };
1159 
1160 class CRGUIResizeEvent : public CRGUIEvent
1161 {
1162     cr_rotate_angle_t _angle;
1163 public:
CRGUIResizeEvent(int dx,int dy,cr_rotate_angle_t angle)1164     CRGUIResizeEvent( int dx, int dy, cr_rotate_angle_t angle )
1165     : CRGUIEvent( CREV_RESIZE )
1166     {
1167         _param1 = dx;
1168         _param2 = dy;
1169         _angle = angle;
1170     }
handle(CRGUIWindow * window)1171     virtual bool handle( CRGUIWindow * window )
1172     {
1173         return false;
1174     }
handle(CRGUIWindowManager * wm)1175     virtual bool handle( CRGUIWindowManager * wm )
1176     {
1177         wm->reconfigure(_param1, _param2, _angle);
1178         return true;
1179     }
1180 };
1181 
1182 class CRGUIKeyDownEvent : public CRGUIEvent
1183 {
1184 public:
isForVisibleOnly()1185     virtual bool isForVisibleOnly() { return true; }
isForModalOnly()1186     virtual bool isForModalOnly() { return true; }
CRGUIKeyDownEvent(int key,int params)1187     CRGUIKeyDownEvent( int key, int params )
1188     : CRGUIEvent( CREV_KEYDOWN )
1189     {
1190         _param1 = key;
1191         _param2 = params;
1192     }
1193     virtual bool handle( CRGUIWindow * window );
handle(CRGUIWindowManager * wm)1194     virtual bool handle( CRGUIWindowManager * wm ) { return false; }
1195 };
1196 
1197 class CRGUICommandEvent : public CRGUIEvent
1198 {
1199 public:
CRGUICommandEvent(int cmd,int params)1200     CRGUICommandEvent( int cmd, int params )
1201     : CRGUIEvent( CREV_COMMAND )
1202     {
1203         _param1 = cmd;
1204         _param2 = params;
1205     }
1206     virtual bool handle( CRGUIWindow * window );
handle(CRGUIWindowManager * wm)1207     virtual bool handle( CRGUIWindowManager * wm ) { return false; }
isForModalOnly()1208     virtual bool isForModalOnly() { return false; }
isForVisibleOnly()1209     virtual bool isForVisibleOnly() { return true; }
1210 };
1211 
1212 
1213 #endif// CR_GUI_INCLUDED
1214