Пример #1
0
const tmAction* FindCmdDlg::ActionList::GetSelectedAction() {
	const int sel = GetSelection();
	return sel == -1 ? NULL : m_items[sel].action;
}
Пример #2
0
void wxFlatNotebook::SetSelection(size_t page)
{
	if(page >= m_windows.GetCount())
		return;

	// Support for disabed tabs
	if(!m_pages->GetEnabled(page) && m_windows.GetCount() > 1 && !m_bForceSelection)
		return;

	if( m_sendPageChangeEvent )
	{
		// Allow the user to veto the selection
		int oldSelection = GetSelection();

		wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGING, GetId());
		event.SetSelection( (int)page );
		event.SetOldSelection( oldSelection );
		event.SetEventObject( this );
		GetEventHandler()->ProcessEvent(event);

		if( !event.IsAllowed() )
		{
			return;
		}
	}

	int curSel = m_pages->GetSelection();

	// program allows the page change
	Freeze();
	if(curSel >= 0)
	{
		// Remove the window from the main sizer
		m_mainSizer->Detach(m_windows[curSel]);
		m_windows[curSel]->Hide();
	}

	if(m_windowStyle & wxFNB_BOTTOM)
	{
		m_mainSizer->Insert(0, m_windows[page], 1, wxEXPAND);
	}
	else
	{
		// We leave a space of 1 pixel around the window
		m_mainSizer->Add(m_windows[page], 1, wxEXPAND);
	}

	m_windows[page]->Show();
	Thaw();
	m_mainSizer->Layout();

	if( page != (size_t)m_pages->m_iActivePage )
		//there is a real poge changing
		m_pages->m_iPreviousActivePage = m_pages->m_iActivePage;

	m_pages->m_iActivePage = (int)page;
	m_pages->DoSetSelection(page);

	if( m_sendPageChangeEvent )
	{
		// Fire event 'Page Changed'
		wxFlatNotebookEvent event(wxEVT_COMMAND_FLATNOTEBOOK_PAGE_CHANGED, GetId());
		event.SetSelection( (int)page );
		event.SetEventObject( this );
		GetEventHandler()->ProcessEvent(event);
	}
}
Пример #3
0
void               P3DPlantModelTreeCtrl::OnAppendBranchCopyClick
                                      (wxCommandEvent     &event)
 {
  P3DListDialog                        SourceSelectionDialog(NULL,wxID_ANY,wxT("Select group to copy"));
  bool                                 Done;
  P3DPlantModel                       *PlantModel;
  P3DBranchModel                      *BranchModel;
  unsigned int                         BranchIndex;

  PlantModel = P3DApp::GetApp()->GetModel();

  BranchIndex = 0;
  BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,BranchIndex);

  while (BranchModel != 0)
   {
    SourceSelectionDialog.AddChoice(BranchModel->GetName());

    BranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,++BranchIndex);
   }

  SourceSelectionDialog.SetSelection(0);

  if (SourceSelectionDialog.ShowModal() == wxID_OK)
   {
    int            SourceBranchIndex;

    SourceBranchIndex = SourceSelectionDialog.GetSelection();

    if (SourceBranchIndex >= 0)
     {
      const P3DBranchModel            *SourceBranchModel;
      P3DBranchModel                  *ParentBranchModel;
      P3DBranchModel                  *ChildBranchModel;
      P3DStemModelWings               *WingsStemModel;
      const P3DBranchingAlg           *SourceBranchingAlg;
      P3DStemModel                    *NewStemModel;
      P3DBranchingAlg                 *NewBranchingAlg;
      P3DVisRangeState                *NewVisRange;
      float                            MinRange,MaxRange;

      SourceBranchModel = P3DPlantModel::GetBranchModelByIndex(PlantModel,SourceBranchIndex);
      ParentBranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(GetSelection())))->GetBranchModel();

      if (dynamic_cast<const P3DStemModelWings*>(SourceBranchModel->GetStemModel()) != 0)
       {
        if (ParentBranchModel->GetStemModel() == 0) /* trunk */
         {
          ::wxMessageBox(wxT("\"Wings\" stem can be added to \"Tube\" stems only"),
                         wxT("Error"),
                         wxICON_ERROR | wxOK);

          return;
         }
       }

      ChildBranchModel = new P3DBranchModel();

      ChildBranchModel->SetName
       (GenerateClonedBranchName
         (P3DApp::GetApp()->GetModel(),SourceBranchModel).c_str());

      NewStemModel = SourceBranchModel->GetStemModel()->CreateCopy();

      WingsStemModel = dynamic_cast<P3DStemModelWings*>(NewStemModel);

      if (WingsStemModel != 0)
       {
        WingsStemModel->SetParent((P3DStemModelTube*)ParentBranchModel->GetStemModel());
       }

      ChildBranchModel->SetStemModel(NewStemModel);

      if ((dynamic_cast<const P3DBranchingAlgBase*>(SourceBranchModel->GetBranchingAlg())) != 0)
       {
        if (ParentBranchModel->GetStemModel() == 0)
         {
          NewBranchingAlg = SourceBranchModel->GetBranchingAlg()->CreateCopy();
         }
        else
         {
          NewBranchingAlg = P3DApp::GetApp()->CreateBranchingAlgStd();
         }
       }
      else
       {
        if (ParentBranchModel->GetStemModel() == 0)
         {
          NewBranchingAlg = new P3DBranchingAlgBase();
         }
        else
         {
          NewBranchingAlg = SourceBranchModel->GetBranchingAlg()->CreateCopy();
         }
       }

      ChildBranchModel->SetBranchingAlg(NewBranchingAlg);

      ChildBranchModel->SetMaterialInstance(SourceBranchModel->GetMaterialInstance()->CreateCopy());

      NewVisRange = ChildBranchModel->GetVisRangeState();

      NewVisRange->SetState(SourceBranchModel->GetVisRangeState()->IsEnabled());

      SourceBranchModel->GetVisRangeState()->GetRange(&MinRange,&MaxRange);

      NewVisRange->SetRange(MinRange,MaxRange);

      P3DApp::GetApp()->ExecEditCmd
       (new AppendBranchCommand(ParentBranchModel,ChildBranchModel,this));
     }
   }
 }
