plugins.wlx
Class WLXPluginAdapter

java.lang.Object
  extended by plugins.wlx.WLXPluginAdapter
All Implemented Interfaces:
WLXPluginInterface
Direct Known Subclasses:
SwingWLXPlugin, SWTWLXPlugin

public abstract class WLXPluginAdapter
extends java.lang.Object
implements WLXPluginInterface

Author:
Ken

Field Summary
 
Fields inherited from interface plugins.wlx.WLXPluginInterface
LC_COPY, LC_NEWPARAMS, LC_SELECT_ALL, LC_SETPERCENT, LCP_ANSI, LCP_ASCII, LCP_CENTER, LCP_FITLARGERONLY, LCP_FITTOWINDOW, LCP_FORCESHOW, LCP_VARIABLE, LCP_WRAPTEXT, LCS_BACKWARDS, LCS_FINDFIRST, LCS_MATCHCASE, LCS_WHOLEWORDS, LISTPLUGIN_ERROR, LISTPLUGIN_OK
 
Constructor Summary
WLXPluginAdapter()
           
 
Method Summary
 int getHWND(java.lang.Object component)
          getHWMD is a callback function, to get the window handle of an AWT component.
 int getHWND2(javax.swing.JFrame frame)
          getHWMD2 is a callback function, to get the window handle of a JFrame.
 void listCloseWindow(int listWin)
          ListCloseWindow is called when a user closes lister, or loads a different file.
 void listDefaultGetParams(DefaultParam dps)
          ListSetDefaultParams is called immediately after loading the DLL, before ListLoad.
abstract  java.lang.String listGetDetectString(int maxLen)
          ListGetDetectString is called when the plugin is loaded for the first time.
 java.lang.Object listGetPreviewBitmap(java.lang.String fileToLoad, int width, int height, java.lang.String contentBuf, int contentBufLen, java.lang.StringBuffer filename)
          ListGetPreviewBitmap is called to retrieve a bitmap for the thumbnails view.
abstract  int listLoad(int parentWin, java.lang.String input, int showFlags)
          ListLoad is called when a user opens lister with F3 or the Quick View Panel with Ctrl+Q, and when the definition string either doesn't exist, or its evaluation returns true.
 int listLoadNext(int parentWin, int listWin, java.lang.String fileToLoad, int showFlags)
          New in Total Commander 7: ListLoadNext is called when a user switches to the next or previous file in lister with 'n' or 'p' keys, or goes to the next/previous file in the Quick View Panel, and when the definition string either doesn't exist, or its evaluation returns true.
 int listNotificationReceived(int listWin, int message, int wParam, int lParam)
          ListNotificationReceived is called when the parent window receives a notification message from the child window: WM_COMMAND, WM_NOTIFY, WM_MEASUREITEM or WM_DRAWITEM.
 int listPrint(int listWin, java.lang.String fileToPrint, java.lang.String defPrinter, int printFlags, java.awt.Rectangle margins)
          ListPrint is called when the user chooses the print function.
 int listSearchDialog(int listWin, int findNext)
          ListSearchDialog is called when the user tries to find text in the plugin.
 int listSearchText(int handle, java.lang.String searchString, int searchParameter)
          ListListSearchText is called when the user tries to find text in the plugin.
 int listSendCommand(int listWin, int command, int parameter)
          ListSendCommand is called when the user changes some options in Lister's menu.
protected  void setSize(int hwnd, int width, int height)
          Set the size of the lister window client area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WLXPluginAdapter

public WLXPluginAdapter()
Method Detail

getHWND

public final int getHWND(java.lang.Object component)
getHWMD is a callback function, to get the window handle of an AWT component.

Parameters:
component - the component to get the HWND for
Returns:
hwnd the HWND window handle of the diplayed component

getHWND2

public final int getHWND2(javax.swing.JFrame frame)
getHWMD2 is a callback function, to get the window handle of a JFrame.

Parameters:
frame - the JFrame to get the HWND window handle for.
Returns:
hwnd the HWND window handle of the JFrame

setSize

protected final void setSize(int hwnd,
                             int width,
                             int height)
Set the size of the lister window client area.

Parameters:
hwnd - the window handle of the lister window
width - the width of the client area
height - the height of the client area

