DOS-->BeOS endlines

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10530 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-12-24 17:55:42 +00:00
parent c74996495a
commit 872e52f249
+469 -469
View File
@@ -1,469 +1,469 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2004, Haiku, Inc. // Copyright (c) 2001-2004, Haiku, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // 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: // Software is furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // 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 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: Menubar.cpp // File Name: Menubar.cpp
// Authors: Marc Flerackers ([email protected]) // Authors: Marc Flerackers ([email protected])
// Stefano Ceccherini ([email protected]) // Stefano Ceccherini ([email protected])
// Description: BMenuBar is a menu that's at the root of a menu hierarchy. // Description: BMenuBar is a menu that's at the root of a menu hierarchy.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// TODO: Finish this class // TODO: Finish this class
#include <Application.h> #include <Application.h>
#include <Autolock.h> #include <Autolock.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Window.h> #include <Window.h>
#include <stdio.h> #include <stdio.h>
#include <AppMisc.h> #include <AppMisc.h>
struct menubar_data struct menubar_data
{ {
BMenuBar *menuBar; BMenuBar *menuBar;
int32 menuIndex; int32 menuIndex;
bool sticky; bool sticky;
bool showMenu; bool showMenu;
bool useRect; bool useRect;
BRect rect; BRect rect;
}; };
BMenuBar::BMenuBar(BRect frame, const char *title, uint32 resizeMask, BMenuBar::BMenuBar(BRect frame, const char *title, uint32 resizeMask,
menu_layout layout, bool resizeToFit) menu_layout layout, bool resizeToFit)
: BMenu(frame, title, resizeMask, : BMenu(frame, title, resizeMask,
B_WILL_DRAW | B_FRAME_EVENTS, layout, resizeToFit), B_WILL_DRAW | B_FRAME_EVENTS, layout, resizeToFit),
fBorder(B_BORDER_FRAME), fBorder(B_BORDER_FRAME),
fTrackingPID(-1), fTrackingPID(-1),
fPrevFocusToken(-1), fPrevFocusToken(-1),
fMenuSem(-1), fMenuSem(-1),
fLastBounds(NULL), fLastBounds(NULL),
fTracking(false) fTracking(false)
{ {
InitData(layout); InitData(layout);
} }
BMenuBar::BMenuBar(BMessage *data) BMenuBar::BMenuBar(BMessage *data)
: BMenu(data), : BMenu(data),
fBorder(B_BORDER_FRAME), fBorder(B_BORDER_FRAME),
fTrackingPID(-1), fTrackingPID(-1),
fPrevFocusToken(-1), fPrevFocusToken(-1),
fMenuSem(-1), fMenuSem(-1),
fLastBounds(NULL), fLastBounds(NULL),
fTracking(false) fTracking(false)
{ {
int32 border; int32 border;
if (data->FindInt32("_border", &border) == B_OK) if (data->FindInt32("_border", &border) == B_OK)
SetBorder((menu_bar_border)border); SetBorder((menu_bar_border)border);
// TODO: InitData() ?? // TODO: InitData() ??
} }
BMenuBar::~BMenuBar() BMenuBar::~BMenuBar()
{ {
if (fTrackingPID >= 0) { if (fTrackingPID >= 0) {
status_t dummy; status_t dummy;
wait_for_thread(fTrackingPID, &dummy); wait_for_thread(fTrackingPID, &dummy);
} }
delete fLastBounds; delete fLastBounds;
} }
BArchivable * BArchivable *
BMenuBar::Instantiate(BMessage *data) BMenuBar::Instantiate(BMessage *data)
{ {
if (validate_instantiation(data, "BMenuBar")) if (validate_instantiation(data, "BMenuBar"))
return new BMenuBar(data); return new BMenuBar(data);
else else
return NULL; return NULL;
} }
status_t status_t
BMenuBar::Archive(BMessage *data, bool deep) const BMenuBar::Archive(BMessage *data, bool deep) const
{ {
status_t err = BMenu::Archive(data, deep); status_t err = BMenu::Archive(data, deep);
if (err < B_OK) if (err < B_OK)
return err; return err;
if (Border() != B_BORDER_FRAME) if (Border() != B_BORDER_FRAME)
err = data->AddInt32("_border", Border()); err = data->AddInt32("_border", Border());
return err; return err;
} }
void void
BMenuBar::SetBorder(menu_bar_border border) BMenuBar::SetBorder(menu_bar_border border)
{ {
fBorder = border; fBorder = border;
} }
menu_bar_border menu_bar_border
BMenuBar::Border() const BMenuBar::Border() const
{ {
return fBorder; return fBorder;
} }
void void
BMenuBar::Draw(BRect updateRect) BMenuBar::Draw(BRect updateRect)
{ {
// TODO: implement additional border styles // TODO: implement additional border styles
// Fix this function, the BMenuBar isn't drawn correctly // Fix this function, the BMenuBar isn't drawn correctly
if (!IsEnabled()) { if (!IsEnabled()) {
LayoutItems(0); LayoutItems(0);
Sync(); Sync();
Invalidate(); Invalidate();
} else { } else {
BRect bounds(Bounds()); BRect bounds(Bounds());
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
StrokeLine(BPoint(0.0f, bounds.bottom - 2.0f), BPoint(0.0f, 0.0f)); StrokeLine(BPoint(0.0f, bounds.bottom - 2.0f), BPoint(0.0f, 0.0f));
StrokeLine(BPoint(bounds.right, 0.0f)); StrokeLine(BPoint(bounds.right, 0.0f));
SetHighColor(tint_color(ui_color( B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); SetHighColor(tint_color(ui_color( B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT));
StrokeLine(BPoint(1.0f, bounds.bottom - 1.0f), StrokeLine(BPoint(1.0f, bounds.bottom - 1.0f),
BPoint(bounds.right, bounds.bottom - 1.0f)); BPoint(bounds.right, bounds.bottom - 1.0f));
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT));
StrokeLine(BPoint(0.0f, bounds.bottom), BPoint(bounds.right, bounds.bottom)); StrokeLine(BPoint(0.0f, bounds.bottom), BPoint(bounds.right, bounds.bottom));
StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom)); StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom));
DrawItems(updateRect); DrawItems(updateRect);
} }
} }
void void
BMenuBar::AttachedToWindow() BMenuBar::AttachedToWindow()
{ {
Install(Window()); Install(Window());
Window()->SetKeyMenuBar(this); Window()->SetKeyMenuBar(this);
BMenu::AttachedToWindow(); BMenu::AttachedToWindow();
} }
void void
BMenuBar::DetachedFromWindow() BMenuBar::DetachedFromWindow()
{ {
BMenu::DetachedFromWindow(); BMenu::DetachedFromWindow();
} }
void void
BMenuBar::MessageReceived(BMessage *msg) BMenuBar::MessageReceived(BMessage *msg)
{ {
BMenu::MessageReceived(msg); BMenu::MessageReceived(msg);
} }
void void
BMenuBar::MouseDown(BPoint where) BMenuBar::MouseDown(BPoint where)
{ {
BWindow *window = Window(); BWindow *window = Window();
if (!window->IsActive() || !window->IsFront()) { if (!window->IsActive() || !window->IsFront()) {
window->Activate(); window->Activate();
window->UpdateIfNeeded(); window->UpdateIfNeeded();
} }
StartMenuBar(-1, false, false); StartMenuBar(-1, false, false);
} }
void void
BMenuBar::WindowActivated(bool state) BMenuBar::WindowActivated(bool state)
{ {
BView::WindowActivated(state); BView::WindowActivated(state);
} }
void void
BMenuBar::MouseUp(BPoint where) BMenuBar::MouseUp(BPoint where)
{ {
BView::MouseUp(where); BView::MouseUp(where);
} }
void void
BMenuBar::FrameMoved(BPoint newPosition) BMenuBar::FrameMoved(BPoint newPosition)
{ {
BMenu::FrameMoved(newPosition); BMenu::FrameMoved(newPosition);
} }
void void
BMenuBar::FrameResized(float newWidth, float newHeight) BMenuBar::FrameResized(float newWidth, float newHeight)
{ {
BMenu::FrameResized(newWidth, newHeight); BMenu::FrameResized(newWidth, newHeight);
} }
void void
BMenuBar::Show() BMenuBar::Show()
{ {
BView::Show(); BView::Show();
} }
void void
BMenuBar::Hide() BMenuBar::Hide()
{ {
BView::Hide(); BView::Hide();
} }
BHandler * BHandler *
BMenuBar::ResolveSpecifier(BMessage *msg, int32 index, BMenuBar::ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form, BMessage *specifier, int32 form,
const char *property) const char *property)
{ {
return BMenu::ResolveSpecifier(msg, index, specifier, form, property); return BMenu::ResolveSpecifier(msg, index, specifier, form, property);
} }
status_t status_t
BMenuBar::GetSupportedSuites(BMessage *data) BMenuBar::GetSupportedSuites(BMessage *data)
{ {
return BMenu::GetSupportedSuites(data); return BMenu::GetSupportedSuites(data);
} }
void void
BMenuBar::ResizeToPreferred() BMenuBar::ResizeToPreferred()
{ {
BMenu::ResizeToPreferred(); BMenu::ResizeToPreferred();
} }
void void
BMenuBar::GetPreferredSize(float *width, float *height) BMenuBar::GetPreferredSize(float *width, float *height)
{ {
BMenu::GetPreferredSize(width, height); BMenu::GetPreferredSize(width, height);
} }
void void
BMenuBar::MakeFocus(bool state) BMenuBar::MakeFocus(bool state)
{ {
BMenu::MakeFocus(state); BMenu::MakeFocus(state);
} }
void void
BMenuBar::AllAttached() BMenuBar::AllAttached()
{ {
BMenu::AllAttached(); BMenu::AllAttached();
} }
void void
BMenuBar::AllDetached() BMenuBar::AllDetached()
{ {
BMenu::AllDetached(); BMenu::AllDetached();
} }
status_t status_t
BMenuBar::Perform(perform_code d, void *arg) BMenuBar::Perform(perform_code d, void *arg)
{ {
return BMenu::Perform(d, arg); return BMenu::Perform(d, arg);
} }
void BMenuBar::_ReservedMenuBar1() {} void BMenuBar::_ReservedMenuBar1() {}
void BMenuBar::_ReservedMenuBar2() {} void BMenuBar::_ReservedMenuBar2() {}
void BMenuBar::_ReservedMenuBar3() {} void BMenuBar::_ReservedMenuBar3() {}
void BMenuBar::_ReservedMenuBar4() {} void BMenuBar::_ReservedMenuBar4() {}
BMenuBar & BMenuBar &
BMenuBar::operator=(const BMenuBar &) BMenuBar::operator=(const BMenuBar &)
{ {
return *this; return *this;
} }
void void
BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool show_menu, BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool show_menu,
BRect *special_rect) BRect *special_rect)
{ {
BWindow *window = Window(); BWindow *window = Window();
if (!window) if (!window)
debugger("MenuBar must be added to a window before it can be used."); debugger("MenuBar must be added to a window before it can be used.");
BAutolock lock(window); BAutolock lock(window);
if (lock.IsLocked()) { if (lock.IsLocked()) {
fPrevFocusToken = -1; fPrevFocusToken = -1;
fTracking = true; fTracking = true;
window->MenusBeginning(); window->MenusBeginning();
fMenuSem = create_sem(0, "window close sem"); fMenuSem = create_sem(0, "window close sem");
_set_menu_sem_(window, fMenuSem); _set_menu_sem_(window, fMenuSem);
fTrackingPID = spawn_thread(TrackTask, "menu_tracking", B_NORMAL_PRIORITY, NULL); fTrackingPID = spawn_thread(TrackTask, "menu_tracking", B_NORMAL_PRIORITY, NULL);
if (fTrackingPID >= 0) { if (fTrackingPID >= 0) {
menubar_data data; menubar_data data;
data.menuBar = this; data.menuBar = this;
data.menuIndex = menuIndex; data.menuIndex = menuIndex;
data.sticky = sticky; data.sticky = sticky;
data.showMenu = show_menu; data.showMenu = show_menu;
data.useRect = special_rect != NULL; data.useRect = special_rect != NULL;
if (data.useRect) if (data.useRect)
data.rect = *special_rect; data.rect = *special_rect;
send_data(fTrackingPID, 0, &data, sizeof(data)); send_data(fTrackingPID, 0, &data, sizeof(data));
resume_thread(fTrackingPID); resume_thread(fTrackingPID);
} else { } else {
_set_menu_sem_(window, B_NO_MORE_SEMS); _set_menu_sem_(window, B_NO_MORE_SEMS);
delete_sem(fMenuSem); delete_sem(fMenuSem);
} }
} }
} }
long long
BMenuBar::TrackTask(void *arg) BMenuBar::TrackTask(void *arg)
{ {
menubar_data data; menubar_data data;
thread_id id; thread_id id;
receive_data(&id, &data, sizeof(data)); receive_data(&id, &data, sizeof(data));
BMenuBar *menuBar = data.menuBar; BMenuBar *menuBar = data.menuBar;
BWindow *window = menuBar->Window(); BWindow *window = menuBar->Window();
menuBar->SetStickyMode(data.sticky); menuBar->SetStickyMode(data.sticky);
int32 action; int32 action;
menuBar->Track(&action, data.menuIndex, data.showMenu); menuBar->Track(&action, data.menuIndex, data.showMenu);
// Sends a _MENUS_DONE_ message to the BWindow. // Sends a _MENUS_DONE_ message to the BWindow.
// Weird: There is a _MENUS_DONE_ message but not a // Weird: There is a _MENUS_DONE_ message but not a
// _MENUS_BEGINNING_ message, in fact the MenusBeginning() // _MENUS_BEGINNING_ message, in fact the MenusBeginning()
// hook function is called directly. // hook function is called directly.
window->PostMessage(_MENUS_DONE_); window->PostMessage(_MENUS_DONE_);
_set_menu_sem_(window, B_BAD_SEM_ID); _set_menu_sem_(window, B_BAD_SEM_ID);
delete_sem(menuBar->fMenuSem); delete_sem(menuBar->fMenuSem);
menuBar->fMenuSem = B_BAD_SEM_ID; menuBar->fMenuSem = B_BAD_SEM_ID;
return 0; return 0;
} }
BMenuItem * BMenuItem *
BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
{ {
// TODO: This function is very incomplete and just partially working: // TODO: This function is very incomplete and just partially working:
// For example, it doesn't respect the "sticky mode" setting. // For example, it doesn't respect the "sticky mode" setting.
// Cleanup // Cleanup
BMenuItem *resultItem = NULL; BMenuItem *resultItem = NULL;
BWindow *window = Window(); BWindow *window = Window();
if (window->LockWithTimeout(200000) == B_OK) { if (window->LockWithTimeout(200000) == B_OK) {
BPoint where; BPoint where;
ulong buttons; ulong buttons;
do { do {
printf("BMenuBar: tracking...\n"); printf("BMenuBar: tracking...\n");
GetMouse(&where, &buttons); GetMouse(&where, &buttons);
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN); BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
if (menuItem) { if (menuItem) {
BMenu *menu = menuItem->Submenu(); BMenu *menu = menuItem->Submenu();
if (menu) { if (menu) {
printf("BMenuBar: showing menu %s\n", menu->Name()); printf("BMenuBar: showing menu %s\n", menu->Name());
menu->Show(); menu->Show();
do { do {
snooze(40000); snooze(40000);
GetMouse(&where, &buttons); GetMouse(&where, &buttons);
// If we aren't over this BMenu anymore, exit the tracking loop. // If we aren't over this BMenu anymore, exit the tracking loop.
BMenuItem *testItem = HitTestItems(where, B_ORIGIN); BMenuItem *testItem = HitTestItems(where, B_ORIGIN);
if (testItem != NULL && testItem != menuItem) if (testItem != NULL && testItem != menuItem)
break; break;
resultItem = menu->_track((int *)action, startIndex); resultItem = menu->_track((int *)action, startIndex);
printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action); printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action);
// "action" is "5" when the BMenu is closed. // "action" is "5" when the BMenu is closed.
} while (*action != 5); } while (*action != 5);
printf("BMenuBar: hiding menu %s\n", menu->Name()); printf("BMenuBar: hiding menu %s\n", menu->Name());
menu->_hide(); menu->_hide();
} }
} }
snooze(40000); snooze(40000);
} while (buttons != 0); } while (buttons != 0);
window->Unlock(); window->Unlock();
} }
if (resultItem != NULL) { if (resultItem != NULL) {
printf("BMenuBar: selected item %s\n", resultItem->Label()); printf("BMenuBar: selected item %s\n", resultItem->Label());
resultItem->Invoke(); resultItem->Invoke();
} }
return resultItem; return resultItem;
} }
void void
BMenuBar::StealFocus() BMenuBar::StealFocus()
{ {
BWindow *window = Window(); BWindow *window = Window();
if (window && window->Lock()) { if (window && window->Lock()) {
BView *focus = window->CurrentFocus(); BView *focus = window->CurrentFocus();
if (focus) if (focus)
fPrevFocusToken = _get_object_token_(focus); fPrevFocusToken = _get_object_token_(focus);
MakeFocus(); MakeFocus();
window->Unlock(); window->Unlock();
} }
} }
void void
BMenuBar::RestoreFocus() BMenuBar::RestoreFocus()
{ {
BWindow *window = Window(); BWindow *window = Window();
if (window && window->Lock()) { if (window && window->Lock()) {
// TODO: Give focus back to the previous focus BView // TODO: Give focus back to the previous focus BView
window->Unlock(); window->Unlock();
} }
} }
void void
BMenuBar::InitData(menu_layout layout) BMenuBar::InitData(menu_layout layout)
{ {
fLastBounds = new BRect(Bounds()); fLastBounds = new BRect(Bounds());
SetItemMargins(8, 2, 8, 2); SetItemMargins(8, 2, 8, 2);
SetIgnoreHidden(true); SetIgnoreHidden(true);
} }