INT_PTR CALLBACK OptDlgProc(HWND hDlg,UINT msg,WPARAM wparam,LPARAM lparam) { RECT rect; plgsettings *ps; //0: current; 1: original logmsg("OptDlgProc"); switch(msg){ case WM_INITDIALOG: logmsg("OptDlgProc::INITDIALOG"); TranslateDialogDefault(hDlg); ps=(plgsettings*)malloc(sizeof(plgsettings)*2); loadDBSettings(&ps[0]); ps[1]=ps[0]; SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)ps); SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_SIZEBOX); SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED); SetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE)|TVS_NOHSCROLL|TVS_CHECKBOXES); SetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE2),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hDlg,IDC_TREE1),GWL_STYLE)|TVS_NOHSCROLL|TVS_CHECKBOXES); CheckDlgButton(hDlg, IDC_RADIO1+ps->align-1, BST_CHECKED); CheckDlgButton(hDlg, IDC_RADIO10+9-ps->salign, BST_CHECKED); CheckDlgButton(hDlg, IDC_CHECK1, ps->altShadow); CheckDlgButton(hDlg, IDC_CHECK2, ps->showMsgWindow); CheckDlgButton(hDlg, IDC_CHECK3, ps->transparent); CheckDlgButton(hDlg, IDC_CHECK4, ps->showShadow); CheckDlgButton(hDlg, IDC_CHECK5, ps->messages); SetDlgItemText(hDlg, IDC_EDIT2, ps->msgformat); CheckDlgButton(hDlg, IDC_CHECK6, ps->a_user); CheckDlgButton(hDlg, IDC_CHECK7, ps->showmystatus); SetDlgItemInt(hDlg, IDC_EDIT1, ps->distance, 0); SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_SETRANGE, 0, MAKELONG(0, 255)); SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_SETPOS, TRUE, (LPARAM)ps->alpha); { TCHAR buf[20]; mir_sntprintf(buf, SIZEOF(buf), _T("%d %%"), ps->alpha*100/255); SetDlgItemText(hDlg, IDC_ALPHATXT, buf); } SetDlgItemInt(hDlg, IDC_EDIT5, ps->timeout, 0); FillCheckBoxTree(GetDlgItem(hDlg, IDC_TREE1), ps->announce); FillCheckBoxTree(GetDlgItem(hDlg, IDC_TREE2), ps->showWhen); return 0; case WM_HSCROLL: if (LOWORD(wparam)==SB_ENDSCROLL||LOWORD(wparam)==SB_THUMBPOSITION||LOWORD(wparam)==SB_ENDSCROLL) return 0; ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); ps->alpha=SendDlgItemMessage(hDlg, IDC_SLIDER1, TBM_GETPOS, 0, 0); { TCHAR buf[20]; mir_sntprintf(buf, SIZEOF(buf), _T("%d %%"), ps->alpha*100/255); SetDlgItemText(hDlg, IDC_ALPHATXT, buf); } goto xxx; case WM_DESTROY: logmsg("OptDlgProc::DESTROY"); ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); ps[0]=ps[1]; saveDBSettings(&ps[0]); SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_FRAMECHANGED); SetWindowPos(hwnd, 0, ps->winxpos, ps->winypos, ps->winx, ps->winy, SWP_NOZORDER|SWP_NOACTIVATE); SetLayeredWindowAttributes(hwnd, ps->bkclr, ps->alpha, (ps->transparent?LWA_COLORKEY:0)|LWA_ALPHA); free((void*)GetWindowLongPtr(hDlg, GWLP_USERDATA)); return 0; case WM_COMMAND: logmsg("OptDlgProc::COMMAND"); ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); switch (LOWORD(wparam)) { case IDC_BUTTON7: MessageBox(hDlg, TranslateT("Variables:\n %n : Nick\n %m : Message\n %l : New line"), TranslateT("Help"), MB_ICONINFORMATION|MB_OK); return 0; case IDC_BUTTON5: SendMessage(hwnd, WM_USER+1, (WPARAM)TranslateT("Miranda NG is great and this is a long message."), 0); break; case IDC_BUTTON1: selectFont(hDlg, &(ps->lf)); break; case IDC_BUTTON2: selectColor(hDlg, &ps->clr_status); break; case IDC_BUTTON6: selectColor(hDlg, &ps->clr_msg); break; case IDC_BUTTON3: selectColor(hDlg, &ps->clr_shadow); break; case IDC_BUTTON4: selectColor(hDlg, &ps->bkclr); break; case IDC_CHECK4: ps->showShadow=IsDlgButtonChecked(hDlg, IDC_CHECK4); break; case IDC_CHECK1: ps->altShadow=IsDlgButtonChecked(hDlg, IDC_CHECK1); break; case IDC_CHECK2: ps->showMsgWindow=IsDlgButtonChecked(hDlg, IDC_CHECK2); case IDC_EDIT1: ps->distance=GetDlgItemInt(hDlg, IDC_EDIT1, 0, 0); break; case IDC_EDIT5: ps->timeout=GetDlgItemInt(hDlg, IDC_EDIT5, 0, 0); break; case IDC_CHECK3: ps->transparent=IsDlgButtonChecked(hDlg, IDC_CHECK3); break; case IDC_CHECK5: ps->messages=IsDlgButtonChecked(hDlg, IDC_CHECK5); break; case IDC_CHECK6: ps->a_user=IsDlgButtonChecked(hDlg, IDC_CHECK6); break; case IDC_CHECK7: ps->showmystatus=IsDlgButtonChecked(hDlg, IDC_CHECK7); break; case IDC_RADIO1: case IDC_RADIO2: case IDC_RADIO3: case IDC_RADIO4: case IDC_RADIO5: case IDC_RADIO6: case IDC_RADIO7: case IDC_RADIO8: case IDC_RADIO9: if (IsDlgButtonChecked(hDlg, LOWORD(wparam))) ps->align=LOWORD(wparam)-IDC_RADIO1+1; break; case IDC_RADIO10: case IDC_RADIO11: case IDC_RADIO12: case IDC_RADIO13: case IDC_RADIO14: case IDC_RADIO15: case IDC_RADIO16: case IDC_RADIO17: case IDC_RADIO18: if (IsDlgButtonChecked(hDlg, LOWORD(wparam))) ps->salign=10-(LOWORD(wparam)-IDC_RADIO10+1); break; } xxx: saveDBSettings(ps); SetWindowPos(hwnd, 0, 0, 0, ps->winx, ps->winy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); SetLayeredWindowAttributes(hwnd, db_get_dw(NULL,THIS_MODULE, "bkclr", DEFAULT_BKCLR), db_get_b(NULL,THIS_MODULE, "alpha", DEFAULT_ALPHA), (db_get_b(NULL,THIS_MODULE, "transparent", DEFAULT_TRANPARENT)?LWA_COLORKEY:0)|LWA_ALPHA); InvalidateRect(hwnd, 0, TRUE); SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); return 0; case WM_NOTIFY: logmsg("OptDlgProc::NOTIFY"); switch(((LPNMHDR)lparam)->code){ case TVN_SETDISPINFO: case NM_CLICK: case NM_RETURN: case TVN_SELCHANGED: if (((LPNMHDR)lparam)->idFrom==IDC_TREE1) SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); break; case PSN_APPLY: ps=(plgsettings*)GetWindowLongPtr(hDlg, GWLP_USERDATA); GetWindowRect(hwnd, &rect); ps->winx=rect.right-rect.left; ps->winy=rect.bottom-rect.top; ps->winxpos=rect.left; ps->winypos=rect.top; ps->announce=MakeCheckBoxTreeFlags(GetDlgItem(hDlg, IDC_TREE1)); ps->showWhen=MakeCheckBoxTreeFlags(GetDlgItem(hDlg, IDC_TREE2)); GetDlgItemText(hDlg, IDC_EDIT2, ps->msgformat, 255); ps[1]=ps[0]; //apply current settings at closing saveDBSettings(ps); SetLayeredWindowAttributes(hwnd, db_get_dw(NULL,THIS_MODULE, "bkclr", DEFAULT_BKCLR), db_get_b(NULL,THIS_MODULE, "alpha", DEFAULT_ALPHA), (db_get_b(NULL,THIS_MODULE, "transparent", DEFAULT_TRANPARENT)?LWA_COLORKEY:0)|LWA_ALPHA); InvalidateRect(hwnd, 0, TRUE); break; } break; } return 0; }
DBConfWindow::~DBConfWindow() { if (!saved) { QMessageBox msgBox; msgBox.setText("The database configuration has been modified."); msgBox.setInformativeText("Do you want to save your changes?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save); int ret = msgBox.exec(); switch (ret) { case QMessageBox::Save: // Save was clicked saveDBSettings(); break; case QMessageBox::Discard: // Don't Save was clicked break; case QMessageBox::Cancel: // Cancel was clicked // TODO: this message box thing should not be in the destructor, but should trap the close signal break; default: // should never be reached break; } } }
/** @brief Catch the OK button pression * @see saveDBSettings */ void settingsUi::okPressed() { saveDBSettings(); this->close(); }