void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
                                        COMPONENT* aComponent, int aFilterType )
{
    wxArrayString   newList;
    wxString        msg;
    wxString        oldSelection;

    if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
        oldSelection = m_footprintList[ GetSelection() ];

    for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
    {
        if( aFilterType == UNFILTERED )
        {
            msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
                        GetChars( aList.GetItem( ii ).GetNickname() ),
                        GetChars( aList.GetItem( ii ).GetFootprintName() ) );
            newList.Add( msg );
            continue;
        }

        if( (aFilterType & BY_LIBRARY) && !aLibName.IsEmpty()
          && !aList.GetItem( ii ).InLibrary( aLibName ) )
            continue;

        if( (aFilterType & BY_COMPONENT) && aComponent
          && !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetFootprintName() ) )
            continue;

        if( (aFilterType & BY_PIN_COUNT) && aComponent
          && aComponent->GetNetCount() != aList.GetItem( ii ).GetPadCount() )
            continue;

        msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
                    GetChars( aList.GetItem( ii ).GetNickname() ),
                    GetChars( aList.GetItem( ii ).GetFootprintName() ) );
        newList.Add( msg );
    }

    if( newList == m_footprintList )
        return;

    m_footprintList = newList;

    int selection = m_footprintList.Index( oldSelection );

    if( selection == wxNOT_FOUND )
        selection = 0;

    DeleteAllItems();

    if( m_footprintList.GetCount() )
    {
        SetItemCount( m_footprintList.GetCount() );
        SetSelection( selection, true );
        RefreshItems( 0L, m_footprintList.GetCount()-1 );

#if defined (__WXGTK__ ) //&& wxMINOR_VERSION == 8
        // @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the

        //      column parameter is -1.  This was the only way to prevent GTK3 from
        //      ellipsizing long strings down to a few characters.  It still doesn't set
        //      the scroll bars correctly (too short) but it's better than any of the
        //      other alternatives.  If someone knows how to fix this, please do.
        SetColumnWidth( -1, wxLIST_AUTOSIZE );
#else
        SetColumnWidth( 0, wxLIST_AUTOSIZE );
#endif
    }
}
Пример #5
0
void thBarViewCtrl::OnMouseLeave(wxMouseEvent &event)
{
    Mark(GetSelection());
}
Пример #6
0
void wxTabbedCtrl::OnPaint(wxPaintEvent &) {
    wxPaintDC dc(this);
    wxSize size = GetSize();
    wxBrush back_brush = wxBrush(GetBackgroundColour());
    wxBrush nosel_brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
    wxBrush sel_brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
    wxPen border_pen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
    wxPen sel_pen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
    wxPen back_pen = wxPen(GetBackgroundColour());
    wxFont normal_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
    wxFont bold_font = normal_font;
    bold_font.SetWeight(wxFONTWEIGHT_BOLD);
    bool mirror = style & wxTB_BOTTOM;
    bool fullborder = !(style & wxNO_BORDER);

    dc.BeginDrawing();

    //background
    dc.SetTextBackground(GetBackgroundColour());
    dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
    dc.SetBrush(back_brush);
    if(fullborder) {
        dc.SetPen(border_pen);
        dc.DrawRectangle(0, 0, size.x, size.y);
    }
    else {
        dc.SetPen(back_pen);
        dc.DrawRectangle(0, 0, size.x, size.y);
        dc.SetPen(border_pen);
        dc.DrawLine(0, mirror ? 0 : size.y-1, size.x, mirror ? 0 : size.y-1);
    }

    int height, width, pom;
    dc.SetFont(bold_font);
    dc.GetTextExtent("Aq", &pom, &height);
    int posx = 3;

    //and tabs
    int i = m_intStartPage;
    for( ; i < GetPageCount(); i++) {
        dc.SetPen(border_pen);
        dc.SetFont((i==GetSelection()) ? bold_font : normal_font);
        dc.SetBrush((i==GetSelection()) ? sel_brush : nosel_brush);
        dc.GetTextExtent(GetPageText(i), &width, &pom);

        int space = padding.x;
        if( ( posx + width+space+padding.x + BUTTON_BAR_SIZE ) > size.x ) {
            break;
        }

        dc.DrawRoundedRectangle(posx, size.y-height-padding.y*2, width+space+padding.x, height+padding.y*2+3, 3);
        dc.DrawText(GetPageText(i), posx+space, size.y-height-padding.y);
        if(i!=GetSelection())
            dc.DrawLine(posx, size.y-1, posx+width+space+padding.x, size.y-1);

        posx += width+space+padding.x;
    }
    m_intLastPage = i - 1;

    //X
    DrawX(hover, dc);
    DrawNext( hover_next, dc );
    DrawPrev( hover_prev, dc );
    DrawMenu( hover_menu, dc );


    dc.EndDrawing();
}
Пример #7
0
void CQueue::SetFocus()
{
	GetPage(GetSelection())->SetFocus();
}
nsresult
nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, PRBool aIsLinksOnly,
                           PRBool aIsFirstVisiblePreferred, PRBool aFindPrev,
                           PRUint16* aResult)
{
  *aResult = FIND_NOTFOUND;
  mFoundLink = nsnull;
  mFoundEditable = nsnull;
  mCurrentWindow = nsnull;
  nsCOMPtr<nsIPresShell> startingPresShell (GetPresShell());
  if (!startingPresShell) {    
    nsCOMPtr<nsIDocShell> ds = do_QueryReferent(mDocShell);
    NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE);

    ds->GetPresShell(getter_AddRefs(startingPresShell));
    mPresShell = do_GetWeakReference(startingPresShell);    
  }  

  nsCOMPtr<nsIPresShell> presShell(aPresShell);

  if (!presShell) {
    presShell = startingPresShell;  // this is the current document

    if (!presShell)
      return NS_ERROR_FAILURE;
  }

  nsRefPtr<nsPresContext> presContext = presShell->GetPresContext();

  if (!presContext)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsISelection> selection;
  nsCOMPtr<nsISelectionController> selectionController = 
    do_QueryReferent(mSelectionController);
  if (!selectionController) {
    GetSelection(presShell, getter_AddRefs(selectionController),
                 getter_AddRefs(selection)); // cache for reuse
    mSelectionController = do_GetWeakReference(selectionController);
  } else {
    selectionController->GetSelection(
      nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
  }
 
  nsCOMPtr<nsISupports> startingContainer = presContext->GetContainer();
  nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(startingContainer));
  NS_ASSERTION(treeItem, "Bug 175321 Crashes with Type Ahead Find [@ nsTypeAheadFind::FindItNow]");
  if (!treeItem)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDocShellTreeItem> rootContentTreeItem;
  nsCOMPtr<nsIDocShell> currentDocShell;
  nsCOMPtr<nsIDocShell> startingDocShell(do_QueryInterface(startingContainer));

  treeItem->GetSameTypeRootTreeItem(getter_AddRefs(rootContentTreeItem));
  nsCOMPtr<nsIDocShell> rootContentDocShell =
    do_QueryInterface(rootContentTreeItem);

  if (!rootContentDocShell)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
  rootContentDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
                                             nsIDocShell::ENUMERATE_FORWARDS,
                                             getter_AddRefs(docShellEnumerator));

  // Default: can start at the current document
  nsCOMPtr<nsISupports> currentContainer = startingContainer =
    do_QueryInterface(rootContentDocShell);

  // Iterate up to current shell, if there's more than 1 that we're
  // dealing with
  PRBool hasMoreDocShells;

  while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) && hasMoreDocShells) {
    docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
    currentDocShell = do_QueryInterface(currentContainer);
    if (!currentDocShell || currentDocShell == startingDocShell || aIsFirstVisiblePreferred)
      break;    
  }

  // ------------ Get ranges ready ----------------
  nsCOMPtr<nsIDOMRange> returnRange;
  nsCOMPtr<nsIPresShell> focusedPS;
  if (NS_FAILED(GetSearchContainers(currentContainer,
                                    (!aIsFirstVisiblePreferred ||
                                     mStartFindRange) ?
                                    selectionController.get() : nsnull,
                                    aIsFirstVisiblePreferred,  aFindPrev,
                                    getter_AddRefs(presShell),
                                    getter_AddRefs(presContext)))) {
    return NS_ERROR_FAILURE;
  }

  PRInt16 rangeCompareResult = 0;
  mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, mSearchRange, &rangeCompareResult);
  // No need to wrap find in doc if starting at beginning
  PRBool hasWrapped = (rangeCompareResult < 0);

  if (mTypeAheadBuffer.IsEmpty())
    return NS_ERROR_FAILURE;

  mFind->SetFindBackwards(aFindPrev);

  while (PR_TRUE) {    // ----- Outer while loop: go through all docs -----
    while (PR_TRUE) {  // === Inner while loop: go through a single doc ===
      mFind->Find(mTypeAheadBuffer.get(), mSearchRange, mStartPointRange,
                  mEndPointRange, getter_AddRefs(returnRange));
      
      if (!returnRange)
        break;  // Nothing found in this doc, go to outer loop (try next doc)

      // ------- Test resulting found range for success conditions ------
      PRBool isInsideLink = PR_FALSE, isStartingLink = PR_FALSE;

      if (aIsLinksOnly) {
        // Don't check if inside link when searching all text
        RangeStartsInsideLink(returnRange, presShell, &isInsideLink,
                              &isStartingLink);
      }

      PRBool usesIndependentSelection;
      if (!IsRangeVisible(presShell, presContext, returnRange,
                          aIsFirstVisiblePreferred, PR_FALSE,
                          getter_AddRefs(mStartPointRange), 
                          &usesIndependentSelection) ||
          (aIsLinksOnly && !isInsideLink) ||
          (mStartLinksOnlyPref && aIsLinksOnly && !isStartingLink)) {
        // ------ Failure ------
        // Start find again from here
        returnRange->CloneRange(getter_AddRefs(mStartPointRange));

        // Collapse to end
        mStartPointRange->Collapse(aFindPrev);

        continue;
      }

      // ------ Success! -------
      // Hide old selection (new one may be on a different controller)
      if (selection) {
        selection->CollapseToStart();
        SetSelectionModeAndRepaint(nsISelectionController::SELECTION_ON);
      }

      // Make sure new document is selected
      if (presShell != startingPresShell) {
        // We are in a new document (because of frames/iframes)
        mPresShell = do_GetWeakReference(presShell);
      }

      nsCOMPtr<nsIDocument> document =
        do_QueryInterface(presShell->GetDocument());
      NS_ASSERTION(document, "Wow, presShell doesn't have document!");
      if (!document)
        return NS_ERROR_UNEXPECTED;

      nsCOMPtr<nsPIDOMWindow> window = document->GetWindow();
      NS_ASSERTION(window, "document has no window");
      if (!window)
        return NS_ERROR_UNEXPECTED;

      nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
      if (usesIndependentSelection) {
        /* If a search result is found inside an editable element, we'll focus
         * the element only if focus is in our content window, i.e.
         * |if (focusedWindow.top == ourWindow.top)| */
        PRBool shouldFocusEditableElement = false;
        if (fm) {
          nsCOMPtr<nsIDOMWindow> focusedWindow;
          nsresult rv = fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
          if (NS_SUCCEEDED(rv)) {
            nsCOMPtr<nsPIDOMWindow> fwPI(do_QueryInterface(focusedWindow, &rv));
            if (NS_SUCCEEDED(rv)) {
              nsCOMPtr<nsIDocShellTreeItem> fwTreeItem
                (do_QueryInterface(fwPI->GetDocShell(), &rv));
              if (NS_SUCCEEDED(rv)) {
                nsCOMPtr<nsIDocShellTreeItem> fwRootTreeItem;
                rv = fwTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(fwRootTreeItem));
                if (NS_SUCCEEDED(rv) && fwRootTreeItem == rootContentTreeItem)
                  shouldFocusEditableElement = PR_TRUE;
              }
            }
          }
        }

        // We may be inside an editable element, and therefore the selection
        // may be controlled by a different selection controller.  Walk up the
        // chain of parent nodes to see if we find one.
        nsCOMPtr<nsIDOMNode> node;
        returnRange->GetStartContainer(getter_AddRefs(node));
        while (node) {
          nsCOMPtr<nsIDOMNSEditableElement> editable = do_QueryInterface(node);
          if (editable) {
            // Inside an editable element.  Get the correct selection 
            // controller and selection.
            nsCOMPtr<nsIEditor> editor;
            editable->GetEditor(getter_AddRefs(editor));
            NS_ASSERTION(editor, "Editable element has no editor!");
            if (!editor) {
              break;
            }
            editor->GetSelectionController(
              getter_AddRefs(selectionController));
            if (selectionController) {
              selectionController->GetSelection(
                nsISelectionController::SELECTION_NORMAL, 
                getter_AddRefs(selection));
            }
            mFoundEditable = do_QueryInterface(node);

            if (!shouldFocusEditableElement)
              break;

            // Otherwise move focus/caret to editable element
            if (fm)
              fm->SetFocus(mFoundEditable, 0);
            break;
          }
          nsIDOMNode* tmp = node;
          tmp->GetParentNode(getter_AddRefs(node));
        }

        // If we reach here without setting mFoundEditable, then something
        // besides editable elements can cause us to have an independent
        // selection controller.  I don't know whether this is possible.
        // Currently, we simply fall back to grabbing the document's selection
        // controller in this case.  Perhaps we should reject this find match
        // and search again.
        NS_ASSERTION(mFoundEditable, "Independent selection controller on "
                     "non-editable element!");
      }

      if (!mFoundEditable) {
        // Not using a separate selection controller, so just get the
        // document's controller and selection.
        GetSelection(presShell, getter_AddRefs(selectionController), 
                     getter_AddRefs(selection));
      }
      mSelectionController = do_GetWeakReference(selectionController);

      // Select the found text
      if (selection) {
        selection->RemoveAllRanges();
        selection->AddRange(returnRange);
      }

      if (!mFoundEditable && fm) {
        nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(window);
        fm->MoveFocus(win, nsnull, nsIFocusManager::MOVEFOCUS_CARET,
                      nsIFocusManager::FLAG_NOSCROLL | nsIFocusManager::FLAG_NOSWITCHFRAME,
                      getter_AddRefs(mFoundLink));
      }

      // Change selection color to ATTENTION and scroll to it.  Careful: we
      // must wait until after we goof with focus above before changing to
      // ATTENTION, or when we MoveFocus() and the selection is not on a
      // link, we'll blur, which will lose the ATTENTION.
      if (selectionController) {
        // Beware! This may flush notifications via synchronous
        // ScrollSelectionIntoView.
        SetSelectionModeAndRepaint(nsISelectionController::SELECTION_ATTENTION);
        selectionController->ScrollSelectionIntoView(
          nsISelectionController::SELECTION_NORMAL, 
          nsISelectionController::SELECTION_WHOLE_SELECTION,
          nsISelectionController::SCROLL_SYNCHRONOUS);
      }

      mCurrentWindow = window;
      *aResult = hasWrapped ? FIND_WRAPPED : FIND_FOUND;
      return NS_OK;
    }

    // ======= end-inner-while (go through a single document) ==========

    // ---------- Nothing found yet, try next document  -------------
    PRBool hasTriedFirstDoc = PR_FALSE;
    do {
      // ==== Second inner loop - get another while  ====
      if (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells))
          && hasMoreDocShells) {
        docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
        NS_ASSERTION(currentContainer, "HasMoreElements lied to us!");
        currentDocShell = do_QueryInterface(currentContainer);

        if (currentDocShell)
          break;
      }
      else if (hasTriedFirstDoc)  // Avoid potential infinite loop
        return NS_ERROR_FAILURE;  // No content doc shells

      // Reached last doc shell, loop around back to first doc shell
      rootContentDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
                                                 nsIDocShell::ENUMERATE_FORWARDS,
                                                 getter_AddRefs(docShellEnumerator));
      hasTriedFirstDoc = PR_TRUE;      
    } while (docShellEnumerator);  // ==== end second inner while  ===

    PRBool continueLoop = PR_FALSE;
    if (currentDocShell != startingDocShell)
      continueLoop = PR_TRUE;  // Try next document
    else if (!hasWrapped || aIsFirstVisiblePreferred) {
      // Finished searching through docshells:
      // If aFirstVisiblePreferred == PR_TRUE, we may need to go through all
      // docshells twice -once to look for visible matches, the second time
      // for any match
      aIsFirstVisiblePreferred = PR_FALSE;
      hasWrapped = PR_TRUE;
      continueLoop = PR_TRUE; // Go through all docs again
    }

    if (continueLoop) {
      if (NS_FAILED(GetSearchContainers(currentContainer, nsnull,
                                        aIsFirstVisiblePreferred, aFindPrev,
                                        getter_AddRefs(presShell),
                                        getter_AddRefs(presContext)))) {
        continue;
      }

      if (aFindPrev) {
        // Reverse mode: swap start and end points, so that we start
        // at end of document and go to beginning
        nsCOMPtr<nsIDOMRange> tempRange;
        mStartPointRange->CloneRange(getter_AddRefs(tempRange));
        mStartPointRange = mEndPointRange;
        mEndPointRange = tempRange;
      }

      continue;
    }

    // ------------- Failed --------------
    break;
  }   // end-outer-while: go through all docs

  return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTypeAheadFind::Find(const nsAString& aSearchString, PRBool aLinksOnly,
                      PRUint16* aResult)
{
  *aResult = FIND_NOTFOUND;

  nsCOMPtr<nsIPresShell> presShell (GetPresShell());
  if (!presShell) {    
    nsCOMPtr<nsIDocShell> ds (do_QueryReferent(mDocShell));
    NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE);

    ds->GetPresShell(getter_AddRefs(presShell));
    mPresShell = do_GetWeakReference(presShell);    
  }  
  nsCOMPtr<nsISelection> selection;
  nsCOMPtr<nsISelectionController> selectionController = 
    do_QueryReferent(mSelectionController);
  if (!selectionController) {
    GetSelection(presShell, getter_AddRefs(selectionController),
                 getter_AddRefs(selection)); // cache for reuse
    mSelectionController = do_GetWeakReference(selectionController);
  } else {
    selectionController->GetSelection(
      nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
  }

  if (selection)
    selection->CollapseToStart();

  if (aSearchString.IsEmpty()) {
    mTypeAheadBuffer.Truncate();

    // These will be initialized to their true values after the first character
    // is typed
    mStartFindRange = nsnull;
    mSelectionController = nsnull;

    *aResult = FIND_FOUND;
    return NS_OK;
  }

  PRBool atEnd = PR_FALSE;    
  if (mTypeAheadBuffer.Length()) {
    const nsAString& oldStr = Substring(mTypeAheadBuffer, 0, mTypeAheadBuffer.Length());
    const nsAString& newStr = Substring(aSearchString, 0, mTypeAheadBuffer.Length());
    if (oldStr.Equals(newStr))
      atEnd = PR_TRUE;
  
    const nsAString& newStr2 = Substring(aSearchString, 0, aSearchString.Length());
    const nsAString& oldStr2 = Substring(mTypeAheadBuffer, 0, aSearchString.Length());
    if (oldStr2.Equals(newStr2))
      atEnd = PR_TRUE;
    
    if (!atEnd)
      mStartFindRange = nsnull;
  }

  if (!mIsSoundInitialized && !mNotFoundSoundURL.IsEmpty()) {
    // This makes sure system sound library is loaded so that
    // there's no lag before the first sound is played
    // by waiting for the first keystroke, we still get the startup time benefits.
    mIsSoundInitialized = PR_TRUE;
    mSoundInterface = do_CreateInstance("@mozilla.org/sound;1");
    if (mSoundInterface && !mNotFoundSoundURL.Equals(NS_LITERAL_CSTRING("beep"))) {
      mSoundInterface->Init();
    }
  }

#ifdef XP_WIN
  // After each keystroke, ensure sound object is destroyed, to free up memory 
  // allocated for error sound, otherwise Windows' nsISound impl 
  // holds onto the last played sound, using up memory.
  mSoundInterface = nsnull;
#endif

  PRInt32 bufferLength = mTypeAheadBuffer.Length();

  mTypeAheadBuffer = aSearchString;

  PRBool isFirstVisiblePreferred = PR_FALSE;

  // --------- Initialize find if 1st char ----------
  if (bufferLength == 0) {
    // If you can see the selection (not collapsed or thru caret browsing),
    // or if already focused on a page element, start there.
    // Otherwise we're going to start at the first visible element
    PRBool isSelectionCollapsed = PR_TRUE;
    if (selection)
      selection->GetIsCollapsed(&isSelectionCollapsed);

    // If true, we will scan from top left of visible area
    // If false, we will scan from start of selection
    isFirstVisiblePreferred = !atEnd && !mCaretBrowsingOn && isSelectionCollapsed;
    if (isFirstVisiblePreferred) {
      // Get the focused content. If there is a focused node, ensure the
      // selection is at that point. Otherwise, we will just want to start
      // from the caret position or the beginning of the document.
      nsPresContext* presContext = presShell->GetPresContext();
      NS_ENSURE_TRUE(presContext, NS_OK);

      nsCOMPtr<nsIDocument> document =
        do_QueryInterface(presShell->GetDocument());
      if (!document)
        return NS_ERROR_UNEXPECTED;

      nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(document->GetWindow());

      nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
      if (fm) {
        nsCOMPtr<nsIDOMElement> focusedElement;
        nsCOMPtr<nsIDOMWindow> focusedWindow;
        fm->GetFocusedElementForWindow(window, PR_FALSE, getter_AddRefs(focusedWindow),
                                       getter_AddRefs(focusedElement));
        // If the root element is focused, then it's actually the document
        // that has the focus, so ignore this.
        if (focusedElement &&
            !SameCOMIdentity(focusedElement, document->GetRootElement())) {
          fm->MoveCaretToFocus(window);
          isFirstVisiblePreferred = PR_FALSE;
        }
      }
    }
  }

  // ----------- Find the text! ---------------------
  // Beware! This may flush notifications via synchronous
  // ScrollSelectionIntoView.
  nsresult rv = FindItNow(nsnull, aLinksOnly, isFirstVisiblePreferred,
                          PR_FALSE, aResult);

  // ---------Handle success or failure ---------------
  if (NS_SUCCEEDED(rv)) {
    if (mTypeAheadBuffer.Length() == 1) {
      // If first letter, store where the first find succeeded
      // (mStartFindRange)

      mStartFindRange = nsnull;
      if (selection) {
        nsCOMPtr<nsIDOMRange> startFindRange;
        selection->GetRangeAt(0, getter_AddRefs(startFindRange));
        if (startFindRange)
          startFindRange->CloneRange(getter_AddRefs(mStartFindRange));
      }
    }
  }
  else {
    // Error sound
    if (mTypeAheadBuffer.Length() > mLastFindLength)
      PlayNotFoundSound();
  }

  SaveFind();
  return NS_OK;
}
Пример #10
0
// Create a command list node.
void KeyboardPage::CreateNode( int nType, LPVOID lpvData )
{
	// Get the currently selected keyboard hash.
	LPHASH pHash = GetSelection();
	LPCNODE pCNode = NULL;
	if ( pHash )
	{
		// Allocate node.
		pCNode = ( LPCNODE )::AllocPooled( pParserPool, sizeof( CNODE ));
		if ( pCNode != NULL )
		{
			// Setup type.
			pCNode->nType = nType;

			// Hardcoded?
			if ( nType == CTYPE_HARDCODED )
				// Setup function.
				pCNode->lpFunc = ::FindCommand(( int )lpvData );
			else
			{
				// Allocate string copy.
				pCNode->pcStr = ::CopyStringPool( pParserPool, ( LPCTSTR )lpvData );
				if ( pCNode->pcStr == NULL )
				{
					// Failure.
					MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK );
					::FreePooled( pParserPool, pCNode );
					pCNode = NULL;
				}
			}
		}
		else
			MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK );
	}

	// Still there?
	if ( pCNode )
	{
		// Add the node to the list.
		AddTail(( LPLIST )pHash->lpCommands, ( LPNODE )pCNode );

		// Add it to the listview.
		int nSel = m_Commands.AddString(( LPCTSTR )pCNode );
		if ( nSel != LB_ERR )
		{
			// Select the entry.
			m_Commands.SetCurSel( nSel );

			// Edit the node.
			SendMessage( WM_COMMAND, MAKEWPARAM( IDC_COMMANDS, LBN_DBLCLK ), ( LPARAM )m_Commands.GetSafeHWND());

			// Changes have been made.
			pSettings->Changed( m_pParser );
			SetupControls();
		}
		else
		{
			// Show out of memory error. Guess this should be the
			// only reason this could fail.
			MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK );

			// Free the node and
			// it's string.
			if ( nType != CTYPE_HARDCODED ) ::FreePooled( pParserPool, pCNode->pcStr );
			::FreePooled( pParserPool, pCNode );
		}
	}
}
Пример #11
0
// WM_COMMAND handler.
LRESULT KeyboardPage::OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl )
{
	// What's up?
	switch ( nCtrlID )
	{
		case	EditToolbar::ETID_NEW:
			// Command toolbar?
			if ( hWndCtrl == m_ComTools )
			{
				// Obtain button rectangle.
				ClsRect rc;
				m_ComTools.GetItemRect( 0, rc );

				// Convert rectangle to screen
				// coordinates.
				m_ComTools.ClientToScreen( rc );

				// Show the menu.
				::TrackPopupMenuEx( m_Menu,//*m_Menu.GetSubMenu( 0 ),
						  TPM_LEFTALIGN,
						  rc.Left(),
						  rc.Bottom(),
						  GetSafeHWND(),
						  NULL );
			}
			else
			{
				// Show the key recorder.
				KeyRec kr;
				ClsString str;
				if ( kr.KeyRecord( *GetParent(), str ))
					AddKeyMapping( str );
			}
			return 0;

		case	EditToolbar::ETID_DELETE:
			// Command toolbar?
			if ( hWndCtrl == m_ComTools )
			{
				// Get current selection.
				LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel());
				if ( pCNode != ( LPCNODE )LB_ERR )
				{
					// Save selection position.
					int nSel = m_Commands.GetCurSel();
					int nPos = nSel;
					int nMax = m_Commands.GetCount();
					
					// Select the next or previous
					// entry.
					if ( nSel == nMax - 1 && nSel ) nSel--;
					else				nSel++;

					// Select the new item
					m_Commands.SetCurSel( nSel );

					// Remove the node from the listview.
					m_Commands.DeleteString( nPos );

					// Remove it from the command list.
					Remove(( LPNODE )pCNode );

					// Free the node
					// data.
					if ( pCNode->nType != CTYPE_HARDCODED )
						::FreePooled( pParserPool, pCNode->pcStr );

					// And the node itself.
					::FreePooled( pParserPool, pCNode );

					// Setup GUI.
					SetupControls();
					pSettings->Changed( m_pParser );
				}
				return 0;
			}
			else
			{
				// Get the key descriptor.
				TCHAR szKeyString[ 64 ];
				int nSel = m_Keys.GetCurSel(), nMax = m_Keys.GetCount();
				if ( nSel != LB_ERR )
				{
					if ( m_Keys.GetText( nSel, szKeyString ) != LB_ERR )
					{
						// Convert to a code and qualifier.
						TCHAR cCode, cQual;
						if ( ::Str2CodeQual( szKeyString, &cCode, &cQual ))
						{
							// Remove the hash. This will automatically destroy
							// the command-list aswell.
							::RemHash( pParserPool, m_pParser->aHash, cCode, cQual );

							// Remove it from the listview.
							m_Keys.DeleteString( nSel );

							// Was it the last one?
							if ( nSel == nMax - 1 ) nSel--;

							// Select the next or previous key.
							m_Keys.SetCurSel( nSel );
							SendMessage( WM_COMMAND, MAKEWPARAM( IDC_KEYS, LBN_SELCHANGE ), ( LPARAM )m_Keys.GetSafeHWND());

							// Changes made...
							pSettings->Changed( m_pParser );
						}
					}
				}
			}
			return 0;

		case	EditToolbar::ETID_UP:
		{
			// Valid node?
			LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel());
			if ( pCNode != ( LPCNODE )LB_ERR )
			{
				// Get it's predecessor.
				LPCNODE pCPrev = pCNode->lpPrev;

				// Swap both data entries.
				CNODE cTemp;
				cTemp.nType	  = pCPrev->nType;
				cTemp.uCommand	  = pCPrev->uCommand;
				pCPrev->nType	  = pCNode->nType;
				pCPrev->uCommand  = pCNode->uCommand;
				pCNode->nType	  = cTemp.nType;
				pCNode->uCommand  = cTemp.uCommand;

				// Select the previous item which
				// in fact is the already selected
				// item.
				m_Commands.SetCurSel( m_Commands.GetCurSel() - 1 );
				SetupControls();
				pSettings->Changed( m_pParser );
				return 0;
			}
		}

		case	EditToolbar::ETID_DOWN:
		{
			// Valid node?
			LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel());
			if ( pCNode != ( LPCNODE )LB_ERR )
			{
				// Get it's successor.
				LPCNODE pCNext = pCNode->lpNext;
				
				// Swap both data entries.
				CNODE cTemp;
				cTemp.nType	  = pCNext->nType;
				cTemp.uCommand	  = pCNext->uCommand;
				pCNext->nType	  = pCNode->nType;
				pCNext->uCommand  = pCNode->uCommand;
				pCNode->nType	  = cTemp.nType;
				pCNode->uCommand  = cTemp.uCommand;

				// Select the next item which
				// in fact is the already selected
				// item.
				m_Commands.SetCurSel( m_Commands.GetCurSel() + 1 );
				SetupControls();
				pSettings->Changed( m_pParser );
				return 0;
			}
		}

		case	IDS_INSERT:
			CreateNode( CTYPE_TEXT, ( LPVOID )( LPCTSTR )ClsString( MAKEINTRESOURCE( IDS_NEWINSERT )));
			return 0;

		case	IDS_HARDCODED:
			CreateNode( CTYPE_HARDCODED, ( LPVOID )( ::GetCommandTable()->nCommandID ));
			return 0;

		case	IDS_RUN:
			CreateNode( CTYPE_RUN, ( LPVOID )( _T( "Calc.exe" )));
			return 0;

		case	IDS_OPEN:
			CreateNode( CTYPE_SHELLOPEN, ( LPVOID )( _T( "ReadMe.txt" )));
			return 0;

		case	IDC_KEYS:
			if ( nNotifyCode == LBN_SELCHANGE )
			{
				// Get the current selection.
				LPHASH pSel = GetSelection();
				if ( pSel )
				{
					// Clear the contents of the command list.
					m_Commands.ResetContent();

					// Add commands.
					LPCNODE pNode;
					for ( pNode = pSel->lpCommands->lpFirst; pNode->lpNext; pNode = pNode->lpNext )
						m_Commands.AddString(( LPCTSTR )pNode );
				}
			}
			// Setup controls.
			SetupControls();
			return 0;

		case	IDC_COMMANDS:
			// Double-click?
			if ( nNotifyCode == LBN_DBLCLK )
			{
				// Find the command node.
				LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel());
				if ( pCNode != ( LPCNODE )LB_ERR )
				{
					// What's the type?
					switch ( pCNode->nType )
					{
						case	CTYPE_HARDCODED:
						{
							// Open the editor.
							Hardcoded h;
							if ( h.Select( *GetParent(), pCNode ))
							{
								// Refresh list.
								m_Commands.Invalidate();
								pSettings->Changed( m_pParser );
							}
							break;
						}

						case	CTYPE_TEXT:
						{
							// Open the editor.
							TextInsert ti;
							HICON hIcon = ImageList_GetIcon( m_hImages, 1, ILD_NORMAL );
							if ( ti.Edit( *GetParent(), pCNode, hIcon ))
							{
								// Refresh list.
								m_Commands.Invalidate();
								pSettings->Changed( m_pParser );
							}
							if ( hIcon ) ::DestroyIcon( hIcon );
							return 0;
						}
						
						case	CTYPE_RUN:
						case	CTYPE_SHELLOPEN:
						{
							// Open the editor.
							Run r;
							if ( r.Edit( *GetParent(), pCNode ))
							{
								// Refresh list.
								m_Commands.Invalidate();
								pSettings->Changed( m_pParser );
							}
						}
					}
				}
			}
			else
				// Setup GUI.
				SetupControls();
			return 0;
	}
	// Pass to the base class.
	return Page::OnCommand( nNotifyCode, nCtrlID, hWndCtrl );
}
Пример #12
0
void wxTextCtrl::OnChar(wxKeyEvent& event)
{
    int key = event.GetKeyCode() ;
    bool eat_key = false ;
    long from, to;

    if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
        !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
//        && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
        )
    {
        // eat it
        return ;
    }

    // Check if we have reached the max # of chars (if it is set), but still
    // allow navigation and deletion
    GetSelection( &from, &to );
    if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength &&
        !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) &&
        !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) &&
        from == to )
    {
        // eat it, we don't want to add more than allowed # of characters

        // TODO: generate EVT_TEXT_MAXLEN()
        return;
    }

    // assume that any key not processed yet is going to modify the control
    m_dirty = true;

    switch ( key )
    {
        case WXK_RETURN:
            if (m_windowStyle & wxTE_PROCESS_ENTER)
            {
                wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
                event.SetEventObject( this );
                event.SetString( GetValue() );
                if ( HandleWindowEvent(event) )
                    return;
            }

            if ( !(m_windowStyle & wxTE_MULTILINE) )
            {
                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
                if ( tlw && tlw->GetDefaultItem() )
                {
                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                    if ( def && def->IsEnabled() )
                    {
                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
                        event.SetEventObject(def);
                        def->Command(event);

                        return ;
                    }
                }

                // this will make wxWidgets eat the ENTER key so that
                // we actually prevent line wrapping in a single line text control
                eat_key = true;
            }
            break;

        case WXK_TAB:
            if ( !(m_windowStyle & wxTE_PROCESS_TAB))
            {
                int flags = 0;
                if (!event.ShiftDown())
                    flags |= wxNavigationKeyEvent::IsForward ;
                if (event.ControlDown())
                    flags |= wxNavigationKeyEvent::WinChange ;
                Navigate(flags);

                return;
            }
            else
            {
                // This is necessary (don't know why);
                // otherwise the tab will not be inserted.
                WriteText(wxT("\t"));
                eat_key = true;
            }
            break;

        default:
            break;
    }

    if (!eat_key)
    {
        // perform keystroke handling
        event.Skip(true) ;
    }

    // osx_cocoa sends its event upon insertText