listLoad

public abstract int listLoad(int parentWin,
                             java.lang.String input,
                             int showFlags)
ListLoad is called when a user opens lister with F3 or the Quick View Panel with Ctrl+Q, and when the definition string either doesn't exist, or its evaluation returns true.
Please note that multiple Lister windows can be open at the same time! Therefore you cannot save settings in global variables. You can call RegisterClass with the parameter cbWndExtra to reserve extra space for your data, which you can then access via GetWindowLong(). Or use an internal list, and store the list parameter via SetWindowLong(hwnd,GWL_ID,...). Lister will subclass your window to catch some hotkeys like 'n' or 'p'.
When lister is activated, it will set the focus to your window. If your window contains child windows, then make sure that you set the focus to the correct child when your main window receives the focus!
If lcp_forceshow is defined, you may try to load the file even if the plugin wasn't made for it. Example: A plugin with line numbers may only show the file as such when the user explicitly chooses 'Image/Multimedia' from the menu. Lister plugins which only create thumbnail images do not need to implement this function.

Specified by:
listLoad in interface WLXPluginInterface
Parameters:
parentWin - This is lister's window. Create your plugin window as a child of this window.
input - The name of the file which has to be loaded.
showFlags - A combination of the following flags:
  • lcp_wraptext Text: Word wrap mode is checked
  • lcp_fittowindow Images: Fit image to window is checked
  • lcp_ansi Ansi charset is checked
  • lcp_ascii Ascii(DOS) charset is checked
  • lcp_variable Variable width charset is checked
  • lcp_forceshow User chose 'Image/Multimedia' from the menu. See remarks.
You may ignore these parameters if they don't apply to your document type.
Returns:
Return a handle to your window if load succeeds, NULL otherwise. If NULL is returned, Lister will try the next plugin.

listCloseWindow

public void listCloseWindow(int listWin)
ListCloseWindow is called when a user closes lister, or loads a different file. If ListCloseWindow isn't present, DestroyWindow() is called.
You can use this function to close open files, free buffers etc.

Specified by:
listCloseWindow in interface WLXPluginInterface
Parameters:
listWin - This is the window handle which needs to be destroyed.

listGetDetectString

public abstract java.lang.String listGetDetectString(int maxLen)
ListGetDetectString is called when the plugin is loaded for the first time. It should return a parse function which allows Lister to find out whether your plugin can probably handle the file or not. You can use this as a first test - more thorough tests may be performed in ListLoad(). It's very important to define a good test string, especially when there are dozens of plugins loaded! The test string allows lister to load only those plugins relevant for that specific file type.
The syntax of the detection string is as follows. There are operands, operators and functions. Operands: Operators Functions Internal handling of variables
Varialbes can store numbers and strings. Operators can compare numbers with numbers and strings with strings, but not numbers with strings. Exception: A single char can also be compared with a number. Its value is its ANSI character code (e.g. "A"=65). Boolean values of comparisons are stored as 1 (true) and 0 (false).
Examples: Operator precedence:

Specified by:
listGetDetectString in interface WLXPluginInterface
Parameters:
maxLen - Maximum length, in bytes, of the detection string (currently 2k).
Returns:
Return the detection string here. See remarks for the syntax.

listSearchText

public int listSearchText(int handle,
                          java.lang.String searchString,
                          int searchParameter)
ListListSearchText is called when the user tries to find text in the plugin. Don't implement this function if your plugin doesn't contain any text, or doesn't support text searches!
The plugin needs to highlight/select the found text by itself.

Specified by:
listSearchText in interface WLXPluginInterface
Parameters:
handle - Handle to your list window created with ListLoad
searchString - String to be searched.
searchParameter - A combination of the following search flags: LCS_FINDFIRST, LCS_MATCHCASE, LCS_WHOLEWORDS, LCS_BACKWARDS
Returns:
LISTPLUGIN_OK - found, LISTPLUGIN_ERROR - not found

listSendCommand

public int listSendCommand(int listWin,
                           int command,
                           int parameter)
ListSendCommand is called when the user changes some options in Lister's menu.

