OSStatus
MySimpleNotificationCallback(ControlRef browser, DataBrowserItemID item, DataBrowserItemNotification message)
{
    UInt32 numItems;
    Rect browserBounds;
    SInt16 height;
    OSStatus err = noErr;
        
    switch (message)
    {	
        case kDataBrowserItemAdded:
            if (item <= kMaxNeighborhoods)
            {
                gNeighborhoodInfo.isNeighborhoodVisible[item - 1] = true;
            }
            break;
        case kDataBrowserItemRemoved:
            if (item <= kMaxNeighborhoods)
            {
                gNeighborhoodInfo.isNeighborhoodVisible[item - 1] = false;
            }
            break;
        case kDataBrowserContainerOpened:
            gNeighborhoodInfo.isNeighborhoodOpen[item - 1] = true;
            DoNeighborhoodLookup(item);
            DoServicesLookup(item);
            break;
        case kDataBrowserContainerClosing:
            gNeighborhoodInfo.isNeighborhoodOpen[item - 1] = false;
            CancelServicesLookup(item);
            CancelNeighborhoodLookup(item);
            break;
        case kDataBrowserContainerClosed:
            RemoveServicesFromNeighborhood(item, false);
            if (gNeighborhoodInfo.isDefaultNeighborhood[item - 1] == true)
            {
                SetDataBrowserScrollPosition(gDataBrowserControl, 0 , 0);
            }
            else
            {
                err = GetDataBrowserItemCount(gDataBrowserControl, 0, true, kDataBrowserItemAnyState, &numItems);
                if (err == noErr)
                {
                    GetControlBounds(gDataBrowserControl, &browserBounds);
                    height = browserBounds.bottom - browserBounds.top;
                    if (numItems < (height/kDataBrowserRowHeight)) SetDataBrowserScrollPosition(gDataBrowserControl, 0 , 0);
                }
            }
            break;
        case kDataBrowserItemSelected:
            gSelectedItem = item;
            break;
        case kDataBrowserItemDeselected:
            if (gSelectedItem == item) gSelectedItem = kDataBrowserNoItem;
            break;
    }
    
    return noErr;
}
Exemple #2
0
void
OPL_LoginDialog::loadFDSNList(char *dsn_path)
{
    char *path_buf;
    DIR *dir;
    struct dirent *dir_entry;
    struct stat fstat;

    fdsnlist->clear();
    if ((dir = opendir(dsn_path)))
    {
        while (dir_entry = readdir(dir))
        {
            asprintf (&path_buf, "%s/%s", dsn_path, dir_entry->d_name);

            if (stat ((LPCSTR) path_buf, &fstat) >= 0 && S_ISDIR (fstat.st_mode))
            {
                if (dir_entry->d_name && dir_entry->d_name[0] != '.')
                {
                    fdsnlist->addItem(OPL_char_to_CFString((char *) dir_entry->d_name), 1);
                }
            }
            else if (stat ((LPCSTR) path_buf, &fstat) >= 0 && !S_ISDIR (fstat.st_mode)
                     && strstr (dir_entry->d_name, ".dsn"))
            {
                fdsnlist->addItem(OPL_char_to_CFString((char *) dir_entry->d_name), 0);
            }

            if (path_buf)
                free (path_buf);
        }
        /* Close the directory entry */
        closedir (dir);
    }

    SetDataBrowserScrollPosition(fdsnView, 0, 0);

    //fill dir menu
    fill_dir_menu(dsn_path);
}
Exemple #3
0
OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
{
    return SetDataBrowserScrollPosition( m_controlRef , top , left );
}
Exemple #4
0
void
addfdsns_to_list (TDSNCHOOSER *dsnchoose_t, char *path, Boolean b_reset)
{
  DataBrowserItemID item = DBITEM_ID + 1;
  DataBrowserCallbacks dbCallbacks;
  ThemeDrawingState outState = NULL;
  UInt16 colSize[3] = { 400, 100, 150 };
  SInt16 outBaseline;
  Point ioBound;
  int i;
  DIR *dir;
  char *path_buf;
  struct dirent *dir_entry;
  struct stat fstat;
  int b_added;
  ControlRef widget;
  WindowRef dlg;

  if (!dsnchoose_t || !path)
    return; 

  widget = dsnchoose_t->fdsnlist;
  dlg = dsnchoose_t->mainwnd;

  GetThemeDrawingState (&outState);

  /* Install an event handler on the component databrowser */
  dbCallbacks.version = kDataBrowserLatestCallbacks;
  InitDataBrowserCallbacks (&dbCallbacks);
  dbCallbacks.u.v1.itemNotificationCallback =
      NewDataBrowserItemNotificationUPP (fdsn_notification_item);
  /* On Mac OS X 10.0.x : clientDataCallback */
  dbCallbacks.u.v1.itemDataCallback =
      NewDataBrowserItemDataUPP (fdsn_getset_item);
  SetDataBrowserCallbacks (widget, &dbCallbacks);
  /* Begin the draw of the data browser */
  SetDataBrowserTarget (widget, DBITEM_ID);

  /* Make the clean up */
  for (i = 0; i < FDSN_nrows; i++, item++)
    {
      CFRelease (FDSN_array[i]);
      FDSN_array[i] = NULL;
      FDSN_type[i] = 0;
      RemoveDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID);
    }

  ActivateControl (widget);
  DrawOneControl (widget);

  /* Global Initialization */
  FDSN_nrows = 0;
  item = DBITEM_ID + 1;

  if ((dir = opendir (path)))
    {
      while ((dir_entry = readdir (dir)) && FDSN_nrows < MAX_ROWS)
	{
	  asprintf (&path_buf, "%s/%s", path, dir_entry->d_name);
	  b_added = 0;

	  if (stat ((LPCSTR) path_buf, &fstat) >= 0 && S_ISDIR (fstat.st_mode))
	    {
	      if (dir_entry->d_name && dir_entry->d_name[0] != '.') 
	        {
                  FDSN_array[FDSN_nrows] = CFStringCreateWithCString(NULL, dir_entry->d_name, kCFStringEncodingUTF8);
                  FDSN_type[FDSN_nrows] = 0;
                  b_added = 1;
	        }
	    }
	  else if (stat ((LPCSTR) path_buf, &fstat) >= 0 && !S_ISDIR (fstat.st_mode)
	           && strstr (dir_entry->d_name, ".dsn"))
	    {
              FDSN_array[FDSN_nrows] = CFStringCreateWithCString(NULL, dir_entry->d_name, kCFStringEncodingUTF8);
              FDSN_type[FDSN_nrows] = 1;
              b_added = 1;
	    }

	  if (path_buf)
	    free (path_buf);

	  if (b_added)
	    {
              GetThemeTextDimensions (FDSN_array[FDSN_nrows], kThemeSystemFont,
                kThemeStateActive, false, &ioBound, &outBaseline);
              if(colSize[0] < ioBound.h) colSize[0] = ioBound.h;

              AddDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID);
              item++;
              FDSN_nrows++;
            }
	}

      /* Close the directory entry */
      closedir (dir);
    }
  else
    create_error (NULL, NULL, "Error during accessing directory information",
	strerror (errno));

  ActivateControl (widget);
  /* Resize the columns to have a good look */
  SetDataBrowserTableViewNamedColumnWidth (widget, DBNAME_ID, colSize[0] + 20);
  DrawOneControl (widget);
  /* Remove the DataBrowser callback */
  SetDataBrowserCallbacks (NULL, &dbCallbacks);
  if(outState) DisposeThemeDrawingState (outState);

  if (b_reset)
    SetDataBrowserScrollPosition(widget, 0, 0);

  fill_dir_menu(dsnchoose_t, path);
}