[sword-svn] r217 - trunk/src/SlideBible

kalemas at crosswire.org kalemas at crosswire.org
Sat Oct 31 14:48:40 MST 2009


Author: kalemas
Date: 2009-10-31 14:48:40 -0700 (Sat, 31 Oct 2009)
New Revision: 217

Modified:
   trunk/src/SlideBible/main.cpp
   trunk/src/SlideBible/sbCore.cpp
   trunk/src/SlideBible/sbCore.h
   trunk/src/SlideBible/sbItem.cpp
   trunk/src/SlideBible/sbList.cpp
   trunk/src/SlideBible/sbList.h
   trunk/src/SlideBible/sbTheme.cpp
   trunk/src/SlideBible/todo.txt
Log:
several bugs, see todo

Modified: trunk/src/SlideBible/main.cpp
===================================================================
--- trunk/src/SlideBible/main.cpp	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/main.cpp	2009-10-31 21:48:40 UTC (rev 217)
@@ -39,7 +39,7 @@
 		wc.hCursor       = 0;
 		wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
 		wc.lpszMenuName  = 0;
-		wc.lpszClassName = L"sbApp";
+		wc.lpszClassName = L"SlideBible Application";
 
 		if (!RegisterClass(&wc))
 		{
@@ -47,7 +47,7 @@
 			return;
 		}
 
-		core = new sbCore();
+		core = new sbCore ( hInstance );
 	}
 
    	~sbApp()
@@ -125,22 +125,20 @@
 	}
 
 private:
-    static HINSTANCE        s_hInstance;
+    HINSTANCE               s_hInstance;
     HACCEL                  m_hAccelTable;
-    static SHACTIVATEINFO   s_sai;
+    SHACTIVATEINFO          s_sai;
     static sbCore          *core;
 };
 
-HINSTANCE sbApp::s_hInstance = SR_NON_INSTANCE;
-SHACTIVATEINFO sbApp::s_sai;
-sbCore* sbApp::core          = NULL;
+sbCore * sbApp::core = NULL;
 
 int WINAPI WinMain(	HINSTANCE hInstance,
 					HINSTANCE hPrevInstance,
 					LPTSTR    lpCmdLine,
 					int       nCmdShow)
 {
-	HWND hwnd = FindWindow(L"SlideBible", L"SlideBible");
+	HWND hwnd = FindWindow(L"SlideBible Application", L"SlideBible");
 
 	if (hwnd)
 	{

Modified: trunk/src/SlideBible/sbCore.cpp
===================================================================
--- trunk/src/SlideBible/sbCore.cpp	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbCore.cpp	2009-10-31 21:48:40 UTC (rev 217)
@@ -46,8 +46,10 @@
 
 LRESULT CALLBACK sbCoreWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
 
-sbCore::sbCore()
+sbCore::sbCore( HINSTANCE hInstance ) : defaultModule (NULL)
 {
+	sbMessage ("Launch SlideBible Core.\n");
+
 	// init data
 	Core            = this;
 	
@@ -64,12 +66,13 @@
 	memset(&threadData, 0, sizeof(THREAD_DATA));
 
 	// init windows
-	hContainer = CreateWindow(L"sbApp", L"SlideBible", WS_VISIBLE,
+	hContainer = CreateWindow(L"SlideBible Application", L"SlideBible", WS_VISIBLE,
 		0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
-		NULL, NULL, NULL, NULL);
+		NULL, NULL, hInstance, NULL);
 
 	if (hContainer == NULL)
 	{
+		sbMessage ("Can not create window becouse of %i error.\n",GetLastError());
 		PostQuitMessage(1);
 		return;
 	}
@@ -156,6 +159,13 @@
 	
 	sbAssert(mpSwordMgr == NULL);
 
+	currentModule = mpSwordMgr->getModule((*mpOptions)["General"].getWithDefault("DefaultModule", "KJV"));
+
+	if (currentModule == NULL && mpSwordMgr->Modules.size() != 0)
+		currentModule = mpSwordMgr->Modules.begin()->second;
+
+	((sword::SWModule*)defaultModule) = currentModule;
+
 	bookmarks.load(".\\verselists.conf","Bookmarks");
 
 	// create ui
@@ -185,13 +195,11 @@
 		}
 	}
 
-	mpOptions->Save();
+	if (mpOptions != NULL) mpOptions->Save();
 
 	// clear sword
-	if (mpSwordMgr != NULL)
-		delete mpSwordMgr;
-	if (mpOptions != NULL)
-		delete mpOptions;
+	if (mpSwordMgr != NULL) delete mpSwordMgr;
+	if (mpOptions != NULL) delete mpOptions;
 
 	for (int i=0; i<SURFACE::COUNT; i++)
 	{
@@ -204,6 +212,8 @@
 	for (std::map<const char *, int>::iterator it = sbObject::tracker.begin(); it != sbObject::tracker.end(); it++)
 		if (it->second != 0)
 			sbMessage ("new/delete misalignment for %s (%i)\n", it->first, it->second);
+
+	sbMessage ("Shutdown SlideBible Core.\n");
 }
 
 bool sbCore::onPaint()
@@ -439,12 +449,14 @@
 	{
 	case TIMER_REDRAW:
 		{
-			if (requestedRedraw)
+			if ( requestedRedraw )
 			{
+				if ( currentList != NULL ) currentList->onTimer( TIMER_BEFORE_REDRAW );
+
 				requestedRedraw = false;
 		
-				InvalidateRect(hContainer, &rClient, false);
-				return UpdateWindow(hContainer) != FALSE;
+				InvalidateRect( hContainer, &rClient, false );
+				return UpdateWindow( hContainer ) != FALSE;
 			}
 		}
 		break;

Modified: trunk/src/SlideBible/sbCore.h
===================================================================
--- trunk/src/SlideBible/sbCore.h	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbCore.h	2009-10-31 21:48:40 UTC (rev 217)
@@ -75,38 +75,37 @@
 		TIMER_TAP,
 		TIMER_BANNER,
 		TIMER_REDRAW,
+		TIMER_BEFORE_REDRAW, // send only before calling redraw view
 		TIMER_SLIDE
 	};
 
-	sbCore();
+	sbCore ( HINSTANCE hInstance );
 	~sbCore();
 	
-	bool                         onMouse        ( int x, int y, const int state );
-	bool                         onPaint        ( );
-	bool                         onTimer        ( const int timer );
-	void                         onChar         ( TCHAR c );
-	bool                         onKeyDown      ( int key );
-	bool                         onKeyUp        ( int key );
+	bool                         onMouse          ( int x, int y, const int state );
+	bool                         onPaint          ( );
+	bool                         onTimer          ( const int timer );
+	void                         onChar           ( TCHAR c );
+	bool                         onKeyDown        ( int key );
+	bool                         onKeyUp          ( int key );
 
-	void                         redraw         ();
+	void                         redraw           ( );
 
-	const sbTheme*               getTheme       ()                   {return &theme;}
-	sword::SWMgr*                getSword       ()                   {return mpSwordMgr;}
-	sword::SWConfig*             getOptions     ()                   {return mpOptions;}
-	const SURFACE*               getSurface     (SURFACE::TYPE type) {return &surfaces[type];}
-	const INPUT*                 getInput       ()                   {return &input;}
-	sbCollection*                getBookmarks   ()                   {return &bookmarks;}
-
-	void                         setSipState    (bool on);
-
-
+	const sbTheme*               getTheme         ( )                    {return &theme;}
+	sword::SWMgr*                getSword         ( )                    {return mpSwordMgr;}
+	sword::SWConfig*             getOptions       ( )                    {return mpOptions;}
+	const SURFACE*               getSurface       ( SURFACE::TYPE type ) {return &surfaces[type];}
+	const INPUT*                 getInput         ( )                    {return &input;}
+	sbCollection*                getBookmarks     ( )                    {return &bookmarks;}
 	
-	void                         switchList     (sbList::TYPE to);
+	void                         setSipState      ( bool on );
+	
+	void                         switchList       ( sbList::TYPE to );
 
-	void                         threadCreate   (sbList *list);
-	void                         threadDestroy  ();
+	void                         threadCreate     ( sbList *list );
+	void                         threadDestroy    ( );
 	
-	void                         controlPressed (sbControl::TYPE type);
+	void                         controlPressed   ( sbControl::TYPE type );
 
 private:
 	struct THREAD_DATA
@@ -165,8 +164,12 @@
 	unsigned int                 scrollStep;
 	unsigned int                 versesMax;
 	unsigned int                 versesOptimal;
+
+
+	sword::SWModule * const      defaultModule;
+	sword::SWModule             *currentModule;
 };
 
 extern sbCore* Core;
 