Specified by:
listSendCommand in interface WLXPluginInterface
Parameters:
listWin - hande to your list window created with ListLoad
command - One of the following commands: LC_COPY, LC_NEWPARAMS, LC_SELECT_ALL, LC_SETPERCENT
parameter - Used for lc_newparams. May be a combination of: LCP_FITTOWINDOW, LCP_ANSI, LCP_ASCII, LCP_VARIABLE, LCP_WRAPTEXT, LCP_FORCESHOW
Returns:
Return either LISTPLUGIN_OK or LISTPLUGIN_ERROR.

listPrint

public int listPrint(int listWin,
                     java.lang.String fileToPrint,
                     java.lang.String defPrinter,
                     int printFlags,
                     java.awt.Rectangle margins)
ListPrint is called when the user chooses the print function.
You need to show a print dialog, in which the user can choose what to print, and select a different printer. See the sample plugin on how to do this!

Specified by:
listPrint in interface WLXPluginInterface
Parameters:
listWin - Hande to your list window created with ListLoad
fileToPrint - The full name of the file which needs to be printed. This is the same file as loaded with ListLoad.
defPrinter - Name of the printer currently chosen in Total Commander. May be NULL (use default printer).
printFlags - Currently not used (set to 0). May be used in a later version.
margins - The left, top, right and bottom margins of the print area, in MM_LOMETRIC measurement units (1/10 mm). May be ignored.
Returns:
Return either LISTPLUGIN_OK or LISTPLUGIN_ERROR.

listNotificationReceived

public int listNotificationReceived(int listWin,
                                    int message,
                                    int wParam,
                                    int lParam)
ListNotificationReceived is called when the parent window receives a notification message from the child window: WM_COMMAND, WM_NOTIFY, WM_MEASUREITEM or WM_DRAWITEM.
Do not implement this function if you don't use any owner-drawn controls and don't require any notification messages! Possible applications: Owner-drawn Listview control, reacting to scroll messages, etc.

Specified by:
listNotificationReceived in interface WLXPluginInterface
Parameters:
listWin - Hande to your list window created with ListLoad
message - The received message, one of the following: WM_COMMAND, WM_NOTIFY, WM_MEASUREITEM or WM_DRAWITEM. (from winuser.h)
wParam - The WPARAM parameter of the message.
lParam - The LPARAM parameter of the message.
Returns:
Return the value described for that message in the Windows API help.

listGetPreviewBitmap

public java.lang.Object listGetPreviewBitmap(java.lang.String fileToLoad,
                                             int width,
                                             int height,
                                             java.lang.String contentBuf,
                                             int contentBufLen,
                                             java.lang.StringBuffer filename)
ListGetPreviewBitmap is called to retrieve a bitmap for the thumbnails view. Please only implement and export this function if it makes sense to show preview pictures for the supported file types! This function is new in version 1.4. It requires Total Commander >=6.5, but is ignored by older versions.
  1. This function is only called in Total Commander 6.5 and later. The plugin version will be >= 1.4.
  2. The bitmap handle goes into possession of Total Commander, which will delete it after using it. The plugin must not delete the bitmap handle!
  3. Make sure you scale your image correctly to the desired maximum width+height! Do not fill the rest of the bitmap - instead, create a bitmap which is SMALLER than requested! This way, Total Commander can center your image and fill the rest with the default background color.

Specified by:
listGetPreviewBitmap in interface WLXPluginInterface
Parameters:
fileToLoad - The name of the file for which to load the preview bitmap.
width - Requested maximum width of the bitmap.
height - Requested maximum height of the bitmap
contentBuf - The first 8 kBytes (8k) of the file. Often this is enough data to show a reasonable preview, e.g. the first few lines of a text file.
contentBufLen - The length of the data passed in contentbuf. Please note that contentbuf is not a 0 terminated string, it may contains 0 bytes in the middle! It's just the 1:1 contents of the first 8k of the file.
filename - Here you need to return the bitmap handle. Three forms are supported:
  1. filename.append ("253|shell32.dll"); // load bitmap from a resource (EXE/DLL), referenced by a resource id
  2. filename.append ("G:\\Totalcmd\\plugins\\java\\Drives\\test.bmp"); // load bitmap from bmp file (absolute path name)
  3. filename.append ("%CWD%\\test.bmp"); // load bitmap from bmp file in the plugin directory
