In the Libharu thread I alluded to a Find feature I added to Ddoc 9c. When 9i came out Don made the source available.
Michael expressed an interest in the feature and I had to start documenting what I had done a couple of years ago to add the find function to Ddoc.
The find function adds a toolbar item in form of binoculars which pops up a dialog into which a search key can be typed. You can set forward or backward search and whether or not to match case.
Anyway, instead of posting all the code I am posting my personal documentation of what I did on version 9c. Hopefully it will be helpful.
DDOC changes to add simple find and highlight function to DDOC version 9c
Needed to do this anyway to add to version 9i. Hopefully things will not be that hard to find
Originally made in 03/04
DDOC.BAS
After GLOBAL gMaxHeight
After DECLARE SUB JumpBox()
After SUB SaveEXEFile()
DDOC_DLG.BAS
After CASE %mnuJum, %tbJump
After the END SUB of the function JumpPage()
ddoc_IMG.BAS
Insert between
SetTextAlign dcOut, iFontBaseline and
TextOut dcOut, i&, j&, zText, LEN(zText)
this code
DDOC_REC.INC
In order to compile in 7.04 I found that a small change had to be made in ddoc_sup.bas
FUNCTION GetTempFile(seed$, Eext$) AS STRING
Originally there was an Ext$. I just found all locations in the program and changed to Eext$
Attached is the modified toolbar.bmp
Bob Mechler
Michael expressed an interest in the feature and I had to start documenting what I had done a couple of years ago to add the find function to Ddoc.
The find function adds a toolbar item in form of binoculars which pops up a dialog into which a search key can be typed. You can set forward or backward search and whether or not to match case.
Anyway, instead of posting all the code I am posting my personal documentation of what I did on version 9c. Hopefully it will be helpful.
DDOC changes to add simple find and highlight function to DDOC version 9c
Needed to do this anyway to add to version 9i. Hopefully things will not be that hard to find
Originally made in 03/04
DDOC.BAS
After GLOBAL gMaxHeight
Code:
GLOBAL gGo AS LONG ' added by bob mechler GLOBAL gSearchtxt AS STRING ' added by bob mechler GLOBAL gtxtloc AS LONG ' added by bob mechler GLOBAL gmcase AS LONG ' added by bob mechler GLOBAL gypos AS LONG ' added by bob mechler GLOBAL gfirstime AS LONG ' added by bob mechler
Code:
DECLARE SUB FindMyText() 'added by bob mechler
Code:
DECLARE CALLBACK FUNCTION ShowFINDDLGProc() DECLARE FUNCTION ShowFINDDLG(BYVAL hParent AS DWORD) AS LONG 'added by bob mechler end
After CASE %mnuJum, %tbJump
Code:
CASE %mnuFind, %tbFind 'added by bob mechler ShowFINDDLG %HWND_DESKTOP 'added by bob mechler Change %TOOLBAR_BUTTON_COUNT = 12 to %TOOLBAR_BUTTON_COUNT = 13 'added by bob mechler was 12
Code:
Change 'tbb(10).iBitmap = 0 'tbb(10).idCommand = 0 'tbb(10).fsState = %TBSTATE_ENABLED 'tbb(10).fsStyle = %TBSTYLE_SEP to tbb(10).iBitmap = 10 'added by bob mechler start tbb(10).idCommand = %tbFind tbb(10).fsState = %TBSTATE_ENABLED tbb(10).fsStyle = %TBSTYLE_BUTTON 'added by bob mechler end
Code:
CALLBACK FUNCTION ShowFINDDLGProc() 'added by bob mechler start LOCAL c_searchtxt AS STRING,yn AS INTEGER LOCAL nextlook AS LONG, i AS INTEGER, colloc AS LONG,lastfind AS LONG STATIC c_direction AS STRING,c_curpage AS LONG,v_pagepos AS DOUBLE,pageheight AS LONG IF c_direction = "" THEN c_direction = "D" SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler gmcase = 0: c_curpage = gCurDoc.CurPage SetWindowPos CBHNDL,%HWND_TOPMOST,0,0,0,0,%SWP_NOMOVE OR %SWP_NOSIZE CASE %WM_SETFOCUS c_curpage = gCurDoc.CurPage CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDT_FINDIT IF CBCTLMSG = %EN_KILLFOCUS THEN CONTROL GET TEXT CBHNDL,%IDT_FINDIT TO gSearchTxt gfirstime = -1 CreateOffScreen pageheight = gCurDoc.ppiY * gCurDoc.PaperHeight * gCurDoc.CurZoom v_pagepos = (CDBL(gypos) / CDBL(pageheight)) * 100 SetScrollPos gScrVert, %SB_CTL, CLNG(v_pagepos), %True RefreshPage END IF CASE %IDOK IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET TEXT CBHNDL,%IDT_FINDIT TO gSearchTxt IF c_direction = "D" AND LEN(TRIM$(gsearchtxt)) > 0 THEN FOR i = c_curpage TO gHeader.PageCount gfirstime = -1 IF i = 1 THEN CachePage i 'test1 'FirstPage ELSE CachePage i 'test1 'NextPage END IF IF gmcase THEN gtxtloc = INSTR(gPage,gsearchtxt ) ELSE gtxtloc = INSTR(UCASE$(gPage),UCASE$(gsearchtxt )) END IF IF gtxtloc AND LEN(TRIM$(gsearchtxt)) > 0 THEN gCurDoc.CurPage = i 'test 1 SetStatusBar 'test 1 SetButtons 'test 1 CreateOffScreen 'test 1 pageheight = gCurDoc.ppiY * gCurDoc.PaperHeight * gCurDoc.CurZoom v_pagepos = (CDBL(gypos) / CDBL(pageheight)) * 100 SetScrollPos gScrVert, %SB_CTL, CLNG(v_pagepos), %True RefreshPage c_curpage = i IF c_curpage < gHeader.PageCount THEN INCR c_curpage END IF EXIT FOR END IF NEXT IF gtxtloc = 0 AND i >= gHeader.PageCount THEN CONTROL DISABLE CBHNDL,%IDOK MSGBOX "Print Preview can not find any more of the search items",%MB_OK,"End of Search!" CONTROL ENABLE CBHNDL,%IDOK 'DECR c_curpage: DECR c_curpage CONTROL SEND CBHNDL,%IDC_UP,%BM_CLICK,0,0 END IF ELSEIF c_direction = "U" THEN FOR i = c_curpage TO 1 STEP -1 gfirstime = -1 IF i = gHeader.PageCount THEN CachePage i 'LastPage ELSE CachePage i 'PrevPage END IF IF gmcase THEN gtxtloc = INSTR(gPage,gsearchtxt ) ELSE gtxtloc = INSTR(UCASE$(gPage),UCASE$(gsearchtxt )) END IF IF gtxtloc AND LEN(TRIM$(gsearchtxt)) > 0 THEN gCurDoc.CurPage = i 'test 1 SetStatusBar 'test 1 SetButtons 'test 1 CreateOffScreen 'test 1 pageheight = gCurDoc.ppiY * gCurDoc.PaperHeight * gCurDoc.CurZoom v_pagepos = (CDBL(gypos) / CDBL(pageheight)) * 100 SetScrollPos gScrVert, %SB_CTL, CLNG(v_pagepos), %True RefreshPage c_curpage = i IF c_curpage > 1 THEN DECR c_curpage END IF EXIT FOR END IF NEXT IF gtxtloc = 0 AND i <= 1 THEN CONTROL DISABLE CBHNDL,%IDOK MSGBOX "Print Preview can not find any more of the search items",%MB_OK,"End of Search!" CONTROL ENABLE CBHNDL,%IDOK 'INCR c_curpage: INCR c_curpage CONTROL SEND CBHNDL,%IDC_OPDOWN,%BM_CLICK,0,0 END IF END IF END IF CASE %IDC_CLOSE IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN gSearchTxt = "" CreateOffScreen DIALOG END CBHNDL,0 END IF CASE %IDC_Up IF CBCTLMSG = %BN_CLICKED THEN c_direction = "U" c_curpage = gCurDoc.CurPage - 1 'DECR c_curpage CONTROL SET TEXT CBHNDL,%IDOK,"Find &Previous Page" END IF CASE %IDC_OPDOWN IF CBCTLMSG = %BN_CLICKED THEN c_direction = "D" c_curpage = gCurDoc.CurPage + 1 'INCR c_curpage CONTROL SET TEXT CBHNDL,%IDOK,"Find &Next Page" END IF CASE %IDC_Case IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN CONTROL GET CHECK CBHNDL,%IDC_CASE TO gmcase CreateOffScreen END IF END SELECT END SELECT END FUNCTION FUNCTION ShowFINDDLG(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG,lrunning AS LONG STATIC hDlg AS DWORD CONTROL HANDLE hdlg,%IDT_FINDIT TO lrunning IF lrunning <> 0 THEN EXIT FUNCTION END IF DIALOG NEW hParent, "Find", 250, 20, 210, 70, %WS_POPUP OR %WS_BORDER OR _ %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _ %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _ %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_TOPMOST, TO hDlg CONTROL ADD LABEL, hDlg, %IDL_Find, "Fi&nd What :", 5, 7, 40, 10 CONTROL ADD TEXTBOX, hDlg, %IDT_FINDIT, "", 45, 5, 110, 12 CONTROL ADD CHECKBOX, hDlg, %IDC_CASE,"Match &Case",10,35,60,12 CONTROL ADD BUTTON, hDlg, %IDOK, "Find &Next Page", 135, 25, 70, 15 CONTROL ADD BUTTON, hDlg, %IDC_CLOSE, "C&lose", 135, 45, 70, 15 CONTROL ADD OPTION, hDlg, %IDC_Up, "&Up", 75, 30, 45, 15 CONTROL ADD OPTION, hDlg, %IDC_OPDOWN, "&Down", 75, 45, 45, 15 CONTROL SET OPTION hDlg, %IDC_OPDOWN,%IDC_UP,%IDC_OPDOWN CONTROL ADD FRAME, hDlg, %IDC_DIR, "Direction", 70, 20, 55, 45 DIALOG SHOW MODAL hDlg, CALL ShowFINDDLGProc TO lRslt FUNCTION = lRslt END FUNCTION 'added by bob mechler end
Insert between
SetTextAlign dcOut, iFontBaseline and
TextOut dcOut, i&, j&, zText, LEN(zText)
this code
Code:
IF gmcase THEN 'added by bob mechler start gtxtloc = INSTR(zText,gsearchtxt ) ELSE gtxtloc = INSTR(UCASE$(zText),UCASE$(gsearchtxt )) END IF IF gtxtloc AND LEN(TRIM$(gsearchtxt)) > 0 THEN rfont.colr = RGB(255,0,0) IF gfirstime THEN gypos = j& gfirstime = 0 END IF ELSE rfont.colr = RGB(0,0,0) END IF GOSUB set_font 'added by bob mechler end
Code:
Added %mnuFind = 720 Added %tbFind = 761 Added at end of file after %MAX_COMMAND_PARAMS = 7 '- Find dialog constants added by bob mechler start %IDD_FINDDLG = 1000 %IDL_Find = 1001 %IDT_FINDIT = 1002 %IDC_BUTTON3 = 1005 '* %IDC_FRAME1 = 1006 '* %IDC_Up = 1007 %IDC_OPDOWN = 1008 %IDC_DIR = 1009 %IDC_Next = 1003 %IDC_CLOSE = 1004 %IDC_TOP = 1010 %IDC_Case = 1011 'added by bob mechler start end
FUNCTION GetTempFile(seed$, Eext$) AS STRING
Originally there was an Ext$. I just found all locations in the program and changed to Eext$
Attached is the modified toolbar.bmp
Bob Mechler