/****************************** Module Header ******************************* * * Module Name: toolbar.e * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ ; Moved from STDCTRL.E ; Used terms: ; default toolbar = toolbar name from NEPMD.INI (maybe different from ; the active toolbar) ; standard toolbar = toolbar of standard EPM = built-in toolbar compile if not defined( SMALL) -- If compiled separately EA_comment 'This defines toolbar macros.' define INCLUDING_FILE = 'TOOLBAR.E' include 'stdconst.e' const tryinclude 'mycnf.e' const compile if not defined( NLS_LANGUAGE) NLS_LANGUAGE = 'ENGLISH' compile endif include NLS_LANGUAGE'.e' compile endif ; --------------------------------------------------------------------------- const -- Use the normal-sized or the tiny icons for the built-in toolbar? compile if not defined( WANT_TINY_ICONS) WANT_TINY_ICONS = 0 compile endif ; --------------------------------------------------------------------------- ; This defc is called by the etke*.dll to generate the list of actions for ; UCMENUS in the hidden file called .actlist. ; If called with a pointer parameter, a buffer is created in which the list ; of actions are placed (used for toolbar buffet creation). ; If called without any parameter, the .actlist file is generated. ; John Ponzo 8/93 ; Optimized by LAM ; ; This is only called on creating or modifying a toolbar button. ; A button action itself is saved in the toolbar data together with the ; .ex filename where it is defined. On execution the ExecuteAction command ; is called, that links the .ex file when the action is undefined. defc Load_Actions universal actionslist_fileid -- Keep track of the active file getfileid activefileid -- See, if the actlist file is already loaded. If not, load it. if actionslist_fileid <> '' then -- Make sure it's still loaded. rc = 0 display -2 activatefile actionslist_fileid display 2 if rc = -260 then actionslist_fileid = '' endif endif if actionslist_fileid == '' then -- Must create 'xcom e /c .actlist' if rc <> -282 then -- sayerror( 'New file') 'SayError 'ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext( rc)'.' return endif getfileid actionslist_fileid .visible = 0 -- Load the actions.lst file which contains the names of all the EX modules -- that have UCMENU actions defined. getfileid actionsfilesfid, 'actions.lst' if actionsfilesfid == '' then findfile destfilename, 'actions.lst', '','D' if rc = -2 then -- "File not found" 'xcom e /c actions.lst' deleteline 1 .modify = 0 else 'xcom e' destfilename if rc then 'SayError 'ERROR__MSG rc '"'destfilename'"' sayerrortext( rc)'.' return endif endif getfileid actionsfilesfid fQuitActionsFile = 1 else fQuitActionsFile = 0 endif -- Load all the EX Modules in actlist.lst, and call EX modules -- actionlist defc. for i = 1 to actionsfilesfid.last getline LineStr, i, actionsfilesfid StrippedLineStr = strip( LineStr) -- Ignore comments, lines starting with ';' at column 1 are comments if substr( LineStr, 1, 1) = ';' then iterate -- Ignore empty lines elseif StrippedLineStr = '' then iterate endif ExFile = StrippedLineStr -- Strip extension if rightstr( upcase( ExFile), 3) = '.EX' then ExFile = substr( ExFile, 1, length( ExFile) - 3) endif fLinkedBefore = (linked( ExFile) >= 0) if not fLinkedBefore then link ExFile -- without msg linkrc = rc if rc < 0 then 'SayError Load_Actions: 'sayerrortext( rc) '-' ExFile'.' fLinkedAfter = 0 -- Don't try to unlink it. else fLinkedAfter = 1 endif endif -- Execute _actionlist command of listed .ex file ExFile'_actionlist' if not fLinkedBefore and fLinkedAfter then -- Standard unlink needs full pathname if .ex file not in current path. -- This is fixed now for def unlink, not for the statement. 'UnLink QUIET 'ExFile endif endfor if fQuitActionsFile then activatefile actionsfilesfid 'xcom quit' endif endif -- actionslist_fileid == '' -- If called with a parameter send EFRAME_ACTIONSLIST message to the frame -- of the edit window. mp1 is a buffer containing all of the actions loaded -- in the hidden file actlist. -- Called with an arg when the toolbar buffet shall be created. if arg( 1) then activatefile actionslist_fileid buflen = filesize() + .last + 1 bufhandle = buffer( CREATEBUF, '', buflen, 1) if not bufhandle then 'SayError CREATEBUF 'ERROR_NUMBER__MSG RC'.' return endif call buffer( PUTBUF, bufhandle, 1, actionslist_fileid.last, NOHEADER + FINALNULL + APPENDCR) if word( arg( 1), 1) <> 'ITEMCHANGED' then windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5913, -- EFRAME_ACTIONSLIST bufhandle, arg( 1)) else windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5918, -- ITEMCHANGED bufhandle, subword( arg( 1), 2)) endif endif activatefile activefileid ; --------------------------------------------------------------------------- ; Generic macro for adding toolbar definitions easily. Here is an example ; for its usage: ; defc TB_Shell ; ExFile = 'newbar' -- Name of the .ex file where this defc is defined. ; Action = 'TB_Shell' -- Name of the defc. Appears in the list of selectable actions. ; Command = 'Shell' -- Command to be executed after release of the button. ; Prompt = SHELL_PROMPT -- Prompt, that appears on the messageline, while the button is pressed. ; Help = '' -- Additional prompt or a help panel id for F1 action while the button is pressed. ; Title = '' -- Title of the help message box (if no help panel id). ; call ToolbarAction( arg(1), Exfile, Action, Command, Prompt, Help, Title) ; Additionally, a line must be added to ; defc _actionlist ; 'TB_Shell ACTIONLIST' ; to make that definition appear in the listbox, where an action can be ; selected from. defproc ToolbarAction universal actionslist_fileid Exfile = arg( 2) Action = arg( 3) Command = arg( 4) Prompt = arg( 5) Help = arg( 6) Title = arg( 7) if Title = '' then Title = Action 'from "'upcase( ExFile)'"' endif if upcase( arg( 1)) = 'ACTIONLIST' then insertline \1''Action''\1''Prompt''\1''ExFile''\1, actionslist_fileid.last + 1, actionslist_fileid else if arg( 1) = 'S' then 'VSyncCursor' sayerror 0 Command --'PostMe 'Command -- PostMe required for LoadFileList elseif arg( 1) = 'I' then 'SayHint' Prompt elseif arg( 1) = 'H' then if words( Help) = 1 & IsNum( Help) then 'HelPanel' Help else call WinMessageBox( Title, Prompt''Help, MB_OK + MB_INFORMATION + MB_MOVEABLE) endif endif endif ; --------------------------------------------------------------------------- ; This defc is called to resolve UCMENU actions. ; It is called with the first parameter being the action name, and the ; second parameter being an action sub-op. ; If the action (Which is a Defc) is not defined the actions list is ; generated in order to try resolving the defc. defc ExecuteAction parse arg DefcModule DefcName DefcParameter --dprintf( 'ExecuteAction: "'arg( 1)'"') if DefcName = '*' then DefcParameter else if defcmodule <> '*' then if linked( defcmodule) < 0 then link defcmodule endif endif if isadefc( DefcName) then --dprintf( 'ExecuteAction: Executing cmd "'DefcName'" with parm "'DefcParameter'"') DefcName DefcParameter else 'SayError 'UNKNOWN_ACTION__MSG DefcName'.' endif endif ; --------------------------------------------------------------------------- ; Save active toolbar name to ini. If arg is specified, use that name. ; Syntax: call SetDefaultToolbar( []) ; Use NEPMD.INI now, because Newbar's .bmps are not available for standard ; EPM. In order to make standard EPM open with a valid toolbar, it should ; better keep the old setting alone. defproc SetDefaultToolbar universal toolbar_loaded BarName = lowcase( arg( 1)) if BarName = '' then -- use current name if no name specified BarName = toolbar_loaded endif if wordpos( lowcase( BarName), \1 lowcase( 'STANDARD')) then BarName = '' -- delete ini key for default toolbar endif KeyPath = '\NEPMD\User\Toolbar\Name' WriteConfigKey( KeyPath, lowcase( BarName)) return ; --------------------------------------------------------------------------- ; Querys saved toolbar name from ini. Returns Barname. ; Syntax: BarName = GetDefaultToolbar() defproc GetDefaultToolbar KeyPath = '\NEPMD\User\Toolbar\Name' StandardName = lowcase( 'STANDARD') call FixupToolbarCase() BarName = lowcase( QueryConfigKey( KeyPath)) if Barname = '' then Barname = StandardName endif return BarName ; --------------------------------------------------------------------------- ; This sets the case of all found toolbar names in the ini to lowercase. If ; all-lower names are present, these names are preferred. If not, the first ; found name is renamed to lowercase. All other cases are deleted. After ; that, all toolbar names are unique and all-lowercase. That eases the ; lookup for tollbar names and their settings. defproc FixupToolbarCase() universal app_hini do once = 1 to 1 -- Find all toolbar names Handle = HINI_NEPMDPROFILE ProfileApp = INI_UCMENU_APP Filter = '' NextName = '' UniqueKeys = '' Delim = \0 --dprintf( '-------------------------------------------------------') -- Create a list of unique keys in lowercase do while NepmdGetNextProfileKey( Handle, ProfileApp, Filter, NextName) --dprintf( 'NextName = 'NextName) if not pos( Delim''lowcase( NextName), UniqueKeys) then UniqueKeys = UniqueKeys''Delim''lowcase( NextName) endif enddo --dprintf( 'UniqueKeys = 'translate( UniqueKeys, '.', \0)) UniqueRest = UniqueKeys do while UniqueRest <> '' parse value UniqueRest with (Delim) NextName (Delim) +0 UniqueRest if NextName = '' then leave endif RenameKeys = '' DeleteKeys = '' fFound = 0 --dprintf( ' ------------') -- First check if an all-lowercase name exists Val = queryprofile( app_hini, INI_UCMENU_APP, lowcase( NextName)) if Val <> '' then fFound = 1 --dprintf( ' Found toolbar (correct case): 'lowcase( NextName)) endif NextKey = '' do while NepmdGetNextProfileKey( Handle, ProfileApp, Filter, NextKey) --dprintf( ' NextKey = 'NextKey) -- Check if name matches, but case-insensitive if lowcase( NextKey) = lowcase( NextName) then --dprintf( ' Caseless match: 'NextKey) if not fFound then fFound = 1 --dprintf( ' Found toolbar (case to fix): 'NextKey) -- Correct the case of the entry to all lowercase, if required if NextKey <> lowcase( NextName) then --dprintf( ' Correct case to: 'lowcase( NextKey)) RenameKeys = RenameKeys''Delim''NextKey endif else if NextKey <> lowcase( NextName) then -- Delete other cases --dprintf( ' Delete toolbar: 'NextKey) DeleteKeys = DeleteKeys''Delim''NextKey else --dprintf( ' This is the found toolbar: 'NextKey) endif endif endif enddo -- Rename keys outside of the NepmdGetNextProfileKey loop Rest = RenameKeys do while Rest <> '' parse value Rest with (Delim) NextKey (Delim) +0 Rest if NextKey = '' then leave endif --dprintf( ' Rename loop: Correct case from 'NextKey' to: 'lowcase( NextKey)) Val = queryprofile( app_hini, INI_UCMENU_APP, NextKey) --dprintf( 'Val = 'translate( leftstr( Val, 50), '.', \0)) call setprofile( app_hini, INI_UCMENU_APP, lowcase( NextKey), Val) call setprofile( app_hini, INI_UCMENU_APP, NextKey, '') enddo -- Delete keys outside of the NepmdGetNextProfileKey loop Rest = DeleteKeys do while Rest <> '' parse value Rest with (Delim) NextKey (Delim) +0 Rest if NextKey = '' then leave endif --dprintf( ' Delete loop: Delete toolbar: 'NextKey) call setprofile( app_hini, INI_UCMENU_APP, NextKey, '') enddo enddo -- while UniqueRest <> '' enddo -- once = 1 to 1 return ; --------------------------------------------------------------------------- ; Save current toolbar to EPM.INI. ; Syntax: SaveToolbar [] ; Default is current name. ; This is also used by the toolbar's context menu item "Save as...". defc SaveToolbar, save_toolbar universal app_hini universal appname universal toolbar_loaded KeyPath = '\NEPMD\User\Toolbar\Name' 'VSyncIfKeepCursor' BarName = lowcase( strip( arg( 1))) call FixupToolbarCase() if BarName = '' then tb = toolbar_loaded if tb = \1 then -- \1 is defined to represent the built-in toolbar tb = '' endif parse value EntryBox( SAVEBAR__MSG, '/'SAVE__MSG'/'Cancel__MSG'/'Help__MSG'/', tb, '', 200, atoi( 1) || atoi( 7010) || GethWndC( APP_HANDLE) || SAVEBAR_PROMPT__MSG) with button 2 BarName \0 if button <> \1 then return endif if BarName = '' then 'SayError 'NOTHING_ENTERED__MSG'.' return endif BarName = lowcase( BarName) -- Always use lowercase toolbar names endif toolbar_loaded = BarName WriteConfigKey( KeyPath, Barname) 'ExportToolbar' Barname ; --------------------------------------------------------------------------- ; Delete a toolbar. defc DeleteToolbar, deletetemplate universal app_hini universal toolbar_loaded KeyPath = '\NEPMD\User\Toolbar\Name' StandardName = lowcase( 'STANDARD') 'VSyncIfKeepCursor' parse arg BarName Barname = lowcase( strip( Barname)) -- Always use lowercase toolbar names call FixupToolbarCase() -- Confirm delete if Ctrl isn't pressed if CtrlIsDown() then rc = 0 else if AskOkCancel( 'Delete toolbar "'barname'" from ini?'\n\n || '('CTRL_KEY__MSG' to bypass confirmation.)') then rc = 0 else rc = -1 endif endif if not rc then call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5919, -- DELETE app_hini, Put_In_Buffer( BarName)) if BarName = toolbar_loaded then -- delete the selected name, too WriteConfigKey( KeyPath, StandardName) endif endif ; --------------------------------------------------------------------------- ; Activate built-in toolbar. ; LoadDefaultToolbar should be avoided (default means from ini)! defc LoadStandardToolbar, LoadDefaultToolbar universal activeucmenu universal toolbar_loaded if activeucmenu = 'toolbar' then -- Already used, delete it to be safe. deletemenu activeucmenu else activeucmenu = 'toolbar' endif compile if WANT_TINY_ICONS ; # Button text # Button bitmap # command # parameters # .ex file buildsubmenu activeucmenu, 1, "#Add File#1131#a_Add_File##sampactn", '', 0, 0 -- EPM.bmp buildsubmenu activeucmenu, 2, "#Save#1130#a_save##sampactn", '', 0, 0 buildsubmenu activeucmenu, 3, "#Print#1133#a_print##sampactn", '', 0, 0 -- print.bmp buildsubmenu activeucmenu, 4, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 5, "#MonoFont#1151#a_MonoFont##sampactn", '', 0, 0 -- monofont.bmp buildsubmenu activeucmenu, 6, "#Style#1147#apply_style##stylebut", '', 0, 0 -- style.bmp buildsubmenu activeucmenu, 7, "#UnStyle#1148#remove_style##stylebut", '', 0, 0 -- style.bmp buildsubmenu activeucmenu, 8, "#Attribs#1152#fonts_attribs##fonts", '', 0, 0 -- attribs.bmp buildmenuitem activeucmenu, 8, 80, "#Bold#1124#fonts_bold##fonts", '', 0, 0 -- bold.bmp buildmenuitem activeucmenu, 8, 81, "#Italic#1123#fonts_italic##fonts", '', 0, 0 -- italic.bmp buildmenuitem activeucmenu, 8, 82, "#Under#1122#fonts_underline##fonts", '', 0, 0 -- undrline.bmp buildmenuitem activeucmenu, 8, 83, "#Strike#1121#fonts_strikeout##fonts", '', 0, 0 -- strikout.bmp buildmenuitem activeucmenu, 8, 84, "#Outline#1120#fonts_outline##fonts", '', 0, 0 -- outline.bmp buildsubmenu activeucmenu, 9, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 10, "#Search#1138#a_SearchDlg##sampactn", '', 0, 0 -- search.bmp buildsubmenu activeucmenu, 11, "#Undo#1134#a_UndoDlg##sampactn", '', 0, 0 -- undo.bmp buildsubmenu activeucmenu, 12, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 13, "#Shell#1153#a_Shell##sampactn", '', 0, 0 -- epmshell.bmp compile else ; # Button text # Button bitmap # command # parameters # .ex file buildsubmenu activeucmenu, 1, "#Add File#1116#a_Add_File##sampactn", '', 0, 0 -- EPM.bmp buildsubmenu activeucmenu, 2, "#Save#1117#a_save##sampactn", '', 0, 0 buildsubmenu activeucmenu, 3, "#Print#1113#a_print##sampactn", '', 0, 0 -- print.bmp buildsubmenu activeucmenu, 4, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 5, "#MonoFont#1106#a_MonoFont##sampactn", '', 0, 0 -- monofont.bmp buildsubmenu activeucmenu, 6, "#Style#1112#apply_style##stylebut", '', 0, 0 -- style.bmp buildsubmenu activeucmenu, 7, "#UnStyle#1128#remove_style##stylebut", '', 0, 0 -- style.bmp buildsubmenu activeucmenu, 8, "#Attribs#1119#fonts_attribs##fonts", '', 0, 0 -- attribs.bmp buildmenuitem activeucmenu, 8, 80, "#Bold#1124#fonts_bold##fonts", '', 0, 0 -- bold.bmp buildmenuitem activeucmenu, 8, 81, "#Italic#1123#fonts_italic##fonts", '', 0, 0 -- italic.bmp buildmenuitem activeucmenu, 8, 82, "#Under#1122#fonts_underline##fonts", '', 0, 0 -- undrline.bmp buildmenuitem activeucmenu, 8, 83, "#Strike#1121#fonts_strikeout##fonts", '', 0, 0 -- strikout.bmp buildmenuitem activeucmenu, 8, 84, "#Outline#1120#fonts_outline##fonts", '', 0, 0 -- outline.bmp buildsubmenu activeucmenu, 9, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 10, "#Search#1115#a_SearchDlg##sampactn", '', 0, 0 -- search.bmp buildsubmenu activeucmenu, 11, "#Undo#1114#a_UndoDlg##sampactn", '', 0, 0 -- undo.bmp buildsubmenu activeucmenu, 12, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 13, "#Shell#1118#a_Shell##sampactn", '', 0, 0 -- epmshell.bmp compile endif -- WANT_TINY_ICONS ; buildsubmenu activeucmenu, 1, "#Open#1102#a_Add_File##sampactn", '', 0, 0 -- EPM.bmp ; buildsubmenu activeucmenu, 2, "#Print#1113#a_print##sampactn", '', 0, 0 ; buildsubmenu activeucmenu, 3, "#Shell#1109#a_Shell##sampactn", '', 0, 0 -- epmshell.bmp ; buildsubmenu activeucmenu, 4, '', '', 16401, 0 -- MIS_SPACER ; buildsubmenu activeucmenu, 5, "#Style#1112#apply_style##stylebut", '', 0, 0 -- style.bmp ; buildsubmenu activeucmenu, 6, "#MonoFont#1106#a_MonoFont##sampactn", '', 0, 0 -- monofont.bmp ; buildsubmenu activeucmenu, 7, "#Reflow#1107#reflow_prompt##reflow", '', 0, 0 -- reflow.bmp ; buildsubmenu activeucmenu, 8, '', '', 16401, 0 -- MIS_SPACER ; buildsubmenu activeucmenu, 9, "#Msgs#1100#a_Messages##sampactn", '', 0, 0 -- info.bmp ; buildsubmenu activeucmenu, 10, "#List Ring#1110#a_List_Ring##sampactn", '', 0, 0 -- ringlist.bmp ;; buildsubmenu activeucmenu, 11, "#Add New#1101#a_Add_New##sampactn", '', 0, 0 -- EPMadd.bmp ;; buildsubmenu activeucmenu, 12, "#NewWind#1103#a_NewWindow##sampactn", '', 0, 0 -- newwindw.bmp ;; buildsubmenu activeucmenu, 13, "#Settings#1104#a_Settings##sampactn", '', 0, 0 -- settings.bmp ;; buildsubmenu activeucmenu, 14, "#Time#1105#a_Time##sampactn", '', 0, 0 -- clock.bmp ;; buildsubmenu activeucmenu, 15, "#Jot#1108#jot_a_note##jot", '', 0, 0 -- idea.bmp ;; buildsubmenu activeucmenu, 16, "#Tree#1111#tree_action##tree", '', 0, 0 -- tree.bmp ;; buildsubmenu activeucmenu, 17, "#KwdHilit#kwdhilit.bmp#a_togl_hilit##sampactn", '', 0, 0 showmenu activeucmenu, 3 toolbar_loaded = \1 ; --------------------------------------------------------------------------- ; Activate last saved toolbar from EPM.INI. defc ReloadToolbar, default_toolbar universal app_hini universal toolbar_loaded IniData = '' BarName = GetDefaultToolbar() -- returns '' for standard toolbar if BarName <> '' then -- check if present, data is not used IniData = queryprofile( app_hini, INI_UCMENU_APP, BarName) -- If not found in ini, try to import it from a .bar file if IniData = '' then barfile = '' findfile barfile, BarName'.bar', 'EPMBARPATH' if barfile > '' then 'ImportToolbar' barfile','BarName if rc = 0 then -- if data of BarName'.bar' successfully written to ini IniData = 1 endif endif endif endif if IniData = '' then 'LoadStandardToolbar' else toolbar_loaded = BarName call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5916, -- LOAD app_hini, Put_In_Buffer( toolbar_loaded)) endif ; --------------------------------------------------------------------------- ; This is called after installation. defc ImportAllToolbarFiles FileMask = '*.bar' ProcessedNames = '' Delim = \1 rest = Get_Env( 'EPMBARPATH') i = 0 do while rest <> '' i = i + 1 parse value rest with Path';'rest if Path = '' then iterate endif Path = strip( Path, 'T', '\') FullFileMask = Path'\'FileMask Handle = '' -- always create a new handle NextFilename = '' do while NepmdGetNextFile( FullFileMask, Handle, NextFilename) lp1 = lastpos( '\', NextFilename) Name = substr( NextFilename, lp1 + 1) lp2 = lastpos( '.', Name) if lp2 > 1 then Basename = substr( Name, 1, lp2 - 1) else Basename = Name endif Basename = lowcase( Basename) -- Process only if not already imported if pos( Delim''Basename''Delim, Delim''ProcessedNames) then iterate endif -- Import 'ImportToolbar QUIET NOTACTIVE' NextFilename','Basename if not rc then ProcessedNames = ProcessedNames''Basename''Delim endif enddo enddo ; --------------------------------------------------------------------------- ; Syntax: LoadToolbar [NOSAVE] [] ; If is not specified, then a ListBox with all previously ; imported toolbar names is opened. "Imported" means: their binary data ; must be written to the ini. ; If NOSAVE is specified, then the name will not be saved in ini as the new ; default toolbar. This is used for mode settings. ; Todo: merge this with defc toggle_toolbar. ; From EPMSMP\LOADTB.E ; Command to load a previously-saved toolbar, by Larry Margolis const NO_TOOLBARS__MSG = 'No saved toolbars from which to select.' LOAD_TOOLBAR__MSG = 'Load Toolbar' -- Dialog box title SELECT_TOOLBAR__MSG = 'Select a Toolbar menu set' TOOLBAR_UNKNOWN__MSG = 'Toolbar unknown:' defc LoadToolbar, load_toolbar universal app_hini universal appname universal toolbar_loaded KeyPath = '\NEPMD\User\Toolbar\Name' StandardName = 'STANDARD' LoadedName = toolbar_loaded if toolbar_loaded = \1 then LoadedName = StandardName endif BarName = lowcase( arg( 1)) -- Always use lowercase toolbar names wp = wordpos( 'NOSAVE', upcase( BarName)) fSave = 1 if wp then fSave = 0 BarName = strip( delword( BarName, wp, 1)) endif if BarName = '' then -- List all toolbars IniData = queryprofile( app_hini, INI_UCMENU_APP, '') if not length( IniData) then 'SayError 'NO_TOOLBARS__MSG'.' return elseif length( IniData) > 1600 then 'SayError Ini key data longer than 1600 chars. Cannot handle that by an E string.' return endif getfileid startfid 'VSyncCursor' 'xcom e /c /q tempfile' if rc <> -282 then -- sayerror( 'New file') 'SayError 'ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext( rc)'.' return endif .autosave = 0 browse_mode = browse() -- query current state if browse_mode then call browse( 0) endif -- Write next string to tempfile do while IniData <> '' parse value IniData with BarName \0 IniData insertline BarName, .last + 1 enddo -- Sort if .last > 2 then getfileid fileid call Sort( 2, .last, 1, 40, fileid, 'I') endif -- Append name for standard toolbar as last insertline StandardName, .last + 1 -- Find current name in list to select it in listbox Selected = 1 do l = 2 to .last -- first line is always empty for a newly created file next = strip( textline( l)) if (next > '') & (next = LoadedName) then Selected = l - 1 leave endif enddo if browse_mode then call browse( 1) endif -- This inserts the contents from the current file into a buffer, -- ready for a call to ListBox(). This can be used when the list -- entry length extends E's max. line length. -- It also quits the current file and activates startfid. if ListBox_Buffer_From_File( startfid, bufhndl, noflines, usedsize) then return endif --Title = LOAD_TOOLBAR__MSG Title = 'Select a toolbar' --Text = SELECT_TOOLBAR__MSG Text = 'Current toolbar: 'LoadedName --HelpPanel = 7000 HelpPanel = 0 parse value ListBox( Title, \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl), '/'OK__MSG'/~Delete/'CANCEL__MSG, --'/'OK__MSG'/'CANCEL__MSG'/'HELP__MSG, -- buttons 0, 0, -- top, left, Min( noflines, 12), 30, -- height, width GethWndC( APP_HANDLE) || atoi( Selected) || atoi( 1) || atoi( HelpPanel) || Text) with button 2 BarName \0 call buffer( FREEBUF, bufhndl) if button = \2 then -- Delete 'DeleteToolbar' BarName 'PostMe LoadToolbar' -- Select a new one or delete another return endif if button <> \1 then -- Delete or Cancel return endif else IniData = queryprofile( app_hini, INI_UCMENU_APP, BarName) -- case-sensitive if IniData = '' then 'SayError 'TOOLBAR_UNKNOWN__MSG BarName'.' return endif endif if upcase( BarName) = upcase( StandardName) then 'LoadStandardToolbar' toolbar_loaded = \1 else call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5916, -- LOAD app_hini, Put_In_Buffer( BarName)) toolbar_loaded = BarName endif if fSave then WriteConfigKey( KeyPath, lowcase( BarName)) KeyPath = '\NEPMD\User\Toolbar' call WriteConfigKey( KeyPath, 1) endif ; --------------------------------------------------------------------------- ; Return current setup string. Colors are always reset. ; The entry for UCMenu -> ConfigInfo changes to some strange values after ; a font is dropped on the toolbar. ; Before: ; 832328.Helv1677721616777216 ; After: ; 270401576262612.System VIO1355361413553614 ; 27040157626269.WarpSans1355361413553614 ; The color values are: ; 16777216 = 0x1000000 (means default color?) ; 13553614 = 0xCECFCE (CE = 205, CF = 206) ; light gray = 204-204-204, values above are probably just not precise. ; Syntax: ; \1 style \1 cx \1 cy \1 font \1 color \ itemcolor \1 defproc GetToolbarSetup universal app_hini Setup = queryprofile( app_hini, 'UCMenu', 'ConfigInfo') i = count( \1, Setup) fWriteDefaultString = (i < 7) if fWriteDefaultString then --Setup = \1'8'\1'32'\1'32'\1'8.Helv'\1'16777216'\1'16777216'\1 -- internal default if no entry in EPM.INI Setup = \1'56'\1'26'\1'26'\1'9.WarpSans'\1'16777216'\1'16777216'\1 -- new default if no entry in EPM.INI -- 16 * 16 * 16 * 16 * 16 * 16 = 16777216 call setprofile( app_hini, 'UCMenu', 'ConfigInfo', Setup) endif -- Always reset background colors, because any other color then PM's -- default looks ugly and apparantly the determination of the -- resulting color is buggy. -- Note: background colors can be changed via the color palette. parse value Setup with \1 Style \1 Cx \1 Cy \1 TbFont \1 Color \1 ItemColor \1 Setup = \1''Style\1''Cx\1''Cy\1''TbFont\1'16777216'\1'16777216'\1 -- always reset colors return Setup ; --------------------------------------------------------------------------- ; Write specified setup string to ini and apply it. defproc SetToolbarSetup universal app_hini Setup = arg( 1) call setprofile( app_hini, 'UCMenu', 'ConfigInfo', Setup) -- The following message seems to be posted at startup as well, without -- calling this proc. The above ini value is used then. call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5921, Put_In_Buffer( Setup), 0) return ; --------------------------------------------------------------------------- ; Toolbar style: /* fText = not (Style bitand 16) fAutosize = not (Style bitand 4) fFlat = not (Style bitand 8) fScaleDel = (not (Style bitand 32)) and (not (Style bitand 96)) fScaleOr = Style bitand 96 fScaleAnd = Style bitand 32 Value Text Auto Delete Or And ------------------------------------------- 8 1 1 1 40 1 1 1 104 1 1 1 12 1 1 44 1 1 108 1 1 24 1 1 56 1 1 120 1 1 28 1 60 1 124 1 0 0x00 0000 0000 Delete 4 0x04 0000 0100 no Auto 8 0x08 0000 1000 Border 16 0x10 0001 0000 no Text 32 0x20 0010 0000 And 64 0x40 0100 0000 (unused) 96 0x60 0110 0000 Or = 32 + 64 */ /* defc testbitand Style = arg(1) fText = not (Style bitand 16) fAutosize = not (Style bitand 4) fFlat = not (Style bitand 8) fScaleDel = (not (Style bitand 32)) and (not (Style bitand 64)) fScaleOr = (Style bitand 32) and (Style bitand 64) fScaleAnd = (Style bitand 32) and (not (Style bitand 64)) next = 16 * (not fText) + 4 * (not fAutosize) + 8 * (not fFlat) + 32 * (fScaleAnd) + 96 * (fScaleOr) sayerror Style'['next']: 'fText fAutosize fScaleDel fScaleOr fScaleAnd */ ; --------------------------------------------------------------------------- ; Syntax: ToolbarSize [cx cy] defc ToolbarSize parse value GetToolbarSetup() with \1 Style \1 Cx \1 Cy \1 SetupRest -- if executed with an arg arg1 = upcase( arg( 1)) if arg1 <> '' then parse value arg1 with newx newy if IsNum( newx) & IsNum( newy) then call SetToolbarSetup( \1''Style\1''newx\1''newy\1''SetupRest) if isadefproc( 'MenuText_toolbarsize') then MenuText_toolbarsize() endif return endif endif -- else open entrybox Title = 'Configure toolbar button size' Text = 'Enter x-size y-size (default: 26 26).' DefaultButton = 1 parse value EntryBox( Title, '/~Set/~Reset/'CANCEL__MSG, -- max. 4 buttons Cx Cy, '', 260, atoi( DefaultButton) || atoi( 0000) || -- help id GethWndC( APP_HANDLE) || Text) with Button 2 NewValue \0 NewValue = strip(NewValue) if Button = \1 then 'ToolbarSize' NewValue return elseif Button = \2 then 'ToolbarSize 26 26' return elseif Button = \3 then return endif ; --------------------------------------------------------------------------- defc DragDrop_BAR Filename = EnquoteFileSpec( arg( 1)) 'ImportToolbar' Filename if rc = 13 then -- ERROR_INVALID_DATA 'Edit' Filename endif ; --------------------------------------------------------------------------- ; Used by ImportToolbar to select a .bar file. defc ImportToolbarSelect BarFile = '' getfileid startfid 'xcom e /c .barlist' if rc <> -282 then -- -282 = sayerror( 'New file') 'SayError 'ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext( rc)'.' return endif getfileid listfid browse_mode = browse() -- query current state if browse_mode then call browse(0) endif .autosave = 0 .visible = 0 display -2 RootDir = strip( Get_Env( 'NEPMD_ROOTDIR'), 't', '\') UserDir = strip( Get_Env( 'NEPMD_USERDIR'), 't', '\') do i = 1 to 3 Handle = '' -- handle must be reset before the search next = '' if i = 1 then UserFileMask = UserDir'\bar\*.bar' FileMask = UserFileMask elseif i = 2 then FileMask = RootDir'\netlabs\bar\*.bar' elseif i = 3 then FileMask = RootDir'\epmbbs\bar\*.bar' endif do while NepmdGetNextFile( FileMask, Handle, next) insertline next, .last + 1 enddo enddo if browse_mode then call browse(1) -- restore browse state endif display 2 if not .modify then -- Nothing added? 'xcom quit' activatefile startfid 'SayError No .bar files found.' return endif if Listbox_Buffer_From_File( startfid, bufhndl, noflines, usedsize) then return endif HelpPanel = 0 Title = 'Select a toolbar filename to import' parse value ListBox( Title''copies( ' ', 20), \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl), '/~Import/~File dialog.../'Cancel__MSG, 0, 0, Min( noflines, 12), 0, GethWndC( APP_HANDLE) || atoi( 1) || atoi( 1) || atoi( HelpPanel)) with Button 2 BarFile \0 call buffer( FREEBUF, bufhndl) if Button = \1 then if BarFile > '' then 'ImportToolbar' BarFile endif elseif Button = \2 then -- Syntax: filedlg title[, cmd[, filemask[, flags]]] 'FileDlg' Title',ImportToolbar,'UserFileMask return endif ; --------------------------------------------------------------------------- const TOOLBAR_SIG = \x9B\xA0\xC1\x53 ; This command can be used for dragdrop processing of .bar files: ; If rc = 13, then the file should be loaded normally. ; Syntax: ImportToolbar [, ] defc ImportToolbar universal app_hini universal toolbar_loaded 'VSyncIfKeepCursor' -- Get .bar file parse arg BarFile ',' BarName fQuiet = 0 wpos = wordpos( 'QUIET', BarFile) if wpos then fQuiet = 1 BarFile = strip( delword( BarFile, wpos, 1)) endif fMakeActive = 1 wpos = wordpos( 'NOTACTIVE', BarFile) if wpos then fMakeActive = 0 BarFile = strip( delword( BarFile, wpos, 1)) endif BarFile = strip( BarFile) BarFile = StripquotesFileSpec( BarFile) BarName = strip( BarName) if BarFile = '' then 'ImportToolbarSelect' return endif -- Append extension, if not specified if (BarFile > '' & upcase( rightstr( BarFile, 4)) <> '.BAR') then BarFile = BarFile'.bar' endif if NepmdFileExists( BarFile) then -- Since a REXX macro is used, no check for size is required anymore. else return 2 -- ERROR_FILE_NOT_FOUND endif -- Read .bar file (to check for signature only) 'xcom e /t /64 /bin /d' EnquoteFileSpec( BarFile) if rc = 0 then .visible = 0 Bar = '' do l = 1 to .last Bar = Bar''textline( l) -- Check for signature if l = 1 then if leftstr( Bar, length( TOOLBAR_SIG)) <> TOOLBAR_SIG then 'xcom quit' return 13 -- ERROR_INVALID_DATA endif else endif end 'xcom quit' else return 5 -- ERROR_ACCESS_DENIED endif if BarName = '' then -- Get default name from file lp = lastpos( '\', BarFile) BarName = lowcase( substr( BarFile, lp + 1)) -- Always use lowercase toolbar names parse value BarName with BarName '.' rest -- Ask user for name Title = 'Import toolbar' Text = 'Enter new toolbar name:' Text = Text''copies( ' ', Max( 50 - length( Text), 0)) Entry = BarName parse value EntryBox( Title, '', Entry, 0, 240, atoi( 1) || atoi( 0) || atol( 0) || Text) with button 2 next \0 next = strip( next) if button = \1 & next <> '' then BarName = lowcase( next) -- Always use lowercase toolbar names else return 31 -- ERROR_GEN_FAILURE endif endif IniFile = NepmdQueryInstValue( 'INIT') IniAppl = 'UCMenu_Templates' -- Write toolbar data from BarFile to IniFile -> IniAppl -> BarName 'rx toolbar IMPORT' IniFile IniAppl BarName EnquoteFileSpec( BarFile) if rc = 0 then toolbar_loaded = BarName -- Make it default if fMakeActive then call SetDefaultToolbar() -- Activate 'PostMe LoadToolbar' BarName endif if rc = 0 then if not fQuiet then if fMakeActive then 'SayError Toolbar "'BarName'" imported and activated.' else 'SayError Toolbar "'BarName'" imported.' endif endif -- If toolbar is imported during first startup then it always shows text, -- ignoring the toolbar style setting. The following is a workaround. 'PostMe RefreshToolbarStyle' else if not fQuiet then if fMakeActive then 'SayError Error: Toolbar "'BarName'" not activated. rc = 'rc'.' endif endif endif else 'SayError Error: Toolbar "'BarName'" not imported. rc = 'rc'.' endif ; --------------------------------------------------------------------------- defc RefreshToolbarStyle universal app_hini Setup = queryprofile( app_hini, 'UCMenu', 'ConfigInfo') call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5921, Put_In_Buffer( Setup), 0) ; --------------------------------------------------------------------------- defc ExportToolbar universal app_hini 'VSyncIfKeepCursor' -- If no name specified, use a tmp name Barname = strip( arg( 1)) fUseTmpBar = 0 if Barname = '' then Barname = '.TmpBar' fUseTmpBar = 1 endif -- Save current toolbar first call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), 5915, app_hini, Put_In_Buffer( Barname)) -- Execute the rest after ini key was saved if fUseTmpBar then 'PostMe ExportToolbar2' Barname else 'PostMe ExportToolbar2' endif defc ExportToolbar2 universal app_hini universal toolbar_loaded -- If a name is specified, it's a tmp name TmpBarName = strip( arg( 1)) fUseTmpBar = 0 if TmpBarname <> '' then fUseTmpBar = 1 endif -- Get name of active toolbar from ini BarName = toolbar_loaded -- query current toolbar name if BarName = \1 then -- \1 means: default toolbar is active BarName = GetDefaultToolbar() -- query last saved toolbar name endif IniFile = NepmdQueryInstValue( 'INIT') IniAppl = 'UCMenu_Templates' 'rx Toolbar EXPORT' IniFile IniAppl BarName TmpBarName if rc = 0 then -- 'SayError Success. rc = 'rc'.' elseif rc = 1 then -- 'SayError Export canceled by user. rc = 'rc'.' else 'SayError Error: Toolbar not exported. rc = 'rc'.' endif if fUseTmpBar then -- Delete temporarily saved toolbar call setprofile( app_hini, 'UCMenu_Templates', TmpBarName, '') endif ---- The rest is commented out ---- ; --------------------------------------------------------------------------- compile if 0 -- No longer used ---------------------------------------------- defc load_toolbar call List_ToolBars( LOAD_TOOLBAR__MSG, SELECT_TOOLBAR__MSG, 7000, 5916) -- LOAD defc delete_toolbar call List_Toolbars( DELETE_TOOLBAR__MSG, SELECT_TOOLBAR__MSG, 7001, 5919) -- DELETE defproc List_ToolBars( list_title, list_prompt, help_panel, msgid) universal app_hini universal toolbar_loaded ; l = dynalink32( 'PMSHAPI', ; '#115', -- PRF32QUERYPROFILESTRING ; atol( app_hini) || -- HINI_PROFILE ; address( App) || -- pointer to application name ; atol( 0) || -- Key name is NULL; returns all keys ; atol( 0) || -- Default return string is NULL ; address( IniData) || -- pointer to returned string buffer ; atol( 1600), 2) -- max length of returned string IniData = queryprofile( app_hini, INI_UCMENU_APP, '') l = length( IniData) if not l then sayerror NO_TOOLBARS__MSG return endif getfileid startfid 'xcom e /c /q tempfile' if rc <> -282 then -- sayerror('New file') sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext( rc) return endif .autosave = 0 browse_mode = browse() -- query current state if browse_mode then call browse( 0) endif do while IniData <> '' parse value IniData with BarName \0 IniData insertline BarName, .last + 1 enddo if browse_mode then call browse( 1) endif if ListBox_Buffer_From_File( startfid, bufhndl, noflines, usedsize) then return endif parse value ListBox( list_title, \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl), '/'OK__MSG'/'Cancel__MSG'/'Help__MSG, 0, 0, Min( noflines,12), 0, GethWndC( APP_HANDLE) || atoi( 1) || atoi( 1) || atoi( help_panel) || list_prompt) with button 2 BarName \0 call buffer( FREEBUF, bufhndl) if button <> \1 then return endif call windowmessage( 0, getpminfo( EPMINFO_EDITFRAME), msgid, app_hini, Put_In_Buffer( BarName)) if msgid = 5916 then -- LOAD toolbar_loaded = BarName endif ; --------------------------------------------------------------------------- ; Unused, already handled by LoadToolbar without args. ; This is left in here as an example for reading all ini applications into ; a buffer instead into a string (like LoadToolbar does it). ; This is able to handle entire data > 1599 byte (but the limit of 1599 ; per a single string cannot be circumvented). defc SelectToolbar universal app_hini universal toolbar_loaded getfileid startfid Appl = 'UCMenu_Templates' bufhndl = buffer( CREATEBUF, Appl, MAXBUFSIZE, 1) -- Create a private buffer retlen = \0\0\0\0 l = dynalink32( 'PMSHAPI', '#115', -- PRF32QUERYPROFILESTRING atol( app_hini) || -- HINI_PROFILE atol( 0) || -- Application name is NULL; returns all apps atol( 0) || -- Key name atol( 0) || -- Default return string is NULL atoi( 0) || atoi( bufhndl) || -- pointer to returned string buffer atol( 65535) || -- max length of returned string address( retlen), 2) -- length of returned string poke bufhndl, 65535, \0 if not l then sayerror 'The application "'Appl'" contains no keys' call buffer( FREEBUF, bufhndl) return endif 'xcom e /c /q tempfile' if rc <> -282 then -- sayerror('New file') sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc) call buffer( FREEBUF, bufhndl) return endif .autosave = 0 browse_mode = browse() -- query current state if browse_mode then call browse( 0) endif buf_ofs = 0 do while buf_ofs < l next = peekz( bufhndl, buf_ofs) insertline next, .last + 1 buf_ofs = buf_ofs + length( next) + 1 enddo call buffer( FREEBUF, bufhndl) if Listbox_Buffer_From_File( startfid, bufhndl, noflines, usedsize) then return endif HelpPanel = 0 Title = 'Select a toolbar' Text = 'Current toolbar: 'toolbar_loaded parse value ListBox( Title''copies( ' ', 20), \0 || atol( usedsize) || atoi( 32) || atoi( bufhndl), '/'OK__MSG'/'CANCEL__MSG, 0, 0, Min( noflines, 12), 0, GethWndC( APP_HANDLE) || atoi(1) || atoi(1) || atoi(HelpPanel) || Text) with Button 2 BarName \0 call buffer( FREEBUF, bufhndl) if Button = \1 then if BarName > '' then 'LoadToolbar' BarName endif endif compile endif -- 0 --------------------------------------------------------- ; --------------------------------------------------------------------------- ; From: Larry Margolis (margoli@ibm.net) ; Subject: Re: change EPM toolbar dynamically ; Newsgroups:comp.os.os2.programmer.tools ; ; Well, here's some sample code if you want to create the toolbar ; completely from the macros: compile if 0 defc loadtb -- I don't like the built-in default; here's mine: universal activeucmenu, toolbar_loaded if activeucmenu = 'toolbar' then -- Already used, delete it to be safe. deletemenu activeucmenu else activeucmenu = 'toolbar' endif -- # button text # button bitmap # command # parameters # .ex file buildsubmenu activeucmenu, 1, "#Msgs#1100#a_Messages##sampactn", '', 0, 0 buildsubmenu activeucmenu, 2, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 3, "#Add New#1101#a_Add_New##sampactn", '', 0, 0 buildsubmenu activeucmenu, 4, "#Open#1102#a_Open_empty##sampactn", '', 0, 0 buildsubmenu activeucmenu, 5, "#NewWind#1103#a_NewWindow##sampactn", '', 0, 0 buildsubmenu activeucmenu, 6, "#Settings#1104#a_Settings##sampactn", '', 0, 0 buildsubmenu activeucmenu, 7, "#Shell#1109#a_Shell##sampactn", '', 0, 0 buildsubmenu activeucmenu, 8, '', '', 16401, 0 -- MIS_SPACER buildsubmenu activeucmenu, 9, "#KwdHilit#1126#a_togl_hilit##sampactn", '', 0, 0 buildsubmenu activeucmenu, 10, "#MonoFont#1106#a_MonoFont##sampactn", '', 0, 0 showmenu activeucmenu, 3 toolbar_loaded = \1 -- "Built-in" defc addtb -- Sample command to add a button to the toolbar defined above -- This can be used to overwrite a button as well. universal activeucmenu, toolbar_loaded activeucmenu = 'toolbar' buildsubmenu activeucmenu, 11, "#OS/2 win#os2win.bmp#cmd_os2win##commands", '', 0, 0 showmenu activeucmenu, 3 defc deltb -- Sample command to delete the Settings button from the toolbar defined above universal activeucmenu, toolbar_loaded activeucmenu = 'toolbar' deletemenu activeucmenu, 6, 0, 0 showmenu activeucmenu, 3 compile endif -- 0