-#endif
\ No newline at end of file
+#endif

Modified: trunk/src/SlideBible/sbItem.cpp
===================================================================
--- trunk/src/SlideBible/sbItem.cpp	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbItem.cpp	2009-10-31 21:48:40 UTC (rev 217)
@@ -37,6 +37,8 @@
 			sbAssert(true);
 		}
 	}
+
+	center = false;
 	
 	switch ( type )
 	{
@@ -44,25 +46,29 @@
 	case TYPE_BUTTON_CHAPTER_NEXT:
 	case TYPE_BUTTON_CHAPTER_PREV:
 		style = sbTheme::STYLE::DESCRIPTION;
+		lines.reserve(2);
 		break;
 
+	case TYPE_CHECKBOX:
+		center = true;
 	case TYPE_BUTTON_BOOKMARK:
 	case TYPE_BUTTON_SELECTION_BOOK:
 	case TYPE_BUTTON_SELECTION_CHAPTER:
 	case TYPE_BUTTON_SELECTION_MODULE:
 		style = sbTheme::STYLE::BUTTON;
+		lines.reserve(2);
 		break;
 
 	case TYPE_HEADER:
 		style = sbTheme::STYLE::CAPTION;
 		center = true;
+		lines.reserve(2);
 		break;
 
 	default:
 		style = sbTheme::STYLE::TEXT;
 	}
 
-	center      = false;
 	highlighted = false;
 	height      = Core->getTheme()->styles[style].size + Core->getTheme()->itemTopMargin + Core->getTheme()->itemBottomMargin;
 	expanding   = 0;
@@ -165,12 +171,12 @@
 
 	sbAssert( _text_ == NULL );
 	
-	SelectObject (Core->getSurface(sbCore::SURFACE::TYPE_ZERO)->hdc, Core->getTheme()->styles[style].font);
+	if ( ! lines.empty() ) lines.clear();
 
-	if ( ! lines.empty() ) lines.erase( lines.begin(), lines.end() );
-
 	lines.push_back( LINE (style) );
 
