BMenuItem also draws ctrl bitmap if needed, BTextView::AutoResize implemented more correctly

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16577 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-03-03 19:31:09 +00:00
parent da2e259d76
commit 2c11ec31c8
5 changed files with 41 additions and 23 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ enum menu_actions {
}; };
const static char *kEmptyMenuLabel = "<empty>"; #define kEmptyMenuLabel "<empty>"
#endif // __MENU_PRIVATE_H #endif // __MENU_PRIVATE_H
+2 -4
View File
@@ -4090,15 +4090,13 @@ BTextView::UpdateScrollbars()
void void
BTextView::AutoResize(bool doredraw) BTextView::AutoResize(bool doredraw)
{ {
// TODO: What about fContainerView ? Should we resize it as well ?
if (fResizable) { if (fResizable) {
float width = 0; float width = 0;
for (int32 i = 0; i < CountLines(); i++) for (int32 i = 0; i < CountLines(); i++)
width = max_c(width, LineWidth(i)); width = max_c(width, LineWidth(i));
ResizeTo(width, max_c(Bounds().Height(), TextHeight(0, CountLines()))); BView *viewToResize = fContainerView != NULL ? fContainerView : this;
if (fContainerView) viewToResize->ResizeTo(width, max_c(Bounds().Height(), TextHeight(0, CountLines())));
fContainerView->ResizeTo(Bounds().Width(), Bounds().Height());
} }
} }
+1 -1
View File
@@ -1816,7 +1816,7 @@ BMenu::UpdateWindowViewSize(bool upWind)
window->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2); window->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2);
else { else {
CacheFontInfo(); CacheFontInfo();
window->ResizeTo(StringWidth("<empty>") + 4, fFontHeight + 6); window->ResizeTo(StringWidth(kEmptyMenuLabel) + 5, fFontHeight + 6);
} }
window->MoveTo(frame.LeftTop()); window->MoveTo(frame.LeftTop());
} }
+34 -15
View File
@@ -647,14 +647,17 @@ BMenuItem::SetSuper(BMenu *super)
void void
BMenuItem::Select(bool on) BMenuItem::Select(bool selected)
{ {
if (fSelected == selected)
return;
if (Submenu()) { if (Submenu()) {
fSelected = on; fSelected = selected;
Highlight(on); Highlight(selected);
} else if (IsEnabled()) { } else if (IsEnabled()) {
fSelected = on; fSelected = selected;
Highlight(on); Highlight(selected);
} }
} }
@@ -704,26 +707,42 @@ BMenuItem::DrawShortcutSymbol()
where -= BPoint(20, 10); where -= BPoint(20, 10);
// TODO: Do this in a better way
bool altAsCommandKey = true;
key_map *keys = NULL;
char *chars;
get_key_map(&keys, &chars);
if (keys == NULL || keys->left_command_key != 0x5d || keys->right_command_key != 0x5f)
altAsCommandKey = false;
free(chars);
free(keys);
if (fModifiers & B_COMMAND_KEY) { if (fModifiers & B_COMMAND_KEY) {
key_map *keys;
char *chars;
get_key_map(&keys, &chars);
BRect rect(0,0,16,10); BRect rect(0,0,16,10);
BBitmap control(rect, B_COLOR_8_BIT); BBitmap control(rect, B_COLOR_8_BIT);
// TODO: isn't there a better way to do this? if (altAsCommandKey)
if (keys != NULL
&& keys->left_command_key == 0x5d && keys->right_command_key == 0x5f)
control.SetBits(kAltBits, kAltLength, 0, B_COLOR_8_BIT); control.SetBits(kAltBits, kAltLength, 0, B_COLOR_8_BIT);
else else
control.SetBits(kCtrlBits, kCtrlLength, 0, B_COLOR_8_BIT); control.SetBits(kCtrlBits, kCtrlLength, 0, B_COLOR_8_BIT);
fSuper->DrawBitmap(&control, where); fSuper->DrawBitmap(&control, where);
where.x -= rect.Width(); where.x -= rect.Width() + 1;
free(chars);
free(keys);
} }
if (fModifiers & B_CONTROL_KEY) {
BRect rect(0,0,16,10);
BBitmap control(rect, B_COLOR_8_BIT);
if (altAsCommandKey)
control.SetBits(kCtrlBits, kCtrlLength, 0, B_COLOR_8_BIT);
else
control.SetBits(kAltBits, kAltLength, 0, B_COLOR_8_BIT);
fSuper->DrawBitmap(&control, where);
where.x -= rect.Width() + 1;
}
if (fModifiers & B_SHIFT_KEY) { if (fModifiers & B_SHIFT_KEY) {
BRect rect(0,0,21,10); BRect rect(0,0,21,10);
BBitmap shift(rect, B_COLOR_8_BIT); BBitmap shift(rect, B_COLOR_8_BIT);
+3 -2
View File
@@ -12,8 +12,9 @@
// TODO: Add scrollers // TODO: Add scrollers
#include <Menu.h> #include <Menu.h>
#include <MenuWindow.h>
#include <MenuPrivate.h>
#include <MenuWindow.h>
#include <WindowPrivate.h> #include <WindowPrivate.h>
@@ -96,7 +97,7 @@ BMenuFrame::Draw(BRect updateRect)
font_height height; font_height height;
GetFontHeight(&height); GetFontHeight(&height);
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT));
DrawString("<empty>", BPoint(2, ceilf(height.ascent + 2))); DrawString(kEmptyMenuLabel, BPoint(3, ceilf(height.ascent + 2)));
} }
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));