From 76b9d53bd09719bdea88316d6b9e552436d03357 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 8 Mar 2016 16:13:38 -0800 Subject: [PATCH] BColorControl: Rebuild control after mode switch App Server sends each window a message that the screen has changed: https://www.haiku-os.org/legacy-docs/bebook/BWindow.html#BWindow_ScreenChanged Propegate B_SCREEN_CHANGED message to all child views first Tell BColorControl to read the B_SCREEN_CHANGED message and reinitialize itself. * Only reinit if switching to or from B_CMAP8 * Initialize all pointers to NULL in constructor * Don't destroy and rebuild offscreen view (and text views) on reinit * Reinitialize offscreen view on reinit. Fixes #8035 Also initialzing the pointers to NULL in constructor fixes #12673 --- src/kits/interface/ColorControl.cpp | 58 +++++++++++++++++++++++++---- src/kits/interface/View.cpp | 12 ++++++ src/kits/interface/Window.cpp | 11 +++++- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 62c6b98802..2b330677ae 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -52,7 +52,12 @@ BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, float cellSize, const char* name, BMessage* message, bool useOffscreen) : BControl(BRect(leftTop, leftTop), name, NULL, message, - B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE) + B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE), + fRedText(NULL), + fGreenText(NULL), + fBlueText(NULL), + fBitmap(NULL), + fOffscreenView(NULL) { _InitData(layout, cellSize, useOffscreen, NULL); } @@ -60,7 +65,12 @@ BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, BColorControl::BColorControl(BMessage* data) : - BControl(data) + BControl(data), + fRedText(NULL), + fGreenText(NULL), + fBlueText(NULL), + fBitmap(NULL), + fOffscreenView(NULL) { int32 layout; float cellSize; @@ -174,13 +184,15 @@ BColorControl::_InitData(color_control_layout layout, float size, ResizeToPreferred(); if (useOffscreen) { - BRect bounds = _PaletteFrame(); - fBitmap = new BBitmap(bounds, B_RGB32, true, false); - fOffscreenView = new BView(bounds, "off_view", 0, 0); + if (fOffscreenView != NULL) { + BRect bounds = _PaletteFrame(); + fBitmap = new BBitmap(bounds, B_RGB32, true, false); + fOffscreenView = new BView(bounds, "off_view", 0, 0); - fBitmap->Lock(); - fBitmap->AddChild(fOffscreenView); - fBitmap->Unlock(); + fBitmap->Lock(); + fBitmap->AddChild(fOffscreenView); + fBitmap->Unlock(); + } } else { fBitmap = NULL; fOffscreenView = NULL; @@ -363,6 +375,36 @@ BColorControl::MessageReceived(BMessage* message) Invoke(); break; } + + case B_SCREEN_CHANGED: + { + BRect frame; + uint32 mode; + if (message->FindRect("frame", &frame) == B_OK + && message->FindInt32("mode", (int32*)&mode) == B_OK) { + if ((fPaletteMode && mode == B_CMAP8) + || (!fPaletteMode && mode != B_CMAP8)) { + // not switching to or from B_CMAP8, break + break; + } + + // fake an archive message (so we don't rebuild views) + BMessage* data = new BMessage(); + data->AddInt32("_val", Value()); + + // reinititialize + bool useOffscreen = fOffscreenView != NULL; + _InitData((color_control_layout)fColumns, fCellSize, + useOffscreen, data); + if (useOffscreen) + _InitOffscreen(); + + // cleanup + delete data; + } + break; + } + default: BControl::MessageReceived(message); } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index cf03b8fad2..004d8771e5 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4955,6 +4955,18 @@ BView::MessageReceived(BMessage* message) case B_FONTS_UPDATED: break; + case B_SCREEN_CHANGED: + { + // propegate message to child views + int32 childCount = CountChildren(); + for (int32 i = 0; i < childCount; i++) { + BView* view = ChildAt(i); + if (view != NULL) + view->MessageReceived(message); + } + break; + } + default: BHandler::MessageReceived(message); break; diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 7a6b203199..d847f3dd09 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -1111,8 +1111,17 @@ FrameMoved(origin); BRect frame; uint32 mode; if (message->FindRect("frame", &frame) == B_OK - && message->FindInt32("mode", (int32*)&mode) == B_OK) + && message->FindInt32("mode", (int32*)&mode) == B_OK) { + // propegate message to child views + int32 childCount = CountChildren(); + for (int32 i = 0; i < childCount; i++) { + BView* view = ChildAt(i); + if (view != NULL) + view->MessageReceived(message); + } + // call hook method ScreenChanged(frame, (color_space)mode); + } } else target->MessageReceived(message); break;