Example #1
0
/*
 * Print menu item
 */
static void
print_item(WINDOW *win,
           const char **items,
           int choice, int selected)
{
    int i;

    /* Clear 'residue' of last item */
    wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < menu_width; i++)
        (void) waddch(win, ' ');

    (void) wmove(win, choice, tag_x);
    wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
    (void) waddch(win, CharOf(ItemName(0)[0]));
    wattrset(win, selected ? tag_selected_attr : tag_attr);
    (void) wprintw(win, "%.*s", item_x - tag_x - 2, ItemName(0) + 1);

    (void) wmove(win, choice, item_x);
    wattrset(win, selected ? item_selected_attr : item_attr);
    (void) wprintw(win, "%.*s", getmaxx(win) - item_x, ItemText(0));

    if (selected) {
        dlg_item_help(ItemHelp(0));
    }
}
/*
 * Print the tag of a menu-item
 */
static void
print_tag(WINDOW *win,
	  char **items,
	  int choice, int selected)
{
    int my_x = item_x;
    int my_y = ItemToRow(choice);
    int tag_width = (my_x - tag_x - GUTTER);
    const int *cols;
    const int *indx;
    int limit;
    unsigned prefix;

    cols = dlg_index_columns(ItemName(0));
    indx = dlg_index_wchars(ItemName(0));
    limit = dlg_count_wchars(ItemName(0));
    prefix = indx[1] - indx[0];

    /* highlight first char of the tag to be special */
    (void) wmove(win, my_y, tag_x);
    wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
    if (strlen(ItemName(0)) != 0)
	(void) waddnstr(win, ItemName(0), prefix);
    /* print rest of the string */
    wattrset(win, selected ? tag_selected_attr : tag_attr);
    if (strlen(ItemName(0)) > prefix) {
	limit = dlg_limit_columns(ItemName(0), tag_width, 1);
	if (limit > 0)
	    (void) waddnstr(win, ItemName(0) + indx[1], indx[limit] - indx[1]);
    }
}
bool SharedMenuBuffer::InsertMenu(UINT id, LPCTSTR text, BOOL check)
{
   //Create a view of the file if none yet
   if (m_hViewPtr == NULL)
   {
      m_hViewPtr = MapViewOfFile(m_hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
      m_pBuffer = (char*)m_hViewPtr;
   }

   if (m_hViewPtr == NULL)
      return false;

   //TODO: Check if there is enough space in buffer

   //Insert the data in the buffer
   ItemType(m_pBuffer) = (char)(check ? MENUITEM_CHECKED : MENUITEM_UNCHECKED);
   ItemId(m_pBuffer) = id;
   _tcscpy(ItemName(m_pBuffer), text ? text : TEXT(""));

   //Move the insertion pointer
   m_pBuffer += ItemLength(m_pBuffer);
   ItemType(m_pBuffer) = MENUITEM_NONE;

   return true;
}
QVariant SceneTreeItem::data(int role) const
{
	QVariant v;

	switch(role)
	{
	case Qt::DecorationRole:
		v = ItemIcon();
		break;
	case Qt::DisplayRole:
		v = ItemName();
		break;
	case EIDR_Type:
		v = ItemType();
		break;
	case EIDR_Data:
		v = ItemData();
		break;
    case Qt::BackgroundColorRole:
        v = ItemBackgroundColor();
        break;
	default:
		break;
	}

	if(v.isNull())
	{
		v = QStandardItem::data(role);
	}

	return v;
}
bool SharedMenuBuffer::ReadMenu(HMENU hMenu, UINT (*filter)(UINT))
{
   LPVOID viewPtr = MapViewOfFile(m_hFileMapping, FILE_MAP_READ, 0, 0, 0);
   char * buffer = (char*)viewPtr;
   bool result = true;

   if (viewPtr == NULL)
      return false;

   //Build the menu from the data in the buffer
   while(ItemType(buffer) != MENUITEM_NONE)
   {
      MENUITEMINFO menuitem;

      menuitem.cbSize = sizeof(MENUITEMINFO);
      menuitem.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING;
      menuitem.fType = (ItemId(buffer) == 0) ? MFT_SEPARATOR : MFT_STRING;
      menuitem.wID = filter(ItemId(buffer));
      menuitem.fState = (ItemType(buffer) == MENUITEM_CHECKED) ? MFS_CHECKED : MFS_UNCHECKED;
      menuitem.dwTypeData = ItemName(buffer);

      if (!InsertMenuItem(hMenu, (UINT)-1, TRUE, &menuitem))
      {
         result = false;
         break;
      }

      buffer += ItemLength(buffer);
   }

   UnmapViewOfFile(viewPtr);

   return result;
}
Example #6
0
// reads overview if you're being attacked
bool CSpeedKernel::ReadOverview(const genstring& s, int FleetID)
{
	genstring::size_type f, f2;
	vector<SItem> items;
	items.resize(T_END);
    size_t i, t;
	for(t = 0; t < T_END; t++)
	{
		items[t].Type = (ITEM_TYPE)t;
		items[t].Num = 0;
	}

	genstring tmp, pos, name, anz, name2;

	f = s.find(m_Ovr[0]);
	if(f == genstring::npos)
		return false;
	f += m_Ovr[0].length();
	f2 = s.find(m_Ovr[1], f) + 1;
    if(f2-1 == genstring::npos)
        return false;
	tmp = s.substr(f, f2 - f);
    // extract planet position
    f = tmp.find(_T("["));
    m_Result.Position = PlaniPos(tmp.substr(f+1));
	// planet name including coords
    tmp = tmp.substr(0, f) + _T(" ") + tmp.substr(f);
    _tcscpy(m_Result.PlaniName, tmp.c_str());
	tmp = s;

	for(i = 0; i < T_END; i++)
	{
		name = ItemName((ITEM_TYPE)i);
        name2 = ItemName2((ITEM_TYPE)i);
		f = tmp.find(name.c_str(), 0);
        if(f == genstring::npos && name2 != _T("")) {
                f = tmp.find(name2.c_str(), 0);
        }
		if(f != genstring::npos)
		{
			int p = f;
			while(s[p] != _T(',') && s[p] != _T('('))
				p--;
            if(p < 0)
                continue;
			anz = s.substr(p + 2, f - p - 1);
			items[i].Num = _ttoi(anz.c_str());
		}
	}
    for(i = 0; i < items.size(); i++) {
        items[i].OwnerID = FleetID;
    }
	SetFleet(&items, NULL);
	m_NumShipsAtt = items;

	return true;
}
/*
 * Print list item
 */
static void
print_item(WINDOW *win, char **items, int status,
	   int choice, int selected)
{
    int i;
    chtype attr = A_NORMAL;
    const int *indx;
    int limit;

    /* Clear 'residue' of last item */
    wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < list_width; i++)
	(void) waddch(win, ' ');

    (void) wmove(win, choice, check_x);
    wattrset(win, selected ? check_selected_attr : check_attr);
    (void) wprintw(win,
		   (checkflag == FLAG_CHECK) ? "[%c]" : "(%c)",
		   status ? 'X' : ' ');
    wattrset(win, menubox_attr);
    (void) waddch(win, ' ');

    if (strlen(ItemName(0)) != 0) {

	indx = dlg_index_wchars(ItemName(0));
	limit = dlg_count_wchars(ItemName(0));

	wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
	(void) waddnstr(win, ItemName(0), indx[1]);

	if ((int) strlen(ItemName(0)) > indx[1]) {
	    limit = dlg_limit_columns(ItemName(0), (item_x - check_x - 6), 1);
	    if (limit > 1) {
		wattrset(win, selected ? tag_selected_attr : tag_attr);
		(void) waddnstr(win,
				ItemName(0) + indx[1],
				indx[limit] - indx[1]);
	    }
	}
    }

    if (strlen(ItemText(0)) != 0) {
	indx = dlg_index_wchars(ItemText(0));
	limit = dlg_limit_columns(ItemText(0), (getmaxx(win) - item_x - 1), 0);

	if (limit > 0) {
	    (void) wmove(win, choice, item_x);
	    wattrset(win, selected ? item_selected_attr : item_attr);
	    dlg_print_text(win, ItemText(0), indx[limit], &attr);
	}
    }

    if (selected) {
	dlg_item_help(ItemHelp(0));
    }
}
static int
handle_button(int code, char **items, int choice)
{
    switch (code) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	dlg_add_result(ItemName(choice));
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	if (USE_ITEM_HELP(ItemHelp(choice))) {
	    dlg_add_result(ItemHelp(choice));
	    code = DLG_EXIT_OK;	/* this is inconsistent */
	} else {
	    dlg_add_result(ItemName(choice));
	}
	break;
    }
    return code;
}
Example #9
0
TBool CAppMain::GetAccessPoint(){
  TBuf<100> CommDBName;
  TUint32 default_iap_ID(0);
  TUint32 will_set_iap_id(0);
  TBuf<100> ItemName(_L("wap"));
  const TUint8 str[]={
  0xfb,0x79,0xa8,0x52,0xa6,0x68,0x51,0x7F,0
  };
  TPtrC ptrYDMW=TPtrC((TUint16*)str,4);
  //创建手机IAP数据库对象
  CCommsDatabase* commsDatabase=CCommsDatabase::NewL(EDatabaseTypeIAP);
  CleanupStack::PushL(commsDatabase);
  
  //打开IAP接入点表
  CCommsDbTableView* tableIAP=commsDatabase->OpenTableLC(TPtrC(IAP));
  if(tableIAP->GotoFirstRecord()==KErrNone){
    do{
      //循环获取IAP接入点,如有移动梦网接入点则对will_set_iap_id赋值
      tableIAP->ReadUintL(TPtrC(COMMDB_ID),default_iap_ID);
      tableIAP->ReadTextL(TPtrC(COMMDB_NAME),CommDBName);
      //iCoeEnv->ReadResource(ItemName, LOC_BUF_ACCESS_POINT_DEFAULT);
      if(CommDBName.FindF(ItemName)>=0||CommDBName.FindF(ptrYDMW)>=0){
        will_set_iap_id=default_iap_ID;
        break;
      }
    }while(tableIAP->GotoNextRecord()==KErrNone);
  }
  //delete tableIAP;
  CleanupStack::PopAndDestroy(tableIAP);
  CleanupStack::PopAndDestroy(commsDatabase);
  
  //将获取的移动梦网接入点做为缺省访问接入点
  if(will_set_iap_id>0){
    iDefaultAccessPointID=will_set_iap_id;
    Log(_L8("cmwap IAP"));
    //    TBuf8<12> buf;
    //    buf.AppendNum((TInt)will_set_iap_id);
    //    Log(buf);
    return ETrue;
  }else{
    //假如没有找到“移动梦网”接入点,则提示用户在手机中设置此接入点
    Log(_L8("no cmwap"));
    return EFalse;
  }
}
Example #10
0
BOOL FontDropDown::FillInFontList()
{
	ERROR2IF(ParentDlg == NULL, FALSE, "FontDropDown not properly initialised");
	TRACEUSER("wuerthne", _T("FillInFontList"));

	SetListRedraw(FALSE);										// Disable redraw while updating
	ClearList();												// Delete combobox contents

	// Setup the static class pointer variable so we can add things to this dropdown...
	CurrentFontDropDown = (void *)this;

	if(Fonts.GetCount() == 0)
	{
		TRACEUSER("wuerthne", _T("FontDropDown enumerating fonts"));
		FontDropEnumFont EnumObj;
		EnumObj.Execute();

		// Loop through the list, checking for ATM / TTF duplicates, and remove the TTF ones from the list
		FontDropItem *Item = (FontDropItem *)Fonts.GetHead();
		while (Item != NULL)
		{
			FontClass ItemType = Item->Type;
			if(ItemType == FC_ATM)
			{
				// It's an ATM font, go through whole list checking for TTF equiv.
				BOOL Removed = FALSE;
				String_64 ItemName(Item->FontName);
				FontDropItem *InnerLoopItem = (FontDropItem *)Fonts.GetHead();
				while (InnerLoopItem != NULL && Removed == FALSE)
				{
					// Have we found our font ? Remove it if we have...
					if((InnerLoopItem->Type == FC_TRUETYPE) && (InnerLoopItem->FontName == ItemName))
					{
						Fonts.RemoveItem((ListItem *)InnerLoopItem);
						delete InnerLoopItem;
						InnerLoopItem = NULL;
						Removed = TRUE;
					}

					// Get the next item
					if(!Removed)
						InnerLoopItem = (FontDropItem *)Fonts.GetNext((ListItem *)InnerLoopItem);
				}
			}
			// Get the next item
			Item = (FontDropItem *)Fonts.GetNext((ListItem *)Item);
		}
	}

	ListItem *Item = Fonts.GetHead();

	while (Item != NULL)
	{
		// Add the font in the list to the combo box
		AddItem((void *) Item);

		// Try the next item
		Item = Fonts.GetNext(Item);
	}

	SetListRedraw(TRUE);									// Re-enable redraw

	return(TRUE);
}
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title, const char *cprompt, int height, int width,
		 int list_height, int item_no, char **items, int flag,
		 int separate_output)
{
    int i, j, key2, found, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0, fkey;
    int button = 0;
    int choice = 0;
    int scrollamt = 0;
    int max_choice, *status;
    int use_width, name_width, text_width;
    int result = DLG_EXIT_UNKNOWN;
    WINDOW *dialog, *list;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (list_height == 0) {
	use_width = calc_listw(item_no, items, CHECKBOX_TAGS) + 10;
	/* calculate height without items (4) */
	auto_size(title, prompt, &height, &width, 4, MAX(26, use_width));
	calc_listh(&height, &list_height, item_no);
    } else {
	auto_size(title, prompt, &height, &width, 4 + list_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    checkflag = flag;

    /* Allocate space for storing item on/off status */
    status = malloc(sizeof(int) * item_no);
    assert_ptr(status, "dialog_checklist");

    /* Initializes status */
    for (i = 0; i < item_no; i++)
	status[i] = !dlg_strcmp(ItemStatus(i), "on");

    max_choice = MIN(list_height, item_no);

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    list_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - list_width) / 2 - 1;

    /* create new window for the list */
    list = sub_window(dialog, list_height, list_width,
		      y + box_y + 1, x + box_x + 1);

    /* draw a box around the list items */
    draw_box(dialog, box_y, box_x,
	     list_height + 2 * MARGIN,
	     list_width + 2 * MARGIN,
	     menubox_border_attr, menubox_attr);

    text_width = 0;
    name_width = 0;
    /* Find length of longest item to center checklist */
    for (i = 0; i < item_no; i++) {
	text_width = MAX(text_width, (int) strlen(ItemText(i)));
	name_width = MAX(name_width, (int) strlen(ItemName(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (list_width - 6);
    if (text_width + name_width > use_width) {
	int need = 0.25 * use_width;
	if (name_width > need) {
	    int want = use_width * ((double) name_width) / (text_width + name_width);
	    name_width = (want > need) ? want : need;
	}
	text_width = use_width - name_width;
    }

    check_x = (use_width - (text_width + name_width)) / 2;
    item_x = name_width + check_x + 6;

    /* Print the list */
    for (i = 0; i < max_choice; i++)
	print_item(list,
		   ItemData(i),
		   status[i], i, i == choice);
    (void) wnoutrefresh(list);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y + 1, box_x, list_height, list_width + 2,
		      KEY_MAX, 1, 1, 1 /* by lines */ );

    dlg_draw_arrows(dialog, scrollamt,
		    scrollamt + max_choice < item_no - 1,
		    box_x + check_x + 5,
		    box_y,
		    box_y + list_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, 0, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (result == DLG_EXIT_UNKNOWN) {
	key = mouse_wgetch(dialog, &fkey);

	if (fkey && (key >= (M_EVENT + KEY_MAX))) {
	    getyx(dialog, cur_y, cur_x);
	    /* De-highlight current item */
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, FALSE);
	    /* Highlight new item */
	    choice = (key - (M_EVENT + KEY_MAX));
	    print_item(list,
		       ItemData(scrollamt + choice),
		       status[scrollamt + choice], choice, TRUE);
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);

	    key = ' ';		/* force the selected item to toggle */
	    fkey = FALSE;
	}

	/*
	 * A space toggles the item status.  We handle either a checklist
	 * (any number of items can be selected) or radio list (zero or one
	 * items can be selected).
	 */
	if (key == ' ') {
	    getyx(dialog, cur_y, cur_x);
	    if (flag == FLAG_CHECK) {	/* checklist? */
		status[scrollamt + choice] = !status[scrollamt + choice];
		print_item(list,
			   ItemData(scrollamt + choice),
			   status[scrollamt + choice], choice, TRUE);
	    } else {		/* radiolist */
		if (!status[scrollamt + choice]) {
		    for (i = 0; i < item_no; i++)
			status[i] = FALSE;
		    status[scrollamt + choice] = TRUE;
		    for (i = 0; i < max_choice; i++)
			print_item(list,
				   ItemData(scrollamt + i),
				   status[scrollamt + i], i, i == choice);
		}
	    }
	    (void) wnoutrefresh(list);
	    (void) wmove(dialog, cur_y, cur_x);
	    wrefresh(dialog);
	    continue;		/* wait for another key press */
	} else if (key == ESC) {
	    result = DLG_EXIT_ESC;
	    continue;
	}

	if (!fkey) {
	    fkey = TRUE;
	    switch (key) {
	    case '\n':
	    case '\r':
		key = KEY_ENTER;
		break;
	    case '-':
		key = KEY_UP;
		break;
	    case '+':
		key = KEY_DOWN;
		break;
	    case TAB:
		key = KEY_RIGHT;
		break;
	    default:
		fkey = FALSE;
		break;
	    }
	}

	/*
	 * Check if key pressed matches first character of any item tag in
	 * list.  If there is more than one match, we will cycle through
	 * each one as the same key is pressed repeatedly.
	 */
	found = FALSE;
	if (!fkey) {
	    for (j = scrollamt + choice + 1; j < item_no; j++) {
		if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
		    found = TRUE;
		    i = j - scrollamt;
		    break;
		}
	    }
	    if (!found) {
		for (j = 0; j <= scrollamt + choice; j++) {
		    if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
			found = TRUE;
			i = j - scrollamt;
			break;
		    }
		}
	    }
	    if (found)
		dlg_flush_getc();
	}

	/*
	 * A single digit (1-9) positions the selection to that line in the
	 * current screen.
	 */
	if (!found
	    && (key <= '9')
	    && (key > '0')
	    && (key - '1' < max_choice)) {
	    found = TRUE;
	    i = key - '1';
	}

	if (!found) {
	    if (fkey) {
		found = TRUE;
		switch (key) {
		case KEY_HOME:
		    i = -scrollamt;
		    break;
		case KEY_LL:
		case KEY_END:
		    i = item_no - 1 - scrollamt;
		    break;
		case M_EVENT + KEY_PPAGE:
		case KEY_PPAGE:
		    if (choice)
			i = 0;
		    else if (scrollamt != 0)
			i = -MIN(scrollamt, max_choice);
		    else
			continue;
		    break;
		case M_EVENT + KEY_NPAGE:
		case KEY_NPAGE:
		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
		    break;
		case KEY_UP:
		    i = choice - 1;
		    if (choice == 0 && scrollamt == 0)
			continue;
		    break;
		case KEY_DOWN:
		    i = choice + 1;
		    if (scrollamt + choice >= item_no - 1)
			continue;
		    break;
		default:
		    found = FALSE;
		    break;
		}
	    }
	}

	if (found) {
	    if (i != choice) {
		getyx(dialog, cur_y, cur_x);
		if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
		    /*
		     * Using wscrl to assist ncurses scrolling is not needed
		     * in version 5.x
		     */
		    if (i == -1) {
			if (list_height > 1) {
			    /* De-highlight current first item */
			    print_item(list,
				       ItemData(scrollamt),
				       status[scrollamt], 0, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, -1);
			    scrollok(list, FALSE);
			}
			scrollamt--;
			print_item(list,
				   ItemData(scrollamt),
				   status[scrollamt], 0, TRUE);
		    } else if (i == max_choice) {
			if (list_height > 1) {
			    /* De-highlight current last item before scrolling up */
			    print_item(list,
				       ItemData(scrollamt + max_choice - 1),
				       status[scrollamt + max_choice - 1],
				       max_choice - 1, FALSE);
			    scrollok(list, TRUE);
			    wscrl(list, 1);
			    scrollok(list, FALSE);
			}
			scrollamt++;
			print_item(list,
				   ItemData(scrollamt + max_choice - 1),
				   status[scrollamt + max_choice - 1],
				   max_choice - 1, TRUE);
		    } else
#endif
		    {
			if (i < 0) {
			    scrollamt += i;
			    choice = 0;
			} else {
			    choice = max_choice - 1;
			    scrollamt += (i - max_choice + 1);
			}
			for (i = 0; i < max_choice; i++) {
			    print_item(list,
				       ItemData(scrollamt + i),
				       status[scrollamt + i], i, i == choice);
			}
		    }
		    (void) wnoutrefresh(list);
		    dlg_draw_arrows(dialog, scrollamt,
				    scrollamt + choice < item_no - 1,
				    box_x + check_x + 5,
				    box_y,
				    box_y + list_height + 1);
		} else {
		    /* De-highlight current item */
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, FALSE);
		    /* Highlight new item */
		    choice = i;
		    print_item(list,
			       ItemData(scrollamt + choice),
			       status[scrollamt + choice], choice, TRUE);
		    (void) wnoutrefresh(list);
		    (void) wmove(dialog, cur_y, cur_x);
		    wrefresh(dialog);
		}
	    }
	    continue;		/* wait for another key press */
	}

	if (fkey) {
	    switch (key) {
	    case KEY_ENTER:
		result = dlg_ok_buttoncode(button);
		break;
	    case KEY_BTAB:
	    case KEY_LEFT:
		button = dlg_prev_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_RIGHT:
		button = dlg_next_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    default:
		if (key >= M_EVENT) {
		    if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) {
			result = key2;
			break;
		    }
		    beep();
		}
	    }
	} else {
	    beep();
	}
    }

    del_window(dialog);
    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	for (i = 0; i < item_no; i++) {
	    if (status[i]) {
		if (flag == FLAG_CHECK) {
		    if (separate_output) {
			dlg_add_result(ItemName(i));
			dlg_add_result("\n");
		    } else {
			dlg_add_result("\"");
			dlg_add_result(ItemName(i));
			dlg_add_result("\" ");
		    }
		} else {
		    dlg_add_result(ItemName(i));
		}
	    }
	}
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	if (USE_ITEM_HELP(ItemHelp(scrollamt + choice))) {
	    dlg_add_result(ItemHelp(scrollamt + choice));
	    result = DLG_EXIT_OK;	/* this is inconsistent */
	} else {
	    dlg_add_result(ItemName(scrollamt + choice));
	}
	break;
    }
    mouse_free_regions();
    free(status);
    free(prompt);
    return result;
}
Example #12
0
int
dialog_mixedform(const char *title,
                 const char *cprompt,
                 int height,
                 int width,
                 int form_height,
                 int item_no,
                 char **items)
{
    int result;
    int choice;
    int i;
    DIALOG_FORMITEM *listitems;
    DIALOG_VARS save_vars;
    bool show_status = FALSE;

    dlg_save_vars(&save_vars);
    dialog_vars.separate_output = TRUE;

    listitems = dlg_calloc(DIALOG_FORMITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_mixedform");

    for (i = 0; i < item_no; ++i) {
        listitems[i].type = dialog_vars.formitem_type;
        listitems[i].name = ItemName(i);
        listitems[i].name_len = (int) strlen(ItemName(i));
        listitems[i].name_y = dlg_ordinate(ItemNameY(i));
        listitems[i].name_x = dlg_ordinate(ItemNameX(i));
        listitems[i].text = ItemText(i);
        listitems[i].text_len = (int) strlen(ItemText(i));
        listitems[i].text_y = dlg_ordinate(ItemTextY(i));
        listitems[i].text_x = dlg_ordinate(ItemTextX(i));
        listitems[i].text_flen = atoi(ItemTextFLen(i));
        listitems[i].text_ilen = atoi(ItemTextILen(i));
        listitems[i].help = (dialog_vars.item_help ? ItemHelp(i) :
                             dlg_strempty());
        listitems[i].type = (unsigned) atoi(ItemTypep(i));
    }

    result = dlg_form(title,
                      cprompt,
                      height,
                      width,
                      form_height,
                      item_no,
                      listitems,
                      &choice);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
        show_status = TRUE;
        break;
    case DLG_EXIT_HELP:
        dlg_add_result("HELP ");
        show_status = dialog_vars.help_status;
        if (USE_ITEM_HELP(listitems[choice].help)) {
            dlg_add_string(listitems[choice].help);
            result = DLG_EXIT_ITEM_HELP;
        } else {
            dlg_add_string(listitems[choice].name);
        }
        if (show_status)
            dlg_add_separator();
        break;
    }
    if (show_status) {
        for (i = 0; i < item_no; i++) {
            if (listitems[i].text_flen > 0) {
                dlg_add_string(listitems[i].text);
                dlg_add_separator();
            }
        }
        dlg_add_last_key(-1);
    }

    dlg_free_formitems(listitems);
    dlg_restore_vars(&save_vars);

    return result;
}
Example #13
0
/******************************************************************************
  ProcessMessage - Process the message coming from Fvwm
    Skeleton based on processmessage() from FvwmIdent:
      Copyright 1994, Robert Nation and Nobutaka Suzuki.
******************************************************************************/
void ProcessMessage(unsigned long type,unsigned long *body)
{
  int redraw=0,i;
  long flags;
  char *name,*string;
  static current_focus=-1;

  Picture p;

  switch(type)
  {
    case M_ADD_WINDOW:
    case M_CONFIGURE_WINDOW:
      if (body[0] == win)
      {
        win_x=(int)body[3];
        win_y=(int)body[4];

        win_title=(int)body[9];
        win_border=(int)body[10];
      }
      if ((i = FindItem(&windows,body[0]))!=-1) 
      { 
/*	printf("does it go here on MOVE %ld, %ld ?\n", i, CurrentDesk);
*/
	if(UpdateItemDesk(&windows, i, body[7]) > 0)
        {
/*         printf("why doesnt it go here on MOVE ?\n");
*/
          AdjustWindow();
          RedrawWindow(1);
        }
	break;
      }

      if (!(body[8]&WINDOWLISTSKIP) || !UseSkipList)
        AddItem(&windows,body[0],body[8], body[7] /* desk */);
      break;
    case M_DESTROY_WINDOW:
      if ((i=DeleteItem(&windows,body[0]))==-1) break;
      RemoveButton(&buttons,i);
      if (WindowIsUp)
        AdjustWindow();

      redraw=1;
      break;

  case M_MINI_ICON:
    if ((i=FindItem(&windows,body[0]))==-1) break;

    if (UpdateButton(&buttons,i,NULL,-1)!=-1)
    {
      p.picture = body[1];
      p.mask = body[2];
      p.width = body[3];
      p.height = body[4];
      p.depth = body[5];
      UpdateButtonPicture(&buttons, i, &p);
      redraw = 0;
    }
    break;

    case M_WINDOW_NAME:
    case M_ICON_NAME:
      if ((type==M_ICON_NAME && !UseIconNames) || 
          (type==M_WINDOW_NAME && UseIconNames)) break;
      if ((i=UpdateItemName(&windows,body[0],(char *)&body[3]))==-1) break;
      string=(char *)&body[3];
      name=makename(string,ItemFlags(&windows,body[0]));
      if (UpdateButton(&buttons,i,name,-1)==-1)
      {
	AddButton(&buttons, name, NULL, 1);
	UpdateButtonSet(&buttons,i,ItemFlags(&windows,body[0])&ICONIFIED?1:0);
        UpdateButtonDesk(&buttons,i,ItemDesk(&windows, body[0]));
      }
      free(name);
      if (WindowIsUp) AdjustWindow();
      redraw=1;
      break;
    case M_DEICONIFY:
    case M_ICONIFY:
      if ((i=FindItem(&windows,body[0]))==-1) break;
      flags=ItemFlags(&windows,body[0]);
      if (type==M_DEICONIFY && !(flags&ICONIFIED)) break;
      if (type==M_ICONIFY && flags&ICONIFIED) break;
      flags^=ICONIFIED;
      UpdateItemFlags(&windows,body[0],flags);
      string=ItemName(&windows,i);
      name=makename(string,flags);
      if (UpdateButton(&buttons,i,name,-1)!=-1) redraw=1;
      if (i!=current_focus||(flags&ICONIFIED))
        if (UpdateButtonSet(&buttons,i,(flags&ICONIFIED) ? 1 : 0)!=-1) redraw=1;
      free(name);
      break;
    case M_FOCUS_CHANGE:

/* old coded, before Task bar code spliced in

      i=FindItem(&windows,body[0]);
      if (i==current_focus) break;
      if (current_focus!=-1)
	if ((ItemFlags(&windows,ItemID(&windows,current_focus))&ICONIFIED)==0)
	  if (UpdateButtonSet(&buttons,current_focus,0)!=-1) redraw=1;
      current_focus=-1;
      if (i!=-1&&(ItemFlags(&windows,body[0])&ICONIFIED)) break;
      current_focus=i;
      if (current_focus!=-1)
	if (UpdateButtonSet(&buttons,current_focus,2)!=-1) redraw=1;
* end of old code */

/* Code copied Straight from TaskBar */

    if ((i=FindItem(&windows,body[0]))!=-1)
    {
	    flags=ItemFlags(&windows,body[0]);
 	    UpdateItemFlags(&windows,body[0],flags);
    }
    RadioButton(&buttons,i);
    redraw = 1;
    break;

      break;
    case M_END_WINDOWLIST:
      if (!WindowIsUp) MakeMeWindow();
      redraw=1;
      break;
    case M_NEW_DESK:
	CurrentDesk = body[0];
	if(ShowCurrentDesk)
	{
	  RESIZE_BUG_HACK = 1;
	  AdjustWindow();
	  RESIZE_BUG_HACK = 0;
	  RedrawWindow(1);
        }
      break;
    case M_NEW_PAGE:
      break;
  }

  if (redraw && WindowIsUp==1) RedrawWindow(0);
}
Example #14
0
/******************************************************************************
  AdjustWindow - Resize the window according to maxwidth by number of buttons
******************************************************************************/
void AdjustWindow()
{
  int new_width=0,new_height=0,tw,i,total;
  char *temp;

  total = ItemCountD(&windows );
  if (!total)
  {
    if (WindowIsUp==1)
    {
      XUnmapWindow(dpy,win);
      WindowIsUp=2;
    }
    return;
  }
  for(i=0;i<total;i++)
  {
    temp=ItemName(&windows,i);
    if(temp != NULL)
    {
	tw=10+XTextWidth(ButtonFont,temp,strlen(temp));
	tw+=XTextWidth(ButtonFont,"()",2);

	tw+=14; /* for title icon */ /* Magic Number ? */

	new_width=max(new_width,tw);
    }
  }
  new_width=max(new_width, MinWidth);
  new_width=min(new_width, MaxWidth);
  new_height=(total*(fontheight+6+1)-1);
  if (WindowIsUp && (new_height!=win_height  || new_width!=win_width))
  {
    if (Anchor)
    {
      if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
        win_x-=(new_width-win_width);

      if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
        win_y-=(new_height-win_height);

      if(RESIZE_BUG_HACK)
      {
        if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
		win_x+= win_border - 2;
	else
		win_x-=win_border;

	if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
		win_y+=win_border - 2;
	else	
		win_y-=win_border;
      }

      XMoveResizeWindow(dpy,win,win_x+win_border,win_y+win_title+win_border,
        new_width,new_height);

    }
    else
      XResizeWindow(dpy, win, new_width,new_height);

    XSync(dpy,False);
  }
  UpdateArray(&buttons,-1,-1,new_width,-1);
  if (new_height>0) win_height = new_height;
  if (new_width>0) win_width = new_width;
  if (WindowIsUp==2)
  {
    XMapWindow(dpy,win);
    WindowIsUp=1;
    WaitForExpose();
  }
}
Example #15
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist(const char *title,
		 const char *cprompt,
		 int height,
		 int width,
		 int list_height,
		 int item_no,
		 char **items,
		 int flag)
{
    int result;
    int i;
    DIALOG_LISTITEM *listitems;
    bool separate_output = ((flag == FLAG_CHECK)
			    && (dialog_vars.separate_output));
    bool show_status = FALSE;
    int current = 0;

    listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
    assert_ptr(listitems, "dialog_checklist");

    for (i = 0; i < item_no; ++i) {
	listitems[i].name = ItemName(i);
	listitems[i].text = ItemText(i);
	listitems[i].help = ((dialog_vars.item_help)
			     ? ItemHelp(i)
			     : dlg_strempty());
	listitems[i].state = !dlg_strcmp(ItemStatus(i), "on");
    }
    dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);

    result = dlg_checklist(title,
			   cprompt,
			   height,
			   width,
			   list_height,
			   item_no,
			   listitems,
			   NULL,
			   flag,
			   &current);

    switch (result) {
    case DLG_EXIT_OK:		/* FALLTHRU */
    case DLG_EXIT_EXTRA:
	show_status = TRUE;
	break;
    case DLG_EXIT_HELP:
	dlg_add_result("HELP ");
	show_status = dialog_vars.help_status;
	if (USE_ITEM_HELP(listitems[current].help)) {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].help);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].help);
		}
	    } else {
		dlg_add_string(listitems[current].help);
	    }
	    result = DLG_EXIT_ITEM_HELP;
	} else {
	    if (show_status) {
		if (separate_output) {
		    dlg_add_string(listitems[current].name);
		    dlg_add_separator();
		} else {
		    dlg_add_quoted(listitems[current].name);
		}
	    } else {
		dlg_add_string(listitems[current].name);
	    }
	}
	break;
    }

    if (show_status) {
	for (i = 0; i < item_no; i++) {
	    if (listitems[i].state) {
		if (separate_output) {
		    dlg_add_string(listitems[i].name);
		    dlg_add_separator();
		} else {
		    if (dlg_need_separator())
			dlg_add_separator();
		    dlg_add_string(listitems[i].name);
		}
	    }
	}
    }

    dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
    free(listitems);
    return result;
}
Example #16
0
// reads defense and own fleet
bool CSpeedKernel::ReadOwnFleet(genstring OwnFleet, int FleetID) {
    vector<SItem> items;
    vector<SItem> def;
    bool dodef = false;
	genstring name, anz, name2;
    genstring::size_type f;
    int i, num = 0;
    while((f = OwnFleet.find(_T("."))) != genstring::npos)
    {
        OwnFleet.erase(f, 1);
    }

    // fleet from fleet menu
    for(i = 0; i < T_SHIPEND; i++) {
        if(i == T_SAT)
            continue;
        name = ItemName((ITEM_TYPE)i);
        name2 = ItemName2((ITEM_TYPE)i);
        f = OwnFleet.find(name.c_str(), 0);
        if(f == genstring::npos && name2 != _T("")) {
            f = OwnFleet.find(name2.c_str(), 0);
			name = name2;
        }
        if(f != genstring::npos) {
            f += name.length();
            if(f >= OwnFleet.length())
                break;
            anz = OwnFleet.substr(f , 10);
            num += _ttoi(anz.c_str());
            SItem si;
            si.Num = _ttoi(anz.c_str());
            si.OwnerID = FleetID;
            si.Type = (ITEM_TYPE)i;
            items.push_back(si);
        }
    }
    // defense from defense menu
    for(i = T_RAK; i < T_END; i++) {
        name = ItemName((ITEM_TYPE)i) + _T(" (") + m_Defense;
        name2 = ItemName2((ITEM_TYPE)i) + _T(" (") + m_Defense;
        f = OwnFleet.find(name.c_str(), 0);
        if(f == genstring::npos && name2 != _T(" (") + m_Defense){
			name = name2;
			f = OwnFleet.find(name2.c_str(), 0);
		}
        if(f != genstring::npos) {
            dodef = true;
            f += name.length();
            if(f >= OwnFleet.length())
                break;
            int p = OwnFleet.find(_T(' '), f+1);
            if(p == genstring::npos)
                continue;
            anz = OwnFleet.substr(f, p - f);
            num += _ttoi(anz.c_str());
            SItem si;
            si.Type = (ITEM_TYPE)i;
            si.Num = _ttoi(anz.c_str());
            si.OwnerID = FleetID;
            def.push_back(si);
        }
    }
    if(!num)
        return false;
    if(dodef) {
        // add old attacking fleet
        SItem tmpItem[T_END];
        GetSetFleet(NULL, tmpItem, FleetID);
        for(i = 0; i < T_END; i++) {
            if(tmpItem[i].Type < T_SHIPEND)
                def.push_back(tmpItem[i]);
        }
        SetFleet(NULL, &def);
    }
    // if not defense, check for esp. report
    else if(OwnFleet.find(m_Ress[0]) != genstring::npos || OwnFleet.find(m_Ress[1]) != genstring::npos ||
        OwnFleet.find(m_Ress[2]) != genstring::npos) {
        return false;
    }
    else {
        SetFleet(&items, NULL);
    }
    return true;
}
Example #17
0
// analyzes esp. report
bool CSpeedKernel::ParseSpioLine(genstring& s, TargetInfo& ti)
{
	genstring name, anz, item, item2;
	genstring::size_type f, f2;
	f2 = 0; f = 0;
    bool founditem = false;
    int techs[3];
    memset(techs, 0, 3 * sizeof(int));

    // read metal/crystal/deuterium and ignore mines etc.
    if(((f2 = s.find(m_Ress[0], 0)) != s.npos) && s.find(m_wrongRess[0], 0) != f2 && s.find(m_wrongRess2[0], 0) != f2)
    {
        f = f2 + m_Ress[0].length();
        anz = s.substr(f);
        ti.Resources.met = _ttoi(anz.c_str());
        if(ti.Resources.met)
            founditem = true;
        if(ti.Resources.met < 0)
            ti.Resources.met = 0;
    }
    if(((f2 = s.find(m_Ress[1], 0)) != s.npos) && s.find(m_wrongRess[1], 0) != f2 && s.find(m_wrongRess2[1], 0) != f2)
    {
        f = f2 + m_Ress[1].length();
        anz = s.substr(f);
        ti.Resources.kris = _ttoi(anz.c_str());
        if(ti.Resources.kris)
            founditem = true;
        if(ti.Resources.kris < 0)
            ti.Resources.met = 0;
    }
    if(((f2 = s.find(m_Ress[2], 0)) != s.npos) && s.find(m_wrongRess[2], 0) != f2 && s.find(m_wrongRess2[2], 0) != f2)
    {
        f = f2 + m_Ress[2].length();
        anz = s.substr(f);
        ti.Resources.deut = _ttoi(anz.c_str());
        if(ti.Resources.deut)
            founditem = true;
        if(ti.Resources.deut< 0)
            ti.Resources.deut = 0;
    }

    // read in defense and fleet
    SItem sit;
    sit.OwnerID = 0;
    int num = 0;
    int i;
    bool found_ship[T_END+1];
    for(i = 0; i < T_END+1; i++)
    {
        ITEM_TYPE type = m_ParseOrder[0][i];
        item = ItemName(type);
        if(!item.length())
            continue;
        /*item2 = ItemName2((ITEM_TYPE)i);*/
        sit.Num = 0;
        if((f2 = s.find(item.c_str(), 0)) != genstring::npos)
        {
            anz = s.substr(f2 + item.length());
            //ITEM_TYPE type = GetItemType(item);
            sit.Type = type;
            num += sit.Num = _ttoi(anz.c_str());
            if(type < T_SHIPEND && sit.Num != 0)
                ti.Fleet.push_back(sit);
            else if(type < T_END && sit.Num != 0)
                ti.Defence.push_back(sit);
            else
                ti.NumABM = sit.Num;
            // substitute name
            s.replace(f2, item.length(), _T("_"));
        }
        if(sit.Num)
            found_ship[type] = true;
        else
            found_ship[type] = false;
    }
    for(i = 0; i < T_END+1; i++)
    {
        ITEM_TYPE type = m_ParseOrder[1][i];
        if(found_ship[type])
            continue;

        item = ItemName2(type);
        if(!item.length())
            continue;
        sit.Num = 0;
        if((f2 = s.find(item.c_str(), 0)) != genstring::npos)
        {
            anz = s.substr(f2 + item.length());
            sit.Type = type;
            num += sit.Num = _ttoi(anz.c_str());
            if(type < T_SHIPEND && sit.Num != 0)
                ti.Fleet.push_back(sit);
            else if(type < T_END && sit.Num != 0)
                ti.Defence.push_back(sit);
            else
                ti.NumABM = sit.Num;
            // substitute name
            s.replace(f2, item.length(), _T("_"));
        }
    }
    sort(ti.Fleet.begin(), ti.Fleet.end(), SItem::IsLess);
    sort(ti.Defence.begin(), ti.Defence.end(), SItem::IsLess);
    // read in techs
    for(int j = 0; j < 3; j++) {
        if((f2 = s.find(m_TechNames[j], 0)) != genstring::npos)
        {
            f = f2 + m_TechNames[j].length();
            anz = s.substr(f);
            techs[j] = _ttoi(anz.c_str());
            if(techs[j])
                founditem = true;
        }
    }
    if(num)
        founditem = true;

    if(founditem || num > 0) {
        ti.Techs.Weapon = techs[0];
        ti.Techs.Shield = techs[1];
        ti.Techs.Armour = techs[2];
    }
	return founditem;
}
Example #18
0
/******************************************************************************
  ProcessMessage - Process the message coming from Fvwm
    Skeleton based on processmessage() from FvwmIdent:
      Copyright 1994, Robert Nation and Nobutaka Suzuki.
******************************************************************************/
void ProcessMessage(unsigned long type,unsigned long *body)
{
    int redraw=0,i;
    long flags;
    char *name,*string;
    static int current_focus=-1;

    FvwmPicture p;

    switch(type)
    {
    case M_ADD_WINDOW:
    case M_CONFIGURE_WINDOW:
        if ((i = FindItem(&windows,body[0]))!=-1)
        {
            if(UpdateItemDesk(&windows, i, body[7]) > 0)
            {
                AdjustWindow();
                RedrawWindow(1);
            }
            break;
        }

        if (!(body[8]&WINDOWLISTSKIP) || !UseSkipList)
            AddItem(&windows,body[0],body[8], body[7] /* desk */);
        break;
    case M_DESTROY_WINDOW:
        if ((i=DeleteItem(&windows,body[0]))==-1) break;
        RemoveButton(&buttons,i);
        if (WindowIsUp)
            AdjustWindow();

        redraw=1;
        break;

#ifdef MINI_ICONS
    case M_MINI_ICON:
        if ((i=FindItem(&windows,body[0]))==-1) break;

        if (UpdateButton(&buttons,i,NULL,-1)!=-1)
        {
            p.width = body[3];
            p.height = body[4];
            p.depth = body[5];
            p.picture = body[6];
            p.mask = body[7];

            UpdateButtonPicture(&buttons, i, &p);
            redraw = 0;
        }
        break;
#endif

    case M_WINDOW_NAME:
    case M_ICON_NAME:
        if ((type==M_ICON_NAME && !UseIconNames) ||
                (type==M_WINDOW_NAME && UseIconNames)) break;
        if ((i=UpdateItemName(&windows,body[0],(char *)&body[3]))==-1) break;
        string=(char *)&body[3];
        name=makename(string,ItemFlags(&windows,body[0]));
        if (UpdateButton(&buttons,i,name,-1)==-1)
        {
            AddButton(&buttons, name, NULL, 1);
            UpdateButtonSet(&buttons,i,ItemFlags(&windows,body[0])&ICONIFIED?1:0);
            UpdateButtonDesk(&buttons,i,ItemDesk(&windows, body[0]));
        }
        free(name);
        if (WindowIsUp) AdjustWindow();
        redraw=1;
        break;
    case M_DEICONIFY:
    case M_ICONIFY:
        if ((i=FindItem(&windows,body[0]))==-1) break;
        flags=ItemFlags(&windows,body[0]);
        if (type==M_DEICONIFY && !(flags&ICONIFIED)) break;
        if (type==M_ICONIFY && flags&ICONIFIED) break;
        flags^=ICONIFIED;
        UpdateItemFlags(&windows,body[0],flags);
        string=ItemName(&windows,i);
        name=makename(string,flags);
        if (UpdateButton(&buttons,i,name,-1)!=-1) redraw=1;
        if (i!=current_focus||(flags&ICONIFIED))
            if (UpdateButtonSet(&buttons,i,(flags&ICONIFIED) ? 1 : 0)!=-1) redraw=1;
        free(name);
        break;
    case M_FOCUS_CHANGE:
        if ((i=FindItem(&windows,body[0]))!=-1)
        {
            flags=ItemFlags(&windows,body[0]);
            UpdateItemFlags(&windows,body[0],flags);
            RadioButton(&buttons,i);
        }
        else
            RadioButton(&buttons,-1);
        redraw = 1;
        break;
    case M_END_WINDOWLIST:
        if (!WindowIsUp) MakeMeWindow();
        redraw = 1;
        break;
    case M_NEW_DESK:
        CurrentDesk = body[0];
        if(ShowCurrentDesk)
        {
            AdjustWindow();
            RedrawWindow(1);
        }
        break;
    case M_NEW_PAGE:
        break;
    }

    if (redraw && WindowIsUp==1) RedrawWindow(0);
}
/*
 * Display a menu for choosing among a number of options
 */
