예제 #1
0
void UIContext::setActiveView(DocumentView* docView)
{
  if (m_lastSelectedView == docView)    // Do nothing case
    return;

  setActiveDocument(docView ? docView->getDocument(): NULL);

  if (docView != NULL) {
    App::instance()->getMainWindow()->getTabsBar()->selectTab(docView);

    if (App::instance()->getMainWindow()->getWorkspace()->activeView() != docView)
      App::instance()->getMainWindow()->getWorkspace()->setActiveView(docView);
  }

  current_editor = (docView ? docView->getEditor(): NULL);

  if (current_editor)
    current_editor->requestFocus();

  App::instance()->getMainWindow()->getMiniEditor()->updateUsingEditor(current_editor);
  App::instance()->getMainWindow()->getTimeline()->updateUsingEditor(current_editor);

  // Change the image-type of color bar.
  ColorBar::instance()->setPixelFormat(app_get_current_pixel_format());

  // Restore the palette of the selected document.
  app_refresh_screen();

  // Change the main frame title.
  App::instance()->updateDisplayTitleBar();

  m_lastSelectedView = docView;
}
예제 #2
0
/// Function name  : removeDocument
// Description     : Removes the destroys the specified document. Should not be called directly, except by 'closeDocumentByIndex'
// 
// DOCUMENTS_DATA*  pWindowData : [in] Documents window data
// DOCUMENT*        pDocument   : [in] Target document
// CONST UINT       iIndex      : [in] Index of target document
// 
VOID  removeDocument(DOCUMENTS_DATA*  pWindowData, DOCUMENT*  pDocument, CONST UINT  iIndex)
{
   UINT   iReplacementIndex;    // Index of document to display instead

   
   // [CHECK] Are we closing the ActiveDocument?
   if (pDocument == getActiveDocument())
   {
      // [CHECK] Is there a replacement for the ActiveDocument?
      if (getDocumentCount() > 1)
      {
         // [SUCCESS] Display document on the right, otherwise one on the left
         iReplacementIndex = (iIndex == getDocumentCount() - 1 ? (iIndex - 1) : (iIndex + 1));
         displayDocumentByIndex(pWindowData->hTabCtrl, iReplacementIndex);       /// [EVENT] Fires UM_DOCUMENT_SWITCHED
      }
      else
         // [FAILED] Reset active document
         setActiveDocument(pWindowData, NULL);     /// [EVENT] Fires UM_DOCUMENT_SWITCHED
   }

   /// Remove tab and Destroy Document
   TabCtrl_DeleteItem(pWindowData->hTabCtrl, iIndex);        // [WARNING] TabCtrl_DeleteItem causes document to be erased but not invalidated
   removeObjectFromListByValue(pWindowData->pDocumentList, (LPARAM)pDocument);
   deleteDocument(pDocument);

   // [CHECK] Is there an active document?
   if (getActiveDocument())
      // [ACTIVE DOCUMENT] Resize in case a row of tabs has been removed
      updateDocumentSize(pWindowData, getActiveDocument());
}
예제 #3
0
파일: context.cpp 프로젝트: Skiles/aseprite
void Context::removeDocument(Document* document)
{
  ASSERT(document != NULL);

  // Remove the item from the documents list.
  m_documents.removeDocument(document);

  // generate onRemoveDocument event
  onRemoveDocument(document);

  // The active document cannot be the removed one.
  if (m_activeDocument == document)
    setActiveDocument(NULL);
}
예제 #4
0
/// Function name  : displayDocumentByIndex
// Description     : Changes the active tab and displays the appropriate document
// 
// HWND        hTabCtrl : [in] Document control handle
// CONST UINT  iIndex   : [in] Zero based index of the document to display
// 
VOID  displayDocumentByIndex(HWND  hTabCtrl, CONST UINT  iIndex)
{
   DOCUMENTS_DATA*  pWindowData;    // Window data
   DOCUMENT*        pDocument;      // Target Document

   
   // Prepare
   pWindowData  = getDocumentsControlData(hTabCtrl);

   // Lookup document and ensure its not already active
   if (findDocumentByIndex(hTabCtrl, iIndex, pDocument) AND pDocument != getActiveDocument())
   {
      // [SUCCESS] Hide current active document (if any)
      if (getActiveDocument())
         ShowWindow(getActiveDocument()->hWnd, SW_HIDE);

      /// Ensure correct tab is selected
      TabCtrl_SetCurSel(pWindowData->hTabCtrl, iIndex);     // Already active if user has changed tab manually

      /// Display new document
      setActiveDocument(pWindowData, pDocument);
   }

}
예제 #5
0
/// Function name  : appendDocument
// Description     : Appends a Document to the documents control
// 
// HWND       hTabCtrl  : [in] Tab control
// DOCUMENT*  pDocument : [in] Document to insert
// 
VOID  appendDocument(HWND  hTabCtrl, DOCUMENT*  pDocument)
{
   DOCUMENTS_DATA*  pWindowData;    // Documents control
   TCITEM           oTabItem;       // New Tab data 
   SIZE             siTabCtrl;      // Size of the tab control
   
   
   // Prepare
   pWindowData = getDocumentsControlData(hTabCtrl);

   // [CHECK] Ensure document count == tab count
   ASSERT(getDocumentCount() == TabCtrl_GetItemCount(hTabCtrl));

   // Define tab
   oTabItem.mask    = TCIF_TEXT WITH TCIF_IMAGE;
   oTabItem.pszText = (TCHAR*)getDocumentFileName(pDocument);
   oTabItem.iImage  = pDocument->eType;

   /// Add DOCUMENT to document list
   appendObjectToList(pWindowData->pDocumentList, (LPARAM)pDocument);

   /// Append new tab, but don't initially select
   TabCtrl_InsertItem(hTabCtrl, getDocumentCount() - 1, (LPARAM)&oTabItem);

   // [CHECK] Is this the first document?
   if (getDocumentCount() == 1)
      /// [SUCCESS] Set as ActiveDocument
      setActiveDocument(pWindowData, pDocument);
   else
   {
      // [FAILURE] Resize the active document in case a new row of tabs has been opened
      utilGetWindowSize(hTabCtrl, &siTabCtrl);
      PostMessage(hTabCtrl, WM_SIZE, NULL, MAKE_LONG(siTabCtrl.cx, siTabCtrl.cy));    // BUG_FIX: Using updateDocumentSize(pWindowData, pDocument) didn't work, TabCtrl must need to update something internal first...
   }

}
bool MultiDocumentPanel::addDocument (Component* const component,
                                      const Colour& docColour,
                                      const bool deleteWhenRemoved)
{
    // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
    // with a frame-within-a-frame! Just pass in the bare content component.
    jassert (dynamic_cast <ResizableWindow*> (component) == nullptr);

    if (component == nullptr || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
        return false;

    components.add (component);
    component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
    component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
    component->addComponentListener (this);

    if (mode == FloatingWindows)
    {
        if (isFullscreenWhenOneDocument())
        {
            if (components.size() == 1)
            {
                addAndMakeVisible (component);
            }
            else
            {
                if (components.size() == 2)
                    addWindow (components.getFirst());

                addWindow (component);
            }
        }
        else
        {
           addWindow (component);
        }
    }
    else
    {
        if (tabComponent == nullptr && components.size() > numDocsBeforeTabsUsed)
        {
            addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());

            Array <Component*> temp (components);

            for (int i = 0; i < temp.size(); ++i)
                tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);

            resized();
        }
        else
        {
            if (tabComponent != nullptr)
                tabComponent->addTab (component->getName(), docColour, component, false);
            else
                addAndMakeVisible (component);
        }

        setActiveDocument (component);
    }

    resized();
    activeDocumentChanged();
    return true;
}
예제 #7
0
bool MultiDocumentPanel::closeDocument (Component* component,
                                        const bool checkItsOkToCloseFirst)
{
    if (components.contains (component))
    {
        if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
            return false;

        component->removeComponentListener (this);

        const bool shouldDelete = MultiDocHelpers::shouldDeleteComp (component);
        component->getProperties().remove ("mdiDocumentDelete_");
        component->getProperties().remove ("mdiDocumentBkg_");

        if (mode == FloatingWindows)
        {
            for (int i = getNumChildComponents(); --i >= 0;)
            {
                if (MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i)))
                {
                    if (dw->getContentComponent() == component)
                    {
                        ScopedPointer<MultiDocumentPanelWindow> (dw)->clearContentComponent();
                        break;
                    }
                }
            }

            if (shouldDelete)
                delete component;

            components.removeFirstMatchingValue (component);

            if (isFullscreenWhenOneDocument() && components.size() == 1)
            {
                for (int i = getNumChildComponents(); --i >= 0;)
                {
                    ScopedPointer<MultiDocumentPanelWindow> dw (dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i)));

                    if (dw != nullptr)
                        dw->clearContentComponent();
                }

                addAndMakeVisible (components.getFirst());
            }
        }
        else
        {
            jassert (components.indexOf (component) >= 0);

            if (tabComponent != nullptr)
            {
                for (int i = tabComponent->getNumTabs(); --i >= 0;)
                    if (tabComponent->getTabContentComponent (i) == component)
                        tabComponent->removeTab (i);
            }
            else
            {
                removeChildComponent (component);
            }

            if (shouldDelete)
                delete component;

            if (tabComponent != nullptr && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
                tabComponent = nullptr;

            components.removeFirstMatchingValue (component);

            if (components.size() > 0 && tabComponent == nullptr)
                addAndMakeVisible (components.getFirst());
        }

        resized();

        // This ensures that the active tab is painted properly when a tab is closed!
        if (Component* activeComponent = getActiveDocument())
            setActiveDocument (activeComponent);

        activeDocumentChanged();
    }
    else
    {
        jassertfalse;
    }

    return true;
}
예제 #8
0
void Context::onRemoveDocument(Document* doc)
{
  if (m_activeDoc == doc)
    setActiveDocument(!m_docs.empty() ? m_docs.back() : NULL);
}
예제 #9
0
Context::~Context()
{
  setActiveDocument(NULL);
  m_docs.removeObserver(this);
}