Returns:
Return a device-dependent bitmap created with e.g. CreateCompatibleBitmap.

listDefaultGetParams

public void listDefaultGetParams(DefaultParam dps)
ListSetDefaultParams is called immediately after loading the DLL, before ListLoad. This function is new in version 1.2. It requires Total Commander >=5.51, but is ignored by older versions.
This function is only called in Total Commander 5.51 and later. The plugin version will be >= 1.2.

Specified by:
listDefaultGetParams in interface WLXPluginInterface
Parameters:
dps - This structure of type ListDefaultParamStruct currently contains the version number of the plugin interface, and the suggested location for the settings file (ini file). It is recommended to store any plugin-specific information either directly in that file, or in that directory under a different name. Make sure to use a unique header when storing data in this file, because it is shared by other file system plugins! If your plugin needs more than 1kbyte of data, you should use your own ini file because ini files are limited to 64k.

listLoadNext

public int listLoadNext(int parentWin,
                        int listWin,
                        java.lang.String fileToLoad,
                        int showFlags)
New in Total Commander 7: ListLoadNext is called when a user switches to the next or previous file in lister with 'n' or 'p' keys, or goes to the next/previous file in the Quick View Panel, and when the definition string either doesn't exist, or its evaluation returns true.

Specified by:
listLoadNext in interface WLXPluginInterface
Parameters:
parentWin - This is lister's window. Your plugin window needs to be a child of this window
listWin - The plugin window returned by ListLoad
fileToLoad - The name of the file which has to be loaded.
showFlags - A combination of the following flags:
  • lcp_wraptext Text: Word wrap mode is checked
  • lcp_fittowindow Images: Fit image to window is checked
  • lcp_fitlargeronly Fit image to window only if larger than the window. Always set together with lcp_fittowindow.
  • lcp_center Center image in viewer window
  • lcp_ansi Ansi charset is checked
  • lcp_ascii Ascii(DOS) charset is checked
  • lcp_variable Variable width charset is checked
  • lcp_forceshow User chose 'Image/Multimedia' from the menu. See remarks.
You may ignore these parameters if they don't apply to your document type.
Returns:
LISTPLUGIN_OK if load succeeds, LISTPLUGIN_ERROR otherwise. If LISTPLUGIN_ERROR is returned, Lister will try to load the file with the normal ListLoad function (also with other plugins).
Remarks:
Please note that multiple Lister windows can be open at the same time! Therefore you cannot save settings in global variables. You can call RegisterClass with the parameter CBWNDEXTRA to reserve extra space for your data, which you can then access via GetWindowLong(). Or use an internal list, and store the list parameter via SetWindowLong(hwnd,GWL_ID,...). Lister will subclass your window to catch some hotkeys like 'n' or 'p'. When lister is activated, it will set the focus to your window. If your window contains child windows, then make sure that you set the focus to the correct child when your main window receives the focus!
If LCP_FORCESHOW is defined, you may try to load the file even if the plugin wasn't made for it.
Example: A plugin with line numbers may only show the file as such when the user explicitly chooses 'Image/Multimedia' from the menu.
Lister plugins which only create thumbnail images do not need to implement this function. If you do not implement ListLoadNext but only ListLoad, then the plugin will be unloaded and loaded again when switching through files, which results in flickering.

listSearchDialog

public int listSearchDialog(int listWin,
                            int findNext)
ListSearchDialog is called when the user tries to find text in the plugin. Only implement this function if your plugin requires a plugin-specific search dialog! For searching text, please implement ListSearchText instead!

Specified by:
listSearchDialog in interface WLXPluginInterface
Parameters:
listWin - Hande to your list window created with ListLoad
findNext - 0: FindFirst was chosen by the user
1: FindNext was chosen from the menu
Returns:
LISTPLUGIN_OK if you implement this function, or LISTPLUGIN_ERROR if Total Commander should show its own text search dialog and call ListSearchText later. This allows a plugin to support both its own search method via ListSearchDialog, and the standard search method via ListSearchText! Do NOT return LISTPLUGIN_ERROR if the search fails!
Remarks:
The plugin needs to show the search dialog and highlight/select the found text by itself. Requires Total Commander 7 or later.