#if wxOSX_USE_CARBON
    if ( ( key >= 0x20 && key < WXK_START ) ||
         ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) ||
         key == WXK_RETURN ||
         key == WXK_DELETE ||
         key == WXK_BACK)
    {
        wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
        event1.SetEventObject( this );
        wxPostEvent( GetEventHandler(), event1 );
    }
#endif
}
Пример #13
0
int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y)
{
	static int startSelection = -1;
	int textWidth;
	string displayValue, originalValue;
	void* fontResource = NULL;

	if (mFont)  fontResource = mFont->GetResource();

	if (!isConditionTrue())
		return -1;

	if (!HasInputFocus) {
		if (state != TOUCH_RELEASE)
			return 0; // Only change focus if touch releases within the input box
		if (GetSelection(x, y) >= 0) {
			// When changing focus, we don't scroll or change the cursor location
			PageManager::SetKeyBoardFocus(0);
			PageManager::NotifyKeyboard(0);
			SetInputFocus(1);
			DrawCursor = true;
			mRendered = false;
		}
	} else {
		switch (state) {
		case TOUCH_HOLD:
		case TOUCH_REPEAT:
			break;
		case TOUCH_START:
			startSelection = GetSelection(x,y);
			lastX = x;
			DrawCursor = false;
			mRendered = false;
			break;

		case TOUCH_DRAG:
			// Check if we dragged out of the selection window
			if (GetSelection(x, y) == -1) {
				lastX = 0;
				break;
			}

			DrawCursor = false;

			// Provide some debounce on initial touches
			if (startSelection != -1 && abs(x - lastX) < 6) {
				break;
			}

			startSelection = -1;
			if (lastX != x)
				HandleTextLocation(x);
			break;

		case TOUCH_RELEASE:
			// We've moved the cursor location
			int relativeX = x - mRenderX;

			mRendered = false;
			DrawCursor = true;
			DataManager::GetValue(mVariable, displayValue);
			if (HasMask) {
				int index, string_size = displayValue.size();
				string maskedValue;
				for (index=0; index<string_size; index++)
					maskedValue += mMask;
				displayValue = maskedValue;
			}
			if (displayValue.size() == 0) {
				skipChars = 0;
				mCursorLocation = -1;
				return 0;
			} else if (skipChars && skipChars < displayValue.size()) {
				displayValue.erase(0, skipChars);
			}

			string cursorString;
			int cursorX = 0;
			unsigned index = 0;

			for(index=0; index<displayValue.size(); index++)
			{
				cursorString = displayValue.substr(0, index);
				cursorX = gr_measureEx(cursorString.c_str(), fontResource) + mRenderX;
				if (cursorX > x) {
					if (index > 0)
						mCursorLocation = index - 1;
					else
						mCursorLocation = index;
					return 0;
				}
			}
			mCursorLocation = -1;
			break;
		}
	}
	return 0;
}
int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y)
{
	static int lastY = 0, last2Y = 0;
	int selection = 0;

	switch (state)
	{
	case TOUCH_START:
		if (scrollingSpeed != 0)
			startSelection = -1;
		else
			startSelection = GetSelection(x,y);
		isHighlighted = (startSelection > -1);
		if (isHighlighted)
			mUpdate = 1;
		startY = lastY = last2Y = y;
		scrollingSpeed = 0;
		break;

	case TOUCH_DRAG:
		// Check if we dragged out of the selection window
		if (GetSelection(x, y) == -1) {
			last2Y = lastY = 0;
			if (isHighlighted) {
				isHighlighted = false;
				mUpdate = 1;
			}
			break;
		}

		// Fast scroll
		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
		{
			int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH);
			int totalSize = mList.size();
			int lines = (mRenderH - mHeaderH) / (actualLineHeight);

			float l = float((totalSize-lines)*pct)/100;
			if(l + lines >= totalSize)
			{
				mStart = totalSize - lines;
				scrollingY = 0;
			}
			else
			{
				mStart = l;
				scrollingY = -(l - int(l))*actualLineHeight;
			}

			startSelection = -1;
			mUpdate = 1;
			scrollingSpeed = 0;
			isHighlighted = false;
			break;
		}

		// Provide some debounce on initial touches
		if (startSelection != -1 && abs(y - startY) < touchDebounce) {
			isHighlighted = true;
			mUpdate = 1;
			break;
		}

		isHighlighted = false;
		last2Y = lastY;
		lastY = y;	
		startSelection = -1;

		// Handle scrolling
		scrollingY += y - startY;
		startY = y;
		while(mStart && scrollingY > 0) {
			mStart--;
			scrollingY -= actualLineHeight;
		}
		if (mStart == 0 && scrollingY > 0)
			scrollingY = 0;
		{
			int totalSize = mList.size();
			int lines = (mRenderH - mHeaderH) / (actualLineHeight);

			if (totalSize > lines) {
				int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight);

				bottom_offset -= actualLineHeight;

				while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) {
					mStart++;
					scrollingY += actualLineHeight;
				}
				if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) {
					mStart = totalSize - lines - 1;
					scrollingY = bottom_offset;
				} else if (mStart + lines >= totalSize && scrollingY < 0) {
					mStart = totalSize - lines;
					scrollingY = 0;
				}
			} else
				scrollingY = 0;
		}
		mUpdate = 1;
		break;

	case TOUCH_RELEASE:
		isHighlighted = false;
		if (startSelection >= 0)
		{
			// We've selected an item!
			std::string str;

			int listSize = mList.size();
			int selectY = scrollingY, actualSelection = mStart;

			// Move the selection to the proper place in the array
			while (selectY + actualLineHeight < startSelection) {
				selectY += actualLineHeight;
				actualSelection++;
			}

			if (actualSelection < listSize && !mVariable.empty())
			{
				int i;
				for (i=0; i<listSize; i++)
					mList.at(i).selected = 0;

				str = mList.at(actualSelection).variableValue;
				mList.at(actualSelection).selected = 1;
				DataManager::SetValue(mVariable, str);
				mUpdate = 1;
			}
		} else {
			// This is for kinetic scrolling
			scrollingSpeed = lastY - last2Y;
			if (abs(scrollingSpeed) > SCROLLING_FLOOR)
				scrollingSpeed *= SCROLLING_MULTIPLIER;
			else
				scrollingSpeed = 0;
		}
	case TOUCH_REPEAT:
	case TOUCH_HOLD:
		break;
	}
	return 0;
}
Пример #15
0
 bool LayerChanged() { return GetSelection() != 0; }
