Exemplo n.º 1
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());
}
Exemplo n.º 2
0
/// Function name  : closeAllDocuments
// Description     : Attempts to close/save all open documents
// 
// CONST BOOL  bExcludeActiveDocument : [in] Whether to leave the active document open 
// 
BOOL   closeAllDocuments(HWND  hTabCtrl, CONST BOOL  bExcludeActive)
{
   DOCUMENTS_DATA*    pWindowData;     // Documents data
   DOCUMENT*          pDocument;       // Document list iterator
   UINT               iDocumentCount;  // Document count

   // [TRACK]
   CONSOLE_COMMAND_BOLD();

   // Prepare  
   pWindowData = getDocumentsControlData(hTabCtrl);

   // [CHECK] Ensure there are documents to close
   if (iDocumentCount = getDocumentCount())
   {
      // Iterate through all open documents
      for (INT  iIndex = (iDocumentCount - 1); findDocumentByIndex(hTabCtrl, iIndex, pDocument); iIndex--)
      {
         // [CHECK] Skip the active document, if appropriate
         if (bExcludeActive AND pDocument == getActiveDocument())
            continue;
         
         /// [CHECK] Attempt to save or discard document
         if (!closeDocumentByIndex(hTabCtrl, iIndex))
            // [CANCELLED] Abort 
            break;
      }
   }

   // Recalculate document count
   iDocumentCount = getDocumentCount();

   // [CLOSING] Have all documents been closed?
   if (isAppClosing() AND !iDocumentCount)
      /// [EVENT] Fire UM_MAIN_WINDOW_CLOSING with state MWS_DOCUMENTS_CLOSED
      postAppClose(MWS_DOCUMENTS_CLOSED);

   // Return TRUE if all documents were closed
   return (iDocumentCount == 0);
}
Exemplo n.º 3
0
/// Function name  : onDocumentsControl_ContextMenu
// Description     : Displays the tab context menu and implements it's commands
// 
// DOCUMENTS_DATA*  pWindowData  : [in] Documents data
// CONST POINT*     ptClick      : [in] Cursor position (in screen co-ordinates)
// 
BOOL  onDocumentsControl_ContextMenu(DOCUMENTS_DATA*  pWindowData, CONST POINT*  ptClick)
{
   TCHITTESTINFO  oHitTest;            // Document tab HitTest
   CUSTOM_MENU*   pCustomMenu;         // Custom menu
   DOCUMENT*      pDocument;           // Document that was clicked, if any
   INT            iDocumentIndex;      // Index of the document that was clicked

   // Prepare
   oHitTest.pt    = *ptClick;
   oHitTest.flags = TCHT_ONITEM;

   /// [CHECK] Has the user clicked a tab heading?
   ScreenToClient(pWindowData->hTabCtrl, &oHitTest.pt);
   iDocumentIndex = TabCtrl_HitTest(pWindowData->hTabCtrl, &oHitTest);

   // Lookup document (Will fails if user did not click a tab heading)
   if (findDocumentByIndex(pWindowData->hTabCtrl, iDocumentIndex, pDocument))
   {
      CONSOLE_ACTION();

      // Generate custom menu
      pCustomMenu = createCustomMenu(TEXT("DIALOG_MENU"), TRUE, IDM_DOCUMENT_POPUP);

      /// Enable/Disable menu items
      EnableMenuItem(pCustomMenu->hPopup, IDM_FILE_SAVE,                    isModified(pDocument) ? MF_ENABLED : MF_DISABLED);
      EnableMenuItem(pCustomMenu->hPopup, IDM_WINDOW_CLOSE_OTHER_DOCUMENTS, getDocumentCount() > 1 ? MF_ENABLED : MF_DISABLED);

      // Enable/Disable project items
      EnableMenuItem(pCustomMenu->hPopup, IDM_DOCUMENT_ADD_PROJECT,    getActiveProject() AND !isDocumentInProject(pDocument) ? MF_ENABLED : MF_DISABLED);
      EnableMenuItem(pCustomMenu->hPopup, IDM_DOCUMENT_REMOVE_PROJECT, getActiveProject() AND isDocumentInProject(pDocument)  ? MF_ENABLED : MF_DISABLED);

      /// Display context menu and return choice immediately
      switch (TrackPopupMenu(pCustomMenu->hPopup, TPM_RETURNCMD WITH TPM_TOPALIGN WITH TPM_LEFTALIGN, ptClick->x, ptClick->y, NULL, pWindowData->hTabCtrl, NULL))
      {
      // [SAVE/CLOSE/CLOSE-OTHER] Perform relevant command
      case IDM_FILE_SAVE:                     commandSaveDocument(getMainWindowData(), pDocument, FALSE, NULL);  break;
      case IDM_FILE_CLOSE:                    closeDocumentByIndex(pWindowData->hTabCtrl, iDocumentIndex);       break;
      case IDM_WINDOW_CLOSE_OTHER_DOCUMENTS:  closeAllDocuments(pWindowData->hTabCtrl, TRUE);                    break;

      // [ADD/REMOVE PROJECT] TODO
      case IDM_DOCUMENT_ADD_PROJECT:          addDocumentToProject(pDocument);         break;
      case IDM_DOCUMENT_REMOVE_PROJECT:       removeDocumentFromProject(pDocument);    break;
         break;
      }

      // Cleanup
      deleteCustomMenu(pCustomMenu);
   }
   
   // Return TRUE if handled, otherwise FALSE
   return (iDocumentIndex != -1);
}
Exemplo n.º 4
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...
   }

}
Exemplo n.º 5
0
daeDocument* daeSTLDatabase::getDocument(daeString name)
{
	// Normalize the input string to an absolute URI with no fragment

	daeURI tempURI(name, true);
	daeString targetURI = tempURI.getURI();

	// Try to find a document that matches

	daeDocument *document;
	int documentCount	= getDocumentCount();
	for (int i=0;i<documentCount;i++)
	{
		document = getDocument(i);
		if(strcmp(document->getDocumentURI()->getURI(), targetURI)==0)
			return(document);
	}
	return(NULL);
}
Exemplo n.º 6
0
/// Function name  : displayNextDocument
// Description     : Switches to the next document
// 
// HWND        hTabCtrl : [in] Document control handle
// CONST UINT  iIndex   : [in] Zero based index of the document to display
// 
VOID  displayNextDocument(HWND  hTabCtrl)
{
   UINT   iDocumentCount,
          iNextIndex;

   // Prepare
   iDocumentCount = getDocumentCount();

   // [CHECK]
   if (iDocumentCount > 1)
   {
      // Prepare
      iNextIndex = TabCtrl_GetCurSel(hTabCtrl) + 1;
      
      // [LAST DOCUMENT] Display first document
      if (iNextIndex >= iDocumentCount)
         iNextIndex = 0;

      // Display next document
      displayDocumentByIndex(hTabCtrl, iNextIndex);
   }

}
Datum ts_rank_idf(PG_FUNCTION_ARGS)
{
    char **documentTokenList, **queryTokenList;
    char *document, *query;
    int documentWords, queryWords;
    int i, j;
    long documentCount;
    float score;

    document = text_to_cstring(PG_GETARG_TEXT_P(0));
    query = text_to_cstring(PG_GETARG_TEXT_P(1));

    documentWords = tokenize(document, &documentTokenList);
    queryWords = tokenize(query, &queryTokenList);

    documentCount = getDocumentCount();
    score = 0.0;
    for(i = 0; i < queryWords; i++)
    {
        for(j = 0; j < documentWords; j++)
        {
            if(!strcmp(queryTokenList[i], documentTokenList[j]))
			    score += log((float) documentCount / getTokenFrequency(queryTokenList[i]));
        }
    }

    pfree(document);
    pfree(query);
    for(i = 0; i < queryWords; i++)
        pfree(queryTokenList[i]);
    for(i = 0; i < documentWords; i++)
        pfree(documentTokenList[i]);
    pfree(queryTokenList);
    pfree(documentTokenList);

    PG_RETURN_FLOAT4(score);
}