+	SelectObject (Core->getSurface(sbCore::SURFACE::TYPE_ZERO)->hdc, Core->getTheme()->styles[style].font);
+
 	for(int i=0; i<length; i++)
 	{
 		TCHAR c = *(_text_+i);
@@ -246,7 +252,10 @@
 			lines.back().width += (unsigned short) sz.cx;
 			
 			if (sz.cy > lines.back().height)
+			{
+				sbAssert ((sz.cy >= 30) && (type == TYPE_VERSE));
 				lines.back().height = (unsigned short) sz.cy;
+			}
 			
 			lines.back().count++;
 
@@ -258,13 +267,7 @@
 
 	height = Core->getTheme()->itemTopMargin + Core->getTheme()->itemBottomMargin;
 
-	for (int i=0; i<lines.size(); i++)
-	{
-		if (lines[i].newLine)
-		{
-			height += lines[i].height;
-		}
-	}
+	for (int i=0; i<lines.size(); i++) if (lines[i].newLine) height += lines[i].height;
 
 	if (style == sbTheme::STYLE::BUTTON && height < Core->getTheme()->fingerSize)
 	{

Modified: trunk/src/SlideBible/sbList.cpp
===================================================================
--- trunk/src/SlideBible/sbList.cpp	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbList.cpp	2009-10-31 21:48:40 UTC (rev 217)
@@ -15,6 +15,7 @@
 
 #include "sbCore.h"
 #include "sbList.h"
+#include <swversion.h>
 
 #pragma warning ( disable : 4018 )
 
@@ -81,61 +82,77 @@
 		{
 			itemCurrent = new sbItem (sbItem::TYPE_CHECKBOX, L"v", Core->getTheme()->size/5);
 			itemCurrent->attach(new sbItem (sbItem::TYPE_DESCRIPTION, L"Background text loading", rect->width()-(Core->getTheme()->size/5)), sbItem::RIGHT);
+			TCHAR vesionText[64];
+			_sntprintf(vesionText,64,L"Current SWORD version :\n%S",sword::SWVersion::currentVersion.getText());
+			itemCurrent->attach(new sbItem (sbItem::TYPE_TEXT, vesionText, rect->width()), sbItem::NEXT);
+			itemCurrent = itemCurrent->next;
+			itemCurrent->center = true;
 		}
 		break;
 
 	case TYPE_HOME:
 		{
 			itemCurrent = new sbItem (sbItem::TYPE_HEADER, L"Welcome to\nSlideBible!", rect->width());
-			
-			if ((*Core->getOptions())["Bookmarks"]["LastPlace"]!="")
+
+			addControl(sbControl::TYPE_BUTTON_OPEN_FILE);
+			addControl(sbControl::TYPE_OPEN_SEARCH);
+			addControl(sbControl::TYPE_BUTTON_CLOSE);
+
+			if (Core->defaultModule != NULL)
 			{
-				itemCurrent->attach(new sbItem (sbItem::TYPE_DESCRIPTION, L"Your Last Place :", rect->width()), sbItem::NEXT);
-				itemCurrent->center = true;
-				itemCurrent = itemCurrent->next;
+				sword::VerseKey workKey ( Core->defaultModule->getKey() );
 
-				const char* b = (*Core->getOptions())["Bookmarks"]["LastPlace"];
+				if ((*Core->getOptions())["Bookmarks"]["LastPlace"] != "")
+				{
+					itemCurrent->attach(new sbItem (sbItem::TYPE_DESCRIPTION, L"Your Last Place :", rect->width()), sbItem::NEXT);
+					itemCurrent->center = true;
+					itemCurrent = itemCurrent->next;
 
-				sword::VerseKey tmpKey(b);
+					const char * bookmark = (*Core->getOptions())["Bookmarks"]["LastPlace"];
 
-				TCHAR *text = new TCHAR [strlen(b)+1];
-				mbstowcs(text, b, strlen(b)+1);
+					workKey.setText ( bookmark );
 
-				itemCurrent->attach(new sbItem (sbItem::TYPE_BUTTON_BOOKMARK, text, rect->width(), tmpKey.Index()), sbItem::NEXT);
-				itemCurrent = itemCurrent->next;
-				itemCurrent->center = true;
+					TCHAR * text = new TCHAR [strlen( bookmark ) + 1];
+					mbstowcs ( text, bookmark , strlen( bookmark ) + 1 );
 
-				delete [] text;
-			}
+					itemCurrent->attach(new sbItem (sbItem::TYPE_BUTTON_BOOKMARK, text, rect->width(), workKey.Index()), sbItem::NEXT);
+					itemCurrent = itemCurrent->next;
+					itemCurrent->center = true;
 
-			for (int i=0; i<Core->getBookmarks()->count(); i++)
-			{
-				if (i == 0)
+					delete [] text;
+				}
+
+				for (int i=0; i < Core->getBookmarks()->count(); i++)
 				{
-					itemCurrent->attach(new sbItem (sbItem::TYPE_DESCRIPTION, L"Your Bookmarks :", rect->width()), sbItem::NEXT);
+					if (i == 0)
+					{
+						itemCurrent->attach(new sbItem (sbItem::TYPE_DESCRIPTION, L"Your Bookmarks :", rect->width()), sbItem::NEXT);
+						itemCurrent->center = true;
+						itemCurrent = itemCurrent->next;
+					}
+
+					const char* bm = (*Core->getBookmarks())[i].verse.getText();
+
+					TCHAR *text = new TCHAR [strlen(bm)+1];
+					mbstowcs(text, bm, strlen(bm)+1);
+
+					itemCurrent->attach(new sbItem (sbItem::TYPE_BUTTON_BOOKMARK, text, rect->width(), (*Core->getBookmarks())[i].verse.Index()), sbItem::NEXT);
+					itemCurrent = itemCurrent->next;
 					itemCurrent->center = true;
-					itemCurrent = itemCurrent->next;
+
+					delete [] text;
 				}
 
-				const char* bm = (*Core->getBookmarks())[i].verse.getText();
-			
-				TCHAR *text = new TCHAR [strlen(bm)+1];
-				mbstowcs(text, bm, strlen(bm)+1);
-
-				itemCurrent->attach(new sbItem (sbItem::TYPE_BUTTON_BOOKMARK, text, rect->width(), (*Core->getBookmarks())[i].verse.Index()), sbItem::NEXT);
+				addControl(sbControl::TYPE_OPEN_TEXT);
+			}
+			else
+			{
+				itemCurrent->attach(new sbItem (sbItem::TYPE_TEXT, L"No modules Found!\n\nPlease download any Bible module from www.crosswire.org and put \"mods.d\" and \"modules\" folders into application floder.", rect->width()), sbItem::NEXT);
 				itemCurrent = itemCurrent->next;
-				itemCurrent->center = true;
-
-				delete [] text;
 			}
 
 			while (itemCurrent->prev != NULL)
 				itemCurrent = itemCurrent->prev;
-
-			addControl(sbControl::TYPE_BUTTON_OPEN_FILE);
-			addControl(sbControl::TYPE_OPEN_SEARCH);
-			addControl(sbControl::TYPE_OPEN_TEXT);
-			addControl(sbControl::TYPE_BUTTON_CLOSE);
 		}
 		break;
 
@@ -180,20 +197,21 @@
 		break;
 
 	case PIN_PARENT:
-		if (type == TYPE_SELECT_BOOK || type == TYPE_SELECT_MODULE)
+		if ( type == TYPE_SELECT_BOOK || type == TYPE_SELECT_MODULE )
 		{
 			parent = list;
-			module = list->module;
-			setKey(list->key);
+			
+			module = list->module == NULL ? Core->currentModule : list->module;
+			
+			setKey ( module->getKey() );
 		}
-		else if (type == TYPE_HOME || type == TYPE_SEARCH)
+		else if ( type == TYPE_HOME || type == TYPE_SEARCH )
 		{
 			parent = list;
 		}
 		else
-		{
-			sbAssert(true);
-		}
+			sbAssert ( true );
+
 		break;
 
 	default:
@@ -208,7 +226,9 @@
 	clear();
 
 	if (next != NULL)
+	{
 		next->prev = prev;
+	}
 	else
 	{
 		//if (type != TYPE_MODULE_VIEW)
@@ -216,15 +236,16 @@
 	}
 	
 	if (prev != NULL)
+	{
 		prev->next = next;
+	}
 	else
 	{
 		//if (type != TYPE_MODULE_VIEW)
 		//	addControl(sbControl::TYPE_CAN_SWITCH_LEFT, false);
 	}
 
-	for (int i=0; i < controls.size(); i++)
-		delete controls[i];
+	for (int i=0; i < controls.size(); i++) delete controls[i];
 }
 
 /*   sbList::setKey
@@ -313,30 +334,32 @@
 
 	case TYPE_SELECT_BOOK:
 		{
-			sbItem* setItem = NULL;
+			sbItem * setItem = NULL;
 
+			sbAssert (module == NULL);
+			
+			sword::VerseKey workKey = module->getKey();
+
+			const char * moduleBook = workKey.getBookName();
+
 			clear();
 
-			sword::VerseKey tmpKey (verse);
+			workKey.setPosition(sword::TOP);
 
-			tmpKey.setPosition(sword::TOP);
-
-			while (true)
+			while ( true )
 			{
-				const char *book = tmpKey.getBookName();
+				const char * book = workKey.getBookName();
 
-				TCHAR *text = new TCHAR [strlen(book)+1];
+				TCHAR * text = new TCHAR [strlen(book)+1];
 				
 				mbstowcs(text,book,strlen(book)+1);
 
-				sbItem *item = new sbItem (sbItem::TYPE_BUTTON_SELECTION_BOOK, text, rect->width(), tmpKey.Index());
+				sbItem *item = new sbItem (sbItem::TYPE_BUTTON_SELECTION_BOOK, text, rect->width(), workKey.Index());
 				item->center = true;
 
 				delete [] text;
 
-				if (parent->module != NULL &&
-					parent->key.getTestament() == tmpKey.getTestament() &&
-					parent->key.getBook() == tmpKey.getBook())
+				if (moduleBook == book)
 				{
 					setItem = item;
 				}
@@ -352,12 +375,11 @@
 				}
 
 				// next book
-				int b = tmpKey.getBook();
+				int b = workKey.getBook();
 
-				tmpKey.setBook(b+1);
+				workKey.setBook(workKey.getBook()+1);
 
-				if (b == tmpKey.getBook())
-					break;
+				if (b == workKey.getBook()) break;
 			}
 
 			if (setItem != NULL)
@@ -374,21 +396,15 @@
 
 	case TYPE_MODULE_VIEW:
 		{
-			int curIndex = verse.Index();
-
-			if (module == NULL)
-			{
-				module = Core->getSword()->getModule((*Core->getOptions())["General"].getWithDefault("DefaultModule", "KJV"));
-
-				if (module == NULL && Core->getSword()->Modules.size() != 0)
-					module = Core->getSword()->Modules.begin()->second;
-			}
+			if (module == NULL) module = Core->defaultModule;
 			
 			sbAssert(module == NULL);
 
-			if (next == NULL) attach(new sbList(sbList::TYPE_MODULE_VIEW), sbList::PIN_NEXT);
-			if (prev == NULL) attach(new sbList(sbList::TYPE_MODULE_VIEW), sbList::PIN_PREV);
+			//sbAssert(strcmp(verse.getVersificationSystem(),module->getConfigEntry("Versification")));
 
+			if (next == NULL) attach (new sbList(sbList::TYPE_MODULE_VIEW), sbList::PIN_NEXT);
+			if (prev == NULL) attach (new sbList(sbList::TYPE_MODULE_VIEW), sbList::PIN_PREV);
+
 			addControl(sbControl::TYPE_CAN_SWITCH_LEFT);
 			if (prev != NULL) prev->addControl(sbControl::TYPE_CAN_SWITCH_RIGHT);
 
@@ -397,15 +413,19 @@
 
 			clear();
 		
-			key = verse;
+			key.setVersificationSystem( module->getConfigEntry("Versification") );
 
-			addBlankVerses();
+			key.setText ( verse.getText() );
 
-			displaceHeight = (rect->height()-itemCurrent->height)/2;
+			displaceHeight = rect->height()*2/5;
 
+			// adding blank verses starts automatically before redraw
+			// filling with text occurs in background thread
+
 			Core->redraw();
 		}
 		break;
+
 	default:
 		sbAssert(true);
 	}
@@ -418,185 +438,150 @@
 {
 	if (itemCurrent != NULL)
 	{
-		while (itemCurrent->prev != NULL)
-			delete itemCurrent->prev;
+		while (itemCurrent->prev != NULL) delete itemCurrent->prev;
 
-		while (itemCurrent->next != NULL)
-			delete itemCurrent->next;
+		while (itemCurrent->next != NULL) delete itemCurrent->next;
 
 		delete itemCurrent;
 
-		itemCurrent = NULL;
-
-		verseFirst = NULL;
-		verseLast = NULL;
-		versesForward = 0;
+		itemCurrent    = NULL;
+		verseFirst     = NULL;
+		verseLast      = NULL;
+		versesForward  = 0;
 		versesBackward = 0;
+		displaceHeight = 0;
 
-		if (type ==TYPE_MODULE_VIEW)
-			listStartConstructed = listEndConstructed = false;
-
-		displaceHeight = 0;
+		if (type == TYPE_MODULE_VIEW) listStartConstructed = listEndConstructed = false;
 	}
 }
 
 /*   sbList::render
  *   draw list
  */
-void sbList::render (HDC hdc)
+void sbList::render ( HDC hdc )
 {
-	sbItem *oldItem,*dItem;
-	sbRect rItem;
-	int screenHeight;
+	sbItem *oldItem , *workItem = itemCurrent;
+	sbRect workRect;
+	int screenHeight = displaceHeight;
 
-	addBlankVerses();
-
-	// itemCurrent may be not first on screen, so do correction
-	if (itemCurrent != NULL)
-	{
-		while (displaceHeight > -Core->getTheme()->ListSeparatorHeight && itemCurrent->prev != NULL)
-		{
-			if (itemCurrent->type == sbItem::TYPE_VERSE)
-				{ versesBackward--; versesForward++; }
-
-			itemCurrent = itemCurrent->prev;
-			displaceHeight -= itemCurrent->height + Core->getTheme()->ListSeparatorHeight;
-		}
-
-		while (displaceHeight < 0 && abs(displaceHeight) > itemCurrent->height + Core->getTheme()->ListSeparatorHeight)
-		{
-			if (itemCurrent->next == NULL) break;
-
-			displaceHeight += itemCurrent->height + Core->getTheme()->ListSeparatorHeight;
-
-			if (itemCurrent->type == sbItem::TYPE_VERSE)
-				{ versesBackward++; versesForward--; }
-
-			itemCurrent = itemCurrent->next;
-		}
-	}
-
-	dItem = itemCurrent;
-	screenHeight = displaceHeight;
-
-	Core->getTheme()->drawElement(hdc, rect, sbTheme::ELEMENT::BACKGROUND);
+	Core->getTheme()->drawElement( hdc, rect, sbTheme::ELEMENT::BACKGROUND );
 	
-	while(true)
+	while ( true )
 	{
-		if (dItem == NULL) break;
+		if (workItem == NULL) break;
 
 		if (screenHeight > rect->bottom()) break;
 
-		oldItem = dItem;
+		oldItem = workItem;
 
-		if (Core->getTheme()->ListSeparatorHeight > 0 && dItem->prev == NULL)
+		if (Core->getTheme()->ListSeparatorHeight > 0 && workItem->prev == NULL)
 		{
-			rItem = *rect;
-			rItem.bottom ( screenHeight );
-			rItem.top ( rItem.bottom()-Core->getTheme()->ListSeparatorHeight );
-			Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::SEPARATOR);
+			workRect = *rect;
+			workRect.bottom ( screenHeight );
+			workRect.top ( workRect.bottom()-Core->getTheme()->ListSeparatorHeight );
+			Core->getTheme()->drawElement(hdc, &workRect, sbTheme::ELEMENT::SEPARATOR);
 		}
 
-		rItem = *rect;
-		rItem.right (0);
+		workRect = *rect;
+		workRect.right (0);
 
 		// horizontal parse
-		while (dItem != NULL)
+		while (workItem != NULL)
 		{
-			rItem.top    ( screenHeight );
-			rItem.bottom ( rItem.top() + dItem->height );
-			rItem.left   ( rItem.right() );
-			rItem.right  ( rItem.left() + dItem->width );
+			sbTheme::ELEMENT::TYPE element = sbTheme::ELEMENT::ITEM;
 
-			if ( dItem == itemHover )
-				Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::ITEM_HOVER);
-			else if (dItem==itemSelected)
-				Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::ITEM_SELECTED);
-			else if (dItem->highlighted)
-				Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::ITEM_HIGHLIGHTED);
-			else
-				Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::ITEM);
+			workRect.top    ( screenHeight );
+			workRect.bottom ( workRect.top() + workItem->height );
+			workRect.left   ( workRect.right() );
+			workRect.right  ( workRect.left() + workItem->width );
 
