|
From: CVS C. to T. <the...@li...> - 2011-06-02 18:11:18
|
Revision: 650
http://themis.svn.sourceforge.net/themis/?rev=650&view=rev
Author: mark_hellegers
Date: 2011-06-02 18:11:12 +0000 (Thu, 02 Jun 2011)
Log Message:
-----------
- Changed the code style to be more compact
- Moved the retrieving of the filtered url list to the GlobalHistory and removed the stripped list function.
- vscroll variable is now private and a function HasScrollBar is added that can be called to check if there is a scrollbar in the popup window.
- Removed several memory leaks although there is at least one left. Can't find it yet, though.
Modified Paths:
--------------
trunk/themis/framework/GlobalHistory.cpp
trunk/themis/framework/GlobalHistory.h
trunk/themis/framework/ThemisUrlPopUpWindow.cpp
trunk/themis/framework/ThemisUrlPopUpWindow.h
trunk/themis/framework/win.cpp
trunk/themis/framework/win.h
Modified: trunk/themis/framework/GlobalHistory.cpp
===================================================================
--- trunk/themis/framework/GlobalHistory.cpp 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/GlobalHistory.cpp 2011-06-02 18:11:12 UTC (rev 650)
@@ -31,33 +31,33 @@
#include <stdio.h>
#include <time.h>
+// BeOS headers
+#include <String.h>
+
// Themis headers
#include "../common/PrefsDefs.h"
#include "GlobalHistory.h"
-GlobalHistory::GlobalHistory(
- int8 depth,
- int8 count )
-{
+GlobalHistory :: GlobalHistory(int8 depth, int8 count) {
+
fHistoryDepthInDays = depth;
fFreeUrlCount = 0;
- fList = new BList( 0 );
+ fList = new BList(0);
+
}
-GlobalHistory::~GlobalHistory()
-{
- printf( "GlobalHistory::~GlobalHistory()\n" );
- printf( " Putting GlobalHistoryData in AppSettings\n" );
+GlobalHistory :: ~GlobalHistory() {
+
+ printf("GlobalHistory::~GlobalHistory()\n");
+ printf(" Putting GlobalHistoryData in AppSettings\n");
BMessage collector;
int32 count = fList->CountItems();
- for( int32 i = 0; i < count; i++ )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( ( int32 )0 );
- if( item != NULL )
- {
+ for (int32 i = 0; i < count; i++) {
+ GlobalHistoryItem * item = (GlobalHistoryItem *)fList->ItemAt((int32) 0);
+ if (item != NULL) {
/*
* Pack up the item data in a BMessage, which will then be stored in the
* collector message.
@@ -67,46 +67,43 @@
// item->Print();
BMessage collitem;
- collitem.AddString( "url", item->Text() );
- collitem.AddInt32( "time", item->Time() );
+ collitem.AddString("url", item->Text());
+ collitem.AddInt32("time", item->Time());
- collector.AddMessage( kPrefsGlobalHistoryItemMessage, &collitem );
+ collector.AddMessage(kPrefsGlobalHistoryItemMessage, &collitem);
}
- fList->RemoveItem( ( int32 )0 );
+ fList->RemoveItem((int32) 0);
delete item;
}
delete fList;
// collector->PrintToStream();
- if( AppSettings->HasMessage( kPrefsGlobalHistoryData ) )
+ if (AppSettings->HasMessage(kPrefsGlobalHistoryData))
AppSettings->ReplaceMessage(
kPrefsGlobalHistoryData,
- &collector );
+ &collector);
else
AppSettings->AddMessage(
kPrefsGlobalHistoryData,
- &collector );
+ &collector);
// AppSettings->PrintToStream();
- printf( "GlobalHistory destructor end.\n" );
+ printf("GlobalHistory destructor end.\n");
}
-void
-GlobalHistory::AddEntry(
- const char* entry )
-{
+void GlobalHistory :: AddEntry(const char* entry) {
+
// printf( "GlobalHistoryItem::AddEntry()\n" );
// printf( " New entry: %s\n", entry );
- GlobalHistoryItem* newitem = new GlobalHistoryItem( entry, time( NULL ) );
+ GlobalHistoryItem * newitem = new GlobalHistoryItem(entry, time(NULL));
/* We don't want to add an item twice for a day.
* ( This has nothing to do about similar entries on different days. )
*/
- if( CheckDoubleDay( newitem ) == false )
- {
+ if (CheckDoubleDay(newitem) == false) {
/*
* Check wether newitem is really younger then the first item in the
* history. If not, cycle through the list to find a suitable place
@@ -117,20 +114,15 @@
int32 count = fList->CountItems();
- if( count == 0 )
- {
- fList->AddItem( newitem, 0 );
+ if (count == 0) {
+ fList->AddItem(newitem, 0);
}
- else
- {
- for( int32 i = 0; i < count; i++ )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( i );
- if( item != NULL )
- {
- if( item->Time() < newitem->Time() )
- {
- fList->AddItem( newitem, i );
+ else {
+ for (int32 i = 0; i < count; i++) {
+ GlobalHistoryItem * item = (GlobalHistoryItem *)fList->ItemAt(i);
+ if (item != NULL) {
+ if (item->Time() < newitem->Time()) {
+ fList->AddItem(newitem, i);
break;
}
}
@@ -145,55 +137,44 @@
// PrintHistory();
}
-bool
-GlobalHistory::CheckDoubleDay(
- GlobalHistoryItem* checkitem )
-{
+bool GlobalHistory :: CheckDoubleDay(GlobalHistoryItem * checkitem) {
+
// printf( "GlobalHistory::CheckDoubleDay()\n" );
const time_t checkitem_time_t = checkitem->Time();
struct tm checkitem_tm;
- if( localtime_r( &checkitem_time_t, &checkitem_tm ) == NULL )
- {
+ if (localtime_r(&checkitem_time_t, &checkitem_tm) == NULL) {
// printf( " checkitem_tm == NULL. aborting.\n" );
return true;
}
int32 count = fList->CountItems();
- for( int32 i = 0; i < count; i++ )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( i );
- if( item != NULL )
- {
+ for (int32 i = 0; i < count; i++) {
+ GlobalHistoryItem* item = (GlobalHistoryItem *)fList->ItemAt(i);
+ if (item != NULL) {
const time_t item_time_t = item->Time();
struct tm item_tm;
- if( localtime_r( &item_time_t, &item_tm ) != NULL )
- {
+ if (localtime_r(&item_time_t, &item_tm) != NULL) {
/* note: If we find an item from the day or year before, we can stop the check.
* ( List is kept chronologically. Newest first. )
*/
- if( item_tm.tm_year == checkitem_tm.tm_year )
- {
- if( item_tm.tm_yday == checkitem_tm.tm_yday )
- {
- if( strcmp( item->Text(), checkitem->Text() ) == 0 )
- {
+ if (item_tm.tm_year == checkitem_tm.tm_year) {
+ if (item_tm.tm_yday == checkitem_tm.tm_yday) {
+ if (strcmp(item->Text(), checkitem->Text()) == 0) {
// printf( " URL already stored today. skipping.\n" );
return true;
}
}
- else
- {
+ else {
// printf( " Found older (or newer) item [day]. break.\n" );
break;
}
}
- else
- {
+ else {
// printf( " Found older (or newer) item [year]. break.\n" );
break;
}
@@ -206,16 +187,15 @@
return false;
}
-void
-GlobalHistory::CheckEntryExpiration()
-{
+void GlobalHistory :: CheckEntryExpiration() {
+
// printf( "GlobalHistory::CheckEntryExpiration()\n" );
int32 count = fList->CountItems();
int8 freecount = 0;
- const time_t now = time( NULL );
+ const time_t now = time(NULL);
struct tm today_tm;
- localtime_r( &now, &today_tm );
+ localtime_r(&now, &today_tm);
// printf( " GlobalHistoryDepthInDays: %d\n", fHistoryDepthInDays );
// printf( " today_tm.tm_yday: %d\n", today_tm.tm_yday );
@@ -225,38 +205,33 @@
* ( Oldest item is stored at the end of the list. )
*/
- for( int32 i = count - 1; i >= 0; i-- )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( i );
+ for (int32 i = count - 1; i >= 0; i--) {
+ GlobalHistoryItem* item = (GlobalHistoryItem *)fList->ItemAt(i);
const time_t itemtime_t = item->Time();
struct tm item_tm;
- localtime_r( &itemtime_t, &item_tm );
+ localtime_r(&itemtime_t, &item_tm);
int16 limit = 0;
- if( item_tm.tm_yday >= fHistoryDepthInDays - 1 )
- {
+ if (item_tm.tm_yday >= fHistoryDepthInDays - 1) {
// printf( " Item within this year.\n" );
- limit = ( int16 )( today_tm.tm_yday - fHistoryDepthInDays );
+ limit = (int16)(today_tm.tm_yday - fHistoryDepthInDays);
}
- else
- {
+ else {
// printf( " Item from last year.\n" );
- limit = ( int16 )( 365 - ( fHistoryDepthInDays - ( item_tm.tm_yday + 1 ) ) );
+ limit = (int16)(365 - (fHistoryDepthInDays - (item_tm.tm_yday + 1)));
}
// printf( " limit: %d ( Entries <= this one are expired. )\n", limit );
- if( item_tm.tm_yday <= limit )
- {
+ if (item_tm.tm_yday <= limit) {
// printf( " The following item is expired. (Will be marked as free url.):\n" );
item->Print();
item->SetFree();
freecount++;
}
- else
- {
+ else {
// printf( " Found in time item. break.\n" );
break;
}
@@ -266,173 +241,173 @@
// remove free urls when we are over GlobalHistoryFreeUrlCount
int8 ghfuc = 0;
- AppSettings->FindInt8( kPrefsGlobalHistoryFreeURLCount, &ghfuc );
- if( freecount > ghfuc )
- {
+ AppSettings->FindInt8(kPrefsGlobalHistoryFreeURLCount, &ghfuc);
+ if (freecount > ghfuc) {
// printf( " Removing expired free URLs.\n" );
freecount -= ghfuc;
- for( int8 i = 0; i < freecount; i++ )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( fList->CountItems() -1 );
- if( item != NULL )
- {
+ for (int8 i = 0; i < freecount; i++) {
+ GlobalHistoryItem* item = (GlobalHistoryItem*)fList->ItemAt(fList->CountItems() -1);
+ if (item != NULL) {
// printf( " Removing following expired free URL:\n" );
// item->Print();
- fList->RemoveItem( item );
+ fList->RemoveItem(item);
delete item;
}
}
- }
+ }
}
-void
-GlobalHistory::Clear()
-{
- printf( "GlobalHistory::Clear()\n" );
- while( fList->CountItems() > 0 )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( 0 );
- if( item != NULL )
- {
- fList->RemoveItem( item );
+void GlobalHistory :: Clear() {
+
+ printf("GlobalHistory::Clear()\n");
+ while (fList->CountItems() > 0) {
+ GlobalHistoryItem* item = (GlobalHistoryItem *)fList->ItemAt(0);
+ if (item != NULL) {
+ fList->RemoveItem(item);
delete item;
}
}
}
-BList*
-GlobalHistory::GetStrippedList()
-{
-// printf( "GlobalHistory::GetStrippedList()\n" );
+BList * GlobalHistory :: GetFilteredList(BString & aText) {
- BList* slist = new BList( 0 );
-
+ BString cached_url; // the cached url
+ BString cached_url_proto(""); // protocol of the cached url
+ GlobalHistoryItem * item = NULL;
+ BList * list = new BList();
+ bool matchFound = false;
+
int32 count = fList->CountItems();
-
- /* start adding from last to first, so that we just have to BList::AddItem()
- * without index in Win::UrlTypedHandler(). This results in newer urls ( if
- * they match ) to be at top of the list.
- */
-
- for( int32 i = 0; i < count; i++ )
- {
-// printf( " ==================\n" );
-
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( i );
- if( item != NULL )
- {
-// printf( " Checking for: %s\n", item->Text() );
-
- bool filed = false;
- int32 count2 = slist->CountItems();
-
- for( int32 j = 0; j < count2; j++ )
- {
- GlobalHistoryItem* compareitem = ( GlobalHistoryItem* )slist->ItemAt( j );
- if( compareitem != NULL )
- {
- if( strcmp( item->Text(), compareitem->Text() ) == 0 )
- {
-// printf( " Entry already filed in stripped list. break.\n" );
- filed = true;
- break;
+
+ for (int32 i = 0; i < count; i++) {
+ item = (GlobalHistoryItem *)fList->ItemAt(i);
+ if (item != NULL) {
+ cached_url.SetTo(item->Text());
+
+ if (aText.Length() != 0) {
+ // if the typed url matches beginning of cached url, add it
+ if (strncmp(cached_url.String(), aText.String(), aText.Length()) == 0) {
+ matchFound = true;
+ }
+ else {
+ // if the urls dont match, take away the protocol of the cached url
+ if (cached_url.FindFirst("://") > 0) {
+ cached_url.MoveInto(cached_url_proto, 0, cached_url.FindFirst("://") + 3);
}
+
+ // if the urls fit now
+ if (strncmp(cached_url.String(), aText.String(), aText.Length()) == 0) {
+ // add the missing proto again
+ if (cached_url_proto.Length() != 0)
+ cached_url.Prepend(cached_url_proto);
+ matchFound = true;
+ }
+ else {
+ // if they still don't fit, remove 'www.' from cached url
+ if (cached_url.FindFirst("www.") == 0) {
+ cached_url.Remove(0, 4);
+ }
+
+ // check if they finally fit
+ if (strncmp(cached_url.String(), aText.String(), aText.Length()) == 0) {
+ // add missing 'www.' and proto
+ cached_url.Prepend("www.");
+
+ if (cached_url_proto.Length() != 0)
+ cached_url.Prepend(cached_url_proto);
+ matchFound = true;
+ }
+ }
+ cached_url_proto.SetTo("");
}
}
- if( filed == false )
- {
-// printf( " Entry not filed. Adding.\n" );
- GlobalHistoryItem* newitem = new GlobalHistoryItem(
- item->Text(),
- item->Time() );
- slist->AddItem( newitem );
+ else {
+ matchFound = true;
}
- }
+
+ if (matchFound) {
+ // Check if we already have it in our collection
+ bool found = false;
+ int32 count2 = list->CountItems();
+
+ int32 j = 0;
+ while (j < count2 && !found) {
+ BStringItem * storedUrl = (BStringItem *)list->ItemAt(j);
+ if (strcmp(cached_url.String(), storedUrl->Text()) == 0) {
+ found = true;
+ }
+ else {
+ j++;
+ }
+ }
+ if (!found) {
+ list->AddItem(new BStringItem(cached_url.String()));
+ }
+ }
+ matchFound = false;
+ } // if( item != NULL )
}
-
-// int32 scount = slist->CountItems();
-//
-// printf( " ============================\n" );
-// printf( " Stripped List: ( %ld items )\n", scount );
-// for( int32 k = 0; k < scount; k++ )
-// {
-// GlobalHistoryItem* item = ( GlobalHistoryItem* )slist->ItemAt( k );
-// if( item != NULL )
-// item->Print();
-// }
-// printf( " ============================\n" );
-
- return slist;
+
+ return list;
+
}
-void
-GlobalHistory::Init(
- BMessage* datamsg )
-{
- printf( "GlobalHistory::Init()\n" );
+void GlobalHistory :: Init(BMessage* datamsg) {
+
+ printf("GlobalHistory::Init()\n");
// datamsg->PrintToStream();
- if( datamsg == NULL )
- return;
-
- type_code tc = B_ANY_TYPE;
- int32 count = -1;
-
- if( datamsg->GetInfo( kPrefsGlobalHistoryItemMessage, &tc, &count ) == B_OK )
- {
- printf( " Found %ld GlobalHistoryItemMessages.\n", count );
+ if (datamsg != NULL) {
+ type_code tc = B_ANY_TYPE;
+ int32 count = -1;
- for( int32 i = 0; i < count; i++ )
- {
- BMessage* ghimsg = new BMessage;
- datamsg->FindMessage( kPrefsGlobalHistoryItemMessage, i, ghimsg );
- if( ghimsg != NULL )
- {
- GlobalHistoryItem* newitem = new GlobalHistoryItem(
- ghimsg->FindString( "url" ),
- ghimsg->FindInt32( "time" ) );
- newitem->Print();
- fList->AddItem( newitem, 0 );
+ if (datamsg->GetInfo(kPrefsGlobalHistoryItemMessage, &tc, &count ) == B_OK) {
+ printf(" Found %ld GlobalHistoryItemMessages.\n", count);
+
+ for (int32 i = 0; i < count; i++) {
+ BMessage* ghimsg = new BMessage;
+ datamsg->FindMessage(kPrefsGlobalHistoryItemMessage, i, ghimsg);
+ if (ghimsg != NULL) {
+ GlobalHistoryItem * newitem = new GlobalHistoryItem(
+ ghimsg->FindString("url"),
+ ghimsg->FindInt32("time"));
+ newitem->Print();
+ fList->AddItem(newitem, 0);
+ }
+ delete ghimsg;
}
- delete ghimsg;
+
+ CheckEntryExpiration();
}
-
- CheckEntryExpiration();
+ else {
+ printf(" No GlobalHistoryItemMessages found.\n");
+ }
}
- else
- {
- printf( " No GlobalHistoryItemMessages found.\n" );
- }
}
-void
-GlobalHistory::PrintHistory()
-{
- printf( "GlobalHistory::PrintHistory()\n" );
+void GlobalHistory :: PrintHistory() {
+
+ printf("GlobalHistory::PrintHistory()\n");
int32 count = fList->CountItems();
- printf( " =============================\n" );
- printf( " Global History: ( %ld items )\n", count );
- for( int32 i = 0; i < count; i++ )
- {
- GlobalHistoryItem* item = ( GlobalHistoryItem* )fList->ItemAt( i );
- if( item != NULL )
+ printf(" =============================\n");
+ printf(" Global History: ( %ld items )\n", count);
+ for (int32 i = 0; i < count; i++) {
+ GlobalHistoryItem* item = (GlobalHistoryItem *)fList->ItemAt(i);
+ if (item != NULL)
item->Print();
}
- printf( " =============================\n" );
+ printf(" =============================\n");
}
-void
-GlobalHistory::SetDepth(
- int8 newdepth )
-{
+void GlobalHistory :: SetDepth(int8 newdepth) {
+
// printf( "GlobalHistory::SetDepth()\n" );
- if( newdepth < fHistoryDepthInDays )
- {
+ if (newdepth < fHistoryDepthInDays) {
// remove entries if needed to suit fMaxDepth
fHistoryDepthInDays = newdepth;
CheckEntryExpiration();
@@ -444,44 +419,34 @@
/* GLOBALHISTORYITEM */
-GlobalHistoryItem::GlobalHistoryItem(
- const char* text,
- time_t time,
- uint32 level = 0,
- bool expanded = true )
- : BStringItem( text, level, expanded )
-{
+GlobalHistoryItem :: GlobalHistoryItem(const char* text,
+ time_t time,
+ uint32 level = 0,
+ bool expanded = true )
+ : BStringItem(text, level, expanded) {
+
fTime = time;
+
}
-GlobalHistoryItem::~GlobalHistoryItem()
-{
+GlobalHistoryItem :: ~GlobalHistoryItem() {
+
}
-void
-GlobalHistoryItem::Print()
-{
+void GlobalHistoryItem :: Print() {
+
// printf( "GlobalHistoryItem::Print()\n" );
// printf( " %s @ %s", Text(), asctime( localtime( &fTime ) ) );
}
-void
-GlobalHistoryItem::SetFree()
-{
+void GlobalHistoryItem :: SetFree() {
+
fTime = 0;
+
}
-//void
-//GlobalHistoryItem::SetTime(
-// time_t newtime )
-//{
-// printf( "GlobalHistoryItem::SetTime()\n" );
-//
-// fTime = newtime;
-//}
+time_t GlobalHistoryItem :: Time() {
-time_t
-GlobalHistoryItem::Time()
-{
return fTime;
+
}
Modified: trunk/themis/framework/GlobalHistory.h
===================================================================
--- trunk/themis/framework/GlobalHistory.h 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/GlobalHistory.h 2011-06-02 18:11:12 UTC (rev 650)
@@ -35,32 +35,28 @@
class GlobalHistoryItem;
-class GlobalHistory
-{
+class GlobalHistory {
+
+ private:
+ int8 fHistoryDepthInDays;
+ int8 fFreeUrlCount;
+ BList * fList;
+
+ bool CheckDoubleDay(GlobalHistoryItem* checkitem);
+ void CheckEntryExpiration();
+
public:
- GlobalHistory(
- int8 depth,
- int8 count );
- ~GlobalHistory();
+ GlobalHistory(int8 depth,
+ int8 count);
+ ~GlobalHistory();
- void AddEntry(
- const char* entry );
- void Clear();
- BList* GetStrippedList();
- void Init(
- BMessage* datamsg );
- void PrintHistory();
- void SetDepth(
- int8 newdepth );
+ void AddEntry(const char* entry);
+ void Clear();
+ BList * GetFilteredList(BString & aText);
+ void Init(BMessage* datamsg);
+ void PrintHistory();
+ void SetDepth(int8 newdepth);
- private:
- bool CheckDoubleDay(
- GlobalHistoryItem* checkitem );
- void CheckEntryExpiration();
-
- int8 fHistoryDepthInDays;
- int8 fFreeUrlCount;
- BList* fList;
};
#endif
@@ -70,25 +66,21 @@
#include <ListItem.h>
-class GlobalHistoryItem : public BStringItem
-{
+class GlobalHistoryItem : public BStringItem {
+ private:
+ time_t fTime;
+
public:
- GlobalHistoryItem(
- const char* text,
- time_t time,
- uint32 level = 0,
- bool expaned = true );
- virtual ~GlobalHistoryItem();
-
- void Print();
- void SetFree();
-// void SetTime(
-// time_t newtime );
- time_t Time();
+ GlobalHistoryItem(const char* text,
+ time_t time,
+ uint32 level = 0,
+ bool expaned = true);
+ virtual ~GlobalHistoryItem();
- private:
- time_t fTime;
-
+ void Print();
+ void SetFree();
+ time_t Time();
+
};
#endif
Modified: trunk/themis/framework/ThemisUrlPopUpWindow.cpp
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpWindow.cpp 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/ThemisUrlPopUpWindow.cpp 2011-06-02 18:11:12 UTC (rev 650)
@@ -15,26 +15,27 @@
#include "../common/commondefs.h"
#include "ThemisUrlPopUpWindow.h"
-ThemisUrlPopUpWindow::ThemisUrlPopUpWindow( BWindow* parent, BRect frame )
- : BWindow(
- frame,
- "UrlPopUpWindow",
- B_NO_BORDER_WINDOW_LOOK,
- B_FLOATING_APP_WINDOW_FEEL,
- B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE |
- B_NOT_MINIMIZABLE | B_WILL_ACCEPT_FIRST_CLICK |
- B_AVOID_FOCUS | B_ASYNCHRONOUS_CONTROLS,
- B_CURRENT_WORKSPACE )
-{
- parentwindow = parent;
+ThemisUrlPopUpWindow :: ThemisUrlPopUpWindow(BWindow * aParent,
+ BRect aFrame,
+ BList * aList)
+ : BWindow(aFrame,
+ "UrlPopUpWindow",
+ B_NO_BORDER_WINDOW_LOOK,
+ B_FLOATING_APP_WINDOW_FEEL,
+ B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE |
+ B_NOT_MINIMIZABLE | B_WILL_ACCEPT_FIRST_CLICK |
+ B_AVOID_FOCUS | B_ASYNCHRONOUS_CONTROLS,
+ B_CURRENT_WORKSPACE) {
+
+ parentwindow = aParent;
lastitem = 0;
vscroll = NULL;
- url_list = NULL;
- trunc_list = NULL;
+ url_list = new BList;
+ trunc_list = new BList;
- urlpopupview = new ThemisUrlPopUpView(
- Bounds() );
- AddChild( urlpopupview );
+ urlpopupview = new ThemisUrlPopUpView(Bounds());
+ AddChild(urlpopupview);
+ ListToDisplay(aList);
}
ThemisUrlPopUpWindow::~ThemisUrlPopUpWindow()
@@ -143,30 +144,39 @@
{
//cout << "ThemisUrlPopUpWindow::ListToDisplay()" << endl;
- if( list != NULL )
- {
+ if(list != NULL) {
+ // First delete the contents of the old lists.
+ if (url_list != NULL) {
+ int32 length = url_list->CountItems();
+ for (int32 i = 0; i < length; i++) {
+ delete url_list->RemoveItem((int32) 0);
+ }
+ }
+ if (trunc_list != NULL) {
+ int32 length = trunc_list->CountItems();
+ for (int32 i = 0; i < length; i++) {
+ delete trunc_list->RemoveItem((int32) 0);
+ }
+ }
+
// we need the url_list with untruncated strings
- url_list = new BList( *list );
- // and the list with truncated urls if urlpopup is
- // smaller then the urls-length
- trunc_list = new BList( url_list->CountItems() );
+ url_list->AddList(list);
// we need to totally independant but similar BLists
// ( copying with the copy-constructor won't do it )
int i = 0;
- BStringItem* item;
- while( url_list->ItemAt( i ) != NULL )
- {
- item = ( BStringItem* )url_list->ItemAt( i );
- trunc_list->AddItem( new BStringItem( item->Text() ) );
+ BStringItem * item;
+ while (url_list->ItemAt( i ) != NULL) {
+ item = ( BStringItem* )url_list->ItemAt(i);
+ trunc_list->AddItem( new BStringItem(item->Text()));
i++;
}
+ urlpopupview->ulv->MakeEmpty();
+ urlpopupview->ulv->AddList(trunc_list);
+
TruncateUrlStrings();
- urlpopupview->ulv->MakeEmpty();
- urlpopupview->ulv->AddList( trunc_list );
-
ResizeToPrefered();
}
}
@@ -245,30 +255,32 @@
}
}
-void
-ThemisUrlPopUpWindow::TruncateUrlStrings()
-{
+void ThemisUrlPopUpWindow :: TruncateUrlStrings() {
+
int i = 0;
BStringItem* urlitem = NULL;
BStringItem* truncitem = NULL;
- BString* string = new BString;
+ BString text;
- while( url_list->ItemAt( i ) != NULL )
- {
- urlitem = ( BStringItem* )url_list->ItemAt( i );
- if( urlitem != NULL );
- string->SetTo( urlitem->Text() );
+ while (url_list->ItemAt(i) != NULL) {
+ urlitem = (BStringItem *)url_list->ItemAt(i);
+ text.SetTo(urlitem->Text());
urlpopupview->TruncateString(
- string,
+ &text,
B_TRUNCATE_END,
- urlpopupview->ulv->Bounds().right - 10 );
+ urlpopupview->ulv->Bounds().right - 10);
- truncitem = ( BStringItem* )urlpopupview->ulv->ItemAt( i );
- if( truncitem != NULL )
- truncitem->SetText( string->String() );
-
+ truncitem = (BStringItem *)urlpopupview->ulv->ItemAt(i);
+ if (truncitem != NULL)
+ truncitem->SetText(text.String());
+
i++;
}
- delete string;
}
+
+bool ThemisUrlPopUpWindow :: HasScrollBar() const {
+
+ return (vscroll != NULL);
+
+}
Modified: trunk/themis/framework/ThemisUrlPopUpWindow.h
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpWindow.h 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/ThemisUrlPopUpWindow.h 2011-06-02 18:11:12 UTC (rev 650)
@@ -13,28 +13,28 @@
#include "ThemisUrlPopUpView.h"
#include "Window.h"
-class ThemisUrlPopUpWindow : public BWindow
-{
+class ThemisUrlPopUpWindow : public BWindow {
+
+ private:
+ BWindow * parentwindow;
+
+ uint32 lastitem;
+ BList * url_list;
+ BList * trunc_list;
+ BScrollBar * vscroll;
+
public:
- ThemisUrlPopUpWindow( BWindow* parent, BRect frame );
+ ThemisUrlPopUpWindow(BWindow* aParent, BRect aFrame, BList * aList);
+ ~ThemisUrlPopUpWindow();
- ~ThemisUrlPopUpWindow();
-
- virtual void MessageReceived( BMessage *msg );
+ virtual void MessageReceived(BMessage *msg);
+ void ListToDisplay(BList* list);
+ void ResizeToPrefered();
+ void TruncateUrlStrings();
+ bool HasScrollBar() const;
- void ListToDisplay( BList* list );
- void ResizeToPrefered();
- void TruncateUrlStrings();
-
- ThemisUrlPopUpView* urlpopupview;
- BScrollBar* vscroll;
-
- private:
- BWindow* parentwindow;
-
- uint32 lastitem;
- BList* url_list;
- BList* trunc_list;
+ ThemisUrlPopUpView * urlpopupview;
+
};
#endif
Modified: trunk/themis/framework/win.cpp
===================================================================
--- trunk/themis/framework/win.cpp 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/win.cpp 2011-06-02 18:11:12 UTC (rev 650)
@@ -217,7 +217,7 @@
// as the urlpopupwindow never gets focus and thus
// never get the mouse wheel messages
if (urlpopupwindow != NULL) {
- if (urlpopupwindow->vscroll != NULL) {
+ if (urlpopupwindow->HasScrollBar()) {
float value = msg->FindFloat( "be:wheel_delta_y");
value *= 10;
@@ -663,7 +663,7 @@
}
-void Win :: CreateUrlPopUpWindow() {
+void Win :: CreateUrlPopUpWindow(BList * aList) {
if (urlpopupwindow == NULL) {
BRect frame(navview->urlview->Frame());
@@ -673,7 +673,7 @@
wframe.top = frame.bottom;
wframe.bottom = wframe.top + 30;
- urlpopupwindow = new ThemisUrlPopUpWindow(this, wframe);
+ urlpopupwindow = new ThemisUrlPopUpWindow(this, wframe, aList);
urlpopupwindow->Run();
urlpopupwindow->Show();
@@ -683,6 +683,11 @@
CurrentFocus()->MakeFocus(false);
navview->urlview->textview->MakeFocus(true);
}
+ else {
+ urlpopupwindow->Lock();
+ urlpopupwindow->ListToDisplay(aList);
+ urlpopupwindow->Unlock();
+ }
}
@@ -830,14 +835,7 @@
void Win :: UrlTypedHandler(bool show_all) {
- // get the stripped list from GlobalHistory
- BList * slist = ((App *)be_app)->GetGlobalHistory()->GetStrippedList();
- // create the matching urls list
- BList * list = new BList(0);
-
BString typed_url; // the typed url
- BString cached_url; // the cached url
- BString cached_url_proto(""); // protocol of the cached url
if (show_all == true)
typed_url.SetTo("");
@@ -846,80 +844,19 @@
typed_url.ToLower();
}
- int32 count = slist->CountItems();
-
- for (int32 i = 0; i < count; i++) {
- GlobalHistoryItem * item = (GlobalHistoryItem *)slist->ItemAt(i);
- if (item != NULL) {
- cached_url.SetTo(item->Text());
-
- if (typed_url.Length() != 0) {
- // if the typed url matches beginning of cached url, add it
- if (strncmp(cached_url.String(), typed_url.String(), typed_url.Length()) == 0) {
- list->AddItem(new BStringItem(cached_url.String()));
- }
- else {
- // if the urls dont match, take away the protocol of the cached url
- if (cached_url.FindFirst("://") > 0) {
- cached_url.MoveInto(cached_url_proto, 0, cached_url.FindFirst("://") + 3);
- }
-
- // if the urls fit now
- if (strncmp(cached_url.String(), typed_url.String(), typed_url.Length()) == 0) {
- // add the missing proto again
- if (cached_url_proto.Length() != 0)
- cached_url.Prepend(cached_url_proto);
-
- list->AddItem(new BStringItem(cached_url.String()));
- }
- else {
- // if they still don't fit, remove 'www.' from cached url
- if (cached_url.FindFirst("www.") == 0) {
- cached_url.Remove(0, 4);
- }
-
- // check if they finally fit
- if (strncmp(cached_url.String(), typed_url.String(), typed_url.Length()) == 0) {
- // add missing 'www.' and proto
- cached_url.Prepend("www.");
-
- if (cached_url_proto.Length() != 0)
- cached_url.Prepend(cached_url_proto);
-
- list->AddItem(new BStringItem(cached_url.String()));
- }
- }
- cached_url_proto.SetTo("");
- }
- }
- else {
- list->AddItem(new BStringItem(cached_url.String()));
- }
- } // if( item != NULL )
- }
-
- // delete slist ( not needed anymore )
- for (int32 i = 0; i < count; i++) {
- GlobalHistoryItem * item = (GlobalHistoryItem *)slist->ItemAt(i);
- if (item != NULL) {
- slist->RemoveItem(item);
- delete item;
- }
- }
- delete slist;
-
+ // create the matching urls list
+ BList * list = ((App *)be_app)->GetGlobalHistory()->GetFilteredList(typed_url);
+
// add the urlpopupwindow if needed
if (list->CountItems() > 0) {
- CreateUrlPopUpWindow();
- // add the list
- urlpopupwindow->Lock();
- urlpopupwindow->ListToDisplay(list);
- urlpopupwindow->Unlock();
+ CreateUrlPopUpWindow(list);
}
else {
CloseUrlPopUpWindow();
}
+ delete list;
+
}
status_t Win :: ReceiveBroadcast(BMessage * message) {
Modified: trunk/themis/framework/win.h
===================================================================
--- trunk/themis/framework/win.h 2011-06-02 18:04:41 UTC (rev 649)
+++ trunk/themis/framework/win.h 2011-06-02 18:11:12 UTC (rev 650)
@@ -96,7 +96,7 @@
bool CloseUrlPopUpWindow();
uint32 BroadcastTarget();
void CreateTabView();
- void CreateUrlPopUpWindow();
+ void CreateUrlPopUpWindow(BList * aList);
void SetLoadingInfo(int doc_progress,
const char* status_text);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|