diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-02 20:37:03 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-02 20:37:03 +0000 |
commit | d961f42c7f709929258c2a5b33fbb47acc399522 (patch) | |
tree | 9582b5cc8adc3c74cb9abd0eda60fe910617f154 /plugins/TopToolBar | |
parent | 5e81836e642adcbed92f9fdaa32afb80546e3aee (diff) |
- mir_cslock - class for locking critical sections;
- unneeded helpers removed;
- code cleaning in TTB
git-svn-id: http://svn.miranda-ng.org/main/trunk@727 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TopToolBar')
-rw-r--r-- | plugins/TopToolBar/common.h | 29 | ||||
-rw-r--r-- | plugins/TopToolBar/toolbar.cpp | 156 | ||||
-rw-r--r-- | plugins/TopToolBar/ttbopt.cpp | 119 |
3 files changed, 125 insertions, 179 deletions
diff --git a/plugins/TopToolBar/common.h b/plugins/TopToolBar/common.h index 26620cf85f..ea577b4c74 100644 --- a/plugins/TopToolBar/common.h +++ b/plugins/TopToolBar/common.h @@ -92,7 +92,6 @@ TopButtonInt* CreateButton(TTBButton* but); int ttbOptionsChanged();
int ArrangeButtons();
-int RecreateWindows();
#define DEFBUTTWIDTH 20
#define DEFBUTTHEIGHT 16
@@ -102,20 +101,17 @@ int RecreateWindows(); extern LIST<TopButtonInt> Buttons;
extern bool StopArrange;
-extern HWND OptionshWnd, hwndTopToolBar;
+extern HWND hwndTopToolBar;
extern HANDLE hHookTTBModuleLoaded;
extern HINSTANCE hInst;
extern LIST<void> arHooks, arServices;
extern HBITMAP hBmpBackground, hBmpSeparator;
extern int BUTTWIDTH, BUTTHEIGHT, BUTTGAP;
+extern CRITICAL_SECTION csButtonsHook;
void AddToOptions(TopButtonInt* b);
void RemoveFromOptions(int id);
-//int OptionsPageRebuild();
-void lockbut();
-void ulockbut();
-
//append string
char *AS(char *str, const char *setting, char *addstr)
{
@@ -128,21 +124,18 @@ char *AS(char *str, const char *setting, char *addstr) #define TTB_LAUNCHSERVICE "TTB/LaunchSerice"
-int LoadInternalButtons( HWND );
-int UnLoadInternalButtons( void );
-
-int LoadToolbarModule( void );
-int UnloadToolbarModule( void );
+INT_PTR TTBAddButton(WPARAM, LPARAM);
+INT_PTR TTBRemoveButton(WPARAM, LPARAM);
-int SetAllBitmaps( void );
-int SaveAllLButs( void );
-int SaveAllButtonsOptions( void );
+int LoadInternalButtons( HWND );
+int UnLoadInternalButtons( void );
-void lockbut();
-void ulockbut();
+int LoadToolbarModule( void );
+int UnloadToolbarModule( void );
-INT_PTR TTBAddButton(WPARAM, LPARAM);
-INT_PTR TTBRemoveButton(WPARAM, LPARAM);
+void SetAllBitmaps( void );
+int SaveAllLButs( void );
+int SaveAllButtonsOptions( void );
void InsertSeparator( int i );
void DeleteSeparator(int i);
diff --git a/plugins/TopToolBar/toolbar.cpp b/plugins/TopToolBar/toolbar.cpp index 8a39e73a09..238558439b 100644 --- a/plugins/TopToolBar/toolbar.cpp +++ b/plugins/TopToolBar/toolbar.cpp @@ -16,7 +16,7 @@ COLORREF bkColour; HBITMAP hBmpBackground, hBmpSeparator;
int backgroundBmpUse;
-static CRITICAL_SECTION csButtonsHook;
+CRITICAL_SECTION csButtonsHook;
static int hFrameTopWindow = -1;
int sortfunc(const TopButtonInt* a, const TopButtonInt* b)
@@ -26,24 +26,11 @@ int sortfunc(const TopButtonInt* a, const TopButtonInt* b) LIST<TopButtonInt> Buttons(8, sortfunc);
-void lockbut()
+static void SetAllBitmaps()
{
- EnterCriticalSection(&csButtonsHook);
-}
-
-void ulockbut()
-{
- LeaveCriticalSection(&csButtonsHook);
-}
-
-int SetAllBitmaps()
-{
- lockbut();
+ mir_cslock lck(csButtonsHook);
for (int i = 0; i < Buttons.getCount(); i++)
Buttons[i]->SetBitmap();
-
- ulockbut();
- return 0;
}
static TopButtonInt* idtopos(int id, int* pPos=NULL)
@@ -74,8 +61,7 @@ void LoadAllSButs() {
//must be locked
int cnt = DBGetContactSettingByte(0, TTB_OPTDIR, "ServiceCnt", 0);
- if (cnt > 0)
- {
+ if (cnt > 0) {
for (int i = 1; i<=cnt; i++)
InsertSBut(i);
}
@@ -137,16 +123,15 @@ void LoadAllSeparators() int SaveAllButtonsOptions()
{
- lockbut();
int SeparatorCnt = 0;
int LaunchCnt = 0;
-
- for (int i = 0; i < Buttons.getCount(); i++)
- Buttons[i]->SaveSettings(&SeparatorCnt, &LaunchCnt);
-
+ {
+ mir_cslock lck(csButtonsHook);
+ for (int i = 0; i < Buttons.getCount(); i++)
+ Buttons[i]->SaveSettings(&SeparatorCnt, &LaunchCnt);
+ }
DBWriteContactSettingByte(0, TTB_OPTDIR, "SepCnt", SeparatorCnt);
DBWriteContactSettingByte(0, TTB_OPTDIR, "LaunchCnt", LaunchCnt);
- ulockbut();
return 0;
}
@@ -178,14 +163,12 @@ int ttbOptionsChanged() INT_PTR TTBRemoveButton(WPARAM wParam, LPARAM lParam)
{
- lockbut();
+ mir_cslock lck(csButtonsHook);
int idx;
TopButtonInt* b = idtopos(wParam, &idx);
- if (b == NULL) {
- ulockbut();
+ if (b == NULL)
return -1;
- }
RemoveFromOptions(b->id);
@@ -193,16 +176,17 @@ INT_PTR TTBRemoveButton(WPARAM wParam, LPARAM lParam) delete b;
ArrangeButtons();
- ulockbut();
return 0;
}
-bool nameexists(const char *name)
+static bool nameexists(const char *name)
{
- if (name != NULL)
- for (int i = 0; i < Buttons.getCount(); i++)
- if ( !lstrcmpA(Buttons[i]->name, name))
- return true;
+ if (name == NULL)
+ return false;
+
+ for (int i = 0; i < Buttons.getCount(); i++)
+ if ( !lstrcmpA(Buttons[i]->name, name))
+ return true;
return false;
}
@@ -224,19 +208,22 @@ HICON LoadIconFromLibrary(char *Name, HICON hIcon, HANDLE& phIcolib) return Skin_GetIconByHandle(phIcolib);
}
-int RecreateWindows()
+static void ReloadIcons()
{
- lockbut();
+ mir_cslock lck(csButtonsHook);
for (int i = 0; i < Buttons.getCount(); i++) {
- TopButtonInt *b = Buttons[i];
- if (b->hwnd) {
- DestroyWindow(b->hwnd);
- b->CreateWnd();
+ TopButtonInt* b = Buttons[i];
+
+ char buf[256];
+ if (b->hIconHandleUp) {
+ sprintf(buf, "%s_up", b->name);
+ b->hIconUp = LoadIconFromLibrary(buf, b->hIconUp, b->hIconHandleUp);
+ }
+ if (b->hIconHandleDn) {
+ sprintf(buf, "%s_dn", b->name);
+ b->hIconDn = LoadIconFromLibrary(buf, b->hIconDn, b->hIconHandleDn);
}
}
-
- ulockbut();
- return (0);
}
TopButtonInt* CreateButton(TTBButton* but)
@@ -306,27 +293,22 @@ INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam) if (hwndContactList == 0)
return -1;
- lockbut();
+ TopButtonInt* b;
+ {
+ mir_cslock lck(csButtonsHook);
- TTBButton *but = (TTBButton*)wParam;
- if ((but->cbSize != sizeof(TTBButton)) ||
- (!(but->dwFlags && TTBBF_ISLBUTTON) && nameexists(but->name))) {
- ulockbut();
- return -1;
- }
+ TTBButton *but = (TTBButton*)wParam;
+ if (but->cbSize != sizeof(TTBButton) || (!(but->dwFlags && TTBBF_ISLBUTTON) && nameexists(but->name)))
+ return -1;
- TopButtonInt* b = CreateButton(but);
-
- b->LoadSettings();
- Buttons.insert(b);
- b->CreateWnd();
+ b = CreateButton(but);
+ b->LoadSettings();
+ Buttons.insert(b);
+ b->CreateWnd();
+ }
- ulockbut();
ArrangeButtons();
-// OptionsPageRebuild();
-
AddToOptions(b);
-
return b->id;
}
@@ -335,7 +317,7 @@ int ArrangeButtons() if (StopArrange == TRUE)
return 0;
- lockbut();
+ mir_cslock lck(csButtonsHook);
RECT winrc;
GetClientRect(hwndTopToolBar, &winrc);
@@ -381,8 +363,6 @@ int ArrangeButtons() }
StopArrange = false;
-
- ulockbut();
return 1;
}
@@ -393,18 +373,15 @@ int ArrangeButtons() //lparam = state
INT_PTR TTBSetState(WPARAM wParam, LPARAM lParam)
{
- lockbut();
+ mir_cslock lck(csButtonsHook);
TopButtonInt* b = idtopos(wParam);
- if (b == NULL) {
- ulockbut();
+ if (b == NULL)
return -1;
- }
b->bPushed = (lParam&TTBST_PUSHED)?TRUE:FALSE;
b->bPushed = (lParam&TTBST_RELEASED)?FALSE:TRUE;
b->SetBitmap();
- ulockbut();
return 0;
}
@@ -413,15 +390,12 @@ INT_PTR TTBSetState(WPARAM wParam, LPARAM lParam) //return = state
INT_PTR TTBGetState(WPARAM wParam, LPARAM lParam)
{
- lockbut();
+ mir_cslock lck(csButtonsHook);
TopButtonInt* b = idtopos(wParam);
- if (b == NULL) {
- ulockbut();
+ if (b == NULL)
return -1;
- }
int retval = (b->bPushed == TRUE) ? TTBST_PUSHED : TTBST_RELEASED;
- ulockbut();
return retval;
}
@@ -429,12 +403,10 @@ INT_PTR TTBGetOptions(WPARAM wParam, LPARAM lParam) {
INT_PTR retval;
- lockbut();
+ mir_cslock lck(csButtonsHook);
TopButtonInt* b = idtopos(wParam);
- if (b == NULL) {
- ulockbut();
+ if (b == NULL)
return -1;
- }
switch(LOWORD(wParam)) {
case TTBO_FLAGS:
@@ -479,7 +451,6 @@ INT_PTR TTBGetOptions(WPARAM wParam, LPARAM lParam) break;
}
- ulockbut();
return retval;
}
@@ -487,12 +458,10 @@ INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) {
int retval;
- lockbut();
+ mir_cslock lck(csButtonsHook);
TopButtonInt* b = idtopos(wParam);
- if (b == NULL) {
- ulockbut();
+ if (b == NULL)
return -1;
- }
switch(LOWORD(wParam)) {
case TTBO_FLAGS:
@@ -574,7 +543,6 @@ INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) break;
}
- ulockbut();
return retval;
}
@@ -717,12 +685,10 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara if ((HIWORD(wParam) == STN_CLICKED || HIWORD(wParam) == STN_DBLCLK)) {
int id = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
if (id != 0) {
- lockbut();
+ mir_cslock lck(csButtonsHook);
TopButtonInt* b = idtopos(id);
- if (b == NULL || b->isSep()) {
- ulockbut();
+ if (b == NULL || b->isSep())
return 0;
- }
// flag inversion inside condition coz we uses Up -> Down for non-push buttons
// condition and inversion can be moved to main condition end
@@ -744,7 +710,6 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara }
b->SetBitmap();
- ulockbut();
}
}
break;
@@ -796,22 +761,7 @@ static INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam) int OnIconChange(WPARAM wParam, LPARAM lParam)
{
- lockbut();
- for (int i = 0; i < Buttons.getCount(); i++) {
- TopButtonInt* b = Buttons[i];
-
- char buf[256];
- if (b->hIconHandleUp) {
- sprintf(buf, "%s_up", b->name);
- b->hIconUp = LoadIconFromLibrary(buf, b->hIconUp, b->hIconHandleUp);
- }
- if (b->hIconHandleDn) {
- sprintf(buf, "%s_dn", b->name);
- b->hIconDn = LoadIconFromLibrary(buf, b->hIconDn, b->hIconHandleDn);
- }
- }
- ulockbut();
-
+ ReloadIcons();
SetAllBitmaps();
return 0;
}
diff --git a/plugins/TopToolBar/ttbopt.cpp b/plugins/TopToolBar/ttbopt.cpp index 63a342c459..6f9565896b 100644 --- a/plugins/TopToolBar/ttbopt.cpp +++ b/plugins/TopToolBar/ttbopt.cpp @@ -1,6 +1,42 @@ #include "common.h"
-HWND OptionshWnd = 0;
+static HWND OptionshWnd;
+
+void AddToOptions(TopButtonInt* b)
+{
+ if (OptionshWnd) {
+ HWND hTree = GetDlgItem(OptionshWnd, IDC_BUTTONORDERTREE);
+ OrderData *dat = (struct OrderData*)GetWindowLongPtr(hTree, GWLP_USERDATA);
+ AddLine(hTree, b, TVI_LAST, dat->himlButtonIcons);
+ }
+}
+
+void RemoveFromOptions(int id)
+{
+ if (OptionshWnd) {
+ HWND hTree = GetDlgItem(OptionshWnd, IDC_BUTTONORDERTREE);
+ TVITEM tvi = { 0 };
+ tvi.hItem = TreeView_GetRoot(hTree);
+ tvi.mask = TVIF_PARAM | TVIF_HANDLE;
+
+ TopButtonInt* btn;
+ while(tvi.hItem != NULL) {
+ TreeView_GetItem(hTree, &tvi);
+ btn = (TopButtonInt*)tvi.lParam;
+ if (btn->id == id) {
+ // delete if was changed
+ if (btn->dwFlags & TTBBF_OPTIONAL)
+ delete btn;
+ TreeView_DeleteItem(hTree,tvi.hItem);
+ break;
+ }
+
+ tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
struct OrderData
{
@@ -9,7 +45,7 @@ struct OrderData HIMAGELIST himlButtonIcons;
};
-HTREEITEM AddLine(HWND hTree,TopButtonInt *b, HTREEITEM hItem, HIMAGELIST il)
+static HTREEITEM AddLine(HWND hTree,TopButtonInt *b, HTREEITEM hItem, HIMAGELIST il)
{
TVINSERTSTRUCT tvis = { 0 };
tvis.hInsertAfter = hItem;
@@ -46,7 +82,7 @@ HTREEITEM AddLine(HWND hTree,TopButtonInt *b, HTREEITEM hItem, HIMAGELIST il) return hti;
}
-int BuildTree(HWND hwndDlg)
+static int BuildTree(HWND hwndDlg)
{
HWND hTree = GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE);
OrderData *dat = (struct OrderData*)GetWindowLongPtr(hTree, GWLP_USERDATA);
@@ -64,51 +100,7 @@ int BuildTree(HWND hwndDlg) return TRUE;
}
-void AddToOptions(TopButtonInt* b)
-{
- if (OptionshWnd) {
- HWND hTree = GetDlgItem(OptionshWnd, IDC_BUTTONORDERTREE);
- OrderData *dat = (struct OrderData*)GetWindowLongPtr(hTree, GWLP_USERDATA);
- AddLine(hTree, b, TVI_LAST, dat->himlButtonIcons);
- }
-}
-
-void RemoveFromOptions(int id)
-{
- if (OptionshWnd) {
- HWND hTree = GetDlgItem(OptionshWnd, IDC_BUTTONORDERTREE);
- TVITEM tvi = { 0 };
- tvi.hItem = TreeView_GetRoot(hTree);
- tvi.mask = TVIF_PARAM | TVIF_HANDLE;
-
- TopButtonInt* btn;
- while(tvi.hItem != NULL) {
- TreeView_GetItem(hTree, &tvi);
- btn = (TopButtonInt*)tvi.lParam;
- if (btn->id == id) {
- // delete if was changed
- if (btn->dwFlags & TTBBF_OPTIONAL)
- delete btn;
- TreeView_DeleteItem(hTree,tvi.hItem);
- break;
- }
-
- tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
- }
- }
-}
-
-/*
-//call this when options opened and buttons added/removed
-int OptionsPageRebuild()
-{
- if (OptionshWnd)
- BuildTree(OptionshWnd);
-
- return 0;
-}
-*/
-void SaveTree(HWND hwndDlg)
+static void SaveTree(HWND hwndDlg)
{
HWND hTree = GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE);
@@ -135,15 +127,14 @@ void SaveTree(HWND hwndDlg) tmpList.insert(btn);
tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
}
+ {
+ mir_cslock lck(csButtonsHook);
+ for (int i=0; i < Buttons.getCount(); i++)
+ delete Buttons[i];
- lockbut();
- for (int i=0; i < Buttons.getCount(); i++)
- delete Buttons[i];
-
- Buttons = tmpList;
- tmpList.destroy();
-
- ulockbut();
+ Buttons = tmpList;
+ tmpList.destroy();
+ }
SaveAllButtonsOptions();
}
@@ -168,6 +159,18 @@ void CancelProcess(HWND hwndDlg) }
}
+static void RecreateWindows()
+{
+ mir_cslock lck(csButtonsHook);
+ for (int i = 0; i < Buttons.getCount(); i++) {
+ TopButtonInt *b = Buttons[i];
+ if (b->hwnd) {
+ DestroyWindow(b->hwnd);
+ b->CreateWnd();
+ }
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Options window: main
@@ -400,7 +403,8 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR break;
TopButtonInt *btn = (TopButtonInt*)((LPNMTREEVIEW)lParam)->itemNew.lParam;
- lockbut();
+
+ mir_cslock lck(csButtonsHook);
if (btn->dwFlags & TTBBF_ISLBUTTON) {
bool enable = (btn->dwFlags & TTBBF_INTERNAL) !=0;
@@ -428,7 +432,6 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR SetDlgItemTextA(hwndDlg, IDC_ENAME, "");
SetDlgItemTextA(hwndDlg, IDC_EPATH, "");
}
- ulockbut();
}
}
break;
|