* style adjustments

* commented out a useless block of code (and added a respective TODO) 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36496 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-04-26 17:11:11 +00:00
parent e76856a4a5
commit e590fb24c6
2 changed files with 125 additions and 106 deletions
+91 -73
View File
@@ -1,20 +1,22 @@
/* /*
* Copyright 2006-2010, Haiku. * Copyright 2006-2010, Haiku Inc. All rights reserved.
* All rights reserved. Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Adrien Destugues <[email protected]>
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Adrien Destugues <[email protected]>
*/ */
#include "LanguageListView.h" #include "LanguageListView.h"
#include "Locale.h"
#include <Bitmap.h>
#include <Country.h>
#include <stdio.h> #include <stdio.h>
#include <new> #include <new>
#include <Bitmap.h>
#include <Country.h>
#include "Locale.h"
#define MAX_DRAG_HEIGHT 200.0 #define MAX_DRAG_HEIGHT 200.0
#define ALPHA 170 #define ALPHA 170
@@ -54,7 +56,7 @@ LanguageListItem::~LanguageListItem()
//MediaListItem - DrawItem //MediaListItem - DrawItem
void void
LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete) LanguageListItem::DrawItem(BView* owner, BRect frame, bool complete)
{ {
rgb_color kHighlight = { 140,140,140,0 }; rgb_color kHighlight = { 140,140,140,0 };
rgb_color kBlack = { 0,0,0,0 }; rgb_color kBlack = { 0,0,0,0 };
@@ -63,22 +65,21 @@ LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
if (IsSelected() || complete) { if (IsSelected() || complete) {
rgb_color color; rgb_color color;
if (IsSelected()) { if (IsSelected())
color = kHighlight; color = kHighlight;
} else { else
color = owner->ViewColor(); color = owner->ViewColor();
}
owner->SetHighColor(color); owner->SetHighColor(color);
owner->SetLowColor(color); owner->SetLowColor(color);
owner->FillRect(r); owner->FillRect(r);
owner->SetHighColor(kBlack); owner->SetHighColor(kBlack);
} else { } else
owner->SetLowColor(owner->ViewColor()); owner->SetLowColor(owner->ViewColor());
}
frame.left += 4; frame.left += 4;
BRect iconFrame(frame); BRect iconFrame(frame);
iconFrame.Set(iconFrame.left, iconFrame.top+1, iconFrame.left+15, iconFrame.top+16); iconFrame.Set(iconFrame.left, iconFrame.top+1, iconFrame.left+15,
iconFrame.top+16);
if (fIcon && fIcon->IsValid()) { if (fIcon && fIcon->IsValid()) {
owner->SetDrawingMode(B_OP_OVER); owner->SetDrawingMode(B_OP_OVER);
@@ -89,12 +90,13 @@ LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
frame.left += 16 * (OutlineLevel() + 1); frame.left += 16 * (OutlineLevel() + 1);
owner->SetHighColor(kBlack); owner->SetHighColor(kBlack);
BFont font = be_plain_font; BFont font = be_plain_font;
font_height finfo; font_height finfo;
font.GetHeight(&finfo); font.GetHeight(&finfo);
owner->SetFont(&font); owner->SetFont(&font);
owner->MovePenTo(frame.left+8, frame.top + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) + owner->MovePenTo(frame.left+8, frame.top + ((frame.Height() - (finfo.ascent
(finfo.ascent + finfo.descent) - 1); + finfo.descent + finfo.leading)) / 2) + (finfo.ascent
+ finfo.descent) - 1);
owner->DrawString(Text()); owner->DrawString(Text());
} }
@@ -108,6 +110,20 @@ LanguageListView::LanguageListView(const char* name, list_view_type type)
} }
LanguageListView::~LanguageListView()
{
delete fMsgPrefLanguagesChanged;
}
void
LanguageListView::AttachedToWindow()
{
BOutlineListView::AttachedToWindow();
ScrollToSelection();
}
void void
LanguageListView::MoveItems(BList& items, int32 index) LanguageListView::MoveItems(BList& items, int32 index)
{ {
@@ -132,8 +148,8 @@ LanguageListView::MoveItems(BList& items, int32 index)
} }
// else ??? -> blow up // else ??? -> blow up
} }
for (int32 i = 0; for (int32 i = 0; BListItem* item = (BListItem*)removedItems.ItemAt(i);
BListItem* item = (BListItem*)removedItems.ItemAt(i); i++) { i++) {
if (AddItem(item, index)) { if (AddItem(item, index)) {
// after we're done, the newly inserted items will be selected // after we're done, the newly inserted items will be selected
Select(index, true); Select(index, true);
@@ -160,22 +176,22 @@ void LanguageListView::MessageReceived (BMessage* message)
BList items; BList items;
int32 index; int32 index;
for (int32 i = 0; message->FindInt32("index", i, &index) for (int32 i = 0;
== B_OK; i++) message->FindInt32("index", i, &index) == B_OK; i++) {
if (BListItem* item = FullListItemAt(index)) if (BListItem* item = FullListItemAt(index))
items.AddItem((void*)item); items.AddItem((void*)item);
}
if (items.CountItems() > 0) { if (items.CountItems() > 0) {
// There is something to move // There is something to move
LanguageListItem* parent = LanguageListItem* parent = static_cast<LanguageListItem*>(
static_cast<LanguageListItem*>(Superitem( Superitem(static_cast<LanguageListItem*>(
static_cast<LanguageListItem*>(
items.FirstItem()))); items.FirstItem())));
if (parent) { if (parent) {
// item has a parent - it should then stay // item has a parent - it should then stay
// below it // below it
if (Superitem(FullListItemAt(fDropIndex - 1)) if (Superitem(FullListItemAt(fDropIndex - 1)) == parent
== parent || FullListItemAt(fDropIndex - 1) == parent) || FullListItemAt(fDropIndex - 1) == parent)
MoveItems(items, fDropIndex); MoveItems(items, fDropIndex);
} else { } else {
// item is top level and should stay so. // item is top level and should stay so.
@@ -184,8 +200,9 @@ void LanguageListView::MessageReceived (BMessage* message)
else { else {
int itemCount = CountItemsUnder( int itemCount = CountItemsUnder(
FullListItemAt(fDropIndex), true); FullListItemAt(fDropIndex), true);
MoveItems(items, FullListIndexOf( MoveItems(items, FullListIndexOf(Superitem(
Superitem(FullListItemAt(fDropIndex - 1))+itemCount)); FullListItemAt(fDropIndex - 1))
+ itemCount));
} }
} }
} }
@@ -200,16 +217,19 @@ void LanguageListView::MessageReceived (BMessage* message)
// in the middle of another outline // in the middle of another outline
if (Superitem(FullListItemAt(fDropIndex))) { if (Superitem(FullListItemAt(fDropIndex))) {
// Item has a parent // Item has a parent
fDropIndex = FullListIndexOf(Superitem(FullListItemAt(fDropIndex))); fDropIndex = FullListIndexOf(Superitem(FullListItemAt(
fDropIndex)));
} }
// Item is now a top level one - we must insert just below its last child // Item is now a top level one - we must insert just below its
fDropIndex += CountItemsUnder(FullListItemAt(fDropIndex),false) + 1; // last child
fDropIndex += CountItemsUnder(FullListItemAt(fDropIndex),false)
+ 1;
int32 index; int32 index;
for (int32 i = 0; message->FindInt32("index", i, &index) for (int32 i = 0;
== B_OK; i++) { message->FindInt32("index", i, &index) == B_OK; i++) {
MoveItemFrom(list,index,fDropIndex); MoveItemFrom(list, index, fDropIndex);
fDropIndex++; fDropIndex++;
} }
@@ -231,8 +251,8 @@ LanguageListView::MoveItemFrom(BOutlineListView* origin, int32 index,
LanguageListItem* itemToMove = static_cast<LanguageListItem*>( LanguageListItem* itemToMove = static_cast<LanguageListItem*>(
origin->Superitem(origin->FullListItemAt(index))); origin->Superitem(origin->FullListItemAt(index)));
if (itemToMove == NULL) { if (itemToMove == NULL) {
itemToMove = static_cast<LanguageListItem*>( itemToMove = static_cast<LanguageListItem*>(origin->FullListItemAt(
origin->FullListItemAt(index)); index));
} else } else
index = origin->FullListIndexOf(itemToMove); index = origin->FullListIndexOf(itemToMove);
@@ -244,7 +264,7 @@ LanguageListView::MoveItemFrom(BOutlineListView* origin, int32 index,
for (int i = 0; i < itemCount ; i++) { for (int i = 0; i < itemCount ; i++) {
LanguageListItem* subItem = static_cast<LanguageListItem*>( LanguageListItem* subItem = static_cast<LanguageListItem*>(
origin->ItemUnderAt(itemToMove, true, i)); origin->ItemUnderAt(itemToMove, true, i));
this->AddUnder(new LanguageListItem(*subItem),newItem); this->AddUnder(new LanguageListItem(*subItem), newItem);
} }
origin->RemoveItem(index); origin->RemoveItem(index);
// This will also remove the children // This will also remove the children
@@ -264,19 +284,19 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
if (item) { if (item) {
// create drag message // create drag message
BMessage msg('DRAG'); BMessage msg('DRAG');
msg.AddPointer("list",(void*)(this)); msg.AddPointer("list", (void*)(this));
int32 index; int32 index;
for (int32 i = 0; (index = FullListCurrentSelection(i)) >= 0; i++) { for (int32 i = 0; (index = FullListCurrentSelection(i)) >= 0; i++)
msg.AddInt32("index", index); msg.AddInt32("index", index);
}
// figure out drag rect // figure out drag rect
float width = Bounds().Width(); float width = Bounds().Width();
BRect dragRect(0.0, 0.0, width, -1.0); BRect dragRect(0.0, 0.0, width, -1.0);
// figure out, how many items fit into our bitmap // figure out, how many items fit into our bitmap
int32 numItems; int32 numItems;
bool fade = false; bool fade = false;
for (numItems = 0; BListItem* item = FullListItemAt(CurrentSelection(numItems)); for (numItems = 0;
numItems++) { BListItem* item = FullListItemAt(CurrentSelection(numItems));
numItems++) {
dragRect.bottom += ceilf(item->Height()) + 1.0; dragRect.bottom += ceilf(item->Height()) + 1.0;
if (dragRect.Height() > MAX_DRAG_HEIGHT) { if (dragRect.Height() > MAX_DRAG_HEIGHT) {
fade = true; fade = true;
@@ -287,8 +307,8 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
} }
BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true); BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
if (dragBitmap && dragBitmap->IsValid()) { if (dragBitmap && dragBitmap->IsValid()) {
BView* v = new BView(dragBitmap->Bounds(), "helper", BView* v = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
B_FOLLOW_NONE, B_WILL_DRAW); B_WILL_DRAW);
dragBitmap->AddChild(v); dragBitmap->AddChild(v);
dragBitmap->Lock(); dragBitmap->Lock();
BRect itemBounds(dragRect) ; BRect itemBounds(dragRect) ;
@@ -315,25 +335,21 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
int32 bpr = dragBitmap->BytesPerRow(); int32 bpr = dragBitmap->BytesPerRow();
if (fade) { if (fade) {
for (int32 y = 0; y < height - ALPHA / 2; for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
y++, bits += bpr) {
uint8* line = bits + 3; uint8* line = bits + 3;
for (uint8* end = line + 4 * width; line < end; for (uint8* end = line + 4 * width; line < end; line += 4)
line += 4)
*line = ALPHA; *line = ALPHA;
} }
for (int32 y = height - ALPHA / 2; y < height; for (int32 y = height - ALPHA / 2; y < height;
y++, bits += bpr) { y++, bits += bpr) {
uint8* line = bits + 3; uint8* line = bits + 3;
for (uint8* end = line + 4 * width; line < end; for (uint8* end = line + 4 * width; line < end; line += 4)
line += 4)
*line = (height - y) << 1; *line = (height - y) << 1;
} }
} else { } else {
for (int32 y = 0; y < height; y++, bits += bpr) { for (int32 y = 0; y < height; y++, bits += bpr) {
uint8* line = bits + 3; uint8* line = bits + 3;
for (uint8* end = line + 4 * width; line < end; for (uint8* end = line + 4 * width; line < end; line += 4)
line += 4)
*line = ALPHA; *line = ALPHA;
} }
} }
@@ -356,10 +372,11 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
void void
LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg) LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg)
{ {
if (msg && (msg->what == 'DRAG')) { if (msg && msg->what == 'DRAG') {
switch (transit) { switch (transit) {
case B_ENTERED_VIEW: case B_ENTERED_VIEW:
case B_INSIDE_VIEW: { case B_INSIDE_VIEW:
{
// set drop target through virtual function // set drop target through virtual function
// offset where by half of item height // offset where by half of item height
BRect r = ItemFrame(0); BRect r = ItemFrame(0);
@@ -371,24 +388,25 @@ LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg)
if (fDropIndex != index) { if (fDropIndex != index) {
fDropIndex = index; fDropIndex = index;
if (fDropIndex >= 0) { if (fDropIndex >= 0) {
int32 count = FullListCountItems(); // TODO: find out what this was intended for (as it doesn't have any effect)
if (fDropIndex == count) { // int32 count = FullListCountItems();
BRect r; // if (fDropIndex == count) {
if (FullListItemAt(count - 1)) { // BRect r;
r = ItemFrame(count - 1); // if (FullListItemAt(count - 1)) {
r.top = r.bottom; // r = ItemFrame(count - 1);
r.bottom = r.top + 1.0; // r.top = r.bottom;
} else { // r.bottom = r.top + 1.0;
r = Bounds(); // } else {
r.bottom--; // r = Bounds();
// compensate for scrollbars moved slightly // r.bottom--;
// out of window // // compensate for scrollbars moved slightly
} // // out of window
} else { // }
BRect r = ItemFrame(fDropIndex); // } else {
r.top--; // BRect r = ItemFrame(fDropIndex);
r.bottom = r.top + 1.0; // r.top--;
} // r.bottom = r.top + 1.0;
// }
} }
} }
break; break;
+34 -33
View File
@@ -1,12 +1,11 @@
/* /*
* Copyright 2006-2010, Haiku. * Copyright 2006-2010, Haiku Inc. All rights reserved.
* All rights reserved. Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Adrien Destugues <[email protected]>
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Adrien Destugues <[email protected]>
*/ */
#ifndef __LANGUAGE_LIST_VIEW_H #ifndef __LANGUAGE_LIST_VIEW_H
#define __LANGUAGE_LIST_VIEW_H #define __LANGUAGE_LIST_VIEW_H
@@ -16,40 +15,42 @@
#include <String.h> #include <String.h>
class LanguageListItem: public BStringItem { class LanguageListItem : public BStringItem {
public: public:
LanguageListItem(const char* text, const char* code); LanguageListItem(const char* text,
LanguageListItem(const LanguageListItem& other); const char* code);
~LanguageListItem(); LanguageListItem(const LanguageListItem& other);
virtual ~LanguageListItem();
const BString& LanguageCode() { return fLanguageCode; } const BString& LanguageCode() { return fLanguageCode; }
void DrawItem(BView *owner, BRect frame, bool complete = false); void DrawItem(BView* owner, BRect frame,
bool complete = false);
private: private:
BString fLanguageCode; BString fLanguageCode;
BBitmap* fIcon; BBitmap* fIcon;
}; };
class LanguageListView: public BOutlineListView { class LanguageListView : public BOutlineListView {
public: public:
LanguageListView(const char* name, list_view_type type); LanguageListView(const char* name,
list_view_type type);
virtual ~LanguageListView();
~LanguageListView() { delete fMsgPrefLanguagesChanged; } bool InitiateDrag(BPoint point, int32 index,
bool wasSelected);
bool InitiateDrag(BPoint point, int32 index, bool wasSelected); void MouseMoved(BPoint where, uint32 transit,
void MouseMoved(BPoint where, uint32 transit, const BMessage* msg); const BMessage* msg);
void MoveItems(BList& items, int32 index); void MoveItems(BList& items, int32 index);
void MoveItemFrom(BOutlineListView* origin, int32 index, int32 dropSpot = 0); void MoveItemFrom(BOutlineListView* origin, int32 index,
void AttachedToWindow() int32 dropSpot = 0);
{ void AttachedToWindow();
BOutlineListView::AttachedToWindow(); void MessageReceived (BMessage* message);
ScrollToSelection(); private:
} int32 fDropIndex;
void MessageReceived (BMessage* message); BMessage* fMsgPrefLanguagesChanged;
private:
int32 fDropIndex;
BMessage* fMsgPrefLanguagesChanged;
}; };
#endif #endif