home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xnotebk.cpp < prev    next >
C/C++ Source or Header  |  1997-12-09  |  8KB  |  243 lines

  1. #include "xnotebk.h"
  2. #include "XBookPg.h"
  3.  
  4. /*@
  5. @class XNoteBook
  6. @parent XControl
  7. @type overview
  8. @symbol _
  9. @changed
  10. */
  11.  
  12. /*@ XNoteBook :: XNoteBook(const XWindow * owner, const XRect& rec, const USHORT id, const ULONG style, char *font)
  13. @group constructors/destructors
  14. @remarks Create a notebook
  15. @parameters <t '°' c=2>
  16.             °XWindow * owner   °the owner-window
  17.             °XRect& rect      °size and position
  18.             °USHORT id         °ID of the window
  19.             °ULONG style       °style of the notebook, valid values are:
  20.                               <t '°' c=1>
  21.                                  °NB_BACKPAGESBR
  22.                                  °NB_BACKPAGESBL
  23.                                  °NB_BACKPAGESTR
  24.                                  °NB_BACKPAGESTL
  25.                                  °NB_MAJORTABRIGHT
  26.                                  °NB_MAJORTABLEFT
  27.                                  °NB_MAJORTABTOP
  28.                                  °NB_MAJORTABBOTTOM
  29.                                  °NB_SQUARETABS
  30.                                  °NB_ROUNDEDTABS
  31.                                  °NB_POLYGONTABS
  32.                                  °NB_SOLIDBIND
  33.                                  °NB_SPIRALBIND
  34.                                  °NB_STATUSTEXTLEFT
  35.                                  °NB_STATUSTEXTRIGHT
  36.                                  °NB_STATUSTEXTCENTER
  37.                                  °NB_TABTEXTLEFT
  38.                                  °NB_TABTEXTRIGHT
  39.                                  °NB_TABTEXTCENTER
  40.                                  °NB_TABBEDDIALOG   (Warp4 only)
  41.                               </t>
  42.                               (can be or-ed, default is NB_SOLIDBIND|NB_BACKPAGESBR|NB_SQUARETABS|NB_TABTEXTCENTER|NB_STATUSTEXTLEFT)
  43.             °char * font         °font to use, eg "8.Helv" (default is NULL)
  44.             </t>
  45. */
  46. XNoteBook :: XNoteBook(const XWindow * owner, const XRect& rec, const USHORT id, const ULONG style, char *font):XControl(&rec, style, owner, "", WC_NOTEBOOK, id, font)
  47. {
  48.    color = XColor(COL_WHITE).GetColor();
  49. }
  50.  
  51.  
  52. XNoteBook :: ~XNoteBook()
  53. {
  54.    ULONG id = (ULONG) WinSendMsg( winhandle, BKM_QUERYPAGEID, 0, MPFROM2SHORT( BKA_FIRST, 0));
  55.    HWND hwnd = (HWND) WinSendMsg( winhandle, BKM_QUERYPAGEWINDOWHWND, (MPARAM) id, 0);
  56.  
  57.    while (hwnd != 0 && id != 0)
  58.    {
  59.       XWindow *w = (XWindow *) WinQueryWindowPtr(hwnd, 0);
  60.       if( w )
  61.          w->Close();
  62.       WinSendMsg( winhandle, BKM_DELETEPAGE, (MPARAM) id, (MPARAM) BKA_SINGLE);
  63.  
  64.       id = (ULONG) WinSendMsg( winhandle, BKM_QUERYPAGEID, 0, MPFROM2SHORT( BKA_FIRST, 0));
  65.       if( id )
  66.          hwnd = (HWND) WinSendMsg( winhandle, BKM_QUERYPAGEWINDOWHWND, (MPARAM) id, 0);
  67.       if( hwnd == BOOKERR_INVALID_PARAMETERS )
  68.          hwnd = 0;
  69.    }
  70. }
  71.  
  72.  
  73. /*@ XNoteBook :: RemovePage( XNoteBookPage * p)
  74. @remarks Remove a page from the notebook
  75. @parameters XNoteBookPage* thePage
  76. @returns BOOL success
  77. @new
  78. */
  79. BOOL XNoteBook :: RemovePage( XNoteBookPage * p)
  80. {
  81.    return (BOOL) WinSendMsg( winhandle, BKM_DELETEPAGE, (MPARAM) p->GetID(), (MPARAM) BKA_SINGLE);
  82. }
  83.  
  84.  
  85. /*@ XNoteBook :: GetPage( USHORT order, ULONG id )
  86. @remarks Retrieve a page from th notebook
  87. @parameters
  88. <t '°' c=2>
  89. °USHORT °order of searching
  90.          <t '°' c=1>
  91.          °BKA_FIRST
  92.          °BKA_NEXT
  93.          °BKA_PREV
  94.          °BKA_LAST
  95.          °BKA_TOP
  96.          </t>
  97. °ULONG   °ID of a relative page. This id is <B>not</B> the window-ID, this ID is automatical
  98.           created from the operating system, you can get this ID with XNoteBookPage::GetID().
  99. @new
  100. </t>
  101. @returns XNoteBookPage* pointer to the page
  102. @example
  103.    //how to enumerate all pages
  104.    XNoteBookPage * last = NULL, * page = noteBook->GetPage( BKA_FIRST );
  105.  
  106.    while( page )
  107.    {
  108.       last = page;
  109.       page = noteBook->GetPage( BKA_NEXT, last->GetID());
  110.    };
  111. */
  112. XNoteBookPage * XNoteBook :: GetPage( USHORT order, ULONG id )
  113. {
  114.    ULONG i = (ULONG) WinSendMsg( winhandle, BKM_QUERYPAGEID, (MPARAM) id, MPFROM2SHORT( order, 0));
  115.    HWND hwnd = (HWND) WinSendMsg( winhandle, BKM_QUERYPAGEWINDOWHWND, (MPARAM) i, 0);
  116.    return (XNoteBookPage*) WinQueryWindowULong( hwnd, 0);
  117. }
  118.  
  119.  
  120. /*@ XNoteBook::SetMajorTabSize(const SHORT width, const SHORT height)
  121. @group size
  122. @remarks Set the size of major tabs.
  123. @parameters SHORT width<BR>
  124.             SHORT hight
  125. */
  126. void XNoteBook::SetMajorTabSize(const SHORT width, const SHORT height) const
  127. {
  128.    WinSendMsg(winhandle, BKM_SETDIMENSIONS, MPFROM2SHORT(width, height), (MPARAM) BKA_MAJORTAB);
  129. }
  130.  
  131.  
  132. /*@ XNoteBook::SetMinorTabSize(const SHORT width, const SHORT height)
  133. @group size
  134. @remarks Set the size of minor tabs.
  135. @parameters SHORT width<BR>
  136.             SHORT hight
  137. */
  138. void XNoteBook::SetMinorTabSize(const SHORT width, const SHORT height) const
  139. {
  140.    WinSendMsg(winhandle, BKM_SETDIMENSIONS, MPFROM2SHORT(width, height), (MPARAM) BKA_MINORTAB);
  141. }
  142.  
  143.  
  144. /*@ XNoteBook::SetBackgroundColor(const XColor * col)
  145. @group colors
  146. @remarks Set the background color.
  147. @parameters XColor * color    the new color
  148. */
  149. BOOL XNoteBook::SetBackgroundColor(const XColor * col)
  150. {
  151.    color = col->GetColor();
  152.    WinSendMsg(winhandle, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(col->GetColor()), MPFROMLONG(BKA_BACKGROUNDPAGECOLOR));
  153.    return TRUE;
  154. }
  155.  
  156.  
  157. /*@ XNoteBook::SetMajorBackgroundColor(const XColor * col)
  158. @group colors
  159. @remarks Set the background color of major tabs.
  160. @parameters XColor * theColor
  161. */
  162. void XNoteBook::SetMajorBackgroundColor(const XColor * col) const
  163. {
  164.    WinSendMsg(winhandle, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(col->GetColor()), MPFROMLONG(BKA_BACKGROUNDMAJORCOLOR));
  165. }
  166.  
  167.  
  168. /*@ XNoteBook::SetMajorForegroundColor(const XColor * col)
  169. @group colors
  170. @remarks Set the foreground color of major tabs.
  171. @parameters XColor * theColor
  172. */
  173. void XNoteBook::SetMajorForegroundColor(const XColor * col) const
  174. {
  175.    WinSendMsg(winhandle, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(col->GetColor()), MPFROMLONG(BKA_FOREGROUNDMAJORCOLOR));
  176. }
  177.  
  178.  
  179. /*@ XNoteBook::SetMinorBackgroundColor(const XColor * col)
  180. @group colors
  181. @remarks Set the backgroundcolor of minor tabs.
  182. @parameters XColor * theColor
  183. */
  184. void XNoteBook::SetMinorBackgroundColor(const XColor * col) const
  185. {
  186.    WinSendMsg(winhandle, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(col->GetColor()), MPFROMLONG(BKA_BACKGROUNDMINORCOLOR));
  187. }
  188.  
  189.  
  190. /*@ XNoteBook::SetMinorForegroundColor(const XColor * col)
  191. @group colors
  192. @remarks Set the foreground color of minor tabs.
  193. @parameters XColor * theColor
  194. */
  195. void XNoteBook::SetMinorForegroundColor(const XColor * col) const
  196. {
  197.    WinSendMsg(winhandle, BKM_SETNOTEBOOKCOLORS, MPFROMLONG(col->GetColor()), MPFROMLONG(BKA_FOREGROUNDMINORCOLOR));
  198. }
  199.  
  200.  
  201. /*@ XNoteBook::GetBackgroundColor(XColor*)
  202. @group colors
  203. @remarks Returns the background color.
  204. @parameters XColor * buffer   buffer to hold the data
  205. */
  206.  
  207.  
  208. /*@ XNoteBook::GetPageCount(void)
  209. @group misc
  210. @remarks Returns the count of pages.
  211. @returns SHORT numberOfPages
  212. @new
  213. */
  214. SHORT XNoteBook::GetPageCount(void) const
  215. {
  216.    return SHORT1FROMMR(WinSendMsg(winhandle, BKM_QUERYPAGECOUNT, (MPARAM) 0, (MPARAM) BKA_END));
  217. }
  218.  
  219.  
  220. /*@ XNoteBook::CalcClientRect(XRect * out)
  221. @group misc
  222. @remarks Calculate the client-region of the notebook.
  223. @parameters XRect * buffer
  224. @new
  225. */
  226. void XNoteBook::CalcClientRect(XRect * out, BOOL page)
  227. {
  228.    RECTL rect;
  229.    XRect r;
  230.    GetSize(&r);
  231.    rect.xLeft = r.GetX();
  232.    rect.yBottom = r.GetY();
  233.    rect.xRight = r.GetWidth() + r.GetX();
  234.    rect.yTop = r.GetY() + r.GetHeight();
  235.    WinSendMsg(winhandle, BKM_CALCPAGERECT, MPFROMP(&rect), (MPARAM) page);
  236.    out->SetX( rect.xLeft );
  237.    out->SetY( rect.yBottom );
  238.    out->SetWidth( rect.xRight - rect.xLeft );
  239.    out->SetHeight( rect.yTop - rect.yBottom );
  240. }
  241.  
  242.  
  243.