summaryrefslogtreecommitdiff
path: root/plugins/Clist_modern/modern_toolbar.cpp
blob: 05ddd6410034c8c7cd7e3570f6d4c1baa89c8f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*

Miranda IM: the free IM client for Microsoft* Windows*


Copyright 2007 Artem Shpynov
Copyright 2000-2008 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "hdr/modern_commonheaders.h"
#include "hdr/modern_commonprototypes.h"
#include "./m_api/m_skinbutton.h"
#include <m_toptoolbar.h>
#include "hdr/modern_sync.h"

#define TTB_OPTDIR "TopToolBar"

#if defined(WIN64)
	static char szUrl[] = "http://nightly.miranda.im/x64/toptoolbar.zip";
#else
	static char szUrl[] = "http://nightly.miranda.im/x32/toptoolbar.zip";
#endif

static TCHAR szWarning[] = LPGENT("To view a toolbar in Clist Modern you need the TopToolBar plugin. Click Yes to download it or Cancel to continue");

static void CopySettings(const char* to, const char* from)
{
	db_set_b(NULL, TTB_OPTDIR, to, db_get_b(NULL,"ModernToolBar",from, 0));
}

static void sttRegisterToolBarButton(char * pszButtonID, char * pszButtonName, char * pszServiceName,
	char * pszTooltipUp, char * pszTooltipDn, int icoDefIdx, int defResource, int defResource2, BOOL bVisByDefault)
{
	TTBButton tbb = { 0 };
	static int defPos = 0;
	defPos += 100;
	tbb.cbSize = sizeof(tbb);
	tbb.dwFlags = TTBBF_ICONBYHANDLE;
	if (pszButtonID) {
		tbb.name = pszButtonID;
		tbb.pszService = pszServiceName;

		char buf[255];
		mir_snprintf(buf,SIZEOF(buf),"%s%s%s", "TTB_", pszButtonID, "_dn");
		tbb.hIconHandleUp = RegisterIcolibIconHandle( buf, "ToolBar", pszButtonName , _T("icons\\toolbar_icons.dll"),-icoDefIdx, g_hInst, defResource );

		if (pszTooltipDn) {
			mir_snprintf(buf,SIZEOF(buf),"%s%s%s", "TTB_", pszButtonID, "_up");
			tbb.hIconHandleUp = RegisterIcolibIconHandle( buf, "ToolBar", pszTooltipDn , _T("icons\\toolbar_icons.dll"),-(icoDefIdx+1), g_hInst, defResource2 );
		}
	}
	else tbb.dwFlags |= TTBBF_ISSEPARATOR;

	tbb.dwFlags |= (bVisByDefault ? TTBBF_VISIBLE :0 );
	CallService(MS_TTB_ADDBUTTON,0, (LPARAM)&tbb);
}

static void	ToolBar_DefaultButtonRegistration()
{
	sttRegisterToolBarButton( "MainMenu", "Main Menu", "CList/ShowMainMenu",
		"Main menu", NULL,  100 , IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );
	
	sttRegisterToolBarButton( "StatusMenu", "Status Menu", "CList/ShowStatusMenu",
		"Status menu", NULL,  105 , IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );

	sttRegisterToolBarButton( "AccoMgr", "Accounts", MS_PROTO_SHOWACCMGR,
		"Accounts...", NULL,  282 , IDI_ACCMGR, IDI_ACCMGR, TRUE  );
	
	sttRegisterToolBarButton( "ShowHideOffline","Show/Hide offline contacts", MS_CLIST_TOGGLEHIDEOFFLINE,
					    "Hide offline contacts", "Show offline contacts", 110, IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );
	
	sttRegisterToolBarButton( "DatabaseEditor","DBEditor++", "DBEditorpp/MenuCommand",
		"Database Editor", NULL,  130 , IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );

	sttRegisterToolBarButton( "FindUser","Find User", "FindAdd/FindAddCommand",
		"Find User", NULL,  140 , IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );
	
	sttRegisterToolBarButton( "Options","Options", "Options/OptionsCommand",
		"Options", NULL,  150 , IDI_RESETVIEW, IDI_RESETVIEW, TRUE  );

	sttRegisterToolBarButton( "UseGroups","Use/Disable groups", MS_CLIST_TOGGLEGROUPS,
		"Use groups", "Disable Groups", 160, IDI_RESETVIEW, IDI_RESETVIEW, FALSE  );

	sttRegisterToolBarButton( "EnableSounds","Enable/Disable sounds", MS_CLIST_TOGGLESOUNDS,
		"Enable sounds", "Disable Sounds", 170, IDI_RESETVIEW, IDI_RESETVIEW, FALSE  );
	
	sttRegisterToolBarButton( "Minimize","Minimize", "CList/ShowHide",
		"Minimize", NULL,  180 , IDI_RESETVIEW, IDI_RESETVIEW, FALSE  );
}

HRESULT ToolbarLoadModule()
{
	if ( db_get_b(NULL, "CLUI", "ShowButtonBar", -1) != -1) {
		CopySettings("BUTTWIDTH",    "option_Bar0_BtnWidth");
		CopySettings("BUTTHEIGHT",   "option_Bar0_BtnHeight");
		CopySettings("BUTTGAP",      "option_Bar0_BtnSpace");
		CopySettings("BUTTAUTOSIZE", "option_Bar0_Autosize");
		CopySettings("BUTTMULTI",    "option_Bar0_Multiline");

		db_unset(NULL, "CLUI", "ShowButtonBar");

		CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)"ModernToolBar");

		if (IDYES == MessageBox(NULL, TranslateTS(szWarning), TranslateT("Toolbar upgrade"), MB_ICONQUESTION | MB_YESNO))
			CallService(MS_UTILS_OPENURL, 0, (LPARAM)szUrl);
	}

	ToolBar_DefaultButtonRegistration();
	return S_OK;
}