Icon-O-Matic: Fix window resizing bug

Previously, the window could not go any smaller than the current size
after some changes were made to the icon such as adding a style.

Fixes #4711

Also cleans up some code style.

Change-Id: I4e7af98ac8afbea28a46d81b9de7aba6fc6c894a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6836
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: humdinger humdinger <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Zardshard
2023-08-17 19:02:51 +00:00
committed by waddlesplash
parent 52b930ce1c
commit 6da29a769f
4 changed files with 100 additions and 55 deletions
@@ -1,9 +1,10 @@
/*
* Copyright 2006-2007, Haiku.
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#include "StateView.h"
@@ -95,12 +96,15 @@ if (dynamic_cast<GradientControl*>(*target))
StateView* fTarget;
};
// #pragma mark -
// constructor
StateView::StateView(BRect frame, const char* name,
uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags),
fStartingRect(frame),
fCurrentState(NULL),
fDropAnticipatingState(NULL),
@@ -117,15 +121,16 @@ StateView::StateView(BRect frame, const char* name,
{
}
// destructor
StateView::~StateView()
{
delete fEventFilter;
}
// #pragma mark -
// AttachedToWindow
void
StateView::AttachedToWindow()
{
@@ -134,7 +139,7 @@ StateView::AttachedToWindow()
BView::AttachedToWindow();
}
// DetachedFromWindow
void
StateView::DetachedFromWindow()
{
@@ -143,14 +148,14 @@ StateView::DetachedFromWindow()
BView::DetachedFromWindow();
}
// Draw
void
StateView::Draw(BRect updateRect)
{
Draw(this, updateRect);
}
// MessageReceived
void
StateView::MessageReceived(BMessage* message)
{
@@ -183,9 +188,10 @@ StateView::MessageReceived(BMessage* message)
}
}
// #pragma mark -
// MouseDown
void
StateView::MouseDown(BPoint where)
{
@@ -212,7 +218,7 @@ StateView::MouseDown(BPoint where)
fLocker->WriteUnlock();
}
// MouseMoved
void
StateView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
@@ -250,7 +256,7 @@ StateView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
fLocker->WriteUnlock();
}
// MouseUp
void
StateView::MouseUp(BPoint where)
{
@@ -280,9 +286,10 @@ StateView::MouseUp(BPoint where)
fLocker->WriteUnlock();
}
// #pragma mark -
// KeyDown
void
StateView::KeyDown(const char* bytes, int32 numBytes)
{
@@ -298,7 +305,7 @@ StateView::KeyDown(const char* bytes, int32 numBytes)
BView::KeyDown(bytes, numBytes);
}
// KeyUp
void
StateView::KeyUp(const char* bytes, int32 numBytes)
{
@@ -327,7 +334,21 @@ StateView::Perform(perform_code code, void* data)
// #pragma mark -
// SetState
void
StateView::GetPreferredSize(float* width, float* height)
{
if (width != NULL)
*width = fStartingRect.Width();
if (height != NULL)
*height = fStartingRect.Height();
}
// #pragma mark -
void
StateView::SetState(ViewState* state)
{
@@ -344,7 +365,7 @@ StateView::SetState(ViewState* state)
fCurrentState->Init();
}
// UpdateStateCursor
void
StateView::UpdateStateCursor()
{
@@ -353,7 +374,7 @@ StateView::UpdateStateCursor()
}
}
// Draw
void
StateView::Draw(BView* into, BRect updateRect)
{
@@ -371,14 +392,14 @@ StateView::Draw(BView* into, BRect updateRect)
fLocker->ReadUnlock();
}
// MouseWheelChanged
bool
StateView::MouseWheelChanged(BPoint where, float x, float y)
{
return false;
}
// HandleKeyDown
bool
StateView::HandleKeyDown(uint32 key, uint32 modifiers)
{
@@ -404,7 +425,7 @@ StateView::HandleKeyDown(uint32 key, uint32 modifiers)
return false;
}
// HandleKeyUp
bool
StateView::HandleKeyUp(uint32 key, uint32 modifiers)
{
@@ -430,34 +451,34 @@ StateView::HandleKeyUp(uint32 key, uint32 modifiers)
return false;
}
// FilterMouse
void
StateView::FilterMouse(BPoint* where) const
{
}
// StateForDragMessage
ViewState*
StateView::StateForDragMessage(const BMessage* message)
{
return NULL;
}
// SetCommandStack
void
StateView::SetCommandStack(::CommandStack* stack)
{
fCommandStack = stack;
}
// SetLocker
void
StateView::SetLocker(RWLocker* locker)
{
fLocker = locker;
}
// SetUpdateTarget
void
StateView::SetUpdateTarget(BHandler* target, uint32 command)
{
@@ -465,7 +486,7 @@ StateView::SetUpdateTarget(BHandler* target, uint32 command)
fUpdateCommand = command;
}
// SetCatchAllEvents
void
StateView::SetCatchAllEvents(bool catchAll)
{
@@ -480,7 +501,7 @@ StateView::SetCatchAllEvents(bool catchAll)
_RemoveEventFilter();
}
// Perform
status_t
StateView::Perform(Command* command)
{
@@ -494,23 +515,24 @@ StateView::Perform(Command* command)
return B_NO_INIT;
}
// #pragma mark -
// _HandleKeyDown
bool
StateView::_HandleKeyDown(uint32 key, uint32 modifiers)
{
return false;
}
// _HandleKeyUp
bool
StateView::_HandleKeyUp(uint32 key, uint32 modifiers)
{
return false;
}
// _InstallEventFilter
void
StateView::_InstallEventFilter()
{
@@ -526,6 +548,7 @@ StateView::_InstallEventFilter()
Window()->AddCommonFilter(fEventFilter);
}
void
StateView::_RemoveEventFilter()
{
@@ -1,9 +1,10 @@
/*
* Copyright 2006-2007, Haiku.
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#ifndef STATE_VIEW_H
@@ -41,6 +42,8 @@ class StateView : public BView {
virtual status_t Perform(perform_code code, void* data);
// Avoids warning about hiding BView::Perform().
virtual void GetPreferredSize(float* width, float* height);
// StateView interface
void SetState(ViewState* state);
void UpdateStateCursor();
@@ -84,6 +87,8 @@ class StateView : public BView {
void _TriggerUpdate();
BRect fStartingRect;
ViewState* fCurrentState;
ViewState* fDropAnticipatingState;
// the drop anticipation state is some
+39 -25
View File
@@ -1,9 +1,10 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#include "GradientControl.h"
@@ -21,7 +22,7 @@
#include "GradientTransformable.h"
// constructor
GradientControl::GradientControl(BMessage* message, BHandler* target)
: BView(BRect(0, 0, 259, 19), "gradient control", B_FOLLOW_NONE,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE),
@@ -40,7 +41,7 @@ GradientControl::GradientControl(BMessage* message, BHandler* target)
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// destructor
GradientControl::~GradientControl()
{
delete fGradient;
@@ -48,8 +49,9 @@ GradientControl::~GradientControl()
delete fMessage;
}
#if LIB_LAYOUT
// layoutprefs
minimax
GradientControl::layoutprefs()
{
@@ -63,7 +65,7 @@ GradientControl::layoutprefs()
return mpm;
}
// layout
BRect
GradientControl::layout(BRect frame)
{
@@ -71,9 +73,10 @@ GradientControl::layout(BRect frame)
ResizeTo(frame.Width(), frame.Height());
return Frame();
}
#endif // LIB_LAYOUT
// WindowActivated
void
GradientControl::WindowActivated(bool active)
{
@@ -81,7 +84,7 @@ GradientControl::WindowActivated(bool active)
Invalidate();
}
// MakeFocus
void
GradientControl::MakeFocus(bool focus)
{
@@ -96,7 +99,7 @@ GradientControl::MakeFocus(bool focus)
BView::MakeFocus(focus);
}
// MouseDown
void
GradientControl::MouseDown(BPoint where)
{
@@ -148,14 +151,14 @@ GradientControl::MouseDown(BPoint where)
}
}
// MouseUp
void
GradientControl::MouseUp(BPoint where)
{
fDraggingStepIndex = -1;
}
// MouseMoved
void
GradientControl::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
@@ -191,7 +194,7 @@ GradientControl::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMe
}
}
// MessageReceived
void
GradientControl::MessageReceived(BMessage* message)
{
@@ -232,7 +235,7 @@ GradientControl::MessageReceived(BMessage* message)
}
}
// KeyDown
void
GradientControl::KeyDown(const char* bytes, int32 numBytes)
{
@@ -316,7 +319,7 @@ GradientControl::KeyDown(const char* bytes, int32 numBytes)
}
}
// Draw
void
GradientControl::Draw(BRect updateRect)
{
@@ -436,7 +439,7 @@ GradientControl::Draw(BRect updateRect)
}
}
// FrameResized
void
GradientControl::FrameResized(float width, float height)
{
@@ -447,7 +450,18 @@ GradientControl::FrameResized(float width, float height)
}
// SetGradient
void
GradientControl::GetPreferredSize(float* width, float* height)
{
if (width != NULL)
*width = 259;
if (height != NULL)
*height = 19;
}
void
GradientControl::SetGradient(const ::Gradient* gradient)
{
@@ -466,7 +480,7 @@ GradientControl::SetGradient(const ::Gradient* gradient)
Invalidate();
}
// SetCurrentStop
void
GradientControl::SetCurrentStop(const rgb_color& color)
{
@@ -477,7 +491,7 @@ GradientControl::SetCurrentStop(const rgb_color& color)
}
}
// GetCurrentStop
bool
GradientControl::GetCurrentStop(rgb_color* color) const
{
@@ -490,7 +504,7 @@ GradientControl::GetCurrentStop(rgb_color* color) const
return false;
}
// SetEnabled
void
GradientControl::SetEnabled(bool enabled)
{
@@ -506,7 +520,7 @@ GradientControl::SetEnabled(bool enabled)
Invalidate();
}
// blend_colors
inline void
blend_colors(uint8* d, uint8 alpha, uint8 c1, uint8 c2, uint8 c3)
{
@@ -523,7 +537,7 @@ blend_colors(uint8* d, uint8 alpha, uint8 c1, uint8 c2, uint8 c3)
}
}
// _UpdateColors
void
GradientControl::_UpdateColors()
{
@@ -605,7 +619,7 @@ GradientControl::_UpdateColors()
}
}
// _AllocBitmap
void
GradientControl::_AllocBitmap(int32 width, int32 height)
{
@@ -616,7 +630,7 @@ GradientControl::_AllocBitmap(int32 width, int32 height)
fGradientBitmap = new BBitmap(BRect(0, 0, width - 1, height - 1), 0, B_RGB32);
}
// _GradientBitmapRect
BRect
GradientControl::_GradientBitmapRect() const
{
@@ -628,7 +642,7 @@ GradientControl::_GradientBitmapRect() const
return r;
}
// _StepIndexFor
int32
GradientControl::_StepIndexFor(BPoint where) const
{
@@ -648,7 +662,7 @@ GradientControl::_StepIndexFor(BPoint where) const
return index;
}
// _OffsetFor
float
GradientControl::_OffsetFor(BPoint where) const
{
@@ -659,7 +673,7 @@ GradientControl::_OffsetFor(BPoint where) const
return offset;
}
// _UpdateCurrentColor
void
GradientControl::_UpdateCurrentColor() const
{
+4 -1
View File
@@ -1,9 +1,10 @@
/*
* Copyright 2006-2007, Haiku.
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/
#ifndef GRADIENT_CONTROL_H
#define GRADIENT_CONTROL_H
@@ -59,6 +60,8 @@ class GradientControl :
virtual void Draw(BRect updateRect);
virtual void FrameResized(float width, float height);
virtual void GetPreferredSize(float* width, float* height);
// GradientControl
void SetGradient(const _ICON_NAMESPACE Gradient*
gradient);