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

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