Exemple #1
0
void ToolBar::ReCreateButtons()
{
   // SetSizer(NULL) detaches mHSizer and deletes it.
   // Do not use Detach() here, as that attempts to detach mHSizer from itself!
   SetSizer( NULL );

   // Get rid of any children we may have
   DestroyChildren();

   // Create the main sizer
   wxBoxSizer *ms = new wxBoxSizer( wxHORIZONTAL );

   // Create the grabber and add it to the main sizer
   mGrabber = new Grabber( this, mType );
   ms->Add( mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1 );

   // Use a box sizer for laying out controls
   mHSizer = new wxBoxSizer( wxHORIZONTAL );
   ms->Add( mHSizer, 1, wxEXPAND );

   // (Re)Establish dock state
   SetDocked( GetDock(), false );

   // Go add all the rest of the gadgets
   Populate();

   // Add some space for the resize border
   if( IsResizable() )
   {
      mSpacer = ms->Add( RWIDTH, 1 );
   }

   // Set the sizer
   SetSizerAndFit( ms );

   // Recalculate the height to be a multiple of toolbarSingle
   const int tbs = toolbarSingle + toolbarGap;
   wxSize sz = GetSize();
   sz.y = ( ( ( sz.y + tbs ) / tbs ) * tbs ) - 1;

   // Set the true AND minimum sizes and do final layout
   if(IsResizable())
   {
      sz.SetWidth(GetMinToolbarWidth());
      SetMinSize(sz);
      sz.SetWidth(GetInitialWidth());
      SetSize(sz);
   }
   else
   {
      SetInitialSize(sz);
   }
   Layout();
}
void DeviceToolBar::RepositionCombos()
{
   int w, h, dockw, dockh;
   float ratioUnused;
   bool constrained = true;
   wxWindow *window;
   wxSize desiredInput, desiredOutput, desiredHost, desiredChannels;
   float hostRatio, outputRatio, inputRatio, channelsRatio;
   // if the toolbar is docked then the width we should use is the project width.
   // as the toolbar's with can extend past this.
   GetClientSize(&w, &h);

   // FIXME: Note that there's some bug in here, in that even if the prefs show the toolbar
   // docked, on initialization, this call to IsDocked() returns false.
   if (IsDocked()) {
      // If the toolbar is docked its width can be larger than what is actually viewable
      // So take the min.  We don't need to worry about having another toolbar to the left off us
      // because if we are larger than the dock size we always get our own row.
      // and if smaller then we don't use the dock size (because we take the min).
      window = GetDock();
      window->GetClientSize(&dockw, &dockh);
      if (dockw < w)
         w = dockw;
   }
   // subtract the main grabber on the left and the resizer as well
   w -= grabberWidth + GetResizeGrabberWidth();
   if (w <= 0)
      return;

   // set up initial sizes and ratios
   hostRatio     = kHostWidthRatio;
   inputRatio    = kInputWidthRatio;
   outputRatio   = kOutputWidthRatio;
   channelsRatio = kChannelsWidthRatio;

   desiredHost     = mHost->GetBestSize();
   desiredInput    = mInput->GetBestSize();
   desiredOutput   = mOutput->GetBestSize();
   desiredChannels = mInputChannels->GetBestSize();

   // wxGtk has larger comboboxes than the other platforms.  For DeviceToolBar this will cause
   // the height to be double because of the discrete grid layout.  So we shrink it to prevent this.
#ifdef __WXGTK__
   desiredHost.SetHeight(desiredHost.GetHeight() -4);
   desiredInput.SetHeight(desiredHost.GetHeight());
   desiredOutput.SetHeight(desiredHost.GetHeight());
   desiredChannels.SetHeight(desiredHost.GetHeight());
#endif

   ratioUnused = 0.995f - (kHostWidthRatio + kInputWidthRatio + kOutputWidthRatio + kChannelsWidthRatio);
   int i = 0;
   // limit the amount of times we solve contraints to 5
   while (constrained && ratioUnused > 0.01f && i < 5) {
      i++;
      constrained = RepositionCombo(mHost,   w,   desiredHost,   hostRatio, ratioUnused, 0, true);
      constrained |= RepositionCombo(mInput,  w,  desiredInput,  inputRatio, ratioUnused, mRecordBitmap->GetWidth(), true);
      constrained |= RepositionCombo(mOutput, w, desiredOutput, outputRatio, ratioUnused, mPlayBitmap->GetWidth(), true);
      constrained |= RepositionCombo(mInputChannels, w, desiredChannels, channelsRatio, ratioUnused, 0, true);
   }

   Update();
}
Exemple #3
0
void ToolBar::ReCreateButtons()
{
   // SetSizer(NULL) detaches mHSizer and deletes it.
   // Do not use Detach() here, as that attempts to detach mHSizer from itself!
   SetSizer( NULL );

   // Get rid of any children we may have
   DestroyChildren();
   mGrabber = NULL;
   mResizer = NULL;

   {
      // Create the main sizer
      auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL);

      // Create the grabber and add it to the main sizer
      mGrabber = safenew Grabber(this, mType);
      ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1);

      // Use a box sizer for laying out controls
      ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);

      // (Re)Establish dock state
      SetDocked(GetDock(), false);

      // Go add all the rest of the gadgets
      Populate();

      // Add some space for the resize border
      if (IsResizable())
      {
         // Create the resizer and add it to the main sizer
         mResizer = safenew ToolBarResizer(this);
         ms->Add(mResizer, 0, wxEXPAND | wxALIGN_TOP | wxLEFT, 1);
         mResizer->SetToolTip(_("Click and drag to resize toolbar"));
      }

      // Set the sizer
      SetSizerAndFit(ms.release());
   }

   // Recalculate the height to be a multiple of toolbarSingle
   const int tbs = toolbarSingle + toolbarGap;
   wxSize sz = GetSize();
   sz.y = ( ( ( sz.y + tbs -1) / tbs ) * tbs ) - 1;

   // Set the true AND minimum sizes and do final layout
   if(IsResizable())
   {
      sz.SetWidth(GetMinToolbarWidth());
      // JKC we're going to allow all resizable toolbars to be resized
      // to 1 unit high!
      wxSize sz2 = sz;
      sz2.y = tbs -1;
      SetMinSize(sz2);
      sz.SetWidth(GetInitialWidth());
      SetSize(sz);
   }
   else
   {
      SetInitialSize(sz);
   }
   Layout();
}
Exemple #4
0
//
// Read the toolbar states
//
void ToolManager::ReadConfig()
{
   wxString oldpath = gPrefs->GetPath();
   wxArrayInt unordered[ DockCount ];
   bool show[ ToolBarCount ];
   int width[ ToolBarCount ];
   int height[ ToolBarCount ];
   int x, y;
   int dock, ndx;
   bool someFound { false };

#if defined(__WXMAC__)
   // Disable window animation
   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
#endif

   // Change to the bar root
   gPrefs->SetPath( wxT("/GUI/ToolBars") );

   ToolBarConfiguration::Legacy topLegacy, botLegacy;

   // Load and apply settings for each bar
   for( ndx = 0; ndx < ToolBarCount; ndx++ )
   {
      ToolBar *bar = mBars[ ndx ].get();
      //wxPoint Center = mParent->GetPosition() + (mParent->GetSize() * 0.33);
      //wxPoint Center( 
      //   wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) /2 ,
      //   wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) /2 );

      // Change to the bar subkey
      gPrefs->SetPath( bar->GetSection() );

      bool bShownByDefault = true;
      int defaultDock = TopDockID;
      
      if( ndx == SelectionBarID )
         defaultDock = BotDockID;
      if( ndx == MeterBarID )
         bShownByDefault = false;
      if( ndx == ScrubbingBarID )
         bShownByDefault = false;

#ifdef EXPERIMENTAL_SPECTRAL_EDITING
      if( ndx == SpectralSelectionBarID ){
         defaultDock = BotDockID;
         bShownByDefault = false; // Only show if asked for.  
      }
#endif

      // Read in all the settings
      gPrefs->Read( wxT("Dock"), &dock, -1);
      const bool found = (dock != -1);
      if (found)
         someFound = true;
      if (!found)
         dock = defaultDock;
      
      ToolDock *d;
      ToolBarConfiguration::Legacy *pLegacy;
      switch(dock)
      {
         case TopDockID: d = mTopDock; pLegacy = &topLegacy; break;
         case BotDockID: d = mBotDock; pLegacy = &botLegacy;  break;
         default:        d = nullptr; pLegacy = nullptr; break;
      }

      bool ordered = ToolBarConfiguration::Read
         (d ? &d->GetConfiguration() : nullptr,
          pLegacy,
          bar, show[ ndx ], bShownByDefault)
      && found;

      gPrefs->Read( wxT("X"), &x, -1 );
      gPrefs->Read( wxT("Y"), &y, -1 );
      gPrefs->Read( wxT("W"), &width[ ndx ], -1 );
      gPrefs->Read( wxT("H"), &height[ ndx ], -1 );

      bar->SetVisible( show[ ndx ] );

      // Docked or floating?
      if( dock )
      {
         // Default to top dock if the ID isn't valid
         if( dock < NoDockID || dock > DockCount ) {
            dock = TopDockID;
         }

         // Create the bar with the correct parent
         if( dock == TopDockID )
         {
            bar->Create( mTopDock );
         }
         else
         {
            bar->Create( mBotDock );
         }

         // Set the width and height
         if( width[ ndx ] != -1 && height[ ndx ] != -1 )
         {
            wxSize sz( width[ ndx ], height[ ndx ] );
            bar->SetSize( sz );
         }

#ifdef EXPERIMENTAL_SYNC_LOCK
         // Set the width
         if( width[ ndx ] >= bar->GetSize().x )
         {
            wxSize sz( width[ ndx ], bar->GetSize().y );
            bar->SetSize( sz );
            bar->Layout();
         }
#else
         // note that this section is here because if you had been using sync-lock and now you aren't,
         // the space for the extra button is stored in audacity.cfg, and so you get an extra space
         // in the EditToolbar.
         // It is needed so that the meterToolbar size gets preserved.
         // Longer-term we should find a better fix for this.
         wxString thisBar = bar->GetSection();
         if( thisBar != wxT("Edit"))
         {
            // Set the width
            if( width[ ndx ] >= bar->GetSize().x )
            {
               wxSize sz( width[ ndx ], bar->GetSize().y );
               bar->SetSize( sz );
               bar->Layout();
            }
         }
#endif

         if (!ordered)
         {
            // These must go at the end
            unordered[ dock - 1 ].Add( ndx );
         }
      }
      else
      {
         // Create the bar (with the top dock being temporary parent)
         bar->Create( mTopDock );

         // Construct a NEW floater
         wxASSERT(mParent);
         ToolFrame *f = safenew ToolFrame( mParent, this, bar, wxPoint( x, y ) );

         // Set the width and height
         if( width[ ndx ] != -1 && height[ ndx ] != -1 )
         {
            wxSize sz( width[ ndx ], height[ ndx ] );
            f->SetSizeHints( sz );
            f->SetSize( sz );
            f->Layout();
            if( (x!=-1) && (y!=-1) )
               bar->SetPositioned();
         }

         // Required on Linux Xfce
         wxSize msz(width[ndx],height[ndx]-1);
         bar->GetParent()->SetMinSize(msz);

         // Inform toolbar of change
         bar->SetDocked( NULL, false );

         // Show or hide it
         Expose( ndx, show[ ndx ] );
      }

      // Change back to the bar root
      //gPrefs->SetPath( wxT("..") );  <-- Causes a warning...
      // May or may not have gone into a subdirectory,
      // so use an absolute path.
      gPrefs->SetPath( wxT("/GUI/ToolBars") );
   }

   mTopDock->GetConfiguration().PostRead(topLegacy);
   mBotDock->GetConfiguration().PostRead(botLegacy);

   // Add all toolbars to their target dock
   for( dock = 0; dock < DockCount; dock++ )
   {
      ToolDock *d = ( dock + 1 == TopDockID ? mTopDock : mBotDock );

      d->LoadConfig();

      // Add all unordered toolbars
      bool deviceWasPositioned = false;
      for( int ord = 0; ord < (int) unordered[ dock ].GetCount(); ord++ )
      {
         ToolBar *t = mBars[ unordered[ dock ][ ord ] ].get();

         if (deviceWasPositioned &&
             t->GetType() == DeviceBarID)
            continue;

         if (someFound &&
             t->GetType() == ScrubbingBarID) {
            // Special case code to put the NEW scrubbing toolbar where we
            // want it, when audacity.cfg is present from an older version
            ToolBar *lastRoot {};

            // Change from the ideal configuration to the constrained one,
            // just as when dragging and dropping
            ToolBarConfiguration dummy;
            mTopDock->WrapConfiguration(dummy);

            // Start a NEW row with just the scrubbing toolbar
            auto &configuration = mTopDock->GetConfiguration();
            for (const auto place : configuration)
               if (place.position.rightOf == nullptr)
                  lastRoot = place.pTree->pBar;
            ToolBarConfiguration::Position position {
               nullptr, lastRoot, false
            };
            mTopDock->Dock(t, false, position);

            // Reposition the device toolbar, if it was docked above,
            // right of scrubbing
            const auto deviceToolBar = mBars[ DeviceBarID ].get();
            if (deviceToolBar->GetDock() == mTopDock) {
               deviceToolBar->GetDock()->Undock(deviceToolBar);
               position = { t, nullptr };
               mTopDock->Dock(deviceToolBar, false, position);

               // Remember not to place the device toolbar again
               deviceWasPositioned = true;
            }
            Expose( t->GetId(), show[ t->GetId() ] );
            continue;
         }

         // Dock it
         d->Dock( t, false );

         // Show or hide the bar
         Expose( t->GetId(), show[ t->GetId() ] );
      }
   }

   // Restore original config path
   gPrefs->SetPath( oldpath );

#if defined(__WXMAC__)
   // Reinstate original transition
   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
#endif

   if (!someFound)
      Reset();
}
Exemple #5
0
// virtual
LDraw::SizeD DockPanel::MeasureOverride(LDraw::SizeD availSize)
{
    LDraw::BBoxD layoutRect(0, 0, availSize.Width, availSize.Height);

    double minWidth = 0;
    double minHeight = 0;
    double totalWidth = 0;
    double totalHeight = 0;

    unsigned int ncount = get_InternalChildren()->GetCount();

#if 0
    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->GetItem(i);//(*get_rchildList())[i];

        // TODO remove this
        //	pVisual->SetRParent(this);
    }