int
dialog_menu(const char *title, const char *cprompt, int height, int width,
	    int menu_height, int item_no, char **items)
{
    int i, j, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0, fkey;
    int button = 0;
    int choice = dlg_default_item(items, MENUBOX_TAGS);
    int result = DLG_EXIT_UNKNOWN;
    int scrollamt = 0;
    int max_choice, min_width;
    int found;
    int use_width, name_width, text_width;
    WINDOW *dialog, *menu;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (menu_height == 0) {
	min_width = calc_listw(item_no, items, MENUBOX_TAGS) + 10;
	/* calculate height without items (4) */
	auto_size(title, prompt, &height, &width, 4, MAX(26, min_width));
	calc_listh(&height, &menu_height, item_no);
    } else {
	auto_size(title, prompt, &height, &width, 4 + menu_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    /* Find out maximal number of displayable items at once. */
    max_choice = MIN(menu_height,
		     RowHeight(item_no));
    if (dialog_vars.input_menu)
	max_choice /= INPUT_ROWS;

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    menu_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - menu_width) / 2 - 1;

    /* create new window for the menu */
    menu = sub_window(dialog, menu_height, menu_width,
		      y + box_y + 1,
		      x + box_x + 1);

    /* draw a box around the menu items */
    draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
	     menubox_border_attr, menubox_attr);

    name_width = 0;
    text_width = 0;

    /* Find length of longest item to center menu  *
     * only if --menu was given, using --inputmenu *
     * won't be centered.                         */
    for (i = 0; i < item_no; i++) {
	name_width = MAX(name_width, dlg_count_columns(ItemName(i)));
	text_width = MAX(text_width, dlg_count_columns(ItemText(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (menu_width - GUTTER);
    if (text_width + name_width > use_width) {
	int need = 0.25 * use_width;
	if (name_width > need) {
	    int want = use_width * ((double) name_width) / (text_width + name_width);
	    name_width = (want > need) ? want : need;
	}
	text_width = use_width - name_width;
    }

    tag_x = (dialog_vars.input_menu
	     ? 0
	     : (use_width - text_width - name_width) / 2);
    item_x = name_width + tag_x + GUTTER;

    if (choice - scrollamt >= max_choice) {
	scrollamt = choice - (max_choice - 1);
	choice = max_choice - 1;
    }

    /* Print the menu */
    for (i = 0; i < max_choice; i++)
	print_item(menu, ItemData(i + scrollamt), i, i == choice);
    (void) wnoutrefresh(menu);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y + 1, box_x, menu_height + 2, menu_width + 2,
		      KEY_MAX, 1, 1, 1 /* by lines */ );

    dlg_draw_arrows(dialog, scrollamt,
		    scrollamt + max_choice < item_no,
		    box_x + tag_x + 1,
		    box_y,
		    box_y + menu_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (result == DLG_EXIT_UNKNOWN) {
	key = mouse_wgetch(dialog, &fkey);

	if (!fkey) {
	    fkey = TRUE;
	    switch (key) {
	    case '\n':
	    case '\r':
		key = KEY_ENTER;
		break;
	    case '-':
		key = KEY_UP;
		break;
	    case '+':
		key = KEY_DOWN;
		break;
	    case ' ':
	    case TAB:
		key = KEY_RIGHT;
		break;
	    case ESC:
		result = DLG_EXIT_ESC;
		continue;
	    default:
		fkey = FALSE;
		break;
	    }
	}

	found = FALSE;
	if (fkey) {
	    /*
	     * Allow a mouse-click on a box to switch selection to that box.
	     * Handling a button click is a little more complicated, since we
	     * push a KEY_ENTER back onto the input stream so we'll put the
	     * cursor at the right place before handling the "keypress".
	     */
	    if (key >= (M_EVENT + KEY_MAX)) {
		key -= (M_EVENT + KEY_MAX);
		i = RowToItem(key);
		found = TRUE;
	    } else if (key >= M_EVENT
		       && dlg_ok_buttoncode(key - M_EVENT) >= 0) {
		button = (key - M_EVENT);
		ungetch('\n');
		continue;
	    }
	} else {
	    /*
	     * Check if key pressed matches first character of any item tag in
	     * list.  If there is more than one match, we will cycle through
	     * each one as the same key is pressed repeatedly.
	     */
	    for (j = scrollamt + choice + 1; j < item_no; j++) {
		if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
		    found = TRUE;
		    i = j - scrollamt;
		    break;
		}
	    }
	    if (!found) {
		for (j = 0; j <= scrollamt + choice; j++) {
		    if (dlg_match_char(dlg_last_getc(), ItemName(j))) {
			found = TRUE;
			i = j - scrollamt;
			break;
		    }
		}
	    }
	    if (found)
		dlg_flush_getc();

	    /*
	     * A single digit (1-9) positions the selection to that line in the
	     * current screen.
	     */
	    if (!found
		&& (key <= '9')
		&& (key > '0')
		&& (key - '1' < max_choice)) {
		found = TRUE;
		i = key - '1';
	    }
	}

	if (!found && fkey) {
	    found = TRUE;
	    switch (key) {
	    case KEY_HOME:
		i = -scrollamt;
		break;
	    case KEY_LL:
	    case KEY_END:
		i = item_no - 1 - scrollamt;
		break;
	    case M_EVENT + KEY_PPAGE:
	    case KEY_PPAGE:
		if (choice)
		    i = 0;
		else if (scrollamt != 0)
		    i = -MIN(scrollamt, max_choice);
		else
		    continue;
		break;
	    case M_EVENT + KEY_NPAGE:
	    case KEY_NPAGE:
		i = MIN(choice + max_choice, item_no - scrollamt - 1);
		break;
	    case KEY_UP:
		i = choice - 1;
		if (choice == 0 && scrollamt == 0)
		    continue;
		break;
	    case KEY_DOWN:
		i = choice + 1;
		if (scrollamt + choice >= item_no - 1)
		    continue;
		break;
	    default:
		found = FALSE;
		break;
	    }
	}

	if (found) {
	    if (i != choice) {
		getyx(dialog, cur_y, cur_x);
		if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
		    /*
		     * Using wscrl to assist ncurses scrolling is not needed
		     * in version 5.x
		     */
		    if (i == -1) {
			if (menu_height > 1) {
			    /* De-highlight current first item */
			    print_item(menu, ItemData(scrollamt), 0, FALSE);
			    scrollok(menu, TRUE);
			    wscrl(menu, -RowHeight(1));
			    scrollok(menu, FALSE);
			}
			scrollamt--;
			print_item(menu, ItemData(scrollamt), 0, TRUE);
		    } else if (i == max_choice) {
			if (menu_height > 1) {
			    /* De-highlight current last item before scrolling up */
			    print_item(menu,
				       ItemData(scrollamt + max_choice - 1),
				       max_choice - 1, FALSE);
			    scrollok(menu, TRUE);
			    wscrl(menu, RowHeight(1));
			    scrollok(menu, FALSE);
			}
			scrollamt++;
			print_item(menu,
				   ItemData(scrollamt + max_choice - 1),
				   max_choice - 1, TRUE);
		    } else
#endif
		    {
			if (i < 0) {
			    scrollamt += i;
			    choice = 0;
			} else {
			    choice = max_choice - 1;
			    scrollamt += (i - max_choice + 1);
			}
			for (i = 0; i < max_choice; i++) {
			    print_item(menu,
				       ItemData(scrollamt + i),
				       i, i == choice);
			}
		    }
		    /* Clean bottom lines */
		    if (dialog_vars.input_menu) {
			int spare_lines, x_count;
			spare_lines = menu_height % INPUT_ROWS;
			wattrset(menu, menubox_attr);
			for (; spare_lines; spare_lines--) {
			    wmove(menu, menu_height - spare_lines, 0);
			    for (x_count = 0; x_count < menu_width;
				 x_count++) {
				waddch(menu, ' ');
			    }
			}
		    }
		    (void) wnoutrefresh(menu);
		    dlg_draw_arrows(dialog, scrollamt,
				    scrollamt + choice < item_no - 1,
				    box_x + tag_x + 1,
				    box_y,
				    box_y + menu_height + 1);
		} else {
		    /* De-highlight current item */
		    print_item(menu,
			       ItemData(scrollamt + choice),
			       choice, FALSE);
		    /* Highlight new item */
		    choice = i;
		    print_item(menu,
			       ItemData(scrollamt + choice),
			       choice, TRUE);
		    (void) wnoutrefresh(menu);
		    (void) wmove(dialog, cur_y, cur_x);
		    wrefresh(dialog);
		}
	    }
	    continue;		/* wait for another key press */
	}

	if (fkey) {
	    switch (key) {
	    case KEY_BTAB:
	    case KEY_LEFT:
		button = dlg_prev_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_RIGHT:
		button = dlg_next_button(buttons, button);
		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
				 FALSE, width);
		break;
	    case KEY_ENTER:
		del_window(dialog);
		result = handle_button(dlg_ok_buttoncode(button),
				       items,
				       scrollamt + choice);

		if (dialog_vars.input_menu && result == DLG_EXIT_EXTRA) {
		    char *tmp;
		    tmp = input_menu_edit(menu, ItemData(scrollamt + choice),
					  choice);

		    dialog_vars.input_result[0] = '\0';
		    dlg_add_result("RENAMED ");
		    dlg_add_result(ItemName(scrollamt + choice));
		    dlg_add_result(" ");
		    dlg_add_result(tmp);
		    free(tmp);

		    dlg_draw_buttons(dialog, height - 2, 0,
				     buttons, button, FALSE, width);
		}
		break;
	    default:
		flash();
		break;
	    }
	}
    }

    mouse_free_regions();
    del_window(dialog);
    free(prompt);
    return result;
}
Example #20
0
/*
 * Display a menu for choosing among a number of options
 */
int
dialog_menu(const char *title, const char *cprompt, int height, int width,
            int menu_height, int item_no, const char **items)
{
    int i, j, x, y, cur_x, cur_y, box_x, box_y;
    int key = 0;
    int button = 0;
    int choice = dlg_default_item(items, MENUBOX_TAGS);
    int scrollamt = 0;
    int max_choice, min_width;
    int found;
    int use_width, name_width, text_width;
    WINDOW *dialog, *menu;
    char *prompt = strclone(cprompt);
    const char **buttons = dlg_ok_labels();

    tab_correct_str(prompt);
    if (menu_height == 0) {
        min_width = calc_listw(item_no, items, MENUBOX_TAGS) + 10;
        /* calculate height without items (4) */
        auto_size(title, prompt, &height, &width, 4, MAX(26, min_width));
        calc_listh(&height, &menu_height, item_no);
    } else {
        auto_size(title, prompt, &height, &width, 4 + menu_height, 26);
    }
    print_size(height, width);
    ctl_size(height, width);

    max_choice = MIN(menu_height, item_no);

    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    mouse_setbase(x, y);

    draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
    draw_bottom_box(dialog);
    draw_title(dialog, title);

    wattrset(dialog, dialog_attr);
    print_autowrap(dialog, prompt, height, width);

    menu_width = width - 6;
    getyx(dialog, cur_y, cur_x);
    box_y = cur_y + 1;
    box_x = (width - menu_width) / 2 - 1;

    /* create new window for the menu */
    menu = sub_window(dialog, menu_height, menu_width, y + box_y + 1,
                      x + box_x + 1);

    /* draw a box around the menu items */
    draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
             menubox_border_attr, menubox_attr);

    name_width = 0;
    text_width = 0;
    /* Find length of longest item to center menu */
    for (i = 0; i < item_no; i++) {
        name_width = MAX(name_width, (int) strlen(ItemName(i)));
        text_width = MAX(text_width, (int) strlen(ItemText(i)));
    }

    /* If the name+text is wider than the list is allowed, then truncate
     * one or both of them.  If the name is no wider than 1/4 of the list,
     * leave it intact.
     */
    use_width = (menu_width - 2);
    if (text_width + name_width > use_width) {
        int need = 0.25 * use_width;
        if (name_width > need) {
            int want = use_width * ((double) name_width) / (text_width + name_width);
            name_width = (want > need) ? want : need;
        }
        text_width = use_width - name_width;
    }

    tag_x = (use_width - text_width - name_width) / 2;
    item_x = name_width + tag_x + 2;

    if (choice - scrollamt >= max_choice) {
        scrollamt = choice - (max_choice - 1);
        choice = max_choice - 1;
    }

    /* Print the menu */
    for (i = 0; i < max_choice; i++)
        print_item(menu, ItemData(i + scrollamt), i, i == choice);
    (void) wnoutrefresh(menu);

    /* register the new window, along with its borders */
    mouse_mkbigregion(box_y, box_x, menu_height + 2, menu_width + 2,
                      item_no, item_x,	/* the threshold */
                      1 /* dirty mode */ );

    dlg_draw_arrows(dialog, scrollamt,
                    scrollamt + max_choice < item_no,
                    box_x + tag_x + 1,
                    box_y,
                    box_y + menu_height + 1);

    dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);

    wtimeout(dialog, WTIMEOUT_VAL);

    while (key != ESC) {
        key = mouse_wgetch(dialog);
        /* Check if key pressed matches first character of any
           item tag in menu */
        for (i = 0; i < max_choice; i++)
            if (toupper(key) == toupper(UCH(ItemName(scrollamt + i)[0])))
                break;

        /*
         * Check if key pressed matches first character of any item tag in
         * list.  If there is more than one match, we will cycle through
         * each one as the same key is pressed repeatedly.
         */
        found = FALSE;
        for (j = scrollamt + choice + 1; j < item_no; j++) {
            if (toupper(key) ==
                    toupper(UCH(ItemName(j)[0]))) {
                found = TRUE;
                i = j - scrollamt;
                break;
            }
        }
        if (!found) {
            for (j = 0; j <= scrollamt + choice; j++) {
                if (toupper(key) ==
                        toupper(UCH(ItemName(j)[0]))) {
                    found = TRUE;
                    i = j - scrollamt;
                    break;
                }
            }
        }

        /*
         * A single digit (1-9) positions the selection to that line in the
         * current screen.
         */
        if (!found
                && (key <= '9')
                && (key > '0')
                && (key - '1' <= max_choice)) {
            found = TRUE;
            i = key - '1';
        }

        if (!found) {
            found = TRUE;
            switch (key) {
            case KEY_HOME:
                i = -scrollamt;
                break;
            case KEY_LL:
            case KEY_END:
                i = item_no - 1 - scrollamt;
                break;
            case KEY_PPAGE:
                if (choice)
                    i = 0;
                else if (scrollamt != 0)
                    i = -MIN(scrollamt, max_choice);
                else
                    continue;
                break;
            case KEY_NPAGE:
                i = MIN(choice + max_choice, item_no - scrollamt - 1);
                break;
            case KEY_UP:
            case '-':
                i = choice - 1;
                if (choice == 0 && scrollamt == 0)
                    continue;
                break;
            case KEY_DOWN:
            case '+':
                i = choice + 1;
                if (scrollamt + choice >= item_no - 1)
                    continue;
                break;
            default:
                found = FALSE;
                break;
            }
        }

        if (found) {
            if (i != choice) {
                getyx(dialog, cur_y, cur_x);
                if (i < 0 || i >= max_choice) {
#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5
                    /*
                     * Using wscrl to assist ncurses scrolling is not needed
                     * in version 5.x
                     */
                    if (i == -1) {
                        if (menu_height > 1) {
                            /* De-highlight current first item */
                            print_item(menu, ItemData(scrollamt), 0, FALSE);
                            scrollok(menu, TRUE);
                            wscrl(menu, -1);
                            scrollok(menu, FALSE);
                        }
                        scrollamt--;
                        print_item(menu, ItemData(scrollamt), 0, TRUE);
                    } else if (i == max_choice) {
                        if (menu_height > 1) {
                            /* De-highlight current last item before scrolling up */
                            print_item(menu,
                                       ItemData(scrollamt + max_choice - 1),
                                       max_choice - 1, FALSE);
                            scrollok(menu, TRUE);
                            wscrl(menu, 1);
                            scrollok(menu, FALSE);
                        }
                        scrollamt++;
                        print_item(menu,
                                   ItemData(scrollamt + max_choice - 1),
                                   max_choice - 1, TRUE);
                    } else
#endif
                    {
                        if (i < 0) {
                            scrollamt += i;
                            choice = 0;
                        } else {
                            choice = max_choice - 1;
                            scrollamt += (i - max_choice + 1);
                        }
                        for (i = 0; i < max_choice; i++) {
                            print_item(menu,
                                       ItemData(scrollamt + i),
                                       i, i == choice);
                        }
                    }
                    (void) wnoutrefresh(menu);
                    dlg_draw_arrows(dialog, scrollamt,
                                    scrollamt + choice < item_no - 1,
                                    box_x + tag_x + 1,
                                    box_y,
                                    box_y + menu_height + 1);
                } else {
                    /* De-highlight current item */
                    print_item(menu,
                               ItemData(scrollamt + choice),
                               choice, FALSE);
                    /* Highlight new item */
                    choice = i;
                    print_item(menu,
                               ItemData(scrollamt + choice),
                               choice, TRUE);
                    (void) wnoutrefresh(menu);
                    (void) wmove(dialog, cur_y, cur_x);
                    wrefresh(dialog);
                }
            }
            continue;		/* wait for another key press */
        }

        switch (key) {
        case M_EVENT + 'O':
            del_window(dialog);
            return scrollamt + choice;
        case M_EVENT + 'C':
            del_window(dialog);
            return -2;
        case M_EVENT + 'o':	/* mouse enter... */
        case M_EVENT + 'c':	/* use the code for toggling */
            button = (key == M_EVENT + 'o');
        /* FALLTHRU */
        case ' ':
        case KEY_BTAB:
        case TAB:
        case KEY_LEFT:
        case KEY_RIGHT:
            if (!dialog_vars.nocancel)
                button = !button;
            dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
            break;
        case '\n':
            del_window(dialog);
            return (button ? -2 : (scrollamt + choice));
        }
    }

    del_window(dialog);
    return -1;			/* ESC pressed */
}
Example #21
0
/******************************************************************************
  AdjustWindow - Resize the window according to maxwidth by number of buttons
******************************************************************************/
void AdjustWindow(void)
{
    int new_width=0,new_height=0,tw,i,total,off_x,off_y;
    char *temp;
    Window frame;
    XWindowAttributes win_attr, frame_attr;

    total = ItemCountD(&windows );
    if (!total)
    {
        if (WindowIsUp==1)
        {
            XUnmapWindow(dpy,win);
            WindowIsUp=2;
        }
        return;
    }
    for(i=0; i<total; i++)
    {
        temp=ItemName(&windows,i);
        if(temp != NULL)
        {
            tw=10+XTextWidth(ButtonFont,temp,strlen(temp));
            tw+=XTextWidth(ButtonFont,"()",2);

#ifdef MINI_ICONS
            tw+=14; /* for title icon */ /* Magic Number ? */
#endif

            new_width=max(new_width,tw);
        }
    }
    new_width=max(new_width, MinWidth);
    new_width=min(new_width, MaxWidth);
    new_height=(total*(fontheight+6+1));
    if (WindowIsUp && (new_height!=win_height  || new_width!=win_width))
    {
        if (Anchor)
        {
            off_x = off_y = 0;
            MyXGrabServer(dpy);
            frame = find_frame_window(win, &off_x, &off_y);
            XGetWindowAttributes(dpy, frame, &frame_attr);
            XGetWindowAttributes(dpy, win, &win_attr);
            win_x = frame_attr.x + frame_attr.border_width + off_x;
            win_y = frame_attr.y + frame_attr.border_width + off_y;

            if (win_grav == SouthEastGravity || win_grav == NorthEastGravity)
                win_x += win_attr.width - new_width;
            if (win_grav == SouthEastGravity || win_grav == SouthWestGravity)
                win_y += win_attr.height - new_height;

            XMoveResizeWindow(dpy, win, win_x, win_y, new_width, new_height);
            MyXUngrabServer(dpy);
        }
        else
            XResizeWindow(dpy, win, new_width, new_height);

    }
    UpdateArray(&buttons,-1,-1,new_width,-1);
    if (new_height>0) win_height = new_height;
    if (new_width>0) win_width = new_width;
    if (WindowIsUp==2)
    {
        XMapWindow(dpy,win);
        WindowIsUp=1;
        WaitForExpose();
    }
}