home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / OLEDLG.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  34KB  |  1,230 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Base OLE UI dialog class definitions
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_OLEDLG_H)
  8. #define OWL_OLEDLG_H
  9.  
  10. #if !defined(OWL_OPENSAVE_H)
  11. # include <owl/opensave.h>
  12. #endif
  13. #if !defined(OWL_CONTROL_H)
  14. # include <owl/control.h>
  15. #endif
  16. #if !defined(OWL_GDIOBJEC_H)
  17. # include <owl/gdiobjec.h>
  18. #endif
  19. #if !defined(OCF_OCVIEW_H)
  20. # include <ocf/ocview.h>
  21. #endif
  22.  
  23. #include <owl/oledlg.rh>
  24. class _OWLCLASS TWindow;
  25. class _OWLCLASS TEdit;
  26. class _OWLCLASS TStatic;
  27. class _OWLCLASS TButton;
  28. class _OWLCLASS TRadioButton;
  29. class _OWLCLASS TCheckBox;
  30. class _OWLCLASS TListBox;
  31.  
  32. //
  33. // Constants
  34. //
  35. const int MaxLinkTypes    = 8;      // Max # of link types
  36. const int MaxPathLen      = 256;    // Max length of file name
  37. const int MaxKeyLen       = 256;    // Max lenght of reg. key
  38. const int LoadStringLen   = 256;    // Default length buffer for LoadStrings
  39. const int MaxLabelLen     = 40;     // Max length of icon label
  40. const int MaxUnknownLen   = 100;    // Max Length of UnknownType string
  41. const int CLSIDStringLen  = 39;     // Length of string CLSID
  42. const int GenericBufferLen= 1024;   // Generic scratch buffer length
  43. const int cxIconPad       = 12;     // x-padding in TIconListBox
  44. const int cyIconPad       = 4;      // y-padding in TIconListBox
  45. const int LinkTypeLen     = 20;     // Hold "Automatic" or "Manual"
  46. const int LinksListCols   = 3;      // Number of Column in Edit Links Dlg
  47. const int PrefixSize      = 8;      // Used for Chopping text
  48. const int MaxFormatEtc    = 20;     // Max. # of FormatEtc
  49. const int HiMetricPerInch = 2540;
  50. extern const char ClsIdStr[];        // "\\CLSID" Helpful when RegDB-searching
  51.  
  52. //
  53. // Clipboard Format Strings
  54. //
  55. #if !defined(CF_EMBEDSOURCE)
  56. # define CF_EMBEDSOURCE        "Embed Source"
  57. #endif
  58. #if !defined(CF_EMBEDDEDOBJECT)
  59. # define CF_EMBEDDEDOBJECT     "Embedded Object"
  60. #endif
  61. #if !defined(CF_LINKSOURCE)
  62. # define CF_LINKSOURCE         "Link Source"
  63. #endif
  64. #if !defined(CF_CUSTOMLINKSOURCE)
  65. # define CF_CUSTOMLINKSOURCE   "Custom Link Source"
  66. #endif
  67. #if !defined(CF_OBJECTDESCRIPTOR)
  68. # define CF_OBJECTDESCRIPTOR   "Object Descriptor"
  69. #endif
  70. #if !defined(CF_LINKSRCDESCRIPTOR)
  71. # define CF_LINKSRCDESCRIPTOR  "Link Source Descriptor"
  72. #endif
  73. #if !defined(CF_OWNERLINK)
  74. # define CF_OWNERLINK          "OwnerLink"
  75. #endif
  76. #if !defined(CF_FILENAME)
  77. # define CF_FILENAME           "FileName"
  78. #endif
  79. #if !defined(NEXTCBVIEWER)
  80. # define NEXTCBVIEWER          "NextCBViewer"
  81. #endif
  82.  
  83. //
  84. // Forward referenced classes
  85. //
  86. class _OWLCLASS TIconListBox;
  87.  
  88. //
  89. //
  90. // Class TOleDialog
  91. // ----- ----------
  92. //  Base class of OLE dialogs
  93. //
  94. class _USERCLASS TOleDialog : public TDialog { 
  95.   public:
  96.     TOleDialog(TWindow* parent,
  97.                TResId   templateId,
  98.                const char far *title = 0,
  99.                TModule *module = 0);
  100.  
  101.     //
  102.     // Disable modeless usage
  103.     //
  104.     HWND          DoCreate()  { return 0; }
  105.  
  106.     //
  107.     // Force derive class to redefine 
  108.     //
  109.     int           DoExecute() = 0;
  110.  
  111.   protected:
  112.     void          SetupWindow();
  113.     void          CleanupWindow();
  114.  
  115.     //
  116.     // Event handlers to allow proper cleanup prior to closing the dialog
  117.     //
  118.     void          CmOk();
  119.     virtual bool  OleDlgOk() = 0;
  120.  
  121.     //
  122.     // To Enable/Show or Disable/Hide a control
  123.     //
  124.     void          Activate(TWindow*, bool);
  125.  
  126.     //
  127.     // OLE 2.0 Wrappers to simplify Dlg. management
  128.     //  [Based on OLESTD, OLE2UI, BOleService etc.]
  129.     //
  130.     HGLOBAL       GetIconFromClass(REFCLSID clsid, const char far* label, bool useType);
  131.     HGLOBAL       GetIconFromFile(const char far* path, bool useFile);
  132.     HGLOBAL       FillObjectDescriptorFromData(LPDATAOBJECT dataObject,
  133.                                                LPSTGMEDIUM  medium,
  134.                                                CLIPFORMAT FAR *cfFmt);
  135.     HGLOBAL       GetObjectDescriptorData(CLSID clsid, DWORD dwDrawAspect,
  136.                                           SIZEL sizel, POINTL pointl,
  137.                                           DWORD dwStatus,
  138.                                           LPSTR lpszFullUserTypeName,
  139.                                           LPSTR lpszSrcOfCopy);
  140.     uint          GetAuxUserType(REFCLSID clsid, WORD auxUserType,
  141.                                  char far* lpszAuxUserType, int len,
  142.                                  HKEY hkey);
  143.     uint          GetUserTypeOfClass(REFCLSID clsid, char far* lpszUserStr,
  144.                                      uint len);
  145.     HGLOBAL       GetData(LPDATAOBJECT dataObj, CLIPFORMAT cfFormat,
  146.                           DVTARGETDEVICE FAR *targetDevice, DWORD aspect,
  147.                           LPSTGMEDIUM medium);
  148.  
  149.     //
  150.     // Helper routines shared by OLE Dialogs
  151.     //
  152.     HFILE         DoesFileExist(const char* filename, OFSTRUCT& ofs);
  153.     char far*     PtrToNthField(char far*, int nField, char chDelim);
  154.     int           ErrorWithFile(uint strId, const char* fileName,
  155.                                 uint mbFlags = MB_OK);
  156.     void          OpenFileError(uint errCode, const char* fileName);
  157.     bool          BrowseDlg(char* file, char* initialDir, uint filterId,
  158.                             uint32 flags);
  159.     int           PopupMessage(uint idMsg, uint idTitle, uint mbFlags);
  160.     int           GetTextWSize(TDC &dc, char far* lpsz);
  161.     char far*     ChopText(TWindow&, int widdth, char far* str);
  162.     char far*     AnsiPrev(const char far* start, const char far* current);
  163.     char far*     AnsiNext(const char far* current);
  164.  
  165.     //
  166.     // Near versions of few helpers from above [used in MEDIUM model]
  167.     //
  168. #if defined(BI_DATA_NEAR)
  169.     char*         ChopText(TWindow&, int width, char* str);
  170.     char*         AnsiPrev(const char* start, const char* current);
  171.     char*         AnsiNext(const char* current);
  172. #endif
  173.  
  174.     //
  175.     // Clipboard formats
  176.     //
  177.     static uint16 cfObjectDescriptor;
  178.     static uint16 cfLinkSrcDescriptor;
  179.     static uint16 cfEmbedSource;
  180.     static uint16 cfEmbeddedObject;
  181.     static uint16 cfLinkSource;
  182.     static uint16 cfOwnerLink;
  183.     static uint16 cfFileName;
  184.     static bool   cfInit;
  185.  
  186.     //
  187.     // Non-bold font for static controls
  188.     //
  189.     TFont*        Font;
  190.  
  191.     //
  192.     // Dialog's title
  193.     //
  194.     const char far* ODTitle;
  195.  
  196.   DECLARE_RESPONSE_TABLE(TOleDialog);
  197. };
  198.  
  199.  
  200. //
  201. // Class TIconImage
  202. // ----- ----------
  203. //  Simple control which displays an OLE Icon [which is really a metafile
  204. //  with embedded icon and label].
  205. //
  206. class TIconImage : public TControl {
  207.   public:
  208.     TIconImage(TWindow* parent, int resourceId, TModule* module = 0);
  209.  
  210.     void        GetWindowClass(WNDCLASS& wndclass);
  211.     char far*   GetClassName();
  212.  
  213.     bool        SetMetaPict(HGLOBAL hMetaPict, bool deleteOld = false);
  214.     HGLOBAL     GetMetaPict() const { return MetaPict;  }
  215.  
  216.   protected:
  217.     void        EvPaint();
  218.     bool        EvEraseBkgnd(HDC);
  219.  
  220.   private:
  221.     HGLOBAL     MetaPict;
  222.  
  223.   DECLARE_RESPONSE_TABLE(TIconImage);
  224. };
  225.  
  226.  
  227. //
  228. // Indices of the predefined bitmap used by TResultImage
  229. //
  230. const uint riNone       = 0xffff;
  231. const uint riPaste      = 0;
  232. const uint riEmbed      = 1;
  233. const uint riEmbedIcon  = 2;
  234. const uint riLink       = 3;
  235. const uint riLinkIcon   = 4;
  236.  
  237.  
  238. //
  239. // Class TResultImage
  240. // ----- ------------
  241. //  Control which simply displays a bitmap leaving one of the colors as
  242. //  transparent. Can also only display part of the bitmap if the latter
  243. //  is a *bitmap of smaller bitmaps*.
  244. //
  245. class _USERCLASS TResultImage : public TControl {
  246.   public:
  247.     TResultImage(TWindow* parent, int resourceId, TModule* module = 0);
  248.     ~TResultImage();
  249.  
  250.     void        GetWindowClass(WNDCLASS& wndclass);
  251.     char far*   GetClassName();
  252.  
  253.     void        SetBitmap(TResId resId, TColor transparent = TColor::Black,
  254.                           uint numRows = 0, uint index = 0,
  255.                           TAutoDelete = AutoDelete);
  256.     void        SetBitmapIndex(uint);
  257.  
  258.   protected:
  259.     void        EvPaint();
  260.     void        SetupWindow();
  261.  
  262.     TBitmap    *Bitmap;
  263.     bool        ShouldDelete;
  264.     uint        NumRows, CurIndex, CX, CY;
  265.     TColor      ClearColor;
  266.  
  267.   DECLARE_RESPONSE_TABLE(TResultImage);
  268. };
  269.  
  270.  
  271. //
  272. // Class TOleMetaPict
  273. // ----- ------------
  274. //  Helper class providing methods to manipulate an OLE Icon [which is
  275. //  really a metafile with embedded icon, label and icon source info]
  276. //
  277. class _USERCLASS TOleMetaPict {
  278.   public:
  279.     TOleMetaPict(HICON hIcon, char far* lpszLabel, TAutoDelete = AutoDelete);
  280.     TOleMetaPict(HGLOBAL metaPict, TAutoDelete = NoAutoDelete);
  281.     ~TOleMetaPict();
  282.  
  283.     //
  284.     // Conversion operator to underlying/native type
  285.     //
  286.     operator      HGLOBAL() const { return MetaPict;  }
  287.  
  288.     bool          Draw(TDC &dc, TRect &rect, bool IconOnly) const;
  289.     int           ExtractLabel(char far* label, uint32* wrap=0) const;
  290.     HICON         ExtractIcon(HINSTANCE) const;
  291.     bool          ExtractIconSource(char far* source, uint& index) const;
  292.     static bool   Free(HGLOBAL& metaPict);
  293.  
  294.   protected:
  295.     HGLOBAL       MetaPict;
  296.     bool          ShouldDelete;
  297. };
  298.  
  299.  
  300. //
  301. // ChangeIcon Data Flags
  302. //
  303. enum TChangeIconFlags {
  304.   ciShowHelp      = 0x0001,
  305.   ciSelectCurrent = 0x0002,
  306.   ciSelectDefault = 0x0004,
  307.   ciSelectFromFile= 0x0008,
  308.   ciUseIconExe    = 0x0010,
  309. };
  310.  
  311.  
  312. //
  313. // Class TChangeIconDlg
  314. // ----- --------------
  315. //
  316. class _USERCLASS TChangeIconDlg : public TOleDialog {
  317.   public:
  318.     class _USERCLASS TData {
  319.       public:
  320.         TData();
  321.         uint32    Flags;                  // Data Flags
  322.         HGLOBAL   MetaPict;               // *The* image
  323.         CLSID     ClsId;                  // Class for Default Icon
  324.         char      IconExe[MaxPathLen];    // File to extract icon from
  325.     };
  326.  
  327.     TChangeIconDlg(TWindow* parent,
  328.                    TData&   data,
  329.                    TResId   templateId = 0,
  330.                    const char far* title = 0,
  331.                    TModule* module = 0);
  332.     ~TChangeIconDlg();
  333.     int                 DoExecute();
  334.  
  335.   protected:
  336.     void                SetupWindow();
  337.     void                CleanupWindow();
  338.     bool                OleDlgOk();
  339.  
  340.     void                SetIcon(TStatic&, HICON);
  341.  
  342.     uint                FillIconList(const char*);
  343.     void                UpdateResultIcon(TChangeIconFlags);
  344.  
  345.     void                CurrentClicked();
  346.     void                DefaultClicked();
  347.     void                FromFileClicked();
  348.  
  349.     void                LabelKillFocus();
  350.     void                FileNameNotification(uint);
  351.     void                IconListSetFocus();
  352.     void                IconListSelChange();
  353.     void                IconListDblClk();
  354.     void                BrowseClicked();
  355.  
  356.     TData&              Data;
  357.  
  358.     TStatic*            CurrentIcon;
  359.     TStatic*            DefaultIcon;
  360.     TRadioButton*       Current;
  361.     TRadioButton*       Default;
  362.     TRadioButton*       FromFile;
  363.  
  364.     TEdit*              FileName;
  365.     TIconListBox*       IconList;
  366.  
  367.     TEdit*              Label;
  368.     TStatic*            ResultIcon;
  369.     TStatic*            ResultLabel;
  370.  
  371.     TButton*            Help;
  372.     TButton*            Browse;
  373.  
  374.   private:
  375.     //
  376.     // Used internally to keep track of dialog's state
  377.     //
  378.     class _USERCLASS THelper {
  379.       public:
  380.         THelper();
  381.  
  382.         uint32    Flags;
  383.         HICON     CurIcon;
  384.         char      Label[MaxLabelLen+1];
  385.         char      File[MaxPathLen];
  386.         uint      IconIndex;
  387.  
  388.         HICON     DefIcon;
  389.         char      DefIconFile[MaxPathLen];
  390.         uint      DefIconIndex;
  391.     };
  392.  
  393.    THelper&       Helper;
  394.  
  395.   DECLARE_RESPONSE_TABLE(TChangeIconDlg);
  396. };
  397.  
  398.  
  399. //
  400. // Enumerations used to populate Flags member of TInsertObjectDlg::TData
  401. //
  402. enum TInsertObjectFlags {
  403.   ioShowHelp            = 0x0001,
  404.   ioSelectCreateNew     = 0x0002,
  405.   ioSelectCreateFromFile= 0x0004,
  406.   ioCheckLink           = 0x0008,
  407.   ioCheckDisplayAsIcon  = 0x0010,
  408.   ioDisableLink         = 0x0100,
  409.   ioVerifyServerExist   = 0x0200,
  410.   ioDisableDisplayAsIcon= 0x0400
  411. };
  412.  
  413.  
  414. //
  415. // Class TInsertObjectDlg
  416. // ----- ----------------
  417. //
  418. class _USERCLASS TInsertObjectDlg : public TOleDialog {
  419.   public:
  420.     //
  421.     // Class TData  (InsertObject Data)
  422.     // ----- -----  ------------- -----
  423.     //
  424.     class _USERCLASS TData {
  425.       public:
  426.         TData();
  427.         uint32      Flags;
  428.         CLSID       ClsId;
  429.         char far*   FileName;
  430.         LPCLSID     lpClsIdExclude;
  431.         uint        cClsIdExclude;
  432.         HGLOBAL     MetaPict;
  433.     };
  434.  
  435.     TInsertObjectDlg(TWindow* parent,
  436.                      TOcInitInfo &initInfo,
  437.                      TData  *insObj = 0,
  438.                      TResId  templateId = 0,
  439.                      const char far* title = 0,
  440.                      TModule* module = 0);
  441.    ~TInsertObjectDlg();
  442.     int           DoExecute();
  443.  
  444.   protected:
  445.     bool          EvInitDialog(HWND);
  446.     void          CleanupWindow();
  447.     bool          OleDlgOk();
  448.  
  449.     int           FillClassList();
  450.     bool          ToggleObjectSource(TInsertObjectFlags);
  451.     void          UpdateClassType(bool);
  452.     void          UpdateClassIcon();
  453.     void          SetInsertObjectResults();
  454.     bool          ValidateInsertFile(bool showErr=true);
  455.     bool          GetCurrentCLSID(CLSID&);
  456.  
  457.     //
  458.     // Response Methods
  459.     //
  460.     void          CreateNewClicked();
  461.     void          CreateFromFileClicked();
  462.     void          BrowseFileClicked();
  463.     void          LinkToFileClicked();
  464.     void          DisplayAsIconClicked();
  465.     void          ChangeIconClicked();
  466.     void          ObjectListChanged();
  467.     void          ObjectListDoubleClicked();
  468.     void          FileNameChanged();
  469.     void          FileNameKillFocus();
  470.  
  471.     TOcInitInfo&  InitInfo;
  472.     TData*        Data;
  473.  
  474.     TCheckBox*    DisplayAsIcon;
  475.     TButton*      ChangeIcon;
  476.     TButton*      Browse;
  477.     TCheckBox*    Link;
  478.     TStatic*      File;
  479.     TStatic*      FileType;
  480.     TEdit*        FileName;
  481.     TListBox*     ObjectList;
  482.     TStatic*      ObjectType;
  483.     TStatic*      ResultText;
  484.     TResultImage* ResultImage;
  485.     TIconImage*   IconImage;
  486.     TButton*      Help;
  487.     TButton*      Ok;
  488.     TRadioButton* CreateNew;
  489.     TRadioButton* CreateFromFile;
  490.  
  491.   private:
  492.     bool          GetDefaultInsertObjectData();
  493.  
  494.     //
  495.     // Class THelper
  496.     // ----- -------
  497.     //  Used internally to keep track of dialog's state
  498.     //
  499.     class _USERCLASS THelper {
  500.       public:
  501.         THelper();
  502.  
  503.         uint32    Flags;
  504.         CLSID     ClsId;
  505.         char      FileName[MaxPathLen];
  506.         bool      FileSelected;
  507.         bool      AsIconNew;
  508.         bool      AsIconFile;
  509.         bool      FileDirty;
  510.         bool      FileValid;
  511.         uint      ErrCode;
  512.         HGLOBAL   MetaPict;
  513.     };
  514.  
  515.     THelper&      Helper;
  516.     bool          DeleteData;
  517.  
  518.     static OLECHAR  DynamicScopePath[MaxPathLen];
  519.     static CLSID    DynamicScopeClsid;
  520.  
  521.   DECLARE_RESPONSE_TABLE(TInsertObjectDlg);
  522. };
  523.  
  524.  
  525. //
  526. // Enumeration flags for Flags member of TConvertDlg::TData
  527. //
  528. enum TConvertFlags {
  529.   cvShowHelpButton      = 0x0001,
  530.   cvSetConvertDefault   = 0x0002,
  531.   cvSetActivateDefault  = 0x0004,
  532.   cvSelectConvertTo     = 0x0008,
  533.   cvSelectActivateAs    = 0x0010,
  534.   cvDisableDisplayAsIcon= 0x0020,
  535.   cvDisableActivateAs   = 0x0040
  536. };
  537.  
  538.  
  539. //
  540. // Class TConvertDlg
  541. // ----- -----------
  542. //
  543. class _USERCLASS TConvertDlg : public TOleDialog {
  544.   public:
  545.     //
  546.     // Class TData
  547.     // ----- -----
  548.     //
  549.     class _USERCLASS TData {
  550.       public:
  551.         TData(TOcPart& ocpart);
  552.  
  553.         uint32    Flags;
  554.         CLSID     ClsId;
  555.         CLSID     ClsIdConvertDefault;
  556.         CLSID     ClsIdActivateDefault;
  557.         CLSID     ClsIdNew;
  558.         uint32    dvAspect;
  559.         WORD      wFormat;
  560.         bool      fIsLinkedObject;
  561.         HGLOBAL   MetaPict;
  562.         LPSTR     lpszUserType;
  563.         bool      fObjectsIconChanged;
  564.         LPSTR     lpszDefLabel;
  565.         uint      ClsIdExclude;
  566.         LPCLSID   lpClsIdExclude;
  567.     };
  568.  
  569.     TConvertDlg(TWindow* parent, TData& data, TResId  templateId = 0,
  570.                 const char far* title = 0, TModule* module = 0);
  571.    ~TConvertDlg();
  572.  
  573.     void          SetupWindow();
  574.     void          CleanupWindow();
  575.  
  576.   protected:
  577.     uint          FillClassList();
  578.     void          UpdateClassIcon();
  579.     bool          IsValidClassID(CLSID);
  580.     void          SetConvertResults();
  581.     bool          FormatIncluded(char* str, WORD wFormat);
  582.  
  583.     TStatic*      ObjectType;
  584.     TListBox*     ConvertList;
  585.     TListBox*     ActivateList;
  586.  
  587.     TCheckBox*    DisplayAsIcon;
  588.     TStatic*      ResultText;
  589.     TStatic*      ResultIcon;
  590.     TStatic*      IconLabel1;
  591.     TStatic*      IconLabel2;
  592.  
  593.     TRadioButton* ConvertTo;
  594.     TRadioButton* ActivateAs;
  595.     TButton*      ChangeIcon;
  596.  
  597.     TButton*      Help;
  598.  
  599.     TData&        Data;
  600.   private:
  601.     //
  602.     // Class used internally to keep track of dialog state
  603.     //
  604.     class _USERCLASS THelper {
  605.       public:
  606.         THelper(){ memset(this, 0, sizeof(THelper)); }
  607.  
  608.         uint32      Flags;
  609.         TListBox*   VisibleList;
  610.         TListBox*   InvisibleList;
  611.         CLSID       ClsId;
  612.         DWORD       dvAspect;
  613.         bool        fCustomIcon;
  614.         uint        IconIndex;
  615.         LPSTR       lpszIconSource;
  616.         LPSTR       lpszCurrentObject;
  617.         LPSTR       lpszConvertDefault;
  618.         LPSTR       lpszActivateDefault;
  619.    };
  620.    THelper&         Helper;
  621.  
  622.   DECLARE_RESPONSE_TABLE(TConvertDlg);
  623. };
  624.  
  625. //
  626. // Enumerations used to populate Flags member of TPasteSpecialDlg::TData
  627. //
  628. enum TPasteSpecialFlags {
  629.   psShowHelp            = 0x0001,
  630.   psSelectPaste         = 0x0002,
  631.   psSelectPasteLink     = 0x0004,
  632.   psCheckDisplayAsIcon  = 0x0008,
  633.   psDisableDisplayAsIcon= 0x0010
  634. };
  635.  
  636. //
  637. //
  638. //
  639. enum  TOleUIPasteFlag {
  640.    pfPasteOnly     = 0,
  641.    pfLinkType1     = 1,
  642.    pfLinkType2     = 2,
  643.    pfLinkType3     = 4,
  644.    pfLinkType4     = 8,
  645.    pfLinkType5     = 16,
  646.    pfLinkType6     = 32,
  647.    pfLinkType7     = 64,
  648.    pfLinkType8     = 128,
  649.    pfPaste         = 512,
  650.    pfLinkAnyType   = 1024,
  651.    pfEnableIcon    = 2048
  652. };
  653.  
  654. //
  655. // Class TPasteSpecialDlg
  656. // ----- ----------------
  657. //
  658. class _USERCLASS TPasteSpecialDlg : public TOleDialog {
  659.  
  660.   public:
  661.     class _USERCLASS TPasteEntry;
  662.  
  663.     //
  664.     // Class TData  (TPasteSpecialDlg Data)
  665.     // ----- -----  ----------------- -----
  666.     //
  667.     class _USERCLASS TData {
  668.       public:
  669.         TData();
  670.         uint32            Flags;
  671.         LPDATAOBJECT      lpSrcDataObj;
  672.         TPasteEntry FAR*  ArrayPasteEntries;
  673.         int               cPasteEntries;
  674.         uint far*         ArrayLinkTypes;
  675.         int               cLinkTypes;
  676.         LPCLSID           lpClsIdExclude;
  677.         uint              cClsIdExclude;
  678.         int               SelectedIndex;
  679.         bool              fLink;
  680.         HGLOBAL           MetaPict;
  681.         SIZEL             SizeL;
  682.     };
  683.  
  684.   protected:
  685.     //
  686.     // Class TPasteEntry
  687.     // ----- -----------
  688.     //
  689.     class _USERCLASS TPasteEntry {
  690.       public:
  691.         TPasteEntry();
  692.  
  693.         FORMATETC     fmtetc;
  694.         LPCSTR        lpstrFormatName;
  695.         LPCSTR        lpstrResultText;
  696.         DWORD         dwFlags;
  697.         DWORD         dwScratchSpace;
  698.     };
  699.  
  700.     //
  701.     // Class TPasteListItemData
  702.     // ----- ------------------
  703.     //
  704.     class _USERCLASS TPasteListItemData {
  705.       public:
  706.         TPasteListItemData();
  707.  
  708.         int   nPasteEntriesIndex;
  709.         bool  fCntrEnableIcon;
  710.     };
  711.  
  712.   public:
  713.     TPasteSpecialDlg(TWindow* parent,
  714.                      TOcInitInfo &initInfo,
  715.                      TData *data = 0,
  716.                      TResId templateId = 0,
  717.                      const char far* title = 0,
  718.                      TModule* module = 0);
  719.     ~TPasteSpecialDlg();
  720.  
  721.     int           DoExecute();
  722.  
  723.   protected:
  724.     bool          EvInitDialog(HWND);
  725.     void          CleanupWindow();
  726.     bool          OleDlgOk();
  727.  
  728.     bool          GetDefaultPasteSpecialData();
  729.  
  730.     bool          TogglePasteType(TPasteSpecialFlags);
  731.     void          ChangeListSelection();
  732.     void          EnableDisplayAsIcon();
  733.     void          ToggleDisplayAsIcon();
  734.     void          SetPasteSpecialHelpResults();
  735.  
  736.     bool          FillPasteList();
  737.     bool          FillPasteLinkList();
  738.     bool          AddPasteListItem(TListBox&, bool,  int, const char far*);
  739.     void          FreeListData(TListBox&);
  740.  
  741.     bool          HasPercentS(const char far*);
  742.  
  743.     void          MarkPasteEntryList(LPDATAOBJECT lpSrcDataObj,
  744.                                      TPasteEntry far* lpPriorityList,
  745.                                      int cEntries);
  746.  
  747.     void          EvDrawClipboard();
  748.     void          EvChangeCBChain(HWND hwndRemoved, HWND hwndNext);
  749.  
  750.     void          ChangeIconClicked();
  751.     void          PasteClicked();
  752.     void          PasteLinkClicked();
  753.     void          DisplayAsIconClicked();
  754.  
  755.     void          DisplayListSelChange();
  756.     void          DisplayListDblClk();
  757.  
  758.     TCheckBox*    DisplayAsIcon;
  759.     TButton*      ChangeIcon;
  760.     TRadioButton* Paste;
  761.     TRadioButton* PasteLink;
  762.     TResultImage* ResultImage;
  763.     TIconImage*   IconImage;
  764.     TListBox*     DisplayList;
  765.     TListBox*     PasteList;
  766.     TListBox*     PasteLinkList;
  767.     TStatic*      ResultText;
  768.     TStatic*      SourceText;
  769.     TButton*      Help;
  770.  
  771.     TOcInitInfo  &InitInfo;
  772.     TData        *Data;
  773.  
  774.   private:
  775.     //
  776.     // Used internally to keep track of dialog's state
  777.     //
  778.     struct _USERCLASS THelper {
  779.       public:
  780.         THelper();
  781.  
  782.         uint32      Flags;
  783.         int         PasteListCurSel;
  784.         int         PasteLinkListCurSel;
  785.         int         SelectedIndex;
  786.         bool        Link;
  787.         char        UnknownType[MaxUnknownLen];
  788.         char        UnknownSource[MaxUnknownLen];
  789.         char        AppName[MaxKeyLen];
  790.  
  791.         CLSID       ClsIdOD;
  792.         SIZEL       SizeLOD;
  793.  
  794.         char far*   FullUserTypeNameOD;
  795.         char far*   SourceOfDataOD;
  796.         bool        SrcAspectIconOD;
  797.         bool        SrcOnlyIconicOD;
  798.         HGLOBAL     MetaPictOD;
  799.         HGLOBAL     ObjDesc;
  800.  
  801.         CLSID       ClsIdLSD;
  802.         SIZEL       SizeLLSD;
  803.  
  804.         char far*   FullUserTypeNameLSD;
  805.         char far*   SourceOfDataLSD;
  806.         bool        SrcAspectIconLSD;
  807.         bool        SrcOnlyIconicLSD;
  808.         HGLOBAL     MetaPictLSD;
  809.         HGLOBAL     LinkSrcDesc;
  810.  
  811.         bool        ClipboardChanged;
  812.     };
  813.  
  814.     THelper&        Helper;
  815.  
  816.     //
  817.     // Used internally if no TData* is specified
  818.     //
  819.     bool                 DeleteData;
  820.     TPasteEntry         *pOleUIEntries;
  821.     TOcFormatInfo*       pBOleEntries;
  822.     uint                *pBOleLinkEntries;
  823.  
  824.   DECLARE_RESPONSE_TABLE(TPasteSpecialDlg);
  825. };
  826.  
  827.  
  828. #if !defined(LPOLEUILINKCONTAINER)
  829.  
  830. // IOleUILinkContainer Interface
  831. // -----------------------------
  832. //    This interface must be implemented by container applications that
  833. //    want to use the EditLinks dialog. the EditLinks dialog calls back
  834. //    to the container app to perform the OLE functions to manipulate
  835. //    the links within the container. The OWL Edit Links Dialog uses
  836. //    Bolero's implementation of this interface.
  837. //
  838.  
  839. #define LPOLEUILINKCONTAINER     IOleUILinkContainer FAR*
  840.  
  841. #undef  INTERFACE
  842. #define INTERFACE   IOleUILinkContainer
  843.  
  844. DECLARE_INTERFACE_(IOleUILinkContainer, IUnknown)
  845. {
  846.   //*** IUnknown methods ***/
  847.   STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  848.   STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  849.   STDMETHOD_(ULONG,Release) (THIS) PURE;
  850.  
  851.   STDMETHOD_(DWORD,GetNextLink) (THIS_ DWORD dwLink) PURE;
  852.   STDMETHOD(SetLinkUpdateOptions) (THIS_ DWORD dwLink, DWORD dwUpdateOpt) PURE;
  853.   STDMETHOD(GetLinkUpdateOptions) (THIS_ DWORD dwLink, DWORD FAR* lpdwUpdateOpt) PURE;
  854.   STDMETHOD(SetLinkSource) (THIS_
  855.       DWORD       dwLink,
  856.       LPSTR       lpszDisplayName,
  857.       ULONG       lenFileName,
  858.       ULONG FAR*  pchEaten,
  859.       BOOL        fValidateSource) PURE;
  860.   STDMETHOD(GetLinkSource) (THIS_
  861.       DWORD       dwLink,
  862.       LPSTR FAR*  lplpszDisplayName,
  863.       ULONG FAR*  lplenFileName,
  864.       LPSTR FAR*  lplpszFullLinkType,
  865.       LPSTR FAR*  lplpszShortLinkType,
  866.       BOOL FAR*   lpfSourceAvailable,
  867.       BOOL FAR*   lpfIsSelected) PURE;
  868.   STDMETHOD(OpenLinkSource) (THIS_ DWORD dwLink) PURE;
  869.   STDMETHOD(UpdateLink) (THIS_
  870.       DWORD dwLink,
  871.       BOOL fErrorMessage,
  872.       BOOL fErrorAction) PURE;
  873.   STDMETHOD(CancelLink) (THIS_ DWORD dwLink) PURE;
  874. };
  875.  
  876. #endif  //  !defined  LPOLEUILINKCONTAINER
  877.  
  878. //
  879. // Enumeration used to populate dwFlags member of TEditLinksDlg::TData
  880. //
  881. enum TEditLinksFlags {
  882.   elShowHelp           = 0x0001,
  883.   elDisableUpdateNow   = 0x0002,
  884.   elDisableOpenSource  = 0x0004,
  885.   elDisableChangeSource= 0x0008,
  886.   elDisableCancelLink  = 0x0010
  887. };
  888.  
  889. //
  890. // Class TEditLinksDlg
  891. // ----- -------------
  892. //
  893. class _USERCLASS TEditLinksDlg : public TOleDialog {
  894.   public:
  895.     //
  896.     // Class TEditLinksDlg::TData
  897.     // ----- --------------------
  898.     //  Class used to pass in the necessary information to the
  899.     //  EditLinks dialog.
  900.     //
  901.     class _USERCLASS TData {
  902.       public:
  903.         TData(const TOcView&);
  904.         ~TData();
  905.         uint32 dwFlags;
  906.         LPOLEUILINKCONTAINER lpOleUILinkContainer;
  907.     };
  908.  
  909.     TEditLinksDlg(TWindow* parent,
  910.                   const TOcView& ocView,
  911.                   TResId templateId = 0,
  912.                   const char far* title = 0,
  913.                   TModule* module = 0);
  914.     ~TEditLinksDlg();
  915.     int             DoExecute();
  916.     bool            OleDlgOk() {return true;}
  917.  
  918.   protected:
  919.     bool            EvInitDialog(HWND);
  920.     void            DrawLinksListEntry(DRAWITEMSTRUCT far&);
  921.  
  922.     void            EvMeasureItem(uint, MEASUREITEMSTRUCT far&);
  923.     void            EvDrawItem(uint, DRAWITEMSTRUCT far&);
  924.     LRESULT         EvCompareItem(uint, COMPAREITEMSTRUCT far&);
  925.     void            EvDeleteItem(uint, DELETEITEMSTRUCT far&);
  926.  
  927.     void            ChangeSourceClicked();
  928.     void            AutomaticClicked();
  929.     void            ManualClicked();
  930.     void            BreakLinkClicked();
  931.     void            UpdateNowClicked();
  932.     void            OpenSourceClicked();
  933.  
  934.   private:
  935.     //
  936.     // Used internally to store information about a particular link
  937.     //
  938.     class _USERCLASS TLinkInfo {
  939.       public:
  940.         TLinkInfo(DWORD);
  941.         ~TLinkInfo();
  942.  
  943.         uint32      dwLink;
  944.         char*       lpszDisplayName;
  945.         char*       lpszItemName;
  946.         char*       lpszShortFileName;
  947.         char*       lpszShortLinkType;
  948.         char*       lpszFullLinkType;
  949.         char*       lpszAMX;
  950.         uint32      clenFileName;
  951.         bool        fSourceAvailable;
  952.         bool        fIsAuto;
  953.         bool        fIsMarked;
  954.         bool        fDontFree;
  955.         bool        fIsSelected;
  956.     };
  957.  
  958.     //
  959.     // Used internally to keep track of dialog's state
  960.     //
  961.     class _USERCLASS THelper {
  962.       public:
  963.         THelper();
  964.  
  965.         bool    fClose;
  966.         int    *rgIndex;
  967.         int     cSelItems;
  968.         bool    fItemsExist;
  969.         char    szClose[50];
  970.     };
  971.  
  972.     //
  973.     // Class TChgSrcFileOpenDlg
  974.     // ----- ------------------
  975.     //  This customized version of the FileOpen dialog performs
  976.     //  validation on the file name entered. It is used when the
  977.     //  user decides to change the source of a Link.
  978.     //
  979.     class _USERCLASS TChgSrcFileOpenDlg : public TFileOpenDialog {
  980.       public:
  981.         //
  982.         // Class TChgSrcData
  983.         // ----- -----------
  984.         //
  985.         class _USERCLASS TChgSrcData {
  986.           public:
  987.             TChgSrcData(TLinkInfo far*, TEditLinksDlg::TData&);
  988.  
  989.             TEditLinksDlg::TLinkInfo far* lpLI;
  990.             TEditLinksDlg::TData&         Data;
  991.             bool                          fValidLink;
  992.             char*                         lpszFrom;
  993.             char*                         lpszTo;
  994.         };
  995.  
  996.         TChgSrcFileOpenDlg(TWindow* parent,
  997.                           TData&   data,
  998.                           TChgSrcData& chgSrcData,
  999.                           TResId   templateId = 0,
  1000.                           const char far* title = 0,
  1001.                           TModule* module = 0);
  1002.         ~TChgSrcFileOpenDlg();
  1003.  
  1004.       protected:
  1005.         void              SetupWindow();
  1006.  
  1007.         TChgSrcData&      ChgSrcData;
  1008.  
  1009.       private:
  1010.         //
  1011.         // Class THelper
  1012.         // ----- -------
  1013.         //
  1014.         class _USERCLASS THelper {
  1015.           public:
  1016.             THelper() { memset(this, 0, sizeof(THelper)); }
  1017.  
  1018.             bool    fValidLink;
  1019.             char    szFileName[MaxPathLen];
  1020.             char    szItemName[MaxPathLen];
  1021.             bool    bFileNameStored;
  1022.             bool    bItemNameStored;
  1023.             char    szEdit[MaxPathLen];
  1024.             LPSTR   lpszFrom;
  1025.             LPSTR   lpszTo;
  1026.         };
  1027.         THelper&    Helper;
  1028.     };
  1029.  
  1030.   protected:
  1031.     bool            Container_ChangeSource();
  1032.     HRESULT         Container_AutomaticManual(bool fAutoMan);
  1033.     HRESULT         Container_UpdateNow();
  1034.     HRESULT         Container_OpenSource();
  1035.  
  1036.     int             AddLinkLBItem(TLinkInfo* lpLinkInfo, bool sel);
  1037.     void            UpdateLinkLBItem(int nIndex, bool bSelect);
  1038.     void            ChangeAllLinks(char* from, char* to);
  1039.     bool            ChangeSource(char* file,
  1040.                                  TChgSrcFileOpenDlg::TChgSrcData&,
  1041.                                  uint);
  1042.     void            BreakString(TLinkInfo*);
  1043.     HRESULT         CancelLink();
  1044.  
  1045.     int             GetSelectedItems(int* &);
  1046.     void            InitControls();
  1047.  
  1048.     void            DiffPrefix(const char*, const char*, char* &, char* &);
  1049.     int             LoadLinkLB();
  1050.     void            RefreshLinkLB();
  1051.     int             LBPad() const;
  1052.  
  1053.     TListBox*       LinksList;
  1054.     TButton*        UpdateBtn;
  1055.     TButton*        OpenBtn;
  1056.     TButton*        ChangeBtn;
  1057.     TButton*        BreakLinkBtn;
  1058.     TButton*        Help;
  1059.     TButton*        Cancel;
  1060.     TRadioButton*   Automatic;
  1061.     TRadioButton*   Manual;
  1062.     TStatic*        LinkSource;
  1063.     TStatic*        LinkType;
  1064.  
  1065.     int             nColPos[LinksListCols];
  1066.     int             nMaxCharWidth, nHeightLine;
  1067.     TData*          Data;
  1068.  
  1069.   private:
  1070.     THelper&        Helper;
  1071.  
  1072.   DECLARE_RESPONSE_TABLE(TEditLinksDlg);
  1073. };
  1074.  
  1075. //----------------------------------------------------------------------------
  1076. // Inlines
  1077. //
  1078.  
  1079. //
  1080. //
  1081. //
  1082. inline HGLOBAL
  1083. TOleDialog::GetIconFromClass(REFCLSID clsid, const char far* label, bool useType)
  1084. {
  1085.   return ::OleGetIconOfClass(clsid, OleStr(const_cast<char far*>(label)), useType);
  1086. }
  1087.  
  1088. //
  1089. //
  1090. //
  1091. inline HGLOBAL
  1092. TOleDialog::GetIconFromFile(const char far* path, bool useFile)
  1093. {
  1094.   return ::OleGetIconOfFile(OleStr(const_cast<char far*>(path)), useFile);
  1095. }
  1096.  
  1097. //
  1098. //
  1099. //
  1100. inline char far*
  1101. TOleDialog::AnsiPrev(const char far* start, const char far* current)
  1102. {
  1103.   return ::AnsiPrev(start, current);
  1104. }
  1105.  
  1106. //
  1107. //
  1108. //
  1109. inline char far*
  1110. TOleDialog::AnsiNext(const char far* current)
  1111. {
  1112.   return ::AnsiNext(current);
  1113. }
  1114.  
  1115. #if defined(BI_DATA_NEAR)
  1116.  
  1117. //
  1118. //
  1119. //
  1120. inline char*
  1121. TOleDialog::AnsiPrev(const char* start, const char* current)
  1122. {
  1123.   char far* str = ::AnsiPrev(start, current);
  1124.   CHECK(HIWORD(str) == HIWORD(start));
  1125.   return (char*)(LOWORD(str));
  1126. }
  1127.  
  1128. //
  1129. //
  1130. //
  1131. inline char*
  1132. TOleDialog::AnsiNext(const char* current)
  1133. {
  1134.   char far* str = ::AnsiNext(current);
  1135.   CHECK(HIWORD(str) == HIWORD(current));
  1136.   return (char*)(LOWORD(str));
  1137. }
  1138.  
  1139. //
  1140. //
  1141. //
  1142. inline char*
  1143. TOleDialog::ChopText(TWindow& win, int width, char* str)
  1144. {
  1145.   char far* lpstr  = str;
  1146.   char far* result = ChopText(win, width, lpstr);
  1147.   CHECK(HIWORD(result) == HIWORD(lpstr));
  1148.   return (char*)(LOWORD(result));
  1149. }
  1150. #endif    // BI_DATA_NEAR
  1151.  
  1152. //
  1153. //
  1154. //
  1155. inline char far*
  1156. TResultImage::GetClassName()
  1157. {
  1158.   return RESULTIMAGE_CLSNAME;
  1159. }
  1160.  
  1161. //
  1162. //
  1163. //
  1164. inline char far*
  1165. TIconImage::GetClassName()
  1166. {
  1167.   return ICONIMAGE_CLSNAME;
  1168. }
  1169.  
  1170. //
  1171. //
  1172. //
  1173. inline HCURSOR
  1174. HourGlassOn()
  1175. {
  1176.   HCURSOR oldCursor = ::SetCursor(::LoadCursor(0, IDC_WAIT));
  1177.   ShowCursor(TRUE);
  1178.   return oldCursor;
  1179. }
  1180.  
  1181. //
  1182. //
  1183. //
  1184. inline void
  1185. HourGlassOff(HCURSOR hCursor)
  1186. {
  1187.   ShowCursor(FALSE);
  1188.   SetCursor(hCursor);
  1189. }
  1190.  
  1191. //
  1192. // Slight variation of strncpy() which guarantees a NULL-terminated
  1193. // destination - Returns 0 if the 'maxLen' is only 1.
  1194. //
  1195. inline char far*
  1196. strcpyn(char far* dest, const char far* src, size_t maxLen)
  1197. {
  1198.   PRECONDITION(!IsBadWritePtr(dest, maxLen));
  1199.   dest[maxLen-1] = 0;
  1200.   return (maxLen > 1) ? strncpy(dest, src, maxLen-1) : 0;
  1201. }
  1202.  
  1203. #if defined(BI_DATA_NEAR)
  1204. inline char*
  1205. strcpyn(char* dest, const char* src, size_t maxlen)
  1206. {
  1207.   char far *lpDest = dest;
  1208.   char far *lpResult = strcpyn(dest, src, maxlen);
  1209.   CHECK(HIWORD(lpResult) == HIWORD(lpDest));
  1210.   return (char*)(LOWORD(lpResult));
  1211. }
  1212. #endif
  1213.  
  1214. //
  1215. // Initialize FORMATETC structure
  1216. //
  1217. inline void
  1218. InitFormatEtc(FORMATETC &fmt, CLIPFORMAT cf, DWORD tymed, LONG lindex = -1,
  1219.               DWORD dwAspect = DVASPECT_CONTENT, 
  1220.               DVTARGETDEVICE FAR* ptd = 0)
  1221. {
  1222.   fmt.cfFormat  = cf;
  1223.   fmt.dwAspect  = dwAspect;
  1224.   fmt.ptd       = ptd;
  1225.   fmt.tymed     = tymed;
  1226.   fmt.lindex    = lindex;
  1227. }
  1228.  
  1229. #endif  //  __USER_OLEDLG_H
  1230.