-			if (dItem->text.size() > 0)
+			if ( workItem == itemHover )       element = sbTheme::ELEMENT::ITEM_HOVER;
+			else if (workItem == itemSelected) element = sbTheme::ELEMENT::ITEM_SELECTED;
+			else if (workItem->highlighted)    element = sbTheme::ELEMENT::ITEM_HIGHLIGHTED;
+
+			Core->getTheme()->drawElement( hdc, &workRect, element );
+
+			if ( workItem->text.size() > 0 )
 			{
-				if (dItem->subtext.size() > 0)
+				if ( workItem->subtext.size() > 0 )
 				{
+					SIZE size;
+
 					SelectObject(hdc, Core->getTheme()->styles[sbTheme::STYLE::STANZA].font);
 					SetTextColor(hdc, Core->getTheme()->ItemSubTextColor);
 
-					SIZE sz;
-					GetTextExtentPoint32(hdc, dItem->subtext.c_str(), dItem->subtext.size(), &sz);
+					GetTextExtentPoint32(hdc, workItem->subtext.c_str(), workItem->subtext.size(), &size);
 
-					ExtTextOut(hdc, rItem.left()+((Core->getTheme()->itemLeftMargin-sz.cx)/2), rItem.top(), ETO_OPAQUE, NULL, dItem->subtext.c_str(), dItem->subtext.size(), 0);
+					ExtTextOut(hdc, workRect.left()+((Core->getTheme()->itemLeftMargin-size.cx)/2), workRect.top(), ETO_OPAQUE, NULL, workItem->subtext.c_str(), workItem->subtext.size(), 0);
 				}
 			
 				SetTextColor(hdc, Core->getTheme()->ItemTextColor);
 
 				int lx = 0;
-				int ly = rItem.top() + Core->getTheme()->itemTopMargin;
+				int ly = workRect.top() + Core->getTheme()->itemTopMargin;
 				
-				for (int i=0; i < dItem->lines.size(); i++)
+				for (int i=0; i < workItem->lines.size(); i++)
 				{
-					int x = lx + Core->getTheme()->itemLeftMargin + rItem.left();
+					int x = lx + Core->getTheme()->itemLeftMargin + workRect.left();
 					int y = ly;
 
 					// possible BUG with center alignment and many text parts
-					if (dItem->center)
-						x += (rItem.width()-Core->getTheme()->itemLeftMargin-Core->getTheme()->itemRightMargin-dItem->lines[i].width)/2;
+					if (workItem->center)
+						x += (workRect.width()-Core->getTheme()->itemLeftMargin-Core->getTheme()->itemRightMargin-workItem->lines[i].width)/2;
 
-					if (dItem->lines[i].newLine)
-						{lx = 0; ly += dItem->lines[i].height;}
+					if (workItem->lines[i].newLine)
+						{lx = 0; ly += workItem->lines[i].height;}
 					else
-						lx += dItem->lines[i].width;
+						lx += workItem->lines[i].width;
 
-					if (dItem->lines[i].count == 0) continue;
+					if (workItem->lines[i].count == 0) continue;
 					
-					if (y + Core->getTheme()->styles[dItem->style].size >= rItem.bottom())
+					if (y + Core->getTheme()->styles[workItem->style].size >= workRect.bottom())
 						break;
 
-					if (y < rect->top() - Core->getTheme()->styles[dItem->style].size)
+					if (y < rect->top() - Core->getTheme()->styles[workItem->style].size)
 						continue;
 
-					SelectObject (hdc, Core->getTheme()->styles[dItem->lines[i].style].font);
-					ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, i == 0 ? dItem->text.c_str() : dItem->text.c_str() + dItem->lines[i].pos, dItem->lines[i].count, 0);
+					SelectObject (hdc, Core->getTheme()->styles[workItem->lines[i].style].font);
+					ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, i == 0 ? workItem->text.c_str() : workItem->text.c_str() + workItem->lines[i].pos, workItem->lines[i].count, 0);
 				}
 			}
 			else
 			{
-				if (dItem->subtext.size() > 0)
+				if (workItem->subtext.size() > 0)
 				{
 					SelectObject(hdc, Core->getTheme()->styles[sbTheme::STYLE::BUTTON].font);
 					SetTextColor(hdc, Core->getTheme()->ItemSubTextColor);
 
 					SIZE sz;
-					GetTextExtentPoint32(hdc, dItem->subtext.c_str(), dItem->subtext.size(), &sz);
+					GetTextExtentPoint32(hdc, workItem->subtext.c_str(), workItem->subtext.size(), &sz);
 
-					ExtTextOut(hdc, rItem.left()+((rItem.width()-sz.cx)/2), rItem.top()+((rItem.height()-sz.cy)/2), ETO_OPAQUE, NULL, dItem->subtext.c_str(), dItem->subtext.size(), 0);
+					ExtTextOut(hdc, workRect.left()+((workRect.width()-sz.cx)/2), workRect.top()+((workRect.height()-sz.cy)/2), ETO_OPAQUE, NULL, workItem->subtext.c_str(), workItem->subtext.size(), 0);
 				}
-				else if (dItem->type != sbItem::TYPE_SPACE)
+				else if (workItem->type != sbItem::TYPE_SPACE)
 					sbAssert(true);
 			}
 
 			if (Core->getTheme()->ListSeparatorHeight > 0)
 			{
-				rItem.top (rItem.bottom());
-				rItem.bottom (rItem.top() + Core->getTheme()->ListSeparatorHeight);
-				Core->getTheme()->drawElement(hdc, &rItem, sbTheme::ELEMENT::SEPARATOR);
+				workRect.top (workRect.bottom());
+				workRect.bottom (workRect.top() + Core->getTheme()->ListSeparatorHeight);
+				Core->getTheme()->drawElement(hdc, &workRect, sbTheme::ELEMENT::SEPARATOR);
 			}
 
 			// TODO vertical separator
 
