* Fixed font sensitivity issues of the directory choosing window.
* Made the code more robust, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16973 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5fef96ef20
commit
290026d3b1
@ -1,34 +1,19 @@
|
|||||||
/*****************************************************************************/
|
/*
|
||||||
// Expander
|
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
|
||||||
// Written by Jérôme Duval
|
* Distributed under the terms of the MIT License.
|
||||||
//
|
*
|
||||||
// DirectoryFilePanel.cpp
|
* Authors:
|
||||||
//
|
* Jérôme Duval
|
||||||
// Copyright (c) 2004 OpenBeOS Project
|
*/
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
|
||||||
// to deal in the Software without restriction, including without limitation
|
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included
|
|
||||||
// in all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
||||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
#include "DirectoryFilePanel.h"
|
#include "DirectoryFilePanel.h"
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
DirectoryRefFilter::DirectoryRefFilter()
|
DirectoryRefFilter::DirectoryRefFilter()
|
||||||
: BRefFilter()
|
: BRefFilter()
|
||||||
{
|
{
|
||||||
@ -39,16 +24,19 @@ bool
|
|||||||
DirectoryRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st,
|
DirectoryRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st,
|
||||||
const char *filetype)
|
const char *filetype)
|
||||||
{
|
{
|
||||||
return (node->IsDirectory());
|
return node->IsDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode, BMessenger *target,
|
DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode, BMessenger *target,
|
||||||
const entry_ref *start_directory, uint32 node_flavors,
|
const entry_ref *startDirectory, uint32 nodeFlavors,
|
||||||
bool allow_multiple_selection, BMessage *message, BRefFilter *filter,
|
bool allowMultipleSelection, BMessage *message, BRefFilter *filter,
|
||||||
bool modal, bool hide_when_done)
|
bool modal, bool hideWhenDone)
|
||||||
:BFilePanel(mode,target,start_directory, node_flavors,
|
: BFilePanel(mode, target, startDirectory, nodeFlavors,
|
||||||
allow_multiple_selection,message,filter,modal,hide_when_done),
|
allowMultipleSelection, message, filter, modal, hideWhenDone),
|
||||||
fCurrentButton(NULL)
|
fCurrentButton(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -57,33 +45,66 @@ DirectoryFilePanel::DirectoryFilePanel(file_panel_mode mode, BMessenger *target,
|
|||||||
void
|
void
|
||||||
DirectoryFilePanel::Show()
|
DirectoryFilePanel::Show()
|
||||||
{
|
{
|
||||||
if (!fCurrentButton) {
|
if (fCurrentButton == NULL) {
|
||||||
entry_ref ref;
|
|
||||||
char label[50];
|
|
||||||
GetPanelDirectory(&ref);
|
|
||||||
sprintf(label, "Select '%s'", ref.name);
|
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
BView *background = Window()->ChildAt(0);
|
BView* background = Window()->ChildAt(0);
|
||||||
fCurrentButton = new BButton(
|
BView* cancel = background->FindView("cancel button");
|
||||||
BRect(113, background->Bounds().bottom-35, 269, background->Bounds().bottom-10),
|
|
||||||
"directoryButton", label, new BMessage(MSG_DIRECTORY), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
BRect rect;
|
||||||
|
if (cancel != NULL)
|
||||||
|
rect = cancel->Frame();
|
||||||
|
else {
|
||||||
|
rect = background->Bounds();
|
||||||
|
rect.left = rect.right;
|
||||||
|
rect.top = rect.bottom - 35;
|
||||||
|
rect.bottom -= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
fCurrentButton = new BButton(rect, "directoryButton", "Select current",
|
||||||
|
new BMessage(MSG_DIRECTORY), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
|
fCurrentButton->ResizeToPreferred();
|
||||||
|
fCurrentButton->MoveBy(-fCurrentButton->Bounds().Width() - 8, 0);
|
||||||
background->AddChild(fCurrentButton);
|
background->AddChild(fCurrentButton);
|
||||||
SetButtonLabel(B_DEFAULT_BUTTON, "Select");
|
|
||||||
fCurrentButton->SetTarget(Messenger());
|
fCurrentButton->SetTarget(Messenger());
|
||||||
|
|
||||||
|
SetButtonLabel(B_DEFAULT_BUTTON, "Select");
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
|
|
||||||
|
SelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
BFilePanel::Show();
|
BFilePanel::Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DirectoryFilePanel::SelectionChanged(void)
|
DirectoryFilePanel::SelectionChanged(void)
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
|
||||||
char label[50];
|
|
||||||
GetPanelDirectory(&ref);
|
|
||||||
Window()->Lock();
|
Window()->Lock();
|
||||||
sprintf(label, "Select '%s'", ref.name);
|
|
||||||
|
char label[64];
|
||||||
|
entry_ref ref;
|
||||||
|
GetPanelDirectory(&ref);
|
||||||
|
if (snprintf(label, sizeof(label), "Select '%s'", ref.name) >= (int)sizeof(label))
|
||||||
|
strcpy(label + sizeof(label) - 5, B_UTF8_ELLIPSIS "'");
|
||||||
|
|
||||||
|
// Resize button so that the label fits
|
||||||
|
// maximum width is dictated by the window's size limits
|
||||||
|
|
||||||
|
float dummy, maxWidth;
|
||||||
|
Window()->GetSizeLimits(&maxWidth, &dummy, &dummy, &dummy);
|
||||||
|
maxWidth -= Window()->Bounds().Width() + 8 - fCurrentButton->Frame().right;
|
||||||
|
|
||||||
|
float oldWidth = fCurrentButton->Bounds().Width();
|
||||||
fCurrentButton->SetLabel(label);
|
fCurrentButton->SetLabel(label);
|
||||||
|
float width, height;
|
||||||
|
fCurrentButton->GetPreferredSize(&width, &height);
|
||||||
|
if (width > maxWidth)
|
||||||
|
width = maxWidth;
|
||||||
|
fCurrentButton->ResizeTo(width, height);
|
||||||
|
fCurrentButton->MoveBy(oldWidth - width, 0);
|
||||||
|
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
|
|
||||||
BFilePanel::SelectionChanged();
|
BFilePanel::SelectionChanged();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user