#endif

    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->get_Item(i);//(*get_rchildList())[i];

        ASSERT(pVisual->GetRParent() == this);

        if (pVisual->get_Visibility() != Collapsed)
        {
            DockEnum dock = GetDock(pVisual);

            if (dock == Fill || ((i == ncount-1) && get_LastChildFill()))
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), layoutRect.GetHeight()));
                totalWidth += pVisual->get_DesiredSize().Width;
                totalHeight += pVisual->get_DesiredSize().Height;
                break;
            }
            else if (dock == Left)
            {
                pVisual->Measure(LDraw::SizeD(0, layoutRect.GetHeight()));
                layoutRect.left += pVisual->get_DesiredSize().Width;
                totalWidth += pVisual->get_DesiredSize().Width;
                //	totalHeight = max(totalHeight, pVisual->m_desiredHeight);
                minHeight = MAX(minHeight, pVisual->get_DesiredSize().Height);
            }
            else if (dock == Top)
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), 0));
                layoutRect.top += pVisual->get_DesiredSize().Height;
                totalHeight += pVisual->get_DesiredSize().Height;
                //	totalWidth = max(totalWidth, pVisual->m_desiredWidth);
                minWidth = MAX(minWidth, pVisual->get_DesiredSize().Width);
            }
            else if (dock == Right)
            {
                pVisual->Measure(LDraw::SizeD(0, layoutRect.GetHeight()));
                layoutRect.right -= pVisual->get_DesiredSize().Width;
                totalWidth += pVisual->get_DesiredSize().Width;
                //	totalHeight = max(totalHeight, pVisual->m_desiredHeight);
                minHeight = MAX(minHeight, pVisual->get_DesiredSize().Height);
            }
            else if (dock == Bottom)
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), 0));
                layoutRect.bottom -= pVisual->get_DesiredSize().Height;
                totalHeight += pVisual->get_DesiredSize().Height;
                //	totalWidth = max(totalWidth, pVisual->m_desiredWidth);
                minWidth = MAX(minWidth, pVisual->get_DesiredSize().Width);
            }
            else
                ASSERT(0);

            //	pVisual->SetLayoutOffset(fLeft, fTop);
            //	pVisual->Arrange(LDraw::SizeF(pVisual->m_computedWidth, pVisual->m_computedHeight));

            /*
            if (dock == Fill ||

            	layoutRect.GetWidth() <= 0 ||
            	layoutRect.GetHeight() <= 0)
            {
            	break;
            }
            */
        }
    }

    return LDraw::SizeD(MAX(minWidth, totalWidth), MAX(minHeight, totalHeight));
}
Exemple #6
0
// virtual
LDraw::SizeD DockPanel::ArrangeOverride(LDraw::SizeD finalSize)
{
    LDraw::BBoxD layoutRect(0, 0, finalSize.Width, finalSize.Height);

    unsigned int ncount = get_InternalChildren()->GetCount();//get_rchildList()->get_Size();
    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->get_Item(i);//(*get_rchildList())[i];

        if (pVisual->get_Visibility() != Collapsed)
        {
            //	long dockValue;
            DockEnum dock = GetDock(pVisual);

            ASSERT(pVisual->get_DesiredSize().Width >= 0 && pVisual->get_DesiredSize().Height >= 0);

            //	double fLeft;
            //	double fTop;

            if (dock == Fill || ((i == ncount-1) && get_LastChildFill()))
            {
                pVisual->Arrange(layoutRect);//LDraw::RectD(layoutRect.GetWidth(), layoutRect.GetHeight()));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
            }
            else if (dock == Left)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.top, pVisual->get_DesiredSize().Width, layoutRect.GetHeight()));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
                layoutRect.left += pVisual->get_ActualSize().Width;
            }
            else if (dock == Top)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.top, layoutRect.GetWidth(), pVisual->get_DesiredSize().Height));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
                layoutRect.top += pVisual->get_ActualSize().Height;
            }
            else if (dock == Right)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.right - pVisual->get_DesiredSize().Width, layoutRect.top, pVisual->get_DesiredSize().Width, layoutRect.GetHeight()));
                //	fLeft = layoutRect.right - pVisual->get_ActualSize().Width;
                //	fTop = layoutRect.top;
                layoutRect.right -= pVisual->get_ActualSize().Width;
            }
            else if (dock == Bottom)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.bottom - pVisual->get_DesiredSize().Height, layoutRect.GetWidth(), pVisual->get_DesiredSize().Height));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.bottom - pVisual->get_ActualSize().Height;
                layoutRect.bottom -= pVisual->get_ActualSize().Height;
            }
            else
                ASSERT(0);

            //	pVisual->SetLayoutOffset(fLeft, fTop);

            if (dock == Fill ||

                    layoutRect.GetWidth() <= 0 ||
                    layoutRect.GetHeight() <= 0)
            {
                break;
            }
        }
    }

    return finalSize;
}