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