home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xbookpg.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  6KB  |  174 lines

  1. #include "XNoteBk.h"
  2. #include "XBookPg.h"
  3. #include "xcntevnt.h"
  4. #include "xcolor.h"
  5. #include "xexcept.h"
  6. #include "xres.h"
  7. #include "xreslib.h"
  8. #include "xbitmap.h"
  9.  
  10. MRESULT HandleDefault(XWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled);
  11. void BuildChilds(HWND dlgHandle);
  12.  
  13.  
  14. MRESULT EXPENTRY bookProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  15. {
  16.     XNoteBookPage *w = (XNoteBookPage *) WinQueryWindowPtr(hwnd, 0);
  17.  
  18.     if (w)
  19.     {
  20.         BOOL handeld = FALSE;
  21.         MRESULT mr = HandleDefault(w, msg, mp1, mp2, handeld);
  22.  
  23.         if (handeld)
  24.             return mr;
  25.     }
  26.     return WinDefDlgProc(hwnd, msg, mp1, mp2);
  27. }
  28.  
  29.  
  30. /*@
  31. @class XNoteBookPage
  32. @parent XWindow
  33. @type overview
  34. @symbol _
  35. */
  36.  
  37. /*@ 
  38. @class XNoteBookPage
  39. @type overview
  40. @symbol _
  41. @remarks XNoteBookPage is a page of XNoteBook. You can add one ore more pages to
  42. a notebook. The behaviour of a XNoteBookPage is like any other window so you can use
  43. all functions like DoCommand, DoControl etc.
  44. */
  45.  
  46.  
  47. /*@ XNoteBookPage :: GetBackgroundColor ( XColor * col )
  48. @group colors
  49. @remarks Returns the background color.
  50. @parameters XColor * buffer
  51. */
  52. void XNoteBookPage::GetBackgroundColor(XColor * col)
  53. {
  54.     owner->GetBackgroundColor(col);
  55. }
  56.  
  57.  
  58. /*@ XNoteBookPage::XNoteBookPage( const XNoteBook * o, const USHORT style, const USHORT order, const char * title, const XNoteBookPage * insertBehind, const XResource * res)
  59. @group contructors/destructors
  60. @remarks Construct a notebook-page and adds it to a given notebook
  61. @parameters <t '°' c=2>
  62.                 °XNoteBook * notebook       °notebook which gets the page
  63.             °USHORT style               °style of the page:
  64.                                                     <t '°' c=2>
  65.                                           °BP_MAJORTAB    °
  66.                                           °BP_MINORTAB    °
  67.                                           °BP_PAGEBUTTON    °
  68.                                           °BP_STATUSTEXTON    °
  69.                                           °BP_MAJOR    °
  70.                                           °BP_MINOR    °
  71.                                                     </t>
  72.                                        (can be or-ed, default is BP_MAJOR|BP_STATUSTEXTON)
  73.             °USHORT order               °where to insert:
  74.                                                     <t '°' c=2>
  75.                                           °BP_LAST    °
  76.                                           °BP_FIRST    °
  77.                                           °BP_NEXT    °
  78.                                           °BP_PREV    °
  79.                                           °BP_TOP    °
  80.                                                     </t>
  81.                                        if BP_LAST or BP_FIRST, insertBehind is ignored (default BP_LAST)
  82.             °XNoteBookPage * insertBehind   °insert behind this page (default is NULL)
  83.             °XResource * resource       °It is possibe to load a dialog from the resources to be a bookpage. If you want to do
  84.                                        so give here a XResource which contains the id of the dialog to load and the resourcelibrary
  85.                                        where to load the dialog from. If you have created one or more pages from resources, you
  86.                                        should resize the notebook.
  87.                                         Default is NULL.
  88.                 </t>
  89. @exceptions    If the method fails an exception of the type XException is thrown.
  90. */
  91. XNoteBookPage :: XNoteBookPage(const XNoteBook * o, const USHORT style, const USHORT order, const char *title, const XNoteBookPage * insertBehind, const XResource * res)
  92. {
  93.     if (res)
  94.     {
  95.         XColor col(COL_PALEGRAY);
  96.  
  97.         SetBackgroundColor(&col);
  98.         if ((winhandle = WinLoadDlg(o->GetHandle(), o->GetHandle(), (PFNWP) bookProc, res->GetResourceLibrary()->GetModuleHandle(), res->GetID(), NULL)) == 0)
  99.             OOLThrow("error loading notebook-template", -10);
  100.  
  101.         WinSetWindowPtr(winhandle, 0, this);
  102.         BuildChilds(winhandle);
  103.     }
  104.     else
  105.     {
  106.         if (WinRegisterClass(WinQueryAnchorBlock(o->GetHandle()), (PSZ) "OOL_BOOKPAGE", (PFNWP) userProc, 0, 4) == FALSE)
  107.             OOLThrow("error registering notebook-class", -10);
  108.  
  109.         winhandle = WinCreateWindow(o->GetHandle(), (PSZ) "OOL_BOOKPAGE", NULL, 0, 0, 0, 0, 0, o->GetHandle(), HWND_TOP, 0, this, 0);
  110.     }
  111.  
  112.     ULONG p = (insertBehind ? insertBehind->id : 0);
  113.  
  114.     owner = (XNoteBook *) o;
  115.     id = LONGFROMMR(WinSendMsg(o->GetHandle(), BKM_INSERTPAGE, (MPARAM) p, MPFROM2SHORT(style | BKA_AUTOPAGESIZE, order)));
  116.     WinSendMsg(o->GetHandle(), BKM_SETPAGEWINDOWHWND, MPFROMLONG(id), MPFROMHWND(winhandle));
  117.     if (title)
  118.         SetText(title);
  119. }
  120.  
  121.  
  122. /*@ XNoteBookPage :: SetStatusText( const char * t)
  123. @group text functions
  124. @remarks Set the text of the status-line (if the page has one)
  125. @parameters char * text    the text to display
  126. */
  127. void XNoteBookPage::SetStatusText(const char *t) const
  128. {
  129.     WinSendMsg(owner->GetHandle(), BKM_SETSTATUSLINETEXT, MPFROMLONG(id), MPFROMP(t));
  130. }
  131.  
  132.  
  133. /*@ XNoteBookPage :: SetText( const char * t)
  134. @group text functions
  135. @remarks Set the text of the tab
  136. @parameters char * text    the text to display
  137. */
  138. void XNoteBookPage::SetText(const char *t)
  139. {
  140.     WinSendMsg(owner->GetHandle(), BKM_SETTABTEXT, MPFROMLONG(id), MPFROMP(t));
  141. }
  142.  
  143.  
  144. /*@ XNoteBookPage :: SetBitmap( const XBitmap * b)
  145. @group text functions
  146. @remarks Set the bitmap of the tab
  147. @parameters XBitmap * bitmap    the bitmap to display
  148. */
  149. void XNoteBookPage::SetBitmap(const XBitmap * b)
  150. {
  151.     WinSendMsg(owner->GetHandle(), BKM_SETTABBITMAP, MPFROMLONG(id), MPFROMLONG(b->GetHandle()));
  152. }
  153.  
  154.  
  155. /*@ XNoteBookPage :: SetTop( void )
  156. @group misc
  157. @remarks Set the page to the top of the notebook
  158. */
  159. void XNoteBookPage::SetTop(void) const
  160. {
  161.     WinSendMsg(owner->GetHandle(), BKM_TURNTOPAGE, MPFROMLONG(id), 0);
  162. }
  163.  
  164.  
  165. /*@ XNoteBookPage :: GetPageCount( void )
  166. @group misc
  167. @remarks Returns the count of minor-pages behind this page up to the next major-page
  168. @returns SHORT numberOfPages
  169. */
  170. SHORT XNoteBookPage::GetPageCount(void) const
  171. {
  172.     return SHORT1FROMMR(WinSendMsg(winhandle, BKM_QUERYPAGECOUNT, (MPARAM) id, (MPARAM) BKA_MAJOR));
  173. }
  174.