-			dItem = dItem->right;
+			workItem = workItem->right;
 		}
 
-		dItem = oldItem;
+		workItem = oldItem;
 
 		if (Core->getTheme()->ListSeparatorHeight > 0)
 			screenHeight += Core->getTheme()->ListSeparatorHeight;
 
-		screenHeight += dItem->height;
+		screenHeight += workItem->height;
 
-		dItem = dItem->next;
+		workItem = workItem->next;
 	}
 
 	//if (true)
@@ -605,11 +590,11 @@
 	//	static char frame = 0;
 	//	static int time = GetTickCount();
 
-	//	/*rItem.top = 16+(frame*32);
-	//	rItem.bottom = 48+(frame*32);
-	//	rItem.left = 0;
-	//	rItem.right = 32;
-	//	FillRect(hdc, &rItem, Core->getTheme()->ListBackgroundBrush);
+	//	/*workRect.top = 16+(frame*32);
+	//	workRect.bottom = 48+(frame*32);
+	//	workRect.left = 0;
+	//	workRect.right = 32;
+	//	FillRect(hdc, &workRect, Core->getTheme()->ListBackgroundBrush);
 
 	//	if (++frame > 6) frame = 0;*/
 
@@ -630,13 +615,13 @@
 	//	SelectObject (hdc, Core->getTheme()->styles[sbTheme::STYLE::CAPTION].font);
 	//	GetTextExtentPoint32(hdc,place,_tcsclen(place),&sz);
 	//	
-	//	rItem.bottom = rect->bottom/2+(sz.cy/2);
-	//	rItem.top = rect->bottom/2-(sz.cy/2);
-	//	rItem.right = rect->right/2+(sz.cx/2);
-	//	rItem.left = rect->right/2-(sz.cx/2);
+	//	workRect.bottom = rect->bottom/2+(sz.cy/2);
+	//	workRect.top = rect->bottom/2-(sz.cy/2);
+	//	workRect.right = rect->right/2+(sz.cx/2);
+	//	workRect.left = rect->right/2-(sz.cx/2);
 
-	//	//FillRect(hdc, &rItem, CreateSolidBrush(Core->getTheme()->SeparatorColor));
-	//	ExtTextOut(hdc, rItem.left, rItem.top, ETO_OPAQUE, NULL, place, _tcsclen(place), 0);
+	//	//FillRect(hdc, &workRect, CreateSolidBrush(Core->getTheme()->SeparatorColor));
+	//	ExtTextOut(hdc, workRect.left, workRect.top, ETO_OPAQUE, NULL, place, _tcsclen(place), 0);
 	//}
 
 	if (displaceHeight >= 0)
@@ -737,7 +722,7 @@
 /*   sbList::onPressed
  *   input
  */
-void sbList::onPressed (int x, int y)
+void sbList::onPressed ( int x, int y )
 {
 	if (Core->getInput()->block) return;
 
@@ -796,28 +781,13 @@
 			sbAssert(parent == NULL);
 			sbAssert(parent->type != sbList::TYPE_MODULE_VIEW);
 
-			parent->key.Index(item->index);
-			parent->setKey(parent->key);
+			sword::VerseKey workKey ( Core->defaultModule->getKey() );
 
-			Core->switchList(sbList::TYPE_MODULE_VIEW);
-		}
-		break;
+			workKey.Index( item->index );
 
-	case sbItem::TYPE_BUTTON_CHAPTER_NEXT:
-		{
-			sword::VerseKey key(module->getKey());
-			key.setChapter(key.getChapter()+1);
-			key.setVerse(1);
-			setKey(key);
-		}
-		break;
+			parent->setKey( workKey );
 
-	case sbItem::TYPE_BUTTON_CHAPTER_PREV:
-		{
-			sword::VerseKey key(module->getKey());
-			key.setChapter(key.getChapter()-1);
-			key.setVerse(1);
-			setKey(key);
+			Core->switchList(sbList::TYPE_MODULE_VIEW);
 		}
 		break;
 
