The task manager is now completely font sensitive.

Enlarged the cancel button a bit.
Started counting mechanism (ie. later, when you really press Ctrl+Alt+Del,
the TMDescView counts down to zero). Ideally, this would be fed by the
keyboard device.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13148 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-06-15 08:36:51 +00:00
parent 73c9d940e7
commit 49a755ef15
4 changed files with 181 additions and 87 deletions

View File

@ -13,22 +13,23 @@
// //
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <string.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <View.h> #include <View.h>
#include "TMListItem.h" #include "TMListItem.h"
#define kITEM_MARGIN 2 #include <string.h>
static const int32 kItemMargin = 2;
TMListItem::TMListItem(team_info &tinfo) TMListItem::TMListItem(team_info &tinfo)
: BListItem(), : BListItem(),
fInfo(tinfo), fInfo(tinfo),
fIcon(BRect(0,0,15,15), B_CMAP8), fIcon(BRect(0, 0, 15, 15), B_CMAP8),
fLargeIcon(BRect(0,0,31,31), B_CMAP8) fLargeIcon(BRect(0, 0, 31, 31), B_CMAP8)
{ {
SetHeight(16 + kITEM_MARGIN);
int32 cookie = 0; int32 cookie = 0;
image_info info; image_info info;
if (get_next_image_info(tinfo.team, &cookie, &info) == B_OK) { if (get_next_image_info(tinfo.team, &cookie, &info) == B_OK) {
@ -90,15 +91,22 @@ TMListItem::DrawItem(BView *owner, BRect frame, bool complete)
} }
void /*static*/
TMListItem::Update(BView *owner, const BFont *finfo) int32
TMListItem::MinimalHeight()
{ {
// we need to override the update method so we can make sure are return 16 + kItemMargin;
// list item size doesn't change }
BListItem::Update(owner, finfo);
if ((Height() < 16 + kITEM_MARGIN)) {
SetHeight(16 + kITEM_MARGIN); void
} TMListItem::Update(BView *owner, const BFont *font)
{
// we need to override the update method so we can make sure
// the list item size doesn't change
BListItem::Update(owner, font);
if (Height() < MinimalHeight())
SetHeight(MinimalHeight());
} }

View File

@ -20,24 +20,27 @@
#include <ListItem.h> #include <ListItem.h>
#include <Path.h> #include <Path.h>
class TMListItem : public BListItem class TMListItem : public BListItem {
{ public:
public: TMListItem(team_info &info);
TMListItem(team_info &info); ~TMListItem();
~TMListItem();
virtual void DrawItem(BView *owner, BRect frame, bool complete = false); virtual void DrawItem(BView *owner, BRect frame, bool complete = false);
virtual void Update(BView *owner, const BFont *finfo); virtual void Update(BView *owner, const BFont *finfo);
const team_info *GetInfo();
const team_info *GetInfo();
const BBitmap *LargeIcon() { return &fLargeIcon; }; const BBitmap *LargeIcon() { return &fLargeIcon; };
const BPath *Path() { return &fPath; }; const BPath *Path() { return &fPath; };
bool IsSystemServer(); bool IsSystemServer();
bool fFound;
private: static int32 MinimalHeight();
team_info fInfo;
BBitmap fIcon, fLargeIcon; bool fFound;
BPath fPath;
private:
team_info fInfo;
BBitmap fIcon, fLargeIcon;
BPath fPath;
}; };

View File

@ -38,7 +38,7 @@ extern "C" void _kshutdown_(bool reboot);
TMWindow::TMWindow() TMWindow::TMWindow()
: BWindow(BRect(0,0,350,300), "Team Monitor", : BWindow(BRect(0, 0, 350, 300), "Team Monitor",
B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL,
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_ALL_WORKSPACES), B_ALL_WORKSPACES),
@ -48,10 +48,14 @@ TMWindow::TMWindow()
// ToDo: make this font sensitive // ToDo: make this font sensitive
fView = new TMView(Bounds(), "background", B_FOLLOW_LEFT | B_FOLLOW_TOP, fView = new TMView(Bounds(), "background", B_FOLLOW_ALL,
B_WILL_DRAW, B_NO_BORDER); B_WILL_DRAW, B_NO_BORDER);
AddChild(fView); AddChild(fView);
float width, height;
fView->GetPreferredSize(&width, &height);
ResizeTo(width, height);
BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame(); BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame();
BPoint point; BPoint point;
point.x = (screenFrame.Width() - Bounds().Width()) / 2; point.x = (screenFrame.Width() - Bounds().Width()) / 2;
@ -122,21 +126,31 @@ TMView::TMView(BRect bounds, const char* name, uint32 resizeFlags,
BRect rect = bounds; BRect rect = bounds;
rect.InsetBy(12, 12); rect.InsetBy(12, 12);
rect.right -= B_V_SCROLL_BAR_WIDTH; rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom = rect.top + 146; rect.bottom = rect.top + TMListItem::MinimalHeight() * 8 + 6;
BFont font = be_plain_font; BFont font = be_plain_font;
fListView = new BListView(rect, "teams", B_SINGLE_SELECTION_LIST, fListView = new BListView(rect, "teams", B_SINGLE_SELECTION_LIST,
B_FOLLOW_ALL); B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM)); fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM));
BScrollView *scrollView = new BScrollView("scroll_teams", fListView, BScrollView *scrollView = new BScrollView("scroll_teams", fListView,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER); B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
AddChild(scrollView); AddChild(scrollView);
rect.left = 10;
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 20;
rect.right = rect.left + font.StringWidth("Kill Application") + 20;
fKillButton = new BButton(rect, "kill", "Kill Application",
new BMessage(TM_KILL_APPLICATION), B_FOLLOW_LEFT | B_FOLLOW_TOP);
AddChild(fKillButton);
fKillButton->SetEnabled(false);
rect = bounds; rect = bounds;
rect.right -= 10; rect.right -= 10;
rect.left = rect.right - font.StringWidth("Cancel") - 20; rect.left = rect.right - font.StringWidth("Cancel") - 40;
rect.bottom -= 14; rect.bottom -= 14;
rect.top = rect.bottom - 20; rect.top = rect.bottom - 20;
@ -151,19 +165,11 @@ TMView::TMView(BRect bounds, const char* name, uint32 resizeFlags,
new BMessage(TM_FORCE_REBOOT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); new BMessage(TM_FORCE_REBOOT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
AddChild(forceReboot); AddChild(forceReboot);
rect.top -= 97; rect.left += 4;
rect.bottom = rect.top + 20; rect.bottom = rect.top - 8;
rect.right = rect.left + font.StringWidth("Kill Application") + 20; rect.top = fKillButton->Frame().bottom + 8;
fKillApp = new BButton(rect, "kill", "Kill Application",
new BMessage(TM_KILL_APPLICATION), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
AddChild(fKillApp);
fKillApp->SetEnabled(false);
rect.top = rect.bottom + 10;
rect.bottom = rect.top + 65;
rect.right = bounds.right - 10; rect.right = bounds.right - 10;
fDescView = new TMDescView(rect); fDescView = new TMDescView(rect, B_FOLLOW_ALL);
AddChild(fDescView); AddChild(fDescView);
} }
@ -176,12 +182,10 @@ TMView::AttachedToWindow()
cancel->SetTarget(this); cancel->SetTarget(this);
} }
if (BButton *kill = dynamic_cast<BButton*>(FindView("kill")))
kill->SetTarget(this);
if (BButton *reboot = dynamic_cast<BButton*>(FindView("force"))) if (BButton *reboot = dynamic_cast<BButton*>(FindView("force")))
reboot->SetTarget(this); reboot->SetTarget(this);
fKillButton->SetTarget(this);
fListView->SetTarget(this); fListView->SetTarget(this);
} }
@ -197,12 +201,11 @@ TMView::MessageReceived(BMessage *msg)
TMListItem *item = (TMListItem*)ListView()->ItemAt( TMListItem *item = (TMListItem*)ListView()->ItemAt(
ListView()->CurrentSelection()); ListView()->CurrentSelection());
kill_team(item->GetInfo()->team); kill_team(item->GetInfo()->team);
fKillApp->SetEnabled(false);
UpdateList(); UpdateList();
break; break;
} }
case TM_SELECTED_TEAM: { case TM_SELECTED_TEAM: {
fKillApp->SetEnabled(fListView->CurrentSelection() >= 0); fKillButton->SetEnabled(fListView->CurrentSelection() >= 0);
TMListItem *item = (TMListItem*)ListView()->ItemAt( TMListItem *item = (TMListItem*)ListView()->ItemAt(
ListView()->CurrentSelection()); ListView()->CurrentSelection());
fDescView->SetItem(item); fDescView->SetItem(item);
@ -264,8 +267,10 @@ TMView::UpdateList()
for (int32 i = fListView->CountItems() - 1; i >= 0; i--) { for (int32 i = fListView->CountItems() - 1; i >= 0; i--) {
TMListItem *item = (TMListItem*)fListView->ItemAt(i); TMListItem *item = (TMListItem*)fListView->ItemAt(i);
if (!item->fFound) { if (!item->fFound) {
if (item == fDescView->Item()) if (item == fDescView->Item()) {
fDescView->SetItem(NULL); fDescView->SetItem(NULL);
fKillButton->SetEnabled(false);
}
delete fListView->RemoveItem(i); delete fListView->RemoveItem(i);
changed = true; changed = true;
@ -277,13 +282,48 @@ TMView::UpdateList()
} }
void
TMView::GetPreferredSize(float *_width, float *_height)
{
fDescView->GetPreferredSize(_width, _height);
if (_width)
*_width += 28;
if (_height) {
*_height += fKillButton->Bounds().Height() * 2
+ TMListItem::MinimalHeight() * 8 + 50;
}
}
// #pragma mark - // #pragma mark -
TMDescView::TMDescView(BRect rect) TMDescView::TMDescView(BRect rect, uint32 resizeMode)
: BBox(rect, "descview", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW, B_NO_BORDER), : BBox(rect, "descview", resizeMode, B_WILL_DRAW | B_PULSE_NEEDED, B_NO_BORDER),
fItem(NULL) fItem(NULL)
{ {
SetFont(be_plain_font);
fText[0] = "Select an application from the list above and click the";
fText[1] = "\"Kill Application\" button in order to close it.";
fText[2] = "Hold CONTROL+ALT+DELETE for %ld seconds to reboot.";
fKeysPressed = false;
fSeconds = 4;
}
void
TMDescView::Pulse()
{
// ToDo: connect this mechanism with the keyboard device - it can tell us
// if ctrl-alt-del is pressed
if (fKeysPressed) {
fSeconds--;
Invalidate();
}
} }
@ -292,46 +332,80 @@ TMDescView::Draw(BRect rect)
{ {
rect = Bounds(); rect = Bounds();
font_height fontInfo;
GetFontHeight(&fontInfo);
float height = ceil(fontInfo.ascent + fontInfo.descent + fontInfo.leading + 2);
if (fItem) { if (fItem) {
// draw icon and application path
BRect frame(rect); BRect frame(rect);
frame.OffsetBy(2,3); frame.Set(frame.left, frame.top, frame.left + 31, frame.top + 31);
frame.Set(frame.left, frame.top, frame.left+31, frame.top+31);
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_OVER);
DrawBitmap(fItem->LargeIcon(), frame); DrawBitmap(fItem->LargeIcon(), frame);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
BFont font = be_plain_font; BPoint line(frame.right + 9, frame.top + fontInfo.ascent);
font_height finfo; if (!fItem->IsSystemServer())
font.GetHeight(&finfo); line.y += (frame.Height() - height) / 2;
SetFont(&font); else
MovePenTo(frame.right+9, frame.top - 2 + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 4) + line.y += (frame.Height() - 2 * height) / 2;
(finfo.ascent + finfo.descent) - 1);
BString path = fItem->Path()->Path(); BString path = fItem->Path()->Path();
TruncateString(&path, B_TRUNCATE_MIDDLE, rect.right - 9 - frame.right); TruncateString(&path, B_TRUNCATE_MIDDLE, rect.right - line.x);
DrawString(path.String()); DrawString(path.String(), line);
if (fItem->IsSystemServer()) { if (fItem->IsSystemServer()) {
MovePenTo(frame.right+9, frame.top + 1 + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) *3 / 4) + line.y += height;
(finfo.ascent + finfo.descent) - 1); //SetFont(be_bold_font);
DrawString("(This team is a system component)"); DrawString("(This team is a system component)", line);
//SetFont(be_plain_font);
} }
} else { } else {
BFont font = be_plain_font; BPoint line(rect.left, rect.top + fontInfo.ascent);
font_height finfo;
font.GetHeight(&finfo);
SetFont(&font);
BPoint point(rect.left+4, rect.top - 9 + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 4) +
(finfo.ascent + finfo.descent) - 1);
MovePenTo(point);
DrawString("Select an application from the list above and click the");
point.y += 13; for (int32 i = 0; i < 2; i++) {
MovePenTo(point); DrawString(fText[i], line);
DrawString("\"Kill Application\" button in order to close it."); line.y += height;
}
point.y += 26; char text[256];
MovePenTo(point); if (fSeconds >= 0)
DrawString("Hold CONTROL+ALT+DELETE for 4 seconds to reboot."); snprintf(text, sizeof(text), fText[2], fSeconds);
else
strcpy(text, "Booom!");
line.y += height;
DrawString(text, line);
}
}
void
TMDescView::GetPreferredSize(float *_width, float *_height)
{
if (_width) {
float width = 0;
for (int32 i = 0; i < 3; i++) {
float stringWidth = StringWidth(fText[i]);
if (stringWidth > width)
width = stringWidth;
}
if (width < 330)
width = 330;
*_width = width;
}
if (_height) {
font_height fontInfo;
GetFontHeight(&fontInfo);
float height = 4 * ceil(fontInfo.ascent + fontInfo.descent + fontInfo.leading + 2);
if (height < 32)
height = 32;
*_height = height;
} }
} }

View File

@ -38,25 +38,34 @@ class TMView : public BBox {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Pulse(); virtual void Pulse();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
virtual void GetPreferredSize(float *_width, float *_height);
void UpdateList(); void UpdateList();
BListView *ListView() { return fListView; } BListView *ListView() { return fListView; }
private: private:
BListView *fListView; BListView *fListView;
BButton *fKillApp; BButton *fKillButton;
TMDescView *fDescView; TMDescView *fDescView;
}; };
class TMDescView : public BBox { class TMDescView : public BBox {
public: public:
TMDescView(BRect bounds); TMDescView(BRect bounds, uint32 resizeMode);
virtual void Pulse();
virtual void Draw(BRect bounds); virtual void Draw(BRect bounds);
virtual void GetPreferredSize(float *_width, float *_height);
void SetItem(TMListItem *item); void SetItem(TMListItem *item);
TMListItem *Item() { return fItem; } TMListItem *Item() { return fItem; }
private: private:
const char *fText[3];
TMListItem *fItem; TMListItem *fItem;
int32 fSeconds;
bool fKeysPressed;
}; };
class TMWindow : public BWindow { class TMWindow : public BWindow {