From 4f9eec722ccbf709057a8c8df2539772ead7199e Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 11 Nov 2012 11:32:30 -0500 Subject: [PATCH 01/66] Add watchpoint capabilities hook to Architecture. Will be used by the watchpoint manager and/or watchpoint UI to present and/or handle the relative limitations of the current platform. --- src/apps/debugger/arch/Architecture.h | 13 ++++++++++++- src/apps/debugger/arch/x86/ArchitectureX86.cpp | 18 +++++++++++++++++- src/apps/debugger/arch/x86/ArchitectureX86.h | 8 ++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/arch/Architecture.h b/src/apps/debugger/arch/Architecture.h index 845af2e2f7..0b8ba3a27d 100644 --- a/src/apps/debugger/arch/Architecture.h +++ b/src/apps/debugger/arch/Architecture.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2011, Rene Gollent, rene@gollent.com. + * Copyright 2011-2012, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef ARCHITECTURE_H @@ -38,6 +38,12 @@ enum { }; +enum { + WATCHPOINT_CAPABILITY_FLAG_READ = 1, + WATCHPOINT_CAPABILITY_FLAG_WRITE = 2 +}; + + class Architecture : public BReferenceable { public: Architecture(TeamMemory* teamMemory, @@ -105,6 +111,11 @@ public: bool useExistingTrace = false); // team is not locked + virtual status_t GetWatchpointDebugCapabilities( + int32& _maxRegisterCount, + uint8& _watchpointCapabilityFlags) = 0; + + protected: TeamMemory* fTeamMemory; uint8 fAddressSize; diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp index 9fd80cfa7a..6cb370b97c 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp +++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2011, Rene Gollent, rene@gollent.com. + * Copyright 2011-2012, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -611,6 +611,22 @@ ArchitectureX86::GetInstructionInfo(target_addr_t address, } +status_t +ArchitectureX86::GetWatchpointDebugCapabilities(int32& _maxRegisterCount, + uint8& _watchpointCapabilityFlags) +{ + // while x86 technically has 4 hardware debug registers, one is reserved by + // the kernel, and one is required for breakpoint support, which leaves + // two available for watchpoints. + _maxRegisterCount = 2; + + // x86 only supports write watchpoints. + _watchpointCapabilityFlags = WATCHPOINT_CAPABILITY_FLAG_WRITE; + + return B_OK; +} + + void ArchitectureX86::_AddRegister(int32 index, const char* name, uint32 bitSize, uint32 valueType, register_type type, bool calleePreserved) diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.h b/src/apps/debugger/arch/x86/ArchitectureX86.h index 33369aa5db..b58be05f75 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.h +++ b/src/apps/debugger/arch/x86/ArchitectureX86.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2011, Rene Gollent, rene@gollent.com. + * Copyright 2011-2012, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef ARCHITECTURE_X86_H @@ -23,7 +23,7 @@ public: virtual status_t Init(); - virtual int32 StackGrowthDirection() const; + virtual int32 StackGrowthDirection() const; virtual int32 CountRegisters() const; virtual const Register* Registers() const; @@ -61,6 +61,10 @@ public: virtual status_t GetInstructionInfo(target_addr_t address, InstructionInfo& _info); + virtual status_t GetWatchpointDebugCapabilities( + int32& _maxRegisterCount, + uint8& _watchpointCapabilityFlags); + private: struct ToDwarfRegisterMap; struct FromDwarfRegisterMap; From 22fc56ce8c63d7b52d6bf2f8e0483413e57e62cd Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 11 Nov 2012 12:03:28 -0500 Subject: [PATCH 02/66] Correct an oversight. Thanks Ingo! --- src/apps/debugger/arch/Architecture.h | 3 ++- src/apps/debugger/arch/x86/ArchitectureX86.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/apps/debugger/arch/Architecture.h b/src/apps/debugger/arch/Architecture.h index 0b8ba3a27d..8d7ed43c60 100644 --- a/src/apps/debugger/arch/Architecture.h +++ b/src/apps/debugger/arch/Architecture.h @@ -40,7 +40,8 @@ enum { enum { WATCHPOINT_CAPABILITY_FLAG_READ = 1, - WATCHPOINT_CAPABILITY_FLAG_WRITE = 2 + WATCHPOINT_CAPABILITY_FLAG_WRITE = 2, + WATCHPOINT_CAPABILITY_FLAG_READ_WRITE = 4 }; diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp index 6cb370b97c..54472477a7 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp +++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp @@ -620,8 +620,9 @@ ArchitectureX86::GetWatchpointDebugCapabilities(int32& _maxRegisterCount, // two available for watchpoints. _maxRegisterCount = 2; - // x86 only supports write watchpoints. - _watchpointCapabilityFlags = WATCHPOINT_CAPABILITY_FLAG_WRITE; + // x86 only supports write and read/write watchpoints. + _watchpointCapabilityFlags = WATCHPOINT_CAPABILITY_FLAG_WRITE + | WATCHPOINT_CAPABILITY_FLAG_READ_WRITE; return B_OK; } From 75b285a9699908edbcab1c081a7c53b7d3b3ca76 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Mon, 12 Nov 2012 18:08:41 +0100 Subject: [PATCH 03/66] ARM: Fix incorrect panic message. As noted during BeGeistert and today again by kallisti5, there's a Pentium reference in the ARM bootloader code. Correct the message to something more appropriate.... Thanks to Rene for the suggestion ;) --- src/system/boot/arch/arm/arch_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/boot/arch/arm/arch_cpu.cpp b/src/system/boot/arch/arm/arch_cpu.cpp index 676191803d..028146b9b5 100644 --- a/src/system/boot/arch/arm/arch_cpu.cpp +++ b/src/system/boot/arch/arm/arch_cpu.cpp @@ -70,7 +70,7 @@ boot_arch_cpu_init(void) status_t err = check_cpu_features(); if (err != B_OK) { - panic("You need a Pentium or higher in order to boot!\n"); + panic("Retire your old Acorn and get something modern to boot!\n"); return err; } From 4b2a1d798b16cff17633e6aedfe99b9992fa30e4 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Mon, 12 Nov 2012 20:03:48 +0100 Subject: [PATCH 04/66] ARM: implement arch_cpu_user_memcpy/memset/strlcpy functions Remove the dummies from the C code and implement them in assembly, due to the label referencing issues with the fault handler. This code is ripe for optimisation, my ARM assembly is pretty basic ;) Does work though, and gets us one step closer to a full arch. --- src/system/kernel/arch/arm/arch_asm.S | 110 ++++++++++++++++++++++ src/system/kernel/arch/arm/arch_cpu.cpp | 116 ------------------------ 2 files changed, 110 insertions(+), 116 deletions(-) diff --git a/src/system/kernel/arch/arm/arch_asm.S b/src/system/kernel/arch/arm/arch_asm.S index c51089c718..eb570a5f90 100644 --- a/src/system/kernel/arch/arm/arch_asm.S +++ b/src/system/kernel/arch/arm/arch_asm.S @@ -94,6 +94,116 @@ FUNCTION(arm_get_far): bx lr FUNCTION_END(arm_get_far) +/* status_t arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *faultHandler) */ +FUNCTION(arch_cpu_user_memcpy): + stmfd sp!, { r4-r6 } + ldr r6, [r3] + ldr r4, =.L_user_memcpy_error + str r4, [r3] /* set fault handler */ + mov r4, r2, lsr #2 /* size / 4 */ +1: + ldr r5, [r1] + str r5, [r0] + add r1, #4 + add r0, #4 + sub r4, #1 + bne 1b +2: + and r4, r2, #3 /* size % 4 */ + ldrb r5, [r1] + strb r5, [r0] + add r1, #1 + add r0, #1 + sub r4, #1 + bne 2b + + str r6, [r3] /* restore fault handler */ + mov r0, #0 + ldmfd sp!, { r4-r6 } + bx lr + +.L_user_memcpy_error: + str r6, [r3] /* restore fault handler */ + mov r0, #-1 + + ldmfd sp!, { r4-r6 } + bx lr +FUNCTION_END(arch_cpu_user_memcpy) + +/* status_t arch_cpu_user_memset(void *to, char c, size_t count, addr_t *faultHandler) */ +FUNCTION(arch_cpu_user_memset): + stmfd sp!, { r4-r5 } + ldr r5, [r3] + ldr r4, =.L_user_memset_error + str r4, [r3] + + and r1, r1, #0xff + add r1, r1, lsl #8 + add r1, r1, lsl #16 + add r1, r1, lsl #24 + + mov r4, r2, lsr #2 /* count / 4 */ +1: + str r1, [r0] + add r0, r0, #4 + sub r4, r4, #1 + bne 1b + + and r4, r2, #3 /* count % 4 */ +2: + strb r1, [r0] + add r0, r0, #1 + sub r4, r4, #1 + bne 2b + + mov r0, #0 + str r5, [r3] + + ldmfd sp!, { r4-r5 } + bx lr + +.L_user_memset_error: + mov r0, #-1 + str r5, [r3] + + ldmfd sp!, { r4-r5 } + bx lr +FUNCTION_END(arch_cpu_user_memset) + +/* ssize_t arch_cpu_user_strlcpy(void *to, const void *from, size_t size, addr_t *faultHandler) */ +FUNCTION(arch_cpu_user_strlcpy): + stmfd sp!, { r4-r6 } + ldr r5, [r3] + ldr r4, =.L_user_strlcpy_error + str r4, [r3] + mov r6, #0 +1: + ldrb r4, [r1, r6] + strb r4, [r0, r6] + add r6, r6, #1 + and r4, #0xff /* done yet? */ + beq 2f + cmp r6, r2 /* reached max length? */ + blt 1b +2: + mov r4, #0 + strb r4, [r0, r6] + + mov r0, r4 /* return B_OK */ + str r5, [r3] /* restore fault handler */ + + ldmfd sp!, { r4-r6 } + bx lr + +.L_user_strlcpy_error: + mov r0, #-1 + str r5, [r3] + + ldmfd sp!, { r4-r6 } + bx lr +FUNCTION_END(arch_cpu_user_strlcpy) + + /*! \fn void arch_debug_call_with_fault_handler(cpu_ent* cpu, jmp_buf jumpBuffer, void (*function)(void*), void* parameter) diff --git a/src/system/kernel/arch/arm/arch_cpu.cpp b/src/system/kernel/arch/arm/arch_cpu.cpp index 65d4795a80..702142766f 100644 --- a/src/system/kernel/arch/arm/arch_cpu.cpp +++ b/src/system/kernel/arch/arm/arch_cpu.cpp @@ -159,119 +159,3 @@ arch_cpu_user_TLB_invalidate(void) */ #warning WRITEME } - - -// TODO: all functions that use fault handlers need to be implemented -// in assembly due to problems passing in label addresses in gcc4. -status_t -arch_cpu_user_memcpy(void *to, const void *from, size_t size, - addr_t *faultHandler) -{ -#warning WRITEME -/* - char *tmp = (char *)to; - char *s = (char *)from; - addr_t oldFaultHandler = *faultHandler; - - if (m68k_set_fault_handler(faultHandler, (addr_t)&&error)) - goto error; - - while (size--) - *tmp++ = *s++; - - *faultHandler = oldFaultHandler; - return 0; - -error: - *faultHandler = oldFaultHandler;*/ - return B_BAD_ADDRESS; -} - - -/** \brief Copies at most (\a size - 1) characters from the string in \a from to - * the string in \a to, NULL-terminating the result. - * - * \param to Pointer to the destination C-string. - * \param from Pointer to the source C-string. - * \param size Size in bytes of the string buffer pointed to by \a to. - * - * \return strlen(\a from). - */ - -ssize_t -arch_cpu_user_strlcpy(char *to, const char *from, - size_t size, addr_t *faultHandler) -{ -#warning WRITEME -/* - int from_length = 0; - addr_t oldFaultHandler = *faultHandler; - - if (m68k_set_fault_handler(faultHandler, (addr_t)&&error)) - goto error; - - if (size > 0) { - to[--size] = '\0'; - // copy - for ( ; size; size--, from_length++, to++, from++) { - if ((*to = *from) == '\0') - break; - } - } - // count any leftover from chars - while (*from++ != '\0') - from_length++; - - *faultHandler = oldFaultHandler; - return from_length; - -error: - *faultHandler = oldFaultHandler;*/ - return B_BAD_ADDRESS; -} - - -status_t -arch_cpu_user_memset(void *s, char c, size_t count, addr_t *faultHandler) -{ -#warning WRITEME - -/* - char *xs = (char *)s; - addr_t oldFaultHandler = *faultHandler; - - if (m68k_set_fault_handler(faultHandler, (addr_t)&&error)) - goto error; - - while (count--) - *xs++ = c; - - *faultHandler = oldFaultHandler; - return 0; - -error: - *faultHandler = oldFaultHandler;*/ - - return B_BAD_ADDRESS; -} - - -// The purpose of this function is to trick the compiler. When setting the -// page_handler to a label that is obviously (to the compiler) never used, -// it may reorganize the control flow, so that the labeled part is optimized -// away. -// By invoking the function like this -// -// if (m68k_set_fault_handler(faultHandler, (addr_t)&&error)) -// goto error; -// -// the compiler has to keep the labeled code, since it can't guess the return -// value of this (non-inlinable) function. At least in my tests it worked that -// way, and I hope it will continue to work like this in the future. -// -/*bool -m68k_set_fault_handler(addr_t *handlerLocation, addr_t handler) -{ - *handlerLocation = handler; - return false; -}*/ From 1e6ae0de3ad774ef86db36636457512cfb4abc4c Mon Sep 17 00:00:00 2001 From: Jerome Duval Date: Mon, 12 Nov 2012 21:00:11 +0100 Subject: [PATCH 05/66] Development: don't link to libs with minor version numbers (for real) * should help with #9126 --- build/jam/HaikuImage | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 1f182c0b8f..b4b6fd85a0 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -335,10 +335,10 @@ SYSTEM_LIBS_ALIASES = ; OPTIONAL_LIBS_ALIASES = - $(HAIKU_FREETYPE_CURRENT_LINK) - $(HAIKU_JPEG_CURRENT_LINK) - $(HAIKU_LIBPNG_CURRENT_LINK) - $(HAIKU_ZLIB_CURRENT_LINK) + libfreetype.so + libjpeg.so + libpng.so + libz.so ; # libfreetype.so links to the current freetype lib From 25a627d8800361c42b1f29bd2f2d29b323e9cc2d Mon Sep 17 00:00:00 2001 From: Jerome Duval Date: Mon, 12 Nov 2012 21:14:43 +0100 Subject: [PATCH 06/66] hda: fixes KDL on HDMI, some digital quirks * avoid crashing in case of lack of playback or record stream * set format on digital output widgets * accept digital output on the output path --- src/add-ons/kernel/drivers/audio/hda/hda_codec.cpp | 1 + src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp | 8 ++++++++ src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/drivers/audio/hda/hda_codec.cpp b/src/add-ons/kernel/drivers/audio/hda/hda_codec.cpp index 0d019fa265..e778ffcbac 100644 --- a/src/add-ons/kernel/drivers/audio/hda/hda_codec.cpp +++ b/src/add-ons/kernel/drivers/audio/hda/hda_codec.cpp @@ -1011,6 +1011,7 @@ TRACE("build output tree: %suse mixer\n", useMixer ? "" : "don't "); int device = CONF_DEFAULT_DEVICE(widget.d.pin.config); if (device != PIN_DEV_HEAD_PHONE_OUT + && device != PIN_DEV_DIGITAL_OTHER_OUT && device != PIN_DEV_SPEAKER && device != PIN_DEV_LINE_OUT) continue; diff --git a/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp b/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp index 6d75b06e1e..2f281c3909 100644 --- a/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp +++ b/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp @@ -770,6 +770,14 @@ hda_stream_setup_buffers(hda_audio_group* audioGroup, hda_stream* stream, hda_send_verbs(codec, verb, response, 2); //channelNum += 2; // TODO stereo widget ? Every output gets the same stream for now dprintf("%ld ", stream->io_widgets[i]); + + hda_widget* widget = hda_audio_group_get_widget(audioGroup, + stream->io_widgets[i]); + if ((widget->capabilities.audio & AUDIO_CAP_DIGITAL) != 0) { + verb[0] = MAKE_VERB(codec->addr, stream->io_widgets[i], + VID_SET_DIGITAL_CONVERTER_CONTROL1, format); + hda_send_verbs(codec, verb, response, 1); + } } dprintf("\n"); diff --git a/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp b/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp index 0c50f8b1b0..6f1a5e273f 100644 --- a/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp +++ b/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp @@ -892,12 +892,14 @@ get_buffers(hda_audio_group* audioGroup, multi_buffer_list* data) || data->return_record_buffers < STREAM_MIN_BUFFERS) data->return_record_buffers = STREAM_MIN_BUFFERS; - if (data->return_playback_buffer_size == 0) { + if (data->return_playback_buffer_size == 0 + && audioGroup->playback_stream != NULL) { data->return_playback_buffer_size = default_buffer_length_for_rate( audioGroup->playback_stream->sample_rate); } - if (data->return_record_buffer_size == 0) { + if (data->return_record_buffer_size == 0 + && audioGroup->record_stream != NULL) { data->return_record_buffer_size = default_buffer_length_for_rate( audioGroup->record_stream->sample_rate); } From a2f6e5ac9c3f022f1c2afb29e6cc616e08d3adca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 12 Nov 2012 23:48:45 +0100 Subject: [PATCH 07/66] Added missing BMessage::{Get|Set}String() methods. * Forgot to add those before accidentally. --- headers/os/app/Message.h | 3 +++ src/kits/app/Message.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/headers/os/app/Message.h b/headers/os/app/Message.h index c4c72dfc00..bb3a74d671 100644 --- a/headers/os/app/Message.h +++ b/headers/os/app/Message.h @@ -475,6 +475,9 @@ public: status_t SetInt64(const char* name, int64 value); status_t SetUInt64(const char* name, uint64 value); status_t SetPointer(const char* name, const void* value); + status_t SetString(const char* name, const char* string); + status_t SetString(const char* name, + const BString& string); status_t SetFloat(const char* name, float value); status_t SetDouble(const char* name, double value); status_t SetAlignment(const char* name, diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index 09bf7e4d91..36db0779ad 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -2564,6 +2564,7 @@ DEFINE_SET_GET_FUNCTIONS(uint64, UInt64, B_UINT64_TYPE); DEFINE_SET_GET_FUNCTIONS(bool, Bool, B_BOOL_TYPE); DEFINE_SET_GET_FUNCTIONS(float, Float, B_FLOAT_TYPE); DEFINE_SET_GET_FUNCTIONS(double, Double, B_DOUBLE_TYPE); +DEFINE_SET_GET_FUNCTIONS(const char *, String, B_STRING_TYPE); #undef DEFINE_SET_GET_FUNCTION @@ -3135,6 +3136,13 @@ BMessage::HasFlat(const char *name, int32 index, const BFlattenable *object) } +status_t +BMessage::SetString(const char *name, const BString& value) +{ + return SetData(name, B_STRING_TYPE, value.String(), value.Length() + 1); +} + + status_t BMessage::SetData(const char* name, type_code type, const void* data, ssize_t numBytes) From b20073726af5c47239330deb359d63c75df2da58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 12 Nov 2012 23:49:38 +0100 Subject: [PATCH 08/66] Added BEntry::Name() method. * GetName() is a bad API, and should be deprecated. --- headers/os/storage/Entry.h | 4 +++- src/kits/storage/Entry.cpp | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/headers/os/storage/Entry.h b/headers/os/storage/Entry.h index f0c628e49e..60a5a56179 100644 --- a/headers/os/storage/Entry.h +++ b/headers/os/storage/Entry.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2012, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _ENTRY_H @@ -50,6 +50,8 @@ public: status_t InitCheck() const; bool Exists() const; + const char* Name() const; + virtual status_t GetStat(struct stat* stat) const; status_t SetTo(const BDirectory* dir, const char* path, diff --git a/src/kits/storage/Entry.cpp b/src/kits/storage/Entry.cpp index 7ff8715695..d04038fd38 100644 --- a/src/kits/storage/Entry.cpp +++ b/src/kits/storage/Entry.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku Inc. + * Copyright 2002-2012, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -191,6 +191,16 @@ BEntry::Exists() const } +const char* +BEntry::Name() const +{ + if (fCStatus != B_OK) + return NULL; + + return fName; +} + + status_t BEntry::SetTo(const BDirectory* dir, const char* path, bool traverse) { @@ -360,18 +370,13 @@ BEntry::GetParent(BDirectory* dir) const status_t BEntry::GetName(char* buffer) const { - status_t result = B_ERROR; + if (fCStatus != B_OK) + return B_NO_INIT; + if (buffer == NULL) + return B_BAD_VALUE; - if (fCStatus != B_OK) { - result = B_NO_INIT; - } else if (buffer == NULL) { - result = B_BAD_VALUE; - } else { - strcpy(buffer, fName); - result = B_OK; - } - - return result; + strcpy(buffer, fName); + return B_OK; } From 5f78788af97122fa9af398364a21e89027529600 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Tue, 13 Nov 2012 00:42:45 +0100 Subject: [PATCH 09/66] ARM: Initial work on a NOR flash driver Currently hardcoded to Verdex target. Code prepared to pick up configuration details from FDT when implemented. Only enabled in FloppyImage for ARM. This actually enables the kernel to read the content of the image file passed using the "-pflash" parameter to QEMU.... --- build/jam/FloppyBootImage | 6 +- src/add-ons/kernel/drivers/disk/Jamfile | 1 + .../kernel/drivers/disk/norflash/Jamfile | 10 + .../kernel/drivers/disk/norflash/norflash.cpp | 297 ++++++++++++++++++ 4 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 src/add-ons/kernel/drivers/disk/norflash/Jamfile create mode 100644 src/add-ons/kernel/drivers/disk/norflash/norflash.cpp diff --git a/build/jam/FloppyBootImage b/build/jam/FloppyBootImage index ea05ca505b..3c792844a7 100644 --- a/build/jam/FloppyBootImage +++ b/build/jam/FloppyBootImage @@ -3,12 +3,15 @@ local X86_ONLY = ; local PPC_ONLY = ; +local ARM_ONLY = ; if $(TARGET_ARCH) = x86 { X86_ONLY = "" ; } else if $(TARGET_ARCH) = ppc { X86_ONLY = ; } else if $(TARGET_ARCH) = m68k { X86_ONLY = ; +} else if $(TARGET_ARCH) = arm { + ARM_ONLY = "" ; } local GPL_ONLY = ; @@ -80,6 +83,7 @@ if $(TARGET_ARCH) = x86 { # drivers AddNewDriversToFloppyBootArchive disk scsi : scsi_cd scsi_disk ; +AddNewDriversToFloppyBootArchive disk : $(ARM_ONLY)norflash ; if $(USB_BOOT) = 1 { AddDriversToFloppyBootArchive disk usb : usb_disk ; } @@ -122,7 +126,7 @@ AddBootModuleSymlinksToFloppyBootArchive ahci generic_ide_pci $(X86_ONLY)ide_isa silicon_image_3112 legacy_sata it8211 $(USB_ONLY)uhci $(USB_ONLY)ohci $(USB_ONLY)ehci - scsi_cd scsi_disk $(USB_ONLY)usb_disk + scsi_cd scsi_disk $(USB_ONLY)usb_disk $(ARM_ONLY)norflash intel session $(SYSTEM_ADD_ONS_FILE_SYSTEMS) $(BOOT_ADD_ONS_NET) diff --git a/src/add-ons/kernel/drivers/disk/Jamfile b/src/add-ons/kernel/drivers/disk/Jamfile index 989aa4d3b9..d6ce88a04a 100644 --- a/src/add-ons/kernel/drivers/disk/Jamfile +++ b/src/add-ons/kernel/drivers/disk/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src add-ons kernel drivers disk ; SubInclude HAIKU_TOP src add-ons kernel drivers disk floppy ; +SubInclude HAIKU_TOP src add-ons kernel drivers disk norflash ; SubInclude HAIKU_TOP src add-ons kernel drivers disk scsi ; SubInclude HAIKU_TOP src add-ons kernel drivers disk usb ; SubInclude HAIKU_TOP src add-ons kernel drivers disk virtual ; diff --git a/src/add-ons/kernel/drivers/disk/norflash/Jamfile b/src/add-ons/kernel/drivers/disk/norflash/Jamfile new file mode 100644 index 0000000000..2294d8d5bc --- /dev/null +++ b/src/add-ons/kernel/drivers/disk/norflash/Jamfile @@ -0,0 +1,10 @@ +SubDir HAIKU_TOP src add-ons kernel drivers disk norflash ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +UsePrivateHeaders drivers kernel ; + +KernelAddon norflash : + norflash.cpp +; + diff --git a/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp b/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp new file mode 100644 index 0000000000..a15db376c5 --- /dev/null +++ b/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp @@ -0,0 +1,297 @@ +/* + * Copyright 2012, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ithamar R. Adema + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +//#define TRACE_NORFLASH +#ifdef TRACE_NORFLASH +#define TRACE(x...) dprintf("nor: " x) +#else +#define TRACE(x...) +#endif + +#define NORFLASH_DEVICE_MODULE_NAME "drivers/disk/norflash/device_v1" +#define NORFLASH_DRIVER_MODULE_NAME "drivers/disk/norflash/driver_v1" + +#define NORFLASH_ADDR 0x00000000 + +struct nor_driver_info { + device_node *node; + size_t blocksize; + size_t totalsize; + + area_id id; + void *mapped; +}; + +static device_manager_info* sDeviceManager; + +static const char *sTabTab = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; +#define DS "%.*s" +#define DA depth - 1, sTabTab + +static void +dump_hex(const char *data, int32 len, int depth = 1) +{ + char str[128]; + char astr[32]; + char *p; + int l; + int i; + + for (i = 0; i < len; ) { + p = str; + l = sizeof(str); + for (; i < len && (p == str || (i % 16 != 0)); i++) { + snprintf(p, l - 1, "%02x ", data[i]); + l -= strlen(p); + p += strlen(p); + astr[i % 16] = isprint(data[i]) ? data[i] : '.'; + astr[i % 16] = isprint(data[i]) ? data[i] : '.'; + astr[(i % 16) + 1] = '\0'; + } + dprintf(DS" %-48.48s %s\n", DA, str, astr); + } +} + + +static status_t +nor_init_device(void* _info, void** _cookie) +{ + TRACE("init_device\n"); + nor_driver_info* info = (nor_driver_info*)_info; + + info->mapped = NULL; + info->blocksize = 128 * 1024; + info->totalsize = info->blocksize * 256; + + info->id = map_physical_memory("NORFlash", NORFLASH_ADDR, info->totalsize, B_ANY_KERNEL_ADDRESS, B_READ_AREA, &info->mapped); + if (info->id < 0) + return info->id; + + *_cookie = info; + return B_OK; +} + + +static void +nor_uninit_device(void* _cookie) +{ + TRACE("uninit_device\n"); + nor_driver_info* info = (nor_driver_info*)_cookie; + if (info) + delete_area(info->id); +} + + +static status_t +nor_open(void *deviceCookie, const char *path, int openMode, + void **_cookie) +{ + TRACE("open(%s)\n", path); + *_cookie = deviceCookie; + return B_OK; +} + + +static status_t +nor_close(void *_cookie) +{ + TRACE("close()\n"); + return B_OK; +} + + +static status_t +nor_free(void *_cookie) +{ + TRACE("free()\n"); + return B_OK; +} + + +static status_t +nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length) +{ + nor_driver_info* info = (nor_driver_info*)cookie; + TRACE("ioctl(%ld,%lu)\n", op, length); + + switch(op) { + case B_GET_GEOMETRY: + { + device_geometry *deviceGeometry = (device_geometry*)buffer; + deviceGeometry->removable = false; + deviceGeometry->bytes_per_sector = info->blocksize; + deviceGeometry->sectors_per_track = info->totalsize / info->blocksize; + deviceGeometry->cylinder_count = 1; + deviceGeometry->head_count = 1; + deviceGeometry->device_type = B_DISK; + deviceGeometry->removable = false; + deviceGeometry->read_only = true; + deviceGeometry->write_once = false; + return B_OK; + } + break; + case B_GET_DEVICE_NAME: + strlcpy((char*)buffer, "NORFlash", length); + break; + } + + return B_ERROR; +} + + +static status_t +nor_read(void *_cookie, off_t position, void *data, size_t *numbytes) +{ + nor_driver_info* info = (nor_driver_info*)_cookie; + TRACE("read(%Ld,%lu)\n", position, *numbytes); + + if (position + *numbytes > info->totalsize) + *numbytes = info->totalsize - (position + *numbytes); + + memcpy(data, info->mapped + position, *numbytes); + +#ifdef TRACE_NORFLASH + dump_hex((const char*)(info->mapped + position), *numbytes, 1); +#endif + + return B_OK; +} + + +static status_t +nor_write(void *_cookie, off_t position, const void *data, size_t *numbytes) +{ + TRACE("write(%Ld,%lu)\n", position, *numbytes); + *numbytes = 0; + return B_ERROR; +} + + +static float +nor_supports_device(device_node *parent) +{ + TRACE("supports_device\n"); + return 0.6; +} + + +static status_t +nor_register_device(device_node *node) +{ + TRACE("register_device\n"); + // ready to register + device_attr attrs[] = { + { NULL } + }; + + return sDeviceManager->register_node(node, NORFLASH_DRIVER_MODULE_NAME, + attrs, NULL, NULL); +} + + +static status_t +nor_init_driver(device_node *node, void **cookie) +{ + TRACE("init_driver\n"); + + nor_driver_info* info = (nor_driver_info*)malloc(sizeof(nor_driver_info)); + if (info == NULL) + return B_NO_MEMORY; + + memset(info, 0, sizeof(*info)); + + info->node = node; + + *cookie = info; + return B_OK; +} + + +static void +nor_uninit_driver(void *_cookie) +{ + TRACE("uninit_driver\n"); + nor_driver_info* info = (nor_driver_info*)_cookie; + free(info); +} + + +static status_t +nor_register_child_devices(void* _cookie) +{ + TRACE("register_child_devices\n"); + nor_driver_info* info = (nor_driver_info*)_cookie; + status_t status; + + status = sDeviceManager->publish_device(info->node, "disk/nor/0/raw", + NORFLASH_DEVICE_MODULE_NAME); + + return status; +} + +struct device_module_info sNORFlashDiskDevice = { + { + NORFLASH_DEVICE_MODULE_NAME, + 0, + NULL + }, + + nor_init_device, + nor_uninit_device, + NULL, //nor_remove, + + nor_open, + nor_close, + nor_free, + nor_read, + nor_write, + NULL, // nor_io, + nor_ioctl, + + NULL, // select + NULL, // deselect +}; + + + +struct driver_module_info sNORFlashDiskDriver = { + { + NORFLASH_DRIVER_MODULE_NAME, + 0, + NULL + }, + + nor_supports_device, + nor_register_device, + nor_init_driver, + nor_uninit_driver, + nor_register_child_devices, + NULL, // rescan + NULL, // removed +}; + +module_dependency module_dependencies[] = { + { B_DEVICE_MANAGER_MODULE_NAME, (module_info**)&sDeviceManager }, + { } +}; + +module_info* modules[] = { + (module_info*)&sNORFlashDiskDriver, + (module_info*)&sNORFlashDiskDevice, + NULL +}; From 6be4555f928cf3287544a0a7e0ba63de45b85fff Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 12 Nov 2012 20:22:15 -0500 Subject: [PATCH 10/66] Also report back the number of bytes each register can watch. --- src/apps/debugger/arch/Architecture.h | 1 + src/apps/debugger/arch/x86/ArchitectureX86.cpp | 3 ++- src/apps/debugger/arch/x86/ArchitectureX86.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/apps/debugger/arch/Architecture.h b/src/apps/debugger/arch/Architecture.h index 8d7ed43c60..998d3be7f4 100644 --- a/src/apps/debugger/arch/Architecture.h +++ b/src/apps/debugger/arch/Architecture.h @@ -114,6 +114,7 @@ public: virtual status_t GetWatchpointDebugCapabilities( int32& _maxRegisterCount, + int32& _maxBytesPerRegister, uint8& _watchpointCapabilityFlags) = 0; diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.cpp b/src/apps/debugger/arch/x86/ArchitectureX86.cpp index 54472477a7..bc2e075684 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.cpp +++ b/src/apps/debugger/arch/x86/ArchitectureX86.cpp @@ -613,12 +613,13 @@ ArchitectureX86::GetInstructionInfo(target_addr_t address, status_t ArchitectureX86::GetWatchpointDebugCapabilities(int32& _maxRegisterCount, - uint8& _watchpointCapabilityFlags) + int32& _maxBytesPerRegister, uint8& _watchpointCapabilityFlags) { // while x86 technically has 4 hardware debug registers, one is reserved by // the kernel, and one is required for breakpoint support, which leaves // two available for watchpoints. _maxRegisterCount = 2; + _maxBytesPerRegister = 4; // x86 only supports write and read/write watchpoints. _watchpointCapabilityFlags = WATCHPOINT_CAPABILITY_FLAG_WRITE diff --git a/src/apps/debugger/arch/x86/ArchitectureX86.h b/src/apps/debugger/arch/x86/ArchitectureX86.h index b58be05f75..48e849c502 100644 --- a/src/apps/debugger/arch/x86/ArchitectureX86.h +++ b/src/apps/debugger/arch/x86/ArchitectureX86.h @@ -63,6 +63,7 @@ public: virtual status_t GetWatchpointDebugCapabilities( int32& _maxRegisterCount, + int32& _maxBytesPerRegister, uint8& _watchpointCapabilityFlags); private: From 5ad155d720823ffacbab56f4dff94f41d32d60d4 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 12 Nov 2012 20:22:47 -0500 Subject: [PATCH 11/66] Use Architecture information in WatchPromptWindow. - We now check what types of watchpoints the target CPU supports and limit the UI accordingly. --- .../gui/team_window/TeamWindow.cpp | 5 ++- .../gui/team_window/WatchPromptWindow.cpp | 42 +++++++++++++++---- .../gui/team_window/WatchPromptWindow.h | 11 +++-- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp index 862895233b..9042ff3e16 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp @@ -261,8 +261,9 @@ TeamWindow::MessageReceived(BMessage* message) } try { - WatchPromptWindow* window = WatchPromptWindow::Create(address, - type, length, fListener); + WatchPromptWindow* window = WatchPromptWindow::Create( + fTeam->GetArchitecture(), address, type, length, + fListener); window->Show(); } catch (...) { // TODO: notify user diff --git a/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.cpp index 2718ce80ff..8464582e1f 100644 --- a/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.cpp @@ -15,38 +15,43 @@ #include +#include "Architecture.h" #include "MessageCodes.h" #include "UserInterface.h" #include "Watchpoint.h" -WatchPromptWindow::WatchPromptWindow(target_addr_t address, uint32 type, - int32 length, UserInterfaceListener* listener) +WatchPromptWindow::WatchPromptWindow(Architecture* architecture, + target_addr_t address, uint32 type, int32 length, + UserInterfaceListener* listener) : BWindow(BRect(), "Edit Watchpoint", B_FLOATING_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fInitialAddress(address), fInitialType(type), fInitialLength(length), + fArchitecture(architecture), fAddressInput(NULL), fLengthInput(NULL), fTypeField(NULL), fListener(listener) { + fArchitecture->AcquireReference(); } WatchPromptWindow::~WatchPromptWindow() { + fArchitecture->ReleaseReference(); } WatchPromptWindow* -WatchPromptWindow::Create(target_addr_t address, uint32 type, int32 length, - UserInterfaceListener* listener) +WatchPromptWindow::Create(Architecture* architecture, target_addr_t address, + uint32 type, int32 length, UserInterfaceListener* listener) { - WatchPromptWindow* self = new WatchPromptWindow(address, type, length, - listener); + WatchPromptWindow* self = new WatchPromptWindow(architecture, address, + type, length, listener); try { self->_Init(); @@ -69,10 +74,29 @@ WatchPromptWindow::_Init() text.SetToFormat("%" B_PRId32, fInitialLength); fLengthInput = new BTextControl("Length:", text, NULL); + int32 maxDebugRegisters = 0; + int32 maxBytesPerRegister = 0; + uint8 debugCapabilityFlags = 0; + fArchitecture->GetWatchpointDebugCapabilities(maxDebugRegisters, + maxBytesPerRegister, debugCapabilityFlags); + BMenu* typeMenu = new BMenu("Watch Type"); - typeMenu->AddItem(new BMenuItem("Read", NULL)); - typeMenu->AddItem(new BMenuItem("Write", NULL)); - typeMenu->AddItem(new BMenuItem("Read/Write", NULL)); + + BMenuItem* watchTypeItem = new BMenuItem("Read", NULL); + watchTypeItem->SetEnabled( + (debugCapabilityFlags & WATCHPOINT_CAPABILITY_FLAG_READ) != 0); + typeMenu->AddItem(watchTypeItem); + + watchTypeItem = new BMenuItem("Write", NULL); + watchTypeItem->SetEnabled( + (debugCapabilityFlags & WATCHPOINT_CAPABILITY_FLAG_WRITE) != 0); + typeMenu->AddItem(watchTypeItem); + + watchTypeItem = new BMenuItem("Read/Write", NULL); + watchTypeItem->SetEnabled( + (debugCapabilityFlags & WATCHPOINT_CAPABILITY_FLAG_READ_WRITE) != 0); + typeMenu->AddItem(watchTypeItem); + fTypeField = new BMenuField("Type:", typeMenu); BLayoutItem* labelItem = fTypeField->CreateLabelLayoutItem(); labelItem->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); diff --git a/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.h b/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.h index 465fdd696c..5854ca8e4e 100644 --- a/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.h +++ b/src/apps/debugger/user_interface/gui/team_window/WatchPromptWindow.h @@ -11,6 +11,7 @@ #include "types/Types.h" +class Architecture; class BTextControl; class Watchpoint; class BMenuField; @@ -20,14 +21,15 @@ class UserInterfaceListener; class WatchPromptWindow : public BWindow { public: - // edit existing watchpoint - WatchPromptWindow(target_addr_t address, - uint32 type, int32 length, + WatchPromptWindow(Architecture* architecture, + target_addr_t address, uint32 type, + int32 length, UserInterfaceListener* listener); ~WatchPromptWindow(); - static WatchPromptWindow* Create(target_addr_t address, uint32 type, + static WatchPromptWindow* Create(Architecture* architecture, + target_addr_t address, uint32 type, int32 length, UserInterfaceListener* listener); // throws @@ -45,6 +47,7 @@ private: target_addr_t fInitialAddress; uint32 fInitialType; int32 fInitialLength; + Architecture* fArchitecture; BTextControl* fAddressInput; BTextControl* fLengthInput; BMenuField* fTypeField; From cb55ef9fb597a3f3bc91e53017360b18b20dd27b Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 27 Jun 2011 22:24:55 -0400 Subject: [PATCH 12/66] WIP: Created a BScrollMenu class that works like BMenuWindow but works on a view instead of a window. Use this to implement a scrollable BarMenuBar in Deskbar. The basics work but there are issues still with sizing and other issues. Modify the ScrollMenu class to use the layout kit by adding a constructor that doesn't take a view. Get the BScrollMenu class to follow the size of the BMenu it is a parent of. Adjust the scrollers to appear in the right places. This is a WIP but it works in Deskbar, next step is to integrate this directly into BMenu with the scrollers as children of the menu instead of as children of the BScroller class. Rebase changes on top of master Deskbar scrolling works for the most part, just need to fix the bottom arrow and clean up a bit. --- headers/os/interface/ScrollMenu.h | 55 ++++ src/apps/deskbar/BarView.cpp | 36 ++- src/apps/deskbar/BarView.h | 3 +- src/apps/deskbar/ExpandoMenuBar.cpp | 19 +- src/apps/deskbar/TeamMenuItem.cpp | 24 +- src/kits/interface/Jamfile | 1 + src/kits/interface/Menu.cpp | 12 +- src/kits/interface/MenuBar.cpp | 32 +- src/kits/interface/ScrollMenu.cpp | 436 ++++++++++++++++++++++++++++ 9 files changed, 580 insertions(+), 38 deletions(-) create mode 100644 headers/os/interface/ScrollMenu.h create mode 100644 src/kits/interface/ScrollMenu.cpp diff --git a/headers/os/interface/ScrollMenu.h b/headers/os/interface/ScrollMenu.h new file mode 100644 index 0000000000..4bb14f2981 --- /dev/null +++ b/headers/os/interface/ScrollMenu.h @@ -0,0 +1,55 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Marc Flerackers (mflerackers@androme.be) + * Stefano Ceccherini (stefano.ceccherini@gmail.com) + * John Scipione (jscipione@gmail.com) + */ +#ifndef SCROLL_MENU_H +#define SCROLL_MENU_H + + +#include + +class BLayout; +class BMenu; +class BMenuScroller; + + +class BScrollMenu : public BView { +public: + BScrollMenu(BMenu* menu); + virtual ~BScrollMenu(); + + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void Draw(BRect updateRect); + virtual void FrameResized(float newWidth, float newHeight); + + void AttachScrollers(); + void DetachScrollers(); + bool HasScrollers() const; + + void SetSmallStep(float step); + void GetSteps(float* _smallStep, float* _largeStep) const; + bool CheckForScrolling(const BPoint& cursor); + bool TryScrollBy(const float& step); + +protected: + bool _Scroll(const BPoint& cursor); + void _ScrollBy(const float& step); + +private: + BMenu* fMenu; + BMenuScroller* fUpperScroller; + BMenuScroller* fLowerScroller; + + float fScrollStep; + float fValue; + float fLimit; +}; + + +#endif // SCROLL_MENU_H diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 0bc16d2f6f..f874bd1536 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -48,6 +48,7 @@ All rights reserved. #include #include #include +#include #include #include "icons.h" @@ -130,6 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, uint32 state, float) : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), + fBarScrollMenu(NULL), fBarMenuBar(NULL), fExpando(NULL), fTrayLocation(1), @@ -347,8 +349,7 @@ TBarView::MouseDown(BPoint where) void TBarView::PlaceDeskbarMenu() { - // top or bottom, full - if (!fVertical && fBarMenuBar) { + if (!fVertical && fBarMenuBar != NULL) { fBarMenuBar->RemoveSelf(); delete fBarMenuBar; fBarMenuBar = NULL; @@ -367,12 +368,13 @@ TBarView::PlaceDeskbarMenu() // if there isn't a bemenu at this point, // DB should be in top/bottom mode, else error - if (!fBarMenuBar) + if (fBarMenuBar == NULL) return; float width = sMinimumWindowWidth; BPoint loc(B_ORIGIN); BRect menuFrame(fBarMenuBar->Frame()); + if (fState == kFullState) { fBarMenuBar->RemoveTeamMenu(); // TODO: Magic constants need explanation @@ -441,22 +443,22 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - if (fExpando != NULL) { - SaveExpandedItems(); + if (fBarScrollMenu != NULL) { + fBarScrollMenu->RemoveSelf(); + delete fBarScrollMenu; + // Also deletes fExpando + fBarScrollMenu = NULL; + fExpando = NULL; + } else if (fExpando != NULL) { fExpando->RemoveSelf(); delete fExpando; fExpando = NULL; } - BRect screenFrame = (BScreen(Window())).Frame(); - if (fState == kMiniState) { - SizeWindow(screenFrame); - PositionWindow(screenFrame); - Window()->UpdateIfNeeded(); - Invalidate(); + if (fState == kMiniState) return; - } + BRect screenFrame = (BScreen(Window())).Frame(); BRect expandoFrame(0, 0, 0, 0); if (fVertical) { // top left/right @@ -485,7 +487,13 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - AddChild(fExpando); + + if (fVertical) { + fBarScrollMenu = new BScrollMenu(fExpando); + AddChild(fBarScrollMenu); +//printf("fExpando bottom: %f, fBarScrollMenu bottom: %f\n", fExpando->Frame().bottom, fBarScrollMenu->Frame().bottom); + } else + AddChild(fExpando); if (fVertical) ExpandItems(); @@ -522,7 +530,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) } else if (fState == kExpandoState) { if (fVertical) { // top left or right - windowHeight = fExpando->Frame().bottom; + windowHeight = fBarScrollMenu->Frame().bottom; } else { // top or bottom, full fExpando->CheckItemSizes(0); diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index f375c872d4..e8e87ba95b 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -65,7 +65,7 @@ const float kStatusHeight = 22.0f; const float kHiddenDimension = 1.0f; const float kMaxPreventHidingDist = 80.0f; - +class BScrollMenu; class BShelf; class TBarMenuBar; class TExpandoMenuBar; @@ -168,6 +168,7 @@ class TBarView : public BView { void ExpandItems(); void _ChangeState(BMessage* message); + BScrollMenu* fBarScrollMenu; TBarMenuBar* fBarMenuBar; TExpandoMenuBar* fExpando; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 15d724fd58..f9cfbb86dc 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -45,6 +45,7 @@ All rights reserved. #include #include #include +#include #include "icons.h" @@ -797,10 +798,22 @@ TExpandoMenuBar::DrawBackground(BRect) void TExpandoMenuBar::CheckForSizeOverrun() { - BRect screenFrame = (BScreen(Window())).Frame(); + if (!fVertical) { + fIsScrolling = false; + return; + } - fIsScrolling = fVertical ? Window()->Frame().bottom > screenFrame.bottom - : false; + BScrollMenu* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu == NULL) + return; + + BRect screenFrame = (BScreen(Window())).Frame(); + fIsScrolling = Window()->Frame().bottom > screenFrame.bottom; + + if (fIsScrolling) + scrollMenu->AttachScrollers(); + else + scrollMenu->DetachScrollers(); } diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index 5b7900f244..35ab7ff65c 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -479,8 +479,7 @@ TTeamMenuItem::DrawContentLabel() if (Submenu() && fVertical) cachedWidth += 18; - const char* label = Label(); - char* truncLabel = NULL; + BString label(Label()); float max = 0; if (fVertical && static_cast(be_app)->Settings()->superExpando) @@ -492,30 +491,23 @@ TTeamMenuItem::DrawContentLabel() BPoint penloc = menu->PenLocation(); BRect frame = Frame(); float offset = penloc.x - frame.left; - if (cachedWidth + offset > max) { - truncLabel = (char*)malloc(strlen(label) + 4); - if (!truncLabel) - return; - TruncateLabel(max-offset, truncLabel); - label = truncLabel; - } + if (cachedWidth + offset > max) + menu->TruncateString(&label, B_TRUNCATE_MIDDLE, max - offset); } if (!label) - label = Label(); + label = BString(Label()); - TBarView* barview = (static_cast(be_app))->BarView(); - bool canHandle = !barview->Dragging() - || barview->AppCanHandleTypes(Signature()); + TBarView* barView = (static_cast(be_app))->BarView(); + bool canHandle = !barView->Dragging() + || barView->AppCanHandleTypes(Signature()); if (_IsSelected() && IsEnabled() && canHandle) menu->SetLowColor(tint_color(menu->LowColor(), B_HIGHLIGHT_BACKGROUND_TINT)); else menu->SetLowColor(menu->LowColor()); - menu->DrawString(label); - - free(truncLabel); + menu->DrawString(label.String()); } diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index 81c59e0b32..4109585a2f 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -101,6 +101,7 @@ MergeObject interface_kit.o : RegionSupport.cpp Screen.cpp ScrollBar.cpp + ScrollMenu.cpp ScrollView.cpp SeparatorItem.cpp SeparatorView.cpp diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 6905c15605..cde95056fe 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -2811,13 +2812,18 @@ BMenu::_ChooseTrigger(const char* title, int32& index, uint32& trigger, void BMenu::_UpdateWindowViewSize(const bool &move) { + if (dynamic_cast(this) != NULL) { + BScrollMenu* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu != NULL) + scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); + + return; + } + BMenuWindow* window = static_cast(Window()); if (window == NULL) return; - if (dynamic_cast(this) != NULL) - return; - if (!fResizeToFit) return; diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index b29f9d5ef5..ee2e978b8f 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -328,7 +329,36 @@ BMenuBar::Draw(BRect updateRect) void BMenuBar::MessageReceived(BMessage* msg) { - BMenu::MessageReceived(msg); + switch (msg->what) { + case B_MOUSE_WHEEL_CHANGED: + { + float deltaY = 0; + msg->FindFloat("be:wheel_delta_y", &deltaY); + if (deltaY == 0) + return; + + BScrollMenu* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu == NULL) + return; + + float largeStep; + float smallStep; + scrollMenu->GetSteps(&smallStep, &largeStep); + + // pressing the option/command/control key scrolls faster + if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) + deltaY *= largeStep; + else + deltaY *= smallStep; + + scrollMenu->TryScrollBy(deltaY); + break; + } + + default: + BMenu::MessageReceived(msg); + break; + } } diff --git a/src/kits/interface/ScrollMenu.cpp b/src/kits/interface/ScrollMenu.cpp new file mode 100644 index 0000000000..2923f01dc7 --- /dev/null +++ b/src/kits/interface/ScrollMenu.cpp @@ -0,0 +1,436 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Marc Flerackers (mflerackers@androme.be) + * Stefano Ceccherini (stefano.ceccherini@gmail.com) + * John Scipione (jscipione@gmail.com) + */ + + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + + +const char* kEmptyMenuLabel = ""; +const int kDefaultScrollStep = 19; +const int kScrollerHeight = 12; + + +class BMenuScroller : public BView { +public: + BMenuScroller(BRect frame); + virtual ~BMenuScroller(); + + bool IsEnabled() const { return fEnabled; }; + void SetEnabled(bool enabled); + +private: + bool fEnabled; +}; + + +class BMenuUpScroller : public BMenuScroller { +public: + BMenuUpScroller(BRect frame); + virtual ~BMenuUpScroller(); + + virtual void Draw(BRect updateRect); +}; + + +class BMenuDownScroller : public BMenuScroller { +public: + BMenuDownScroller(BRect frame); + virtual ~BMenuDownScroller(); + + virtual void Draw(BRect updateRect); +}; + + +// #pragma mark - + + +BMenuScroller::BMenuScroller(BRect frame) + : + BView(frame, "menu scroll arrow", 0, B_WILL_DRAW | B_FRAME_EVENTS), + fEnabled(false) +{ + SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); +} + + +BMenuScroller::~BMenuScroller() +{ +} + + +void +BMenuScroller::SetEnabled(bool enabled) +{ + fEnabled = enabled; + Invalidate(); +} + + +// #pragma mark - + + +BMenuUpScroller::BMenuUpScroller(BRect frame) + : + BMenuScroller(frame) +{ +} + + +BMenuUpScroller::~BMenuUpScroller() +{ +} + + +void +BMenuUpScroller::Draw(BRect updateRect) +{ + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + + // Draw the upper arrow. + if (IsEnabled()) + SetHighColor(0, 0, 0); + else { + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + } + + FillRect(Bounds(), B_SOLID_LOW); + + float middle = Bounds().right / 2; + FillTriangle(BPoint(middle, (kScrollerHeight / 2) - 3), + BPoint(middle + 5, (kScrollerHeight / 2) + 2), + BPoint(middle - 5, (kScrollerHeight / 2) + 2)); +} + + +// #pragma mark - + + +BMenuDownScroller::BMenuDownScroller(BRect frame) + : + BMenuScroller(frame) +{ +} + + +BMenuDownScroller::~BMenuDownScroller() +{ +} + + +void +BMenuDownScroller::Draw(BRect updateRect) +{ + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + + // Draw the lower arrow. + if (IsEnabled()) + SetHighColor(0, 0, 0); + else { + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + } + + BRect frame = Bounds(); + FillRect(frame, B_SOLID_LOW); + + float middle = Bounds().right / 2; + FillTriangle(BPoint(middle, frame.bottom - (kScrollerHeight / 2) + 3), + BPoint(middle + 5, frame.bottom - (kScrollerHeight / 2) - 2), + BPoint(middle - 5, frame.bottom - (kScrollerHeight / 2) - 2)); +} + + +// #pragma mark - + + +BScrollMenu::BScrollMenu(BMenu *menu) + : + BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS), + fMenu(menu), + fUpperScroller(NULL), + fLowerScroller(NULL), + fScrollStep(kDefaultScrollStep) +{ +} + + +BScrollMenu::~BScrollMenu() +{ + if (fMenu != NULL) { + fMenu->RemoveSelf(); + delete fMenu; + fMenu = NULL; + } + + if (fUpperScroller != NULL) { + fUpperScroller->RemoveSelf(); + delete fUpperScroller; + fUpperScroller = NULL; + } + + if (fLowerScroller != NULL) { + fLowerScroller->RemoveSelf(); + delete fLowerScroller; + fLowerScroller = NULL; + } +} + + +void +BScrollMenu::AttachedToWindow() +{ + BView::AttachedToWindow(); + + if (fMenu == NULL) + return; + + AddChild(fMenu); + + // Move the scroll menu into the right position + MoveTo(fMenu->Frame().LeftTop()); + + BFont font; + fMenu->GetFont(&font); + SetFont(&font); +} + + +void +BScrollMenu::DetachedFromWindow() +{ + BView::DetachedFromWindow(); + + if (fMenu != NULL) + fMenu->RemoveSelf(); + + if (fUpperScroller != NULL) + fUpperScroller->RemoveSelf(); + + if (fLowerScroller != NULL) + fLowerScroller->RemoveSelf(); +} + + +void +BScrollMenu::Draw(BRect updateRect) +{ + if (be_control_look != NULL) + return; + + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); + BRect bounds(Bounds()); + + StrokeLine(BPoint(bounds.right, bounds.top), + BPoint(bounds.right, bounds.bottom - 1)); + StrokeLine(BPoint(bounds.left + 1, bounds.bottom), + BPoint(bounds.right, bounds.bottom)); +} + + +void +BScrollMenu::FrameResized(float newWidth, float newHeight) +{ + BView::FrameResized(newWidth, newHeight); + + if (fMenu != NULL) { + if (HasScrollers()) + fMenu->MoveTo(0, kScrollerHeight); + else + fMenu->MoveTo(0, 0); + } +} + + +void +BScrollMenu::AttachScrollers() +{ + if (fMenu == NULL) + return; + + BRect frame = Bounds(); + BRect screenFrame = (BScreen(Window())).Frame(); + + if (HasScrollers()) { + fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + return; + } + + fMenu->MakeFocus(true); + + if (fUpperScroller == NULL) { + fUpperScroller = new BMenuUpScroller( + BRect(0, 0, frame.right, kScrollerHeight - 1)); + AddChild(fUpperScroller, fMenu); + } + + if (fLowerScroller == NULL) { + fLowerScroller = new BMenuDownScroller( + BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, + frame.bottom)); + AddChild(fLowerScroller); + } + + fUpperScroller->SetEnabled(false); + fLowerScroller->SetEnabled(true); + + fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + fValue = 0; +} + + +void +BScrollMenu::DetachScrollers() +{ + if (!HasScrollers()) + return; + + if (fLowerScroller) { + fLowerScroller->RemoveSelf(); + delete fLowerScroller; + fLowerScroller = NULL; + } + + if (fUpperScroller) { + fUpperScroller->RemoveSelf(); + delete fUpperScroller; + fUpperScroller = NULL; + } + + if (fMenu) { + // We don't remember the position where the last scrolling + // ended, so scroll back to the beginning. + fMenu->ScrollTo(0, 0); + // Since the scrollers were removed move back up. + //fMenu->ResizeBy(0, 2 * kScrollerHeight); + //fMenu->MoveBy(0, -kScrollerHeight); + fValue = 0; + } +} + + +bool +BScrollMenu::HasScrollers() const +{ + return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL; +} + + +void +BScrollMenu::SetSmallStep(float step) +{ + fScrollStep = step; +} + + +void +BScrollMenu::GetSteps(float* _smallStep, float* _largeStep) const +{ + if (_smallStep != NULL) + *_smallStep = fScrollStep; + if (_largeStep != NULL) { + if (fMenu != NULL) + *_largeStep = fMenu->Frame().Height() - fScrollStep; + else + *_largeStep = fScrollStep * 2; + } +} + + +bool +BScrollMenu::CheckForScrolling(const BPoint &cursor) +{ + if (!HasScrollers()) + return false; + + return _Scroll(cursor); +} + + +bool +BScrollMenu::TryScrollBy(const float& step) +{ + if (!HasScrollers()) + return false; + + _ScrollBy(step); + return true; +} + + +bool +BScrollMenu::_Scroll(const BPoint& where) +{ + ASSERT((fLowerScroller != NULL)); + ASSERT((fUpperScroller != NULL)); + + const BPoint cursor = ConvertFromScreen(where); + const BRect &lowerFrame = fLowerScroller->Frame(); + const BRect &upperFrame = fUpperScroller->Frame(); + + int32 delta = 0; + if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) + delta = 1; + else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) + delta = -1; + + if (delta == 0) + return false; + + float smallStep; + GetSteps(&smallStep, NULL); + _ScrollBy(smallStep * delta); + + snooze(5000); + + return true; +} + + +void +BScrollMenu::_ScrollBy(const float& step) +{ + if (step > 0) { + if (fValue == 0) + fUpperScroller->SetEnabled(true); + + if (fValue + step >= fLimit) { + // If we reached the limit, only scroll to the end + fMenu->ScrollBy(0, fLimit - fValue); + fValue = fLimit; + fLowerScroller->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + } else if (step < 0) { + if (fValue == fLimit) + fLowerScroller->SetEnabled(true); + + if (fValue + step <= 0) { + fMenu->ScrollBy(0, -fValue); + fValue = 0; + fUpperScroller->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + } +} From 49ff476d139dc28ebaa95d65b7820423b6061d60 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 20 Jul 2012 01:13:14 -0400 Subject: [PATCH 13/66] Make ScrollMenu not rely on Menu.cpp Rename ScrollMenu.cpp to MenuScrollView.cpp Half step towards making this class work as part of Deskbar without extending any other classes. Scrolling works both with mouse and scroll wheel. Redraws on scroll, need to make that work better. Also need to move classes out of the Interface Kit and into Deskbar. --- .../{ScrollMenu.h => MenuScrollView.h} | 12 ++-- src/apps/deskbar/BarView.cpp | 33 +++++---- src/apps/deskbar/BarView.h | 4 +- src/apps/deskbar/ExpandoMenuBar.cpp | 70 ++++++++++++++----- src/apps/deskbar/ExpandoMenuBar.h | 2 +- src/apps/deskbar/TeamMenuItem.cpp | 28 +++++--- src/kits/interface/Jamfile | 2 +- src/kits/interface/Menu.cpp | 7 +- src/kits/interface/MenuBar.cpp | 33 +-------- .../{ScrollMenu.cpp => MenuScrollView.cpp} | 39 ++++++----- 10 files changed, 123 insertions(+), 107 deletions(-) rename headers/os/interface/{ScrollMenu.h => MenuScrollView.h} (84%) rename src/kits/interface/{ScrollMenu.cpp => MenuScrollView.cpp} (89%) diff --git a/headers/os/interface/ScrollMenu.h b/headers/os/interface/MenuScrollView.h similarity index 84% rename from headers/os/interface/ScrollMenu.h rename to headers/os/interface/MenuScrollView.h index 4bb14f2981..2a1904e437 100644 --- a/headers/os/interface/ScrollMenu.h +++ b/headers/os/interface/MenuScrollView.h @@ -7,8 +7,8 @@ * Stefano Ceccherini (stefano.ceccherini@gmail.com) * John Scipione (jscipione@gmail.com) */ -#ifndef SCROLL_MENU_H -#define SCROLL_MENU_H +#ifndef MENU_SCROLL_VIEW_H +#define MENU_SCROLL_VIEW_H #include @@ -18,10 +18,10 @@ class BMenu; class BMenuScroller; -class BScrollMenu : public BView { +class BMenuScrollView : public BView { public: - BScrollMenu(BMenu* menu); - virtual ~BScrollMenu(); + BMenuScrollView(BMenu* menu); + virtual ~BMenuScrollView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); @@ -52,4 +52,4 @@ private: }; -#endif // SCROLL_MENU_H +#endif // MENU_SCROLL_VIEW_H diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index f874bd1536..d174166929 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -48,7 +48,7 @@ All rights reserved. #include #include #include -#include +#include #include #include "icons.h" @@ -131,7 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, uint32 state, float) : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), - fBarScrollMenu(NULL), + fMenuScrollView(NULL), fBarMenuBar(NULL), fExpando(NULL), fTrayLocation(1), @@ -443,11 +443,11 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - if (fBarScrollMenu != NULL) { - fBarScrollMenu->RemoveSelf(); - delete fBarScrollMenu; + if (fMenuScrollView != NULL) { + fMenuScrollView->RemoveSelf(); + delete fMenuScrollView; // Also deletes fExpando - fBarScrollMenu = NULL; + fMenuScrollView = NULL; fExpando = NULL; } else if (fExpando != NULL) { fExpando->RemoveSelf(); @@ -488,12 +488,9 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - if (fVertical) { - fBarScrollMenu = new BScrollMenu(fExpando); - AddChild(fBarScrollMenu); -//printf("fExpando bottom: %f, fBarScrollMenu bottom: %f\n", fExpando->Frame().bottom, fBarScrollMenu->Frame().bottom); - } else - AddChild(fExpando); + fMenuScrollView = new BMenuScrollView(fExpando); + AddChild(fMenuScrollView); +//printf("fExpando bottom: %f, fMenuScrollView bottom: %f\n", fExpando->Frame().bottom, fMenuScrollView->Frame().bottom); if (fVertical) ExpandItems(); @@ -530,7 +527,7 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) } else if (fState == kExpandoState) { if (fVertical) { // top left or right - windowHeight = fBarScrollMenu->Frame().bottom; + windowHeight = fMenuScrollView->Frame().bottom; } else { // top or bottom, full fExpando->CheckItemSizes(0); @@ -557,8 +554,14 @@ TBarView::SizeWindow(BRect screenFrame) float windowWidth, windowHeight; GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight); Window()->ResizeTo(windowWidth, windowHeight); - if (fExpando) + + if (fExpando != NULL) { + if (fMenuScrollView != NULL) { + fMenuScrollView->ResizeTo(fExpando->Bounds().Width(), + fExpando->Bounds().Height()); + } fExpando->CheckForSizeOverrun(); + } } @@ -687,7 +690,7 @@ TBarView::ExpandItems() // Clean up the expanded items list RemoveExpandedItems(); - fExpando->SizeWindow(); + fExpando->SizeWindow(1); } diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index e8e87ba95b..e118012300 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -65,7 +65,7 @@ const float kStatusHeight = 22.0f; const float kHiddenDimension = 1.0f; const float kMaxPreventHidingDist = 80.0f; -class BScrollMenu; +class BMenuScrollView; class BShelf; class TBarMenuBar; class TExpandoMenuBar; @@ -168,7 +168,7 @@ class TBarView : public BView { void ExpandItems(); void _ChangeState(BMessage* message); - BScrollMenu* fBarScrollMenu; + BMenuScrollView* fMenuScrollView; TBarMenuBar* fBarMenuBar; TExpandoMenuBar* fExpando; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index f9cfbb86dc..246d7bfcf2 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -45,7 +45,7 @@ All rights reserved. #include #include #include -#include +#include #include "icons.h" @@ -194,6 +194,10 @@ TExpandoMenuBar::AttachedToWindow() ResizeTo(itemWidth, 0); } + BMenuScrollView* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu != NULL) + scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); + if (fVertical) { sDoMonitor = true; sMonThread = spawn_thread(monitor_team_windows, @@ -263,6 +267,32 @@ TExpandoMenuBar::MessageReceived(BMessage* message) break; } + case B_MOUSE_WHEEL_CHANGED: + { + float deltaY = 0; + message->FindFloat("be:wheel_delta_y", &deltaY); + if (deltaY == 0) + return; + + BMenuScrollView* scrollMenu + = dynamic_cast(Parent()); + if (scrollMenu == NULL) + return; + + float largeStep; + float smallStep; + scrollMenu->GetSteps(&smallStep, &largeStep); + + // pressing the option/command/control key scrolls faster + if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) + deltaY *= largeStep; + else + deltaY *= smallStep; + + scrollMenu->TryScrollBy(deltaY); + break; + } + case kAddTeam: AddTeam(message->FindInt32("team"), message->FindString("sig")); break; @@ -397,6 +427,14 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message) // force a cleanup _FinishedDrag(); + // check for scrolling menu + BMenuScrollView* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu != NULL) { + BPoint screenLocation = ConvertToScreen(where); + while(scrollMenu->CheckForScrolling(screenLocation)) + TExpandoMenuBar::MouseMoved(where, code, message); + } + switch (code) { case B_ENTERED_VIEW: case B_INSIDE_VIEW: @@ -611,10 +649,9 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name, if (fVertical) { if (item && fShowTeamExpander && fExpandNewTeams) item->ToggleExpandState(false); + } - fBarView->SizeWindow(BScreen(Window()).Frame()); - } else - CheckItemSizes(1); + SizeWindow(1); Window()->UpdateIfNeeded(); } @@ -656,14 +693,7 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial) RemoveItem(i); - if (fVertical) { - // instead of resizing the window here and there in the - // code the resize method will be centered in one place - // thus, the same behavior (good or bad) will be used - // whereever window sizing is done - fBarView->SizeWindow(BScreen(Window()).Frame()); - } else - CheckItemSizes(-1); + SizeWindow(-1); Window()->UpdateIfNeeded(); @@ -803,7 +833,7 @@ TExpandoMenuBar::CheckForSizeOverrun() return; } - BScrollMenu* scrollMenu = dynamic_cast(Parent()); + BMenuScrollView* scrollMenu = dynamic_cast(Parent()); if (scrollMenu == NULL) return; @@ -818,12 +848,20 @@ TExpandoMenuBar::CheckForSizeOverrun() void -TExpandoMenuBar::SizeWindow() +TExpandoMenuBar::SizeWindow(int32 delta) { + BMenuScrollView* scrollMenu = dynamic_cast(Parent()); + if (scrollMenu != NULL) + scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); + + // instead of resizing the window here and there in the + // code the resize method will be centered in one place + // thus, the same behavior (good or bad) will be used + // wherever window sizing is done if (fVertical) fBarView->SizeWindow(BScreen(Window()).Frame()); else - CheckItemSizes(1); + CheckItemSizes(delta); } @@ -928,7 +966,7 @@ TExpandoMenuBar::monitor_team_windows(void* arg) if (itemModified || resize) { teamMenu->Invalidate(); if (resize) - teamMenu->SizeWindow(); + teamMenu->SizeWindow(1); } teamMenu->Window()->Unlock(); diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index 4eabc96d8d..2bd1bd68c5 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -82,7 +82,7 @@ class TExpandoMenuBar : public BMenuBar { menu_layout MenuLayout() const; - void SizeWindow(); + void SizeWindow(int32 delta); void CheckForSizeOverrun(); private: diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index 35ab7ff65c..0f6fa4c4dc 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -479,7 +479,8 @@ TTeamMenuItem::DrawContentLabel() if (Submenu() && fVertical) cachedWidth += 18; - BString label(Label()); + const char* label = Label(); + char* truncLabel = NULL; float max = 0; if (fVertical && static_cast(be_app)->Settings()->superExpando) @@ -491,23 +492,30 @@ TTeamMenuItem::DrawContentLabel() BPoint penloc = menu->PenLocation(); BRect frame = Frame(); float offset = penloc.x - frame.left; - if (cachedWidth + offset > max) - menu->TruncateString(&label, B_TRUNCATE_MIDDLE, max - offset); + if (cachedWidth + offset > max) { + truncLabel = (char*)malloc(strlen(label) + 4); + if (!truncLabel) + return; + TruncateLabel(max-offset, truncLabel); + label = truncLabel; + } } if (!label) - label = BString(Label()); + label = Label(); - TBarView* barView = (static_cast(be_app))->BarView(); - bool canHandle = !barView->Dragging() - || barView->AppCanHandleTypes(Signature()); + TBarView* barview = (static_cast(be_app))->BarView(); + bool canHandle = !barview->Dragging() + || barview->AppCanHandleTypes(Signature()); if (_IsSelected() && IsEnabled() && canHandle) menu->SetLowColor(tint_color(menu->LowColor(), B_HIGHLIGHT_BACKGROUND_TINT)); else menu->SetLowColor(menu->LowColor()); - menu->DrawString(label.String()); + menu->DrawString(label); + + free(truncLabel); } @@ -551,7 +559,7 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow) sub->SetExpanded(true, myindex + childIndex); if (resizeWindow) - parent->SizeWindow(); + parent->SizeWindow(1); } } } else { @@ -573,7 +581,7 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow) sub->SetExpanded(false, 0); if (resizeWindow) - parent->SizeWindow(); + parent->SizeWindow(1); } } } diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index 4109585a2f..5726843de7 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -82,6 +82,7 @@ MergeObject interface_kit.o : MenuField.cpp MenuItem.cpp MenuPrivate.cpp + MenuScrollView.cpp MenuWindow.cpp OptionControl.cpp OptionPopUp.cpp @@ -101,7 +102,6 @@ MergeObject interface_kit.o : RegionSupport.cpp Screen.cpp ScrollBar.cpp - ScrollMenu.cpp ScrollView.cpp SeparatorItem.cpp SeparatorView.cpp diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index cde95056fe..2833899973 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -2812,13 +2812,8 @@ BMenu::_ChooseTrigger(const char* title, int32& index, uint32& trigger, void BMenu::_UpdateWindowViewSize(const bool &move) { - if (dynamic_cast(this) != NULL) { - BScrollMenu* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) - scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); - + if (dynamic_cast(this) != NULL) return; - } BMenuWindow* window = static_cast(Window()); if (window == NULL) diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index ee2e978b8f..fc47dc7d9c 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -329,36 +329,7 @@ BMenuBar::Draw(BRect updateRect) void BMenuBar::MessageReceived(BMessage* msg) { - switch (msg->what) { - case B_MOUSE_WHEEL_CHANGED: - { - float deltaY = 0; - msg->FindFloat("be:wheel_delta_y", &deltaY); - if (deltaY == 0) - return; - - BScrollMenu* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu == NULL) - return; - - float largeStep; - float smallStep; - scrollMenu->GetSteps(&smallStep, &largeStep); - - // pressing the option/command/control key scrolls faster - if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) - deltaY *= largeStep; - else - deltaY *= smallStep; - - scrollMenu->TryScrollBy(deltaY); - break; - } - - default: - BMenu::MessageReceived(msg); - break; - } + BMenu::MessageReceived(msg); } diff --git a/src/kits/interface/ScrollMenu.cpp b/src/kits/interface/MenuScrollView.cpp similarity index 89% rename from src/kits/interface/ScrollMenu.cpp rename to src/kits/interface/MenuScrollView.cpp index 2923f01dc7..e67d3d384d 100644 --- a/src/kits/interface/ScrollMenu.cpp +++ b/src/kits/interface/MenuScrollView.cpp @@ -9,7 +9,7 @@ */ -#include +#include #include #include @@ -22,8 +22,7 @@ #include -const char* kEmptyMenuLabel = ""; -const int kDefaultScrollStep = 19; +const int kDefaultScrollStep = 8; const int kScrollerHeight = 12; @@ -161,7 +160,7 @@ BMenuDownScroller::Draw(BRect updateRect) // #pragma mark - -BScrollMenu::BScrollMenu(BMenu *menu) +BMenuScrollView::BMenuScrollView(BMenu *menu) : BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), @@ -172,7 +171,7 @@ BScrollMenu::BScrollMenu(BMenu *menu) } -BScrollMenu::~BScrollMenu() +BMenuScrollView::~BMenuScrollView() { if (fMenu != NULL) { fMenu->RemoveSelf(); @@ -195,7 +194,7 @@ BScrollMenu::~BScrollMenu() void -BScrollMenu::AttachedToWindow() +BMenuScrollView::AttachedToWindow() { BView::AttachedToWindow(); @@ -204,7 +203,7 @@ BScrollMenu::AttachedToWindow() AddChild(fMenu); - // Move the scroll menu into the right position + // Move the scroll menu into position MoveTo(fMenu->Frame().LeftTop()); BFont font; @@ -214,7 +213,7 @@ BScrollMenu::AttachedToWindow() void -BScrollMenu::DetachedFromWindow() +BMenuScrollView::DetachedFromWindow() { BView::DetachedFromWindow(); @@ -230,7 +229,7 @@ BScrollMenu::DetachedFromWindow() void -BScrollMenu::Draw(BRect updateRect) +BMenuScrollView::Draw(BRect updateRect) { if (be_control_look != NULL) return; @@ -246,7 +245,7 @@ BScrollMenu::Draw(BRect updateRect) void -BScrollMenu::FrameResized(float newWidth, float newHeight) +BMenuScrollView::FrameResized(float newWidth, float newHeight) { BView::FrameResized(newWidth, newHeight); @@ -260,7 +259,7 @@ BScrollMenu::FrameResized(float newWidth, float newHeight) void -BScrollMenu::AttachScrollers() +BMenuScrollView::AttachScrollers() { if (fMenu == NULL) return; @@ -297,7 +296,7 @@ BScrollMenu::AttachScrollers() void -BScrollMenu::DetachScrollers() +BMenuScrollView::DetachScrollers() { if (!HasScrollers()) return; @@ -327,21 +326,21 @@ BScrollMenu::DetachScrollers() bool -BScrollMenu::HasScrollers() const +BMenuScrollView::HasScrollers() const { return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL; } void -BScrollMenu::SetSmallStep(float step) +BMenuScrollView::SetSmallStep(float step) { fScrollStep = step; } void -BScrollMenu::GetSteps(float* _smallStep, float* _largeStep) const +BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const { if (_smallStep != NULL) *_smallStep = fScrollStep; @@ -355,7 +354,7 @@ BScrollMenu::GetSteps(float* _smallStep, float* _largeStep) const bool -BScrollMenu::CheckForScrolling(const BPoint &cursor) +BMenuScrollView::CheckForScrolling(const BPoint &cursor) { if (!HasScrollers()) return false; @@ -365,7 +364,7 @@ BScrollMenu::CheckForScrolling(const BPoint &cursor) bool -BScrollMenu::TryScrollBy(const float& step) +BMenuScrollView::TryScrollBy(const float& step) { if (!HasScrollers()) return false; @@ -376,7 +375,7 @@ BScrollMenu::TryScrollBy(const float& step) bool -BScrollMenu::_Scroll(const BPoint& where) +BMenuScrollView::_Scroll(const BPoint& where) { ASSERT((fLowerScroller != NULL)); ASSERT((fUpperScroller != NULL)); @@ -405,7 +404,7 @@ BScrollMenu::_Scroll(const BPoint& where) void -BScrollMenu::_ScrollBy(const float& step) +BMenuScrollView::_ScrollBy(const float& step) { if (step > 0) { if (fValue == 0) @@ -420,6 +419,7 @@ BScrollMenu::_ScrollBy(const float& step) fMenu->ScrollBy(0, step); fValue += step; } + fMenu->Invalidate(); } else if (step < 0) { if (fValue == fLimit) fLowerScroller->SetEnabled(true); @@ -432,5 +432,6 @@ BScrollMenu::_ScrollBy(const float& step) fMenu->ScrollBy(0, step); fValue += step; } + fMenu->Invalidate(); } } From 7ee3b479d14579e4a9db2709499c4706850e53c9 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 21 Jul 2012 17:32:17 -0400 Subject: [PATCH 14/66] Make the MenuScrollView a fixed size... instead of trying to make it follow fExpando just make it a fixed size on creation. It is invisible and extends to the bottom of the screen. fExpando grows inside it, and the window follows fExpando. When the window grows taller than the screenframe the arrows are added. You can scroll with the mouse wheel, but I haven't yet gotten scrolling to work from clicking. Deskbar still crashes when going from Mini mode to vertical expando mode. I have no idea why. --- headers/os/interface/MenuScrollView.h | 7 ++-- src/apps/deskbar/BarView.cpp | 39 +++++++++++++----- src/apps/deskbar/ExpandoMenuBar.cpp | 36 ++-------------- src/apps/deskbar/ExpandoMenuBar.h | 3 +- src/kits/interface/MenuScrollView.cpp | 59 ++++++++------------------- 5 files changed, 54 insertions(+), 90 deletions(-) diff --git a/headers/os/interface/MenuScrollView.h b/headers/os/interface/MenuScrollView.h index 2a1904e437..1a1cb6dea9 100644 --- a/headers/os/interface/MenuScrollView.h +++ b/headers/os/interface/MenuScrollView.h @@ -16,17 +16,17 @@ class BLayout; class BMenu; class BMenuScroller; +class BPoint; class BMenuScrollView : public BView { public: - BMenuScrollView(BMenu* menu); + BMenuScrollView(BRect frame, BMenu* menu); virtual ~BMenuScrollView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); - virtual void Draw(BRect updateRect); - virtual void FrameResized(float newWidth, float newHeight); + virtual void MouseDown(BPoint where); void AttachScrollers(); void DetachScrollers(); @@ -34,6 +34,7 @@ public: void SetSmallStep(float step); void GetSteps(float* _smallStep, float* _largeStep) const; + bool CheckForScrolling(const BPoint& cursor); bool TryScrollBy(const float& step); diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index d174166929..a1307ea3b5 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -443,6 +443,9 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { + if (fExpando != NULL) + SaveExpandedItems(); + if (fMenuScrollView != NULL) { fMenuScrollView->RemoveSelf(); delete fMenuScrollView; @@ -455,10 +458,16 @@ TBarView::PlaceApplicationBar() fExpando = NULL; } - if (fState == kMiniState) - return; - BRect screenFrame = (BScreen(Window())).Frame(); + if (fState == kMiniState) { + SizeWindow(screenFrame); + PositionWindow(screenFrame); + Window()->UpdateIfNeeded(); + Invalidate(); + return; + } + + BRect menuScrollFrame(0, 0, 0, 0); BRect expandoFrame(0, 0, 0, 0); if (fVertical) { // top left/right @@ -472,6 +481,9 @@ TBarView::PlaceApplicationBar() expandoFrame.right = fBarMenuBar->Frame().Width(); else expandoFrame.right = sMinimumWindowWidth; + + menuScrollFrame = expandoFrame; + menuScrollFrame.bottom = screenFrame.bottom; } else { // top or bottom expandoFrame.top = 0; @@ -481,6 +493,8 @@ TBarView::PlaceApplicationBar() expandoFrame.right = fDragRegion->Frame().left - 1; else expandoFrame.right = screenFrame.Width(); + + menuScrollFrame = expandoFrame; } bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels; @@ -488,9 +502,8 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fMenuScrollView = new BMenuScrollView(fExpando); + fMenuScrollView = new BMenuScrollView(menuScrollFrame, fExpando); AddChild(fMenuScrollView); -//printf("fExpando bottom: %f, fMenuScrollView bottom: %f\n", fExpando->Frame().bottom, fMenuScrollView->Frame().bottom); if (fVertical) ExpandItems(); @@ -527,7 +540,12 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) } else if (fState == kExpandoState) { if (fVertical) { // top left or right - windowHeight = fMenuScrollView->Frame().bottom; + if (fTrayLocation != 0) + windowHeight = fDragRegion->Frame().bottom + 1; + else + windowHeight = fBarMenuBar->Frame().bottom + 1; + + windowHeight += fExpando->Bounds().Height(); } else { // top or bottom, full fExpando->CheckItemSizes(0); @@ -556,11 +574,10 @@ TBarView::SizeWindow(BRect screenFrame) Window()->ResizeTo(windowWidth, windowHeight); if (fExpando != NULL) { - if (fMenuScrollView != NULL) { - fMenuScrollView->ResizeTo(fExpando->Bounds().Width(), - fExpando->Bounds().Height()); - } - fExpando->CheckForSizeOverrun(); + if (fExpando->CheckForSizeOverrun()) + fMenuScrollView->AttachScrollers(); + else + fMenuScrollView->DetachScrollers(); } } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 246d7bfcf2..2b9bacbd97 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -83,7 +83,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, fVertical(vertical), fOverflow(false), fDrawLabel(drawLabel), - fIsScrolling(false), fShowTeamExpander(static_cast(be_app)->Settings()->superExpando), fExpandNewTeams(static_cast(be_app)->Settings()->expandNewTeams), fDeskbarMenuWidth(kDefaultDeskbarMenuWidth), @@ -194,10 +193,6 @@ TExpandoMenuBar::AttachedToWindow() ResizeTo(itemWidth, 0); } - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) - scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); - if (fVertical) { sDoMonitor = true; sMonThread = spawn_thread(monitor_team_windows, @@ -427,14 +422,6 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message) // force a cleanup _FinishedDrag(); - // check for scrolling menu - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) { - BPoint screenLocation = ConvertToScreen(where); - while(scrollMenu->CheckForScrolling(screenLocation)) - TExpandoMenuBar::MouseMoved(where, code, message); - } - switch (code) { case B_ENTERED_VIEW: case B_INSIDE_VIEW: @@ -825,35 +812,20 @@ TExpandoMenuBar::DrawBackground(BRect) /*! Something to help determine if we are showing too many apps need to add in scrolling functionality. */ -void +bool TExpandoMenuBar::CheckForSizeOverrun() { - if (!fVertical) { - fIsScrolling = false; - return; - } - - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu == NULL) - return; + if (!fVertical) + return false; BRect screenFrame = (BScreen(Window())).Frame(); - fIsScrolling = Window()->Frame().bottom > screenFrame.bottom; - - if (fIsScrolling) - scrollMenu->AttachScrollers(); - else - scrollMenu->DetachScrollers(); + return Window()->Frame().bottom > screenFrame.bottom; } void TExpandoMenuBar::SizeWindow(int32 delta) { - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) - scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); - // instead of resizing the window here and there in the // code the resize method will be centered in one place // thus, the same behavior (good or bad) will be used diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index 2bd1bd68c5..5a08a0b67e 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -83,7 +83,7 @@ class TExpandoMenuBar : public BMenuBar { menu_layout MenuLayout() const; void SizeWindow(int32 delta); - void CheckForSizeOverrun(); + bool CheckForSizeOverrun(); private: static int CompareByName(const void* first, const void* second); @@ -98,7 +98,6 @@ class TExpandoMenuBar : public BMenuBar { bool fVertical : 1; bool fOverflow : 1; bool fDrawLabel : 1; - bool fIsScrolling : 1; bool fShowTeamExpander : 1; bool fExpandNewTeams : 1; diff --git a/src/kits/interface/MenuScrollView.cpp b/src/kits/interface/MenuScrollView.cpp index e67d3d384d..385988100e 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/kits/interface/MenuScrollView.cpp @@ -14,15 +14,13 @@ #include #include #include -#include -#include #include +#include #include - -#include +#include -const int kDefaultScrollStep = 8; +const int kDefaultScrollStep = 19; const int kScrollerHeight = 12; @@ -160,9 +158,9 @@ BMenuDownScroller::Draw(BRect updateRect) // #pragma mark - -BMenuScrollView::BMenuScrollView(BMenu *menu) +BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) : - BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS), + BView(frame, "menu scroll view", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), fUpperScroller(NULL), fLowerScroller(NULL), @@ -201,14 +199,9 @@ BMenuScrollView::AttachedToWindow() if (fMenu == NULL) return; + fMenu->MoveTo(0, 0); + AddChild(fMenu); - - // Move the scroll menu into position - MoveTo(fMenu->Frame().LeftTop()); - - BFont font; - fMenu->GetFont(&font); - SetFont(&font); } @@ -229,33 +222,13 @@ BMenuScrollView::DetachedFromWindow() void -BMenuScrollView::Draw(BRect updateRect) +BMenuScrollView::MouseDown(BPoint where) { - if (be_control_look != NULL) - return; - - SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); - BRect bounds(Bounds()); - - StrokeLine(BPoint(bounds.right, bounds.top), - BPoint(bounds.right, bounds.bottom - 1)); - StrokeLine(BPoint(bounds.left + 1, bounds.bottom), - BPoint(bounds.right, bounds.bottom)); + } -void -BMenuScrollView::FrameResized(float newWidth, float newHeight) -{ - BView::FrameResized(newWidth, newHeight); - - if (fMenu != NULL) { - if (HasScrollers()) - fMenu->MoveTo(0, kScrollerHeight); - else - fMenu->MoveTo(0, 0); - } -} +// #pragma mark - void @@ -268,7 +241,8 @@ BMenuScrollView::AttachScrollers() BRect screenFrame = (BScreen(Window())).Frame(); if (HasScrollers()) { - fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + - screenFrame.bottom; return; } @@ -280,6 +254,8 @@ BMenuScrollView::AttachScrollers() AddChild(fUpperScroller, fMenu); } + fMenu->MoveBy(0, kScrollerHeight); + if (fLowerScroller == NULL) { fLowerScroller = new BMenuDownScroller( BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, @@ -290,7 +266,8 @@ BMenuScrollView::AttachScrollers() fUpperScroller->SetEnabled(false); fLowerScroller->SetEnabled(true); - fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + - screenFrame.bottom; fValue = 0; } @@ -317,9 +294,7 @@ BMenuScrollView::DetachScrollers() // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. fMenu->ScrollTo(0, 0); - // Since the scrollers were removed move back up. - //fMenu->ResizeBy(0, 2 * kScrollerHeight); - //fMenu->MoveBy(0, -kScrollerHeight); + fMenu->MoveBy(0, -kScrollerHeight); fValue = 0; } } From afa1c29104c7f6b7a904008fbfc6a4835de4b3d3 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 22 Jul 2012 12:48:56 -0400 Subject: [PATCH 15/66] Tweaks, remove dead code. Menu and Menubar are stock again. --- headers/os/interface/MenuScrollView.h | 1 - src/apps/deskbar/BarView.cpp | 16 +++++++--------- src/apps/deskbar/ExpandoMenuBar.cpp | 2 +- src/apps/deskbar/TeamMenuItem.cpp | 2 +- src/kits/interface/Menu.cpp | 7 +++---- src/kits/interface/MenuBar.cpp | 1 - src/kits/interface/MenuScrollView.cpp | 16 +--------------- 7 files changed, 13 insertions(+), 32 deletions(-) diff --git a/headers/os/interface/MenuScrollView.h b/headers/os/interface/MenuScrollView.h index 1a1cb6dea9..37359a82fa 100644 --- a/headers/os/interface/MenuScrollView.h +++ b/headers/os/interface/MenuScrollView.h @@ -26,7 +26,6 @@ public: virtual void AttachedToWindow(); virtual void DetachedFromWindow(); - virtual void MouseDown(BPoint where); void AttachScrollers(); void DetachScrollers(); diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index a1307ea3b5..e915adf8e6 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -358,7 +358,7 @@ TBarView::PlaceDeskbarMenu() // top or bottom expando mode has Be menu built in for tracking // only for vertical mini or expanded // mini mode will have team menu added as part of BarMenuBar - if (fVertical && !fBarMenuBar) { + if (fVertical && fBarMenuBar == NULL) { // create the Be menu BRect mbarFrame(Bounds()); mbarFrame.bottom = mbarFrame.top + kMenuBarHeight; @@ -443,19 +443,17 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - if (fExpando != NULL) + if (fExpando != NULL) { SaveExpandedItems(); + fExpando->RemoveSelf(); + delete fExpando; + fExpando = NULL; + } if (fMenuScrollView != NULL) { fMenuScrollView->RemoveSelf(); delete fMenuScrollView; - // Also deletes fExpando fMenuScrollView = NULL; - fExpando = NULL; - } else if (fExpando != NULL) { - fExpando->RemoveSelf(); - delete fExpando; - fExpando = NULL; } BRect screenFrame = (BScreen(Window())).Frame(); @@ -467,8 +465,8 @@ TBarView::PlaceApplicationBar() return; } - BRect menuScrollFrame(0, 0, 0, 0); BRect expandoFrame(0, 0, 0, 0); + BRect menuScrollFrame(0, 0, 0, 0); if (fVertical) { // top left/right if (fTrayLocation != 0) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 2b9bacbd97..d1ff430546 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -42,10 +42,10 @@ All rights reserved. #include #include #include +#include #include #include #include -#include #include "icons.h" diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index 0f6fa4c4dc..dd0e07347c 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -559,7 +559,7 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow) sub->SetExpanded(true, myindex + childIndex); if (resizeWindow) - parent->SizeWindow(1); + parent->SizeWindow(-1); } } } else { diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 2833899973..6905c15605 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -2812,13 +2811,13 @@ BMenu::_ChooseTrigger(const char* title, int32& index, uint32& trigger, void BMenu::_UpdateWindowViewSize(const bool &move) { - if (dynamic_cast(this) != NULL) - return; - BMenuWindow* window = static_cast(Window()); if (window == NULL) return; + if (dynamic_cast(this) != NULL) + return; + if (!fResizeToFit) return; diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index fc47dc7d9c..b29f9d5ef5 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/src/kits/interface/MenuScrollView.cpp b/src/kits/interface/MenuScrollView.cpp index 385988100e..8bf9dd5486 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/kits/interface/MenuScrollView.cpp @@ -171,12 +171,6 @@ BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) BMenuScrollView::~BMenuScrollView() { - if (fMenu != NULL) { - fMenu->RemoveSelf(); - delete fMenu; - fMenu = NULL; - } - if (fUpperScroller != NULL) { fUpperScroller->RemoveSelf(); delete fUpperScroller; @@ -199,9 +193,8 @@ BMenuScrollView::AttachedToWindow() if (fMenu == NULL) return; - fMenu->MoveTo(0, 0); - AddChild(fMenu); + fMenu->MoveTo(0, 0); } @@ -221,13 +214,6 @@ BMenuScrollView::DetachedFromWindow() } -void -BMenuScrollView::MouseDown(BPoint where) -{ - -} - - // #pragma mark - From d7b5131b1a1272046bfab1afc7085206249155aa Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 22 Jul 2012 17:26:38 -0400 Subject: [PATCH 16/66] Set fValue and fLimit to be 0 in the MenuScrollView contructor. --- src/kits/interface/MenuScrollView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/MenuScrollView.cpp b/src/kits/interface/MenuScrollView.cpp index 8bf9dd5486..c3faa0ebc1 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/kits/interface/MenuScrollView.cpp @@ -164,7 +164,9 @@ BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) fMenu(menu), fUpperScroller(NULL), fLowerScroller(NULL), - fScrollStep(kDefaultScrollStep) + fScrollStep(kDefaultScrollStep), + fValue(0), + fLimit(0) { } @@ -279,8 +281,8 @@ BMenuScrollView::DetachScrollers() if (fMenu) { // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. - fMenu->ScrollTo(0, 0); fMenu->MoveBy(0, -kScrollerHeight); + fMenu->ScrollTo(0, 0); fValue = 0; } } From fcfe60b02ec06525dbe76eedc110d20b7eb808f7 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 00:35:35 -0400 Subject: [PATCH 17/66] Renamed BMenuScrollView to TScrollArrowView and moved it into Deskbar Also gave the Up Arrow and Down Arrow a scroll arrow. The up arrow works but the down arrow doesn't because the sibling menu is stealing the MouseDown event." --- src/apps/deskbar/BarView.cpp | 20 +- src/apps/deskbar/BarView.h | 4 +- src/apps/deskbar/ExpandoMenuBar.cpp | 8 +- src/apps/deskbar/Jamfile | 1 + .../deskbar/ScrollArrowView.cpp} | 248 ++++++++++-------- .../apps/deskbar/ScrollArrowView.h | 23 +- src/kits/interface/Jamfile | 1 - 7 files changed, 160 insertions(+), 145 deletions(-) rename src/{kits/interface/MenuScrollView.cpp => apps/deskbar/ScrollArrowView.cpp} (56%) rename headers/os/interface/MenuScrollView.h => src/apps/deskbar/ScrollArrowView.h (65%) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index e915adf8e6..77b7a21c9e 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -48,7 +48,6 @@ All rights reserved. #include #include #include -#include #include #include "icons.h" @@ -60,6 +59,7 @@ All rights reserved. #include "ExpandoMenuBar.h" #include "FSUtils.h" #include "ResourceSet.h" +#include "ScrollArrowView.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -131,7 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, uint32 state, float) : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), - fMenuScrollView(NULL), + fScrollArrowView(NULL), fBarMenuBar(NULL), fExpando(NULL), fTrayLocation(1), @@ -450,10 +450,10 @@ TBarView::PlaceApplicationBar() fExpando = NULL; } - if (fMenuScrollView != NULL) { - fMenuScrollView->RemoveSelf(); - delete fMenuScrollView; - fMenuScrollView = NULL; + if (fScrollArrowView != NULL) { + fScrollArrowView->RemoveSelf(); + delete fScrollArrowView; + fScrollArrowView = NULL; } BRect screenFrame = (BScreen(Window())).Frame(); @@ -500,8 +500,8 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fMenuScrollView = new BMenuScrollView(menuScrollFrame, fExpando); - AddChild(fMenuScrollView); + fScrollArrowView = new TScrollArrowView(menuScrollFrame, fExpando); + AddChild(fScrollArrowView); if (fVertical) ExpandItems(); @@ -573,9 +573,9 @@ TBarView::SizeWindow(BRect screenFrame) if (fExpando != NULL) { if (fExpando->CheckForSizeOverrun()) - fMenuScrollView->AttachScrollers(); + fScrollArrowView->AttachScrollers(); else - fMenuScrollView->DetachScrollers(); + fScrollArrowView->DetachScrollers(); } } diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index e118012300..41eea6bbd9 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -65,12 +65,12 @@ const float kStatusHeight = 22.0f; const float kHiddenDimension = 1.0f; const float kMaxPreventHidingDist = 80.0f; -class BMenuScrollView; class BShelf; class TBarMenuBar; class TExpandoMenuBar; class TReplicantTray; class TDragRegion; +class TScrollArrowView; class TTeamMenuItem; @@ -168,7 +168,7 @@ class TBarView : public BView { void ExpandItems(); void _ChangeState(BMessage* message); - BMenuScrollView* fMenuScrollView; + TScrollArrowView* fScrollArrowView; TBarMenuBar* fBarMenuBar; TExpandoMenuBar* fExpando; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index d1ff430546..bb3a26ba33 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -42,7 +42,6 @@ All rights reserved. #include #include #include -#include #include #include #include @@ -56,6 +55,7 @@ All rights reserved. #include "DeskbarMenu.h" #include "DeskbarUtils.h" #include "ResourceSet.h" +#include "ScrollArrowView.h" #include "ShowHideMenuItem.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -269,8 +269,8 @@ TExpandoMenuBar::MessageReceived(BMessage* message) if (deltaY == 0) return; - BMenuScrollView* scrollMenu - = dynamic_cast(Parent()); + TScrollArrowView* scrollMenu + = dynamic_cast(Parent()); if (scrollMenu == NULL) return; @@ -284,7 +284,7 @@ TExpandoMenuBar::MessageReceived(BMessage* message) else deltaY *= smallStep; - scrollMenu->TryScrollBy(deltaY); + scrollMenu->ScrollBy(deltaY); break; } diff --git a/src/apps/deskbar/Jamfile b/src/apps/deskbar/Jamfile index 8fc34a1c55..86a8d55514 100644 --- a/src/apps/deskbar/Jamfile +++ b/src/apps/deskbar/Jamfile @@ -28,6 +28,7 @@ Application Deskbar : DeskbarUtils.cpp ExpandoMenuBar.cpp PreferencesWindow.cpp + ScrollArrowView.cpp ShowHideMenuItem.cpp StatusView.cpp StatusViewShelf.cpp diff --git a/src/kits/interface/MenuScrollView.cpp b/src/apps/deskbar/ScrollArrowView.cpp similarity index 56% rename from src/kits/interface/MenuScrollView.cpp rename to src/apps/deskbar/ScrollArrowView.cpp index c3faa0ebc1..8335e243bb 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/apps/deskbar/ScrollArrowView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, Haiku, Inc. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -9,7 +9,7 @@ */ -#include +#include "ScrollArrowView.h" #include #include @@ -24,10 +24,10 @@ const int kDefaultScrollStep = 19; const int kScrollerHeight = 12; -class BMenuScroller : public BView { +class ScrollArrow : public BView { public: - BMenuScroller(BRect frame); - virtual ~BMenuScroller(); + ScrollArrow(BRect frame); + virtual ~ScrollArrow(); bool IsEnabled() const { return fEnabled; }; void SetEnabled(bool enabled); @@ -37,28 +37,30 @@ private: }; -class BMenuUpScroller : public BMenuScroller { +class UpScrollArrow : public ScrollArrow { public: - BMenuUpScroller(BRect frame); - virtual ~BMenuUpScroller(); + UpScrollArrow(BRect frame); + virtual ~UpScrollArrow(); virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); }; -class BMenuDownScroller : public BMenuScroller { +class DownScrollArrow : public ScrollArrow { public: - BMenuDownScroller(BRect frame); - virtual ~BMenuDownScroller(); + DownScrollArrow(BRect frame); + virtual ~DownScrollArrow(); virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); }; // #pragma mark - -BMenuScroller::BMenuScroller(BRect frame) +ScrollArrow::ScrollArrow(BRect frame) : BView(frame, "menu scroll arrow", 0, B_WILL_DRAW | B_FRAME_EVENTS), fEnabled(false) @@ -67,13 +69,13 @@ BMenuScroller::BMenuScroller(BRect frame) } -BMenuScroller::~BMenuScroller() +ScrollArrow::~ScrollArrow() { } void -BMenuScroller::SetEnabled(bool enabled) +ScrollArrow::SetEnabled(bool enabled) { fEnabled = enabled; Invalidate(); @@ -83,20 +85,20 @@ BMenuScroller::SetEnabled(bool enabled) // #pragma mark - -BMenuUpScroller::BMenuUpScroller(BRect frame) +UpScrollArrow::UpScrollArrow(BRect frame) : - BMenuScroller(frame) + ScrollArrow(frame) { } -BMenuUpScroller::~BMenuUpScroller() +UpScrollArrow::~UpScrollArrow() { } void -BMenuUpScroller::Draw(BRect updateRect) +UpScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); @@ -117,23 +119,34 @@ BMenuUpScroller::Draw(BRect updateRect) } +void +UpScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + dynamic_cast(Parent())->ScrollBy(-kDefaultScrollStep); + snooze(5000); +} + + // #pragma mark - -BMenuDownScroller::BMenuDownScroller(BRect frame) +DownScrollArrow::DownScrollArrow(BRect frame) : - BMenuScroller(frame) + ScrollArrow(frame) { } -BMenuDownScroller::~BMenuDownScroller() +DownScrollArrow::~DownScrollArrow() { } void -BMenuDownScroller::Draw(BRect updateRect) +DownScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); @@ -155,15 +168,26 @@ BMenuDownScroller::Draw(BRect updateRect) } +void +DownScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + dynamic_cast(Parent())->ScrollBy(kDefaultScrollStep); + snooze(5000); +} + + // #pragma mark - -BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) +TScrollArrowView::TScrollArrowView(BRect frame, BMenu* menu) : BView(frame, "menu scroll view", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), - fUpperScroller(NULL), - fLowerScroller(NULL), + fUpperScrollArrow(NULL), + fLowerScrollArrow(NULL), fScrollStep(kDefaultScrollStep), fValue(0), fLimit(0) @@ -171,24 +195,24 @@ BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) } -BMenuScrollView::~BMenuScrollView() +TScrollArrowView::~TScrollArrowView() { - if (fUpperScroller != NULL) { - fUpperScroller->RemoveSelf(); - delete fUpperScroller; - fUpperScroller = NULL; + if (fUpperScrollArrow != NULL) { + fUpperScrollArrow->RemoveSelf(); + delete fUpperScrollArrow; + fUpperScrollArrow = NULL; } - if (fLowerScroller != NULL) { - fLowerScroller->RemoveSelf(); - delete fLowerScroller; - fLowerScroller = NULL; + if (fLowerScrollArrow != NULL) { + fLowerScrollArrow->RemoveSelf(); + delete fLowerScrollArrow; + fLowerScrollArrow = NULL; } } void -BMenuScrollView::AttachedToWindow() +TScrollArrowView::AttachedToWindow() { BView::AttachedToWindow(); @@ -201,18 +225,18 @@ BMenuScrollView::AttachedToWindow() void -BMenuScrollView::DetachedFromWindow() +TScrollArrowView::DetachedFromWindow() { BView::DetachedFromWindow(); if (fMenu != NULL) fMenu->RemoveSelf(); - if (fUpperScroller != NULL) - fUpperScroller->RemoveSelf(); + if (fUpperScrollArrow != NULL) + fUpperScrollArrow->RemoveSelf(); - if (fLowerScroller != NULL) - fLowerScroller->RemoveSelf(); + if (fLowerScrollArrow != NULL) + fLowerScrollArrow->RemoveSelf(); } @@ -220,7 +244,7 @@ BMenuScrollView::DetachedFromWindow() void -BMenuScrollView::AttachScrollers() +TScrollArrowView::AttachScrollers() { if (fMenu == NULL) return; @@ -236,23 +260,23 @@ BMenuScrollView::AttachScrollers() fMenu->MakeFocus(true); - if (fUpperScroller == NULL) { - fUpperScroller = new BMenuUpScroller( + if (fUpperScrollArrow == NULL) { + fUpperScrollArrow = new UpScrollArrow( BRect(0, 0, frame.right, kScrollerHeight - 1)); - AddChild(fUpperScroller, fMenu); + AddChild(fUpperScrollArrow); } fMenu->MoveBy(0, kScrollerHeight); - if (fLowerScroller == NULL) { - fLowerScroller = new BMenuDownScroller( + if (fLowerScrollArrow == NULL) { + fLowerScrollArrow = new DownScrollArrow( BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, frame.bottom)); - AddChild(fLowerScroller); + AddChild(fLowerScrollArrow, fMenu); } - fUpperScroller->SetEnabled(false); - fLowerScroller->SetEnabled(true); + fUpperScrollArrow->SetEnabled(false); + fLowerScrollArrow->SetEnabled(true); fLimit = Window()->Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; @@ -261,21 +285,21 @@ BMenuScrollView::AttachScrollers() void -BMenuScrollView::DetachScrollers() +TScrollArrowView::DetachScrollers() { if (!HasScrollers()) return; - if (fLowerScroller) { - fLowerScroller->RemoveSelf(); - delete fLowerScroller; - fLowerScroller = NULL; + if (fLowerScrollArrow) { + fLowerScrollArrow->RemoveSelf(); + delete fLowerScrollArrow; + fLowerScrollArrow = NULL; } - if (fUpperScroller) { - fUpperScroller->RemoveSelf(); - delete fUpperScroller; - fUpperScroller = NULL; + if (fUpperScrollArrow) { + fUpperScrollArrow->RemoveSelf(); + delete fUpperScrollArrow; + fUpperScrollArrow = NULL; } if (fMenu) { @@ -289,21 +313,21 @@ BMenuScrollView::DetachScrollers() bool -BMenuScrollView::HasScrollers() const +TScrollArrowView::HasScrollers() const { - return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL; + return fMenu != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL; } void -BMenuScrollView::SetSmallStep(float step) +TScrollArrowView::SetSmallStep(float step) { fScrollStep = step; } void -BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const +TScrollArrowView::GetSteps(float* _smallStep, float* _largeStep) const { if (_smallStep != NULL) *_smallStep = fScrollStep; @@ -316,8 +340,45 @@ BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const } +void +TScrollArrowView::ScrollBy(const float& step) +{ + if (!HasScrollers()) + return; + + if (step > 0) { + if (fValue == 0) + fUpperScrollArrow->SetEnabled(true); + + if (fValue + step >= fLimit) { + // If we reached the limit, only scroll to the end + fMenu->ScrollBy(0, fLimit - fValue); + fValue = fLimit; + fLowerScrollArrow->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + fMenu->Invalidate(); + } else if (step < 0) { + if (fValue == fLimit) + fLowerScrollArrow->SetEnabled(true); + + if (fValue + step <= 0) { + fMenu->ScrollBy(0, -fValue); + fValue = 0; + fUpperScrollArrow->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + fMenu->Invalidate(); + } +} + + bool -BMenuScrollView::CheckForScrolling(const BPoint &cursor) +TScrollArrowView::CheckForScrolling(const BPoint &cursor) { if (!HasScrollers()) return false; @@ -327,30 +388,19 @@ BMenuScrollView::CheckForScrolling(const BPoint &cursor) bool -BMenuScrollView::TryScrollBy(const float& step) +TScrollArrowView::_Scroll(const BPoint& where) { - if (!HasScrollers()) - return false; - - _ScrollBy(step); - return true; -} - - -bool -BMenuScrollView::_Scroll(const BPoint& where) -{ - ASSERT((fLowerScroller != NULL)); - ASSERT((fUpperScroller != NULL)); + ASSERT((fLowerScrollArrow != NULL)); + ASSERT((fUpperScrollArrow != NULL)); const BPoint cursor = ConvertFromScreen(where); - const BRect &lowerFrame = fLowerScroller->Frame(); - const BRect &upperFrame = fUpperScroller->Frame(); + const BRect &lowerFrame = fLowerScrollArrow->Frame(); + const BRect &upperFrame = fUpperScrollArrow->Frame(); int32 delta = 0; - if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) + if (fLowerScrollArrow->IsEnabled() && lowerFrame.Contains(cursor)) delta = 1; - else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) + else if (fUpperScrollArrow->IsEnabled() && upperFrame.Contains(cursor)) delta = -1; if (delta == 0) @@ -358,43 +408,9 @@ BMenuScrollView::_Scroll(const BPoint& where) float smallStep; GetSteps(&smallStep, NULL); - _ScrollBy(smallStep * delta); + ScrollBy(smallStep * delta); snooze(5000); return true; } - - -void -BMenuScrollView::_ScrollBy(const float& step) -{ - if (step > 0) { - if (fValue == 0) - fUpperScroller->SetEnabled(true); - - if (fValue + step >= fLimit) { - // If we reached the limit, only scroll to the end - fMenu->ScrollBy(0, fLimit - fValue); - fValue = fLimit; - fLowerScroller->SetEnabled(false); - } else { - fMenu->ScrollBy(0, step); - fValue += step; - } - fMenu->Invalidate(); - } else if (step < 0) { - if (fValue == fLimit) - fLowerScroller->SetEnabled(true); - - if (fValue + step <= 0) { - fMenu->ScrollBy(0, -fValue); - fValue = 0; - fUpperScroller->SetEnabled(false); - } else { - fMenu->ScrollBy(0, step); - fValue += step; - } - fMenu->Invalidate(); - } -} diff --git a/headers/os/interface/MenuScrollView.h b/src/apps/deskbar/ScrollArrowView.h similarity index 65% rename from headers/os/interface/MenuScrollView.h rename to src/apps/deskbar/ScrollArrowView.h index 37359a82fa..ad2b1893b0 100644 --- a/headers/os/interface/MenuScrollView.h +++ b/src/apps/deskbar/ScrollArrowView.h @@ -1,5 +1,5 @@ /* - * Copyright 2011, Haiku, Inc. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -7,22 +7,22 @@ * Stefano Ceccherini (stefano.ceccherini@gmail.com) * John Scipione (jscipione@gmail.com) */ -#ifndef MENU_SCROLL_VIEW_H -#define MENU_SCROLL_VIEW_H +#ifndef SCROLL_ARROW_VIEW_H +#define SCROLL_ARROW_VIEW_H #include class BLayout; class BMenu; -class BMenuScroller; +class ScrollArrow; class BPoint; -class BMenuScrollView : public BView { +class TScrollArrowView : public BView { public: - BMenuScrollView(BRect frame, BMenu* menu); - virtual ~BMenuScrollView(); + TScrollArrowView(BRect frame, BMenu* menu); + virtual ~TScrollArrowView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); @@ -35,16 +35,15 @@ public: void GetSteps(float* _smallStep, float* _largeStep) const; bool CheckForScrolling(const BPoint& cursor); - bool TryScrollBy(const float& step); + void ScrollBy(const float& step); protected: bool _Scroll(const BPoint& cursor); - void _ScrollBy(const float& step); private: BMenu* fMenu; - BMenuScroller* fUpperScroller; - BMenuScroller* fLowerScroller; + ScrollArrow* fUpperScrollArrow; + ScrollArrow* fLowerScrollArrow; float fScrollStep; float fValue; @@ -52,4 +51,4 @@ private: }; -#endif // MENU_SCROLL_VIEW_H +#endif // SCROLL_ARROW_VIEW_H diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index 5726843de7..81c59e0b32 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -82,7 +82,6 @@ MergeObject interface_kit.o : MenuField.cpp MenuItem.cpp MenuPrivate.cpp - MenuScrollView.cpp MenuWindow.cpp OptionControl.cpp OptionPopUp.cpp From 36ac19ebc1ba85ea7ab353d1b18e26f491a663d0 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 01:43:16 -0400 Subject: [PATCH 18/66] Make the lower arrow a child of the menu instead. When you scroll, make the lower arrow scroll the same way to give the illusion that it isn't moving at all. So, now both arrows scroll on MouseDown, but, Deskbar crashes on resolution change. --- src/apps/deskbar/ScrollArrowView.cpp | 66 +++++++--------------------- src/apps/deskbar/ScrollArrowView.h | 5 --- 2 files changed, 16 insertions(+), 55 deletions(-) diff --git a/src/apps/deskbar/ScrollArrowView.cpp b/src/apps/deskbar/ScrollArrowView.cpp index 8335e243bb..707a8600ef 100644 --- a/src/apps/deskbar/ScrollArrowView.cpp +++ b/src/apps/deskbar/ScrollArrowView.cpp @@ -62,7 +62,7 @@ public: ScrollArrow::ScrollArrow(BRect frame) : - BView(frame, "menu scroll arrow", 0, B_WILL_DRAW | B_FRAME_EVENTS), + BView(frame, "menu scroll arrow", B_FOLLOW_NONE, B_WILL_DRAW), fEnabled(false) { SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); @@ -174,7 +174,10 @@ DownScrollArrow::MouseDown(BPoint where) if (!IsEnabled()) return; - dynamic_cast(Parent())->ScrollBy(kDefaultScrollStep); + TScrollArrowView* grandparent + = dynamic_cast(Parent()->Parent()); + + grandparent->ScrollBy(kDefaultScrollStep); snooze(5000); } @@ -266,15 +269,15 @@ TScrollArrowView::AttachScrollers() AddChild(fUpperScrollArrow); } - fMenu->MoveBy(0, kScrollerHeight); - if (fLowerScrollArrow == NULL) { fLowerScrollArrow = new DownScrollArrow( - BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, - frame.bottom)); - AddChild(fLowerScrollArrow, fMenu); + BRect(0, frame.bottom - 2 * kScrollerHeight + 1, frame.right, + frame.bottom - kScrollerHeight)); + fMenu->AddChild(fLowerScrollArrow); } + fMenu->MoveBy(0, kScrollerHeight); + fUpperScrollArrow->SetEnabled(false); fLowerScrollArrow->SetEnabled(true); @@ -353,64 +356,27 @@ TScrollArrowView::ScrollBy(const float& step) if (fValue + step >= fLimit) { // If we reached the limit, only scroll to the end fMenu->ScrollBy(0, fLimit - fValue); - fValue = fLimit; + fLowerScrollArrow->MoveBy(0, fLimit - fValue); fLowerScrollArrow->SetEnabled(false); + fValue = fLimit; } else { fMenu->ScrollBy(0, step); + fLowerScrollArrow->MoveBy(0, step); fValue += step; } - fMenu->Invalidate(); } else if (step < 0) { if (fValue == fLimit) fLowerScrollArrow->SetEnabled(true); if (fValue + step <= 0) { fMenu->ScrollBy(0, -fValue); - fValue = 0; + fLowerScrollArrow->MoveBy(0, -fValue); fUpperScrollArrow->SetEnabled(false); + fValue = 0; } else { fMenu->ScrollBy(0, step); + fLowerScrollArrow->MoveBy(0, step); fValue += step; } - fMenu->Invalidate(); } } - - -bool -TScrollArrowView::CheckForScrolling(const BPoint &cursor) -{ - if (!HasScrollers()) - return false; - - return _Scroll(cursor); -} - - -bool -TScrollArrowView::_Scroll(const BPoint& where) -{ - ASSERT((fLowerScrollArrow != NULL)); - ASSERT((fUpperScrollArrow != NULL)); - - const BPoint cursor = ConvertFromScreen(where); - const BRect &lowerFrame = fLowerScrollArrow->Frame(); - const BRect &upperFrame = fUpperScrollArrow->Frame(); - - int32 delta = 0; - if (fLowerScrollArrow->IsEnabled() && lowerFrame.Contains(cursor)) - delta = 1; - else if (fUpperScrollArrow->IsEnabled() && upperFrame.Contains(cursor)) - delta = -1; - - if (delta == 0) - return false; - - float smallStep; - GetSteps(&smallStep, NULL); - ScrollBy(smallStep * delta); - - snooze(5000); - - return true; -} diff --git a/src/apps/deskbar/ScrollArrowView.h b/src/apps/deskbar/ScrollArrowView.h index ad2b1893b0..0a71c29c5c 100644 --- a/src/apps/deskbar/ScrollArrowView.h +++ b/src/apps/deskbar/ScrollArrowView.h @@ -33,13 +33,8 @@ public: void SetSmallStep(float step); void GetSteps(float* _smallStep, float* _largeStep) const; - - bool CheckForScrolling(const BPoint& cursor); void ScrollBy(const float& step); -protected: - bool _Scroll(const BPoint& cursor); - private: BMenu* fMenu; ScrollArrow* fUpperScrollArrow; From 9c5644aa0913c5af2926f43353122d580e28bf79 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 12:48:14 -0400 Subject: [PATCH 19/66] Detach the scrollbars before deleting fExpando. ... when rebuilding the application bar. This fixes a Deskbar crash on resolution change because the lower scrollbar is a child of fExpando so it must be removed and deleted before fExpando is. So the tear down is remote scroll arrows (if attached) then remote fExpando, then remove the scroll arrow container view. The application bar is then rebuilt in reverse. --- src/apps/deskbar/BarView.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 77b7a21c9e..e08d6d8114 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -443,6 +443,9 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { + if (fScrollArrowView != NULL) + fScrollArrowView->DetachScrollers(); + if (fExpando != NULL) { SaveExpandedItems(); fExpando->RemoveSelf(); From e06f13f9110879dca0e2338266c20e6f44f14d1c Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 13:36:30 -0400 Subject: [PATCH 20/66] Replace a deleted comment, check parent is not NULL before using it. --- src/apps/deskbar/BarView.cpp | 1 + src/apps/deskbar/ScrollArrowView.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index e08d6d8114..a966e47006 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -349,6 +349,7 @@ TBarView::MouseDown(BPoint where) void TBarView::PlaceDeskbarMenu() { + // top or bottom, full if (!fVertical && fBarMenuBar != NULL) { fBarMenuBar->RemoveSelf(); delete fBarMenuBar; diff --git a/src/apps/deskbar/ScrollArrowView.cpp b/src/apps/deskbar/ScrollArrowView.cpp index 707a8600ef..39497299c3 100644 --- a/src/apps/deskbar/ScrollArrowView.cpp +++ b/src/apps/deskbar/ScrollArrowView.cpp @@ -125,8 +125,12 @@ UpScrollArrow::MouseDown(BPoint where) if (!IsEnabled()) return; - dynamic_cast(Parent())->ScrollBy(-kDefaultScrollStep); - snooze(5000); + TScrollArrowView* parent = dynamic_cast(Parent()); + + if (parent != NULL) { + parent->ScrollBy(-kDefaultScrollStep); + snooze(5000); + } } @@ -177,8 +181,10 @@ DownScrollArrow::MouseDown(BPoint where) TScrollArrowView* grandparent = dynamic_cast(Parent()->Parent()); - grandparent->ScrollBy(kDefaultScrollStep); - snooze(5000); + if (grandparent != NULL) { + grandparent->ScrollBy(kDefaultScrollStep); + snooze(5000); + } } From 32f840b7684012009c47338da6e00a202388126b Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 14:01:53 -0400 Subject: [PATCH 21/66] Rename ScrollArrowView to InlineScrollView InlineScrollView takes a BView instead of a BMenu as well, and it no longer has flags to do drawing respond to frame changes since this view does neither of those things. --- src/apps/deskbar/BarView.cpp | 24 +++---- src/apps/deskbar/BarView.h | 4 +- src/apps/deskbar/ExpandoMenuBar.cpp | 12 ++-- ...rollArrowView.cpp => InlineScrollView.cpp} | 70 +++++++++---------- .../{ScrollArrowView.h => InlineScrollView.h} | 15 ++-- src/apps/deskbar/Jamfile | 2 +- 6 files changed, 63 insertions(+), 64 deletions(-) rename src/apps/deskbar/{ScrollArrowView.cpp => InlineScrollView.cpp} (81%) rename src/apps/deskbar/{ScrollArrowView.h => InlineScrollView.h} (76%) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index a966e47006..ab0f1e24c2 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -58,8 +58,8 @@ All rights reserved. #include "DeskbarUtils.h" #include "ExpandoMenuBar.h" #include "FSUtils.h" +#include "InlineScrollView.h" #include "ResourceSet.h" -#include "ScrollArrowView.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -131,7 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, uint32 state, float) : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), - fScrollArrowView(NULL), + fInlineScrollView(NULL), fBarMenuBar(NULL), fExpando(NULL), fTrayLocation(1), @@ -444,8 +444,8 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - if (fScrollArrowView != NULL) - fScrollArrowView->DetachScrollers(); + if (fInlineScrollView != NULL) + fInlineScrollView->DetachScrollers(); if (fExpando != NULL) { SaveExpandedItems(); @@ -454,10 +454,10 @@ TBarView::PlaceApplicationBar() fExpando = NULL; } - if (fScrollArrowView != NULL) { - fScrollArrowView->RemoveSelf(); - delete fScrollArrowView; - fScrollArrowView = NULL; + if (fInlineScrollView != NULL) { + fInlineScrollView->RemoveSelf(); + delete fInlineScrollView; + fInlineScrollView = NULL; } BRect screenFrame = (BScreen(Window())).Frame(); @@ -504,8 +504,8 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fScrollArrowView = new TScrollArrowView(menuScrollFrame, fExpando); - AddChild(fScrollArrowView); + fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando); + AddChild(fInlineScrollView); if (fVertical) ExpandItems(); @@ -577,9 +577,9 @@ TBarView::SizeWindow(BRect screenFrame) if (fExpando != NULL) { if (fExpando->CheckForSizeOverrun()) - fScrollArrowView->AttachScrollers(); + fInlineScrollView->AttachScrollers(); else - fScrollArrowView->DetachScrollers(); + fInlineScrollView->DetachScrollers(); } } diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index 41eea6bbd9..cebb819060 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -70,7 +70,7 @@ class TBarMenuBar; class TExpandoMenuBar; class TReplicantTray; class TDragRegion; -class TScrollArrowView; +class TInlineScrollView; class TTeamMenuItem; @@ -168,7 +168,7 @@ class TBarView : public BView { void ExpandItems(); void _ChangeState(BMessage* message); - TScrollArrowView* fScrollArrowView; + TInlineScrollView* fInlineScrollView; TBarMenuBar* fBarMenuBar; TExpandoMenuBar* fExpando; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index bb3a26ba33..5a723b0ab5 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -54,8 +54,8 @@ All rights reserved. #include "BarWindow.h" #include "DeskbarMenu.h" #include "DeskbarUtils.h" +#include "InlineScrollView.h" #include "ResourceSet.h" -#include "ScrollArrowView.h" #include "ShowHideMenuItem.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -269,14 +269,14 @@ TExpandoMenuBar::MessageReceived(BMessage* message) if (deltaY == 0) return; - TScrollArrowView* scrollMenu - = dynamic_cast(Parent()); - if (scrollMenu == NULL) + TInlineScrollView* scrollView + = dynamic_cast(Parent()); + if (scrollView == NULL) return; float largeStep; float smallStep; - scrollMenu->GetSteps(&smallStep, &largeStep); + scrollView->GetSteps(&smallStep, &largeStep); // pressing the option/command/control key scrolls faster if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) @@ -284,7 +284,7 @@ TExpandoMenuBar::MessageReceived(BMessage* message) else deltaY *= smallStep; - scrollMenu->ScrollBy(deltaY); + scrollView->ScrollBy(deltaY); break; } diff --git a/src/apps/deskbar/ScrollArrowView.cpp b/src/apps/deskbar/InlineScrollView.cpp similarity index 81% rename from src/apps/deskbar/ScrollArrowView.cpp rename to src/apps/deskbar/InlineScrollView.cpp index 39497299c3..3c28cee5f6 100644 --- a/src/apps/deskbar/ScrollArrowView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -9,7 +9,7 @@ */ -#include "ScrollArrowView.h" +#include "InlineScrollView.h" #include #include @@ -125,7 +125,7 @@ UpScrollArrow::MouseDown(BPoint where) if (!IsEnabled()) return; - TScrollArrowView* parent = dynamic_cast(Parent()); + TInlineScrollView* parent = dynamic_cast(Parent()); if (parent != NULL) { parent->ScrollBy(-kDefaultScrollStep); @@ -178,8 +178,8 @@ DownScrollArrow::MouseDown(BPoint where) if (!IsEnabled()) return; - TScrollArrowView* grandparent - = dynamic_cast(Parent()->Parent()); + TInlineScrollView* grandparent + = dynamic_cast(Parent()->Parent()); if (grandparent != NULL) { grandparent->ScrollBy(kDefaultScrollStep); @@ -191,10 +191,10 @@ DownScrollArrow::MouseDown(BPoint where) // #pragma mark - -TScrollArrowView::TScrollArrowView(BRect frame, BMenu* menu) +TInlineScrollView::TInlineScrollView(BRect frame, BView* target) : - BView(frame, "menu scroll view", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), - fMenu(menu), + BView(frame, "inline scroll view", B_FOLLOW_NONE, 0), + fTarget(target), fUpperScrollArrow(NULL), fLowerScrollArrow(NULL), fScrollStep(kDefaultScrollStep), @@ -204,7 +204,7 @@ TScrollArrowView::TScrollArrowView(BRect frame, BMenu* menu) } -TScrollArrowView::~TScrollArrowView() +TInlineScrollView::~TInlineScrollView() { if (fUpperScrollArrow != NULL) { fUpperScrollArrow->RemoveSelf(); @@ -221,25 +221,25 @@ TScrollArrowView::~TScrollArrowView() void -TScrollArrowView::AttachedToWindow() +TInlineScrollView::AttachedToWindow() { BView::AttachedToWindow(); - if (fMenu == NULL) + if (fTarget == NULL) return; - AddChild(fMenu); - fMenu->MoveTo(0, 0); + AddChild(fTarget); + fTarget->MoveTo(0, 0); } void -TScrollArrowView::DetachedFromWindow() +TInlineScrollView::DetachedFromWindow() { BView::DetachedFromWindow(); - if (fMenu != NULL) - fMenu->RemoveSelf(); + if (fTarget != NULL) + fTarget->RemoveSelf(); if (fUpperScrollArrow != NULL) fUpperScrollArrow->RemoveSelf(); @@ -253,9 +253,9 @@ TScrollArrowView::DetachedFromWindow() void -TScrollArrowView::AttachScrollers() +TInlineScrollView::AttachScrollers() { - if (fMenu == NULL) + if (fTarget == NULL) return; BRect frame = Bounds(); @@ -267,7 +267,7 @@ TScrollArrowView::AttachScrollers() return; } - fMenu->MakeFocus(true); + fTarget->MakeFocus(true); if (fUpperScrollArrow == NULL) { fUpperScrollArrow = new UpScrollArrow( @@ -279,10 +279,10 @@ TScrollArrowView::AttachScrollers() fLowerScrollArrow = new DownScrollArrow( BRect(0, frame.bottom - 2 * kScrollerHeight + 1, frame.right, frame.bottom - kScrollerHeight)); - fMenu->AddChild(fLowerScrollArrow); + fTarget->AddChild(fLowerScrollArrow); } - fMenu->MoveBy(0, kScrollerHeight); + fTarget->MoveBy(0, kScrollerHeight); fUpperScrollArrow->SetEnabled(false); fLowerScrollArrow->SetEnabled(true); @@ -294,7 +294,7 @@ TScrollArrowView::AttachScrollers() void -TScrollArrowView::DetachScrollers() +TInlineScrollView::DetachScrollers() { if (!HasScrollers()) return; @@ -311,38 +311,38 @@ TScrollArrowView::DetachScrollers() fUpperScrollArrow = NULL; } - if (fMenu) { + if (fTarget) { // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. - fMenu->MoveBy(0, -kScrollerHeight); - fMenu->ScrollTo(0, 0); + fTarget->MoveBy(0, -kScrollerHeight); + fTarget->ScrollTo(0, 0); fValue = 0; } } bool -TScrollArrowView::HasScrollers() const +TInlineScrollView::HasScrollers() const { - return fMenu != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL; + return fTarget != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL; } void -TScrollArrowView::SetSmallStep(float step) +TInlineScrollView::SetSmallStep(float step) { fScrollStep = step; } void -TScrollArrowView::GetSteps(float* _smallStep, float* _largeStep) const +TInlineScrollView::GetSteps(float* _smallStep, float* _largeStep) const { if (_smallStep != NULL) *_smallStep = fScrollStep; if (_largeStep != NULL) { - if (fMenu != NULL) - *_largeStep = fMenu->Frame().Height() - fScrollStep; + if (fTarget != NULL) + *_largeStep = fTarget->Frame().Height() - fScrollStep; else *_largeStep = fScrollStep * 2; } @@ -350,7 +350,7 @@ TScrollArrowView::GetSteps(float* _smallStep, float* _largeStep) const void -TScrollArrowView::ScrollBy(const float& step) +TInlineScrollView::ScrollBy(const float& step) { if (!HasScrollers()) return; @@ -361,12 +361,12 @@ TScrollArrowView::ScrollBy(const float& step) if (fValue + step >= fLimit) { // If we reached the limit, only scroll to the end - fMenu->ScrollBy(0, fLimit - fValue); + fTarget->ScrollBy(0, fLimit - fValue); fLowerScrollArrow->MoveBy(0, fLimit - fValue); fLowerScrollArrow->SetEnabled(false); fValue = fLimit; } else { - fMenu->ScrollBy(0, step); + fTarget->ScrollBy(0, step); fLowerScrollArrow->MoveBy(0, step); fValue += step; } @@ -375,12 +375,12 @@ TScrollArrowView::ScrollBy(const float& step) fLowerScrollArrow->SetEnabled(true); if (fValue + step <= 0) { - fMenu->ScrollBy(0, -fValue); + fTarget->ScrollBy(0, -fValue); fLowerScrollArrow->MoveBy(0, -fValue); fUpperScrollArrow->SetEnabled(false); fValue = 0; } else { - fMenu->ScrollBy(0, step); + fTarget->ScrollBy(0, step); fLowerScrollArrow->MoveBy(0, step); fValue += step; } diff --git a/src/apps/deskbar/ScrollArrowView.h b/src/apps/deskbar/InlineScrollView.h similarity index 76% rename from src/apps/deskbar/ScrollArrowView.h rename to src/apps/deskbar/InlineScrollView.h index 0a71c29c5c..db6581db82 100644 --- a/src/apps/deskbar/ScrollArrowView.h +++ b/src/apps/deskbar/InlineScrollView.h @@ -7,22 +7,21 @@ * Stefano Ceccherini (stefano.ceccherini@gmail.com) * John Scipione (jscipione@gmail.com) */ -#ifndef SCROLL_ARROW_VIEW_H -#define SCROLL_ARROW_VIEW_H +#ifndef INLINE_SCROLL_VIEW_H +#define INLINE_SCROLL_VIEW_H #include class BLayout; -class BMenu; class ScrollArrow; class BPoint; -class TScrollArrowView : public BView { +class TInlineScrollView : public BView { public: - TScrollArrowView(BRect frame, BMenu* menu); - virtual ~TScrollArrowView(); + TInlineScrollView(BRect frame, BView* target); + virtual ~TInlineScrollView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); @@ -36,7 +35,7 @@ public: void ScrollBy(const float& step); private: - BMenu* fMenu; + BView* fTarget; ScrollArrow* fUpperScrollArrow; ScrollArrow* fLowerScrollArrow; @@ -46,4 +45,4 @@ private: }; -#endif // SCROLL_ARROW_VIEW_H +#endif // INLINE_SCROLL_VIEW_H diff --git a/src/apps/deskbar/Jamfile b/src/apps/deskbar/Jamfile index 86a8d55514..5f9c38a58a 100644 --- a/src/apps/deskbar/Jamfile +++ b/src/apps/deskbar/Jamfile @@ -27,8 +27,8 @@ Application Deskbar : DeskbarMenu.cpp DeskbarUtils.cpp ExpandoMenuBar.cpp + InlineScrollView.cpp PreferencesWindow.cpp - ScrollArrowView.cpp ShowHideMenuItem.cpp StatusView.cpp StatusViewShelf.cpp From 255853fe1593130db397b0923d0c82f1c2924557 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 22:05:02 -0400 Subject: [PATCH 22/66] Add left and right Scrollers and also an orientation parameter. Set the limit based on the view bottom and not the window bottom. --- src/apps/deskbar/InlineScrollView.cpp | 157 +++++++++++++++++++++++--- src/apps/deskbar/InlineScrollView.h | 3 +- 2 files changed, 142 insertions(+), 18 deletions(-) diff --git a/src/apps/deskbar/InlineScrollView.cpp b/src/apps/deskbar/InlineScrollView.cpp index 3c28cee5f6..c44aeedcb5 100644 --- a/src/apps/deskbar/InlineScrollView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -21,7 +21,7 @@ const int kDefaultScrollStep = 19; -const int kScrollerHeight = 12; +const int kScrollerDimension = 12; class ScrollArrow : public BView { @@ -57,6 +57,26 @@ public: }; +class LeftScrollArrow : public ScrollArrow { +public: + LeftScrollArrow(BRect frame); + virtual ~LeftScrollArrow(); + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); +}; + + +class RightScrollArrow : public ScrollArrow { +public: + RightScrollArrow(BRect frame); + virtual ~RightScrollArrow(); + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); +}; + + // #pragma mark - @@ -102,7 +122,6 @@ UpScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); - // Draw the upper arrow. if (IsEnabled()) SetHighColor(0, 0, 0); else { @@ -113,9 +132,9 @@ UpScrollArrow::Draw(BRect updateRect) FillRect(Bounds(), B_SOLID_LOW); float middle = Bounds().right / 2; - FillTriangle(BPoint(middle, (kScrollerHeight / 2) - 3), - BPoint(middle + 5, (kScrollerHeight / 2) + 2), - BPoint(middle - 5, (kScrollerHeight / 2) + 2)); + FillTriangle(BPoint(middle, (kScrollerDimension / 2) - 3), + BPoint(middle + 5, (kScrollerDimension / 2) + 2), + BPoint(middle - 5, (kScrollerDimension / 2) + 2)); } @@ -154,7 +173,6 @@ DownScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); - // Draw the lower arrow. if (IsEnabled()) SetHighColor(0, 0, 0); else { @@ -166,9 +184,9 @@ DownScrollArrow::Draw(BRect updateRect) FillRect(frame, B_SOLID_LOW); float middle = Bounds().right / 2; - FillTriangle(BPoint(middle, frame.bottom - (kScrollerHeight / 2) + 3), - BPoint(middle + 5, frame.bottom - (kScrollerHeight / 2) - 2), - BPoint(middle - 5, frame.bottom - (kScrollerHeight / 2) - 2)); + FillTriangle(BPoint(middle, frame.bottom - (kScrollerDimension / 2) + 3), + BPoint(middle + 5, frame.bottom - (kScrollerDimension / 2) - 2), + BPoint(middle - 5, frame.bottom - (kScrollerDimension / 2) - 2)); } @@ -191,7 +209,112 @@ DownScrollArrow::MouseDown(BPoint where) // #pragma mark - -TInlineScrollView::TInlineScrollView(BRect frame, BView* target) +LeftScrollArrow::LeftScrollArrow(BRect frame) + : + ScrollArrow(frame) +{ +} + + +LeftScrollArrow::~LeftScrollArrow() +{ +} + + +void +LeftScrollArrow::Draw(BRect updateRect) +{ + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + + if (IsEnabled()) + SetHighColor(0, 0, 0); + else { + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + } + + FillRect(Bounds(), B_SOLID_LOW); + + float middle = Bounds().bottom / 2; + FillTriangle(BPoint((kScrollerDimension / 2) - 3, middle), + BPoint((kScrollerDimension / 2) + 2, middle + 5), + BPoint((kScrollerDimension / 2) + 2, middle - 5)); +} + + +void +LeftScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + TInlineScrollView* parent = dynamic_cast(Parent()); + + if (parent != NULL) { + parent->ScrollBy(-kDefaultScrollStep); + snooze(5000); + } +} + + +// #pragma mark - + + +RightScrollArrow::RightScrollArrow(BRect frame) + : + ScrollArrow(frame) +{ +} + + +RightScrollArrow::~RightScrollArrow() +{ +} + + +void +RightScrollArrow::Draw(BRect updateRect) +{ + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + + if (IsEnabled()) + SetHighColor(0, 0, 0); + else { + SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + } + + BRect frame = Bounds(); + FillRect(frame, B_SOLID_LOW); + + float middle = Bounds().bottom / 2; + FillTriangle(BPoint(frame.bottom - (kScrollerDimension / 2) + 3, middle), + BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle + 5), + BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle - 5)); +} + + +void +RightScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + TInlineScrollView* grandparent + = dynamic_cast(Parent()->Parent()); + + if (grandparent != NULL) { + grandparent->ScrollBy(kDefaultScrollStep); + snooze(5000); + } +} + + +// #pragma mark - + + +TInlineScrollView::TInlineScrollView(BRect frame, BView* target, + enum orientation orientation) : BView(frame, "inline scroll view", B_FOLLOW_NONE, 0), fTarget(target), @@ -262,7 +385,7 @@ TInlineScrollView::AttachScrollers() BRect screenFrame = (BScreen(Window())).Frame(); if (HasScrollers()) { - fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension - screenFrame.bottom; return; } @@ -271,23 +394,23 @@ TInlineScrollView::AttachScrollers() if (fUpperScrollArrow == NULL) { fUpperScrollArrow = new UpScrollArrow( - BRect(0, 0, frame.right, kScrollerHeight - 1)); + BRect(0, 0, frame.right, kScrollerDimension - 1)); AddChild(fUpperScrollArrow); } if (fLowerScrollArrow == NULL) { fLowerScrollArrow = new DownScrollArrow( - BRect(0, frame.bottom - 2 * kScrollerHeight + 1, frame.right, - frame.bottom - kScrollerHeight)); + BRect(0, frame.bottom - 2 * kScrollerDimension + 1, frame.right, + frame.bottom - kScrollerDimension)); fTarget->AddChild(fLowerScrollArrow); } - fTarget->MoveBy(0, kScrollerHeight); + fTarget->MoveBy(0, kScrollerDimension); fUpperScrollArrow->SetEnabled(false); fLowerScrollArrow->SetEnabled(true); - fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension - screenFrame.bottom; fValue = 0; } @@ -314,7 +437,7 @@ TInlineScrollView::DetachScrollers() if (fTarget) { // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. - fTarget->MoveBy(0, -kScrollerHeight); + fTarget->MoveBy(0, -kScrollerDimension); fTarget->ScrollTo(0, 0); fValue = 0; } diff --git a/src/apps/deskbar/InlineScrollView.h b/src/apps/deskbar/InlineScrollView.h index db6581db82..82d53ba680 100644 --- a/src/apps/deskbar/InlineScrollView.h +++ b/src/apps/deskbar/InlineScrollView.h @@ -20,7 +20,8 @@ class BPoint; class TInlineScrollView : public BView { public: - TInlineScrollView(BRect frame, BView* target); + TInlineScrollView(BRect frame, BView* target, + enum orientation orientation = B_VERTICAL); virtual ~TInlineScrollView(); virtual void AttachedToWindow(); From e6d8c22a7d78f0e47be55db2338083ada4766b2a Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 26 Jul 2012 02:02:50 -0400 Subject: [PATCH 23/66] WIP: Add support for horizontal scrolling. --- src/apps/deskbar/BarView.cpp | 24 +++- src/apps/deskbar/BarView.h | 2 + src/apps/deskbar/ExpandoMenuBar.cpp | 14 +- src/apps/deskbar/InlineScrollView.cpp | 200 ++++++++++++++++---------- src/apps/deskbar/InlineScrollView.h | 14 +- 5 files changed, 167 insertions(+), 87 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index ab0f1e24c2..b0b620c847 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -504,7 +504,10 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando); + fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando, + fVertical ? expandoFrame.top : expandoFrame.left, + fVertical ? screenFrame.bottom : expandoFrame.right, + fVertical ? B_VERTICAL : B_HORIZONTAL); AddChild(fInlineScrollView); if (fVertical) @@ -575,12 +578,7 @@ TBarView::SizeWindow(BRect screenFrame) GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight); Window()->ResizeTo(windowWidth, windowHeight); - if (fExpando != NULL) { - if (fExpando->CheckForSizeOverrun()) - fInlineScrollView->AttachScrollers(); - else - fInlineScrollView->DetachScrollers(); - } + CheckForScrolling(); } @@ -607,6 +605,18 @@ TBarView::PositionWindow(BRect screenFrame) } +void +TBarView::CheckForScrolling() +{ + if (fExpando != NULL) { + if (fExpando->CheckForSizeOverrun()) + fInlineScrollView->AttachScrollers(); + else + fInlineScrollView->DetachScrollers(); + } +} + + void TBarView::SaveSettings() { diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index cebb819060..d04586775e 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -148,6 +148,8 @@ class TBarView : public BView { void PositionWindow(BRect screenFrame); void AddExpandedItem(const char* signature); + void CheckForScrolling(); + TExpandoMenuBar* ExpandoMenuBar() const; TBarMenuBar* BarMenuBar() const; TDragRegion* DragRegion() const { return fDragRegion; } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 5a723b0ab5..b395d1e1e2 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -734,6 +734,9 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) if (newWidth > maxContentWidth) newWidth = maxContentWidth; + if (newWidth < iconOnlyWidth) + newWidth = iconOnlyWidth; + if (reset) { SetMaxContentWidth(newWidth); if (newWidth == maxContentWidth) @@ -755,6 +758,8 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) Invalidate(); Window()->UpdateIfNeeded(); } + + fBarView->CheckForScrolling(); } @@ -815,11 +820,12 @@ TExpandoMenuBar::DrawBackground(BRect) bool TExpandoMenuBar::CheckForSizeOverrun() { - if (!fVertical) - return false; - BRect screenFrame = (BScreen(Window())).Frame(); - return Window()->Frame().bottom > screenFrame.bottom; + + if (fVertical) + return Window()->Frame().bottom > screenFrame.bottom; + else + return Frame().right > fBarView->DragRegion()->Frame().left; } diff --git a/src/apps/deskbar/InlineScrollView.cpp b/src/apps/deskbar/InlineScrollView.cpp index c44aeedcb5..0a44188e3d 100644 --- a/src/apps/deskbar/InlineScrollView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -288,9 +288,9 @@ RightScrollArrow::Draw(BRect updateRect) FillRect(frame, B_SOLID_LOW); float middle = Bounds().bottom / 2; - FillTriangle(BPoint(frame.bottom - (kScrollerDimension / 2) + 3, middle), - BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle + 5), - BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle - 5)); + FillTriangle(BPoint(kScrollerDimension / 2 + 3, middle), + BPoint(kScrollerDimension / 2 - 2, middle + 5), + BPoint(kScrollerDimension / 2 - 2, middle - 5)); } @@ -314,31 +314,34 @@ RightScrollArrow::MouseDown(BPoint where) TInlineScrollView::TInlineScrollView(BRect frame, BView* target, - enum orientation orientation) + float beginLimit, float endLimit, enum orientation orientation) : BView(frame, "inline scroll view", B_FOLLOW_NONE, 0), fTarget(target), - fUpperScrollArrow(NULL), - fLowerScrollArrow(NULL), + fBeginScrollArrow(NULL), + fEndScrollArrow(NULL), fScrollStep(kDefaultScrollStep), - fValue(0), - fLimit(0) + fScrollValue(0), + fScrollLimit(0), + fBeginLimit(beginLimit), + fEndLimit(endLimit), + fOrientation(orientation) { } TInlineScrollView::~TInlineScrollView() { - if (fUpperScrollArrow != NULL) { - fUpperScrollArrow->RemoveSelf(); - delete fUpperScrollArrow; - fUpperScrollArrow = NULL; + if (fBeginScrollArrow != NULL) { + fBeginScrollArrow->RemoveSelf(); + delete fBeginScrollArrow; + fBeginScrollArrow = NULL; } - if (fLowerScrollArrow != NULL) { - fLowerScrollArrow->RemoveSelf(); - delete fLowerScrollArrow; - fLowerScrollArrow = NULL; + if (fEndScrollArrow != NULL) { + fEndScrollArrow->RemoveSelf(); + delete fEndScrollArrow; + fEndScrollArrow = NULL; } } @@ -364,11 +367,11 @@ TInlineScrollView::DetachedFromWindow() if (fTarget != NULL) fTarget->RemoveSelf(); - if (fUpperScrollArrow != NULL) - fUpperScrollArrow->RemoveSelf(); + if (fBeginScrollArrow != NULL) + fBeginScrollArrow->RemoveSelf(); - if (fLowerScrollArrow != NULL) - fLowerScrollArrow->RemoveSelf(); + if (fEndScrollArrow != NULL) + fEndScrollArrow->RemoveSelf(); } @@ -382,37 +385,64 @@ TInlineScrollView::AttachScrollers() return; BRect frame = Bounds(); - BRect screenFrame = (BScreen(Window())).Frame(); if (HasScrollers()) { - fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension - - screenFrame.bottom; + if (fOrientation == B_VERTICAL) { + fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension + - fEndLimit; + } else { + fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension + - fEndLimit; + } return; } fTarget->MakeFocus(true); - if (fUpperScrollArrow == NULL) { - fUpperScrollArrow = new UpScrollArrow( - BRect(0, 0, frame.right, kScrollerDimension - 1)); - AddChild(fUpperScrollArrow); + if (fOrientation == B_VERTICAL) { + if (fBeginScrollArrow == NULL) { + fBeginScrollArrow = new UpScrollArrow( + BRect(frame.left, frame.top, frame.right, + kScrollerDimension - 1)); + AddChild(fBeginScrollArrow); + } + + if (fEndScrollArrow == NULL) { + fEndScrollArrow = new DownScrollArrow( + BRect(0, frame.bottom - 2 * kScrollerDimension + 1, frame.right, + frame.bottom - kScrollerDimension)); + fTarget->AddChild(fEndScrollArrow); + } + + fTarget->MoveBy(0, kScrollerDimension); + + fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension + - fEndLimit; + } else { + if (fBeginScrollArrow == NULL) { + fBeginScrollArrow = new LeftScrollArrow( + BRect(frame.left, frame.top, + frame.left + kScrollerDimension - 1, frame.bottom)); + AddChild(fBeginScrollArrow); + } + + if (fEndScrollArrow == NULL) { + fEndScrollArrow = new RightScrollArrow( + BRect(frame.right - 2 * kScrollerDimension + 1, frame.top, + frame.right, frame.bottom)); + fTarget->AddChild(fEndScrollArrow); + } + + fTarget->MoveBy(kScrollerDimension, 0); + + fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension + - fEndLimit; } - if (fLowerScrollArrow == NULL) { - fLowerScrollArrow = new DownScrollArrow( - BRect(0, frame.bottom - 2 * kScrollerDimension + 1, frame.right, - frame.bottom - kScrollerDimension)); - fTarget->AddChild(fLowerScrollArrow); - } + fBeginScrollArrow->SetEnabled(false); + fEndScrollArrow->SetEnabled(true); - fTarget->MoveBy(0, kScrollerDimension); - - fUpperScrollArrow->SetEnabled(false); - fLowerScrollArrow->SetEnabled(true); - - fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension - - screenFrame.bottom; - fValue = 0; + fScrollValue = 0; } @@ -422,24 +452,28 @@ TInlineScrollView::DetachScrollers() if (!HasScrollers()) return; - if (fLowerScrollArrow) { - fLowerScrollArrow->RemoveSelf(); - delete fLowerScrollArrow; - fLowerScrollArrow = NULL; + if (fEndScrollArrow) { + fEndScrollArrow->RemoveSelf(); + delete fEndScrollArrow; + fEndScrollArrow = NULL; } - if (fUpperScrollArrow) { - fUpperScrollArrow->RemoveSelf(); - delete fUpperScrollArrow; - fUpperScrollArrow = NULL; + if (fBeginScrollArrow) { + fBeginScrollArrow->RemoveSelf(); + delete fBeginScrollArrow; + fBeginScrollArrow = NULL; } if (fTarget) { // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. - fTarget->MoveBy(0, -kScrollerDimension); + if (fOrientation == B_VERTICAL) + fTarget->MoveBy(0, -kScrollerDimension); + else + fTarget->MoveBy(-kScrollerDimension, 0); + fTarget->ScrollTo(0, 0); - fValue = 0; + fScrollValue = 0; } } @@ -447,7 +481,7 @@ TInlineScrollView::DetachScrollers() bool TInlineScrollView::HasScrollers() const { - return fTarget != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL; + return fTarget != NULL && fBeginScrollArrow != NULL && fEndScrollArrow != NULL; } @@ -479,33 +513,55 @@ TInlineScrollView::ScrollBy(const float& step) return; if (step > 0) { - if (fValue == 0) - fUpperScrollArrow->SetEnabled(true); + if (fScrollValue == 0) + fBeginScrollArrow->SetEnabled(true); - if (fValue + step >= fLimit) { + if (fScrollValue + step >= fScrollLimit) { // If we reached the limit, only scroll to the end - fTarget->ScrollBy(0, fLimit - fValue); - fLowerScrollArrow->MoveBy(0, fLimit - fValue); - fLowerScrollArrow->SetEnabled(false); - fValue = fLimit; + if (fOrientation == B_VERTICAL) { + fTarget->ScrollBy(0, fScrollLimit - fScrollValue); + fEndScrollArrow->MoveBy(0, fScrollLimit - fScrollValue); + } else { + fTarget->ScrollBy(fScrollLimit - fScrollValue, 0); + fEndScrollArrow->MoveBy(fScrollLimit - fScrollValue, 0); + } + fEndScrollArrow->SetEnabled(false); + fScrollValue = fScrollLimit; } else { - fTarget->ScrollBy(0, step); - fLowerScrollArrow->MoveBy(0, step); - fValue += step; + if (fOrientation == B_VERTICAL) { + fTarget->ScrollBy(0, step); + fEndScrollArrow->MoveBy(0, step); + } else { + fTarget->ScrollBy(step, 0); + fEndScrollArrow->MoveBy(step, 0); + } + fScrollValue += step; } } else if (step < 0) { - if (fValue == fLimit) - fLowerScrollArrow->SetEnabled(true); + if (fScrollValue == fScrollLimit) + fEndScrollArrow->SetEnabled(true); - if (fValue + step <= 0) { - fTarget->ScrollBy(0, -fValue); - fLowerScrollArrow->MoveBy(0, -fValue); - fUpperScrollArrow->SetEnabled(false); - fValue = 0; + if (fScrollValue + step <= 0) { + if (fOrientation == B_VERTICAL) { + fTarget->ScrollBy(0, -fScrollValue); + fEndScrollArrow->MoveBy(0, -fScrollValue); + } else { + fTarget->ScrollBy(-fScrollValue, 0); + fEndScrollArrow->MoveBy(-fScrollValue, 0); + } + fBeginScrollArrow->SetEnabled(false); + fScrollValue = 0; } else { - fTarget->ScrollBy(0, step); - fLowerScrollArrow->MoveBy(0, step); - fValue += step; + if (fOrientation == B_VERTICAL) { + fTarget->ScrollBy(0, step); + fEndScrollArrow->MoveBy(0, step); + } else { + fTarget->ScrollBy(step, 0); + fEndScrollArrow->MoveBy(step, 0); + } + fScrollValue += step; } } + + //fTarget->Invalidate(); } diff --git a/src/apps/deskbar/InlineScrollView.h b/src/apps/deskbar/InlineScrollView.h index 82d53ba680..74dc97010b 100644 --- a/src/apps/deskbar/InlineScrollView.h +++ b/src/apps/deskbar/InlineScrollView.h @@ -21,6 +21,7 @@ class BPoint; class TInlineScrollView : public BView { public: TInlineScrollView(BRect frame, BView* target, + float beginLimit, float endLimit, enum orientation orientation = B_VERTICAL); virtual ~TInlineScrollView(); @@ -37,12 +38,17 @@ public: private: BView* fTarget; - ScrollArrow* fUpperScrollArrow; - ScrollArrow* fLowerScrollArrow; + ScrollArrow* fBeginScrollArrow; + ScrollArrow* fEndScrollArrow; float fScrollStep; - float fValue; - float fLimit; + float fScrollValue; + float fScrollLimit; + + float fBeginLimit; + float fEndLimit; + + int32 fOrientation; }; From c07e6ff292cbe19ab758ce8bcb6c5cde38a3e662 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 26 Oct 2012 02:00:29 -0400 Subject: [PATCH 24/66] Make horizontal scrolling work in Deskbar * Split the Leaf menu and seperator into their own menubar. * I got rid of a lot of special cases for horizontal in the ExpandoMenuBar class because now the menubar contains the same items as in vertical mode. However, it also means that the dreaded bug also affects horizontal mode. * Make the application menubar resize itself even in horizontal mode. This means that the view background shows through so I'm going to have to fix this up. * Calculate when to add the scroll arrows and how much to allow the user to scroll by for horizontal. CheckItemSizes() got a big refactoring. * Rework the InlineScrollView class a bit. It no longer requires you to specify the begin and end limits on construction because it can calculate them instead. It also no longer depends on the screen at all, this means this class can be extened to be used more generally and in more places. --- src/apps/deskbar/BarMenuBar.cpp | 50 +++++++++- src/apps/deskbar/BarMenuBar.h | 4 + src/apps/deskbar/BarView.cpp | 50 +++++----- src/apps/deskbar/ExpandoMenuBar.cpp | 128 +++++++++++--------------- src/apps/deskbar/ExpandoMenuBar.h | 5 +- src/apps/deskbar/InlineScrollView.cpp | 20 ++-- src/apps/deskbar/InlineScrollView.h | 13 +-- src/apps/deskbar/TeamMenuItem.cpp | 2 +- 8 files changed, 144 insertions(+), 128 deletions(-) diff --git a/src/apps/deskbar/BarMenuBar.cpp b/src/apps/deskbar/BarMenuBar.cpp index bd093ae8e6..ae3689fb0c 100644 --- a/src/apps/deskbar/BarMenuBar.cpp +++ b/src/apps/deskbar/BarMenuBar.cpp @@ -51,6 +51,8 @@ All rights reserved. #include "TeamMenu.h" +const float kSepItemWidth = 5.0f; + TBarMenuBar::TBarMenuBar(TBarView* bar, BRect frame, const char* name) : BMenuBar(frame, name, B_FOLLOW_NONE, B_ITEMS_IN_ROW, false), fBarView(bar), @@ -86,11 +88,15 @@ TBarMenuBar::SmartResize(float width, float height) width -= 1; - int32 count = CountItems(); - if (fDeskbarMenuItem) - fDeskbarMenuItem->SetWidthHeight(width / count, height); - if (fAppListMenuItem) - fAppListMenuItem->SetWidthHeight(width / count, height); + if (fSeparatorItem) + fDeskbarMenuItem->SetWidthHeight(width - kSepItemWidth, height); + else { + int32 count = CountItems(); + if (fDeskbarMenuItem) + fDeskbarMenuItem->SetWidthHeight(width / count, height); + if (fAppListMenuItem) + fAppListMenuItem->SetWidthHeight(width / count, height); + } InvalidateLayout(); } @@ -129,6 +135,40 @@ TBarMenuBar::RemoveTeamMenu() } +void +TBarMenuBar::AddSeperatorItem() +{ + if (CountItems() > 1) + return; + + BRect frame(Frame()); + delete fSeparatorItem; + + fSeparatorItem = new TTeamMenuItem(kSepItemWidth, + frame.Height() - 2, false); + AddItem(fSeparatorItem); + fSeparatorItem->SetEnabled(false); + SmartResize(frame.Width() - 1.0f, frame.Height()); +} + + +void +TBarMenuBar::RemoveSeperatorItem() +{ + if (CountItems() < 2) + return; + + if (fSeparatorItem) { + RemoveItem((BMenuItem*)fSeparatorItem); + delete fSeparatorItem; + fSeparatorItem = NULL; + } + + BRect frame = Frame(); + SmartResize(frame.Width(), frame.Height()); +} + + void TBarMenuBar::Draw(BRect rect) { diff --git a/src/apps/deskbar/BarMenuBar.h b/src/apps/deskbar/BarMenuBar.h index a10630dbfc..f691a903a5 100644 --- a/src/apps/deskbar/BarMenuBar.h +++ b/src/apps/deskbar/BarMenuBar.h @@ -63,6 +63,9 @@ class TBarMenuBar : public BMenuBar { void AddTeamMenu(); void RemoveTeamMenu(); + void AddSeperatorItem(); + void RemoveSeperatorItem(); + void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state, bool both = false); @@ -70,6 +73,7 @@ class TBarMenuBar : public BMenuBar { TBarView* fBarView; TBarMenuTitle* fDeskbarMenuItem; TBarMenuTitle* fAppListMenuItem; + TTeamMenuItem* fSeparatorItem; }; diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index b0b620c847..94a256c6cf 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -42,6 +42,7 @@ All rights reserved. #include #include +#include #include #include #include @@ -71,6 +72,7 @@ const int32 kDefaultRecentAppCount = 10; const int32 kMenuTrackMargin = 20; const uint32 kUpdateOrientation = 'UpOr'; +const float kSepItemWidth = 5.0f; class BarViewMessageFilter : public BMessageFilter @@ -349,49 +351,47 @@ TBarView::MouseDown(BPoint where) void TBarView::PlaceDeskbarMenu() { - // top or bottom, full - if (!fVertical && fBarMenuBar != NULL) { - fBarMenuBar->RemoveSelf(); - delete fBarMenuBar; - fBarMenuBar = NULL; + // Calculate the size of the deskbar menu + BRect menuFrame(Bounds()); + if (fVertical) + menuFrame.bottom = menuFrame.top + kMenuBarHeight; + else { + menuFrame.bottom = menuFrame.top + + static_cast(be_app)->IconSize() + 4; } - // top or bottom expando mode has Be menu built in for tracking - // only for vertical mini or expanded - // mini mode will have team menu added as part of BarMenuBar - if (fVertical && fBarMenuBar == NULL) { + if (fBarMenuBar == NULL) { // create the Be menu - BRect mbarFrame(Bounds()); - mbarFrame.bottom = mbarFrame.top + kMenuBarHeight; - fBarMenuBar = new TBarMenuBar(this, mbarFrame, "BarMenuBar"); + fBarMenuBar = new TBarMenuBar(this, menuFrame, "BarMenuBar"); AddChild(fBarMenuBar); } - // if there isn't a bemenu at this point, - // DB should be in top/bottom mode, else error - if (fBarMenuBar == NULL) - return; - float width = sMinimumWindowWidth; BPoint loc(B_ORIGIN); - BRect menuFrame(fBarMenuBar->Frame()); if (fState == kFullState) { fBarMenuBar->RemoveTeamMenu(); + fBarMenuBar->RemoveSeperatorItem(); // TODO: Magic constants need explanation width = 8 + 16 + 8; + fBarMenuBar->SmartResize(width, menuFrame.Height()); loc = Bounds().LeftTop(); } else if (fState == kExpandoState) { - // shows apps below tray fBarMenuBar->RemoveTeamMenu(); - if (fVertical) + if (fVertical) { + // shows apps below tray + fBarMenuBar->RemoveSeperatorItem(); width += 1; - else - width = floorf(width) / 2; + } else { + // shows apps to the right of bemenu + fBarMenuBar->AddSeperatorItem(); + width = floorf(width) / 2 + kSepItemWidth; + } loc = Bounds().LeftTop(); } else { // mini mode, DeskbarMenu next to team menu fBarMenuBar->AddTeamMenu(); + fBarMenuBar->RemoveSeperatorItem(); } fBarMenuBar->SmartResize(width, menuFrame.Height()); @@ -491,6 +491,10 @@ TBarView::PlaceApplicationBar() expandoFrame.top = 0; int32 iconSize = static_cast(be_app)->IconSize(); expandoFrame.bottom = iconSize + 4; + + if (fBarMenuBar != NULL) + expandoFrame.left = fBarMenuBar->Frame().Width(); + if (fTrayLocation != 0) expandoFrame.right = fDragRegion->Frame().left - 1; else @@ -505,8 +509,6 @@ TBarView::PlaceApplicationBar() fVertical, !hideLabels && fState != kFullState); fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando, - fVertical ? expandoFrame.top : expandoFrame.left, - fVertical ? screenFrame.bottom : expandoFrame.right, fVertical ? B_VERTICAL : B_HORIZONTAL); AddChild(fInlineScrollView); diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index b395d1e1e2..a4561ee7de 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -79,7 +79,7 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, bool vertical, bool drawLabel) : BMenuBar(frame, name, B_FOLLOW_NONE, - vertical ? B_ITEMS_IN_COLUMN : B_ITEMS_IN_ROW, vertical), + vertical ? B_ITEMS_IN_COLUMN : B_ITEMS_IN_ROW), fVertical(vertical), fOverflow(false), fDrawLabel(drawLabel), @@ -87,7 +87,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, fExpandNewTeams(static_cast(be_app)->Settings()->expandNewTeams), fDeskbarMenuWidth(kDefaultDeskbarMenuWidth), fBarView(bar), - fFirstApp(0), fPreviousDragTargetItem(NULL), fLastClickItem(NULL) { @@ -137,24 +136,10 @@ TExpandoMenuBar::AttachedToWindow() // top or bottom mode, add deskbar menu and sep for menubar tracking // consistency if (!fVertical) { - TDeskbarMenu* beMenu = new TDeskbarMenu(fBarView); - TBarWindow::SetDeskbarMenu(beMenu); const BBitmap* logoBitmap = AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_LeafLogoBitmap); if (logoBitmap != NULL) fDeskbarMenuWidth = logoBitmap->Bounds().Width() + 16; - - fDeskbarMenuItem = new TBarMenuTitle(fDeskbarMenuWidth, - Frame().Height(), logoBitmap, beMenu, true); - AddItem(fDeskbarMenuItem); - - fSeparatorItem = new TTeamMenuItem(kSepItemWidth, itemHeight, fVertical); - AddItem(fSeparatorItem); - fSeparatorItem->SetEnabled(false); - fFirstApp = 2; - } else { - fDeskbarMenuItem = NULL; - fSeparatorItem = NULL; } if (settings->sortRunningApps) @@ -169,7 +154,7 @@ TExpandoMenuBar::AttachedToWindow() && !strcmp(barInfo->sig, kTrackerSignature)) { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, barInfo->name, barInfo->sig, itemWidth, itemHeight, - fDrawLabel, fVertical), fFirstApp); + fDrawLabel, fVertical), 0); } else { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, barInfo->name, barInfo->sig, itemWidth, itemHeight, @@ -526,20 +511,15 @@ TExpandoMenuBar::MouseUp(BPoint where) bool TExpandoMenuBar::InDeskbarMenu(BPoint loc) const { - if (!fVertical) { - if (fDeskbarMenuItem && fDeskbarMenuItem->Frame().Contains(loc)) - return true; - } else { - TBarWindow* window = dynamic_cast(Window()); - if (window) { - if (TDeskbarMenu* bemenu = window->DeskbarMenu()) { - bool inDeskbarMenu = false; - if (bemenu->LockLooper()) { - inDeskbarMenu = bemenu->Frame().Contains(loc); - bemenu->UnlockLooper(); - } - return inDeskbarMenu; + TBarWindow* window = dynamic_cast(Window()); + if (window) { + if (TDeskbarMenu* bemenu = window->DeskbarMenu()) { + bool inDeskbarMenu = false; + if (bemenu->LockLooper()) { + inDeskbarMenu = bemenu->Frame().Contains(loc); + bemenu->UnlockLooper(); } + return inDeskbarMenu; } } @@ -558,7 +538,7 @@ TExpandoMenuBar::TeamItemAtPoint(BPoint point, BMenuItem** _item) TTeamMenuItem* lastApp = NULL; int32 count = CountItems(); - for (int32 i = fFirstApp; i < count; i++) { + for (int32 i = 0; i < count; i++) { BMenuItem* item = ItemAt(i); if (dynamic_cast(item) != NULL) @@ -604,11 +584,11 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name, itemWidth, itemHeight, fDrawLabel, fVertical); if (settings->trackerAlwaysFirst && !strcmp(signature, kTrackerSignature)) - AddItem(item, fFirstApp); + AddItem(item, 0); else if (settings->sortRunningApps) { TTeamMenuItem* teamItem - = dynamic_cast(ItemAt(fFirstApp)); - int32 firstApp = fFirstApp; + = dynamic_cast(ItemAt(0)); + int32 firstApp = 0; // if Tracker should always be the first item, we need to skip it // when sorting in the current item @@ -648,7 +628,7 @@ void TExpandoMenuBar::AddTeam(team_id team, const char* signature) { int32 count = CountItems(); - for (int32 i = fFirstApp; i < count; i++) { + for (int32 i = 0; i < count; i++) { // Only add to team menu items if (TTeamMenuItem* item = dynamic_cast(ItemAt(i))) { if (strcasecmp(item->Signature(), signature) == 0) { @@ -665,7 +645,7 @@ void TExpandoMenuBar::RemoveTeam(team_id team, bool partial) { int32 count = CountItems(); - for (int32 i = fFirstApp; i < count; i++) { + for (int32 i = 0; i < count; i++) { if (TTeamMenuItem* item = dynamic_cast(ItemAt(i))) { if (item->Teams()->HasItem((void*)team)) { item->Teams()->RemoveItem(team); @@ -698,61 +678,51 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) if (fBarView->Vertical()) return; + float maxWidth = fBarView->DragRegion()->Frame().left + - fDeskbarMenuWidth - kSepItemWidth; int32 iconSize = static_cast(be_app)->IconSize(); - float maxContentWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize; - - // There are 2 extra items: - // The Be Menu - // The little separator item - int32 count = CountItems() - 2; - float maxWidth = Frame().Width() - fDeskbarMenuWidth - kSepItemWidth * 2; - float fullWidth = maxContentWidth * count + fDeskbarMenuWidth - + kSepItemWidth; float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; + float minItemWidth = fDrawLabel ? iconOnlyWidth + fDeskbarMenuWidth + : iconOnlyWidth; + float maxItemWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize; + float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth + + kSepItemWidth; bool reset = false; float newWidth = 0.0f; - if (delta >= 0 && fullWidth > maxWidth) { + if (delta >= 0 && menuWidth > maxWidth) { fOverflow = true; reset = true; - if (fDrawLabel) - newWidth = floorf(maxWidth / count); - else - newWidth = iconOnlyWidth; + newWidth = floorf(maxWidth / CountItems()); } else if (delta < 0 && fOverflow) { reset = true; - if (fullWidth > maxWidth) { - if (fDrawLabel) - newWidth = floorf(maxWidth / count); - else - newWidth = iconOnlyWidth; - } else - newWidth = maxContentWidth; + if (menuWidth > maxWidth) + newWidth = floorf(maxWidth / CountItems()); + else + newWidth = maxItemWidth; } - if (newWidth > maxContentWidth) - newWidth = maxContentWidth; - - if (newWidth < iconOnlyWidth) - newWidth = iconOnlyWidth; + if (newWidth > maxItemWidth) + newWidth = maxItemWidth; + else if (newWidth < minItemWidth) + newWidth = minItemWidth; if (reset) { SetMaxContentWidth(newWidth); - if (newWidth == maxContentWidth) + if (newWidth == maxItemWidth) fOverflow = false; InvalidateLayout(); - for (int32 index = fFirstApp; ; index++) { + for (int32 index = 0; ; index++) { TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index); if (!item) break; - if (!fDrawLabel && newWidth > iconOnlyWidth) { + if (!fDrawLabel && newWidth > iconOnlyWidth) item->SetOverrideWidth(iconOnlyWidth); - } else { + else item->SetOverrideWidth(newWidth); - } } Invalidate(); @@ -788,9 +758,9 @@ TExpandoMenuBar::DrawBackground(BRect) rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT); - int32 last = CountItems() - 1; - if (last >= 0) - bounds.left = ItemAt(last)->Frame().right + 1; + int32 count = CountItems() - 1; + if (count >= 0) + bounds.left = ItemAt(count)->Frame().right + 1; else bounds.left = 0; @@ -820,12 +790,20 @@ TExpandoMenuBar::DrawBackground(BRect) bool TExpandoMenuBar::CheckForSizeOverrun() { - BRect screenFrame = (BScreen(Window())).Frame(); - - if (fVertical) + if (fVertical) { + BRect screenFrame = (BScreen(Window())).Frame(); return Window()->Frame().bottom > screenFrame.bottom; - else - return Frame().right > fBarView->DragRegion()->Frame().left; + } + + // horizontal + int32 count = CountItems() - 1; + if (count < 0) + return false; + + float menuWidth = ItemAt(count)->Frame().right + fDeskbarMenuWidth + + kSepItemWidth + 1; + float maxWidth = fBarView->DragRegion()->Frame().left - 1; + return menuWidth > maxWidth; } diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index 5a08a0b67e..79f628cda8 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -104,11 +104,8 @@ class TExpandoMenuBar : public BMenuBar { float fDeskbarMenuWidth; TBarView* fBarView; - int32 fFirstApp; - TBarMenuTitle* fDeskbarMenuItem; - TTeamMenuItem* fSeparatorItem; - TTeamMenuItem* fPreviousDragTargetItem; + TTeamMenuItem* fPreviousDragTargetItem; TTeamMenuItem* fLastMousedOverItem; BMenuItem* fLastClickItem; diff --git a/src/apps/deskbar/InlineScrollView.cpp b/src/apps/deskbar/InlineScrollView.cpp index 0a44188e3d..ab3ef7a913 100644 --- a/src/apps/deskbar/InlineScrollView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -314,7 +314,7 @@ RightScrollArrow::MouseDown(BPoint where) TInlineScrollView::TInlineScrollView(BRect frame, BView* target, - float beginLimit, float endLimit, enum orientation orientation) + enum orientation orientation) : BView(frame, "inline scroll view", B_FOLLOW_NONE, 0), fTarget(target), @@ -323,8 +323,6 @@ TInlineScrollView::TInlineScrollView(BRect frame, BView* target, fScrollStep(kDefaultScrollStep), fScrollValue(0), fScrollLimit(0), - fBeginLimit(beginLimit), - fEndLimit(endLimit), fOrientation(orientation) { } @@ -388,11 +386,11 @@ TInlineScrollView::AttachScrollers() if (HasScrollers()) { if (fOrientation == B_VERTICAL) { - fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension - - fEndLimit; + fScrollLimit = fTarget->Bounds().Height() + - (frame.Height() - 2 * kScrollerDimension); } else { - fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension - - fEndLimit; + fScrollLimit = fTarget->Bounds().Width() + - (frame.Width() - 2 * kScrollerDimension); } return; } @@ -416,8 +414,8 @@ TInlineScrollView::AttachScrollers() fTarget->MoveBy(0, kScrollerDimension); - fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension - - fEndLimit; + fScrollLimit = fTarget->Bounds().Height() + - (frame.Height() - 2 * kScrollerDimension); } else { if (fBeginScrollArrow == NULL) { fBeginScrollArrow = new LeftScrollArrow( @@ -435,8 +433,8 @@ TInlineScrollView::AttachScrollers() fTarget->MoveBy(kScrollerDimension, 0); - fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension - - fEndLimit; + fScrollLimit = fTarget->Bounds().Width() + - (frame.Width() - 2 * kScrollerDimension); } fBeginScrollArrow->SetEnabled(false); diff --git a/src/apps/deskbar/InlineScrollView.h b/src/apps/deskbar/InlineScrollView.h index 74dc97010b..e483e0e2f8 100644 --- a/src/apps/deskbar/InlineScrollView.h +++ b/src/apps/deskbar/InlineScrollView.h @@ -13,15 +13,14 @@ #include -class BLayout; -class ScrollArrow; -class BPoint; +class BLayout; +class BPoint; +class ScrollArrow; class TInlineScrollView : public BView { public: TInlineScrollView(BRect frame, BView* target, - float beginLimit, float endLimit, enum orientation orientation = B_VERTICAL); virtual ~TInlineScrollView(); @@ -33,7 +32,8 @@ public: bool HasScrollers() const; void SetSmallStep(float step); - void GetSteps(float* _smallStep, float* _largeStep) const; + void GetSteps(float* _smallStep, + float* _largeStep) const; void ScrollBy(const float& step); private: @@ -45,9 +45,6 @@ private: float fScrollValue; float fScrollLimit; - float fBeginLimit; - float fEndLimit; - int32 fOrientation; }; diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index dd0e07347c..1d33cf66a1 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -240,7 +240,7 @@ TTeamMenuItem::GetContentSize(float* width, float* height) if (fDrawLabel && iconBounds.Width() > 32) *height += fLabelAscent + fLabelDescent; } else { - *height = iconBounds.Height() - kVPad * 8; + *height = iconBounds.Height() + kVPad * 4; } } *height += 2; From ed75ca72012fb47fc551edcbb4274b4daadc042f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 26 Oct 2012 02:58:45 -0400 Subject: [PATCH 25/66] Set the scroll arrow limit based on the min menu item widths ... rather than the current menu item widths. This means that Deskbar will shrink the menu items until they are at their minimum size before it activates the scroll arrows. Previous to this change the scroll arrows were being turned on prematurely. Also lower the minimum menu item width to the icon width + 50pixels which is arbitrary but looks good to my eye. --- src/apps/deskbar/ExpandoMenuBar.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index a4561ee7de..1e493fad2f 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -63,7 +63,7 @@ All rights reserved. #include "WindowMenuItem.h" -const float kDefaultDeskbarMenuWidth = 50.0f; +const float kMinMenuItemWidth = 50.0f; const float kSepItemWidth = 5.0f; const float kIconPadding = 8.0f; @@ -85,7 +85,7 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, fDrawLabel(drawLabel), fShowTeamExpander(static_cast(be_app)->Settings()->superExpando), fExpandNewTeams(static_cast(be_app)->Settings()->expandNewTeams), - fDeskbarMenuWidth(kDefaultDeskbarMenuWidth), + fDeskbarMenuWidth(kMinMenuItemWidth), fBarView(bar), fPreviousDragTargetItem(NULL), fLastClickItem(NULL) @@ -682,7 +682,7 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) - fDeskbarMenuWidth - kSepItemWidth; int32 iconSize = static_cast(be_app)->IconSize(); float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; - float minItemWidth = fDrawLabel ? iconOnlyWidth + fDeskbarMenuWidth + float minItemWidth = fDrawLabel ? iconOnlyWidth + kMinMenuItemWidth : iconOnlyWidth; float maxItemWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize; float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth @@ -800,9 +800,14 @@ TExpandoMenuBar::CheckForSizeOverrun() if (count < 0) return false; - float menuWidth = ItemAt(count)->Frame().right + fDeskbarMenuWidth - + kSepItemWidth + 1; - float maxWidth = fBarView->DragRegion()->Frame().left - 1; + int32 iconSize = static_cast(be_app)->IconSize(); + float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; + float minItemWidth = fDrawLabel ? iconOnlyWidth + kMinMenuItemWidth + : iconOnlyWidth; + float menuWidth = minItemWidth * CountItems() + fDeskbarMenuWidth + + kSepItemWidth; + float maxWidth = fBarView->DragRegion()->Frame().left + - fDeskbarMenuWidth - kSepItemWidth; return menuWidth > maxWidth; } From 0e100a37a9c94088d334f4c56b1aacf1a9de503c Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 26 Oct 2012 20:51:06 -0400 Subject: [PATCH 26/66] Cleanup --- src/apps/deskbar/BarView.cpp | 1 - src/apps/deskbar/InlineScrollView.cpp | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 94a256c6cf..26732044d4 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -42,7 +42,6 @@ All rights reserved. #include #include -#include #include #include #include diff --git a/src/apps/deskbar/InlineScrollView.cpp b/src/apps/deskbar/InlineScrollView.cpp index ab3ef7a913..7571bea0b6 100644 --- a/src/apps/deskbar/InlineScrollView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -120,7 +120,8 @@ UpScrollArrow::~UpScrollArrow() void UpScrollArrow::Draw(BRect updateRect) { - SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_1_TINT)); if (IsEnabled()) SetHighColor(0, 0, 0); @@ -171,7 +172,8 @@ DownScrollArrow::~DownScrollArrow() void DownScrollArrow::Draw(BRect updateRect) { - SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); + SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_1_TINT)); if (IsEnabled()) SetHighColor(0, 0, 0); From d6f6b835adcb34abfca03207f272614373f38bb1 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 26 Oct 2012 21:45:09 -0400 Subject: [PATCH 27/66] Draw a nice menu background on the inline scroll view and when scroll faster when you push control/option/command and click the little arrow button. --- src/apps/deskbar/BarMenuBar.cpp | 8 +-- src/apps/deskbar/ExpandoMenuBar.cpp | 6 +- src/apps/deskbar/InlineScrollView.cpp | 99 +++++++++++++++++++++------ src/apps/deskbar/InlineScrollView.h | 2 + 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/apps/deskbar/BarMenuBar.cpp b/src/apps/deskbar/BarMenuBar.cpp index ae3689fb0c..ce4932edc2 100644 --- a/src/apps/deskbar/BarMenuBar.cpp +++ b/src/apps/deskbar/BarMenuBar.cpp @@ -170,17 +170,17 @@ TBarMenuBar::RemoveSeperatorItem() void -TBarMenuBar::Draw(BRect rect) +TBarMenuBar::Draw(BRect updateRect) { // want to skip the fancy BMenuBar drawing code. - BMenu::Draw(rect); + BMenu::Draw(updateRect); } void -TBarMenuBar::DrawBackground(BRect rect) +TBarMenuBar::DrawBackground(BRect updateRect) { - BMenu::DrawBackground(rect); + BMenu::DrawBackground(updateRect); } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 1e493fad2f..f2cbca65b9 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -741,14 +741,14 @@ TExpandoMenuBar::MenuLayout() const void -TExpandoMenuBar::Draw(BRect update) +TExpandoMenuBar::Draw(BRect updateRect) { - BMenu::Draw(update); + BMenu::Draw(updateRect); } void -TExpandoMenuBar::DrawBackground(BRect) +TExpandoMenuBar::DrawBackground(BRect updateRect) { if (fVertical) return; diff --git a/src/apps/deskbar/InlineScrollView.cpp b/src/apps/deskbar/InlineScrollView.cpp index 7571bea0b6..5d38f40797 100644 --- a/src/apps/deskbar/InlineScrollView.cpp +++ b/src/apps/deskbar/InlineScrollView.cpp @@ -146,11 +146,23 @@ UpScrollArrow::MouseDown(BPoint where) return; TInlineScrollView* parent = dynamic_cast(Parent()); + if (parent == NULL) + return; - if (parent != NULL) { - parent->ScrollBy(-kDefaultScrollStep); - snooze(5000); - } + float smallStep; + float largeStep; + parent->GetSteps(&smallStep, &largeStep); + + BMessage* message = Window()->CurrentMessage(); + int32 modifiers = 0; + message->FindInt32("modifiers", &modifiers); + // pressing the option/command/control key scrolls faster + if ((modifiers & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) != 0) + parent->ScrollBy(-largeStep); + else + parent->ScrollBy(-smallStep); + + snooze(5000); } @@ -200,11 +212,23 @@ DownScrollArrow::MouseDown(BPoint where) TInlineScrollView* grandparent = dynamic_cast(Parent()->Parent()); + if (grandparent == NULL) + return; - if (grandparent != NULL) { - grandparent->ScrollBy(kDefaultScrollStep); - snooze(5000); - } + float smallStep; + float largeStep; + grandparent->GetSteps(&smallStep, &largeStep); + + BMessage* message = Window()->CurrentMessage(); + int32 modifiers = 0; + message->FindInt32("modifiers", &modifiers); + // pressing the option/command/control key scrolls faster + if ((modifiers & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) != 0) + grandparent->ScrollBy(largeStep); + else + grandparent->ScrollBy(smallStep); + + snooze(5000); } @@ -251,11 +275,23 @@ LeftScrollArrow::MouseDown(BPoint where) return; TInlineScrollView* parent = dynamic_cast(Parent()); + if (parent == NULL) + return; - if (parent != NULL) { - parent->ScrollBy(-kDefaultScrollStep); - snooze(5000); - } + float smallStep; + float largeStep; + parent->GetSteps(&smallStep, &largeStep); + + BMessage* message = Window()->CurrentMessage(); + int32 modifiers = 0; + message->FindInt32("modifiers", &modifiers); + // pressing the option/command/control key scrolls faster + if ((modifiers & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) != 0) + parent->ScrollBy(-largeStep); + else + parent->ScrollBy(-smallStep); + + snooze(5000); } @@ -304,11 +340,23 @@ RightScrollArrow::MouseDown(BPoint where) TInlineScrollView* grandparent = dynamic_cast(Parent()->Parent()); + if (grandparent == NULL) + return; - if (grandparent != NULL) { - grandparent->ScrollBy(kDefaultScrollStep); - snooze(5000); - } + float smallStep; + float largeStep; + grandparent->GetSteps(&smallStep, &largeStep); + + BMessage* message = Window()->CurrentMessage(); + int32 modifiers = 0; + message->FindInt32("modifiers", &modifiers); + // pressing the option/command/control key scrolls faster + if ((modifiers & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) != 0) + grandparent->ScrollBy(largeStep); + else + grandparent->ScrollBy(smallStep); + + snooze(5000); } @@ -318,7 +366,7 @@ RightScrollArrow::MouseDown(BPoint where) TInlineScrollView::TInlineScrollView(BRect frame, BView* target, enum orientation orientation) : - BView(frame, "inline scroll view", B_FOLLOW_NONE, 0), + BView(frame, "inline scroll view", B_FOLLOW_NONE, B_WILL_DRAW), fTarget(target), fBeginScrollArrow(NULL), fEndScrollArrow(NULL), @@ -375,6 +423,15 @@ TInlineScrollView::DetachedFromWindow() } +void +TInlineScrollView::Draw(BRect updateRect) +{ + BRect frame = Bounds(); + be_control_look->DrawButtonBackground(this, frame, updateRect, + ui_color(B_MENU_BACKGROUND_COLOR)); +} + + // #pragma mark - @@ -481,7 +538,8 @@ TInlineScrollView::DetachScrollers() bool TInlineScrollView::HasScrollers() const { - return fTarget != NULL && fBeginScrollArrow != NULL && fEndScrollArrow != NULL; + return fTarget != NULL && fBeginScrollArrow != NULL + && fEndScrollArrow != NULL; } @@ -498,10 +556,7 @@ TInlineScrollView::GetSteps(float* _smallStep, float* _largeStep) const if (_smallStep != NULL) *_smallStep = fScrollStep; if (_largeStep != NULL) { - if (fTarget != NULL) - *_largeStep = fTarget->Frame().Height() - fScrollStep; - else - *_largeStep = fScrollStep * 2; + *_largeStep = fScrollStep * 3; } } diff --git a/src/apps/deskbar/InlineScrollView.h b/src/apps/deskbar/InlineScrollView.h index e483e0e2f8..0a80cbead5 100644 --- a/src/apps/deskbar/InlineScrollView.h +++ b/src/apps/deskbar/InlineScrollView.h @@ -27,6 +27,8 @@ public: virtual void AttachedToWindow(); virtual void DetachedFromWindow(); + virtual void Draw(BRect updateRect); + void AttachScrollers(); void DetachScrollers(); bool HasScrollers() const; From dec421b1dbfb82da1e693da603e59fa3602e50a2 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 26 Oct 2012 22:36:12 -0400 Subject: [PATCH 28/66] Make sure that you remove the separator item before adding the team menu in mini mode or it won't work all the time --- src/apps/deskbar/BarView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 26732044d4..a52a21cdd1 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -389,8 +389,8 @@ TBarView::PlaceDeskbarMenu() loc = Bounds().LeftTop(); } else { // mini mode, DeskbarMenu next to team menu - fBarMenuBar->AddTeamMenu(); fBarMenuBar->RemoveSeperatorItem(); + fBarMenuBar->AddTeamMenu(); } fBarMenuBar->SmartResize(width, menuFrame.Height()); From e4f9bfce33a0baeb0b45297eb8c021934928d49a Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 27 Oct 2012 17:34:10 -0400 Subject: [PATCH 29/66] Need to position window before checking for scrolling. Otherwise when you switch from bottom mini mode to vertical expando mode you'll get scroll arrows when you shouldn't because the bottom of the window frame will be below the screen. --- src/apps/deskbar/BarView.cpp | 8 +++----- src/apps/deskbar/ExpandoMenuBar.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index a52a21cdd1..2e88320efa 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -516,6 +516,8 @@ TBarView::PlaceApplicationBar() SizeWindow(screenFrame); PositionWindow(screenFrame); + CheckForScrolling(); + Window()->UpdateIfNeeded(); Invalidate(); } @@ -578,8 +580,6 @@ TBarView::SizeWindow(BRect screenFrame) float windowWidth, windowHeight; GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight); Window()->ResizeTo(windowWidth, windowHeight); - - CheckForScrolling(); } @@ -609,7 +609,7 @@ TBarView::PositionWindow(BRect screenFrame) void TBarView::CheckForScrolling() { - if (fExpando != NULL) { + if (fInlineScrollView != NULL && fExpando != NULL) { if (fExpando->CheckForSizeOverrun()) fInlineScrollView->AttachScrollers(); else @@ -719,8 +719,6 @@ TBarView::ExpandItems() // Clean up the expanded items list RemoveExpandedItems(); - - fExpando->SizeWindow(1); } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index f2cbca65b9..d44fc069da 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -808,6 +808,7 @@ TExpandoMenuBar::CheckForSizeOverrun() + kSepItemWidth; float maxWidth = fBarView->DragRegion()->Frame().left - fDeskbarMenuWidth - kSepItemWidth; + return menuWidth > maxWidth; } @@ -819,9 +820,12 @@ TExpandoMenuBar::SizeWindow(int32 delta) // code the resize method will be centered in one place // thus, the same behavior (good or bad) will be used // wherever window sizing is done - if (fVertical) - fBarView->SizeWindow(BScreen(Window()).Frame()); - else + if (fVertical) { + BRect screenFrame = (BScreen(Window())).Frame(); + fBarView->SizeWindow(screenFrame); + fBarView->PositionWindow(screenFrame); + fBarView->CheckForScrolling(); + } else CheckItemSizes(delta); } From 3135d0e0de20e432df89b42d02fde4993c1d9bbf Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 27 Oct 2012 19:11:49 -0400 Subject: [PATCH 30/66] Shrink icon only width a bit to make room for more icons ...before turning scrolling on. --- src/apps/deskbar/ExpandoMenuBar.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index d44fc069da..529a44446d 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -683,8 +683,9 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) int32 iconSize = static_cast(be_app)->IconSize(); float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; float minItemWidth = fDrawLabel ? iconOnlyWidth + kMinMenuItemWidth - : iconOnlyWidth; - float maxItemWidth = sMinimumWindowWidth + iconSize - kMinimumIconSize; + : iconOnlyWidth - kIconPadding; + float maxItemWidth = fDrawLabel ? sMinimumWindowWidth + iconSize + - kMinimumIconSize : iconOnlyWidth; float menuWidth = maxItemWidth * CountItems() + fDeskbarMenuWidth + kSepItemWidth; @@ -716,13 +717,10 @@ TExpandoMenuBar::CheckItemSizes(int32 delta) for (int32 index = 0; ; index++) { TTeamMenuItem* item = (TTeamMenuItem*)ItemAt(index); - if (!item) + if (item == NULL) break; - if (!fDrawLabel && newWidth > iconOnlyWidth) - item->SetOverrideWidth(iconOnlyWidth); - else - item->SetOverrideWidth(newWidth); + item->SetOverrideWidth(newWidth); } Invalidate(); @@ -803,7 +801,7 @@ TExpandoMenuBar::CheckForSizeOverrun() int32 iconSize = static_cast(be_app)->IconSize(); float iconOnlyWidth = kIconPadding + iconSize + kIconPadding; float minItemWidth = fDrawLabel ? iconOnlyWidth + kMinMenuItemWidth - : iconOnlyWidth; + : iconOnlyWidth - kIconPadding; float menuWidth = minItemWidth * CountItems() + fDeskbarMenuWidth + kSepItemWidth; float maxWidth = fBarView->DragRegion()->Frame().left From b4c922197ca723c35514a76d8f668f8de8429f4e Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 20:33:18 -0500 Subject: [PATCH 31/66] Fix Deskbar crash when scroll arrows are removed. fExpando is added and removed from InlineScrollView only and it is created and destroyed in BarView only. Before this there was a case where it was removed in both InlineScrollView and BarView causing a crash from the double remove --- src/apps/deskbar/BarView.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 2e88320efa..91d22c0115 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -445,20 +445,17 @@ TBarView::PlaceApplicationBar() { if (fInlineScrollView != NULL) fInlineScrollView->DetachScrollers(); - - if (fExpando != NULL) { - SaveExpandedItems(); - fExpando->RemoveSelf(); - delete fExpando; - fExpando = NULL; - } - - if (fInlineScrollView != NULL) { fInlineScrollView->RemoveSelf(); delete fInlineScrollView; fInlineScrollView = NULL; } + if (fExpando != NULL) { + SaveExpandedItems(); + delete fExpando; + fExpando = NULL; + } + BRect screenFrame = (BScreen(Window())).Frame(); if (fState == kMiniState) { SizeWindow(screenFrame); From 27a53c3c9ee61c7c5938baa266074989daa9b743 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 20:42:27 -0500 Subject: [PATCH 32/66] Fix build, forgot a { --- src/apps/deskbar/BarView.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 91d22c0115..78bb6a3918 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -363,7 +363,8 @@ TBarView::PlaceDeskbarMenu() // create the Be menu fBarMenuBar = new TBarMenuBar(this, menuFrame, "BarMenuBar"); AddChild(fBarMenuBar); - } + } else + fBarMenuBar->SmartResize(-1, -1); float width = sMinimumWindowWidth; BPoint loc(B_ORIGIN); @@ -443,7 +444,7 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { - if (fInlineScrollView != NULL) + if (fInlineScrollView != NULL) { fInlineScrollView->DetachScrollers(); fInlineScrollView->RemoveSelf(); delete fInlineScrollView; From 652a115c1cef9a100765f2ad83d71075ae7b29c6 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 21:06:48 -0500 Subject: [PATCH 33/66] Use fDragRegion width not left, you can't depend on the screen position reliably --- src/apps/deskbar/BarView.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 78bb6a3918..ded264be4c 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -492,9 +492,10 @@ TBarView::PlaceApplicationBar() if (fBarMenuBar != NULL) expandoFrame.left = fBarMenuBar->Frame().Width(); - if (fTrayLocation != 0) - expandoFrame.right = fDragRegion->Frame().left - 1; - else + if (fTrayLocation != 0 && fDragRegion != NULL) { + expandoFrame.right = screenFrame.Width() + - fDragRegion->Frame().Width() - 1; + } else expandoFrame.right = screenFrame.Width(); menuScrollFrame = expandoFrame; From d1e438cad1c1072d0abe208f6373038b4650871f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 21:35:44 -0500 Subject: [PATCH 34/66] Force app menu to auto-layout before recomputing scroll limits. This makes Deskbar correctly calulate the scroll limits in the case when scrollbars are attached but not due to an app being added or removed for example because the icon sizes increased. --- src/apps/deskbar/BarView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index ded264be4c..726022c94b 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -515,6 +515,8 @@ TBarView::PlaceApplicationBar() SizeWindow(screenFrame); PositionWindow(screenFrame); + fExpando->DoLayout(); + // force menu to autosize CheckForScrolling(); Window()->UpdateIfNeeded(); From a05a00c8496ff16cb0101f6a1eaf716699c6d62f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 21:59:56 -0500 Subject: [PATCH 35/66] Tiny style fix --- src/apps/deskbar/ExpandoMenuBar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 529a44446d..91f4cfa2be 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -217,7 +217,8 @@ TExpandoMenuBar::MessageReceived(BMessage* message) TTeamMenuItem* item; switch (message->what) { - case B_SOME_APP_LAUNCHED: { + case B_SOME_APP_LAUNCHED: + { BList* teams = NULL; message->FindPointer("teams", (void**)&teams); From 1a5df674c1bb93a405699daec540c7cdddc86e1b Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 12 Nov 2012 23:30:51 -0500 Subject: [PATCH 36/66] Fix saving and re-expanding items. Subtle bug #1 found, 11th hour change broke this feature, fixed once again. --- src/apps/deskbar/BarView.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 726022c94b..07f28782a7 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -444,6 +444,8 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { + SaveExpandedItems(); + if (fInlineScrollView != NULL) { fInlineScrollView->DetachScrollers(); fInlineScrollView->RemoveSelf(); @@ -452,7 +454,6 @@ TBarView::PlaceApplicationBar() } if (fExpando != NULL) { - SaveExpandedItems(); delete fExpando; fExpando = NULL; } From 0046f4443675694b16fda4829e6f838954bf23fa Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 1 Aug 2012 07:25:56 -0400 Subject: [PATCH 37/66] Modify about window to take an app signature. * Grabs the app icon and version from the resource file. * Allow you to specify the copyright holder instead of hardcoding "Haiku, Inc." * Support multiple extra copyright fields. * Modify BAlert to take a custom icon. * Set the custom icon of the BAlert to the app icon. * Also set the app version. * Convert BAboutWindow to derive from BWindow * Place a 128x128 icon and fill out a scrolling BTextView with options such as authors, version history, copyright, license, etc. Still needs some work but is coming along. * Add the word Version to the version line, i8n'ed of course, and tweak the info box and default sizes. --- headers/private/shared/AboutWindow.h | 45 ++- src/apps/deskcalc/CalcApplication.cpp | 1 + src/apps/deskcalc/CalcApplication.h | 1 + src/apps/deskcalc/CalcView.cpp | 18 +- src/apps/deskcalc/CalcView.h | 1 + src/apps/deskcalc/CalcWindow.cpp | 5 +- src/apps/deskcalc/DeskCalc.rdef | 5 +- src/kits/shared/AboutWindow.cpp | 435 +++++++++++++++++++++++--- 8 files changed, 439 insertions(+), 72 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index da7d5c8e37..d6ac30e6ef 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -1,28 +1,45 @@ /* - * Copyright 2007-2009 Haiku, Inc. + * Copyright 2007-2012 Haiku, Inc. * Distributed under the terms of the MIT License. - * - * Authors: - * Ryan Leavengood, leavengood@gmail.com */ #ifndef B_ABOUT_WINDOW_H #define B_ABOUT_WINDOW_H -#include +#include +#include +#include -class BAboutWindow { - public: - BAboutWindow(const char *appName, int32 firstCopyrightYear, - const char **authors, const char *extraInfo = NULL); - virtual ~BAboutWindow(); +class AboutView; +class BPoint; - void Show(); +class BAboutWindow : public BWindow { + public: + BAboutWindow(const char* appName, + int32 firstCopyrightYear, + const char** authors = NULL, + const char* extraInfo = NULL); + BAboutWindow(const char* appName, + const char* signature); + virtual ~BAboutWindow(); - private: - BString* fAppName; - BString* fText; + void AddDescription(const char* description); + void AddCopyright(int32 firstCopyrightYear, + const char* copyrightHolder, + const char** extraCopyrights = NULL); + void AddAuthors(const char** authors); + void AddSpecialThanks(const char** thanks); + void AddVersionHistory(const char** history); + void AddExtraInfo(const char* extraInfo); + + BPoint AboutPosition(float width, float height); + + protected: + void _Init(const char* appName, const char* signature); + + private: + AboutView* fAboutView; }; #endif // B_ABOUT_WINDOW_H diff --git a/src/apps/deskcalc/CalcApplication.cpp b/src/apps/deskcalc/CalcApplication.cpp index 2e32e6266d..d91002ce90 100644 --- a/src/apps/deskcalc/CalcApplication.cpp +++ b/src/apps/deskcalc/CalcApplication.cpp @@ -30,6 +30,7 @@ static const char* kSettingsFileName = "DeskCalc_settings"; +const char* kAppName = B_TRANSLATE_SYSTEM_NAME("DeskCalc"); const char* kAppSig = "application/x-vnd.Haiku-DeskCalc"; static const float kDefaultWindowWidth = 220.0; diff --git a/src/apps/deskcalc/CalcApplication.h b/src/apps/deskcalc/CalcApplication.h index d47f445cec..9707daf4be 100644 --- a/src/apps/deskcalc/CalcApplication.h +++ b/src/apps/deskcalc/CalcApplication.h @@ -15,6 +15,7 @@ #include +extern const char* kAppName; extern const char* kAppSig; class BFile; diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 73e2d7925e..d0b53d6c4e 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -712,15 +712,14 @@ CalcView::FrameResized(float width, float height) void CalcView::AboutRequested() { - const char* authors[] = { - "Timothy Wayper", - "Stephan Aßmus", - "Ingo Weinhold", + const char* extraCopyrights[] = { + "1997, 1998 R3 Software Ltd.", NULL }; - BAboutWindow about(B_TRANSLATE_SYSTEM_NAME("DeskCalc"), 2006, authors, - B_UTF8_COPYRIGHT "1997, 1998 R3 Software Ltd."); - about.Show(); + + BAboutWindow* about = new BAboutWindow(kAppName, kAppSig); + about->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); + about->Show(); } @@ -1289,6 +1288,9 @@ CalcView::_CreatePopUpMenu(bool addKeypadModeMenuItems) fKeypadModeScientificItem = new BMenuItem(B_TRANSLATE("Scientific"), new BMessage(MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC), '2'); } + BMenuItem* aboutItem + = new BMenuItem(B_TRANSLATE("About DeskCalc" B_UTF8_ELLIPSIS), + new BMessage(B_ABOUT_REQUESTED)); // apply current settings fAutoNumlockItem->SetMarked(fOptions->auto_num_lock); @@ -1313,6 +1315,8 @@ CalcView::_CreatePopUpMenu(bool addKeypadModeMenuItems) fPopUpMenu->AddItem(fKeypadModeScientificItem); _MarkKeypadItems(fOptions->keypad_mode); } + fPopUpMenu->AddSeparatorItem(); + fPopUpMenu->AddItem(aboutItem); } diff --git a/src/apps/deskcalc/CalcView.h b/src/apps/deskcalc/CalcView.h index c004f668fb..93bc594f2a 100644 --- a/src/apps/deskcalc/CalcView.h +++ b/src/apps/deskcalc/CalcView.h @@ -31,6 +31,7 @@ static const float kMaximumWidthBasic = 400.0f; static const float kMinimumHeightBasic = 130.0f; static const float kMaximumHeightBasic = 400.0f; +class BAboutWindow; class BString; class BMenuItem; class BPopUpMenu; diff --git a/src/apps/deskcalc/CalcWindow.cpp b/src/apps/deskcalc/CalcWindow.cpp index 4a3740edb3..ae6e337c42 100644 --- a/src/apps/deskcalc/CalcWindow.cpp +++ b/src/apps/deskcalc/CalcWindow.cpp @@ -21,6 +21,7 @@ #include #include +#include "CalcApplication.h" #include "CalcOptions.h" #include "CalcView.h" @@ -31,8 +32,8 @@ CalcWindow::CalcWindow(BRect frame, BMessage* settings) : - BWindow(frame, B_TRANSLATE_SYSTEM_NAME("DeskCalc"), B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ANCHORED_ON_ACTIVATE) + BWindow(frame, kAppName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS + | B_NOT_ANCHORED_ON_ACTIVATE) { // create calculator view with calculator description and // desktop background color diff --git a/src/apps/deskcalc/DeskCalc.rdef b/src/apps/deskcalc/DeskCalc.rdef index eb159ece92..7cfe95e212 100644 --- a/src/apps/deskcalc/DeskCalc.rdef +++ b/src/apps/deskcalc/DeskCalc.rdef @@ -5,14 +5,14 @@ resource app_name_catalog_entry "x-vnd.Haiku-DeskCalc:System name:DeskCalc"; resource app_version { major = 2, - middle = 2, + middle = 4, minor = 0, variety = B_APPV_ALPHA, internal = 1, short_info = "DeskCalc", - long_info = "DeskCalc ©2006-2012 Haiku, Inc." + long_info = "DeskCalc ©1997, 1998 R3 Software Ltd. ©2006-2012 Haiku, Inc." }; resource app_flags B_SINGLE_LAUNCH; @@ -31,4 +31,3 @@ resource vector_icon { $"011001178400040A010102000A050105000A06030806071001178122040A0201" $"03000A030104000A0706090A0B0D0E0C100117810004" }; - diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index e8fbe72bf0..e7d968277e 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -1,39 +1,292 @@ /* - * Copyright 2007-2009 Haiku, Inc. + * Copyright 2007-2012 Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: * Ryan Leavengood, leavengood@gmail.com + * John Scipione, jscipione@gmail.com */ + #include #include #include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include #include +#include + + +static const float kStripeWidth = 30.0; using BPrivate::gSystemCatalog; - #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "AboutWindow" -BAboutWindow::BAboutWindow(const char *appName, int32 firstCopyrightYear, - const char **authors, const char *extraInfo) -{ - fAppName = new BString(appName); +class StripeView : public BView { + public: + StripeView(BBitmap* icon); + virtual ~StripeView(); - const char* copyright = gSystemCatalog.GetString( - B_TRANSLATE_MARK("Copyright " B_UTF8_COPYRIGHT " %years% Haiku, Inc."), - "AboutWindow"); - const char* writtenBy = gSystemCatalog.GetString( - B_TRANSLATE_MARK("Written by:"), "AboutWindow"); + virtual void Draw(BRect updateRect); + + private: + BBitmap* fIcon; +}; + + +class AboutView : public BGroupView { + public: + AboutView(const char* name, + const char* signature); + virtual ~AboutView(); + + BTextView* InfoView() const { return fInfoView; }; + + protected: + const char* AppVersion(const char* signature); + BBitmap* AppIcon(const char* signature); + + private: + BStringView* fNameView; + BStringView* fVersionView; + BTextView* fInfoView; +}; + + +// #pragma mark - + + +StripeView::StripeView(BBitmap* icon) + : + BView("StripeView", B_WILL_DRAW), + fIcon(icon) +{ + SetExplicitMinSize(BSize(160.0, B_SIZE_UNSET)); + SetExplicitPreferredSize(BSize(160.0, B_SIZE_UNLIMITED)); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); +} + + +StripeView::~StripeView() +{ +} + + +void +StripeView::Draw(BRect updateRect) +{ + SetHighColor(ViewColor()); + FillRect(updateRect); + + BRect stripeRect = Bounds(); + stripeRect.right = kStripeWidth; + SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); + FillRect(stripeRect); + + if (fIcon == NULL) + return; + + SetDrawingMode(B_OP_ALPHA); + SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + DrawBitmapAsync(fIcon, BPoint(15.0, 5.0)); +} + + +// #pragma mark - + + +AboutView::AboutView(const char* appName, const char* signature) + : + BGroupView("AboutView", B_VERTICAL) +{ + fNameView = new BStringView("name", appName); + BFont font; + fNameView->GetFont(&font); + font.SetFace(B_BOLD_FACE); + font.SetSize(font.Size() * 2.0); + fNameView->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE + | B_FONT_FLAGS); + + fVersionView = new BStringView("version", AppVersion(signature)); + + fInfoView = new BTextView("info", B_WILL_DRAW); + fInfoView->SetExplicitMinSize(BSize(210.0, 100.0)); + fInfoView->MakeEditable(false); + fInfoView->SetWordWrap(true); + fInfoView->SetInsets(5.0, 5.0, 5.0, 5.0); + fInfoView->SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR)); + fInfoView->SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR)); + + BScrollView* infoViewScroller = new BScrollView( + "infoViewScroller", fInfoView, B_WILL_DRAW | B_FRAME_EVENTS, + false, true, B_PLAIN_BORDER); + + GroupLayout()->SetSpacing(0); + BLayoutBuilder::Group<>(this) + .AddGroup(B_HORIZONTAL, 0) + .Add(new StripeView(AppIcon(signature))) + .AddGroup(B_VERTICAL, B_USE_SMALL_SPACING) + .SetInsets(0, B_USE_DEFAULT_SPACING, + B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) + .Add(fNameView) + .Add(fVersionView) + .Add(infoViewScroller) + .End() + .AddGlue() + .End(); +} + + +AboutView::~AboutView() +{ +} + + +const char* +AboutView::AppVersion(const char* signature) +{ + if (signature == NULL) + return NULL; + + app_info appInfo; + if (be_roster->GetAppInfo(signature, &appInfo) != B_OK) + return NULL; + + BFile file(&appInfo.ref, B_READ_ONLY); + BAppFileInfo appMime(&file); + if (appMime.InitCheck() != B_OK) + return NULL; + + version_info versionInfo; + if (appMime.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) { + if (versionInfo.major == 0 && versionInfo.middle == 0 + && versionInfo.minor == 0) { + return NULL; + } + + const char* version = B_TRANSLATE_MARK("Version"); + version = gSystemCatalog.GetString(version, "AboutWindow"); + BString appVersion(version); + appVersion << " " << versionInfo.major << "." << versionInfo.middle; + if (versionInfo.minor > 0) + appVersion << "." << versionInfo.minor; + + return appVersion.String(); + } + + return NULL; +} + + +BBitmap* +AboutView::AppIcon(const char* signature) +{ + if (signature == NULL) + return NULL; + + app_info appInfo; + if (be_roster->GetAppInfo(signature, &appInfo) != B_OK) + return NULL; + + BFile file(&appInfo.ref, B_READ_ONLY); + BAppFileInfo appMime(&file); + if (appMime.InitCheck() != B_OK) + return NULL; + + // fetch the app icon + BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32); + if (appMime.GetIcon(icon, B_LARGE_ICON) == B_OK) + return icon; + + // couldn't find the app icon + // fetch the generic 3 boxes icon + BMimeType defaultAppMime; + defaultAppMime.SetTo(B_APP_MIME_TYPE); + if (defaultAppMime.GetIcon(icon, B_LARGE_ICON) == B_OK) + return icon; + + return NULL; +} + + +// #pragma mark - + + +BAboutWindow::BAboutWindow(const char* appName, int32 firstCopyrightYear, + const char** authors, const char* extraInfo) + : BWindow(BRect(0.0, 0.0, 300.0, 140.0), appName, B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS) +{ + _Init(appName, NULL); + AddCopyright(firstCopyrightYear, "Haiku, Inc.", NULL); + AddAuthors(authors); + AddExtraInfo(extraInfo); +} + + +BAboutWindow::BAboutWindow(const char* appName, const char* signature) + : BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS) +{ + _Init(appName, signature); +} + + +BAboutWindow::~BAboutWindow() +{ + fAboutView->RemoveSelf(); + delete fAboutView; + fAboutView = NULL; +} + + +void +BAboutWindow::AddDescription(const char* description) +{ + if (description == NULL) + return; + + const char* appDesc = B_TRANSLATE_MARK(description); + appDesc = gSystemCatalog.GetString(appDesc, "AboutWindow"); + + BString desc(appDesc); + desc << "\n\n"; + + fAboutView->InfoView()->Insert(desc.String()); +} + + +void +BAboutWindow::AddCopyright(int32 firstCopyrightYear, + const char* copyrightHolder, const char** extraCopyrights) +{ + BString copyright(B_UTF8_COPYRIGHT " %years%"); + if (copyrightHolder != NULL) + copyright << " " << copyrightHolder; + + const char* firstCopyright = B_TRANSLATE_MARK(copyright.String()); + firstCopyright = gSystemCatalog.GetString(copyright, "AboutWindow"); // Get current year time_t tp; @@ -45,50 +298,140 @@ BAboutWindow::BAboutWindow(const char *appName, int32 firstCopyrightYear, if (copyrightYears != currentYear) copyrightYears << "-" << currentYear; - // Build the text to display - BString text(appName); - text << "\n\n"; - text << copyright; - text << "\n\n"; + BString text(firstCopyright); + + // Replace the copyright year with the current year text.ReplaceAll("%years%", copyrightYears.String()); - text << writtenBy << "\n"; - for (int32 i = 0; authors[i]; i++) { - text << " " << authors[i] << "\n"; + + // Add extra copyright strings + if (extraCopyrights != NULL) { + // Add optional extra copyright information + for (int32 i = 0; extraCopyrights[i]; i++) + text << "\n" << B_UTF8_COPYRIGHT << " " << extraCopyrights[i]; } + text << "\n"; - // The extra information is optional - if (extraInfo != NULL) { - text << "\n" << extraInfo << "\n"; - } + const char* allRightsReserved = B_TRANSLATE_MARK("All Rights Reserved."); + allRightsReserved = gSystemCatalog.GetString(allRightsReserved, + "AboutWindow"); + text << " " << allRightsReserved << "\n\n"; - fText = new BString(text); -} - - -BAboutWindow::~BAboutWindow() -{ - delete fText; - delete fAppName; + fAboutView->InfoView()->Insert(text.String()); } void -BAboutWindow::Show() +BAboutWindow::AddAuthors(const char** authors) { - const char* aboutTitle = gSystemCatalog.GetString( - B_TRANSLATE_MARK("About" B_UTF8_ELLIPSIS), "AboutWindow"); - const char* closeLabel = gSystemCatalog.GetString( - B_TRANSLATE_MARK("Close"), "AboutWindow"); + if (authors == NULL) + return; - BAlert *alert = new BAlert(aboutTitle, fText->String(), closeLabel); - BTextView *view = alert->TextView(); - BFont font; - view->SetStylable(true); - view->GetFont(&font); - font.SetFace(B_BOLD_FACE); - font.SetSize(font.Size() * 1.7); - view->SetFontAndColor(0, fAppName->Length(), &font); - alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); - alert->Go(); + const char* writtenBy = B_TRANSLATE_MARK("Written by:"); + writtenBy = gSystemCatalog.GetString(writtenBy, "AboutWindow"); + + BString text(writtenBy); + text << "\n"; + for (int32 i = 0; authors[i]; i++) + text << " " << authors[i] << "\n"; + text << "\n"; + + fAboutView->InfoView()->Insert(text.String()); } + +void +BAboutWindow::AddSpecialThanks(const char** thanks) +{ + if (thanks == NULL) + return; + + const char* specialThanks = B_TRANSLATE_MARK("Special Thanks:"); + specialThanks = gSystemCatalog.GetString(specialThanks, "AboutWindow"); + + BString text(specialThanks); + text << "\n"; + for (int32 i = 0; thanks[i]; i++) + text << " " << thanks[i] << "\n"; + text << "\n"; + + fAboutView->InfoView()->Insert(text.String()); +} + + +void +BAboutWindow::AddVersionHistory(const char** history) +{ + if (history == NULL) + return; + + const char* versionHistory = B_TRANSLATE_MARK("Version history:"); + versionHistory = gSystemCatalog.GetString(versionHistory, "AboutWindow"); + BString text(versionHistory); + text << "\n"; + for (int32 i = 0; history[i]; i++) + text << " " << history[i] << "\n"; + text << "\n"; + + fAboutView->InfoView()->Insert(text.String()); +} + + +void +BAboutWindow::AddExtraInfo(const char* extraInfo) +{ + if (extraInfo == NULL) + return; + + const char* appExtraInfo = B_TRANSLATE_MARK(extraInfo); + appExtraInfo = gSystemCatalog.GetString(extraInfo, "AboutWindow"); + + BString extra(appExtraInfo); + extra << "\n"; + + fAboutView->InfoView()->Insert(extra.String()); +} + + +BPoint +BAboutWindow::AboutPosition(float width, float height) +{ + BPoint result(100, 100); + + BWindow* window = + dynamic_cast(BLooper::LooperForThread(find_thread(NULL))); + + BScreen screen(window); + BRect screenFrame(0, 0, 640, 480); + if (screen.IsValid()) + screenFrame = screen.Frame(); + + // Horizontally, we're smack in the middle + result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 2.0); + + // This is probably sooo wrong, but it looks right on 1024 x 768 + result.y = screenFrame.top + (screenFrame.Height() / 4.0) - ceil(height / 3.0); + + return result; +} + + +// #pragma mark - + + +void +BAboutWindow::_Init(const char* appName, const char* signature) +{ + SetLayout(new BGroupLayout(B_VERTICAL)); + + const char* about = B_TRANSLATE_MARK("About"); + about = gSystemCatalog.GetString(about, "AboutWindow"); + + BString title(about); + title << " " << appName; + SetTitle(title.String()); + + fAboutView = new AboutView(appName, signature); + AddChild(fAboutView); + + MoveTo(AboutPosition(Frame().Width(), Frame().Height())); +} From 5b0cd98792de98b6ef3f40c432f0971ca6a5d405 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Fri, 17 Aug 2012 02:19:40 -0400 Subject: [PATCH 38/66] WIP: Create the about dialog once, hide and show, Quit() when object is destroyed. --- headers/private/shared/AboutWindow.h | 3 + src/apps/activitymonitor/ActivityMonitor.cpp | 19 +- src/apps/activitymonitor/ActivityMonitor.h | 5 +- src/apps/activitymonitor/ActivityView.cpp | 9 +- src/apps/activitymonitor/ActivityView.h | 5 +- src/apps/deskcalc/CalcApplication.cpp | 12 +- src/apps/deskcalc/CalcApplication.h | 2 +- src/apps/deskcalc/CalcView.cpp | 209 +++++++++---------- src/apps/deskcalc/CalcView.h | 11 +- src/apps/deskcalc/CalcWindow.h | 2 + src/kits/shared/AboutWindow.cpp | 84 +++++--- 11 files changed, 196 insertions(+), 165 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index d6ac30e6ef..3741d2c3bc 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -24,6 +24,8 @@ class BAboutWindow : public BWindow { const char* signature); virtual ~BAboutWindow(); + virtual bool QuitRequested(); + void AddDescription(const char* description); void AddCopyright(int32 firstCopyrightYear, const char* copyrightHolder, @@ -40,6 +42,7 @@ class BAboutWindow : public BWindow { private: AboutView* fAboutView; + BHandler* fCaller; }; #endif // B_ABOUT_WINDOW_H diff --git a/src/apps/activitymonitor/ActivityMonitor.cpp b/src/apps/activitymonitor/ActivityMonitor.cpp index cf9ba52f16..0db3cd1060 100644 --- a/src/apps/activitymonitor/ActivityMonitor.cpp +++ b/src/apps/activitymonitor/ActivityMonitor.cpp @@ -8,17 +8,19 @@ #include -#include #include #include "ActivityWindow.h" + +const char* kAppName = B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"); const char* kSignature = "application/x-vnd.Haiku-ActivityMonitor"; ActivityMonitor::ActivityMonitor() : BApplication(kSignature) { + fWindow = new ActivityWindow(); } @@ -30,7 +32,6 @@ ActivityMonitor::~ActivityMonitor() void ActivityMonitor::ReadyToRun() { - fWindow = new ActivityWindow(); fWindow->Show(); } @@ -52,20 +53,6 @@ ActivityMonitor::MessageReceived(BMessage* message) void ActivityMonitor::AboutRequested() { - ShowAbout(); -} - - -/*static*/ void -ActivityMonitor::ShowAbout() -{ - const char* kAuthors[] = { - "Axel Dörfler", - NULL - }; - - BAboutWindow aboutWindow(B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"), 2008, kAuthors); - aboutWindow.Show(); } diff --git a/src/apps/activitymonitor/ActivityMonitor.h b/src/apps/activitymonitor/ActivityMonitor.h index 7ac0fd3bb1..036acb5559 100644 --- a/src/apps/activitymonitor/ActivityMonitor.h +++ b/src/apps/activitymonitor/ActivityMonitor.h @@ -9,8 +9,9 @@ #include #include -class BMessage; + class ActivityWindow; +class BMessage; #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "ActivityWindow" @@ -28,8 +29,6 @@ public: virtual void AboutRequested(); - static void ShowAbout(); - private: ActivityWindow* fWindow; }; diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index e3db9f8845..664ef9a564 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -12,6 +12,7 @@ #include #ifdef __HAIKU__ +# include # include # include #endif @@ -175,6 +176,7 @@ const uint32 kMsgToggleDataSource = 'tgds'; const uint32 kMsgToggleLegend = 'tglg'; const uint32 kMsgUpdateResolution = 'ures'; +extern const char* kAppName; extern const char* kSignature; @@ -598,6 +600,8 @@ ActivityView::~ActivityView() { delete fOffscreen; delete fSystemInfoHandler; + + fAboutWindow->Quit(); } @@ -614,6 +618,9 @@ ActivityView::_Init(const BMessage* settings) #endif SetViewColor(B_TRANSPARENT_COLOR); + fAboutWindow = new BAboutWindow(kAppName, kSignature); + fAboutWindow->AddCopyright(2008, "Haiku, Inc."); + fLastRefresh = 0; fDrawResolution = 1; fZooming = false; @@ -1104,7 +1111,7 @@ ActivityView::MessageReceived(BMessage* message) switch (message->what) { case B_ABOUT_REQUESTED: - ActivityMonitor::ShowAbout(); + fAboutWindow->Show(); break; case kMsgUpdateResolution: diff --git a/src/apps/activitymonitor/ActivityView.h b/src/apps/activitymonitor/ActivityView.h index 5ffa336312..0e1ccf6520 100644 --- a/src/apps/activitymonitor/ActivityView.h +++ b/src/apps/activitymonitor/ActivityView.h @@ -16,6 +16,8 @@ #include "CircularBuffer.h" #include "DataSource.h" + +class BAboutWindow; class BBitmap; class BMessageRunner; class Scale; @@ -23,7 +25,6 @@ class SystemInfoHandler; class ViewHistory; struct data_item; - class DataHistory { public: DataHistory(bigtime_t memorize, bigtime_t interval); @@ -145,6 +146,8 @@ private: int32 fOriginalResolution; SystemInfoHandler* fSystemInfoHandler; std::map fScales; + + BAboutWindow* fAboutWindow; }; #endif // ACTIVITY_VIEW_H diff --git a/src/apps/deskcalc/CalcApplication.cpp b/src/apps/deskcalc/CalcApplication.cpp index d91002ce90..9c6d4c0052 100644 --- a/src/apps/deskcalc/CalcApplication.cpp +++ b/src/apps/deskcalc/CalcApplication.cpp @@ -22,6 +22,7 @@ #include #include +#include "CalcView.h" #include "CalcWindow.h" @@ -29,9 +30,9 @@ #define B_TRANSLATION_CONTEXT "CalcApplication" -static const char* kSettingsFileName = "DeskCalc_settings"; -const char* kAppName = B_TRANSLATE_SYSTEM_NAME("DeskCalc"); -const char* kAppSig = "application/x-vnd.Haiku-DeskCalc"; +static const char* kSettingsFileName = "DeskCalc_settings"; +const char* kAppName = B_TRANSLATE_SYSTEM_NAME("DeskCalc"); +const char* kSignature = "application/x-vnd.Haiku-DeskCalc"; static const float kDefaultWindowWidth = 220.0; static const float kDefaultWindowHeight = 140.0; @@ -39,7 +40,7 @@ static const float kDefaultWindowHeight = 140.0; CalcApplication::CalcApplication() : - BApplication(kAppSig), + BApplication(kSignature), fCalcWindow(NULL) { } @@ -67,8 +68,7 @@ CalcApplication::ReadyToRun() void CalcApplication::AboutRequested() { - // TODO: implement me! - return BApplication::AboutRequested(); + fCalcWindow->View()->MessageReceived(new BMessage(B_ABOUT_REQUESTED)); } diff --git a/src/apps/deskcalc/CalcApplication.h b/src/apps/deskcalc/CalcApplication.h index 9707daf4be..d66f4be406 100644 --- a/src/apps/deskcalc/CalcApplication.h +++ b/src/apps/deskcalc/CalcApplication.h @@ -16,7 +16,7 @@ extern const char* kAppName; -extern const char* kAppSig; +extern const char* kSignature; class BFile; class CalcWindow; diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index d0b53d6c4e..285671cf5d 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -138,24 +138,10 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage* settings) fAudioFeedbackItem(NULL), fOptions(new CalcOptions()) { - // create expression text view - fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); - AddChild(fExpressionTextView); - - // read data from archive - _LoadSettings(settings); - // tell the app server not to erase our b/g SetViewColor(B_TRANSPARENT_32_BIT); - // parse calculator description - _ParseCalcDesc(fKeypadDescription); - - // colorize based on base color. - _Colorize(); - - // Fetch the calc icon for compact view - _FetchAppIcon(fCalcIcon); + _Init(settings); } @@ -188,15 +174,7 @@ CalcView::CalcView(BMessage* archive) // Do not restore the follow mode, in shelfs, we never follow. SetResizingMode(B_FOLLOW_NONE); - // create expression text view - fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); - AddChild(fExpressionTextView); - - // read data from archive - _LoadSettings(archive); - - // Fetch the calc icon for compact view - _FetchAppIcon(fCalcIcon); + _Init(archive); } @@ -205,6 +183,8 @@ CalcView::~CalcView() delete fKeypad; delete fOptions; free(fKeypadDescription); + + fAboutWindow->Quit(); } @@ -288,7 +268,7 @@ CalcView::MessageReceived(BMessage* message) // (replicant) about box requested case B_ABOUT_REQUESTED: - AboutRequested(); + fAboutWindow->Show(); break; case MSG_UNFLASH_KEY: @@ -296,6 +276,7 @@ CalcView::MessageReceived(BMessage* message) int32 key; if (message->FindInt32("key", &key) == B_OK) _FlashKey(key, 0); + break; } @@ -709,20 +690,6 @@ CalcView::FrameResized(float width, float height) } -void -CalcView::AboutRequested() -{ - const char* extraCopyrights[] = { - "1997, 1998 R3 Software Ltd.", - NULL - }; - - BAboutWindow* about = new BAboutWindow(kAppName, kAppSig); - about->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); - about->Show(); -} - - status_t CalcView::Archive(BMessage* archive, bool deep) const { @@ -735,7 +702,7 @@ CalcView::Archive(BMessage* archive, bool deep) const // save app signature for replicant add-on loading if (ret == B_OK) - ret = archive->AddString("add_on", kAppSig); + ret = archive->AddString("add_on", kSignature); // save all the options if (ret == B_OK) @@ -816,73 +783,6 @@ CalcView::Paste(BMessage* message) } -status_t -CalcView::_LoadSettings(BMessage* archive) -{ - if (!archive) - return B_BAD_VALUE; - - // record calculator description - const char* calcDesc; - if (archive->FindString("calcDesc", &calcDesc) < B_OK) - calcDesc = kKeypadDescriptionBasic; - - // save calculator description for reference - free(fKeypadDescription); - fKeypadDescription = strdup(calcDesc); - - // read grid dimensions - if (archive->FindInt16("cols", &fColumns) < B_OK) - fColumns = 5; - if (archive->FindInt16("rows", &fRows) < B_OK) - fRows = 4; - - // read color scheme - const rgb_color* color; - ssize_t size; - if (archive->FindData("rgbBaseColor", B_RGB_COLOR_TYPE, - (const void**)&color, &size) < B_OK - || size != sizeof(rgb_color)) { - fBaseColor = ui_color(B_PANEL_BACKGROUND_COLOR); - puts("Missing rgbBaseColor from CalcView archive!\n"); - } else { - fBaseColor = *color; - } - - if (archive->FindData("rgbDisplay", B_RGB_COLOR_TYPE, - (const void**)&color, &size) < B_OK - || size != sizeof(rgb_color)) { - fExpressionBGColor = (rgb_color){ 0, 0, 0, 255 }; - puts("Missing rgbBaseColor from CalcView archive!\n"); - } else { - fExpressionBGColor = *color; - } - - // load options - fOptions->LoadSettings(archive); - - // load display text - const char* display; - if (archive->FindString("displayText", &display) < B_OK) { - puts("Missing expression text from CalcView archive.\n"); - } else { - // init expression text - fExpressionTextView->SetText(display); - } - - // load expression history - fExpressionTextView->LoadSettings(archive); - - // parse calculator description - _ParseCalcDesc(fKeypadDescription); - - // colorize based on base color. - _Colorize(); - - return B_OK; -} - - status_t CalcView::SaveSettings(BMessage* archive) const { @@ -1068,6 +968,99 @@ CalcView::SetKeypadMode(uint8 mode) // #pragma mark - +void +CalcView::_Init(BMessage* settings) +{ + // create the about window + const char* extraCopyrights[] = { + "1997, 1998 R3 Software Ltd.", + NULL + }; + + fAboutWindow = new BAboutWindow(kAppName, kSignature); + fAboutWindow->AddCopyright(2006, "Haiku, Inc.", + extraCopyrights); + + // create expression text view + fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); + AddChild(fExpressionTextView); + + // read data from archive + _LoadSettings(settings); + + // fetch the calc icon for compact view + _FetchAppIcon(fCalcIcon); + +} + + +status_t +CalcView::_LoadSettings(BMessage* archive) +{ + if (!archive) + return B_BAD_VALUE; + + // record calculator description + const char* calcDesc; + if (archive->FindString("calcDesc", &calcDesc) < B_OK) + calcDesc = kKeypadDescriptionBasic; + + // save calculator description for reference + free(fKeypadDescription); + fKeypadDescription = strdup(calcDesc); + + // read grid dimensions + if (archive->FindInt16("cols", &fColumns) < B_OK) + fColumns = 5; + if (archive->FindInt16("rows", &fRows) < B_OK) + fRows = 4; + + // read color scheme + const rgb_color* color; + ssize_t size; + if (archive->FindData("rgbBaseColor", B_RGB_COLOR_TYPE, + (const void**)&color, &size) < B_OK + || size != sizeof(rgb_color)) { + fBaseColor = ui_color(B_PANEL_BACKGROUND_COLOR); + puts("Missing rgbBaseColor from CalcView archive!\n"); + } else { + fBaseColor = *color; + } + + if (archive->FindData("rgbDisplay", B_RGB_COLOR_TYPE, + (const void**)&color, &size) < B_OK + || size != sizeof(rgb_color)) { + fExpressionBGColor = (rgb_color){ 0, 0, 0, 255 }; + puts("Missing rgbBaseColor from CalcView archive!\n"); + } else { + fExpressionBGColor = *color; + } + + // load options + fOptions->LoadSettings(archive); + + // load display text + const char* display; + if (archive->FindString("displayText", &display) < B_OK) { + puts("Missing expression text from CalcView archive.\n"); + } else { + // init expression text + fExpressionTextView->SetText(display); + } + + // load expression history + fExpressionTextView->LoadSettings(archive); + + // parse calculator description + _ParseCalcDesc(fKeypadDescription); + + // colorize based on base color. + _Colorize(); + + return B_OK; +} + + void CalcView::_ParseCalcDesc(const char* keypadDescription) { @@ -1372,7 +1365,7 @@ void CalcView::_FetchAppIcon(BBitmap* into) { entry_ref appRef; - status_t status = be_roster->FindApp(kAppSig, &appRef); + status_t status = be_roster->FindApp(kSignature, &appRef); if (status == B_OK) { BFile file(&appRef, B_READ_ONLY); BAppFileInfo appInfo(&file); diff --git a/src/apps/deskcalc/CalcView.h b/src/apps/deskcalc/CalcView.h index 93bc594f2a..50a121df7d 100644 --- a/src/apps/deskcalc/CalcView.h +++ b/src/apps/deskcalc/CalcView.h @@ -34,6 +34,7 @@ static const float kMaximumHeightBasic = 400.0f; class BAboutWindow; class BString; class BMenuItem; +class BMessage; class BPopUpMenu; class CalcOptions; class CalcOptionsWindow; @@ -64,9 +65,6 @@ class CalcView : public BView { virtual void ResizeTo(float width, float height); virtual void FrameResized(float width, float height); - // Present about box for view (replicant). - virtual void AboutRequested(); - // Archive this view. virtual status_t Archive(BMessage* archive, bool deep) const; @@ -102,6 +100,8 @@ class CalcView : public BView { void SetKeypadMode(uint8 mode); private: + void _Init(BMessage* settings); + status_t _LoadSettings(BMessage* archive); void _ParseCalcDesc(const char* keypadDescription); void _PressKey(int key); @@ -121,8 +121,6 @@ class CalcView : public BView { void _FetchAppIcon(BBitmap* into); - status_t _LoadSettings(BMessage* archive); - // grid dimensions int16 fColumns; int16 fRows; @@ -165,6 +163,9 @@ class CalcView : public BView { // calculator options. CalcOptions* fOptions; + + // about window for replicant + BAboutWindow* fAboutWindow; }; #endif // _CALC_VIEW_H diff --git a/src/apps/deskcalc/CalcWindow.h b/src/apps/deskcalc/CalcWindow.h index 421f4605a9..5e6b16c769 100644 --- a/src/apps/deskcalc/CalcWindow.h +++ b/src/apps/deskcalc/CalcWindow.h @@ -31,6 +31,8 @@ class CalcWindow : public BWindow { void SetFrame(BRect frame, bool forceCenter = false); + CalcView* View() const { return fCalcView; }; + private: CalcView* fCalcView; }; diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index e7d968277e..74dbef066c 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include static const float kStripeWidth = 30.0; @@ -80,8 +81,12 @@ StripeView::StripeView(BBitmap* icon) BView("StripeView", B_WILL_DRAW), fIcon(icon) { - SetExplicitMinSize(BSize(160.0, B_SIZE_UNSET)); - SetExplicitPreferredSize(BSize(160.0, B_SIZE_UNLIMITED)); + float width = 48.0f; + if (icon != NULL) + width += icon->Bounds().Width() - 16.0f; + + SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); + SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } @@ -233,7 +238,7 @@ AboutView::AppIcon(const char* signature) BAboutWindow::BAboutWindow(const char* appName, int32 firstCopyrightYear, const char** authors, const char* extraInfo) - : BWindow(BRect(0.0, 0.0, 300.0, 140.0), appName, B_TITLED_WINDOW, + : BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS) { @@ -261,6 +266,19 @@ BAboutWindow::~BAboutWindow() } +bool +BAboutWindow::QuitRequested() +{ + while (!IsHidden()) + Hide(); + + return false; +} + + +// #pragma mark - + + void BAboutWindow::AddDescription(const char* description) { @@ -270,8 +288,11 @@ BAboutWindow::AddDescription(const char* description) const char* appDesc = B_TRANSLATE_MARK(description); appDesc = gSystemCatalog.GetString(appDesc, "AboutWindow"); - BString desc(appDesc); - desc << "\n\n"; + BString desc(""); + if (fAboutView->InfoView()->TextLength() > 0) + desc << "\n\n"; + + desc << appDesc; fAboutView->InfoView()->Insert(desc.String()); } @@ -281,10 +302,7 @@ void BAboutWindow::AddCopyright(int32 firstCopyrightYear, const char* copyrightHolder, const char** extraCopyrights) { - BString copyright(B_UTF8_COPYRIGHT " %years%"); - if (copyrightHolder != NULL) - copyright << " " << copyrightHolder; - + BString copyright(B_UTF8_COPYRIGHT " %years% %holder%"); const char* firstCopyright = B_TRANSLATE_MARK(copyright.String()); firstCopyright = gSystemCatalog.GetString(copyright, "AboutWindow"); @@ -298,23 +316,29 @@ BAboutWindow::AddCopyright(int32 firstCopyrightYear, if (copyrightYears != currentYear) copyrightYears << "-" << currentYear; - BString text(firstCopyright); + BString text(""); + if (fAboutView->InfoView()->TextLength() > 0) + text << "\n\n"; - // Replace the copyright year with the current year + text << firstCopyright; + + // Fill out the copyright year placeholder text.ReplaceAll("%years%", copyrightYears.String()); + // Fill in the copyright holder placeholder + text.ReplaceAll("%holder%", copyrightHolder); + // Add extra copyright strings if (extraCopyrights != NULL) { // Add optional extra copyright information for (int32 i = 0; extraCopyrights[i]; i++) text << "\n" << B_UTF8_COPYRIGHT << " " << extraCopyrights[i]; } - text << "\n"; const char* allRightsReserved = B_TRANSLATE_MARK("All Rights Reserved."); allRightsReserved = gSystemCatalog.GetString(allRightsReserved, "AboutWindow"); - text << " " << allRightsReserved << "\n\n"; + text << "\n " << allRightsReserved; fAboutView->InfoView()->Insert(text.String()); } @@ -329,11 +353,14 @@ BAboutWindow::AddAuthors(const char** authors) const char* writtenBy = B_TRANSLATE_MARK("Written by:"); writtenBy = gSystemCatalog.GetString(writtenBy, "AboutWindow"); - BString text(writtenBy); + BString text(""); + if (fAboutView->InfoView()->TextLength() > 0) + text << "\n\n"; + + text << writtenBy; text << "\n"; for (int32 i = 0; authors[i]; i++) text << " " << authors[i] << "\n"; - text << "\n"; fAboutView->InfoView()->Insert(text.String()); } @@ -348,11 +375,13 @@ BAboutWindow::AddSpecialThanks(const char** thanks) const char* specialThanks = B_TRANSLATE_MARK("Special Thanks:"); specialThanks = gSystemCatalog.GetString(specialThanks, "AboutWindow"); - BString text(specialThanks); - text << "\n"; + BString text(""); + if (fAboutView->InfoView()->TextLength() > 0) + text << "\n\n"; + + text << specialThanks << "\n"; for (int32 i = 0; thanks[i]; i++) text << " " << thanks[i] << "\n"; - text << "\n"; fAboutView->InfoView()->Insert(text.String()); } @@ -366,11 +395,14 @@ BAboutWindow::AddVersionHistory(const char** history) const char* versionHistory = B_TRANSLATE_MARK("Version history:"); versionHistory = gSystemCatalog.GetString(versionHistory, "AboutWindow"); - BString text(versionHistory); - text << "\n"; + + BString text(""); + if (fAboutView->InfoView()->TextLength() > 0) + text << "\n\n"; + + text << versionHistory << "\n"; for (int32 i = 0; history[i]; i++) text << " " << history[i] << "\n"; - text << "\n"; fAboutView->InfoView()->Insert(text.String()); } @@ -385,8 +417,11 @@ BAboutWindow::AddExtraInfo(const char* extraInfo) const char* appExtraInfo = B_TRANSLATE_MARK(extraInfo); appExtraInfo = gSystemCatalog.GetString(extraInfo, "AboutWindow"); - BString extra(appExtraInfo); - extra << "\n"; + BString extra(""); + if (fAboutView->InfoView()->TextLength() > 0) + extra << "\n\n"; + + extra << appExtraInfo; fAboutView->InfoView()->Insert(extra.String()); } @@ -409,7 +444,8 @@ BAboutWindow::AboutPosition(float width, float height) result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 2.0); // This is probably sooo wrong, but it looks right on 1024 x 768 - result.y = screenFrame.top + (screenFrame.Height() / 4.0) - ceil(height / 3.0); + result.y = screenFrame.top + (screenFrame.Height() / 4.0) + - ceil(height / 3.0); return result; } From 3fdab584468f3b71e8a1ecc4238ed6699cfe78cd Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 03:31:21 -0400 Subject: [PATCH 39/66] Set the about window object to NULL on close or quit. Pass the BHandler object that opened the about window to BAboutWindow. When the window closes, send a kAboutWindowClosed message back to the handler. This allows the handler to set the variable to NULL. Implement the new about dialog constructor in all apps that use it. Remove the old constructor. This now works reliably for all cases I tested without crashing and does the right thing on close. The setup and teardown is a bit more complicated than I wanted though. Unfortunately this seems to be necessary when not using a BAlert. Fetching the app icon does not work reliably yet. This is because for replicants the app may not be running. I may have to pass the icon in instead of grabbing it from the signature. --- headers/private/shared/AboutWindow.h | 10 ++-- src/apps/activitymonitor/ActivityView.cpp | 21 ++++++-- src/apps/deskcalc/CalcView.cpp | 34 ++++++++----- src/apps/deskcalc/CalcView.h | 4 +- .../processcontroller/ProcessController.cpp | 46 ++++++++++------- .../processcontroller/ProcessController.h | 3 +- src/kits/shared/AboutWindow.cpp | 48 ++++++------------ src/preferences/locale/LocalePreflet.cpp | 50 ++++++++++++------- 8 files changed, 120 insertions(+), 96 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 3741d2c3bc..c314a7c5f8 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -11,16 +11,16 @@ #include +const int32 kAboutWindowClosed = 'abwc'; + class AboutView; class BPoint; +class BHandler; class BAboutWindow : public BWindow { public: - BAboutWindow(const char* appName, - int32 firstCopyrightYear, - const char** authors = NULL, - const char* extraInfo = NULL); - BAboutWindow(const char* appName, + BAboutWindow(BHandler* handler, + const char* appName, const char* signature); virtual ~BAboutWindow(); diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index 664ef9a564..13959ccbbf 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -601,7 +601,9 @@ ActivityView::~ActivityView() delete fOffscreen; delete fSystemInfoHandler; - fAboutWindow->Quit(); + // replicant deleted, destroy the about window + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -618,9 +620,6 @@ ActivityView::_Init(const BMessage* settings) #endif SetViewColor(B_TRANSPARENT_COLOR); - fAboutWindow = new BAboutWindow(kAppName, kSignature); - fAboutWindow->AddCopyright(2008, "Haiku, Inc."); - fLastRefresh = 0; fDrawResolution = 1; fZooming = false; @@ -648,6 +647,8 @@ ActivityView::_Init(const BMessage* settings) const char* name; for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) AddDataSource(DataSource::FindSource(name), settings); + + fAboutWindow = NULL; } @@ -1111,7 +1112,17 @@ ActivityView::MessageReceived(BMessage* message) switch (message->what) { case B_ABOUT_REQUESTED: - fAboutWindow->Show(); + if (fAboutWindow == NULL) { + fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow->AddCopyright(2008, "Haiku, Inc."); + fAboutWindow->Show(); + } else + fAboutWindow->Activate(); + + break; + + case kAboutWindowClosed: + fAboutWindow = NULL; break; case kMsgUpdateResolution: diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 285671cf5d..814c36f543 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -184,7 +184,9 @@ CalcView::~CalcView() delete fOptions; free(fKeypadDescription); - fAboutWindow->Quit(); + // replicant deleted, destroy the about window + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -268,7 +270,24 @@ CalcView::MessageReceived(BMessage* message) // (replicant) about box requested case B_ABOUT_REQUESTED: - fAboutWindow->Show(); + if (fAboutWindow == NULL) { + // create the about window + const char* extraCopyrights[] = { + "1997, 1998 R3 Software Ltd.", + NULL + }; + + fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow->AddCopyright(2006, "Haiku, Inc.", + extraCopyrights); + fAboutWindow->Show(); + } else + fAboutWindow->Activate(); + + break; + + case kAboutWindowClosed: + fAboutWindow = NULL; break; case MSG_UNFLASH_KEY: @@ -971,16 +990,6 @@ CalcView::SetKeypadMode(uint8 mode) void CalcView::_Init(BMessage* settings) { - // create the about window - const char* extraCopyrights[] = { - "1997, 1998 R3 Software Ltd.", - NULL - }; - - fAboutWindow = new BAboutWindow(kAppName, kSignature); - fAboutWindow->AddCopyright(2006, "Haiku, Inc.", - extraCopyrights); - // create expression text view fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); AddChild(fExpressionTextView); @@ -991,6 +1000,7 @@ CalcView::_Init(BMessage* settings) // fetch the calc icon for compact view _FetchAppIcon(fCalcIcon); + fAboutWindow = NULL; } diff --git a/src/apps/deskcalc/CalcView.h b/src/apps/deskcalc/CalcView.h index 50a121df7d..446d44dfd9 100644 --- a/src/apps/deskcalc/CalcView.h +++ b/src/apps/deskcalc/CalcView.h @@ -50,9 +50,7 @@ class CalcView : public BView { CalcView(BRect frame, rgb_color rgbBaseColor, BMessage* settings); - CalcView(BMessage* archive); - virtual ~CalcView(); virtual void AttachedToWindow(); @@ -62,7 +60,7 @@ class CalcView : public BView { virtual void MouseUp(BPoint point); virtual void KeyDown(const char* bytes, int32 numBytes); virtual void MakeFocus(bool focused = true); - virtual void ResizeTo(float width, float height); + virtual void ResizeTo(float width, float height); virtual void FrameResized(float width, float height); // Archive this view. diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index 8f9417554c..cbecafe1c4 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -204,6 +204,10 @@ ProcessController::~ProcessController() delete fMessageRunner; gPCView = NULL; + + // replicant deleted, destroy the about window + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -217,10 +221,11 @@ ProcessController::Init() memset(fCPUTimes, 0, sizeof(fCPUTimes)); memset(fPrevActive, 0, sizeof(fPrevActive)); fPrevTime = 0; + fAboutWindow = NULL; } -ProcessController * +ProcessController* ProcessController::Instantiate(BMessage *data) { if (!validate_instantiation(data, kClassName)) @@ -421,7 +426,29 @@ ProcessController::MessageReceived(BMessage *message) } case B_ABOUT_REQUESTED: - AboutRequested(); + if (fAboutWindow == NULL) { + const char* extraCopyrights[] = { + "1997-2001 Georges-Edouard Berenger", + NULL + }; + + const char* authors[] = { + "Georges-Edouard Berenger", + NULL + }; + + fAboutWindow = new BAboutWindow(this, + B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature); + fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); + fAboutWindow->AddAuthors(authors); + fAboutWindow->Show(); + } else + fAboutWindow->Activate(); + + break; + + case kAboutWindowClosed: + fAboutWindow = NULL; break; default: @@ -430,21 +457,6 @@ ProcessController::MessageReceived(BMessage *message) } -void -ProcessController::AboutRequested() -{ - const char* authors[] = { - "Georges-Edouard Berenger", - NULL - }; - - BAboutWindow about(B_TRANSLATE_SYSTEM_NAME("ProcessController"), 2007, authors, - "Copyright 1997-2001\n" - "Georges-Edouard Berenger."); - about.Show(); -} - - void ProcessController::DefaultColors() { diff --git a/src/apps/processcontroller/ProcessController.h b/src/apps/processcontroller/ProcessController.h index d158c6b8cb..33e3dc2bb3 100644 --- a/src/apps/processcontroller/ProcessController.h +++ b/src/apps/processcontroller/ProcessController.h @@ -25,6 +25,7 @@ #include +class BAboutWindow; class BMessageRunner; class ThreadBarMenu; @@ -44,7 +45,6 @@ class ProcessController : public BView { static ProcessController* Instantiate(BMessage* data); virtual status_t Archive(BMessage *data, bool deep = true) const; - void AboutRequested(); void Update(); void DefaultColors(); @@ -58,6 +58,7 @@ class ProcessController : public BView { private: void Init(); + BAboutWindow* fAboutWindow; bool fTemp; float fMemoryUsage; float fLastBarHeight[B_MAX_CPU_COUNT]; diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 74dbef066c..c480033bbd 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -208,27 +208,15 @@ AboutView::AppIcon(const char* signature) if (signature == NULL) return NULL; - app_info appInfo; - if (be_roster->GetAppInfo(signature, &appInfo) != B_OK) + entry_ref ref; + if (be_roster->FindApp(signature, &ref) != B_OK) return NULL; - BFile file(&appInfo.ref, B_READ_ONLY); - BAppFileInfo appMime(&file); - if (appMime.InitCheck() != B_OK) - return NULL; - - // fetch the app icon BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32); - if (appMime.GetIcon(icon, B_LARGE_ICON) == B_OK) - return icon; - - // couldn't find the app icon - // fetch the generic 3 boxes icon - BMimeType defaultAppMime; - defaultAppMime.SetTo(B_APP_MIME_TYPE); - if (defaultAppMime.GetIcon(icon, B_LARGE_ICON) == B_OK) + if (BNodeInfo::GetTrackerIcon(&ref, icon) == B_OK) return icon; + delete icon; return NULL; } @@ -236,23 +224,11 @@ AboutView::AppIcon(const char* signature) // #pragma mark - -BAboutWindow::BAboutWindow(const char* appName, int32 firstCopyrightYear, - const char** authors, const char* extraInfo) - : BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE - | B_AUTO_UPDATE_SIZE_LIMITS) -{ - _Init(appName, NULL); - AddCopyright(firstCopyrightYear, "Haiku, Inc.", NULL); - AddAuthors(authors); - AddExtraInfo(extraInfo); -} - - -BAboutWindow::BAboutWindow(const char* appName, const char* signature) +BAboutWindow::BAboutWindow(BHandler* handler, const char* appName, const char* signature) : BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE - | B_AUTO_UPDATE_SIZE_LIMITS) + | B_AUTO_UPDATE_SIZE_LIMITS), + fCaller(handler) { _Init(appName, signature); } @@ -269,10 +245,14 @@ BAboutWindow::~BAboutWindow() bool BAboutWindow::QuitRequested() { - while (!IsHidden()) - Hide(); + if (fCaller != NULL) { + status_t status; + BMessenger messenger(fCaller, NULL, &status); + if (status == B_OK && messenger.IsValid()) + messenger.SendMessage(new BMessage(kAboutWindowClosed)); + } - return false; + return true; } diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index 5db4bfb600..81dc7eda44 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -21,6 +21,7 @@ #define B_TRANSLATION_CONTEXT "Locale Preflet" +const char* kAppName = B_TRANSLATE("Locale"); const char* kSignature = "application/x-vnd.Haiku-Locale"; @@ -29,13 +30,13 @@ class LocalePreflet : public BApplication { LocalePreflet(); virtual ~LocalePreflet(); - virtual void AboutRequested(); virtual void MessageReceived(BMessage* message); private: status_t _RestartApp(const char* signature) const; LocaleWindow* fLocaleWindow; + BAboutWindow* fAboutWindow; }; @@ -44,30 +45,19 @@ private: LocalePreflet::LocalePreflet() : - BApplication(kSignature) + BApplication(kSignature), + fLocaleWindow(new LocaleWindow()), + fAboutWindow(NULL) { - fLocaleWindow = new LocaleWindow(); - fLocaleWindow->Show(); } LocalePreflet::~LocalePreflet() { -} - - -void -LocalePreflet::AboutRequested() -{ - const char* authors[] = { - "Axel Dörfler", - "Adrien Destugues", - "Oliver Tappe", - NULL - }; - BAboutWindow about(B_TRANSLATE("Locale"), 2005, authors); - about.Show(); + // replicant deleted, destroy the about window + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -81,7 +71,29 @@ LocalePreflet::MessageReceived(BMessage* message) _RestartApp("application/x-vnd.Be-TSKB"); } break; - + + case B_ABOUT_REQUESTED: + if (fAboutWindow == NULL) { + const char* authors[] = { + "Axel Dörfler", + "Adrien Destugues", + "Oliver Tappe", + NULL + }; + + fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow->AddCopyright(2005, "Haiku, Inc."); + fAboutWindow->AddAuthors(authors); + fAboutWindow->Show(); + } else + fAboutWindow->Activate(); + + break; + + case kAboutWindowClosed: + fAboutWindow = NULL; + break; + default: BApplication::MessageReceived(message); break; From 12a9a71db61beed2755d9916f454a61500613630 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 13:48:47 -0400 Subject: [PATCH 40/66] Use a quit bool in B_ABOUT_REQUESTED to indicate that the about window has quit instead of using kAboutWindowClosed message. This prevents message signature clashes. --- headers/private/shared/AboutWindow.h | 2 -- src/apps/activitymonitor/ActivityView.cpp | 12 ++++++++---- src/apps/deskcalc/CalcView.cpp | 12 ++++++++---- src/apps/processcontroller/ProcessController.cpp | 12 ++++++++---- src/kits/shared/AboutWindow.cpp | 8 ++++++-- src/preferences/locale/LocalePreflet.cpp | 12 ++++++++---- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index c314a7c5f8..7c5b789449 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -11,8 +11,6 @@ #include -const int32 kAboutWindowClosed = 'abwc'; - class AboutView; class BPoint; class BHandler; diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index 13959ccbbf..20113b8a9d 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -1112,6 +1112,13 @@ ActivityView::MessageReceived(BMessage* message) switch (message->what) { case B_ABOUT_REQUESTED: + { + bool quit = false; + if (message->FindBool("quit", &quit) == B_OK && quit) { + fAboutWindow = NULL; + break; + } + if (fAboutWindow == NULL) { fAboutWindow = new BAboutWindow(this, kAppName, kSignature); fAboutWindow->AddCopyright(2008, "Haiku, Inc."); @@ -1120,10 +1127,7 @@ ActivityView::MessageReceived(BMessage* message) fAboutWindow->Activate(); break; - - case kAboutWindowClosed: - fAboutWindow = NULL; - break; + } case kMsgUpdateResolution: { diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 814c36f543..6568a9b479 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -270,6 +270,13 @@ CalcView::MessageReceived(BMessage* message) // (replicant) about box requested case B_ABOUT_REQUESTED: + { + bool quit = false; + if (message->FindBool("quit", &quit) == B_OK && quit) { + fAboutWindow = NULL; + break; + } + if (fAboutWindow == NULL) { // create the about window const char* extraCopyrights[] = { @@ -285,10 +292,7 @@ CalcView::MessageReceived(BMessage* message) fAboutWindow->Activate(); break; - - case kAboutWindowClosed: - fAboutWindow = NULL; - break; + } case MSG_UNFLASH_KEY: { diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index cbecafe1c4..660ff2497b 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -426,6 +426,13 @@ ProcessController::MessageReceived(BMessage *message) } case B_ABOUT_REQUESTED: + { + bool quit = false; + if (message->FindBool("quit", &quit) == B_OK && quit) { + fAboutWindow = NULL; + break; + } + if (fAboutWindow == NULL) { const char* extraCopyrights[] = { "1997-2001 Georges-Edouard Berenger", @@ -446,10 +453,7 @@ ProcessController::MessageReceived(BMessage *message) fAboutWindow->Activate(); break; - - case kAboutWindowClosed: - fAboutWindow = NULL; - break; + } default: BView::MessageReceived(message); diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index c480033bbd..e5def2f31f 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -248,8 +248,12 @@ BAboutWindow::QuitRequested() if (fCaller != NULL) { status_t status; BMessenger messenger(fCaller, NULL, &status); - if (status == B_OK && messenger.IsValid()) - messenger.SendMessage(new BMessage(kAboutWindowClosed)); + if (status == B_OK && messenger.IsValid()) { + BMessage* message = new BMessage(B_ABOUT_REQUESTED); + message->AddBool("quit", true); + messenger.SendMessage(message); + delete message; + } } return true; diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index 81dc7eda44..d8945f27ef 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -73,6 +73,13 @@ LocalePreflet::MessageReceived(BMessage* message) break; case B_ABOUT_REQUESTED: + { + bool quit = false; + if (message->FindBool("quit", &quit) == B_OK && quit) { + fAboutWindow = NULL; + break; + } + if (fAboutWindow == NULL) { const char* authors[] = { "Axel Dörfler", @@ -89,10 +96,7 @@ LocalePreflet::MessageReceived(BMessage* message) fAboutWindow->Activate(); break; - - case kAboutWindowClosed: - fAboutWindow = NULL; - break; + } default: BApplication::MessageReceived(message); From a792461b21227f9145c6baa604933d9d36fce504 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 14:07:11 -0400 Subject: [PATCH 41/66] Pass in 128 as an icon_size to GetTrackerIcon(), this makes it grab a nice 128x128 HVIF icon --- src/kits/shared/AboutWindow.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index e5def2f31f..46100e73b5 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -81,9 +81,9 @@ StripeView::StripeView(BBitmap* icon) BView("StripeView", B_WILL_DRAW), fIcon(icon) { - float width = 48.0f; + float width = 0.0f; if (icon != NULL) - width += icon->Bounds().Width() - 16.0f; + width += icon->Bounds().Width() + 32.0f; SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); @@ -99,6 +99,9 @@ StripeView::~StripeView() void StripeView::Draw(BRect updateRect) { + if (fIcon == NULL) + return; + SetHighColor(ViewColor()); FillRect(updateRect); @@ -107,9 +110,6 @@ StripeView::Draw(BRect updateRect) SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); FillRect(stripeRect); - if (fIcon == NULL) - return; - SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); DrawBitmapAsync(fIcon, BPoint(15.0, 5.0)); @@ -213,7 +213,7 @@ AboutView::AppIcon(const char* signature) return NULL; BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32); - if (BNodeInfo::GetTrackerIcon(&ref, icon) == B_OK) + if (BNodeInfo::GetTrackerIcon(&ref, icon, (icon_size)128) == B_OK) return icon; delete icon; @@ -225,7 +225,7 @@ AboutView::AppIcon(const char* signature) BAboutWindow::BAboutWindow(BHandler* handler, const char* appName, const char* signature) - : BWindow(BRect(0.0, 0.0, 310.0, 140.0), appName, B_TITLED_WINDOW, + : BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), fCaller(handler) From 6cdd1023ab743a1deda5e6f48a248c4f00fc18e5 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 14:39:02 -0400 Subject: [PATCH 42/66] Get the icon and version from FindApp which works whether or not the app is currently running. This makes process controller show it's icon and version even though it lives in Deskbar. --- src/kits/shared/AboutWindow.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 46100e73b5..5f5f6e13af 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -172,11 +172,11 @@ AboutView::AppVersion(const char* signature) if (signature == NULL) return NULL; - app_info appInfo; - if (be_roster->GetAppInfo(signature, &appInfo) != B_OK) + entry_ref ref; + if (be_roster->FindApp(signature, &ref) != B_OK) return NULL; - BFile file(&appInfo.ref, B_READ_ONLY); + BFile file(&ref, B_READ_ONLY); BAppFileInfo appMime(&file); if (appMime.InitCheck() != B_OK) return NULL; @@ -212,8 +212,13 @@ AboutView::AppIcon(const char* signature) if (be_roster->FindApp(signature, &ref) != B_OK) return NULL; + BFile file(&ref, B_READ_ONLY); + BAppFileInfo appMime(&file); + if (appMime.InitCheck() != B_OK) + return NULL; + BBitmap* icon = new BBitmap(BRect(0.0, 0.0, 127.0, 127.0), B_RGBA32); - if (BNodeInfo::GetTrackerIcon(&ref, icon, (icon_size)128) == B_OK) + if (appMime.GetIcon(icon, (icon_size)128) == B_OK) return icon; delete icon; From 0fbb37d23860526352b22a73c1816e41c7a2329c Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 14:40:24 -0400 Subject: [PATCH 43/66] Move the app icon down a bit. --- src/kits/shared/AboutWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 5f5f6e13af..a64321ddc5 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -112,7 +112,7 @@ StripeView::Draw(BRect updateRect) SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - DrawBitmapAsync(fIcon, BPoint(15.0, 5.0)); + DrawBitmapAsync(fIcon, BPoint(31.0, 5.0)); } From 04875296c4fe3e58628e4cbe0eb813cbdb40e6ca Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 15:26:52 -0400 Subject: [PATCH 44/66] Add version variety to the end of the version string (alpha, beta, etc.) --- src/kits/shared/AboutWindow.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index a64321ddc5..c22b72d77d 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -112,7 +112,7 @@ StripeView::Draw(BRect updateRect) SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - DrawBitmapAsync(fIcon, BPoint(31.0, 5.0)); + DrawBitmapAsync(fIcon, BPoint(15.0f, 10.0f)); } @@ -195,6 +195,31 @@ AboutView::AppVersion(const char* signature) if (versionInfo.minor > 0) appVersion << "." << versionInfo.minor; + // Add the version variety + const char* variety = NULL; + switch (versionInfo.variety) { + case B_DEVELOPMENT_VERSION: + variety = B_TRANSLATE_MARK("development"); + break; + case B_ALPHA_VERSION: + variety = B_TRANSLATE_MARK("alpha"); + break; + case B_BETA_VERSION: + variety = B_TRANSLATE_MARK("beta"); + break; + case B_GAMMA_VERSION: + variety = B_TRANSLATE_MARK("gamma"); + break; + case B_GOLDEN_MASTER_VERSION: + variety = B_TRANSLATE_MARK("gold master"); + break; + } + + if (variety != NULL) { + variety = gSystemCatalog.GetString(variety, "AboutWindow"); + appVersion << "-" << variety; + } + return appVersion.String(); } From 97a814061e5b6fc26fbfedf2efb859ec2bcf87a1 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:01:31 -0400 Subject: [PATCH 45/66] Instead of destroying the BAboutWindow object on close, Hide() it, then on the destructor of the calling window call Quit() explicitly to destroy it. --- headers/private/shared/AboutWindow.h | 3 +-- src/apps/activitymonitor/ActivityView.cpp | 14 ++++---------- src/apps/deskcalc/CalcView.cpp | 14 ++++---------- .../processcontroller/ProcessController.cpp | 14 ++++---------- src/kits/shared/AboutWindow.cpp | 18 ++++-------------- src/preferences/locale/LocalePreflet.cpp | 14 ++++---------- 6 files changed, 21 insertions(+), 56 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 7c5b789449..423d9f4e1a 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -17,8 +17,7 @@ class BHandler; class BAboutWindow : public BWindow { public: - BAboutWindow(BHandler* handler, - const char* appName, + BAboutWindow(const char* appName, const char* signature); virtual ~BAboutWindow(); diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index 20113b8a9d..eb78190ed3 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -1112,22 +1112,16 @@ ActivityView::MessageReceived(BMessage* message) switch (message->what) { case B_ABOUT_REQUESTED: - { - bool quit = false; - if (message->FindBool("quit", &quit) == B_OK && quit) { - fAboutWindow = NULL; - break; - } - if (fAboutWindow == NULL) { - fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow = new BAboutWindow(kAppName, kSignature); fAboutWindow->AddCopyright(2008, "Haiku, Inc."); fAboutWindow->Show(); - } else + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else fAboutWindow->Activate(); break; - } case kMsgUpdateResolution: { diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 6568a9b479..9c01f30e16 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -270,13 +270,6 @@ CalcView::MessageReceived(BMessage* message) // (replicant) about box requested case B_ABOUT_REQUESTED: - { - bool quit = false; - if (message->FindBool("quit", &quit) == B_OK && quit) { - fAboutWindow = NULL; - break; - } - if (fAboutWindow == NULL) { // create the about window const char* extraCopyrights[] = { @@ -284,15 +277,16 @@ CalcView::MessageReceived(BMessage* message) NULL }; - fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow = new BAboutWindow(kAppName, kSignature); fAboutWindow->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); fAboutWindow->Show(); - } else + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else fAboutWindow->Activate(); break; - } case MSG_UNFLASH_KEY: { diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index 660ff2497b..66bc517e41 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -426,13 +426,6 @@ ProcessController::MessageReceived(BMessage *message) } case B_ABOUT_REQUESTED: - { - bool quit = false; - if (message->FindBool("quit", &quit) == B_OK && quit) { - fAboutWindow = NULL; - break; - } - if (fAboutWindow == NULL) { const char* extraCopyrights[] = { "1997-2001 Georges-Edouard Berenger", @@ -444,16 +437,17 @@ ProcessController::MessageReceived(BMessage *message) NULL }; - fAboutWindow = new BAboutWindow(this, + fAboutWindow = new BAboutWindow( B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature); fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); fAboutWindow->AddAuthors(authors); fAboutWindow->Show(); - } else + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else fAboutWindow->Activate(); break; - } default: BView::MessageReceived(message); diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index c22b72d77d..696fb17388 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -254,11 +254,10 @@ AboutView::AppIcon(const char* signature) // #pragma mark - -BAboutWindow::BAboutWindow(BHandler* handler, const char* appName, const char* signature) +BAboutWindow::BAboutWindow(const char* appName, const char* signature) : BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE - | B_AUTO_UPDATE_SIZE_LIMITS), - fCaller(handler) + | B_AUTO_UPDATE_SIZE_LIMITS) { _Init(appName, signature); } @@ -275,18 +274,9 @@ BAboutWindow::~BAboutWindow() bool BAboutWindow::QuitRequested() { - if (fCaller != NULL) { - status_t status; - BMessenger messenger(fCaller, NULL, &status); - if (status == B_OK && messenger.IsValid()) { - BMessage* message = new BMessage(B_ABOUT_REQUESTED); - message->AddBool("quit", true); - messenger.SendMessage(message); - delete message; - } - } + Hide(); - return true; + return false; } diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index d8945f27ef..d71b26be72 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -73,13 +73,6 @@ LocalePreflet::MessageReceived(BMessage* message) break; case B_ABOUT_REQUESTED: - { - bool quit = false; - if (message->FindBool("quit", &quit) == B_OK && quit) { - fAboutWindow = NULL; - break; - } - if (fAboutWindow == NULL) { const char* authors[] = { "Axel Dörfler", @@ -88,15 +81,16 @@ LocalePreflet::MessageReceived(BMessage* message) NULL }; - fAboutWindow = new BAboutWindow(this, kAppName, kSignature); + fAboutWindow = new BAboutWindow(kAppName, kSignature); fAboutWindow->AddCopyright(2005, "Haiku, Inc."); fAboutWindow->AddAuthors(authors); fAboutWindow->Show(); - } else + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else fAboutWindow->Activate(); break; - } default: BApplication::MessageReceived(message); From d156f97655ce79535a29f528a3aed4a2de21e8ee Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:17:00 -0400 Subject: [PATCH 46/66] Get rid of the _Init() method in BAboutWindow, just the single constructor body. --- headers/private/shared/AboutWindow.h | 3 --- src/kits/shared/AboutWindow.cpp | 36 ++++++++++------------------ 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 423d9f4e1a..57e79e7392 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -34,9 +34,6 @@ class BAboutWindow : public BWindow { BPoint AboutPosition(float width, float height); - protected: - void _Init(const char* appName, const char* signature); - private: AboutView* fAboutView; BHandler* fCaller; diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 696fb17388..cf513a9d39 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -259,7 +259,19 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature) B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS) { - _Init(appName, signature); + SetLayout(new BGroupLayout(B_VERTICAL)); + + const char* about = B_TRANSLATE_MARK("About"); + about = gSystemCatalog.GetString(about, "AboutWindow"); + + BString title(about); + title << " " << appName; + SetTitle(title.String()); + + fAboutView = new AboutView(appName, signature); + AddChild(fAboutView); + + MoveTo(AboutPosition(Frame().Width(), Frame().Height())); } @@ -453,25 +465,3 @@ BAboutWindow::AboutPosition(float width, float height) return result; } - - -// #pragma mark - - - -void -BAboutWindow::_Init(const char* appName, const char* signature) -{ - SetLayout(new BGroupLayout(B_VERTICAL)); - - const char* about = B_TRANSLATE_MARK("About"); - about = gSystemCatalog.GetString(about, "AboutWindow"); - - BString title(about); - title << " " << appName; - SetTitle(title.String()); - - fAboutView = new AboutView(appName, signature); - AddChild(fAboutView); - - MoveTo(AboutPosition(Frame().Width(), Frame().Height())); -} From c73d4b3dc21ef6fb52f17c174d55fba92b54f3e9 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:22:23 -0400 Subject: [PATCH 47/66] Move AboutPosition() method up. --- headers/private/shared/AboutWindow.h | 3 +- src/kits/shared/AboutWindow.cpp | 48 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 57e79e7392..1d03fb1226 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -23,6 +23,7 @@ class BAboutWindow : public BWindow { virtual bool QuitRequested(); + BPoint AboutPosition(float width, float height); void AddDescription(const char* description); void AddCopyright(int32 firstCopyrightYear, const char* copyrightHolder, @@ -32,8 +33,6 @@ class BAboutWindow : public BWindow { void AddVersionHistory(const char** history); void AddExtraInfo(const char* extraInfo); - BPoint AboutPosition(float width, float height); - private: AboutView* fAboutView; BHandler* fCaller; diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index cf513a9d39..cb30ee8ee5 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -295,6 +295,30 @@ BAboutWindow::QuitRequested() // #pragma mark - +BPoint +BAboutWindow::AboutPosition(float width, float height) +{ + BPoint result(100, 100); + + BWindow* window = + dynamic_cast(BLooper::LooperForThread(find_thread(NULL))); + + BScreen screen(window); + BRect screenFrame(0, 0, 640, 480); + if (screen.IsValid()) + screenFrame = screen.Frame(); + + // Horizontally, we're smack in the middle + result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 2.0); + + // This is probably sooo wrong, but it looks right on 1024 x 768 + result.y = screenFrame.top + (screenFrame.Height() / 4.0) + - ceil(height / 3.0); + + return result; +} + + void BAboutWindow::AddDescription(const char* description) { @@ -441,27 +465,3 @@ BAboutWindow::AddExtraInfo(const char* extraInfo) fAboutView->InfoView()->Insert(extra.String()); } - - -BPoint -BAboutWindow::AboutPosition(float width, float height) -{ - BPoint result(100, 100); - - BWindow* window = - dynamic_cast(BLooper::LooperForThread(find_thread(NULL))); - - BScreen screen(window); - BRect screenFrame(0, 0, 640, 480); - if (screen.IsValid()) - screenFrame = screen.Frame(); - - // Horizontally, we're smack in the middle - result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 2.0); - - // This is probably sooo wrong, but it looks right on 1024 x 768 - result.y = screenFrame.top + (screenFrame.Height() / 4.0) - - ceil(height / 3.0); - - return result; -} From d1b2e338efa3e5c11786c846de2f2a23cc27ba3a Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:24:53 -0400 Subject: [PATCH 48/66] There is nothing to translate in the initial copyright string, it is just '(c) %years% %holder%' --- src/kits/shared/AboutWindow.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index cb30ee8ee5..753dbbf014 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -343,8 +343,6 @@ BAboutWindow::AddCopyright(int32 firstCopyrightYear, const char* copyrightHolder, const char** extraCopyrights) { BString copyright(B_UTF8_COPYRIGHT " %years% %holder%"); - const char* firstCopyright = B_TRANSLATE_MARK(copyright.String()); - firstCopyright = gSystemCatalog.GetString(copyright, "AboutWindow"); // Get current year time_t tp; From 80d7bf83bdaf85b1676816ccdbd2c60f2a72c167 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:30:28 -0400 Subject: [PATCH 49/66] Add authors back. --- src/apps/activitymonitor/ActivityView.cpp | 6 ++++++ src/apps/deskcalc/CalcView.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index eb78190ed3..fc4f32efa0 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -1113,8 +1113,14 @@ ActivityView::MessageReceived(BMessage* message) switch (message->what) { case B_ABOUT_REQUESTED: if (fAboutWindow == NULL) { + const char* authors[] = { + "Axel Dörfler", + NULL + }; + fAboutWindow = new BAboutWindow(kAppName, kSignature); fAboutWindow->AddCopyright(2008, "Haiku, Inc."); + fAboutWindow->AddAuthors(authors); fAboutWindow->Show(); } else if (fAboutWindow->IsHidden()) fAboutWindow->Show(); diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 9c01f30e16..7a158ca757 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -277,9 +277,18 @@ CalcView::MessageReceived(BMessage* message) NULL }; + const char* authors[] = { + "Stephan Aßmus", + "John Scipione", + "Timothy Wayper", + "Ingo Weinhold", + NULL + }; + fAboutWindow = new BAboutWindow(kAppName, kSignature); fAboutWindow->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); + fAboutWindow->AddAuthors(authors); fAboutWindow->Show(); } else if (fAboutWindow->IsHidden()) fAboutWindow->Show(); From 7031e2beb2b29121d7633928bf719d73aca679d8 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sat, 18 Aug 2012 16:40:17 -0400 Subject: [PATCH 50/66] Fix build, that's what I get for committing without testing first. --- src/kits/shared/AboutWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index 753dbbf014..b39ea25808 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -358,7 +358,7 @@ BAboutWindow::AddCopyright(int32 firstCopyrightYear, if (fAboutView->InfoView()->TextLength() > 0) text << "\n\n"; - text << firstCopyright; + text << copyright; // Fill out the copyright year placeholder text.ReplaceAll("%years%", copyrightYears.String()); From 96a5a088ba7b83989262cc7e01034a589a068ccd Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 00:28:06 -0500 Subject: [PATCH 51/66] Add the authors back to AboutWindow.h, also use <> style for email addresses --- headers/private/shared/AboutWindow.h | 4 ++++ src/kits/shared/AboutWindow.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 1d03fb1226..6dcaa77845 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -1,6 +1,10 @@ /* * Copyright 2007-2012 Haiku, Inc. * Distributed under the terms of the MIT License. + * + * Authors: + * Ryan Leavengood + * John Scipione */ #ifndef B_ABOUT_WINDOW_H #define B_ABOUT_WINDOW_H diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index b39ea25808..a6b20e8da2 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -3,8 +3,8 @@ * Distributed under the terms of the MIT License. * * Authors: - * Ryan Leavengood, leavengood@gmail.com - * John Scipione, jscipione@gmail.com + * Ryan Leavengood + * John Scipione */ From cea381197409f6102836e57678dc3848c76e108f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 00:36:33 -0500 Subject: [PATCH 52/66] Remove About DeskCalc... from right click menu. We decided not to include about dialogs in system apps (right?) --- src/apps/deskcalc/CalcView.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 7a158ca757..b2af685692 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -1298,9 +1298,6 @@ CalcView::_CreatePopUpMenu(bool addKeypadModeMenuItems) fKeypadModeScientificItem = new BMenuItem(B_TRANSLATE("Scientific"), new BMessage(MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC), '2'); } - BMenuItem* aboutItem - = new BMenuItem(B_TRANSLATE("About DeskCalc" B_UTF8_ELLIPSIS), - new BMessage(B_ABOUT_REQUESTED)); // apply current settings fAutoNumlockItem->SetMarked(fOptions->auto_num_lock); @@ -1325,8 +1322,6 @@ CalcView::_CreatePopUpMenu(bool addKeypadModeMenuItems) fPopUpMenu->AddItem(fKeypadModeScientificItem); _MarkKeypadItems(fOptions->keypad_mode); } - fPopUpMenu->AddSeparatorItem(); - fPopUpMenu->AddItem(aboutItem); } From 5bf91175bc99816d1c07656bf4be07b86ee14488 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 00:45:01 -0500 Subject: [PATCH 53/66] Haiku may be alpha quality, but DeskCalc isn't --- src/apps/deskcalc/DeskCalc.rdef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/deskcalc/DeskCalc.rdef b/src/apps/deskcalc/DeskCalc.rdef index 7cfe95e212..73cd064257 100644 --- a/src/apps/deskcalc/DeskCalc.rdef +++ b/src/apps/deskcalc/DeskCalc.rdef @@ -8,7 +8,7 @@ resource app_version { middle = 4, minor = 0, - variety = B_APPV_ALPHA, + variety = B_APPV_FINAL, internal = 1, short_info = "DeskCalc", From 730a45ee8f314649f7989e1014287b4766875fe1 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:12:44 -0500 Subject: [PATCH 54/66] Rework NetworkStatus to use a non-modal BAboutWindow --- src/apps/networkstatus/Jamfile | 2 +- src/apps/networkstatus/NetworkStatusView.cpp | 41 ++++++++++---------- src/apps/networkstatus/NetworkStatusView.h | 3 ++ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/apps/networkstatus/Jamfile b/src/apps/networkstatus/Jamfile index 9cc32fba80..c05d505124 100644 --- a/src/apps/networkstatus/Jamfile +++ b/src/apps/networkstatus/Jamfile @@ -17,7 +17,7 @@ Application NetworkStatus : RadioView.cpp WirelessNetworkMenuItem.cpp - : be $(HAIKU_LOCALE_LIBS) $(icon_libs) $(TARGET_NETWORK_LIBS) + : be libshared.a $(HAIKU_LOCALE_LIBS) $(icon_libs) $(TARGET_NETWORK_LIBS) libbnetapi.so $(TARGET_LIBSTDC++) : NetworkStatus.rdef NetworkStatusIcons.rdef ; diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index 626cb60757..73a55f24c5 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -138,6 +139,9 @@ NetworkStatusView::NetworkStatusView(BMessage* archive) NetworkStatusView::~NetworkStatusView() { + // replicant deleted, destroy the about window + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -150,6 +154,7 @@ NetworkStatusView::_Init() } _UpdateBitmaps(); + fAboutWindow = NULL; } @@ -216,7 +221,7 @@ NetworkStatusView::_Quit() } -NetworkStatusView * +NetworkStatusView* NetworkStatusView::Instantiate(BMessage* archive) { if (!validate_instantiation(archive, "NetworkStatusView")) @@ -503,26 +508,22 @@ NetworkStatusView::MouseDown(BPoint point) void NetworkStatusView::_AboutRequested() { - BString about = B_TRANSLATE( - "NetworkStatus\n\twritten by %1 and Hugo Santos\n\t%2, Haiku, Inc.\n" - ); - about.ReplaceFirst("%1", "Axel Dörfler"); - // Append a new developer here - about.ReplaceFirst("%2", "Copyright 2007-2010"); - // Append a new year here - BAlert* alert = new BAlert("about", about, B_TRANSLATE("OK")); - alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); - BTextView *view = alert->TextView(); - BFont font; + if (fAboutWindow == NULL) { + const char* authors[] = { + "Axel Dörfler", + "Hugo Santos", + NULL + }; - view->SetStylable(true); - - view->GetFont(&font); - font.SetSize(18); - font.SetFace(B_BOLD_FACE); - view->SetFontAndColor(0, 13, &font); - - alert->Go(); + fAboutWindow = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("NetworkStatus"), kSignature); + fAboutWindow->AddCopyright(2007, "Haiku, Inc."); + fAboutWindow->AddAuthors(authors); + fAboutWindow->Show(); + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else + fAboutWindow->Activate(); } diff --git a/src/apps/networkstatus/NetworkStatusView.h b/src/apps/networkstatus/NetworkStatusView.h index 8508efe6cc..53e6b3ab37 100644 --- a/src/apps/networkstatus/NetworkStatusView.h +++ b/src/apps/networkstatus/NetworkStatusView.h @@ -16,6 +16,8 @@ #include + +class BAboutWindow; class BMessageRunner; class BNetworkInterface; @@ -64,6 +66,7 @@ class NetworkStatusView : public BView { std::map fInterfaceStatuses; + BAboutWindow* fAboutWindow; bool fInDeskbar; BBitmap* fTrayIcons[kStatusCount]; BBitmap* fNotifyIcons[kStatusCount]; From be7c552a5088390b02d63b4e64c0529758a93e91 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:18:37 -0500 Subject: [PATCH 55/66] Bring AboutRequested() method back, not sure why I removed it. --- .../processcontroller/ProcessController.cpp | 48 +++++++++++-------- .../processcontroller/ProcessController.h | 1 + 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index 66bc517e41..a420bc684c 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -426,27 +426,7 @@ ProcessController::MessageReceived(BMessage *message) } case B_ABOUT_REQUESTED: - if (fAboutWindow == NULL) { - const char* extraCopyrights[] = { - "1997-2001 Georges-Edouard Berenger", - NULL - }; - - const char* authors[] = { - "Georges-Edouard Berenger", - NULL - }; - - fAboutWindow = new BAboutWindow( - B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature); - fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); - fAboutWindow->AddAuthors(authors); - fAboutWindow->Show(); - } else if (fAboutWindow->IsHidden()) - fAboutWindow->Show(); - else - fAboutWindow->Activate(); - + AboutRequested(); break; default: @@ -455,6 +435,32 @@ ProcessController::MessageReceived(BMessage *message) } +void +ProcessController::AboutRequested() +{ + if (fAboutWindow == NULL) { + const char* extraCopyrights[] = { + "1997-2001 Georges-Edouard Berenger", + NULL + }; + + const char* authors[] = { + "Georges-Edouard Berenger", + NULL + }; + + fAboutWindow = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature); + fAboutWindow->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); + fAboutWindow->AddAuthors(authors); + fAboutWindow->Show(); + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else + fAboutWindow->Activate(); +} + + void ProcessController::DefaultColors() { diff --git a/src/apps/processcontroller/ProcessController.h b/src/apps/processcontroller/ProcessController.h index 33e3dc2bb3..d2f9dbdb3a 100644 --- a/src/apps/processcontroller/ProcessController.h +++ b/src/apps/processcontroller/ProcessController.h @@ -45,6 +45,7 @@ class ProcessController : public BView { static ProcessController* Instantiate(BMessage* data); virtual status_t Archive(BMessage *data, bool deep = true) const; + void AboutRequested(); void Update(); void DefaultColors(); From 83baea76a81def7ecdb47c0ae522770310f37333 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:24:18 -0500 Subject: [PATCH 56/66] Update copyright info for ProcessController --- src/apps/processcontroller/ProcessController.cpp | 3 ++- src/apps/processcontroller/ProcessController.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index a420bc684c..28e708db40 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -1,7 +1,7 @@ /* ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. Copyright (C) 2004 beunited.org - Copyright (c) 2006-2009, Haiku, Inc. All rights reserved. + Copyright (c) 2006-2012, Haiku, Inc. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -440,6 +440,7 @@ ProcessController::AboutRequested() { if (fAboutWindow == NULL) { const char* extraCopyrights[] = { + "2004 beunited.org", "1997-2001 Georges-Edouard Berenger", NULL }; diff --git a/src/apps/processcontroller/ProcessController.h b/src/apps/processcontroller/ProcessController.h index d2f9dbdb3a..78d1212741 100644 --- a/src/apps/processcontroller/ProcessController.h +++ b/src/apps/processcontroller/ProcessController.h @@ -1,6 +1,7 @@ /* ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. - Copyright (C) 2004 beunited.org + Copyright (C) 2004 beunited.org + Copyright (c) 2006-2012, Haiku, Inc. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public From 5070e7e2228b34caae7f8d99846059672bb86b69 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:29:10 -0500 Subject: [PATCH 57/66] Init fAboutWindow NULL first --- src/apps/networkstatus/NetworkStatusView.cpp | 3 ++- src/apps/powerstatus/PowerStatusView.cpp | 2 +- src/apps/powerstatus/PowerStatusView.h | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index 73a55f24c5..d5244751a0 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -148,13 +148,14 @@ NetworkStatusView::~NetworkStatusView() void NetworkStatusView::_Init() { + fAboutWindow = NULL; + for (int i = 0; i < kStatusCount; i++) { fTrayIcons[i] = NULL; fNotifyIcons[i] = NULL; } _UpdateBitmaps(); - fAboutWindow = NULL; } diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 0d540f60cc..726747a775 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h index 837bb2d3e1..6661b47504 100644 --- a/src/apps/powerstatus/PowerStatusView.h +++ b/src/apps/powerstatus/PowerStatusView.h @@ -15,6 +15,7 @@ #include "DriverInterface.h" +class BAboutWindow; class BFile; @@ -53,6 +54,7 @@ private: protected: PowerStatusDriverInterface* fDriverInterface; + BAboutWindow* fAboutWindow; bool fShowLabel; bool fShowTime; From d4d5bf6c50e67ebc57430df8dc1fec2b2b682c8b Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:37:30 -0500 Subject: [PATCH 58/66] Update PowerStatus about window --- src/apps/powerstatus/Jamfile | 2 +- src/apps/powerstatus/PowerStatusView.cpp | 39 +++++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/apps/powerstatus/Jamfile b/src/apps/powerstatus/Jamfile index 6ce508e3ab..59d8d7a82d 100644 --- a/src/apps/powerstatus/Jamfile +++ b/src/apps/powerstatus/Jamfile @@ -13,7 +13,7 @@ Application PowerStatus : PowerStatusWindow.cpp PowerStatusView.cpp PowerStatus.cpp - : be $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) + : be libshared.a $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : PowerStatus.rdef ; DoCatalogs PowerStatus : diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 726747a775..be86d1aebf 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -96,6 +96,8 @@ PowerStatusView::_Init() { SetViewColor(B_TRANSPARENT_COLOR); + fAboutWindow = NULL; + fShowLabel = true; fShowTime = false; fShowStatusIcon = true; @@ -503,14 +505,16 @@ PowerStatusReplicant::PowerStatusReplicant(BMessage* archive) PowerStatusReplicant::~PowerStatusReplicant() { - if (fMessengerExist) { + if (fMessengerExist) delete fExtWindowMessenger; - } fDriverInterface->StopWatching(this); fDriverInterface->Disconnect(); fDriverInterface->ReleaseReference(); + if (fAboutWindow != NULL) + fAboutWindow->Quit(); + _SaveSettings(); } @@ -621,22 +625,23 @@ PowerStatusReplicant::MouseDown(BPoint point) void PowerStatusReplicant::_AboutRequested() { - BAlert* alert = new BAlert(B_TRANSLATE("About"), - B_TRANSLATE("PowerStatus\n" - "written by Axel Dörfler, Clemens Zeidler\n" - "Copyright 2006, Haiku, Inc.\n"), B_TRANSLATE("OK")); - BTextView *view = alert->TextView(); - BFont font; + if (fAboutWindow == NULL) { + const char* authors[] = { + "Axel Dörfler", + "Alexander von Gluck", + "Clemens Zeidler", + NULL + }; - view->SetStylable(true); - - view->GetFont(&font); - font.SetSize(18); - font.SetFace(B_BOLD_FACE); - view->SetFontAndColor(0, strlen(B_TRANSLATE("PowerStatus")), &font); - - alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); - alert->Go(); + fAboutWindow = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("PowerStatus"), kSignature); + fAboutWindow->AddCopyright(2006, "Haiku, Inc."); + fAboutWindow->AddAuthors(authors); + fAboutWindow->Show(); + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else + fAboutWindow->Activate(); } From c191daa8164725b930bfcf5e2f6b691a5df1fe84 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:41:25 -0500 Subject: [PATCH 59/66] remove uneeded comment --- src/apps/networkstatus/NetworkStatusView.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index d5244751a0..ccbdb85b9a 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -139,7 +139,6 @@ NetworkStatusView::NetworkStatusView(BMessage* archive) NetworkStatusView::~NetworkStatusView() { - // replicant deleted, destroy the about window if (fAboutWindow != NULL) fAboutWindow->Quit(); } From b23f8cd41f1dcd1b6d58964b6b1ebd6594d19089 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:42:01 -0500 Subject: [PATCH 60/66] Destroy AboutWindow on destruction --- src/apps/powerstatus/PowerStatusView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index be86d1aebf..1fced11ca3 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -77,6 +77,8 @@ PowerStatusView::PowerStatusView(BMessage* archive) PowerStatusView::~PowerStatusView() { + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } From df02847b499c7ff50601b932dcc099be216d1e73 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:53:31 -0500 Subject: [PATCH 61/66] Update Workspaces about dialog --- src/apps/workspaces/Jamfile | 4 +-- src/apps/workspaces/Workspaces.cpp | 57 ++++++++++++++++++------------ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/apps/workspaces/Jamfile b/src/apps/workspaces/Jamfile index e9fbe094b1..cdc936ac87 100644 --- a/src/apps/workspaces/Jamfile +++ b/src/apps/workspaces/Jamfile @@ -3,11 +3,11 @@ SubDir HAIKU_TOP src apps workspaces ; SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; -UsePrivateHeaders app interface ; +UsePrivateHeaders app interface shared ; Application Workspaces : Workspaces.cpp - : be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) + : be libshared.a $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) : Workspaces.rdef ; diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index 0c3ea0fc75..f5d5de5467 100644 --- a/src/apps/workspaces/Workspaces.cpp +++ b/src/apps/workspaces/Workspaces.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku, Inc. All rights reserved. + * Copyright 2002-2012, Haiku, Inc. All rights reserved. * Copyright 2002, François Revol, revol@free.fr. * This file is distributed under the terms of the MIT License. * @@ -11,7 +11,7 @@ */ -#include +#include #include #include #include @@ -119,6 +119,7 @@ class WorkspacesView : public BView { BView* fParentWhichDrawsOnChildren; BRect fCurrentFrame; + BAboutWindow* fAboutWindow; }; class WorkspacesWindow : public BWindow { @@ -341,7 +342,8 @@ WorkspacesView::WorkspacesView(BRect frame, bool showDragger=true) BView(frame, kDeskbarItemName, B_FOLLOW_ALL, kWorkspacesViewFlag | B_FRAME_EVENTS), fParentWhichDrawsOnChildren(NULL), - fCurrentFrame(frame) + fCurrentFrame(frame), + fAboutWindow(NULL) { if(showDragger) { frame.OffsetTo(B_ORIGIN); @@ -358,7 +360,8 @@ WorkspacesView::WorkspacesView(BMessage* archive) : BView(archive), fParentWhichDrawsOnChildren(NULL), - fCurrentFrame(Frame()) + fCurrentFrame(Frame()), + fAboutWindow(NULL) { // Just in case we are instantiated from an older archive... SetFlags(Flags() | B_FRAME_EVENTS); @@ -371,6 +374,8 @@ WorkspacesView::WorkspacesView(BMessage* archive) WorkspacesView::~WorkspacesView() { + if (fAboutWindow != NULL) + fAboutWindow->Quit(); } @@ -400,28 +405,34 @@ WorkspacesView::Archive(BMessage* archive, bool deep) const void WorkspacesView::_AboutRequested() { - BString text = B_TRANSLATE("Workspaces\n" - "written by %1, and %2.\n\n" - "Copyright %3, Haiku.\n\n" - "Send windows behind using the Option key. " - "Move windows to front using the Control key.\n"); - text.ReplaceFirst("%1", "François Revol, Axel Dörfler"); - text.ReplaceFirst("%2", "Matt Madia"); - text.ReplaceFirst("%3", "2002-2008"); - - BAlert *alert = new BAlert("about", text.String(), B_TRANSLATE("OK")); - BTextView *view = alert->TextView(); - BFont font; + if (fAboutWindow == NULL) { + const char* authors[] = { + "Axel Dörfler", + "Oliver \"Madison\" Kohl", + "Matt Madia", + "François Revol", + NULL + }; - view->SetStylable(true); + const char* extraCopyrights[] = { + "2002 François Revol", + NULL + }; - view->GetFont(&font); - font.SetSize(18); - font.SetFace(B_BOLD_FACE); - view->SetFontAndColor(0, 10, &font); + const char* extraInfo = "Send windows behind using the Option key. " + "Move windows to front using the Control key.\n"; - alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); - alert->Go(); + fAboutWindow = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("Workspaces"), kSignature); + fAboutWindow->AddCopyright(2002, "Haiku, Inc.", + extraCopyrights); + fAboutWindow->AddAuthors(authors); + fAboutWindow->AddExtraInfo(extraInfo); + fAboutWindow->Show(); + } else if (fAboutWindow->IsHidden()) + fAboutWindow->Show(); + else + fAboutWindow->Activate(); } From 67bc15211fe106c057b3371a6157384ff72ef58f Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 13 Nov 2012 01:58:35 -0500 Subject: [PATCH 62/66] Make about window a bit taller so it fits the average amount of text ... without scrolling. This completes my about window treatment for all replicants. It is my hope that BAboutWindow will be used by all apps that need an about dialog instead of using a BAlert. --- src/kits/shared/AboutWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index a6b20e8da2..8e4d103d89 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -134,7 +134,7 @@ AboutView::AboutView(const char* appName, const char* signature) fVersionView = new BStringView("version", AppVersion(signature)); fInfoView = new BTextView("info", B_WILL_DRAW); - fInfoView->SetExplicitMinSize(BSize(210.0, 100.0)); + fInfoView->SetExplicitMinSize(BSize(210.0, 160.0)); fInfoView->MakeEditable(false); fInfoView->SetWordWrap(true); fInfoView->SetInsets(5.0, 5.0, 5.0, 5.0); @@ -255,7 +255,7 @@ AboutView::AppIcon(const char* signature) BAboutWindow::BAboutWindow(const char* appName, const char* signature) - : BWindow(BRect(0.0, 0.0, 200.0, 140.0), appName, B_TITLED_WINDOW, + : BWindow(BRect(0.0, 0.0, 200.0, 200.0), appName, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS) { From 959e7602bcba83b108f691c7c7a93de9eb361730 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Tue, 13 Nov 2012 11:43:37 +0100 Subject: [PATCH 63/66] ARM: fix copyright of NOR driver Signed-off-by: Ithamar R. Adema --- src/add-ons/kernel/drivers/disk/norflash/norflash.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp b/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp index a15db376c5..cfd8c1fff9 100644 --- a/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp +++ b/src/add-ons/kernel/drivers/disk/norflash/norflash.cpp @@ -1,11 +1,12 @@ /* - * Copyright 2012, Haiku. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: * Ithamar R. Adema */ + #include #include #include From 1df5784a22ff1783bb42fbcb63cb86b9965237a1 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Tue, 13 Nov 2012 12:04:35 +0100 Subject: [PATCH 64/66] ARM: Add ARM architecture detection to generic bootloader ARM code. This detects everything up to ARMv6 right now. Need to check more recent ARM ARMs for ARMv7 detection. The detected details get passed on to the kernel, which can use the pre-detected info for selecting right pagetable format and such. Copyright removal of Axel done after agreement with Axel @ BeGeistert that for files that were copy/pasted from x86 arch and then fully replaced the implementation, removal of original copyright holder is allowed, since their actual code is gone ;) --- headers/private/kernel/arch/arm/arch_cpu.h | 29 ++++++-- src/system/boot/arch/arm/arch_cpu.cpp | 87 ++++++++++++++-------- 2 files changed, 78 insertions(+), 38 deletions(-) diff --git a/headers/private/kernel/arch/arm/arch_cpu.h b/headers/private/kernel/arch/arm/arch_cpu.h index 34364a8004..a70398aa64 100644 --- a/headers/private/kernel/arch/arm/arch_cpu.h +++ b/headers/private/kernel/arch/arm/arch_cpu.h @@ -33,14 +33,29 @@ struct iframe { uint32 pc; } _PACKED; -typedef struct arch_cpu_info { -} arch_cpu_info; +/**! Values for arch_cpu_info.arch */ +enum { + ARCH_ARM_PRE_ARM7, + ARCH_ARM_v3, + ARCH_ARM_v4, + ARCH_ARM_v4T, + ARCH_ARM_v5, + ARCH_ARM_v5T, + ARCH_ARM_v5TE, + ARCH_ARM_v5TEJ, + ARCH_ARM_v6 +}; -extern int arch_cpu_type; -extern int arch_fpu_type; -extern int arch_mmu_type; -extern int arch_platform; -extern int arch_machine; +typedef struct arch_cpu_info { + /* For a detailed interpretation of these values, + see "The System Control coprocessor", + "Main ID register" in your ARM ARM */ + int implementor; + int part_number; + int revision; + int variant; + int arch; +} arch_cpu_info; #ifdef __cplusplus extern "C" { diff --git a/src/system/boot/arch/arm/arch_cpu.cpp b/src/system/boot/arch/arm/arch_cpu.cpp index 028146b9b5..2decd55ab3 100644 --- a/src/system/boot/arch/arm/arch_cpu.cpp +++ b/src/system/boot/arch/arm/arch_cpu.cpp @@ -1,12 +1,11 @@ /* - * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * - * calculate_cpu_conversion_factor() was written by Travis Geiselbrecht and - * licensed under the NewOS license. + * Authors: + * Ithamar R. Adema */ - #include "cpu.h" #include @@ -17,50 +16,80 @@ #include #include #include - +#include #include - -//#define TRACE_CPU +#define TRACE_CPU #ifdef TRACE_CPU # define TRACE(x) dprintf x #else # define TRACE(x) ; #endif -//uint32 gTimeConversionFactor; - - -static void -calculate_cpu_conversion_factor() -{ - #warning U-Boot:TODO! -} - +/*! check_cpu_features + * + * Please note the fact that ARM7 and ARMv7 are two different things ;) + * ARMx is a specific ARM CPU core instance, while ARMvX refers to the + * ARM architecture specification version.... + * + * Most of the architecture versions we're detecting here we will probably + * never run on, just included for completeness sake... ARMv5 and up are + * the likely ones for us to support (as they all have some kind of MMU). + */ static status_t check_cpu_features() { + uint32 result = 0; + int arch, variant = 0, part = 0, revision = 0, implementor = 0; + + asm volatile("MRC p15, 0, %[c1out], c0, c0, 0":[c1out] "=r" (result)); + + implementor = (result >> 24) & 0xff; + + if (!(result & (1 << 19))) { + switch((result >> 12) & 0xf) { + case 0: /* early ARMv3 or even older */ + arch = ARCH_ARM_PRE_ARM7; + break; + + case 7: /* ARM7 processor */ + arch = (result & (1 << 23)) ? ARCH_ARM_v4T : ARCH_ARM_v3; + variant = (result >> 16) & 0x7f; + part = (result >> 4) & 0xfff; + revision = result & 0xf; + break; + + default: + revision = result & 0xf; + part = (result >> 4) & 0xfff; + switch((result >> 16) & 0xf) { + case 1: arch = ARCH_ARM_v4; break; + case 2: arch = ARCH_ARM_v4T; break; + case 3: arch = ARCH_ARM_v5; break; + case 4: arch = ARCH_ARM_v5T; break; + case 5: arch = ARCH_ARM_v5TE; break; + case 6: arch = ARCH_ARM_v5TEJ; break; + case 7: arch = ARCH_ARM_v6; break; + case 0xf: /* XXX TODO ARMv7 */; break; + } + variant = (result >> 20) & 0xf; + break; + } + } + + TRACE(("%s: implementor=0x%x('%c'), arch=%d, variant=0x%x, part=0x%x, revision=0x%x\n", + __func__, implementor, implementor, arch, variant, part, revision)); - #warning U-Boot:TODO! return B_OK; } - // #pragma mark - - extern "C" void arch_spin(bigtime_t microseconds) { - for(bigtime_t i=0;i Date: Tue, 13 Nov 2012 12:12:23 +0100 Subject: [PATCH 65/66] ARM: add todo note about VM implementation Signed-off-by: Ithamar R. Adema --- docs/develop/ports/arm/todo.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/develop/ports/arm/todo.txt b/docs/develop/ports/arm/todo.txt index fae21763fc..17cc54bf21 100644 --- a/docs/develop/ports/arm/todo.txt +++ b/docs/develop/ports/arm/todo.txt @@ -1,4 +1,6 @@ * Figure out how to get page flags (modified/accessed) and implement it ;) + use unmapped/read-only mappings to trigger soft faults + for tracking used/modified flags for ARMv5 and ARMv6 * Fix serial port mapping. Currently kernel uses the haiku_loader identity mapping for it, but this lives in user virtual address space... From 344b3218d40b44df5bfc8c7c4859e7d9ed4d06f2 Mon Sep 17 00:00:00 2001 From: "Ithamar R. Adema" Date: Tue, 13 Nov 2012 12:27:11 +0100 Subject: [PATCH 66/66] ARM/u-boot: Add support for FDTs passed in the uImage Since we're using multi-part uImage format, we can add the FDT as a seperate "blob" in the uImage, if the used U-Boot version is not "FDT enabled". This is used for example for our Verdex target. Currently I've got a local hack in the platform/u-boot/Jamfile, looking into pulling in the FDT files and a proper Jam setup to do that properly... --- .../platform/u-boot/platform_stage2_args.h | 2 ++ src/system/boot/platform/u-boot/start.cpp | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/headers/private/kernel/boot/platform/u-boot/platform_stage2_args.h b/headers/private/kernel/boot/platform/u-boot/platform_stage2_args.h index d47bbb3c66..966fd1761e 100644 --- a/headers/private/kernel/boot/platform/u-boot/platform_stage2_args.h +++ b/headers/private/kernel/boot/platform/u-boot/platform_stage2_args.h @@ -12,6 +12,8 @@ struct platform_stage2_args { void *boot_tgz_data; uint32 boot_tgz_size; + void *fdt_data; + uint32 fdt_size; }; #endif /* KERNEL_BOOT_PLATFORM_UBOOT_STAGE2_H */ diff --git a/src/system/boot/platform/u-boot/start.cpp b/src/system/boot/platform/u-boot/start.cpp index 81b03bf03c..898830f0aa 100644 --- a/src/system/boot/platform/u-boot/start.cpp +++ b/src/system/boot/platform/u-boot/start.cpp @@ -172,11 +172,33 @@ start_raw(int argc, const char **argv) args.arguments = NULL; args.platform.boot_tgz_data = NULL; args.platform.boot_tgz_size = 0; + args.platform.fdt_data = NULL; + args.platform.fdt_size = 0; + + // if we get passed a uimage, try to find the third blob only if we do not have FDT data yet + if (gUImage != NULL + && !gFDT + && image_multi_getimg(gUImage, 2, + (uint32*)&args.platform.fdt_data, + &args.platform.fdt_size)) { + // found a blob, assume it is FDT data, when working on a platform + // which does not have an FDT enabled U-Boot + gFDT = args.platform.fdt_data; + } serial_init(gFDT); console_init(); cpu_init(); + if (args.platform.fdt_data) { + dprintf("Found FDT from uimage @ %p, %" B_PRIu32 " bytes\n", + args.platform.fdt_data, args.platform.fdt_size); + } else if (gFDT) { + /* Fixup args so we can pass the gFDT on to the kernel */ + args.platform.fdt_data = gFDT; + args.platform.fdt_size = fdt_totalsize(gFDT); + } + // if we get passed an FDT, check /chosen for initrd if (gFDT != NULL) { int node = fdt_path_offset(gFDT, "/chosen");