@@ -839,16 +809,16 @@
 				{
 					// add chapters
 					sbItem *tmpItem = item;
-					sword::VerseKey key;
-					key.Index(item->index);
+					sword::VerseKey workKey ( module->getKey() );
+					workKey.Index( item->index );
 
-					for (int i=0;i<key.getChapterMax();i++)
+					for (int i=0; i < workKey.getChapterMax(); i++)
 					{
-						key.setChapter(i+1);
+						workKey.setChapter( i + 1 );
 						TCHAR text[8];
-						_itot(key.getChapter(), text, 10);
+						_itot(workKey.getChapter(), text, 10);
 						
-						sbItem *item = new sbItem (sbItem::TYPE_BUTTON_SELECTION_CHAPTER, text, rect->width()/3, key.Index());
+						sbItem *item = new sbItem (sbItem::TYPE_BUTTON_SELECTION_CHAPTER, text, rect->width()/3, workKey.Index());
 
 						item->center = true;
 
@@ -856,8 +826,7 @@
 							(tmpItem->right == NULL || tmpItem->right->right == NULL))
 						{
 							sbItem *last = tmpItem;
-							while(last->right != NULL)
-								last = last->right;
+							while(last->right != NULL) last = last->right;
 							last->attach(item, sbItem::RIGHT);
 						}
 						else
@@ -881,34 +850,48 @@
 		break;
 	case sbItem::TYPE_BUTTON_SELECTION_CHAPTER:
 		{
-			sbAssert(parent == NULL);
+			sbAssert(module == NULL);
 
-			key.Index(item->index);
+			sword::VerseKey workKey ( module->getKey() );
 
-			addControl((sbControl::TYPE)(sbControl::TYPE_MENU_SET_VERSE+key.getVerseMax()));
+			workKey.Index ( item->index );
+
+			module->setKey ( workKey );  // necessary for menu correct work
+
+			addControl((sbControl::TYPE)(sbControl::TYPE_MENU_SET_VERSE+workKey.getVerseMax()));
 		}
 		break;
 
 	case sbItem::TYPE_BUTTON_SELECTION_MODULE:
 		{
-			sword::SWModule *m = (sword::SWModule*)item->index;
+			sword::SWModule *newModule = (sword::SWModule*) item->index;
 
-			sbAssert(m == NULL);
+			sbAssert ( newModule == NULL );
 			
-			if (parent == NULL)
+			sbAssert ( parent == NULL );
+			
+			if (parent->module != newModule)
 			{
-				module = m;
-				setKey(getKey());
-			}
-			else
-			{
 				if (parent->module == NULL)
-					m->SetKey("John 1:1");
+					newModule->setKey ( "John 1:1" );
 				else
-					m->SetKey(parent->getKey());
-	
-				parent->module = m;
-				parent->setKey(parent->getKey());
+					newModule->setKey ( parent->module->getKey() );
+
+				parent->module = newModule;
+				parent->setKey ( parent->module->getKey() );
+
+
+				// highlighting
+				sbItem * workItem = item;
+				while ( workItem->prev != NULL ) workItem = workItem->prev;
+				while ( workItem->next != NULL )
+				{
+					workItem->highlighted = false;
+					workItem = workItem->next;
+				}
+				item->highlighted = true;
+
+				Core->redraw();
 			}
 		}
 		break;
@@ -942,143 +925,6 @@
 	return &key;
 }
 
-/*   sbList::addBlankVerses
- *   add verses templates, for futher processing in thread
- */
-void sbList::addBlankVerses()
-{
-	if (type == sbList::TYPE_MODULE_VIEW && module != NULL)
-	{
-		sword::VerseKey tmpKey = key;
-		int added = 0;
-
-		if (itemCurrent == NULL)
-		{
-			itemCurrent = new sbItem (sbItem::TYPE_VERSE, NULL, rect->width(), tmpKey.Index(), tmpKey.getVerse());
-			
-			verseFirst = itemCurrent;
-			verseLast = itemCurrent;
-
-			if (tmpKey.getVerse() == 1)
-			{
-				TCHAR headerText [16];
-			
-				const char* book = tmpKey.getBookName();
-				int s = strlen(book);
-				mbstowcs(headerText,book,s);
-
-				char chap[8];
-				_itoa(tmpKey.getChapter(),chap,10);
-
-				headerText[s++] = s > 9 ? L'\n' : L' ';
-
-				for(int i=0;i<strlen(chap)+1;i++)
-					headerText[s++] = chap[i];
-
-				itemCurrent->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), tmpKey.Index()), sbItem::PREV);
-			}
-
-			added++;
-			needFill = true;
-		}
-
-		while (true)
-		{
-			bool atEnd;
-
-			if (versesForward+versesBackward > Core->versesMax)
-			{
-				Sleep(25);
-				break; // need for memory reason
-			}
-
-			if (versesForward+versesBackward > Core->versesOptimal*2)
-				Sleep(5);
-			
-			if (versesForward < 15 && !listEndConstructed)
-				atEnd = true;
-			else if (versesBackward < 5 && !listStartConstructed)
-				atEnd = false;
-			else if (added > 4)
-				break;
-			else
-			{
-				if (versesForward+versesBackward > Core->versesOptimal/2) break;
-			
-				atEnd = added%2==0;
-				if ((listEndConstructed && atEnd) || (listStartConstructed && !atEnd))
-				{
-					added++;
-					continue;
-				}
-			}
-
-			sbItem* item = atEnd ? verseLast : verseFirst;
-			int index = 0;
-
-			while (true)
-			{
-				if (item->type == sbItem::TYPE_VERSE) index = item->index;
-				if (atEnd ? item->next == NULL : item->prev == NULL) break;
-
-				item = atEnd ? item->next : item->prev;
-			}
-
-			tmpKey.Index(index);
-			atEnd ? tmpKey.increment() : tmpKey.decrement();
-			
-			if (tmpKey.Index() != index)
-			{
-				item->attach(new sbItem (sbItem::TYPE_VERSE, NULL, rect->width(), tmpKey.Index(), tmpKey.getVerse()), atEnd ? sbItem::NEXT : sbItem::PREV);
-
-				if (atEnd)
-				{
-					verseLast = item->next;
-					versesForward++;
-				}
-				else
-				{
-					verseFirst = item->prev;
-					versesBackward++;
-				}
-
-				if (tmpKey.getVerse() == 1)
-				{
-					TCHAR headerText [16];
-				
-					const char* book = tmpKey.getBookName();
-					int s = strlen(book);
-					mbstowcs(headerText,book,s);
-
-					char chap[8];
-					_itoa(tmpKey.getChapter(),chap,10);
-
-					headerText[s++] = s > 9 ? L'\n' : L' ';
-
-					for(int i=0;i<strlen(chap)+1;i++)
-						headerText[s++] = chap[i];
-
-					if (atEnd)
-					{
-						verseLast->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), tmpKey.Index()), sbItem::PREV);
-						verseLast->prev->center = true;
-					}
-					else
-					{
-						verseFirst->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), tmpKey.Index()), sbItem::PREV);
-						verseFirst->prev->center = true;
-					}
-				}
-				added++;
-			}
-			else
-			{
-				atEnd ? listEndConstructed = true : listStartConstructed = true;
-			}
-		}
-	}
-}
-
 /*   sbList::updateVerses
  *   fill verses with text from module
  *   also delete unnecessary items
@@ -1142,23 +988,22 @@
 			// process item text
 			if (item->type == sbItem::TYPE_VERSE && item->text.size() == 0)
 			{
-				static sword::VerseKey workKey;
+				sword::VerseKey workKey ( key );
 
-				workKey = key;
 				workKey.Index(item->index);
 
 				module->SetKey(workKey);
-				TCHAR *text = (TCHAR*)module->RenderText();
 
-				int len = _tcslen(text);
+				// TODO some times this cause crush, should i make it in try statement?
+				TCHAR * text = (TCHAR*) module->RenderText();
 
-				TCHAR *add = new TCHAR[len+1];
-				for (int i=0; i<=len; i++)
-					add[i] = text[i];
+				int len = _tcslen ( text );
+				TCHAR * add = new TCHAR [ len + 1 ];
+				for (int i=0; i <= len; i++) add[i] = text[i];
 
 				int oldHeight = item->height;
 
-				item->setText(add);
+				item->setText ( add );
 
 				item->expanding = item->height;
 				item->height    = oldHeight;
@@ -1181,26 +1026,27 @@
 			else
 				return;
 
-			atEnd = !atEnd;
+			atEnd = ! atEnd;
 		}
 	}
 }
 
-/*   sbList::controlPressed
+/*
+ *   sbList::controlPressed
  *   process action for pressed control
  */
