void EditorBase::GetCompleteTextByPost(wyString &query, MDIWindow *wnd) { wyUInt32 nstrlen; wyChar *data; THREAD_MSG_PARAM tmp = {0}; //set the lparam sent if(GetWindowThreadProcessId(m_hwnd , NULL) == GetCurrentThreadId()) { nstrlen = SendMessage(m_hwnd, SCI_GETTEXTLENGTH, 0, 0); data = AllocateBuff(nstrlen + 1); SendMessage(m_hwnd, SCI_GETTEXT, (WPARAM)nstrlen+1, (LPARAM)data); query.SetAs(data); free(data); } else { if(WaitForSingleObject(pGlobals->m_pcmainwin->m_sqlyogcloseevent, 0) != WAIT_OBJECT_0 ) { query.SetAs(""); return; } tmp.m_lparam = (LPARAM)&query; tmp.m_hevent = CreateEvent(NULL, TRUE, FALSE, NULL); //now post the message to ui thread and wait for the event to be set PostMessage(wnd->GetHwnd(), UM_GETEDITORTEXT, (WPARAM)this->GetHWND(), (LPARAM)&tmp); if(WaitForSingleObject(tmp.m_hevent, 10000) == WAIT_TIMEOUT) { //CloseHandle(tmp.m_hevent); query.SetAs(""); //return; } //WaitForSingleObject(tmp.m_hevent, INFINITE); //close the event handle CloseHandle(tmp.m_hevent); tmp.m_hevent = NULL; //data = (wyChar*)tmp.m_lparam; } return; }
wyChar* BlobMgmt::Ucs2toUtf8(const wyChar *ucs2str, wyInt32 len) { wyWChar *lpszw = NULL; wyChar *utf8str = NULL; wyInt32 length = MultiByteToWideChar(CP_UTF8, 0, ucs2str, len, NULL, NULL ); lpszw = new wyWChar[length+1]; utf8str = AllocateBuff(length + 1); MultiByteToWideChar(CP_UTF8, 0, ucs2str, -1, lpszw, length); WideCharToMultiByte(CP_UTF8, 0, lpszw, -1, utf8str, length, NULL, NULL); utf8str[length] = 0; delete lpszw; return utf8str; }
void EditorBase::GetCompleteText(wyString &query) { wyUInt32 nstrlen; wyChar *data; nstrlen = SendMessage(m_hwnd, SCI_GETTEXTLENGTH, 0, 0); data = AllocateBuff(nstrlen + 1); SendMessage(m_hwnd, SCI_GETTEXT, (WPARAM)nstrlen+1, (LPARAM)data); query.SetAs(data); free(data); return; }
//Setting indentation in editor wyBool EditorBase::SetAutoIndentation(HWND hwnd, WPARAM wparam) { wyInt32 curline, prevlinelength, curpos, pos; wyChar *prevlinedata = NULL; wyString strdata; //if it is a enter key if(LOWORD(wparam) == VK_RETURN) { // for getting the current line in the editor curpos = SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); curline = SendMessage(hwnd, SCI_LINEFROMPOSITION, curpos, 0); if(curline > 0 ) { prevlinelength = SendMessage(hwnd, SCI_LINELENGTH, curline - 1 , 0); prevlinedata = AllocateBuff(prevlinelength + 1); SendMessage(hwnd, SCI_GETLINE,(WPARAM)curline - 1,(LPARAM)prevlinedata); prevlinedata[prevlinelength ] = '\0'; for(pos = 0; prevlinedata[pos]; pos++) { //if it is not a space or tab charater then we will replace that charater with '\0' if(prevlinedata[pos] != ' ' && prevlinedata[pos] != '\t') prevlinedata[pos] = '\0'; } strdata.SetAs(prevlinedata); SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)strdata.GetString()); if(prevlinedata) free(prevlinedata); return wyTrue; } } return wyFalse; }
// function to process file type Favorite// wyBool FavoriteBase::AddFile(HMENU hmenu, wyString &parentpath, wyWChar *filename) { wyInt32 i , j=0; wyUInt32 lengthwchar = 1; wyWChar ext[_MAX_EXT] = {0} , *data = {0}; wyChar *path = {0}; MENUITEMINFO lpmii={0}; parentpath.GetAsWideChar(&lengthwchar); path = AllocateBuff(parentpath.GetLength() + 2); data = AllocateBuffWChar(wcslen(filename) + 2); wcscpy(data, (wyWChar*)filename); strcpy(path, (wyChar*)parentpath.GetString()); for(i = wcslen(data) - 1; i && data[i]!='.'; i--, j++) ext[j] = data[i]; if(wcsnicmp(ext, L"lqs", 3) != 0) return wyFalse; ext[j] = 0; data[i] = 0; lpmii.cbSize = sizeof(MENUITEMINFO); lpmii.fMask = MIIM_STRING|MIIM_ID|MIIM_DATA; lpmii.wID = m_menuid++; lpmii.dwItemData = (ULONG_PTR)path; lpmii.cch = wcslen(data); lpmii.dwTypeData = data; VERIFY(::InsertMenuItem(hmenu, -1, TRUE, &lpmii)); free(data); return wyTrue; }
// Function to implement Find and Replace in Blob Viewer. wyBool BlobMgmt::FindOrReplace(HWND hwnd, wyBool uIsReplace) { static FINDREPLACE fr; static wyWChar texttofind[FIND_STR_LEN + 1]; static wyWChar texttoreplace[FIND_STR_LEN + 1]; wyChar *textfind = NULL; wyUInt32 start, end; wyString findtextstr; wyInt32 ret, len = 0; // set the flag pGlobals->m_findreplace = wyTrue; // prepare the structure. memset(&fr, 0, sizeof(FINDREPLACE)); fr.lStructSize = sizeof(FINDREPLACE); start = SendMessage(hwnd, SCI_GETSELECTIONSTART, 0, 0); end = SendMessage(hwnd, SCI_GETSELECTIONEND, 0, 0); len = (end - start)+ 1; textfind = AllocateBuff(len); ret = SendMessage(hwnd, SCI_GETSELTEXT, (WPARAM)len, (LPARAM)textfind); findtextstr.SetAs(textfind ); len = findtextstr.GetLength(); if(len > 256) { textfind[256] = 0; findtextstr.SetAs(textfind); } free(textfind ); //To remember last string in find dialog box if(len != 0) { //wcscpy(texttofind, findtextstr.GetAsWideChar()); wcsncpy(texttofind, findtextstr.GetAsWideChar(), FIND_STR_LEN); texttofind[FIND_STR_LEN] = '\0'; } if(!findtextstr.GetLength()) { //wcscpy(texttofind, pGlobals->m_pcmainwin->m_findtext.GetAsWideChar()); wcsncpy(texttofind, pGlobals->m_pcmainwin->m_findtext.GetAsWideChar(), FIND_STR_LEN); texttofind[FIND_STR_LEN] = '\0'; } else { pGlobals->m_pcmainwin->m_findtext.SetAs(findtextstr); } fr.hwndOwner = hwnd; fr.lpstrFindWhat = texttofind; fr.wFindWhatLen = FIND_STR_LEN; m_findreplace = new FindAndReplace(hwnd); if(uIsReplace) { fr.lpstrReplaceWith = texttoreplace; fr.wReplaceWithLen = FIND_STR_LEN; } else { if(pGlobals->m_pcmainwin->m_frstruct.hwndOwner == NULL) { pGlobals->m_pcmainwin->m_frstruct.hwndOwner = fr.hwndOwner; pGlobals->m_pcmainwin->m_frstruct.Flags = fr.Flags = FR_DOWN; } else { fr.Flags = pGlobals->m_pcmainwin->m_frstruct.Flags; } } // Call the appropriate function. if(uIsReplace && (GetFocus() == hwnd)) pGlobals->m_pcmainwin->m_finddlg = ReplaceText(&fr); else pGlobals->m_pcmainwin->m_finddlg = FindText(&fr); //subclass the FindText dialog if(!pGlobals->m_pcmainwin->m_findproc) { pGlobals->m_pcmainwin->m_findproc = (WNDPROC)SetWindowLongPtr(pGlobals->m_pcmainwin->m_finddlg, GWLP_WNDPROC, (LONG_PTR)FindAndReplace::FindWndProc); } return wyTrue; }
wyBool BlobMgmt::ProcessOK() { wyChar *newbuf = {0}; wyInt32 bufsize, sel; wyString newdatastr, codepagestr; // check in three steps if(SendMessage(GetDlgItem(m_hwnddlg, IDC_SETNULL), BM_GETCHECK, 0, 0) == BST_CHECKED) { m_newdata = NULL; m_piub->m_isnull = wyTrue; m_piub->m_ischanged = wyTrue; return wyTrue; } sel = TabCtrl_GetCurSel(m_hwndtab); // then we see whether edit box has been modified if(sel == 0 && SendMessage(m_hwndedit, SCI_GETMODIFY, 0, 0) && m_isencodingchanged == wyFalse) { bufsize = SendMessage(m_hwndedit, SCI_GETTEXTLENGTH, 0, 0); VERIFY(newbuf = AllocateBuff(bufsize + 2)); bufsize = SendMessage(m_hwndedit, SCI_GETTEXT, bufsize + 1,(LPARAM)newbuf); m_piub->m_data = (wyChar *)newbuf; m_piub->m_datasize = bufsize; m_piub->m_isnull = wyFalse; m_piub->m_ischanged = wyTrue; return wyTrue; } // we change the blob otherwise if(sel == 1 && m_olddata != m_piub->m_data && m_isencodingchanged == wyFalse) { m_piub->m_olddata = m_olddata; m_piub->m_isnull = wyFalse; m_piub->m_ischanged = wyTrue; return wyTrue; } if(m_isencodingchanged == wyTrue) { bufsize = SendMessage(m_hwndedit, SCI_GETTEXTLENGTH, 0, 0); VERIFY(newbuf = AllocateBuff(bufsize + 2)); bufsize = SendMessage(m_hwndedit, SCI_GETTEXT, bufsize + 1,(LPARAM)newbuf); m_piub->m_data = (wyChar *)newbuf; m_piub->m_datasize = bufsize; m_piub->m_isnull = wyFalse; m_piub->m_ischanged = wyTrue; m_blobdata.SetAs(newbuf); ProcessComboSelection(m_changedcombotext); return wyTrue; } if((sel == 0 || sel == 1)&& m_checkboxstate == BST_CHECKED) { VERIFY(newbuf = AllocateBuff(1)); newbuf[0] = '\0'; m_piub->m_data = (wyChar *)newbuf; m_piub->m_datasize = 0; m_piub->m_isnull = wyFalse; m_piub->m_ischanged = wyTrue; return wyTrue; } m_piub->m_olddata = NULL; m_piub->m_olddatasize = 0; m_piub->m_data = m_olddata; m_piub->m_datasize = m_olddatasize; m_piub->m_ischanged = wyFalse; return wyFalse; }
void TableMakerAdvProperties::FillStructure () { wyInt32 selindex; HWND hwndcombo; wyWChar textbuf[512]= {0}; // none of the value will go more then this and neway we send the max len to the api so it will not fail wyChar *commentbuff = {0}; wyBool ismysql41 = IsMySQL41(m_tunnel, m_mysql); wyString rowformat, enginestr; // now we start getting all the text. // 1. With the table type. VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_TYPE)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR ); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); //if default is selected then it should take 'default'(with quotes) enginestr.SetAs(textbuf); if(enginestr.CompareI(STR_DEFAULT) == 0) m_advprop->m_type.SetAs("'Default'"); else m_advprop->m_type.SetAs(textbuf); //2. With the checksum thing. VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_CHECKSUM)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); m_advprop->m_checksum.SetAs(textbuf); if(ismysql41 == wyTrue) { textbuf[0] = NULL; VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_TABCHARSET)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); if(wcslen(textbuf) == 0) m_advprop->m_charset.SetAs(STR_DEFAULT); else m_advprop->m_charset.SetAs(textbuf); textbuf[0] = NULL; VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_TABCOLLATION)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); if(wcslen(textbuf) == 0) m_advprop->m_collation.SetAs(STR_DEFAULT); else m_advprop->m_collation.SetAs(textbuf); } // 3. The autoincr thing. SendMessage(GetDlgItem(m_hwnd, IDC_AUTOINCR), WM_GETTEXT, 15, (LPARAM)textbuf); m_advprop->m_auto_incr.SetAs(textbuf); // 4. The average row thing. SendMessage(GetDlgItem(m_hwnd, IDC_AVGROW), WM_GETTEXT, 15, (LPARAM)textbuf); m_advprop->m_avg_row.SetAs(textbuf); // 5. The comment thing. SendMessage(GetDlgItem(m_hwnd, IDC_COMMENT ), WM_GETTEXT, 511, (LPARAM)textbuf); m_advprop->m_comment.SetAs(textbuf); // Escape the comment string commentbuff = AllocateBuff((m_advprop->m_comment.GetLength() + 1) * 2); // Considering allocation including escape characters m_tunnel->mysql_real_escape_string(*m_mysql, commentbuff, m_advprop->m_comment.GetString(), m_advprop->m_comment.GetLength()); m_advprop->m_comment.SetAs(commentbuff); // 6. The max row thing. SendMessage(GetDlgItem(m_hwnd, IDC_MAXROW), WM_GETTEXT, 15, (LPARAM)textbuf); m_advprop->m_max_rows.SetAs(textbuf); // 7. The max row thing. SendMessage(GetDlgItem(m_hwnd, IDC_MINROW), WM_GETTEXT, 15, (LPARAM)textbuf); m_advprop->m_min_rows.SetAs(textbuf); // 9. The delay thing. VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_DELAYKEY)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); m_advprop->m_delay.SetAs(textbuf); // 10. The row format thing. VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_ROWFORMAT)); VERIFY((selindex = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0)) != CB_ERR); SendMessage(hwndcombo, CB_GETLBTEXT, selindex, (LPARAM)textbuf); rowformat.SetAs(textbuf); // bug reported in http://www.webyog.com/forums//index.php?showtopic=3887 (solved in 6.52) if(rowformat.CompareI(STR_DEFAULT) == 0) m_advprop->m_rowformat.SetAs("Default"); else m_advprop->m_rowformat.SetAs(textbuf); // 12. The chunks thing. SendMessage(GetDlgItem(m_hwnd, IDC_CHUNKS), WM_GETTEXT, 511, (LPARAM)textbuf); m_advprop->m_chunks.SetAs(textbuf); // 13. The chunks size thing. SendMessage(GetDlgItem(m_hwnd, IDC_CHUNKSIZE), WM_GETTEXT, 511, (LPARAM)textbuf); m_advprop->m_chunksize.SetAs(textbuf); m_advprop->m_changed = wyTrue; free(commentbuff); }
wyBool ExportAsSimpleSQL::AddValues(ExportSQLData *data, wyString &value) { wyInt32 count, last, lenrow; wyString temp, resrow, buffer; wyInt32 *lengths = NULL; wyInt32 escapeddatalen; wyBool startflag = wyFalse; if(WriteToFile(value) == wyFalse) return wyFalse; //this condition is true if export from from result tab if result set is not edited if(!data->m_tabrec->m_rowarray) { if(m_isdatafromquery == wyTrue) { lengths = (wyInt32 *)sja_mysql_fetch_lengths(m_tunnel, m_myres); } else { lengths = (wyInt32 *)m_rowlength; } } for(count = 0; count < data->m_result->field_count; count++) { if(data->m_selcol[count] == wyFalse) continue; if(startflag == wyTrue) buffer.Add(","); /// Check for NULL value or not if(!m_myrow[count]) { buffer.Add("NULL"); startflag = wyTrue; continue; } if(m_escapeddata) free(m_escapeddata); //This condion true if the result tab in table tab or edit mode or result set is edited if(!lengths) { resrow.SetAs(m_myrow[count]); lenrow = resrow.GetLength(); } else { lenrow = lengths[count]; } //It requires double buffer bcs the real_escape_string returns 2 char for special chars like '\' escapeddatalen = (lenrow * 2) + 1; m_escapeddata = AllocateBuff(escapeddatalen); last = sja_mysql_real_escape_string(m_tunnel, *m_mysql, m_escapeddata, m_myrow[count], lenrow); m_escapeddata[last] = 0; buffer.Add("'"); startflag = wyTrue; buffer.Add(m_escapeddata); buffer.Add("'"); } //Write to file WriteToFile(buffer); buffer.SetAs(""); value.SetAs(""); return wyTrue; }