summaryrefslogtreecommitdiff
path: root/plugins/TopToolBar/topbutton.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-22 12:29:14 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-22 12:29:14 +0000
commit5095e9d08fedfb4ea175403266b343f4561a1a9d (patch)
treeaee2b45b3fdb0273bc1031d62f6a158808a9afdf /plugins/TopToolBar/topbutton.cpp
parentcebec2980d00661cddf6d287800de656c6909f29 (diff)
pointers, pointers everywhere
git-svn-id: http://svn.miranda-ng.org/main/trunk@525 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TopToolBar/topbutton.cpp')
-rw-r--r--plugins/TopToolBar/topbutton.cpp162
1 files changed, 162 insertions, 0 deletions
diff --git a/plugins/TopToolBar/topbutton.cpp b/plugins/TopToolBar/topbutton.cpp
new file mode 100644
index 0000000000..e5705f5ecd
--- /dev/null
+++ b/plugins/TopToolBar/topbutton.cpp
@@ -0,0 +1,162 @@
+
+#include "common.h"
+#pragma hdrstop
+
+#define BitChanged(c) (dwFlags ^ Flags) & c
+
+TopButtonInt::~TopButtonInt()
+{
+ if (dwFlags & TTBBF_ISLBUTTON) {
+ if (program != NULL)
+ free(program);
+ }
+ else if (pszService != NULL)
+ free(pszService);
+
+ if (name != NULL)
+ free(name);
+ if (tooltip != NULL)
+ free(tooltip);
+}
+
+DWORD TopButtonInt::CheckFlags(DWORD Flags)
+{
+ int res = 0;
+ if (BitChanged(TTBBF_DISABLED)) {
+ dwFlags^=TTBBF_DISABLED;
+ EnableWindow(hwnd,(dwFlags & TTBBF_DISABLED)?FALSE:TRUE);
+ }
+ if (BitChanged(TTBBF_ASPUSHBUTTON)) {
+ dwFlags^=TTBBF_ASPUSHBUTTON;
+ SendMessage(hwnd, BUTTONSETASPUSHBTN, (dwFlags & TTBBF_ASPUSHBUTTON)?1:0, 0);
+ }
+ if (BitChanged(TTBBF_SHOWTOOLTIP)) {
+ dwFlags^=TTBBF_SHOWTOOLTIP;
+ SendMessage(hwnd,BUTTONADDTOOLTIP,
+ (WPARAM)((dwFlags & TTBBF_SHOWTOOLTIP)?tooltip:L""),BATF_UNICODE);
+ }
+ // next settings changing visual side, requires additional actions
+ if (BitChanged(TTBBF_VISIBLE)) {
+ dwFlags^=TTBBF_VISIBLE;
+ res |= TTBBF_VISIBLE;
+ }
+ if (BitChanged(TTBBF_PUSHED)) {
+ dwFlags^=TTBBF_PUSHED;
+ res |= TTBBF_PUSHED;
+ bPushed = (dwFlags & TTBBF_PUSHED) ? TRUE : FALSE;
+ }
+ return res;
+}
+
+void TopButtonInt::CreateWnd()
+{
+ if ( !(dwFlags & TTBBF_ISSEPARATOR)) {
+ hwnd = CreateWindow(MIRANDABUTTONCLASS, _T(""), BS_PUSHBUTTON|WS_CHILD|WS_TABSTOP|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0);
+
+ if (dwFlags & TTBBF_ASPUSHBUTTON)
+ SendMessage(hwnd, BUTTONSETASPUSHBTN, 1, 0);
+
+ if (DBGetContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", 1))
+ SendMessage(hwnd, BUTTONSETASFLATBTN, TRUE, 0);
+
+ EnableWindow(hwnd,(dwFlags & TTBBF_DISABLED)?FALSE:TRUE);
+ }
+ // maybe SEPWIDTH, not BUTTWIDTH?
+ else
+ hwnd = CreateWindow( _T("STATIC"), _T(""), WS_CHILD|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0);
+
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, id);
+ SetBitmap();
+}
+
+void TopButtonInt::LoadSettings()
+{
+ char buf[255];
+
+ BYTE oldv = (dwFlags & TTBBF_VISIBLE) != 0;
+ dwFlags = dwFlags & (~TTBBF_VISIBLE);
+
+ if (dwFlags & TTBBF_ISSEPARATOR) {
+ if (wParamDown != 0) {
+ char buf1[10];
+ _itoa(wParamDown, buf1, 10);
+ char buf2[20];
+ AS(buf2, "Sep", buf1);
+
+ arrangedpos = DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Position"), Buttons.getCount());
+ if ( DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Visible"), oldv) > 0 )
+ dwFlags |= TTBBF_VISIBLE;
+ }
+ }
+ else if (dwFlags & TTBBF_ISLBUTTON) {
+ if (wParamDown != 0) {
+ char buf1[10];
+ _itoa(wParamDown, buf1, 10);
+ char buf2[20];
+ AS(buf2, "Launch", buf1);
+
+ if (name != NULL) free(name);
+ name = DBGetString(0, TTB_OPTDIR, AS(buf, buf2, "_name"));
+ if (program != NULL) free(program);
+ program = DBGetStringT(0, TTB_OPTDIR, AS(buf, buf2, "_lpath"));
+
+ arrangedpos = DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Position"), Buttons.getCount());
+ if ( DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Visible"), oldv) > 0 )
+ dwFlags |= TTBBF_VISIBLE;
+ }
+ }
+ else {
+ arrangedpos = DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, name, "_Position"), Buttons.getCount());
+ if ( DBGetContactSettingByte(0, TTB_OPTDIR, AS(buf, name, "_Visible"), oldv) > 0 )
+ dwFlags |= TTBBF_VISIBLE;
+ }
+}
+
+void TopButtonInt::SaveSettings(int &SepCnt, int &LaunchCnt)
+{
+ char buf[255];
+
+ if (dwFlags & TTBBF_ISSEPARATOR) {
+ char buf1[10];
+ _itoa(++SepCnt, buf1, 10);
+ char buf2[20];
+ AS(buf2, "Sep", buf1);
+
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Position"), arrangedpos);
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Visible"), dwFlags & TTBBF_VISIBLE);
+ }
+ else if (dwFlags & TTBBF_ISLBUTTON) {
+ char buf1[10];
+ _itoa(++LaunchCnt, buf1, 10);
+ char buf2[20];
+ AS(buf2, "Launch", buf1);
+
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, buf2, "_name"), name);
+ DBWriteContactSettingTString(0, TTB_OPTDIR, AS(buf, buf2, "_lpath"), program);
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Position"), arrangedpos);
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, buf2, "_Visible"), dwFlags & TTBBF_VISIBLE);
+ }
+ else {
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, name, "_Position"), arrangedpos);
+ DBWriteContactSettingByte(0, TTB_OPTDIR, AS(buf, name, "_Visible"), dwFlags & TTBBF_VISIBLE);
+ }
+}
+
+void TopButtonInt::SetBitmap()
+{
+ int curstyle = GetWindowLongPtr(hwnd, GWL_STYLE);
+ curstyle &= (~SS_BITMAP);
+ curstyle &= (~SS_ICON);
+
+ if (dwFlags & TTBBF_ISSEPARATOR) {
+ SetWindowLongPtr(hwnd, GWL_STYLE, curstyle | SS_BITMAP);
+ SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmpSeparator);
+ SendMessage(hwnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmpSeparator);
+ }
+ else {
+ if (GetWindowLongPtr(hwnd, GWL_STYLE) & SS_ICON)
+ SetWindowLongPtr(hwnd, GWL_STYLE, curstyle | SS_ICON);
+ SendMessage(hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)((bPushed)?(hIconDn):(hIconUp)));
+ SendMessage(hwnd, BM_SETCHECK, bPushed?BST_CHECKED:BST_UNCHECKED ,0);
+ }
+}