-bool sbList::onControl (sbControl::TYPE type)
+bool sbList::onControl ( sbControl::TYPE type )
 {
-	switch (type)
+	switch ( type )
 	{
 	case sbControl::TYPE_MENU_VERSE_ADD_STATIC_BOOKMARK:
-		(Core->getBookmarks()->add(key)).dynamic = false;
-		removeControl(sbControl::TYPE_MENU_CURRENT);
+		(Core->getBookmarks()->add( key )).dynamic = false;
+		removeControl ( sbControl::TYPE_MENU_CURRENT );
 		break;
 
 	case sbControl::TYPE_MENU_VERSE_ADD_DYNAMIC_BOOKMARK:
-		(Core->getBookmarks()->add(key)).dynamic = true;
-		removeControl(sbControl::TYPE_MENU_CURRENT);
+		(Core->getBookmarks()->add( key )).dynamic = true;
+		removeControl( sbControl::TYPE_MENU_CURRENT );
 		break;
 
 	case sbControl::TYPE_MENU_VERSE_START_EDITING:
@@ -1213,32 +1059,35 @@
 				else
 					item = item->next;
 
-			sbAssert(item == NULL);
-			setEditMode(item);
-			removeControl(sbControl::TYPE_MENU_CURRENT);
+			sbAssert ( item == NULL );
+			setEditMode ( item );
+			removeControl ( sbControl::TYPE_MENU_CURRENT );
 		}
 		break;
 
 	case sbControl::TYPE_MENU_EXIT_NO:
 	case sbControl::TYPE_MENU_CANCEL:
-
-		removeControl(sbControl::TYPE_MENU_CURRENT);
+		removeControl ( sbControl::TYPE_MENU_CURRENT );
 		break;
 
 	case sbControl::TYPE_BUTTON_CLOSE:
-		addControl(sbControl::TYPE_MENU_EXIT);
+		addControl ( sbControl::TYPE_MENU_EXIT );
 		break;
 
 	default:
 		if (type >= sbControl::TYPE_SET_VERSE && type < sbControl::TYPE_SET_VERSE_MAX)
 		{
-			sbAssert(this->type != sbList::TYPE_SELECT_BOOK);
+			sbAssert ( this->type != sbList::TYPE_SELECT_BOOK );
+			sbAssert ( module == NULL );
+
+			sword::VerseKey workKey ( module->getKey() );
 			
-			key.setVerse(type-sbControl::TYPE_SET_VERSE);
-			parent->setKey(key);
-			Core->switchList(sbList::PIN_PARENT);
+			workKey.setVerse ( type-sbControl::TYPE_SET_VERSE );
+			parent->setKey ( workKey );
 
-			removeControl(sbControl::TYPE_MENU_CURRENT);
+			Core->switchList ( sbList::PIN_PARENT );
+
+			removeControl ( sbControl::TYPE_MENU_CURRENT );
 		}
 		else
 			return false;
@@ -1248,11 +1097,11 @@
 
 void sbList::addControl ( sbControl::TYPE type )
 {
-	for (int i=0; i<controls.size(); i++) if (controls[i]->type == type) return;
+	for (int i=0; i < controls.size(); i++) if (controls[i]->type == type) return;
 
-	controls.push_back (new sbControl (type));
+	controls.push_back ( new sbControl ( type ) );
 
-	if (controls.back()->isMenu())
+	if ( controls.back()->isMenu() )
 	{
 		sbAssert(Core->getSurface(sbCore::SURFACE::TYPE_WHOLE)->fade || Core->getInput()->block);
 
@@ -1292,7 +1141,7 @@
 			{
 				const int halfscreen = rect->height()/2;
 
-				for ( int dir=0; dir<2; dir++ )
+				for ( int dir=0; dir < 2; dir++ )
 				{
 					sbItem* item = itemCurrent;
 					int displace = displaceHeight;
@@ -1344,6 +1193,163 @@
 			}
 		}
 		break;
+
+	case sbCore::TIMER_BEFORE_REDRAW:
+		{
+			// add blank verses
+			if ( type == sbList::TYPE_MODULE_VIEW && module != NULL )
+			{
+				sword::VerseKey workKey ( key );
+				int added = 0;
+
+				if (itemCurrent == NULL)
+				{
+					itemCurrent = new sbItem (sbItem::TYPE_VERSE, NULL, rect->width(), workKey.Index(), workKey.getVerse());
+
+					verseFirst = itemCurrent;
+					verseLast = itemCurrent;
+
+					if (workKey.getVerse() == 1)
+					{
+						TCHAR headerText [16];
+
+						const char* book = workKey.getBookName();
+						int s = strlen ( book );
+						mbstowcs ( headerText , book  ,s );
+
+						char chap [ 8 ];
+						_itoa ( workKey.getChapter() , chap , 10 );
+
+						headerText[s++] = s > 9 ? L'\n' : L' ';
+
+						for(int i=0;i<strlen(chap)+1;i++)
+							headerText[s++] = chap[i];
+
+						itemCurrent->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), workKey.Index()), sbItem::PREV);
+					}
+
+					added++;
+					needFill = true;
+				}
+
+				while (true)
+				{
+					bool atEnd;
+
+					if (versesForward+versesBackward > Core->versesMax)
+					{ Sleep(25); break; } // need for memory reason
+
+					if (versesForward+versesBackward > Core->versesOptimal*2) Sleep(5);
+
+					if (versesForward < 15 && !listEndConstructed)        atEnd = true;
+					else if (versesBackward < 5 && !listStartConstructed) atEnd = false;
+					else if (added > 4) break;
+					else
+					{
+						if (versesForward+versesBackward > Core->versesOptimal/2) break;
+
+						atEnd = added%2==0;
+						if ((listEndConstructed && atEnd) || (listStartConstructed && !atEnd))
+						{
+							added++;
+							continue;
+						}
+					}
+
+					sbItem* item = atEnd ? verseLast : verseFirst;
+					int index = 0;
+
+					while (true)
+					{
+						if (item->type == sbItem::TYPE_VERSE) index = item->index;
+						if (atEnd ? item->next == NULL : item->prev == NULL) break;
+
+						item = atEnd ? item->next : item->prev;
+					}
+
+					workKey.Index(index);
+					atEnd ? workKey.increment() : workKey.decrement();
+
+					if (workKey.Index() != index)
+					{
+						item->attach(new sbItem (sbItem::TYPE_VERSE, NULL, rect->width(), workKey.Index(), workKey.getVerse()), atEnd ? sbItem::NEXT : sbItem::PREV);
+
+						if (atEnd)
+						{
+							verseLast = item->next;
+							versesForward++;
+						}
+						else
+						{
+							verseFirst = item->prev;
+							versesBackward++;
+						}
+
+						if (workKey.getVerse() == 1)
+						{
+							TCHAR headerText [16];
+
+							const char* book = workKey.getBookName();
+							int s = strlen(book);
+							mbstowcs(headerText,book,s);
+
+							char chap[8];
+							_itoa(workKey.getChapter(),chap,10);
+
+							headerText[s++] = s > 9 ? L'\n' : L' ';
+
+							for(int i=0;i<strlen(chap)+1;i++)
+								headerText[s++] = chap[i];
+
+							if (atEnd)
+							{
+								verseLast->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), workKey.Index()), sbItem::PREV);
+								verseLast->prev->center = true;
+							}
+							else
+							{
+								verseFirst->attach(new sbItem (sbItem::TYPE_HEADER, headerText, rect->width(), workKey.Index()), sbItem::PREV);
+								verseFirst->prev->center = true;
+							}
+						}
+						added++;
+					}
+					else
+					{
+						atEnd ? listEndConstructed = true : listStartConstructed = true;
+					}
+				}
+			}
+
+			// itemCurrent may be not first on screen, so do correction
+			if ( itemCurrent != NULL )
+			{
+				while (displaceHeight > -Core->getTheme()->ListSeparatorHeight && itemCurrent->prev != NULL)
+				{
+					if (itemCurrent->type == sbItem::TYPE_VERSE)
+					{
+						versesBackward--;
+						versesForward++;
+					}
+
+					itemCurrent = itemCurrent->prev;
+					displaceHeight -= itemCurrent->height + Core->getTheme()->ListSeparatorHeight;
+				}
+
+				while (displaceHeight < 0 && abs(displaceHeight) > itemCurrent->height + Core->getTheme()->ListSeparatorHeight)
+				{
+					if (itemCurrent->next == NULL) break;
+
+					displaceHeight += itemCurrent->height + Core->getTheme()->ListSeparatorHeight;
+
+					if (itemCurrent->type == sbItem::TYPE_VERSE)
+					{ versesBackward++; versesForward--; }
+
+					itemCurrent = itemCurrent->next;
+				}
+			}
+		}
+		break;
 	}
 }
 
