home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 June / CHIP_CD_2004-06.iso / software / miranda_hit / files / popup.mir / m_popup_inc < prev    next >
Text File  |  2003-03-13  |  8KB  |  223 lines

  1. (*
  2. ===============================================================================
  3.                                 PopUp plugin
  4. Plugin Name: PopUp
  5. Plugin author: hrk, Luca Santarelli, hrk@users.sourceforge.net
  6. This file has been created by egodust, Sam, egodust@users.sourceforge.net
  7. ===============================================================================
  8.  
  9. The purpose of this plugin is to give developers a common "platform/interface" to show PopUps. It is born from the source code of NewStatusNotify, another plugin I've made.
  10.  
  11. Remember that users *must* have this plugin enabled, or they won't get any popup. Write this in the requirements, do whatever you wish ;-)... but tell them!
  12. ===============================================================================
  13.  
  14. -- To use this file you need Windows.pas, m_globaldefs.pas (get it from the CVS under the 'inc' module)
  15. -- To include this in the source, use {$include m_popup.h}
  16.  
  17. *)
  18.  
  19. {$ifndef M_POPUP_H}
  20. {$define M_POPUP_H}
  21.  
  22. {$ifdef FPC}
  23.     {$PACKRECORDS C}
  24.     {$MODE Delphi}
  25. {$endif}
  26.  
  27. const
  28.  
  29.     MAX_CONTACTNAME = 2048;
  30.     MAX_SECONDLINE  = 2048;
  31.  
  32.     SM_WARNING      = $01;      //Triangle icon.
  33.     SM_NOTIFY       = $02;      //Exclamation mark icon.
  34.  
  35. type
  36.  
  37.     // for info on what this stuff is, see m_popup.h
  38.  
  39.     PPOPUPDATA = ^TPOPUPDATA;
  40.     TPOPUPDATA = record
  41.         lchContact: HCONTACT;
  42.         lchIcon: THandle;
  43.         lpszContactName: array[0..MAX_CONTACTNAME-1] of Char;
  44.         lpszText: array[0..MAX_SECONDLINE-1] of Char;
  45.         colorBack: COLORREF;
  46.         colorForeText: COLORREF;
  47.         PluginWindowProc: Pointer;      // must be a window procedure using stdcall
  48.         PluginData: Pointer;
  49.     end;
  50.  
  51. type
  52.  
  53.     // for info on what this stuff is, see m_popup.h
  54.  
  55.     PPOPUPDATAEX = ^TPOPUPDATAEX;
  56.     TPOPUPDATAEX = record
  57.         lchContact: HCONTACT;
  58.         lchIcon: THandle;
  59.         lpszContactName: array[0..MAX_CONTACTNAME-1] of Char;
  60.         lpszText: array[0..MAX_SECONDLINE-1] of Char;
  61.         colorBack: COLORREF;
  62.         colorForeText: COLORREF;
  63.         PluginWindowProc: Pointer;      // must be a window procedure using stdcall
  64.         PluginData: Pointer;
  65.         iSeconds: int;      //Custom delay time in seconds. -1 means "forever", 0 means "default time".
  66.         cZero: array[0..15] of Char;      //16 unused bytes which may come useful in the future.
  67.     end;
  68.  
  69. const
  70.  
  71. (*
  72.     Creates, adds and shows a popup, given a (valid) POPUPDATA structure pointer.
  73.     wParam = (WPARAM)(*POPUPDATA)PopUpDataAddress
  74.     lParam = 0
  75.     Returns: > 0 on success, 0 if creation went bad, -1 if the PopUpData contained unacceptable values.
  76.     NOTE: it returns -1 if the PopUpData was not valid, if there were already too many popups, if the module was disabled.
  77.     Otherwise, it can return anything else...
  78. *)
  79.  
  80.     MS_POPUP_ADDPOPUP = 'PopUp/AddPopUp';
  81.  
  82. (*
  83.     The same, but with a POPUPDATAEX structure pointer.
  84.     wParam = (WPARAM)(*POPUPDATAEX)PopUpDataExAddress
  85.     lParam = 0
  86. *)
  87.  
  88.     MS_POPUP_ADDPOPUPEX = 'PopUp/AddPopUpEx';
  89.  
  90. (*
  91.     Returns the handle to the contact associated to the specified PopUpWindow.
  92.     You will probably need to know this handle inside your WNDPROC. Exampole: you want to open the MessageWindow. :-)
  93.     Call MS_POPUP_GETCONTACT on the hWnd you were given in the WNDPROC.
  94.     wParam = (WPARAM)(HWND)hPopUpWindow
  95.     lParam = 0;
  96.     Returns: the HANDLE of the contact. Can return NULL, meaning it's the main contact. -1 means failure.
  97. *)  
  98.  
  99.     MS_POPUP_GETCONTACT = 'PopUp/GetContact';
  100.     
  101. (*
  102.     wParam = hPopUpWindow
  103.     lParam = PluginDataAddress;
  104.     Returns: the address of the PLUGINDATA structure. Can return NULL, meaning nothing was given. -1 means failure.
  105.     IMPORTANT NOTE: it doesn't seem to work if you do:
  106.     CallService(..., (LPARAM)aPointerToAStruct);
  107.     and then use that struct.
  108.     Do this, instead:
  109.     aPointerToStruct = CallService(..., (LPARAM)aPointerToAStruct);
  110.     and it will work. Just look at the example I've written above (PopUpDlgProc).
  111. *)
  112.     MS_POPUP_GETPLUGINDATA = 'PopUp/GetPluginData';
  113.     
  114. (*
  115.     wParam = 0
  116.     lParam = 0
  117.     Returns: 0 if the user has chosen not to have the second line, 1 if he choose to have the second line.
  118. *)
  119.     MS_POPUP_ISSECONDLINESHOWN = 'PopUp/IsSecondLineShown';
  120.     
  121. (*
  122.     UM_FREEPLUGINDATA
  123.     wParam = lParam = 0. Process this message if you have allocated your own memory. (i.e.: POPUPDATA.PluginData != NULL)
  124. *)
  125.     UM_FREEPLUGINDATA        = ((*WM_USER*)$400 + $200);
  126.     
  127. (*
  128.     UM_DESTROYPOPUP
  129.     wParam = lParam = 0. Send this message when you want to destroy the popup, or use the function below.
  130. *)
  131.     UM_DESTROYPOPUP          = ((*WM_USER*)$400 + $201);
  132.  
  133. (*
  134.     UM_INITPOPUP
  135.     wParam = (WPARAM)(HWND)hPopUpWindow (but this is useless, since I'll directly send it to your hPopUpWindow
  136.     lParam = 0.
  137.     This message is sent to the PopUp when its creation has been finished, so POPUPDATA (and thus your PluginData) is reachable.
  138.     Catch it if you needed to catch WM_CREATE or WM_INITDIALOG, which you'll never ever get in your entire popup-life.
  139.     Return value: if you process this message, return 0. If you don't process it, return 0. Do whatever you like ;-)
  140. *)
  141.     UM_INITPOPUP            = ($400(*WM_USER*) + $202);
  142.  
  143. (*
  144.     wParam = hPopUpWindow
  145.     lParam = lpzNewText
  146.     returns: > 0 for success, -1 for failure, 0 if the failure is due to second line not being shown. (but you could call PUIsSecondLineShown() before changing the text...)
  147.     Changes the text displayed in the second line of the popup.
  148. *)
  149.     MS_POPUP_CHANGETEXT         = 'PopUp/Changetext';
  150.  
  151. (*
  152.     This is mainly for developers.
  153.     Shows a warning message in a PopUp. It's useful if you need a "MessageBox" like function, but you don't want a modal window (which will interfere with a DialogProcedure. MessageBox steals focus and control, this one not.
  154.     wParam = lpzMessage
  155.     lParam = 0;  Returns: 0 if the popup was shown, -1 in case of failure.
  156. *)
  157.     MS_POPUP_SHOWMESSAGE        = 'PopUp/ShowMessage';
  158.     
  159.  
  160.     (* helper functions, will be inlined on FPC if you have the swithces enabled *)
  161.     
  162.     function PUAddPopup(ppdp: PPOPUPDATA): int;
  163.     {$ifdef FPC}
  164.     inline;
  165.     {$endif}
  166.     begin
  167.         Result := CallService(MS_POPUP_ADDPOPUP, WPARAM(ppdp), 0);
  168.     end;
  169.     
  170.     function PUGetContact(hPopUpWindow: THandle): THandle;
  171.     {$ifdef FPC}
  172.     inline;
  173.     {$endif}
  174.     begin
  175.         Result := CallService(MS_POPUP_GETCONTACT, WPARAM(hPopUpWindow), 0);
  176.     end;
  177.  
  178.     function PUGetPluginData(hPopUpWindow: THandle): Pointer;
  179.     {$ifdef FPC}
  180.     inline;
  181.     {$endif}
  182.     var
  183.         dummy: pointer;
  184.     begin
  185.         dummy := nil;
  186.         Int(Result) := CallService(MS_POPUP_GETPLUGINDATA, WPARAM(hPopUpWindow), LPARAM(dummy));
  187.     end;
  188.  
  189.     function PUIsSecondLineShown: BOOL;
  190.     {$ifdef FPC}
  191.     inline;
  192.     {$endif}
  193.     begin
  194.         Int(Result) := CallService(MS_POPUP_ISSECONDLINESHOWN, 0, 0);
  195.     end;
  196.  
  197.     function PUDeletePopUp(hWndPopUp: THandle): int;
  198.     {$ifdef FPC}
  199.     inline;
  200.     {$endif}
  201.     begin
  202.         Result := SendMessage(hWndPopUp, UM_DESTROYPOPUP, 0, 0);
  203.     end;
  204.     
  205.     function PUChangeText(hWndPopUp: THandle; lpzNewText: PChar): int;
  206.     {$ifdef FPC}
  207.     inline;
  208.     {$endif}
  209.     begin
  210.         Result := CallService(MS_POPUP_CHANGETEXT, WPARAM(hWndPopUp), LPARAM(lpzNewText));
  211.     end;
  212.     
  213.     function PUShowMessage(lpzText: PChar; kind: Byte): int;
  214.     {$ifdef FPC}
  215.     inline;
  216.     {$endif}
  217.     begin
  218.         Result := CallService(MS_POPUP_SHOWMESSAGE, WPARAM(lpzText), LPARAM(kind));
  219.     end;
  220.  
  221. {$endif}
  222.  
  223.