Ticket #8035: modeswitch2.patch

File modeswitch2.patch, 4.0 KB (added by jscipione, 8 years ago)

ebuild 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.

  • src/kits/interface/ColorControl.cpp

    diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp
    index 0379cd5..8799136 100644
    a b BColorControl::BColorControl(BPoint leftTop, color_control_layout layout,  
    5252    float cellSize, const char* name, BMessage* message, bool bufferedDrawing)
    5353    :
    5454    BControl(BRect(leftTop, leftTop), name, NULL, message,
    55         B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
     55        B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE),
     56    fRedText(NULL),
     57    fGreenText(NULL),
     58    fBlueText(NULL),
     59    fBitmap(NULL),
     60    fOffscreenView(NULL)
    5661{
    5762    _InitData(layout, cellSize, bufferedDrawing, NULL);
    5863}
    BColorControl::BColorControl(BPoint leftTop, color_control_layout layout,  
    6065
    6166BColorControl::BColorControl(BMessage* data)
    6267    :
    63     BControl(data)
     68    BControl(data),
     69    fRedText(NULL),
     70    fGreenText(NULL),
     71    fBlueText(NULL),
     72    fBitmap(NULL),
     73    fOffscreenView(NULL)
    6474{
    6575    int32 layout;
    6676    float cellSize;
    BColorControl::_InitData(color_control_layout layout, float size,  
    174184    ResizeToPreferred();
    175185
    176186    if (useOffscreen) {
    177         BRect bounds = _PaletteFrame();
    178         fBitmap = new BBitmap(bounds, B_RGB32, true, false);
    179         fOffscreenView = new BView(bounds, "off_view", 0, 0);
    180 
    181         fBitmap->Lock();
    182         fBitmap->AddChild(fOffscreenView);
    183         fBitmap->Unlock();
     187        if (fOffscreenView != NULL) {
     188            BRect bounds = _PaletteFrame();
     189            fBitmap = new BBitmap(bounds, B_RGB32, true, false);
     190            fOffscreenView = new BView(bounds, "off_view", 0, 0);
     191
     192            fBitmap->Lock();
     193            fBitmap->AddChild(fOffscreenView);
     194            fBitmap->Unlock();
     195        }
    184196    } else {
    185197        fBitmap = NULL;
    186198        fOffscreenView = NULL;
    BColorControl::MessageReceived(BMessage* message)  
    362374            Invoke();
    363375            break;
    364376        }
     377
     378        case B_SCREEN_CHANGED:
     379        {
     380            BRect frame;
     381            uint32 mode;
     382            if (message->FindRect("frame", &frame) == B_OK
     383                && message->FindInt32("mode", (int32*)&mode) == B_OK) {
     384                if ((fPaletteMode && mode == B_CMAP8)
     385                    || (!fPaletteMode && mode != B_CMAP8)) {
     386                    // not switching to or from B_CMAP8, break
     387                    break;
     388                }
     389
     390                // fake an archive message (so we don't rebuild views)
     391                BMessage* data = new BMessage();
     392                data->AddInt32("_val", Value());
     393
     394                // reinititialize
     395                bool useOffscreen = fOffscreenView != NULL;
     396                _InitData((color_control_layout)fColumns, fCellSize,
     397                    useOffscreen, data);
     398                if (useOffscreen)
     399                    _InitOffscreen();
     400
     401                // cleanup
     402                delete data;
     403            }
     404            break;
     405        }
     406
    365407        default:
    366408            BControl::MessageReceived(message);
    367409    }
  • src/kits/interface/View.cpp

    diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp
    index cf03b8f..7f94992 100644
    a b BView::MessageReceived(BMessage* message)  
    49554955            case B_FONTS_UPDATED:
    49564956                break;
    49574957
     4958            case B_SCREEN_CHANGED:
     4959            {
     4960                BRect frame;
     4961                uint32 mode;
     4962                if (message->FindRect("frame", &frame) == B_OK
     4963                    && message->FindInt32("mode", (int32*)&mode) == B_OK) {
     4964                    // propegate message to child views
     4965                    for (int32 i = 0; i < CountChildren(); i++) {
     4966                        BView* view = ChildAt(i);
     4967                        if (view != NULL)
     4968                            view->MessageReceived(message);
     4969                    }
     4970                }
     4971                break;
     4972            }
     4973
    49584974            default:
    49594975                BHandler::MessageReceived(message);
    49604976                break;
  • src/kits/interface/Window.cpp

    diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
    index 7a6b203..887b8b8 100644
    a b FrameMoved(origin);  
    11111111                BRect frame;
    11121112                uint32 mode;
    11131113                if (message->FindRect("frame", &frame) == B_OK
    1114                     && message->FindInt32("mode", (int32*)&mode) == B_OK)
     1114                    && message->FindInt32("mode", (int32*)&mode) == B_OK) {
     1115                    // propegate message to child views
     1116                    for (int32 i = 0; i < CountChildren(); i++) {
     1117                        BView* view = ChildAt(i);
     1118                        if (view != NULL)
     1119                            view->MessageReceived(message);
     1120                    }
     1121                    // call hook method
    11151122                    ScreenChanged(frame, (color_space)mode);
     1123                }
    11161124            } else
    11171125                target->MessageReceived(message);
    11181126            break;