home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / strdbw.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-28  |  14.5 KB  |  455 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- // 
  5. // C++ Header File Name: strdbw.h
  6. // Compiler Used: MSVC40, HP CPP 10.24
  7. // Produced By: Doug Gaer 
  8. // File Creation Date: 12/16/1997 
  9. // Date Last Modified: 03/29/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The string database is a general purpose object-oriented
  32. database. This version is designed to work with the wxWindow
  33. GUI library version 1.68
  34.  
  35. - Modify "dbconfig.h" file to customize the database
  36. - Modify "dbvers.h" file to uniquely identify the database
  37. - Modify "dbtcfg.h" file to customize this program
  38. - Modify "version.h" file to report changes and fixes
  39. */
  40. // ----------------------------------------------------------- //
  41. #ifndef __STRDBW_HPP__
  42. #define __STRDBW_HPP__
  43.  
  44. #include "strdb.h"
  45. #include "config.h"
  46. #include "dbconfig.h"
  47. #include "timer.h"
  48. #include "version.h"
  49. #include "dbtcfg.h"
  50. #include "strdb_sh.h"
  51. #include "pscript.h"
  52. #include "htmldrv.h"
  53.  
  54. #ifdef __GNUG__
  55. #pragma implementation
  56. #pragma interface
  57. #endif
  58.  
  59. // For compilers that support precompilation, includes "wx.h".
  60. #include "wx_prec.h"
  61.  
  62. #ifdef __BORLANDC__
  63. #pragma hdrstop
  64. #endif
  65.  
  66. #ifndef WX_PRECOMP
  67. #include "wx.h"
  68. #endif
  69.  
  70. // Define this macro to use the wxWindows printing features under
  71. // Microsoft Windows. A separate PostScript driver is provided for
  72. // UNIX system. Define this macro for UNIX compiles to enable MSW
  73. // style printing in motif using wxWindow 1.68B.
  74. // #ifndef __USE_MSW_PRINTING__
  75. // #define __USE_MSW_PRINTING__
  76. // #endif
  77.  
  78. #ifdef __USE_MSW_PRINTING__
  79. // Setup wxWindows printing for MSW
  80. #if !USE_PRINTING_ARCHITECTURE
  81. #error You must set USE_PRINTING_ARCHITECTURE to 1 in wx_setup.h to compile 
  82. #endif
  83.  
  84. #include "wx_mf.h"
  85. #include "wx_print.h"
  86. #endif // __USE_MSW_PRINTING__
  87.  
  88. // Define new frame types for wxWindow frames and sub-frames
  89. class MyFrame;       // Main window frame
  90. class MyTextWindow;  // Text windos frames
  91. class MyText;        // Class used to encapsulate wxText objects
  92.  
  93. // Define configurable parameters
  94. int CacheSize = 15;  // Memory cache size for the index file
  95. int AdminRights = 0; // Define user privileges 
  96.  
  97. // Define file access modes used in the application
  98. VBDFile::AccessMode RWMode = VBDFile::READWRITE;
  99. VBDFile::AccessMode ROMode = VBDFile::READONLY;
  100.  
  101. // Function prototypes for wxWindows controls
  102. void AddBtnProc(wxButton& but, wxCommandEvent& event);
  103. void ClearAddPanel();
  104. void ChBtnProc(wxButton& but, wxCommandEvent& event);
  105. void ClearChangePanel();
  106. void DsBtnProc(wxButton& but, wxCommandEvent& event);
  107. void ClearDisplayPanel();
  108. void text_proc(wxText &but, wxCommandEvent &event);
  109.  
  110. #ifdef __USE_MSW_PRINTING__
  111. void  page_btn_proc(wxButton& but, wxCommandEvent& event);
  112. #endif // __USE_MSW_PRINTING__
  113.  
  114. // File menu functions
  115. void ExportToASCII(MyTextWindow &textWin);
  116. void ImportFromASCII(MyTextWindow &textWin);
  117. void BackUp(MyTextWindow &textWin);
  118. void Merge(MyTextWindow &textWin);
  119. void CreateTemplate(MyTextWindow &textWin);
  120. void CompareIndexFile(MyTextWindow &textWin);
  121. void RebuildIndexFile(MyTextWindow &textWin);
  122.  
  123. // Database menu functions
  124. void Add(MyTextWindow &textWin);
  125. void Change(MyTextWindow &textWin);
  126. void Remove(MyTextWindow &textWin, char *keyNM = 0);
  127. void DisplayDB(MyTextWindow &textWin); 
  128.  
  129. // Find menu functions
  130. void FindBy(MyTextWindow &textWin, const char *MemberName, StrDBItem item);
  131.  
  132. // Print menu functions
  133. void ASCIIPrintAll(MyTextWindow &textWin); // Print abbreviated listing
  134. void ASCIIPrintAllLong(MyTextWindow &textWin); // Print full listing 
  135. void ASCIIPrintObject(MyTextWindow &textWin, char *keyNM = 0);
  136. void PostScriptPrint(MyTextWindow & textWin);
  137. void HTMLPrint(MyTextWindow & textWin);
  138.  
  139. // View menu functions
  140. void Clear(MyTextWindow &textWin);
  141.  
  142. // Function prototypes for non-menu functions
  143. void DisplayObject(StrDB &strdb);
  144. int LoadIndexKeys();
  145.  
  146. enum PrintMode {
  147.   PORTRAIT,
  148.   LANDSCAPE
  149. };
  150.  
  151. void PrintItemBar(ofstream &stream, int abv = 1);
  152. void PrintLineByLine(StrDB &strdb, ofstream &stream, int abv = 1);
  153. int ASCIIPrint(PrintMode mode, MyTextWindow &textWin);
  154. void PrintObject(StrDB &strdb, MyTextWindow &textWin);
  155. int PrintPSItemBar(ofstream &stream, PostScriptDrv &psdrv,
  156.             int x_offset, int char_offset, int max_len);
  157.  
  158. // Search functions
  159. void StrDBSearch(StrDB &strdb, StrDBItem item, UString &str,
  160.          MyTextWindow &textWin, const char *wildcard = 0);
  161.  
  162. // Version number for this windows program 
  163. char *VerNumber();
  164.  
  165. // Control key macro used for wxWindows key events
  166. #define CONTROL(c) ((c) & 037)
  167.  
  168. // Identification for the all wxWindows main menu functions
  169. enum MainMenu {
  170.   // File menu constants
  171.   FILE_QUIT = 1,
  172.   FILE_VBDSTATS,
  173.   FILE_EXPORT,
  174.   FILE_IMPORT,
  175.   FILE_BACKUP,
  176.   FILE_MERGE,
  177.   FILE_TEMPLATE,
  178.   FILE_COMPARE_INDEX,
  179.   FILE_REBUILD_INDEX,
  180.   
  181.   // Edit menu constants
  182.   EDIT_CUT,   
  183.   EDIT_COPY,  
  184.   EDIT_PASTE, 
  185.  
  186.   // Database menu constants
  187.   DB_DISPLAY,
  188.   DB_ADD,
  189.   DB_CHANGE,
  190.   DB_REMOVE,
  191.   
  192.   // Find menu constants
  193.   FIND_BYKEYNAME,
  194.   FIND_BYM2NAME,
  195.   FIND_BYM3NAME,
  196.   FIND_BYM4NAME,
  197.   FIND_BYM5NAME,
  198.   FIND_BYM6NAME,
  199.   FIND_BYM7NAME,
  200.   FIND_BYM8NAME,
  201.   FIND_BYCOMMENTS,
  202.   
  203.   // Print menu constants
  204.   WXPRINT_PRINT,
  205.   WXPRINT_PRINTER_SETUP,
  206.   WXPRINT_PREVIEW,
  207.   WXPRINT_PAGE_SETUP,
  208.   PRINT_POSTSCRIPT,
  209.   PRINT_HTML,
  210.   PRINT_ASCIIALL,
  211.   PRINT_ASCIILONG,
  212.   PRINT_ASCIIOBJECT,
  213.   
  214.   // View menu constants
  215.   VIEW_CLEAR,
  216.   
  217.   // Help menu constants
  218.   HELP_ABOUT,
  219.   HELP_USERLEVEL
  220. };
  221.  
  222. // Define control button tags for wxWindow panel buttons
  223. #define ADD_BUTTON_ADD     1
  224. #define ADD_BUTTON_CANCEL  2
  225. #define ADD_BUTTON_CLOSE   3
  226. #define ADD_BUTTON_REVERT  4
  227.  
  228. #define CHANGE_BUTTON_CM     11
  229. #define CHANGE_BUTTON_CANCEL 12
  230. #define CHANGE_BUTTON_CLOSE  13
  231. #define CHANGE_BUTTON_REVERT 14
  232. #define CHANGE_BUTTON_SH     15
  233.  
  234. #define DISPLAY_BUTTON_NX     21
  235. #define DISPLAY_BUTTON_PREV   22
  236. #define DISPLAY_BUTTON_CHANGE 23
  237. #define DISPLAY_BUTTON_CLOSE  24
  238. #define DISPLAY_BUTTON_REMOVE 25
  239.  
  240. #ifdef __USE_MSW_PRINTING__
  241. #define PAGE_DIALOG_BUTTON_CLOSE   400
  242. #define PAGE_DIALOG_BUTTON_ACCEPT  401
  243. #define PAGE_DIALOG_BUTTON_CANCEL  402
  244. #define PAGE_DIALOG_BUTTON_DEFAULT 403
  245. #endif // __USE_MSW_PRINTING__
  246.  
  247. // Define a new text subwindow that can respond to drag-and-drop
  248. class MyTextWindow: public wxTextWindow
  249. {
  250. public:
  251.   MyTextWindow(wxFrame *frame, int x=-1, int y=-1, int width=-1, int height=-1,
  252.                long style=0):
  253.     wxTextWindow(frame, x, y, width, height, style) { DragAcceptFiles(TRUE); }
  254.  
  255. public:
  256.   void OnDropFiles(int n, char *files[], int x, int y) { LoadFile(files[0]); }
  257.   void OnChar(wxKeyEvent& event);
  258. };
  259.  
  260. // Define a new application type
  261. class MyApp: public wxApp
  262. {
  263. public:
  264.   wxFrame *OnInit();
  265. };
  266.  
  267. // Define a new frame type
  268. class MyFrame: public wxFrame
  269. {
  270. public:
  271.   MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
  272.  
  273. public:
  274.   void OnMenuCommand(int id);
  275.   void OnSize(int w, int h);
  276.   Bool OnClose();
  277.   void OnActivate(Bool active) { }
  278.   
  279. public:
  280.   MyTextWindow *textWin;  // Text window for main frame
  281.   wxPanel *apanel;        // Panel for adding objects
  282.   wxPanel *cpanel;        // Panel for changing object
  283.   wxPanel *dpanel;        // Panel for display objects
  284.   MyText *addText;        // wxText object used for the apanel
  285.   MyText *changeText;     // wxText object used for the cpanel
  286.   MyText *displayText;    // wxText object used for the dpanel
  287. };
  288.  
  289. class MyText: public wxText
  290. {
  291. public:
  292.   MyText(wxPanel *parent, wxFunction func, char *label, char *value = "",
  293.         int x = -1, int y = -1, int width = -1, int height = -1,
  294.         long style = 0, char *name = "text");
  295.  
  296.   MyText() { key = m2 = m3 = m4 = m5 = m6 = m7 = m8 = cmt = 0; }
  297.   ~MyText();
  298.   
  299. public:
  300.   wxText *key;
  301.   wxText *m2;
  302.   wxText *m3;
  303.   wxText *m4;
  304.   wxText *m5;
  305.   wxText *m6;
  306.   wxText *m7;
  307.   wxText *m8;
  308.   wxText *cmt;
  309. };
  310.  
  311. // Setup wxWindows printing for MSW
  312. #ifdef __USE_MSW_PRINTING__
  313.  
  314. // wxWindows MSW Printer defaults
  315. // NOTE: Left/Right and Top/Bottom magrins are in logical units (20 per inch). 
  316. const int mswpLINES_PER_PAGE = 34;    // Default lines per page
  317. const int mswpCELL_LENGTH = 19;       // Default cell length for spacing
  318. const int mswpFONT_SIZE = 9;          // Default font size
  319. const int mswpLR_MARGINS = 5;         // Default for left/right margins
  320. const int mswpORIENTATION = 0;        // Default to landsacpe
  321. const int mswpFONT = 0;               // Default font code: 0 = wxSWISS
  322. const int mswpTB_MARGINS = 20;        // Default for 1" top/bottom margins
  323. const int mswpLINE_WIDTH = 2;         // Line width for separator lines
  324. const int mswpPRINTABLE_OFFSET_X = 5; // Printable page area x offset
  325. const int mswpPRINTABLE_OFFSET_Y = 5; // Printable page area y offset
  326.  
  327. // Data structure use to hold various parameters for MSW printing
  328. struct MSWPrintingParameters
  329. {
  330.   MSWPrintingParameters() {
  331.     // Set current print settings using the mswp defaults
  332.     lines_per_page = mswpLINES_PER_PAGE; 
  333.     cell_length = mswpCELL_LENGTH;    
  334.     font_size = mswpFONT_SIZE;   
  335.     orientation = mswpORIENTATION;
  336.     font = mswpFONT;        
  337.     lr_margin = mswpLR_MARGINS;  
  338.     tb_margin = mswpTB_MARGINS; 
  339.     
  340.     // Set previous print setting
  341.     prev_lines_per_page = lines_per_page;
  342.     prev_cell_length = cell_length;
  343.     prev_font_size = font_size;
  344.     prev_orientation = orientation;
  345.     prev_font = font;
  346.     prev_lr_margin = lr_margin;
  347.     prev_tb_margin = tb_margin;
  348.     
  349.     // Set default print setting
  350.     default_lines_per_page = lines_per_page;
  351.     default_cell_length = cell_length;
  352.     default_font_size = font_size;
  353.     default_orientation = orientation;
  354.     default_font = font;
  355.     default_lr_margin = lr_margin;
  356.     default_tb_margin = tb_margin;
  357.   }    
  358.  
  359.   // Current print settings
  360.   int lines_per_page; // Number of line per page
  361.   int cell_length;    // Spacing between the object's data
  362.   int font_size;      // Font or point size fot the object's data
  363.   int orientation;    // 0 == Landscape, 1 == Portrait
  364.   float lr_margin;    // Left and right magrin in logical units (20 per inch) 
  365.   float tb_margin;    // Top and bottom magrin in logical units (20 per inch)
  366.   int font;           // Font codes must match FontChoiceStrings array:
  367.                       // 0 = wxSWISS
  368.                       // 1 = wxROMAN
  369.                       // 2 = wxDECORATIVE
  370.                       // 3 = wxMODERN 
  371.                       // 4 = wxSCRIPT
  372.                       // 5 = wxDEFAULT
  373.   
  374.   // Previous print setting
  375.   int prev_lines_per_page;
  376.   int prev_cell_length;
  377.   int prev_font_size;
  378.   int prev_orientation;
  379.   float prev_lr_margin;
  380.   float prev_tb_margin;
  381.   int prev_font;
  382.   
  383.   int default_lines_per_page;
  384.   int default_cell_length;
  385.   int default_font_size;
  386.   int default_orientation;
  387.   float default_lr_margin;
  388.   float default_tb_margin;
  389.   int default_font;
  390. };
  391.  
  392. // Declare a global printer page setup for MSW printing
  393. extern MSWPrintingParameters MSWPrnPars;
  394. extern MSWPrintingParameters *MSWPrintSetup;
  395.  
  396. // (w)xWindows (S)tring (D)atabase (P)rinting class
  397. class wStrDBPrint: public wxPrintout
  398. {
  399. public:
  400.   wStrDBPrint(char *title):wxPrintout(title) { }
  401.  
  402. public: // Override virtual functions in base class 
  403.   Bool OnPrintPage(int page);
  404.   Bool HasPage(int page);
  405.   Bool OnBeginDocument(int startPage, int endPage);
  406.   void OnPreparePrinting();
  407.   void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom,
  408.            int *selPageTo);
  409.  
  410. public: 
  411.   void SetFont(int style = wxNORMAL, int weight = wxNORMAL);
  412.   void SetHeaderFont(int size, int font, int style, int weight);
  413.   void SetItemBarFont(int style = wxITALIC, int weight = wxBOLD);
  414.   void ScaleDC(wxDC *dc);
  415.   void PrintText(wxDC *dc, char *s, int max_len, float xpos, float ypos);
  416.   void PrintText(wxDC *dc, char *s, float xpos, float ypos);
  417.   void PrintText(wxDC *dc, char c, float xpos, float ypos);  
  418.   void PrintText(wxDC *dc, int i, float xpos, float ypos);
  419.   void PrintText(wxDC *dc, long i, float xpos, float ypos);
  420.   void PrintText(wxDC *dc, double i, float xpos, float ypos);
  421.   void PrintText(wxDC *dc, float i, float xpos, float ypos);
  422.   void DrawTextPage(wxDC *dc, int page);
  423.   void WritePageHeader(wxDC *dc, char *doc_name, char *doc_date = 0);
  424.   void WritePageNumber(wxDC *dc, int pagenum);
  425.  
  426. private: // Font dependent members
  427.   wxFont *printerFont; // Text font for object's data
  428.   wxFont *itembarFont; // Text font for the item bar
  429.   wxFont *headerFont;  // Text font for page header and page numbers
  430.   float char_width;    // Width of each character based on the font type
  431.  
  432. private: // Page dependent members
  433.   int page_width;  // Page width in millimetres
  434.   int page_height; // Page height in millimetres
  435.   float start_x;   // Starting x position 
  436.   float start_y;   // Starting y position 
  437.  
  438. private: // Device Context/Page scaling members
  439.   float logUnitsFactor; // Factor for converting millimetres to logical units
  440.   float scale;          // Factor for printout/screen scaling.
  441.   int ppiScreenX;       // Logical pixels per inch of screen
  442.   int ppiScreenY;       // Logical pixels per inch of screen
  443.   int ppiPrinterX;      // Logical pixels per inch of screen
  444.   int ppiPrinterY;      // Logical pixels per inch of screen
  445. };
  446.  
  447. #endif // __USE_MSW_PRINTING__
  448.  
  449. #endif // __STRDBW_HPP__
  450. // ----------------------------------------------------------- //
  451. // ------------------------------- //
  452. // --------- End of File --------- //
  453. // ------------------------------- //
  454.  
  455.