source: vendor/emx/current/src/pmgdb/srcfiles.cc

Last change on this file was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.1 KB
Line 
1/* srcfiles.cc
2 Copyright (c) 1996 Eberhard Mattes
3
4This file is part of pmgdb.
5
6pmgdb is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11pmgdb is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with pmgdb; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21
22#define INCL_DOS
23#define INCL_WIN
24#include <os2.h>
25#include <stdlib.h>
26#include <string.h>
27#include "string.h"
28#include "pmapp.h"
29#include "pmframe.h"
30#include "pmtxt.h"
31#include "pmtty.h"
32#include "pmgdb.h"
33#include "help.h"
34#include "breakpoi.h"
35#include "srcfiles.h"
36#include "command.h"
37
38
39source_files_window::source_files_window (command_window *in_cmd,
40 unsigned in_id, const SWP *pswp,
41 const char *fontnamesize)
42 : pmtxt (in_cmd->get_app (), in_id,
43 pswp == NULL ? FCF_SHELLPOSITION : 0, pswp, fontnamesize)
44{
45 cmd = in_cmd;
46 head = NULL;
47 lines = 0; sel_line = -1;
48 set_title ("pmgdb - Source Files");
49 set_keys_help_id (HELP_SRCS_KEYS);
50
51 sel_attr = get_default_attr ();
52 set_fg_color (sel_attr, CLR_BLACK);
53 set_bg_color (sel_attr, CLR_PALEGRAY);
54}
55
56
57source_files_window::~source_files_window ()
58{
59 delete_all ();
60}
61
62
63MRESULT source_files_window::wm_close (HWND, ULONG, MPARAM, MPARAM)
64{
65 show (false);
66 return 0;
67}
68
69
70MRESULT source_files_window::wm_command (HWND hwnd, ULONG msg,
71 MPARAM mp1, MPARAM mp2)
72{
73 return cmd->wm_command (hwnd, msg, mp1, mp2);
74}
75
76
77MRESULT source_files_window::wm_activate (HWND hwnd, ULONG msg,
78 MPARAM mp1, MPARAM mp2)
79{
80 if (SHORT1FROMMP (mp1))
81 cmd->associate_help (get_hwndFrame ());
82 return WinDefWindowProc (hwnd, msg, mp1, mp2);
83}
84
85
86void source_files_window::button_event (int line, int column, int, int button,
87 int clicks)
88{
89 if (line >= 0 && column >= 0)
90 {
91 // TODO: Context menu
92 if (button == 1 && clicks == 1)
93 select_line (line, true);
94 else if (button == 1 && clicks == 2)
95 {
96 const srcs_node *p = find_by_line (line);
97 if (p == NULL)
98 WinAlarm (HWND_DESKTOP, WA_ERROR);
99 else
100 cmd->show_source (p->fname, NULL, true);
101 select_line (line);
102 }
103 else
104 select_line (-1);
105 }
106 else
107 select_line (-1);
108}
109
110
111source_files_window::srcs_node *source_files_window::find_by_line (int line)
112{
113 for (srcs_node *p = head; p != NULL; p = p->next)
114 if (line == 0)
115 return p;
116 else
117 --line;
118 return NULL;
119}
120
121
122void source_files_window::add (const char *fname)
123{
124 srcs_node *p = new srcs_node;
125 p->next = head;
126 p->fname = fname;
127 head = p;
128 ++lines;
129}
130
131
132static int compare (const void *p1, const void *p2)
133{
134 const source_files_window::srcs_node *n1
135 = *((source_files_window::srcs_node **)p1);
136 const source_files_window::srcs_node *n2
137 = *((source_files_window::srcs_node **)p2);
138 return _fncmp ((const unsigned char *)_getname (n1->fname),
139 (const unsigned char *)_getname (n2->fname));
140}
141
142
143void source_files_window::done ()
144{
145 int i;
146 srcs_node *p;
147
148 if (lines > 1)
149 {
150 srcs_node **vector = new srcs_node *[lines];
151 i = 0;
152 for (p = head; p != NULL; p = p->next)
153 vector[i++] = p;
154 qsort (vector, lines, sizeof (*vector), compare);
155 srcs_node **patch = &head;
156 for (i = 0; i < lines; ++i)
157 {
158 *patch = vector[i];
159 patch = &(*patch)->next;
160 }
161 *patch = NULL;
162 delete[] vector;
163 }
164 for (i = 0, p = head; p != NULL; p = p->next, ++i)
165 {
166 put (i, 0, 1, " ", true);
167 put (i, 1, strlen (p->fname), p->fname, true);
168 }
169}
170
171
172void source_files_window::delete_all ()
173{
174 parent::delete_all ();
175 srcs_node *p, *next;
176 for (p = head; p != NULL; p = next)
177 {
178 next = p->next;
179 delete p;
180 }
181 head = NULL;
182 lines = 0; sel_line = -1;
183}
184
185
186void source_files_window::select (const char *fname)
187{
188 int line = 0;
189 for (srcs_node *p = head; p != NULL; p = p->next, ++line)
190 if (strcmp (p->fname, fname) == 0)
191 {
192 select_line (line);
193 return;
194 }
195 select_line (-1);
196}
197
198
199void source_files_window::select_line (int line, bool toggle)
200{
201 if (toggle && line != -1 && line == sel_line)
202 line = -1;
203 if (line != sel_line)
204 {
205 if (sel_line != -1)
206 {
207 put (sel_line, 0, max_line_len, get_default_attr (), true);
208 set_eol_attr (sel_line, get_default_attr (), true);
209 }
210 if (line != -1)
211 {
212 put (line, 0, max_line_len, sel_attr, true);
213 set_eol_attr (line, sel_attr, true);
214 }
215 sel_line = line;
216 }
217 if (line != -1)
218 show_line (line, 0, 0);
219}
Note: See TracBrowser for help on using the repository browser.