Пример #16
0
void WrappingTextView::KeyDown(const char *bytes, int32 numBytes) 
{ 
	if (IsEditable() && numBytes==1) {
		m_last_key_was_del = (bytes[0]==B_DELETE);
		switch( bytes[0]) {
			case B_RIGHT_ARROW: {
				// implement word-wise movement:
				int32 mods = Window()->CurrentMessage()->FindInt32("modifiers");
				if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) {
					int32 len=TextLength();
					int32 startPos, endPos;
					GetSelection( &startPos, &endPos);
					if (endPos==len)
						break;
					if (startPos==endPos && (mods & B_SHIFT_KEY))
						m_selection_start=B_RIGHT_ARROW;
					int32 wordStart, wordEnd;
					if (mods & B_SHIFT_KEY && m_selection_start==B_LEFT_ARROW) {
						do {
							FindWord( startPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( ++startPos < len);
						Select( MIN(endPos, wordEnd), endPos);
					} else {
						do {
							FindWord( endPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( ++endPos < len);
						if (mods & B_SHIFT_KEY) {
							Select( startPos, wordEnd);
						} else
							Select( wordEnd, wordEnd);
					}
					ScrollToSelection();
				} else
					inherited::KeyDown( bytes, numBytes);
				break;
			}
			case B_LEFT_ARROW: {
				// implement word-wise movement:
				int32 mods = Window()->CurrentMessage()->FindInt32("modifiers");
				if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) {
					int32 startPos, endPos;
					GetSelection( &startPos, &endPos);
					if (!startPos)
						break;
					if (startPos==endPos && (mods & B_SHIFT_KEY))
						m_selection_start=B_LEFT_ARROW;
					int32 wordStart, wordEnd;
					if (mods & B_SHIFT_KEY && m_selection_start==B_RIGHT_ARROW) {
						--endPos;
						do {
							FindWord( endPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( --endPos > 0);
						Select( startPos, MAX( startPos, wordStart));
					} else {
						--startPos;
						do {
							FindWord( startPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( --startPos > 0);
						if (mods & B_SHIFT_KEY)
							Select( wordStart, endPos);
						else
							Select( wordStart, wordStart);
					}
					ScrollToSelection();
				} else
					inherited::KeyDown( bytes, numBytes);
				break;
			}
			default:
				inherited::KeyDown( bytes, numBytes);
				break;
		}
	} else if ( numBytes == 1 ) {
		// in read-only mode, we use cursor-keys to move scrollbar, and
		// we remap HOME / END to the vertical scrollbar (not the horizontal,
		// which is default).
		switch( bytes[0]) {
			case B_PAGE_UP:
			case B_PAGE_DOWN:
			case B_UP_ARROW:
			case B_DOWN_ARROW:
			case B_HOME: 
			case B_END: {
				// move vertical scrollbar:
				float min, max, smallStep, bigStep, value;
				BScrollBar* bar = ScrollBar( B_VERTICAL);
				if (!bar) 	return;
				bar->GetRange( &min, &max);
				bar->GetSteps( &smallStep, &bigStep);
				value = bar->Value();
				if (bytes[0] == B_UP_ARROW) {
					value = MAX( value-smallStep, min);
				} else if (bytes[0] == B_DOWN_ARROW) {
					value = MIN( value+smallStep, max);
				} else if (bytes[0] == B_PAGE_UP) {
					value = MAX( value-bigStep, min);
				} else if (bytes[0] == B_PAGE_DOWN) {
					value = MIN( value+bigStep, max);
				} else if (bytes[0] == B_HOME) {
					value = min;
				} else if (bytes[0] == B_END) {
					value = max;
				}
				bar->SetValue( value);
				break;
			}
			default:
				BTextView::KeyDown( bytes, numBytes);
				break;
		}
	} else
		inherited::KeyDown( bytes, numBytes);
}
Пример #17
0
bool CppSymbolTree::ActivateSelectedItem()
{
    wxTreeItemId item = GetSelection();
    wxTreeEvent dummy;
    return DoItemActivated(item, dummy, true);
}
Пример #18
0
void InfoPane::OnClear(wxCommandEvent& event)
{
    int i = GetPageIndexByWindow(GetPage(GetSelection()));
    if (page[i].islogger)
        page[i].logger->Clear();
}
Пример #19
0
void
BComboBox::TextInput::KeyDown(const char *bytes, int32 numBytes)
{
	BComboBox* cb;
	uchar aKey = bytes[0];

	switch (aKey) {
		case B_RETURN:
			cb = dynamic_cast<BComboBox*>(Parent());
			ASSERT(cb);

			if (!cb->IsEnabled())
				break;

			ASSERT(fInitialText);
			if (strcmp(fInitialText, Text()) != 0)
				cb->CommitValue();
			free(fInitialText);
			fInitialText = strdup(Text());
			{
				int32 end = TextLength();
				Select(end, end);
			}
			// hide popup window if it's showing when the user presses the
			// enter key
			if (cb->fPopupWindow && cb->fPopupWindow->Lock()) {
				if (!cb->fPopupWindow->IsHidden()) {
					cb->HidePopupWindow();
				}
				cb->fPopupWindow->Unlock();
			}
			break;
		case B_TAB:
//			cb = dynamic_cast<BComboBox*>Parent());
//			ASSERT(cb);
//			if (cb->fAutoComplete && cb->fCompletionIndex >= 0) {	
//				int32 from, to;
//				cb->fText->GetSelection(&from, &to);
//				if (from == to) {
//					// HACK: this should never happen.  The rest of the class
//					// should be fixed so that fCompletionIndex is set to -1 if the
//					// text is modified
//					printf("BComboBox::TextInput::KeyDown() -- HACK! this shouldn't happen!");
//					cb->fCompletionIndex = -1;
//				}
//				
//				const char *text = cb->fText->Text();
//				BString prefix;
//				prefix.Append(text, from);
//				
//				int32 match;
//				const char *completion;
//				if (cb->fChoiceList->GetMatch(	prefix.String(),
//											  	cb->fCompletionIndex + 1,
//												&match,
//												&completion) == B_OK)
//				{
//					cb->fText->Delete(); 			// delete the selection
//					cb->fText->Insert(completion);
//					cb->fText->Select(from, from + strlen(completion));
//					cb->fCompletionIndex = match;
//					cb->Select(cb->fCompletionIndex);
//				} else {
//					//system_beep();
//				}	
//			} else {
				BView::KeyDown(bytes, numBytes);
//			}
			break;
#if 0
		case B_UP_ARROW:		// fall through
		case B_DOWN_ARROW:
			cb = dynamic_cast<BComboBox*>(Parent());
			ASSERT(cb);
			if (cb->fChoiceList) {
				cb = dynamic_cast<BComboBox*>(Parent());
				ASSERT(cb);
				if (!(cb->fPopupWindow)) {
					cb->fPopupWindow = cb->CreatePopupWindow();
				}
				if (cb->fPopupWindow->Lock()) {
					// show popup window, if needed
					if (cb->fPopupWindow->IsHidden()) {
						cb->ShowPopupWindow();
					} else {
						printf("Whoa!!! Erroneously got up/down arrow key down in TextInput::KeyDown()!\n");
					}
					int32 index = cb->CurrentSelection();
					int32 choices = cb->fChoiceList->CountChoices();
					// select something, if no selection
					if (index < 0 && choices > 0) {
						if (aKey == B_UP_ARROW) {
							cb->Select(choices - 1);
						} else {
							cb->Select(0);
						}
					}
					cb->fPopupWindow->Unlock();
				}
			}
			break;
#endif
		case B_ESCAPE:
			cb = dynamic_cast<BComboBox*>(Parent());
			ASSERT(cb);
			if (cb->fChoiceList)
			{
				cb = dynamic_cast<BComboBox*>(Parent());
				ASSERT(cb);
				if (cb->fPopupWindow && cb->fPopupWindow->Lock())
				{
					if (!cb->fPopupWindow->IsHidden())
						cb->HidePopupWindow();

					cb->fPopupWindow->Unlock();
				}
			}
			break;
		case ',':
			{
				int32 startSel, endSel;
				GetSelection(&startSel, &endSel);
				int32 length = TextLength();
				if (endSel == length)
					Select(endSel, endSel);
				BTextView::KeyDown(bytes, numBytes);
			}
			break;
		default:
			BTextView::KeyDown(bytes, numBytes);
			break;
	}
}
Пример #20
0
void CDirstatDoc::OnRefreshselected()
{
    // FIXME: Multi-select
    RefreshItem(GetSelection(0));
}
WIDGET_HOTKEY_CLIENT_DATA* WIDGET_HOTKEY_LIST::GetSelHKClientData()
{
    return GetHKClientData( GetSelection() );
}
Пример #22
0
void CDirstatDoc::OnUpdateTreemapSelectparent(CCmdUI *pCmdUI)
{
    // FIXME: Multi-select
    pCmdUI->Enable(GetSelection(0) != NULL && GetSelection(0)->GetParent() != NULL);
}
Пример #23
0
bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
{
    bool handled = false;
    // we have a native implementation for Win32 and so don't need this one
#ifndef __WIN32__
    wxChar ch = 0;
    int keycode = event.GetKeyCode();

    long from, to;
    GetSelection(&from,&to);
    long insert = GetInsertionPoint();
    long last = GetLastPosition();

    // catch arrow left and right

    switch ( keycode )
    {
        case WXK_LEFT:
            if ( event.ShiftDown() )
                SetSelection( (from > 0 ? from - 1 : 0) , to );
            else
            {
                if ( from != to )
                    insert = from;
                else if ( insert > 0 )
                    insert -= 1;
                SetInsertionPoint( insert );
            }
            handled = true;
            break;
        case WXK_RIGHT:
            if ( event.ShiftDown() )
                SetSelection( from, (to < last ? to + 1 : last) );
            else
            {
                if ( from != to )
                    insert = to;
                else if ( insert < last )
                    insert += 1;
                SetInsertionPoint( insert );
            }
            handled = true;
            break;
        case WXK_NUMPAD0:
        case WXK_NUMPAD1:
        case WXK_NUMPAD2:
        case WXK_NUMPAD3:
        case WXK_NUMPAD4:
        case WXK_NUMPAD5:
        case WXK_NUMPAD6:
        case WXK_NUMPAD7:
        case WXK_NUMPAD8:
        case WXK_NUMPAD9:
            ch = (wxChar)(wxT('0') + keycode - WXK_NUMPAD0);
            break;

        case WXK_MULTIPLY:
        case WXK_NUMPAD_MULTIPLY:
            ch = wxT('*');
            break;

        case WXK_ADD:
        case WXK_NUMPAD_ADD:
            ch = wxT('+');
            break;

        case WXK_SUBTRACT:
        case WXK_NUMPAD_SUBTRACT:
            ch = wxT('-');
            break;

        case WXK_DECIMAL:
        case WXK_NUMPAD_DECIMAL:
            ch = wxT('.');
            break;

        case WXK_DIVIDE:
        case WXK_NUMPAD_DIVIDE:
            ch = wxT('/');
            break;

        case WXK_DELETE:
        case WXK_NUMPAD_DELETE:
            // delete the character at cursor
            {
                const long pos = GetInsertionPoint();
                if ( pos < GetLastPosition() )
                    Remove(pos, pos + 1);
                handled = true;
            }
            break;

        case WXK_BACK:
            // delete the character before the cursor
            {
                const long pos = GetInsertionPoint();
                if ( pos > 0 )
                    Remove(pos - 1, pos);
                handled = true;
            }
            break;

        default:
#if wxUSE_UNICODE
            if ( event.GetUnicodeKey() )
            {
                ch = event.GetUnicodeKey();
            }
            else
#endif
            if ( keycode < 256 && keycode >= 0 && wxIsprint(keycode) )
            {
                // FIXME this is not going to work for non letters...
                if ( !event.ShiftDown() )
                {
                    keycode = wxTolower(keycode);
                }

                ch = (wxChar)keycode;
            }
            else
            {
                ch = wxT('\0');
            }
    }

    if ( ch )
    {
        WriteText(ch);

        handled = true;
    }
#else // __WIN32__
    wxUnusedVar(event);
#endif // !__WIN32__/__WIN32__

    return handled;
}
Пример #24
0
void CDirstatDoc::OnRefreshselected()
{
	RefreshItem(GetSelection());
}
Пример #25
0
int wxPageContainer::HitTest(const wxPoint& pt, wxPageInfo& pageInfo, int &tabIdx)
{
	wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() );
	
	wxRect rect = GetClientRect();
	int btnLeftPos = render->GetLeftButtonPos(this);
	int btnRightPos = render->GetRightButtonPos(this);
	int btnXPos =render->GetXPos(this);
	long style = GetParent()->GetWindowStyleFlag();

	tabIdx = -1;
	if(m_pagesInfoVec.IsEmpty())
	{
		return wxFNB_NOWHERE;
	}

	rect = wxRect(btnXPos, 8, 16, 16);
	if(rect.Contains(pt))
	{
		return (style & wxFNB_NO_X_BUTTON) ? wxFNB_NOWHERE : wxFNB_X;
	}

	rect = wxRect(btnRightPos, 8, 16, 16);
	if( style & wxFNB_DROPDOWN_TABS_LIST )
	{
		rect = wxRect(render->GetDropArrowButtonPos( this ), 8, 16, 16);
		if( rect.Contains(pt) )
			return wxFNB_DROP_DOWN_ARROW;
	}

	if(rect.Contains(pt))
	{
		return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_RIGHT_ARROW;
	}


	rect = wxRect(btnLeftPos, 8, 16, 16);
	if(rect.Contains(pt))
	{
		return (style & wxFNB_NO_NAV_BUTTONS) ? wxFNB_NOWHERE : wxFNB_LEFT_ARROW;
	}

	// Test whether a left click was made on a tab
	bool bFoundMatch = false;
	for(size_t cur=m_nFrom; cur<m_pagesInfoVec.GetCount(); cur++)
	{
		wxPageInfo pgInfo = m_pagesInfoVec[cur];
		if(pgInfo.GetPosition() == wxPoint(-1, -1))
			continue;

		// check for mouse over tab's x button
		if(style & wxFNB_X_ON_TAB && (int)cur == GetSelection())
		{
			// 'x' button exists on a tab
			if(m_pagesInfoVec[cur].GetXRect().Contains(pt))
			{
				pageInfo = pgInfo;
				tabIdx = (int)cur;
				return wxFNB_TAB_X;
			}
		}

		if(style & wxFNB_VC8)
		{
			if(m_pagesInfoVec[cur].GetRegion().Contains(pt) == wxInRegion)
			{
				if(bFoundMatch || (int)cur == GetSelection())
				{
					pageInfo = pgInfo;
					tabIdx = (int)cur;
					return wxFNB_TAB;
				}
				pageInfo = pgInfo;
				tabIdx = (int)cur;
				bFoundMatch = true;
			}
		}
		else
		{

			wxRect tabRect = wxRect(pgInfo.GetPosition().x, pgInfo.GetPosition().y, 
				pgInfo.GetSize().x, pgInfo.GetSize().y);
			if(tabRect.Contains(pt))
			{
				// We have a match
				pageInfo = pgInfo;
				tabIdx = (int)cur;
				return wxFNB_TAB;
			}
		}
	}

	if(bFoundMatch)
		return wxFNB_TAB;

	// Default
	return wxFNB_NOWHERE;
}
Пример #26
0
void CDirstatDoc::OnUpdateTreemapSelectparent(CCmdUI *pCmdUI)
{
	pCmdUI->Enable(GetSelection() != NULL && GetSelection()->GetParent() != NULL);
}
Пример #27
0
void               P3DPlantModelTreeCtrl::OnItemRightClick
                                      (wxTreeEvent        &event)
 {
  P3DBranchModel                      *BranchModel;
  P3DMaterialInstanceSimple           *MaterialSimple;

  if (event.GetItem() != GetSelection())
   {
    SelectItem(event.GetItem());
   }

  BranchModel = ((P3DPlantModelTreeCtrlItemData*)(GetItemData(GetSelection())))->GetBranchModel();

  wxMenu                               PopupMenu;
  wxMenu                              *StemModelMenu;
  wxMenu                              *AppendBranchMenu;

  P3DStemModel *StemModel = BranchModel->GetStemModel();

  if (StemModel == 0)
   {
   }
  else
   {
    StemModelMenu = new wxMenu();
    StemModelMenu->Append(P3D_SET_STEM_MODEL_TUBE_ID,wxT("Tube"));
    StemModelMenu->Append(P3D_SET_STEM_MODEL_QUAD_ID,wxT("Quad"));
    StemModelMenu->Append(P3D_SET_STEM_MODEL_WINGS_ID,wxT("Wings"));

    if      (dynamic_cast<P3DStemModelTube*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_TUBE_ID,false);
     }
    else if (dynamic_cast<P3DStemModelQuad*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_QUAD_ID,false);
     }
    else if (dynamic_cast<P3DStemModelWings*>(StemModel) != 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
     }

    const P3DPluginInfoVector &GMeshPlugins = P3DApp::GetApp()->GetGMeshPlugins();

    if (GMeshPlugins.size() > 0)
     {
      wxMenu      *GMeshPluginsMenu = new wxMenu();
      int          MenuItemId = wxID_GMESH_PLUGIN_FIRST;

      for (unsigned int Index = 0; Index < GMeshPlugins.size(); Index++)
       {
        GMeshPluginsMenu->Append(MenuItemId++,wxString(GMeshPlugins[Index].GetMenuName(),wxConvUTF8));
       }

      StemModelMenu->Append(P3D_SET_STEM_MODEL_GMESH_ID,wxT("G-Mesh"),GMeshPluginsMenu);
     }
    else
     {
      StemModelMenu->Append(P3D_SET_STEM_MODEL_GMESH_ID,wxT("G-Mesh"));
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_GMESH_ID,false);
     }

    if (BranchModel->GetSubBranchCount() > 0)
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_QUAD_ID,false);
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_GMESH_ID,false);
     }

    if (GetItemParent(GetSelection()) == GetRootItem())
     {
      StemModelMenu->Enable(P3D_SET_STEM_MODEL_WINGS_ID,false);
     }
   }

  MaterialSimple = dynamic_cast<P3DMaterialInstanceSimple*>(BranchModel->GetMaterialInstance());

  AppendBranchMenu = new wxMenu();
  AppendBranchMenu->Append(PLANT_TREE_APPEND_BRANCH_NEW_ID,wxT("New branch"));
  AppendBranchMenu->Append(PLANT_TREE_APPEND_BRANCH_COPY_ID,wxT("Copy branch..."));

  PopupMenu.Append(PLANT_TREE_APPEND_BRANCH_ID,wxT("Append branch"),AppendBranchMenu);
  PopupMenu.Append(PLANT_TREE_REMOVE_STEM_ID,wxT("Delete stem"));

  if (GetItemParent(GetSelection()).IsOk())
   {
    PopupMenu.AppendSeparator();
    PopupMenu.Append(P3D_SET_STEM_MODEL_ID,wxT("Stem model"),StemModelMenu);

    wxMenuItem *DummyModeMenuItem = PopupMenu.AppendCheckItem(P3D_SET_STEM_DUMMY_MODE,wxT("Dummy"));

    DummyModeMenuItem->Check(BranchModel->IsDummy());

    PopupMenu.AppendSeparator();

    if (!BranchModel->IsDummy())
     {
      if (MaterialSimple->IsHidden())
       {
        PopupMenu.Append(PLANT_TREE_HIDESHOW_STEM_ID,wxT("Show"));
       }
      else
       {
        PopupMenu.Append(PLANT_TREE_HIDESHOW_STEM_ID,wxT("Hide"));
       }
     }
   }

  PopupMenu.Append(PLANT_TREE_RENAME_STEM_ID,wxT("Rename..."));

  if (GetRootItem() == GetSelection())
   {
    PopupMenu.Enable(PLANT_TREE_REMOVE_STEM_ID,false);
   }

  if (BranchModel->GetSubBranchCount() < P3DBranchModelSubBranchMaxCount)
   {
   }
  else
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }

  if      (dynamic_cast<P3DStemModelQuad*>(StemModel) != 0)
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }
  else if (dynamic_cast<P3DStemModelWings*>(StemModel) != 0)
   {
    PopupMenu.Enable(PLANT_TREE_APPEND_BRANCH_ID,false);
   }

  this->PopupMenu(&PopupMenu,event.GetPoint());
 }