@@ -1353,6 +1359,11 @@
 void sbList::onActivate()
 {
 	Core->setSipState(itemEdit != NULL);
+
+	if (module != NULL)
+	{
+		Core->currentModule = module;
+	}
 }
 
 /*  sbList::setEditMode

Modified: trunk/src/SlideBible/sbList.h
===================================================================
--- trunk/src/SlideBible/sbList.h	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbList.h	2009-10-31 21:48:40 UTC (rev 217)
@@ -51,26 +51,24 @@
 	
 	sbList(sbList::TYPE type);
 	~sbList();
+ 
+	// event handlers
+	void                      onPressed      ( int x, int y );
+	void                      onReleased     ( int x, int y );
+	void                      onClicked      ( int x, int y );
+	void                      onTapped       ( int x, int y );
 
-	void                      attach   (sbList * list, sbList::TYPE pin);
-
-	bool                      scroll   (float amount);
-
-	// input methods
-	void                      onPressed  (int x, int y);
-	void                      onReleased (int x, int y);
-	void                      onClicked  (int x, int y);
-	void                      onTapped   (int x, int y);
-
-	bool                      onChar     (TCHAR character);
+	bool                      onChar         ( TCHAR character );
 	
-	void                      render (HDC hdc);
-	void                      renderControls (HDC hdc);
+	void                      onTimer        ( const int timer );
+	void                      onActivate     ( );
+	bool                      onControl      ( sbControl::TYPE type );
 
-	void                      onTimer (const int timer);
-	void                      onActivate (void);
+	// methods
+	void                      attach         ( sbList * list, sbList::TYPE pin );
+	bool                      scroll         ( float amount );
+	void                      render         ( HDC hdc );
 
-
 	int                       displaceHeight;
 	float                     displacePart;
 	int                       screenHeight;
@@ -80,23 +78,20 @@
 	
 	const TYPE                type;
 
-	sbList*                   getNext () const {return next;}
-	sbList*                   getPrev () const {return prev;}
-	sbList*                   getParent () const {return parent;}
+	sbList*                   getNext       ( ) const {return next;}
+	sbList*                   getPrev       ( ) const {return prev;}
+	sbList*                   getParent     ( ) const {return parent;}
 
-	bool                      hasModule () const {return module != NULL;}
-	sword::VerseKey*          getKey ();
-	void                      updateVerses (bool *abort);
+	bool                      hasModule     ( ) const {return module != NULL;}
+	sword::VerseKey*          getKey        ( );
+	void                      updateVerses  ( bool *abort );
 
-	bool                      onControl (sbControl::TYPE type);
-
 	const std::vector<sbControl*>* getControls () const { return &controls; }
 	
 private:
-	void                      addBlankVerses();
-	void                      setKey(sword::VerseKey verse);
-	void                      clear ();
-	sbItem*                   getItem (int x, int y) const;
+	void                      setKey  ( sword::VerseKey verse ); // to cut
+	void                      clear   ( );
+	sbItem*                   getItem ( int x, int y ) const;
 
 	sbItem                   *itemCurrent;
 	sbItem                   *itemHover;
@@ -125,10 +120,13 @@
 
 	std::vector<sbControl*>   controls;
 
+	const sbRect             *rect;
+
+	// Module View related
 	sword::SWModule          *module;
-	sword::VerseKey           key;
+	sword::VerseKey           key; // to cut
 
-	const sbRect             *rect;
+	// Navigation related
 };
 
 #endif
\ No newline at end of file

Modified: trunk/src/SlideBible/sbTheme.cpp
===================================================================
--- trunk/src/SlideBible/sbTheme.cpp	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/sbTheme.cpp	2009-10-31 21:48:40 UTC (rev 217)
@@ -250,6 +250,11 @@
 			DeleteObject(elements[i].bitmap);
 }
 
+/*
+ *  sbTheme::drawElement
+ *  outside methods should only place element types on the screen
+ *  in future real paint will be in something like flushScreen()
+ */
 void sbTheme::drawElement (HDC hdc, const sbRect* rect, sbTheme::ELEMENT::TYPE type, const int animFrame) const
 {
 	bool vertical = true;

Modified: trunk/src/SlideBible/todo.txt
===================================================================
--- trunk/src/SlideBible/todo.txt	2009-10-25 18:21:36 UTC (rev 216)
+++ trunk/src/SlideBible/todo.txt	2009-10-31 21:48:40 UTC (rev 217)
@@ -1,20 +1,35 @@
 alpha
 +	make button-items min height of finger size
++	fix findwindow on start
++	show sword version somewhere
++	change versification system in navigation view
++	when mods.d not found - show tip message
++	sometimes happens something wrong with height of empty verse and verse text line height
 
 	draw module view description on sbList activate
 
 *	navigation list from last place
 
-	search field, titles
-		cursor
+	search
+		clucence
+		input text items
++			sip control
+			cursor
+?			copy/paste
 		
 	bookmarks, history, ratings, verselists
 		dialog: verse actions(favorite|send to list...|send to new list)
 		dialog: select verse(s)
 		dialog: menu verse
+		
+?		verse features:
+			readings count (forgotten places/chapters)
+			bookmarks static/dynamic
+			attendance history: date, module, key
+			verse lists (remember for...)
 
 *	static / dynamic bookmarks
-		on screen item
+		on screen marks
 
 	text fade
 	2. Ïàðàëèïîìå\níîí\n4
@@ -29,23 +44,16 @@
 	loading all locale takes too long
 	screen rotation
 	slide list and stroke down/up - link list
-	search
-?	data abort on emulator
-?	create base class for sbItem and sbControl for holding screen text
+?	data abort in gwes.exe on emulator
+?	base class for sbItem and sbControl for holding screen text
 ?	make lists pins (next/prev/left/right) links constant. so instances of same type should not change their values direct
 ?	moving to sdl
-	
-	verse features:
-		readings count (forgotten places/chapters)
-		bookmarks static/dynamic
-		attendance history: date, module, key
-		verse lists (remember for...)
 
 beta	
 	toTest
 		other locales, utf encoding
 		russian paths
-		different screens and orientation change
+		different screens and runtime orientation change
 
 release
 	sliding backgrounds




More information about the sword-cvs mailing list