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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1993, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Defines TVbxControl and associated classes
  6. //----------------------------------------------------------------------------
  7. #if !defined(OWL_VBXCTL_H)
  8. #define OWL_VBXCTL_H
  9. #define __OWL_VBXCTL_H   // Old-style define for VbxGen compatibility
  10.  
  11. #if !defined(OWL_CONTROL_H)
  12. # include <owl/control.h>
  13. #endif
  14. #if !defined(__BIVBX_H)
  15. # include <bivbx.h>
  16. #endif
  17. #if !defined(BI_PLAT_MSW)
  18. # error VBX supported only under MS Windows
  19. #endif
  20.  
  21.  
  22. //
  23. //  class TBIVbxLibrary
  24. //  ----- -------------
  25. //
  26. class TBIVbxLibrary : public TModule {
  27.   public:
  28.    class _OWLCLASS_RTL TXVbxLibrary : public TXOwl {
  29.     public:
  30.       TXVbxLibrary();
  31.       TXOwl* Clone();
  32.       void Throw();
  33.    };
  34.  
  35.    TBIVbxLibrary();
  36.   ~TBIVbxLibrary();
  37. };
  38.  
  39. //
  40. //  class TVbxEventHandler
  41. //  ----- ----------------
  42. //
  43. class TVbxEventHandler : virtual public TEventHandler {
  44.   protected:
  45.     LRESULT  EvVbxDispatch(WPARAM wp, LPARAM lp);
  46.     LRESULT  EvVbxInitForm(WPARAM wp, LPARAM lp);
  47.  
  48.   DECLARE_RESPONSE_TABLE(TVbxEventHandler);
  49. };
  50.  
  51. //
  52. //  class TVbxControl
  53. //  ----- -----------
  54. //
  55. class TVbxControl : public TControl, public TVbxEventHandler {
  56.   public:
  57.     TVbxControl(TWindow*        parent,
  58.                 int             id,
  59.                 const char far* vbxName,
  60.                 const char far* vbxClass,
  61.                 const char far* title,
  62.                 int             x,
  63.                 int             y,
  64.                 int             w,
  65.                 int             h,
  66.                 long            initLen = 0,
  67.                 void far*       initData = 0,
  68.                 TModule*        module = 0);
  69.  
  70.     TVbxControl(TWindow* parent, int resourceId, TModule* module = 0);
  71.    ~TVbxControl();
  72.  
  73.     void SetupWindow();
  74.  
  75.     // properties
  76.     int GetNumProps();
  77.     int GetPropIndex(const char far* name);
  78. #if defined(BI_PLAT_WIN16)
  79.     const char far* GetPropName(int propIndex);
  80. #endif
  81.     void GetPropName(int propIndex, string& str);
  82.     int GetPropType(int propIndex);
  83.     int GetPropType(char far* name);
  84.     bool IsArrayProp(int propIndex);
  85.     bool IsArrayProp(char far* name);
  86.  
  87.     // get properties by index
  88.     bool GetProp(int propIndex, int& value, int arrayIndex=-1);
  89.     bool GetProp(int propIndex, long& value, int arrayIndex=-1);
  90. #if defined(BI_UNIQUE_BOOL)
  91.     bool GetProp(int propIndex, bool& value, int arrayIndex=-1);
  92. #endif
  93.     bool GetProp(int propIndex, ENUM& value, int arrayIndex=-1);
  94.     bool GetProp(int propIndex, HPIC& value, int arrayIndex=-1);
  95.     bool GetProp(int propIndex, float& value, int arrayIndex=-1);
  96.     bool GetProp(int propIndex, string& value, int arrayIndex=-1);
  97.     bool GetProp(int propIndex, COLORREF& value, int arrayIndex=-1);
  98.  
  99.     // get properties by name
  100.     bool GetProp(const char far* name, int& value, int arrayIndex=-1);
  101.     bool GetProp(const char far* name, long& value, int arrayIndex=-1);
  102. #if defined(BI_UNIQUE_BOOL)
  103.     bool GetProp(const char far* name, bool& value, int arrayIndex=-1);
  104. #endif
  105.     bool GetProp(const char far* name, ENUM& value, int arrayIndex=-1);
  106.     bool GetProp(const char far* name, HPIC& value, int arrayIndex=-1);
  107.     bool GetProp(const char far* name, float& value, int arrayIndex=-1);
  108.     bool GetProp(const char far* name, string& value, int arrayIndex=-1);
  109.     bool GetProp(const char far* name, COLORREF& value, int arrayIndex=-1);
  110.  
  111.     // set properties by index
  112.     bool SetProp(int propIndex, int value, int arrayIndex=-1);
  113.     bool SetProp(int propIndex, long value, int arrayIndex=-1);
  114.     bool SetProp(int propIndex, ENUM value, int arrayIndex=-1);
  115.     bool SetProp(int propIndex, HPIC value, int arrayIndex=-1);
  116.     bool SetProp(int propIndex, float value, int arrayIndex=-1);
  117.     bool SetProp(int propIndex, const string& value, int arrayIndex=-1);
  118.     bool SetProp(int propIndex, const char far* value, int arrayIndex=-1);
  119.     bool SetProp(int propIndex, COLORREF value, int arrayIndex=-1);
  120.  
  121.     // set properties by name
  122.     bool SetProp(const char far* name, int value, int arrayIndex=-1);
  123.     bool SetProp(const char far* name, long value, int arrayIndex=-1);
  124.     bool SetProp(const char far* name, ENUM value, int arrayIndex=-1);
  125.     bool SetProp(const char far* name, HPIC value, int arrayIndex=-1);
  126.     bool SetProp(const char far* name, float value, int arrayIndex=-1);
  127.     bool SetProp(const char far* name, const string& value, int arrayIndex=-1);
  128.     bool SetProp(const char far* name, const char far* value, int arrayIndex=-1);
  129.     bool SetProp(const char far*, COLORREF value, int arrayIndex=-1);
  130.  
  131.     // events
  132.     int GetNumEvents();
  133.     int GetEventIndex(const char far* name);
  134. #if defined(BI_PLAT_WIN16)
  135.     const char far* GetEventName(int eventIndex);
  136. #endif
  137.     void GetEventName(int eventIndex, string& str);
  138.  
  139.     // methods
  140.     bool AddItem(int index, const char far* item);
  141.     bool Drag(int action);
  142.     bool Move(long x, long y, long w, long h);
  143.     bool Refresh();
  144.     bool RemoveItem(int index);
  145.  
  146.     // control
  147.     HCTL GetHCTL() {return HCtl;}
  148.  
  149.   protected:
  150.     char far* GetClassName();
  151.     void PerformCreate(int menuOrId);
  152.     bool GetVBXProperty(int propIndex, void far *value, int arrayIndex=-1);
  153.     bool SetVBXProperty(int propIndex, int32 value, int arrayIndex=-1);
  154.  
  155.   private:
  156.     HCTL      HCtl;
  157.     char far* VbxName;
  158.     char far* VbxClass;
  159.     long      InitLen;
  160.     void far* InitData;
  161.  
  162.     LRESULT EvDefaultProcessing(WPARAM, LPARAM);
  163.  
  164.   DECLARE_RESPONSE_TABLE(TVbxControl);
  165.   DECLARE_CASTABLE;
  166. };
  167.  
  168.  
  169. //
  170. // Response table macros for VBX events
  171. //
  172. #define EV_VBXEVENTNAME(id,name,method)\
  173.   {WM_VBXNAME,id,(TAnyDispatcher)name,(TMyPMF)VbxSig(&TMyClass::method)}
  174.  
  175. #define EV_VBXEVENTINDEX(id,event,method)\
  176.   {WM_VBXBASE+event,id,(TAnyDispatcher)::i_LPARAM_Dispatch,\
  177.   (TMyPMF)VbxSig(&TMyClass::method)}
  178.  
  179. //
  180. // WM_VBXFIREEVENT signature template
  181. //
  182. template <class T>
  183. inline void(T::*VbxSig(void(T::*pmf)(VBXEVENT FAR*))) (VBXEVENT FAR*)
  184. {
  185.   return pmf;
  186. }
  187.  
  188. //
  189. //  VBXDispatch - dispatch function to crack a WM_VBXFIREEVENT message and
  190. //  pass control to a pointer to member function.
  191. //
  192. LRESULT
  193. VBXDispatch(GENERIC& generic,
  194.             void    (GENERIC::*pmf)(VBXEVENT FAR*),
  195.             WPARAM   wParam,
  196.             LPARAM   lParam);
  197.  
  198. //
  199. // TVbxControl Inlines
  200. //
  201.  
  202. inline int TVbxControl::GetNumProps()
  203. {
  204.   return ::VBXGetNumProps(HCtl);
  205. }
  206.  
  207. inline int TVbxControl::GetPropIndex(const char far* name)
  208. {
  209.   return ::VBXGetPropIndex(HCtl, name);
  210. }
  211.  
  212. #if defined(BI_PLAT_WIN16)
  213. inline const char far* TVbxControl::GetPropName(int propIndex)
  214. {
  215.   return ::VBXGetPropName(HCtl, propIndex);
  216. }
  217. #endif
  218.  
  219. inline void TVbxControl::GetPropName(int propIndex, string& str)
  220. {
  221.   char buff[64];
  222.   ::VBXGetPropNameBuf(HCtl, propIndex, buff, sizeof buff);
  223.   str = buff;
  224. }
  225.  
  226. inline int TVbxControl::GetPropType(int propIndex)
  227. {
  228.   return ::VBXGetPropType(HCtl, propIndex);
  229. }
  230.  
  231. inline int TVbxControl::GetPropType(char far* name)
  232. {
  233.   return GetPropType(GetPropIndex(name));
  234. }
  235.  
  236. inline bool TVbxControl::IsArrayProp(int propIndex)
  237. {
  238.   return ::VBXIsArrayProp(HCtl, propIndex);
  239. }
  240.  
  241. inline bool TVbxControl::IsArrayProp(char far* name)
  242. {
  243.   return IsArrayProp(GetPropIndex(name));
  244. }
  245.  
  246.  
  247. // get properties by id
  248.  
  249. inline bool
  250. TVbxControl::GetProp(int propIndex, int& value, int arrayIndex)
  251. {
  252. #if defined(BI_PLAT_WIN32)
  253.   int16 temp;
  254.   bool rv = GetVBXProperty(propIndex, &temp, arrayIndex);
  255.   value = temp;
  256.   return rv;
  257. #else
  258.   return GetVBXProperty(propIndex, &value, arrayIndex);
  259. #endif
  260. }
  261.  
  262. inline bool
  263. TVbxControl::GetProp(int propIndex, long& value, int arrayIndex)
  264. {
  265.   return GetVBXProperty(propIndex, &value, arrayIndex);
  266. }
  267.  
  268. #if defined(BI_UNIQUE_BOOL)
  269. inline bool
  270. TVbxControl::GetProp(int propIndex, bool& value, int arrayIndex)
  271. {
  272. #if defined(BI_PLAT_WIN32)
  273.   int16 temp;
  274.   bool rv = GetVBXProperty(propIndex, &temp, arrayIndex);
  275.   value = temp;
  276.   return rv;
  277. #else
  278.   return GetVBXProperty(propIndex, &value, arrayIndex);
  279. #endif
  280. }
  281. #endif
  282.  
  283. inline bool
  284. TVbxControl::GetProp(int propIndex, ENUM& value, int arrayIndex)
  285. {
  286.   int16 temp;
  287.   bool rv = GetVBXProperty(propIndex, &temp, arrayIndex);
  288.   value = (ENUM)temp;
  289.   return rv;
  290. }
  291.  
  292. inline bool
  293. TVbxControl::GetProp(int propIndex, HPIC& value, int arrayIndex)
  294. {
  295.   return GetVBXProperty(propIndex, &value, arrayIndex);
  296. }
  297.  
  298. inline bool
  299. TVbxControl::GetProp(int propIndex, float& value, int arrayIndex)
  300. {
  301.   return GetVBXProperty(propIndex, &value, arrayIndex);
  302. }
  303.  
  304. inline bool
  305. TVbxControl::GetProp(int propIndex, COLORREF& value, int arrayIndex)
  306. {
  307.   return GetVBXProperty(propIndex, &value, arrayIndex);
  308. }
  309.  
  310. // get properties by name
  311.  
  312. #if defined(BI_UNIQUE_BOOL)
  313. inline bool
  314. TVbxControl::GetProp(const char far* name, int& value, int arrayIndex)
  315. {
  316.   return GetProp(GetPropIndex(name), value, arrayIndex);
  317. }
  318. #endif
  319.  
  320. inline bool
  321. TVbxControl::GetProp(const char far* name, long& value, int arrayIndex)
  322. {
  323.   return GetProp(GetPropIndex(name), value, arrayIndex);
  324. }
  325.  
  326. inline bool
  327. TVbxControl::GetProp(const char far* name, bool& value, int arrayIndex)
  328. {
  329.   return GetProp(GetPropIndex(name), value, arrayIndex);
  330. }
  331.  
  332. inline bool
  333. TVbxControl::GetProp(const char far* name, ENUM& value, int arrayIndex)
  334. {
  335.   return GetProp(GetPropIndex(name), value, arrayIndex);
  336. }
  337.  
  338. inline bool
  339. TVbxControl::GetProp(const char far* name, HPIC& value, int arrayIndex)
  340. {
  341.   return GetProp(GetPropIndex(name), value, arrayIndex);
  342. }
  343.  
  344. inline bool
  345. TVbxControl::GetProp(const char far* name, float& value, int arrayIndex)
  346. {
  347.   return GetProp(GetPropIndex(name), value, arrayIndex);
  348. }
  349.  
  350. inline bool
  351. TVbxControl::GetProp(const char far* name, string& value, int arrayIndex)
  352. {
  353.   return GetProp(GetPropIndex(name), value, arrayIndex);
  354. }
  355.  
  356. inline bool
  357. TVbxControl::GetProp(const char far* name, COLORREF& value, int arrayIndex)
  358. {
  359.   return GetProp(GetPropIndex(name), value, arrayIndex);
  360. }
  361.  
  362. // set properties by id
  363.  
  364. inline bool
  365. TVbxControl::SetProp(int propIndex, int value, int arrayIndex)
  366. {
  367.   return SetVBXProperty(propIndex, value, arrayIndex);
  368. }
  369.  
  370. inline bool
  371. TVbxControl::SetProp(int propIndex, long value, int arrayIndex)
  372. {
  373.   return SetVBXProperty(propIndex, value, arrayIndex);
  374. }
  375.  
  376. inline bool
  377. TVbxControl::SetProp(int propIndex, HPIC value, int arrayIndex)
  378. {
  379.   return SetVBXProperty(propIndex, value, arrayIndex);
  380. }
  381.  
  382. inline bool
  383. TVbxControl::SetProp(int propIndex, ENUM value, int arrayIndex)
  384. {
  385.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  386. }
  387.  
  388. inline bool
  389. TVbxControl::SetProp(int propIndex, float value, int arrayIndex)
  390. {
  391.   return SetVBXProperty(propIndex, *((long*)&value), arrayIndex);
  392. }
  393.  
  394. inline bool
  395. TVbxControl::SetProp(int propIndex, const string& value, int arrayIndex)
  396. {
  397.   return SetVBXProperty(propIndex, long(value.c_str()), arrayIndex);
  398. }
  399.  
  400. inline bool
  401. TVbxControl::SetProp(int propIndex, const char far* value, int arrayIndex)
  402. {
  403.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  404. }
  405.  
  406. inline bool
  407. TVbxControl::SetProp(int propIndex, COLORREF value, int arrayIndex)
  408. {
  409.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  410. }
  411.  
  412. // set properties by name
  413.  
  414. inline bool
  415. TVbxControl::SetProp(const char far* name, int value, int arrayIndex)
  416. {
  417.   return SetProp(GetPropIndex(name), value);
  418. }
  419.  
  420. inline bool
  421. TVbxControl::SetProp(const char far* name, long value, int arrayIndex)
  422. {
  423.   return SetProp(GetPropIndex(name), value);
  424. }
  425.  
  426. inline bool
  427. TVbxControl::SetProp(const char far* name, ENUM value, int arrayIndex)
  428. {
  429.   return SetProp(GetPropIndex(name), value);
  430. }
  431.  
  432. inline bool
  433. TVbxControl::SetProp(const char far* name, HPIC value, int arrayIndex)
  434. {
  435.   return SetProp(GetPropIndex(name), value);
  436. }
  437.  
  438. inline bool
  439. TVbxControl::SetProp(const char far* name, float value, int arrayIndex)
  440. {
  441.   return SetProp(GetPropIndex(name), value);
  442. }
  443.  
  444. inline bool
  445. TVbxControl::SetProp(const char far* name, const string& value, int arrayIndex)
  446. {
  447.   return SetProp(GetPropIndex(name), value.c_str());
  448. }
  449.  
  450. inline bool
  451. TVbxControl::SetProp(const char far* name, const char far* value, int arrayIndex)
  452. {
  453.   return SetProp(GetPropIndex(name), value);
  454. }
  455.  
  456. inline bool
  457. TVbxControl::SetProp(const char far* name, COLORREF value, int arrayIndex)
  458. {
  459.   return SetProp(GetPropIndex(name), value);
  460. }
  461.  
  462.  
  463. inline int
  464. TVbxControl::GetNumEvents()
  465. {
  466.   return ::VBXGetNumEvents(HCtl);
  467. }
  468.  
  469. inline int
  470. TVbxControl::GetEventIndex(const char far* name)
  471. {
  472.   return ::VBXGetEventIndex(HCtl, name);
  473. }
  474.  
  475. #if defined(BI_PLAT_WIN16)
  476. inline const char far*
  477. TVbxControl::GetEventName(int eventIndex)
  478. {
  479.   return ::VBXGetEventName(HCtl, eventIndex);
  480. }
  481. #endif
  482.  
  483. inline void
  484. TVbxControl::GetEventName(int eventIndex, string& str)
  485. {
  486.   char buff[64];
  487.   ::VBXGetEventNameBuf(HCtl, eventIndex, buff, sizeof buff);
  488.   str = buff;
  489. }
  490.  
  491. inline bool
  492. TVbxControl::AddItem(int index, const char far* item)
  493. {
  494.   return ::VBXMethodAddItem(HCtl, index, item);
  495. }
  496.  
  497. inline bool
  498. TVbxControl::Drag(int action)
  499. {
  500.   return ::VBXMethodDrag(HCtl, action);
  501. }
  502.  
  503. inline bool
  504. TVbxControl::Move(long x, long y, long w, long h)
  505. {
  506.   return ::VBXMethodMove(HCtl, x, y, w, h);
  507. }
  508.  
  509. inline bool
  510. TVbxControl::Refresh()
  511. {
  512.   return ::VBXMethodRefresh(HCtl);
  513. }
  514.  
  515. inline bool
  516. TVbxControl::RemoveItem(int index)
  517. {
  518.   return ::VBXMethodRemoveItem(HCtl, index);
  519. }
  520.  
  521. #endif  // OWL_VBXCTL_H
  522.