Пример #28
0
 int GetLayer() { return GetSelection() - 1; }
Пример #29
0
int wxSTEditorNotebook::FindString(const wxString &str, STE_TextPos start_pos,
                                   int flags, int action)
{
    int n_pages = (int)GetPageCount();
    int n_sel = GetSelection();
    int n = -1;
    STE_TextPos pos = start_pos;
    bool forward = STE_HASBIT(flags, wxFR_DOWN) != 0;
    int noteb_flags = flags & (~STE_FR_WRAPAROUND); // switch to new page

    wxSTEditor *editor = NULL;
    if (n_sel < 0) return wxNOT_FOUND; // oops

    // search this page and later or before to end
    for (n = n_sel;
         forward ? n < n_pages : n >= 0;
         n = forward ? n+1 : n-1)
    {
        editor = GetEditor(n);
        if (!editor)
            continue;

        if (n != n_sel)
            pos = forward ? 0 : editor->GetLength();

        pos = editor->FindString(str, pos, -1, noteb_flags, action);

        if (pos != wxNOT_FOUND)
        {
            SetSelection(n);
            editor->UpdateCanDo(true); // make sure CanFind is updated
            return pos;
        }
    }

    // search through remaining pages
    for (n = forward ? 0 : n_pages-1;
         forward ? n < n_sel : n > n_sel;
         n = forward ? n+1 : n-1)
    {
        editor = GetEditor(n);
        if (!editor)
            continue;

        pos = forward ? 0 : editor->GetLength();

        pos = editor->FindString(str, pos, -1, noteb_flags, action);

        if (pos != wxNOT_FOUND)
        {
            SetSelection(n);
            editor->UpdateCanDo(true); // make sure CanFind is updated
            return pos;
        }
    }

    // if we haven't found the string then try to wrap around on this doc.
    editor = GetEditor(n_sel);
    if ((editor != NULL) && STE_HASBIT(flags, STE_FR_WRAPAROUND))
    {
        pos = editor->FindString(str, start_pos, -1, flags, action);
        editor->UpdateCanDo(true); // make sure CanFind is updated
        return pos;
    }

    return wxNOT_FOUND;
}
Пример #30
0
void wxCheckListBox::OnKeyDown(wxKeyEvent& event)
{
    // what do we do?
    enum
    {
        NONE,
        TOGGLE,
        SET,
        CLEAR
    } oper;

    switch ( event.GetKeyCode() )
    {
        case WXK_SPACE:
            oper = TOGGLE;
            break;

        case WXK_NUMPAD_ADD:
        case '+':
            oper = SET;
            break;

        case WXK_NUMPAD_SUBTRACT:
        case '-':
            oper = CLEAR;
            break;

        default:
            oper = NONE;
    }

    if ( oper != NONE )
    {
        wxArrayInt selections;
        int count = 0;
        if ( HasMultipleSelection() )
        {
            count = GetSelections(selections);
        }
        else
        {
            int sel = GetSelection();
            if (sel != -1)
            {
                count = 1;
                selections.Add(sel);
            }
        }

        for ( int i = 0; i < count; i++ )
        {
            int nItem = selections[i];

            switch ( oper )
            {
                case TOGGLE:
                    Toggle(nItem);
                    break;

                case SET:
                case CLEAR:
                    Check(nItem, oper == SET);
                    break;

                default:
                    wxFAIL_MSG( wxT("what should this key do?") );
            }

            // we should send an event as this has been done by the user and
            // not by the program
            SendEvent(nItem);
        }
    }
    else // nothing to do
    {
        event.Skip();
    }
}