|
From: CVS C. to T. <the...@li...> - 2011-07-16 23:25:33
|
Revision: 662
http://themis.svn.sourceforge.net/themis/?rev=662&view=rev
Author: mark_hellegers
Date: 2011-07-16 23:25:27 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
Reworked parts of the url popup window. It is now simpler and the parts of the code are refactored.
Modified Paths:
--------------
trunk/themis/framework/GlobalHistory.cpp
trunk/themis/framework/ThemisUrlPopUpView.cpp
trunk/themis/framework/ThemisUrlPopUpView.h
trunk/themis/framework/ThemisUrlPopUpWindow.cpp
trunk/themis/framework/ThemisUrlPopUpWindow.h
trunk/themis/framework/UrlItem.cpp
trunk/themis/framework/UrlItem.hpp
trunk/themis/framework/app.cpp
trunk/themis/framework/win.cpp
Modified: trunk/themis/framework/GlobalHistory.cpp
===================================================================
--- trunk/themis/framework/GlobalHistory.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/GlobalHistory.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -334,7 +334,7 @@
int32 j = 0;
while (j < count2 && !found) {
- BStringItem * storedUrl = (BStringItem *)list->ItemAt(j);
+ UrlItem * storedUrl = (UrlItem *)list->ItemAt(j);
if (strcmp(cached_url.String(), storedUrl->Text()) == 0) {
found = true;
}
Modified: trunk/themis/framework/ThemisUrlPopUpView.cpp
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpView.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/ThemisUrlPopUpView.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -4,9 +4,13 @@
#include <iostream>
#include <string>
+// BeOS headers
+#include <interface/ScrollBar.h>
+
// Themis headers
#include "../common/commondefs.h"
#include "ThemisUrlPopUpView.h"
+#include "UrlItem.hpp"
ThemisUrlPopUpView :: ThemisUrlPopUpView(BRect frame)
: BView(frame,
@@ -17,7 +21,7 @@
BRect rect = Bounds();
ulv = new BListView(
- BRect(rect.left + 19,
+ BRect(rect.left + 1,
rect.top + 1,
rect.right - 1,
rect.bottom - 1),
@@ -28,6 +32,7 @@
ulv->SetFontSize(10.0);
AddChild(ulv);
ulv->AddFilter(new ThemisUrlPopUpViewMessageFilter(Window()));
+ mScrollBar = NULL;
}
void
@@ -51,6 +56,80 @@
SetHighColor( hi );
}
+const char * ThemisUrlPopUpView :: SetUrlSelection(int aOffset) {
+
+ if (aOffset != 0) {
+ ulv->Select(ulv->CurrentSelection() + aOffset);
+ ulv->ScrollToSelection();
+ }
+
+ UrlItem * item = (UrlItem *)ulv->ItemAt(ulv->CurrentSelection());
+
+ return item->Text();
+
+}
+
+int32 ThemisUrlPopUpView :: CurrentSelection() {
+
+ return ulv->CurrentSelection();
+
+}
+
+void ThemisUrlPopUpView :: MakeEmpty() {
+
+ ulv->MakeEmpty();
+
+}
+
+void ThemisUrlPopUpView :: AddList(BList * aList) {
+
+ ulv->AddList(aList);
+
+}
+
+UrlItem * ThemisUrlPopUpView :: FirstItem() {
+
+ return (UrlItem *) ulv->FirstItem();
+
+}
+
+int32 ThemisUrlPopUpView :: CountItems() {
+
+ return ulv->CountItems();
+
+}
+
+void ThemisUrlPopUpView :: SetScrollBarRange(float aMin, float aMax) {
+
+ if (!mScrollBar) {
+ BRect scrollRect = Bounds();
+ scrollRect.left = scrollRect.right - B_V_SCROLL_BAR_WIDTH;
+ mScrollBar = new BScrollBar(
+ scrollRect,
+ "UrlScrollBar",
+ ulv,
+ aMin,
+ aMax,
+ B_VERTICAL);
+ AddChild(mScrollBar);
+ ulv->ResizeBy(-B_V_SCROLL_BAR_WIDTH - 1, 0);
+ }
+ else {
+ mScrollBar->SetRange(aMin, aMax);
+ }
+
+}
+
+void ThemisUrlPopUpView :: RemoveScrollBar() {
+
+ if (mScrollBar) {
+ RemoveChild(mScrollBar);
+ mScrollBar = NULL;
+ ulv->ResizeBy(B_V_SCROLL_BAR_WIDTH + 1, 0);
+ }
+
+}
+
/////////////////////////////////////
// ThemisUrlPopUpViewMessageFilter
/////////////////////////////////////
Modified: trunk/themis/framework/ThemisUrlPopUpView.h
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpView.h 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/ThemisUrlPopUpView.h 2011-07-16 23:25:27 UTC (rev 662)
@@ -9,20 +9,28 @@
#include <MessageFilter.h>
#include <GraphicsDefs.h>
-// C/C++ headers
+// Declarations used
+class UrlItem;
+class BScrollBar;
-// myheaders
+class ThemisUrlPopUpView : public BView {
-class ThemisUrlListView;
+ private:
+ BListView * ulv;
+ BScrollBar * mScrollBar;
-class ThemisUrlPopUpView : public BView {
-
public:
ThemisUrlPopUpView(BRect frame);
virtual void Draw(BRect updaterect);
- BListView * ulv;
-
+ const char * SetUrlSelection(int aOffset);
+ int32 CurrentSelection();
+ void MakeEmpty();
+ void AddList(BList * aList);
+ UrlItem * FirstItem();
+ int32 CountItems();
+ void SetScrollBarRange(float aMin, float aMax);
+ void RemoveScrollBar();
};
#endif
Modified: trunk/themis/framework/ThemisUrlPopUpWindow.cpp
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpWindow.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/ThemisUrlPopUpWindow.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -1,19 +1,15 @@
/* ThemisUrlPopUpWindow.cpp */
-// BeOS headers
-
// Standard C headers
#include <stdio.h>
-// Standard C++ headers
-#include <iostream>
-
// Themis headers
#include "ThemisUrlView.h"
#include "ThemisNavView.h"
#include "win.h"
#include "../common/commondefs.h"
#include "ThemisUrlPopUpWindow.h"
+#include "ThemisUrlPopUpView.h"
#include "UrlItem.hpp"
ThemisUrlPopUpWindow :: ThemisUrlPopUpWindow(BWindow * aParent,
@@ -30,67 +26,66 @@
parentwindow = aParent;
lastitem = 0;
- vscroll = NULL;
- url_list = new BList;
+ mUrlList = new BList();
- urlpopupview = new ThemisUrlPopUpView(Bounds());
- AddChild(urlpopupview);
+ mMaxHeight = (int32) Bounds().bottom;
+ mItemHeight = 0;
+ mUrlListView = new ThemisUrlPopUpView(
+ Bounds());
+ mUrlListView->SetFontSize(10.0);
ListToDisplay(aList);
+
+ AddChild(mUrlListView);
}
-ThemisUrlPopUpWindow::~ThemisUrlPopUpWindow()
-{
- UrlItem * item = NULL;
+ThemisUrlPopUpWindow::~ThemisUrlPopUpWindow() {
- int32 length = url_list->CountItems();
- for( int32 i = 0; i < length; i++ )
- {
- item = (UrlItem *)url_list->RemoveItem((int32)0);
- delete item;
- }
-
- delete url_list;
+ EmptyUrlList();
+ delete mUrlList;
+
}
void ThemisUrlPopUpWindow :: SetUrlSelection(int aOffset) {
- if (aOffset != 0) {
- urlpopupview->ulv->Select(urlpopupview->ulv->CurrentSelection() + aOffset);
- urlpopupview->ulv->ScrollToSelection();
- }
- UrlItem * item = (UrlItem *)url_list->ItemAt(
- urlpopupview->ulv->CurrentSelection());
+ const char * urlText = mUrlListView->SetUrlSelection(aOffset);
- if (item) {
+ if (urlText) {
parentwindow->Lock();
- ((Win *)parentwindow)->GetNavView()->SetUrl(item->Text());
+ ((Win *)parentwindow)->GetNavView()->SetUrl(urlText);
parentwindow->Unlock();
}
}
+void ThemisUrlPopUpWindow :: EmptyUrlList() {
-void
-ThemisUrlPopUpWindow::MessageReceived( BMessage *msg )
-{
- switch( msg->what )
- {
- case URL_SELECT_MOUSE :
- {
+ UrlItem * item = NULL;
+
+ int32 length = mUrlList->CountItems();
+
+ for (int32 i = 0; i < length; i++) {
+ item = (UrlItem *)mUrlList->RemoveItem((int32)0);
+ delete item;
+ }
+
+}
+
+
+void ThemisUrlPopUpWindow :: MessageReceived(BMessage *msg) {
+
+ switch (msg->what) {
+ case URL_SELECT_MOUSE: {
// set the urlview-text
SetUrlSelection();
// doubleclick opens url
- uint32 clickitem = urlpopupview->ulv->CurrentSelection();
- if( msg->HasBool( "doubleclick" ) )
- {
- if( msg->FindBool( "doubleclick" ) == true )
- {
- if( clickitem == lastitem )
- {
- BMessenger msgr( NULL, parentwindow, NULL );
- msgr.SendMessage( new BMessage( URL_OPEN ) );
+ uint32 clickitem = mUrlListView->CurrentSelection();
+ if (msg->HasBool( "doubleclick" )) {
+ if (msg->FindBool("doubleclick") == true) {
+ if (clickitem == lastitem) {
+ BMessenger msgr(NULL, parentwindow, NULL);
+ msgr.SendMessage(new BMessage(URL_OPEN));
}
}
}
@@ -98,122 +93,74 @@
break;
}
- case URL_SELECT_NEXT :
- {
+ case URL_SELECT_NEXT: {
SetUrlSelection(1);
break;
}
- case URL_SELECT_PREV :
- {
+ case URL_SELECT_PREV: {
SetUrlSelection(-1);
break;
}
case B_MOUSE_WHEEL_CHANGED: {
float value = msg->FindFloat( "be:wheel_delta_y");
value *= 10;
- urlpopupview->ulv->ScrollBy(0, value);
+ mUrlListView->ScrollBy(0, value);
break;
}
- default :
- BWindow::MessageReceived( msg );
+ default:
+ BWindow::MessageReceived(msg);
}
}
void ThemisUrlPopUpWindow :: ListToDisplay(BList * list) {
if (list != NULL) {
- // First delete the contents of the old lists.
- int32 length = url_list->CountItems();
- for (int32 i = 0; i < length; i++) {
- delete url_list->RemoveItem((int32) 0);
- }
+ mUrlListView->MakeEmpty();
+ EmptyUrlList();
+ mUrlList->AddList(list);
+ mUrlListView->AddList(mUrlList);
- // we need to totally independant but similar BLists
- // ( copying with the copy-constructor won't do it )
- url_list->AddList(list);
-
- urlpopupview->ulv->MakeEmpty();
- urlpopupview->ulv->AddList(url_list);
-
- ResizeToPrefered();
+ ResizeToPrefered();
}
}
-void
-ThemisUrlPopUpWindow::ResizeToPrefered()
-{
- BPoint parent_bottom = parentwindow->Bounds().RightBottom();
- BPoint parent_bottom_cts = parentwindow->ConvertToScreen( parent_bottom );
-
- float itemheight = urlpopupview->ulv->ItemAt( 0 )->Height();
- int32 count = urlpopupview->ulv->CountItems();
-
- float newheight = ( itemheight * count ) + ( 1.9 * count ) + 1;
-
- BPoint new_popup_bottom;
- new_popup_bottom.y = newheight;
- BPoint new_popup_bottom_cts = ConvertToScreen( new_popup_bottom );
-
- float difference = parent_bottom_cts.y - new_popup_bottom_cts.y - 20;
-
+void ThemisUrlPopUpWindow :: ResizeToPrefered() {
+
+ parentwindow->Lock();
float urlview_width = ((Win*)parentwindow)->GetNavView()->GetBoundsOfUrlView().right;
+ parentwindow->Unlock();
- if( difference < 0 )
- {
- // the urlpopup would reach over the parentwindows bottom
-
- new_popup_bottom.y -= -difference;
- ResizeTo( urlview_width, new_popup_bottom.y );
-
- if( vscroll == NULL )
- {
- urlpopupview->ResizeTo(
- urlpopupview->Bounds().right - B_V_SCROLL_BAR_WIDTH,
- urlpopupview->Bounds().bottom );
-
- BRect bounds = Bounds();
-
- vscroll = new BScrollBar(
- BRect(
- bounds.right - B_V_SCROLL_BAR_WIDTH,
- bounds.top,
- bounds.right,
- bounds.bottom ),
- "URLPOPUPVSCROLLBAR",
- urlpopupview->ulv,
- 0,
- newheight - urlpopupview->ulv->Bounds().bottom,
- B_VERTICAL );
- AddChild( vscroll );
- }
- else
- {
- vscroll->SetRange(
- 0,
- newheight - urlpopupview->ulv->Bounds().bottom );
- }
- }
- else
- {
- // the urlpopup fits into the parentwindow
-
- ResizeTo( urlview_width, new_popup_bottom.y );
-
- if( vscroll != NULL )
- {
- RemoveChild( vscroll );
- vscroll = NULL;
+ // Calculate the total height of the items to see if we should shrink the list view.
+ if (mItemHeight == 0) {
+ // Only calculate the height once. It won't change.
+ mItemHeight = mUrlListView->FirstItem()->Height();
+ if (mItemHeight == 0) {
+ // Happens sometimes and I don't know why. Get the lineheight as an approximation.
+ font_height height;
+ mUrlListView->GetFontHeight(&height);
+ mItemHeight = height.ascent + height.descent + height.leading;
- urlpopupview->ResizeTo(
- urlpopupview->Bounds().right + B_V_SCROLL_BAR_WIDTH,
- urlpopupview->Bounds().bottom );
}
}
+
+ int32 count = mUrlListView->CountItems();
+
+ int32 listHeight = (int32) ((mItemHeight * count) + (1.9 * count) + 1);
+ if (listHeight > mMaxHeight) {
+ mUrlListView->SetScrollBarRange(0, listHeight - mUrlListView->Bounds().bottom);
+ listHeight = mMaxHeight;
+ }
+ else {
+ mUrlListView->RemoveScrollBar();
+ }
+
+ // Only resize if needed
+ BRect rect = Bounds();
+ int32 width = (int32) rect.Width();
+ int32 height = (int32) rect.Height();
+ if ((width != urlview_width) || (height != listHeight)) {
+ ResizeTo(urlview_width, listHeight);
+ }
+
}
-
-bool ThemisUrlPopUpWindow :: HasScrollBar() const {
-
- return (vscroll != NULL);
-
-}
Modified: trunk/themis/framework/ThemisUrlPopUpWindow.h
===================================================================
--- trunk/themis/framework/ThemisUrlPopUpWindow.h 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/ThemisUrlPopUpWindow.h 2011-07-16 23:25:27 UTC (rev 662)
@@ -4,25 +4,26 @@
#define _THEMISURLPOPUPWINDOW_H_
// BeOS headers
-#include "Window.h"
-#include <ScrollBar.h>
+#include <Window.h>
-// C/C++ headers
+// Declarations used
+class BScrollBar;
+class BList;
+class ThemisUrlPopUpView;
-// myheaders
-#include "ThemisUrlPopUpView.h"
-#include "Window.h"
-
class ThemisUrlPopUpWindow : public BWindow {
private:
BWindow * parentwindow;
+ ThemisUrlPopUpView * mUrlListView;
+ BList * mUrlList;
+ int32 mMaxHeight;
+ float mItemHeight;
+
uint32 lastitem;
- BList * url_list;
- BScrollBar * vscroll;
- ThemisUrlPopUpView * urlpopupview;
void SetUrlSelection(int aOffset = 0);
+ void EmptyUrlList();
public:
ThemisUrlPopUpWindow(BWindow* aParent, BRect aFrame, BList * aList);
@@ -31,8 +32,6 @@
virtual void MessageReceived(BMessage *msg);
void ListToDisplay(BList* list);
void ResizeToPrefered();
- bool HasScrollBar() const;
-
};
Modified: trunk/themis/framework/UrlItem.cpp
===================================================================
--- trunk/themis/framework/UrlItem.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/UrlItem.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -33,18 +33,21 @@
*/
+#include <stdio.h>
+
// BeOS headers
-#include "be/interface/GraphicsDefs.h"
-#include "be/interface/InterfaceDefs.h"
-#include "be/interface/View.h"
-#include "be/support/String.h"
+#include <be/interface/GraphicsDefs.h>
+#include <be/interface/InterfaceDefs.h>
+#include <be/interface/View.h>
// Themis headers
#include "UrlItem.hpp"
UrlItem :: UrlItem(const char * aUrl)
- : BStringItem(aUrl) {
+ : BListItem() {
+ mUrl = BString(aUrl);
+
}
void UrlItem :: DrawItem(BView * aOwner,
@@ -65,13 +68,26 @@
color = ui_color(B_MENU_ITEM_TEXT_COLOR);
aOwner->SetHighColor(color);
- BString url(Text());
+ BString url = mUrl;
+/*
aOwner->TruncateString(
&url,
B_TRUNCATE_END,
- aFrame.right - 10);
-
- aOwner->MovePenTo(aFrame.left + 4, aFrame.bottom - 2);
+ aFrame.right - 29);
+*/
+ aOwner->MovePenTo(aFrame.left + 4 + 19, aFrame.bottom - 2);
aOwner->DrawString(url.String());
}
+
+void UrlItem :: SetText(const char * aText) {
+
+ mUrl.SetTo(aText);
+
+}
+
+const char * UrlItem :: Text() {
+
+ return mUrl.String();
+
+}
Modified: trunk/themis/framework/UrlItem.hpp
===================================================================
--- trunk/themis/framework/UrlItem.hpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/UrlItem.hpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -32,16 +32,22 @@
#define URLITEM_HPP
// BeOS headers
-#include <ListItem.h>
+#include <be/interface/ListItem.h>
+#include <be/support/String.h>
-class UrlItem : public BStringItem {
+class UrlItem : public BListItem {
+ private:
+ BString mUrl;
+
public:
UrlItem(const char * aUrl);
virtual void DrawItem(BView * aOwner,
BRect aFrame,
bool aComplete = false);
+ void SetText(const char * aText);
+ const char * Text();
};
Modified: trunk/themis/framework/app.cpp
===================================================================
--- trunk/themis/framework/app.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/app.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -47,7 +47,6 @@
#include "PrefsWin.h"
#include "ThemisTab.h"
#include "SiteHandler.h"
-#include "ThemisUrlView.h"
#include "ThemisNavView.h"
#include "app.h"
Modified: trunk/themis/framework/win.cpp
===================================================================
--- trunk/themis/framework/win.cpp 2011-06-05 14:23:23 UTC (rev 661)
+++ trunk/themis/framework/win.cpp 2011-07-16 23:25:27 UTC (rev 662)
@@ -48,7 +48,6 @@
#include "SiteHandler.h"
#include "SiteEntry.h"
#include "UrlEntry.h"
-#include "ThemisUrlView.h"
#include "ThemisNavView.h"
#include "ThemisStatusView.h"
#include "ThemisTabView.h"
@@ -217,10 +216,8 @@
// as the urlpopupwindow never gets focus and thus
// never get the mouse wheel messages
if (urlpopupwindow != NULL) {
- if (urlpopupwindow->HasScrollBar()) {
- BMessenger* msgr = new BMessenger(NULL, urlpopupwindow, NULL);
- msgr->SendMessage(msg);
- }
+ BMessenger* msgr = new BMessenger(NULL, urlpopupwindow, NULL);
+ msgr->SendMessage(msg);
}
break;
}
@@ -665,7 +662,7 @@
BRect wframe(frame);
wframe.top = frame.bottom;
- wframe.bottom = wframe.top + 30;
+ wframe.bottom = wframe.top + 130;
urlpopupwindow = new ThemisUrlPopUpWindow(this, wframe, aList);
urlpopupwindow->Run();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|