示例#1
0
void StickersBox::prepare() {
	if (_section == Section::Installed) {
		Local::readArchivedStickers();
	} else if (_section == Section::Archived) {
		requestArchivedSets();
	} else if (_section == Section::ArchivedPart) {
		setTitle(lang(lng_stickers_archived));
	}
	if (Global::ArchivedStickerSetsOrder().isEmpty()) {
		preloadArchivedSets();
	}
	if (_tabs) {
		setNoContentMargin(true);
		_tabs->setSectionActivatedCallback([this] {
			switchTab();
		});
		refreshTabs();
	}
	if (_installed.widget() && _section != Section::Installed) _installed.widget()->hide();
	if (_featured.widget() && _section != Section::Featured) _featured.widget()->hide();
	if (_section != Section::Archived && _section != Section::ArchivedPart) _archived.widget()->hide();

	if (_featured.widget()) {
		_featured.widget()->setInstallSetCallback([this](uint64 setId) { installSet(setId); });
	}
	_archived.widget()->setInstallSetCallback([this](uint64 setId) { installSet(setId); });
	_archived.widget()->setLoadMoreCallback([this] { loadMoreArchived(); });

	addButton(lang(lng_about_done), [this] { closeBox(); });

	if (_section == Section::Installed) {
		_tab = &_installed;
	} else if (_section == Section::ArchivedPart) {
		_aboutHeight = st::stickersReorderPadding.top() + _about.countHeight(_aboutWidth) + st::stickersReorderPadding.bottom();
		_titleShadow.create(this);
		_tab = &_archived;
	} else if (_section == Section::Archived) {
		_tab = &_archived;
	} else { // _section == Section::Featured
		_tab = &_featured;
	}
	setInnerWidget(_tab->takeWidget(), getTopSkip());
	setDimensions(st::boxWideWidth, (_section == Section::ArchivedPart) ? st::sessionsHeight : st::boxMaxListHeight);

	connect(App::main(), SIGNAL(stickersUpdated()), this, SLOT(onStickersUpdated()));
	App::main()->updateStickers();

	if (_installed.widget()) {
		connect(_installed.widget(), SIGNAL(draggingScrollDelta(int)), this, SLOT(onDraggingScrollDelta(int)));
	}
int CHARSOCCURRENCESCALL
ListNotificationReceived(HWND ListWin, int Message, WPARAM /*wParam*/, LPARAM lParam)
{
    HWND hwndTabCtrl = ListWin;
    Status * pStatus = (Status *) GetProp(hwndTabCtrl, cn::PointerToStatus);

    if (Message == WM_NOTIFY)
    {
        switch ( ((NMHDR *) lParam) -> code)
        {
        case TCN_SELCHANGING:
            return FALSE;       // Switching to this tab is permitted
        case TCN_SELCHANGE:
            pStatus->setLastChosenTab(TabCtrl_GetCurSel(hwndTabCtrl));
            switchTab(hwndTabCtrl);
            return 0;           // To return some (ignored) value
        }
    }
    return 0;       // To return some (ignored) value
}
示例#3
0
void MainWindow::createControls()
{
	LOG(L"creating tabs");

	int yOffset = 40;

	if (settings::settings()[L"tabs"].length() == 0)
	{
		if (!m_emptyLink)
		{
			LOG(L"creating \"no tabs\" link");
			m_emptyLink = CreateWindow(L"BUTTON", loadString(m_instance, IDS_EMPTY_LINK).c_str(), 
				WS_CHILD | WS_VISIBLE | BS_COMMANDLINK, 4, yOffset + 10, 232, 50, m_wnd, nullptr, m_instance, 0);
			SetWindowLong(m_emptyLink, GWL_ID, IDC_EMPTY_LINK);
			SendMessage(m_emptyLink, BCM_SETNOTE, 0, (LPARAM)loadString(m_instance, IDS_EMPTY_LINK_NOTE).c_str());
		}
		return;
	}

	if (m_emptyLink)
	{
		LOG(L"destroying \"no tabs\" link");
		DestroyWindow(m_emptyLink);
		m_emptyLink = nullptr;
	}

	auto tabs = settings::settings()[L"tabs"];

	if (tabs.length() > 1)
	{
		yOffset = 70;
	}

	int tabWidth = 0;
	HDC dc = GetDC(m_wnd);
	for (auto tab : tabs)
	{
		auto name = tab[L"name"].asString();
		RECT r = { 0 };
		DrawText(dc, name.c_str(), -1, &r, DT_CALCRECT | DT_SINGLELINE);
		tabWidth = std::max(tabWidth, int(r.right));
	}
	tabWidth += 20;

	LOG(L"tab button width: %i", tabWidth);

	size_t selectedTab = size_t(settings::cache()[L"tab"].asNumber());
	if (selectedTab >= tabs.length())
	{
		selectedTab = 0;
	}

	for (size_t i = 0; i < tabs.length(); ++i)
	{
		if (tabs.length() > 1)
		{
			auto name = tabs[i][L"name"].asString();
			LOG(L"ceating tab button %ls", name.c_str());
			auto tab = CreateWindow(WC_BUTTON, name.c_str(), WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CENTER | BS_FLAT | BS_PUSHLIKE | BS_TEXT, 
				10 + i * (tabWidth + 4), 40, tabWidth, 24, m_wnd, nullptr, m_instance, nullptr);
			SetWindowLong(tab, GWL_ID, IDC_TAB);
			SendMessage(tab, WM_SETFONT, (WPARAM)m_tabFont, 0);
			m_tabs.push_back(tab);
			if (i == selectedTab)
			{
				Button_SetCheck(tab, 1);
			}
		}

		LOG(L"ceating table");
		auto table = new Table(m_instance, m_wnd, i, 8, yOffset);
		LOG(L"table created");
		m_tables.push_back(table);
		if (i == selectedTab)
		{
			table->show(true);
		}
	}

	switchTab();
}
示例#4
0
LRESULT MainWindow::wndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_NCHITTEST:
		return HTCAPTION;
	case WM_CTLCOLORSTATIC:
		SetTextColor(reinterpret_cast<HDC>(wParam), theme::color(theme::WINDOW_TITLE));
		SetBkColor(reinterpret_cast<HDC>(wParam), theme::color(theme::BACKGROUND));
		return (LRESULT)GetStockObject(NULL_BRUSH);
	case WM_CTLCOLORBTN:
		return (LRESULT)theme::brush(theme::BACKGROUND);
	case WM_ERASEBKGND:
	{
		HDC dc = HDC(wParam);
		RECT r;
		GetClientRect(m_wnd, &r);
		SelectObject(dc, theme::brush(theme::BACKGROUND));
		SelectObject(dc, theme::pen(theme::LINE));
		Rectangle(dc, r.left, r.top, r.right, r.bottom);
		return 1;
	}
	case WM_MENUCOMMAND:
	{
		HMENU menu = (HMENU)lParam;
		int idx = wParam;
		switch (GetMenuItemID(menu, idx))
		{
		case ID_USER_MENU:
		{
			MENUITEMINFO info;
			info.cbSize = sizeof(info);
			info.fMask = MIIM_DATA;
			GetMenuItemInfo(menu, idx, TRUE, &info);
			auto& item = m_menuItems[info.dwItemData];
			Table* table = nullptr;
			for (auto t : m_tables)
			{
				if (t->isVisible())
				{
					table = t;
					break;
				}
			}
			table->launch(item.verb.c_str(), item.path.c_str(), item.args.c_str(), false);
			break;
		}
		case ID_MENU_REFRESH:
			refresh();
			break;
		case IDM_ABOUT:
			m_inDialog = true;
			DialogBox(m_instance, MAKEINTRESOURCE(IDD_ABOUTBOX), m_wnd, about);
			m_inDialog = false;
			break;
		case IDM_EXIT:
			PostQuitMessage(0);
			break;
		case IDM_SETTINGS:
		{
			m_inDialog = true;
			auto ok = ShowSettingsDialog(m_wnd);
			if (ok)
			{
				applySettings();
			}
			m_inDialog = false;
			break;
		}
		}
		break;
	}
	case WM_COMMAND:
	{
		int wmId = LOWORD(wParam);
		switch (wmId)
		{
		case IDC_MENU:
		{
			HMENU menu = createMenu(); 
			RECT rect;
			GetWindowRect(GetDlgItem(m_wnd, IDC_MENU), &rect);
			TrackPopupMenu(menu, TPM_RIGHTALIGN | TPM_TOPALIGN, rect.right, rect.bottom, 0, m_wnd, NULL);
			break;
		}
		case IDC_TAB:
			switchTab();
			return 0;
		case IDC_EMPTY_LINK:
		{
			m_inDialog = true;
			auto ok = ShowSettingsDialog(m_wnd, SETTINGS_CONTENT);
			if (ok)
			{
				applySettings();
			}
			m_inDialog = false;
			break;
		}
		default:
			return DefWindowProc(m_wnd, message, wParam, lParam);
		}
	}
	break;
	case WM_DRAWITEM:
	{
		auto draw = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
		FillRect(draw->hDC, &draw->rcItem, theme::brush(theme::BACKGROUND));
		SelectPen(draw->hDC, theme::pen(theme::TEXT));
		SelectBrush(draw->hDC, theme::brush(theme::TEXT));
		const int radius = 4;
		Ellipse(draw->hDC, 0, 12, radius, 12 + radius);
		Ellipse(draw->hDC, 8, 12, radius + 8, 12 + radius);
		Ellipse(draw->hDC, 16, 12, radius + 16, 12 + radius);
		break;
	}
	case WM_ACTIVATEAPP:
		if (!m_inDialog && wParam == FALSE && settings::settings()[L"general"][L"bottomWindow"].asNumber() == 0)
		{
			PostQuitMessage(0);
		}
		break;
	case WM_MOVE:
	{
		RECT r;
		GetWindowRect(m_wnd, &r);
		settings::cache()[L"left"] = simplejson::Value::number(r.left);
		settings::cache()[L"top"] = simplejson::Value::number(r.top);
		settings::saveCache();
		break;
	}
	default:
		return DefWindowProc(m_wnd, message, wParam, lParam);
	}
	return 0;
}
示例#5
0
void InternalLink::handleInternalLink(const char* link)
{
	std::vector<gcString> list;
	bool badLink = false;

	g_pMainApp->showMainWindow(true);
	
	if (strncmp("desura://", link, 9) == 0)
	{
		char* str = nullptr;
		Safe::strcpy(&str, link+9, 255);

		char* context = nullptr;

		char* token = Safe::strtok(str, "/", &context);

		while (token)
		{
			list.push_back(gcString(token));
			token = Safe::strtok(nullptr, "/", &context);
		}

		safe_delete(str);
	}
	else
	{	
		badLink = true;
	}

	if (list.size() >= 1)
	{
		if (list[0] == "switchtab" || list[0] == "tab")
		{
			if (!switchTab(badLink, list, link))
				return;
		}
		else if (list[0] == "settings")
		{
			gcString url(GetGCThemeManager()->getWebPage("settings"));

			if (list.size() >=2 )
				url += "#" + list[1];
			else
				url += "#general";

			g_pMainApp->loadUrl(url.c_str(), SUPPORT);
		}
		else if (list[0] == "cip")
		{
			handleInternalLink(0, ACTION_SHOWSETTINGS, FormatArgs("tab=cip"));
		}
		else if (list.size() < 3)
		{
#ifdef WIN32
			if (list[0] == "installwizard")
			{
				handleInternalLink(0, ACTION_INSTALLEDW);
			}
			else 
#endif	
			if (list[0] == "refresh")
			{
				GetUserCore()->forceUpdatePoll();

				if ((list.size() >= 2 && list[1] == "background") == false)
					g_pMainApp->showPlay();
			}
			else
			{
				badLink = true;
			}
		}
		else
		{
			if (!processItemLink(badLink, list, link))
				return;
		}
	}

	if (badLink)
	{
		Warning(gcString("{0} [{1}]\n", Managers::GetString("#MF_BADLINK"), link));

		gcWString errMsg(L"{0}: {1}.", Managers::GetString("#MF_BADLINK"), link);
		gcMessageBox(g_pMainApp->getMainWindow(), errMsg, Managers::GetString(L"#MF_ERRTITLE"));
	}
}