How to iterate menu items in the menu?



In my GUI I have a sub-menu Zoom with a list of most used numbers (200%, 100%, 75%, 50%, etc) and a special item "Custom..." which opens a separate dialog window.
I also have an external function:

extern int zoom;
extern GtkWidget *miZoom200, *miZoom100, *miZoom50, .... etc
void setZoom(int newZoom) {
  zoom = newZoom;
  switch (zoom) {
    case 200:
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(miZoom200), TRUE);
      break;
    case 100:
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(miZoom100), TRUE);
      break;
    case 50:
      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(miZoom50), TRUE);
      break;
    /// etc
    default:
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(miZoomCustom), TRUE);
   }
}
This works fine, but I do need to keep pointers to each individual menu item.

Is there a way to iterate items of the menu and do something like this:
void setZoom(int newZoom, GtkMenu *mZoom) {
  gchar zoomText[8];
  g_sprintf(zoomText, "%d%%", newZoom);
  for each item in mZoom {/// ???
    if(g_strcmp0 ( gtk_menu_item_get_label(item), zoomText) ==0 ) {
      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), TRUE);
      return;
    }
  }
  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(miZoomCustom), TRUE);
}

I am using GTK3, (answers for GTK2 would also be welcomed)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]